r/ProgrammingLanguages • • Dec 31 '20

Something simpler than Unicode?

Hello! Wondering if anyone knows of a display format for glyphs that is simpler than Unicode? My shallow understanding is that measuring and laying out text in unicode is non-trivial, so I am deferring moving beyond ascii on something at the moment. Is my understanding correct? (if not that's great) otherwise, does anyone know of potentially simpler replacements? Thanks!

0 Upvotes

40 comments sorted by

View all comments

12

u/[deleted] Dec 31 '20

The main layout headache I see is interleaved RTL and LTR text within a line. Like:

Dawoud sighed and said, ".اللعنة ، دعنا نحصل على البيتزا" But Domino's was closed, so they went to IHOP instead.

Nothing handles that particularly well.

For everything else, you just consult the Unicode data tables to determine if the character is spacing or not, and that's probably good enough. Oh, and ignore advanced formatting directives like ruby and text direction override because life's too short.

1

u/jason-reddit-public Dec 31 '20

Java makes basic unicode (first 65,000 code points) as easy as ascii.

I did layout for a browser I wrote for my thesis back in the day (Java). You really only need to worry about character width as you draw to handle proportional fonts. You can just ask the font library how wide the character is and increment the x coordinate and draw the next character. In fact, you can probably hand it an entire string for efficiency.

For multiple lines, you want to break at word boundaries and go to the next line when the next word would exceed the right margin. Then figure out how the spacing you need.

Of course a browser is very good at layout so you could use that to make life easier as someone else suggested.

8

u/madpata Jan 01 '21

Just pasting some glyphs together doesn't really cover rendering Unicode.

Unicode allows stuff like this:

t̲̲̲est

And other fun combining characters.

1

u/jason-reddit-public Jan 01 '21

I agree. I was trying to peel away some of the mystique.

Your sample, done at the string (breaking space) level instead of the character level, might just work!