Search code examples
unicodefontsopentype

How can I substitute one glyph for another in an OpenType PostScript OTF font file?


I'm trying to use fonts from the Nitti Basic family for programming. These fonts are packaged as OpenType PostScript OTF files.

Its U+002D (HYPHEN-MINUS) glyph works well as a hyphen, but not so well as a minus. For example, it doesn't line up with the horizontal bar of the plus sign. On the other hand, Nitti's glyph for U+2212 (MINUS) is perfect as a minus (of course), and this is what I need when programming. It's not feasible for me to actually use codepoint U+2212; after all, U+002D is what you get when you press the minus sign on the keyboard and it's what programming languages use for subtraction.

So instead I'd like to steal the glyph from U+2212 and use it for U+002D, so that that character looks like a minus sign.

How can I do it?

Update: Yes, it is possible to use U+002D as a hyphen in source code. As mentioned above, a minus sign is what I need.


Solution

  • For posterity, here's how to do it:

    1. Obtain Adobe's AFDKO font tools and install them.

    2. Put the OTF files into an empty directory.

    3. Run ttx *.otf to convert the OTF files to TTX (XML).

    4. Edit each TTX file in a text editor:

      1. In the cmap section, change occurrences of hyphen to minus. This table maps characters to glyphs. Character U+002D was originally mapped to the hyphen glyph; this change maps it to the minus glyph.

      2. Over the whole file, change ocurrences of NittiBasic to NittiBasicM and Nitti Basic to Nitti Basic M. This will distinguish the modified version of the font from the original once it's installed.

    5. Rename the TTX files, replacing Nitti Basic with Nitti Basic M.

    6. Run ttx -b *.ttx to convert the TTX files back to OTF.

    7. Finally, install the newly-created OTF files.