peterhinch / micropython-font-to-py

A Python 3 utility to convert fonts to Python source capable of being frozen as bytecode
MIT License
368 stars 67 forks source link

function get_ch returns nonsense #55

Closed WarriorKnight closed 7 months ago

WarriorKnight commented 7 months ago

Hey, I've generated font with this command - python font_to_py.py Quantum.otf 19 custom.py -f -c 1234567890: (Font in question https://www.dafont.com/quantum-4.font) But when testing, the get_ch returns what seems to me like a nonsense, I'm testing it with this code, print(bytes(get_ch('0'))), and it returns this - b'\x00\x00\x07\x80\x1f\xe0?\xf0\x1f\xf0Hp`xpxxxxxxxx8x\x18x@?\xe0?\xf0\x1f\xe0\x07\x80'. Which just looks like a nonsense to me. When testing other chars, it sometimes looks better, like for ex. '5' returns this b'\x00\x00\x7f\xf0\x7f\xf0\x7f\xf0\x7f\xf0x\x00\x7f\xc0\x7f\xe0\x7f\xf0\x7f\xf0\x00p\x00p\x000\x00\x10\x7f\x80\x7f\xc0\x7f\xc0\x7f\x80' So my question is, is this a bug, or how do i read individual bytes from this ?

peterhinch commented 7 months ago

The way to validate a font is with font_test.py. I generated custom.py using your command and ran font_test.py:

$ ./font_test.py custom 123456789
Vertical map
Normal bit order
Fixed spacing
Dimensions height*max_width 18 * 16
Start char "0" (ord 48) end char "?" (ord 63)
................................................................................................................................................
......#####............#####.....#######.........####...####.....###########.........#####.......##########.........####..............##........
.....######..........########....#########.......####...####.....###########........#####........##########.........######.........#######......
....#######..........#########...##########......####...####.....###########.......#####.........##########..........######.......#########.....
...########.........###########..##########......####...####.....###########......#####..........#########........#...#####.......#########.....
..#####.###.........####...####........####......####...####.....####............#####................####.......###....###......####..####.....
........###.........###....####........####......####...####.....#########.......####.................####.......####...###......####...###.....
........###.........###....####.......#####......####...####.....##########......####.................####.......####..####......###...####.....
.........##................####......#####.......###########.....###########.....########.............###.........#########.......#...#####.....
..........#.................##.......####........###########.....###########.....#######..............###.........########...........######.....
.........................#...#.......#####.......###########.............###.....######...#............##.........#########.........#######.....
........#...............###...........#####......###########.............###.....#####...##.......................#########..........##.###.....
........##.............#####..........#####................#..............##.....####...####........##...........####...###.............###.....
........###...........#####............####.............#..................#.....####...####........###..........####...###............####.....
........###..........#####.......####..####.............##.......########.........#########.........###..........##########...........#####.....
........###.........##########...#####..###.............###......#########........#########........####...........#########..........#####......
........###........###########...######..#..............####.....#########.........#######.........####............#######..........#####.......
........###.......############...#######................####.....########...........#####..........####.............####...........#####........
[adminpete@meerkat]: /mnt/qnap2/data/Projects/MicroPython/micropython-font-to-py
$ 

Looks OK to me.