General Category > General Discussion

FT813 Custom Font Text

(1/3) > >>

jberkhout:
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: ---/*
 * 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 */
}


--- End code ---

The function Ft813Text:


--- Code: ---/* 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();
}

--- End code ---
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.

FTDI Community:
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.

jberkhout:
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).

FTDI Community:
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

jberkhout:
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?

Navigation

[0] Message Index

[#] Next page

Go to full version