How can I add a glyph to a TrueType font?

Moderator: BarryK

Post Reply
User avatar
BarryK
Posts: 2692
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 132 times
Been thanked: 738 times

How can I add a glyph to a TrueType font?

Post by BarryK »

I seem to recall, there are guys on this forum who know about Fontforge -- don't recall who, or if they are still around.

Anyway, although I'm posting in the EasyOS section, this is a generic question that could apply to any pup.

We use gettext to translate application text-strings for non-English users. We have the MoManager tool to help with creating .mo translation files. Here is an example English text, followed by a French translation:

Code: Select all

Exited from init script early, nothing yet mounted.
Sortie anticipée du script d'initialisation, rien n'est encore monté.

That single-quote character in the French translation is ASCII ', a single byte, hex 27. It is also known as a "neutral apostrophe", as it isn't slanted:

https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

A lot of languages use this neutral apostrophe. A problem is, depending on how the text is implemented in the app, the neutral apostrophe might have to be escaped. For example, in a script:

Code: Select all

VAR1='Sortie anticipée du script d'\''initialisation, rien n'\''est encore monté.'

The same problem can occur with the neutral double-quote character, it may need to be escaped.

I am wondering if I am over-thinking this, perhaps in practice it is not such a problem. Anyway, the need to escape the ' and " characters can be completely avoided by having two extra characters (glyphs) in a truetype font that are multibyte and look exactly the same as the ' and " characters.

Then, we would completely eliminate any need to escape them.

So, the question I am posing, for the truetype fonts that we are using in our pup, would it be easy to use a tool like Fontforge to duplicate ' and " as multibye characters and add them to the font?

That is, they are different glyphs, just look the same as the single-byte ASCII characters.

A clarification: UTF-8 recognizes the 8-bit (one byte) ASCII characters, including ' and ". The above link shows the neutral apostrophe as U+0027, multibyte, but that would be for UTF-16. In UTF-8, the character is only the one-byte ASCII.

Most of my GTK themes use DejaVu Sans, so I would start with editing that font.

User avatar
MochiMoppel
Posts: 1236
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 439 times

Re: How can I add a glyph to a TrueType font?

Post by MochiMoppel »

BarryK wrote: Fri Feb 03, 2023 9:50 am

I am wondering if I am over-thinking this, perhaps in practice it is not such a problem. Anyway, the need to escape the ' and " characters can be completely avoided by having two extra characters (glyphs) in a truetype font that are multibyte and look exactly the same as the ' and " characters.

IMHO that's the wrong approach. Even if you manage to define your own glyphs, which you certainly can do, using one of the "private use" code blocks, you have to make sure that all of your users will use your hacked font and use no other font. Does this make sense?
You don't need to invent "fake" apostrophs because, at least in DejaVu Sans/Sans Mono/Serif, you can choose from 3 different apostrophs: n'est nʼest n՚est . The first is ASCII, the second is U+02BC MODIFIER LETTER APOSTROPHE (Block "Spacing Modifier Letters"), also present in the Liberation font, and the third is U+055A ARMENIAN APOSTROPHE. No need to misuse quotation marks, which semantically have a different purpose.

Similar already existing surrogates for ASCII " (hex 22) are available, although I assume that they seldom appear in translated phrases. Should be sufficient to escape them.

Anyway, although I'm posting in the EasyOS section, this is a generic question that could apply to any pup

Indeed. This is why you should post such questions in the general section. Would certainly generate more views and better replies.

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

Re: How can I add a glyph to a TrueType font?

Post by don570 »

A phony character replacement using Fontforge doesn't sound like a good idea.

Running the script in the terminal and checking for errors is how I write a script.
Use real characters already existing in DejaVu.

In Europe the quoting of a citation is done with other symbols.
i.e. <<Hallo>> or other characters in set. They shouldn't be done with basic ascii characters.

Note that in the German language the apostrophe is rarely used except in colloquial speaking to indicate bad pronunciation..
However there is the possessive i.e. Max' Buch , Marx' Lehren

I think the apostophe is most popular in English.

______________________________________

User avatar
BarryK
Posts: 2692
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 132 times
Been thanked: 738 times

Re: How can I add a glyph to a TrueType font?

Post by BarryK »

Yeah, point taken. It is impractical to add multibyte neutral apostrophe and neutral double-quote to the fonts.

don570
Posts: 688
Joined: Sat Nov 21, 2020 4:43 pm
Has thanked: 5 times
Been thanked: 117 times

gettext utilities

Post by don570 »

Just a warning to forum members that scripts need to be written by genuine text editors like Geany.

I had a bad experience. I accidently used a word processor to transfer text (using the clipboard) to Geany from Abiword.
I probably had some non-ascii character in the text that I transferred.
This caused me a lot of grief when I tried to internationalize the script using gettext utilities.
The terminal warning pointed to one line of the script giving me problems.
I rewrote that line with Geany and the gettext utilities then worked.
______________________________________________________

Post Reply

Return to “EasyOS”