rdagger / micropython-ili9341

MicroPython ILI9341Display & XPT2046 Touch Screen Driver
MIT License
194 stars 40 forks source link

help with a new font #19

Closed fieldofhats closed 11 months ago

fieldofhats commented 12 months ago

Hello, any chance you could help me figure out how to load a new font? I'm on linux so not using glcd-font-creator, I found a different utility that make a .c font file and I was able to load it after some struggles (the font has a different bytes per letter than specified in the load code from the xglcd_font script. Now I am getting an error in the get_letters function (in the xglcd_font scrip) when i try to draw letters on the screen. the error is on line 144 of the xglcd script, and I do not have much experience dealing with raw memmory. If you are willing to take a look I can share the font file etc. Thank you in advance, Brian

rdagger commented 12 months ago

I'd try manually decoding and drawing a letter from your .c file on some graph paper or a spreadsheet. Then draw the same letter from one of my existing fonts (preferably the same size or close to the same size). Pick a letter such as "F" that doesn't have line symmetry.

I don't think there is any standard for generating .c font files. Your program may be incompatible. You can post the line for the letter F and I will take a look. I might be able to create a converter.

fieldofhats commented 12 months ago

Thank you for getting back to me and taking a look at this. I understand my font might be incomparable. The font file can be viewed at : https://github.com/fieldofhats/c_font_example/blob/main/28_pt_font.c. Ill paste the line for F below.
fyi this is the app that I used: https://github.com/ayoy/fontedit/releases/v1.1.0

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF0,0x00, 0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00, 0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0xFF,0x07,0xF0,0xFF,0x07,0xF0,0xFF,0x07,0xF0, 0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00, 0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00,0xF0,0x00,0x00, 0xF0,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, // Character 0x46 (70: 'F')
rdagger commented 12 months ago

Please generate a font the same size as one of my fonts such as 13x21 pixels. Also, a variable width font would be better than fixed width.

rdagger commented 12 months ago

A quick review of the coding of your letter F show several differences from GLCD Font Creator format.

  1. The bits of the provided hex values encodes pixels in row format as opposed to column format.
  2. The byte order is Big-Endian as opposed to Little-Endian.
  3. There is no leading hex value to indicate the width of the individual letter.

Here's what your F would look like when decoded:

000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000011111111111111110000
000011111111111111110000
000011111111111111110000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011111111111111100000
000011111111111111100000
000011111111111111100000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000011110000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000
000000000000000000000000

Here's how to write a conversion program:

  1. Read the hex values of the new font and convert them to binary.
  2. Create a function to transpose the rows to columns. This function will convert the row-based representation to a column-based one.
  3. Since the original format is little-endian, reverse the bits in each byte after transposition.
  4. The GLCD font code requires width information for each character, calculate the width based on the transposed data and prepend it.
fieldofhats commented 12 months ago

great, Ill give it a try. Thank you for the advice.

rdagger commented 12 months ago

I went ahead and created a FontEdit conversion utility for you. This is a very quick release that I didn't thoroughly test. I converted your Deja Vu font and it worked.

DejaVu

fieldofhats commented 12 months ago

Wow, Rad! thank you, ill try it out.