Best way to write text (if possible left and right justified)

FTDI/Bridgetek EVE2 & EVE3 & EVE4 SPI TFT Series by Matrix Orbital

Moderator: Mods

Post Reply
rascalito
LCD Geek
Posts: 38
Joined: Sat Apr 18, 2020 11:22 pm

Best way to write text (if possible left and right justified)

Post by rascalito »

Hello!

I'm writing an application for a measurement device, and I'm thinking of adding help on the device itself.
I would like to write text left and right justified, and if I could have some possibility of writing some
simple HTML, it would be great. So before reinventing the wheel:
- Is there a mechanism like this in BT815? I read the documentation at least partly, but I found nothing.
If not, I guess I have to write my own markup language, not necessarily HTML, maybe part of it.
- Is there a way to know the width of a string (in pixels) for a specific char string and specific font?

Thanks!

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Best way to write text (if possible left and right justified)

Post by Rudolph »

>I would like to write text left and right justified

Then use CMD_TEXT? Default is left justified and then there is OPT_RIGHTX.
Also OPT_CENTERX and OPT_CENTERY.

No HTML though, just plain text.
The BT81x added OPT_FORMAT though which adds printf() style output.

EVE_cmd_text_var_burst(320,70,27, EVE_OPT_FORMAT|EVE_OPT_RIGHTX, "xfont.signature: 0x%08X", 1, xfont.signature);

>Is there a way to know the width of a string (in pixels) for a specific char string and specific font?

Not directly, you would need to read out the widths for every char in the string.
And to do this repeatedly for changing strings I would recommend copying the whole width table for
that font once to your micro.

rascalito
LCD Geek
Posts: 38
Joined: Sat Apr 18, 2020 11:22 pm

Re: Best way to write text (if possible left and right justified)

Post by rascalito »

Hello Rudolph!

Thanks for your reply.
Then use CMD_TEXT? Default is left justified and then there is OPT_RIGHTX.
Also OPT_CENTERX and OPT_CENTERY.
Yes, that's what I'm doing for regular alignment. But what I meant with "I would like to write text
left and right justified" is that with OPT_RIGHTX or OPT_LEFTX, you can justify on either of the
sides not both. I don't know how to say that in english, but I want the text to be justified
left AND right, not left OR right.

Ok, writing HTML-like, both sides justified text will be a pain, but I have already implemented
the <FONT> and <COLOR> tags. Basically the only way I found is to cut the string into words, and
check for every word if there is enough space in the current line. And there will be a big overhead
because it will add the whole string command everytime...
you would need to read out the widths for every char in the string.
Thanks for the info! I found a reference to it in the documentation. Every font has an array of all
the character widths.

Thanks

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Best way to write text (if possible left and right justified)

Post by Rudolph »

Oh, you mean like in a book where the lines of text are spread out evenly over a fixed width?
I do not believe that EVE can do this directly.

rascalito
LCD Geek
Posts: 38
Joined: Sat Apr 18, 2020 11:22 pm

Re: Best way to write text (if possible left and right justified)

Post by rascalito »

Hello Rudolph!
Oh, you mean like in a book where the lines of text are spread out evenly over a fixed width?
I do not believe that EVE can do this directly.
Yes, that was more or less my conclusion. Anyway, for large areas of text, the overhead id not that
big after all. In the CPU:
- Spread in word items
- Calculate the size of every word.
- Add one space each time you add a word on a line except the for the first word of the current line.
- Once you cannot add the next word, add the remaining width evenly on all spaces.
- Write all the items.

Not sure how many characters there can be on one page, it depends on the font, but counting 20 lines of
60 characters when horizontal, it's 1200. And with an overhead of 12 bytes per text command (therefore
per word), it might be feasible with a single buffer of 4K. I will try.

Thanks

Rudolph
LCD Guru
Posts: 67
Joined: Wed Feb 28, 2018 11:09 am

Re: Best way to write text (if possible left and right justified)

Post by Rudolph »

The maximum number of displayable chars depends on how random the characters are and if it is an internal font on the resolution
of the display as well.
With internal fonts and coordinates below 510 you get the maximum amount of chars, somewhere near 2000.

This: CMD_TEXT(172, 319, 28, 0, "Text")
Is translated to this:
SAVE_CONTEXT()
BITMAP_HANDLE(28)
BEGIN(BITMAPS)
VERTEX2II(172, 319, 28, 'T')
VERTEX2II(186, 319, 28, 'e')
VERTEX2II(197, 319, 28, 'x')
VERTEX2II(208, 319, 28, 't')
RESTORE_CONTEXT()

This however: CMD_TEXT(631, 365, 28, 0, "Text")
Is translated to this:
SAVE_CONTEXT()
VERTEX_FORMAT(2)
BITMAP_HANDLE(28)
BEGIN(BITMAPS)
CELL(84)
VERTEX2F(2524, 1460)
CELL(101)
VERTEX2F(2580, 1460)
CELL(120)
VERTEX2F(2624, 1460)
CELL(116)
VERTEX2F(2668, 1460)
RESTORE_CONTEXT()

And with a UTF-8 font from FLASH this looks like this:
SAVE_CONTEXT()
VERTEX_FORMAT(2)
CELL(0)
BITMAP_HANDLE(12)
BEGIN(BITMAPS)
BITMAP_SOURCE(0x800000 | 808)
VERTEX2F(2316, 756)
BITMAP_SOURCE(0x800000 | 988)
VERTEX2F(2376, 756)
RESTORE_CONTEXT()

So you need two commands per char, one to setup the adresss, one to display the image.
And the display lists can "only" hold 2048 commands.

I also just noticed that the command co-processor is not optimising the display list.
A CMD_TEXT(617, 367, 28, 0, "aaa") gets translated to:
CELL(97)
VERTEX2F(2468, 1468)
CELL(97)
VERTEX2F(2512, 1468)
CELL(97)

Well, repeating characters might be rare enough to not make a real difference.

Oh yes, transferring 8192 bytes over spi at the maximum speed of 30MHz takes at least 2.5ms.
And transferring this thru the FIFO of the command co-processor is a bit more tricky since the FIFO only
has 4k.

This is not really something EVE is good at.

rascalito
LCD Geek
Posts: 38
Joined: Sat Apr 18, 2020 11:22 pm

Re: Best way to write text (if possible left and right justified)

Post by rascalito »

Hello Rudolph!

Thanks a lot for the explanations. And you also answered a question I had for a long time but never asked:
why can't I write characters in the right half of the screen. I didn't know the vertex2F and cell trick. But anyway
it already worked well with CMD_TEXT, so I forgot to ask.
This is not really something EVE is good at.
Yes, and if somebody from the chip maker is reading this, I would like to summarize my frustrations with the
current implementation. Here is a wish list:
1. Access to some more graphic primitives.
There is already a way to draw a line, and a series of lines with line strip. However, there is no way to write
for instance a circle, or more generally an arc of an ellipse. At least not that I'm aware of, so if there is anything,
please tell me! What should be doable in a single command requires really a lot of time, consumes buffer space,
etc. The only solution is to pre-cook bitmaps.
2. As mentioned in this thread, a better text engine.
3. A utility that would write a curve in a rectangle would be really a dream. Example:
- Setup a rectangle area;
- Send a buffer
And you get the whole graphic.
I'm doing this one "by hand".
Ok, only claims would not be fair: I like the sub-pixel drawing which allows for instance to have a thinner subgrid.


IMG_4367.jpeg
IMG_4367.jpeg (96.73 KiB) Viewed 1799 times
Thanks,

Post Reply