Search code examples
phpfontsserver-sideopentypetruetype

Font-File manipulation with PHP


I'm looking fore a way to manipulate a font file with php (or something else on server side). I want want to reassociate the path for a letter with a different letter.

Lets say we have a association like this:

  • Path 1 defines the look of U+0041 (A)
  • Path 2 defines the look of U+0042 (B)

I now want wo to chance the definition:

  • Path 2 defines the look of U+0041 (A)
  • Path 1 defines the look of U+0042 (B)

So when someone uses the font and enters an "A" a "B" is actually shown.

I already managed to chance this manually with the software Glyphs. Then i tried to trace the chance with a hex editor, but could really find no correlation. Its also really hard for me to understand the file format definition (using .otf at the moment). So, does someone have a starting point? At the moment i am back to beginning.


Solution

  • Recommendation: run the font through the python tool TTX instead. Convert the font to TTX xml form, trivially swap the TTFGlyph elements for those points, then run it back through TTX to form a new TTF, done.

    If you were trying to look to effect that using a hex editor for OpenType with CFF: that's probably a bad idea. For OpenType with TrueType data, it requires updating the cmap; for OpenType with CFF, it requires updating the CFF block as well, which is a hell of a lot more work.