Simplifying CIDFont Glyph Corrections Using AFDKO Tools

The process of building a CIDFont resource, which serves as the source file for the ‘CFF‘ table of a CID-keyed OpenType/CFF font, usually entails “rolling up” or combining two or more name-keyed fonts into a larger CID-keyed one. Depending on which tools are used to build the CIDFont resource, fixing glyphs can become a cumbersome or time-consuming task. First, you need to map the CID to a glyph name in the name-keyed source fonts, and if you are fixing multiple glyphs, you may need to modify more than one name-keyed source font. Many font developers are not aware that some AFDKO tools, such as tx, mergeFonts, sfntedit, and autohint, can simplify this process, if used appropriately.

To demonstrate this, I will modify two glyphs in KozGoPr6N-Medium, which is an Adobe-Japan1-6 OpenType/CFF font that includes 23,058 glyphs (CIDs 0 through 23057). The two glyphs that will be modified are CIDs 26 (9; U+0039) and 1200 (一; U+4E00). Below is a glyph synopsis as generated by tx (using tx -pdf -g 26,1200 KozGoPr6N-Medium.otf cids26+1200.pdf):

The first step is to extract the two glyphs as a name-keyed font. If all glyphs being extracted belong to the same FDArray element (aka, hint dictionary), the following tx command line will work:

% tx -t1 -decid -g 26,1200 KozGoPr6N-Medium.otf fix.pfa

But, in this case, CID+26 is assigned to FDArray element 12, and CID+1200 is assigned to FDArray element 11. This can be confirmed using the following tx command line:

% tx -1 -g 26,1200 KozGoPr6N-Medium.otf

Below is the output that matters:

## glyph[tag] {cid,iFD,LanguageGroup}
glyph[26] {26,12,0}
glyph[1200] {1200,11,1}

In this particular case, the “-usefd” option and an FDArray index must be specified. I usually specify 0 as the FDArray index, because for the purposes of fixing glyphs, it doesn’t matter. Here is the tx command line:

% tx -t1 -decid -usefd 0 -g 26,1200 KozGoPr6N-Medium.otf fix.pfa

This produces a three-glyph name-keyed Type 1 font with the following glyph names:

.notdef
cid26
cid1200

Now, simply use your favorite font editor, such as FontLab Studio, to make adjustments to the glyphs. For demonstration purposes, to make the changes obvious, I mirrored (along the horizontal axis) the glyph for CID+26, and rotated (90 degrees) the glyph for CID+1200. When done making adjustments, simply generate a Type 1 font. For FontLab Studio, I suggest the “ASCII/UNIX Type 1” output option. I used fix-new.pfa as the name of this name-keyed font.

The next step involves converting the name-keyed font into a CID-keyed font. The first step it to prepare appropriate mergeFonts mapping files. One is required per FDArray element. For this example, I created mapping files named prop.map and kanji.prop, with the following contents, respectively:

mergeFonts KozGoPr6N-Medium-Proportional 0
0 .notdef
26 cid26

mergeFonts KozGoPr6N-Medium-Kanji 1
1200 cid1200

Note that I specified the FDArray element name (that matches that used in the original CID-keyed font) and the LanguageGroup as arguments to “mergeFonts.” Also note that at least one of the mapping files must map a glyph to CID+0. These mapping files simply convert glyphs that are named according to CIDs into their respective CIDs.

Assuming that the modified name-keyed font is named fix-new.pfa, below is the command line to use:

% mergeFonts -cid cidfontinfo cidfont-26+1200.ps prop.map fix-new.pfa kanji.map fix-new.pfa

This produces a three-glyph CIDFont resource named cidfont-26+1200.ps with the following CIDs:

0
26
1200

Injecting these two modified glyphs into the original font is simple, and involves the following tx and mergeFonts command lines:

% tx -t1 KozGoPr6N-Medium.otf cidfont.orig
% mergeFonts cidfont.ps cidfont-26+1200.ps cidfont.orig

The first command line converts the ‘CFF’ table of the OpenType/CFF font into a CIDFont resource named cidfont.orig. (When using mergeFonts in this way, you cannot mix charstring types, hence the need for this command line; CFF uses Type 2, and CIDFont resources use Type 1.) The second command line merges the glyphs of both CIDFont resources, cidfont-26+1200.ps and cidfont.orig, into a single CIDFont resource named cidfont.ps. IMPORTANT: The mergeFonts tool employs “the first one wins” principle when two (or more) source fonts include a glyph with the same name (for name-keyed fonts) or CID (for CID-keyed fonts). In other words, the order of the source fonts, cidfont-26+1200.ps cidfont.orig, in the command line is important. Reversing them would have the effect of ignoring the glyphs in cidfont-26+1200.ps.

The last step is to convert the CIDFont resource back into CFF using tx, optionally hinting it using autohint, and replacing the ‘CFF’ table with the new version using sfntedit:

% tx -cff cidfont.ps CFF
% autohint -a -r CFF
% sfntedit -a CFF=CFF KozGoPr6N-Medium.otf
% sfntedit -f KozGoPr6N-Medium.otf

Finally, the glyph synopsis below shows the modified glyphs:

Note that the FDArray element index has changed, but that is okay, because all of the other glyphs that belong to the same FDArray element also changed in terms of their index. The mergeFonts tool manages this.

As you can see, modifying glyphs and reinserting them into a CID-keyed OpenType/CFF font is relatively easy, and as mentioned in previous blog posts, the technique scales very easily, when the number of glyphs being modified is greater.

Comments are closed.