FTDI Community

Please login or register.

Login with username, password and session length.
Advanced Search  

News:

Welcome to the FTDI Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ FTDI Support


New Bridgetek Community is now open

Please note that we have created the Bridgetek Community to discuss all Bridgetek products e.g. EVE, MCU.

Please follow this link and create a new user account to get started.

Bridgetek Community

Author Topic: FT813 Custom Font Text  (Read 11026 times)

jberkhout

  • Newbie
  • *
  • Posts: 38
    • View Profile
FT813 Custom Font Text
« on: September 07, 2019, 09:09:59 PM »

Hi, I use a custom font.
I ported Rudolph Riedel library (Thank you very much!) to STM32H7 (480MHz) and drive the display using Quad-SPI (4-bit).
For the SD-card, I use the SDMMC (4-bit) interface, and FATFS.

I created the font with command:
fnt_cvt.exe -i SourceCodePro-Regular.ttf -s 40 -u characters.txt -d 1000
The file characters.txt contains this string (excluding the first and last double-quote):
" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[|]^_`abcdefghijklmnopqrstuvwxyz{|}~"

When printing strings, all works fine until the printed character value reaches 96, after which the characters are printed over each other (so the cursor-position didn't increment to the next horizontal character position). To illustrate it, I have attached a photo from the screen.

In the top three lines, I first print the characters individually on a calculated (forced) position. That works, all characters are printable.

The fourth line should read as: "0123456789 The quick brown fox jumps over the lazy dog", but problems start beyond character value 96, with the lower case characters, being printed over each other.
The 7th line should read as "abcdefghijklmnopqrstuvwxyz", but shows those characters all printed over each other on one place.
In the last line I take a string with the character 96 somewhere near the end ("XYZ[|]^_`abc"). The first part goes well until character 96.

My code:

Code: [Select]
/*
 * This example shows the use of the SETFONT2 command.
 * Simpler method to load RAM font. Use the font conversion utility to convert the desired
 * subset of the ASCII characters, load font data, and use cmd_setfont2 command.
 * In characters.txt
 *  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[|]^_`abcdefghijklmnopqrstuvwxyz{|}~
 */
void Ft813Setfont40(void)
{
  /*
   * The converted font file will have a starting address of
   * RAM_G or 0th byte mark
   */
  uint8_t FontHandle = 1;
  uint16_t fontFileAddress = RAM_G + 1000;
  uint16_t FontWidth = 22;
  uint16_t FontHeight = 40;

  Ft813DLstart();
  Ft813DL(CLEAR_COLOR_RGB(0, 0, 0));
  Ft813DL(CLEAR(1, 1, 1));
  Ft813DL(COLOR_RGB(255, 255, 255));
  Ft813LoadRawFile(fontFileAddress, "SourceCodePro-Regular.ttf_40_L4.raw");      /* Load font data */
  Ft813SetFont2(1, fontFileAddress, 31);
  /*
   * Set ram font to font handle 1, font metric block starts at fontFileAddress(RAM_G),
   * and set the starting character to the 32th character in the set.
   */
  uint16_t x = 10;
  for(uint8_t i = 0; i < 32; i++)
  {
    char str[2];
    str[1] = 0;
    str[0] = i + 0x20;
    Ft813Text(x, 10, FontHandle, 0, str);
    str[0] = i + 0x20 + 32;
    Ft813Text(x, 10 + FontHeight, FontHandle, 0, str);
    if (i + 0x20 + 64 < 127)    /* Do not print space character (0x20) */
    {
      str[0] = i + 0x20 + 64;
      Ft813Text(x, 10 + FontHeight * 2, FontHandle, 0, str);
    }
    x += FontWidth;
  }

  Ft813Text(10, 10 + FontHeight*4, FontHandle, 0, "0123456789 The quick brown fox jumps over the lazy dog");
  Ft813Text(10, 10 + FontHeight*5, FontHandle, 0, "The quick brown fox jumps over the lazy dog");
  Ft813Text(10, 10 + FontHeight*6, FontHandle, 0, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  Ft813Text(10, 10 + FontHeight*7, FontHandle, 0, "abcdefghijklmnopqrstuvwxyz");

  Ft813DL(DISPLAY());         /* Display the image */
  Ft813Swap();                /* Swap the current display list */
  Ft813Flush_Co_Buffer();     /* Download the commands into fifo */
  Ft813WaitCmdFifoEmpty();    /* Wait till coprocessor completes the operation */
}


The function Ft813Text:

Code: [Select]
/* Draw Text: FT81x Series Programmers Guide Section 5.41 */
void Ft813Text(int16_t x, int16_t y, int16_t font, uint16_t options, const char* s)
{
  Ft813StartFunc(FT_CMD_SIZE * 3 + strlen(s) + 1);
  Ft813SendCmd(CMD_TEXT); // 4294967052 = FFFFFF0C
  Ft813SendCmd((((uint32_t) y << 16) | (x & 0xffff)));
  Ft813SendCmd((((uint32_t) options << 16) | (uint32_t) font));
  Ft813SendStr(s);
  Ft813EndFunc();
}
Probably, I'm overlooking something.
Note, in the function Ft813SetFont2, I specified 31 as first character, perhaps there is a limit on the character value of 127.
I hope this helps somebody having the same problems.
« Last Edit: July 24, 2020, 12:12:38 AM by jberkhout »
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: FT813 Custome Font Text
« Reply #1 on: September 10, 2019, 04:09:11 PM »

Hello,

Rudolph may be able to advise you on his Library's operation, but it looks like maybe a font width issue.

You can find a draft of an upcoming application note which covers the use of special font characters at the following:
BRT_AN_042.zip

Please let me know if this helps.

Best Regards,
FTDI Community

EDIT: the hyperlink seems to be messing with the URL, if you copy it into your browser it should work fine.
« Last Edit: September 13, 2019, 03:12:43 PM by FTDI Community »
Logged

jberkhout

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: FT813 Custome Font Text
« Reply #2 on: September 10, 2019, 06:04:18 PM »

Thank you. The link to BRT_AN_042.zip does not work unfortunately.

Yes it clearly is a issue with the fonts width table, having the widths in the wrong locations.

Rudolph and me follow the standard FTDI API, and we do not handle the width of individual characters, the display does it using the information in the RAW file.
Therefore Rudolph's code can't be blamed anyway.

Looking a bit further,I found this:
In SourceCodePro-Regular.ttf_40_L4.rawh, the below line exactly explains the problem:

/* Widths */
0,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

The list is actually shifted to much to the front, using the index as in the characters file. The display expect the index conform the ASCII values.

This works fine (modified):
/* Widths */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,
24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,

After editing the raw file with a hex-editor and fixing the wrong font-widths, it works!
I changed the values inside the red box from 0x00 to the correct width 0x18 (mono-space font here).

Perhaps the font convert utility can be corrected?
In the mean time I will create my own font convert utility (with GUI).
« Last Edit: July 23, 2020, 10:38:31 AM by jberkhout »
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: FT813 Custome Font Text
« Reply #3 on: September 11, 2019, 10:52:11 AM »

Hello,

Copying the URL into your browser should work as noted in the last post.
It covers pulling the font widths from the data and printing the characters correctly with these widths.

I will pass this on to the development team to see if they can adjust the font convertor utility accordingly.

Best Regards,
FTDI Community
Logged

jberkhout

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: FT813 Custome Font Text
« Reply #4 on: September 11, 2019, 06:12:23 PM »

Hi thank you very much!
BTW, pasting the URL helps, except it then asks for a username and password, and it doesn't accept what I use over here.
Do you have any ideas?
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: FT813 Custome Font Text
« Reply #5 on: September 12, 2019, 12:19:49 PM »

Hello,

Sorry, must have pasted the link back in without the password after a couple minutes of fighting with the hyperlink.
This one should work now:
BRT_AN_042.zip

Best Regards,
FTDI Community
« Last Edit: September 13, 2019, 03:13:12 PM by FTDI Community »
Logged

jberkhout

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: FT813 Custome Font Text
« Reply #6 on: October 04, 2019, 09:19:03 AM »

Hi, thank you very much! I tested the utility used in the upcoming application note BRT_AN_042.zip, and it has exactly the same issue.
While I may be missing something, the proposed fix (modifying the raw file) works well.
« Last Edit: July 23, 2020, 10:40:45 AM by jberkhout »
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: FT813 Custome Font Text
« Reply #7 on: October 07, 2019, 01:26:36 PM »

Hello,

I will pass this on to the development team so they can look into it.

Best Regards,
FTDI Community
Logged

jberkhout

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: FT813 Custome Font Text
« Reply #8 on: July 21, 2020, 07:55:42 PM »

It seems EVE Asset Builder Version 1.6.0 still has this little glitch where, when converting fonts, the font width table has the glyph widths shifted to much too the start of the table.
This results in all lowercase characters all being printed over each other, so the cursor doesn't move on when these characters are printed, according to the wrong table content.
The raw file can easily be patched by editing using an HEX-editor, shifting the values in the glyph width table to the right positions solves the issue. I created and attached a python script to do this, it is easy to use.
Note my characters.txt contains these characters (including a space at the start):
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
The first 128 bytes in the raw file are for the width of the individual glyphs.
The displays assumes the index of this table being equal the ASCII character value, but Asset builder assumes the index as in the characters.txt file (that defines the characters to be captured).
When we shift those values to the right place, the display prints the strings as expected.
This can easily be done with a python script, I created and attached here.
These are my observations, I hope it will help others who want to use custom fonts.
It is possible I have a flaw somewhere in my conversion process, but I can't see how or where.
Otherwise the EVE Asset Builder is a great program!
For the font conversion, I created a windows program, where I select a font via the font dialog, then it generates the .raw and .h files, see attached example of a .h file.
Some part of the .h header file generated by my program looks like:
Code: [Select]
  /* Character 56 0x38 '8' */
  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, 0x05, 0x9B, 0xA7, 0x20, 0x00, 0x00,  /*      :e63+.      */
  0x00, 0x01, 0xCF, 0xFE, 0xFF, 0xF6, 0x00, 0x00,  /*    `G##$###r     */
  0x00, 0x0D, 0xF8, 0x00, 0x04, 0xEF, 0x40, 0x00,  /*    8#o   ,$#,    */
  0x00, 0x4F, 0xC0, 0x00, 0x00, 0x4F, 0xB0, 0x00,  /*   ,#G     ,#6    */
  0x00, 0x6F, 0x90, 0x00, 0x00, 0x0F, 0xD0, 0x00,  /*   r#e      #8    */
  0x00, 0x4F, 0xC0, 0x00, 0x00, 0x1F, 0xB0, 0x00,  /*   ,#G     `#6    */
  0x00, 0x0D, 0xF8, 0x00, 0x00, 0x8F, 0x50, 0x00,  /*    8#o    o#:    */
  0x00, 0x02, 0xDF, 0xD6, 0x05, 0xF9, 0x00, 0x00,  /*    .8#8r :#e     */
  0x00, 0x00, 0x3F, 0xFF, 0xFF, 0xA0, 0x00, 0x00,  /*     -#####3      */
  0x00, 0x08, 0xFA, 0x38, 0xDF, 0xF9, 0x00, 0x00,  /*    o#3-o8##e     */
  0x00, 0x9F, 0x70, 0x00, 0x03, 0xDF, 0xB0, 0x00,  /*   e#+    -8#6    */
  0x02, 0xFB, 0x00, 0x00, 0x00, 0x0D, 0xF4, 0x00,  /*  .#6       8#,   */
  0x06, 0xF8, 0x00, 0x00, 0x00, 0x08, 0xF8, 0x00,  /*  r#o       o#o   */
  0x05, 0xF9, 0x00, 0x00, 0x00, 0x08, 0xF8, 0x00,  /*  :#e       o#o   */
  0x01, 0xFF, 0x30, 0x00, 0x00, 0x1E, 0xF4, 0x00,  /*  `##-     `$#,   */
  0x00, 0x7F, 0xF8, 0x31, 0x26, 0xDF, 0xB0, 0x00,  /*   +##o-`.r8#6    */
  0x00, 0x05, 0xEF, 0xFF, 0xFF, 0xF8, 0x00, 0x00,  /*    :$######o     */
  0x00, 0x00, 0x03, 0x67, 0x64, 0x00, 0x00, 0x00,  /*      -r+r,       */
  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, 0x00, 0x00, 0x00,  /*                  */
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  /*                  */
It gives me some extra flexibility to adjust character and line spacing. It also can load raw files to show the characters in it, as they would appear on the display, but just on the PC.
I'm using the display connected to a QUADSPI peripheral on a 480MHz STM32H7. I do like the EVE displays much!
« Last Edit: July 24, 2020, 12:11:32 AM by jberkhout »
Logged

FTDI Community

  • Administrator
  • Sr. Member
  • *****
  • Posts: 443
    • View Profile
Re: FT813 Custome Font Text
« Reply #9 on: July 23, 2020, 02:15:27 PM »

Hello,

I had the dev team look at this and unfortunately they cannot reproduce what you are seeing:
The only thing they did note was to ensure the first character is at ASCII 32, not 31.


Best Regards,
FTDI Community
Logged

jberkhout

  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: FT813 Custome Font Text
« Reply #10 on: July 23, 2020, 05:07:01 PM »

Thank you very much!

Indeed I saw I had to specify 31 as the first character instead of 32.
The problem was the Raw Data Address (RDA) in the Metric Block (MB), that Asset builder calculated.
It is possible I make some wrong adjustment in Asset Builder, but I couldn't find it.
Asset Builder got the RDA wrong, which caused that problem.
And it uses a wrong index in the Glyph Width Table (the first 128 bytes in the Metric Block).
But for bitmaps it is an excellent tool!

Using a font start of 31 was the only way to get it working when the raw file was generated from Asset Builder.
I noticed it calculated various values for the RDA, depending on the chosen font size.
It sometime even came up with negative values for it!
To calculate the RDA, it seemed to follow this formula: RDA = 1000 - Stride * Max_Height + 148;

I got around these issues by creating my own program to convert fonts to raw and header files.
The RDA reflects the load address in RAMG and the MB size (148 Bytes).
This program creates a valid Glyph Width Table and RDA.
It also does batch processing for different font families, styles and sizes, generating many file sets in one go. (no need to wait, just let it work for a period of time)
And I can replace the '$' for '°' symbol. I never use the $ sign on an embedded project but I do use '°' symbol for temperatures.

Now I modified my embedded library so it calculates and sets the RDA on the fly during loading, to allow for much more flexibility.
This way font raw files can be loaded at any location in RAMG, regardless the RAMG address used during conversion.
I now specify 32 as the first character, the RDA will always be correct.
The function that loads the raw files no longers takes a destination address, instead it returns the address it got loaded to.
It also stores the properties into a structure, and it keeps track of the content of the RAMG.
A collection of fonts and images in RAMG can be assigned an unique ID, so it is easy to check if a page needs to reload RAMG with a different collection of images and fonts.
There also is a function to check if a particular images exists in RAMG, and what the properties are.
« Last Edit: July 30, 2020, 11:18:15 AM by jberkhout »
Logged