Swapping TTGlyph Records For Text Obfuscation Project (letter positioning issue)

38 views
Skip to first unread message

cmw4...@gmail.com

unread,
Apr 10, 2019, 4:17:52 PM4/10/19
to fonttools
Font: SourceSerifPro-Regular.ttf
URL: https://fonts.google.com/specimen/Source+Serif+Pro

In a nut shell, I swapping the name attribute in TTGlyph with another random character. Then update the HTML to reflect this change.

Example (actual use case via a random number generator):
V = "at"
A = "c.sups"

NOTE: White space characters, ligature glyphs, and compound glyphs (made up of only components) are not swapped. I also ensure any swapped glyphs are referenced in all of the cmap format tables.

Original Values:
<TTGlyph name="V" xMin="14" yMin="-10" xMax="663" yMax="669">
<mtx name="V" width="673" lsb="14"/>

<TTGlyph name="at" xMin="35" yMin="-157" xMax="805" yMax="648">
<mtx name="at" width="840" lsb="35"/>

<TTGlyph name="A" xMin="5" yMin="0" xMax="654" yMax="669">
<mtx name="A" width="664" lsb="5"/>

<TTGlyph name="c.sups" xMin="30" yMin="415" xMax="316" yMax="749">
<mtx name="c.sups" width="333" lsb="30"/>

Update Values:
<TTGlyph name="V" xMin="35" yMin="-157" xMax="805" yMax="648">
<mtx name="V" width="840" lsb="35" />

<TTGlyph name="at" xMin="14" yMin="-10" xMax="663" yMax="669">
<mtx name="at" width="673" lsb="14" />

<TTGlyph name="A" xMin="30" yMin="415" xMax="316" yMax="749">
<mtx name="A" width="333" lsb="30" />

<TTGlyph name="c.sups" xMin="5" yMin="0" xMax="654" yMax="669">
<mtx name="c.sups" width="664" lsb="5" />

NOTE: TTGlyph components and Ligature components are updated to reflect these changes.

In the HTML file:
If you wanted to display a "V", you would type "@"
If you wanted to display an "A", you would type "&#7580;"

If you combine the two: "&#7580;@", you'll notice the spacing isn't correct.

I tried updating the references in GPOS but it's not correcting the space issue.

If there any other tables which could be manipulating the character spacing?

cmw4...@gmail.com

unread,
Apr 22, 2019, 6:42:48 PM4/22/19
to fonttools
I understand the sound of crickets is generally a sign of a rather stupid question (I'll bet my wallet it's not the opposite here).

If so, please forgive my ignorance; fonts are not my forte.

If what I'm trying to accomplish is not feasible, then by all means, please let me know. I appreciate constructive criticism and I don't bite; seriously.

No hand-holding is necessary. I just want a quick run-down on what I'm missing or should be doing.

Behdad Esfahbod

unread,
Apr 22, 2019, 8:04:36 PM4/22/19
to cmw4...@gmail.com, fonttools
It feels to me like you just need to shuffle the cmap table...

--
You received this message because you are subscribed to the Google Groups "fonttools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fonttools+...@googlegroups.com.
To post to this group, send email to font...@googlegroups.com.
Visit this group at https://groups.google.com/group/fonttools.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

cmw4...@gmail.com

unread,
Apr 23, 2019, 3:16:45 AM4/23/19
to fonttools
On Monday, April 22, 2019 at 8:04:36 PM UTC-4, behdad wrote:
> It feels to me like you just need to shuffle the cmap table...
>
>
> On Mon, Apr 22, 2019, 6:42 PM <cmw4...@gmail.com> wrote:
> I understand the sound of crickets is generally a sign of a rather stupid question (I'll bet my wallet it's not the opposite here).
>
>
>
> If so, please forgive my ignorance; fonts are not my forte.
>
>
>
> If what I'm trying to accomplish is not feasible, then by all means, please let me know. I appreciate constructive criticism and I don't bite; seriously.
>
>
>
> No hand-holding is necessary. I just want a quick run-down on what I'm missing or should be doing.
>
>
>
> --
>
> You received this message because you are subscribed to the Google Groups "fonttools" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an email to font...@googlegroups.com.
>
> To post to this group, send email to font...@googlegroups.com.
>
> Visit this group at https://groups.google.com/group/fonttools.
>
> For more options, visit https://groups.google.com/d/optout.

That gets me 90% there for TTF font files. I still run into spacing issues. Some of the characters are displayed too close or completely overlap.

For instance, using the ttf font referenced above, replace "uni030C" (COMBINING CARON 0x30c) with "s" (LATIN SMALL LETTER S 0x73) in the cmap tables.
Now, if you type "̌ a", you would expect to see "sa". However, the "s" completely overlaps the "a"

If I also also swap the "width" and "lsb" attributes in the htmx table, the spacing gets a little better, but there's still some overlapping.

Here's the kicker. If I convert the ttf font to an otf, and then repeat the exact same steps, the the spacing is perfect!

Denis Jacquerye

unread,
Apr 23, 2019, 6:01:25 AM4/23/19
to cmw4...@gmail.com, fonttools
On Tue, 23 Apr 2019 at 08:16, <cmw4...@gmail.com> wrote:
On Monday, April 22, 2019 at 8:04:36 PM UTC-4, behdad wrote:
> It feels to me like you just need to shuffle the cmap table...
>
>

That gets me 90% there for TTF font files. I still run into spacing issues. Some of the characters are displayed too close or completely overlap.

For instance, using the ttf font referenced above, replace "uni030C" (COMBINING CARON 0x30c) with "s" (LATIN SMALL LETTER S 0x73) in the cmap tables.
Now, if you type "̌ a", you would expect to see "sa". However, the "s" completely overlaps the "a"

If I also also swap the "width" and "lsb" attributes in the htmx table, the spacing gets a little better, but there's still some overlapping.

Here's the kicker. If I convert the ttf font to an otf, and then repeat the exact same steps, the the spacing is perfect!


You can shuffe sets of the cmap.
Use fontTools.unicodedata.combining(chr) (to get the combining class of chr) or fontTools.unicodedata.category(chr) to create those sets.
For example don’t shuffle the combining marks (any combining class != 0) with the letters and symbols (combining class == 0).

cmw4...@gmail.com

unread,
May 2, 2019, 12:37:34 AM5/2/19
to fonttools
Thanks Denis! This is very helpful.
Reply all
Reply to author
Forward
0 new messages