ropod7 / pyboard_drive

23 stars 11 forks source link

Help wanted on character encoding in font.py #9

Closed mchobby closed 8 years ago

mchobby commented 8 years ago

Hi Roman, I'm planning to work on easy font creation by using a python script. The plan is to extract the font from a structured bmp in order to create a font_xx.py file for the PyBoard.

However, I do need your help to understand the coding of your existing font.

'width'  : 0x0D, # width  --> 13 pixels width
'height' : 0x0E, # height --> 14 pixels height

So 182 bits or 30 bytes per character. In the sample here under....

'65' : (0x4c00, 0x4300, 0x41c0, 0x4138, 0x4104, 0x4138,
        0x41c0, 0x4300, 0x4c00),                           # 65 A

However, I cannot figure out how the character is encoded. Could you help me with the encoding/decoding method?

Thanks

ropod7 commented 8 years ago

One character is rectangular I/O object. So, 2 bytes (one position) in tuple is one vertical pixel line in char. Better if I show in python code:

for line in Arial_14['65']: . . . print(bin(line)) . . . '0b100110000000000' '0b100001100000000' '0b100000111000000' '0b100000100111000' '0b100000100000100' '0b100000100111000' '0b100000111000000' '0b100001100000000' '0b100110000000000'

Then turn this rectangle into 90 degrees to the left and you will see 'A' character. Driver slices every line as string from '0b1' and than we have a quiet normal char in rectangular filling. But before we must replace zeros as 'bgcolor' tuples, otherwise (high levels) as character 'color'.

mchobby commented 8 years ago

More obvious now.

The first bit (left most one) in '0b1' is to 1 because we don't care it's value since the font has 14 pixels height. So we only care about the 14 bits on the right.

Thanks

mchobby commented 8 years ago

I'm getting some initial result around font. At this stage I'm loading a FreeType font and rendering the bitmap representation. Shortly, I will generate the xxx.py font file for the driver.

c:\Python\freetype-test>python freetype-generator.py
Load font Vera.ttf, set size to 19
max size (width,height): 18,19
--- w ----------------
width, height = 14, 10
**    **    **
**    **    **
**   ****   **
 **  ****  **
 **  *  *  **
 ** **  ** **
 ** **  ** **
  ***    ***
  ***    ***
  ***    ***

--- W ----------------
width, height = 18, 14
**     ****     **
**     ****     **
 **    ****    **
 **    ****    **
 **   **  **   **
 **   **  **   **
  **  **  **  **
  **  **  **  **
  ** **    ** **
  ** **    ** **
   ****    ****
   ****    ****
   ***      ***