- if ((pos = seekTable("cmap")) < 0) {
- goto err;
- }
-
- // To match up with the Adobe-defined behaviour, we choose a cmap
- // like this:
- // 1. If the PDF font has an encoding:
- // 1a. If the TrueType font has a Microsoft Unicode cmap, use it,
- // and use the Unicode indexes, not the char codes.
- // 1b. If the TrueType font has a Macintosh Roman cmap, use it,
- // and reverse map the char names through MacRomanEncoding to
- // get char codes.
- // 2. If the PDF font does not have an encoding:
- // 2a. If the TrueType font has a Macintosh Roman cmap, use it,
- // and use char codes directly.
- // 2b. If the TrueType font has a Microsoft Symbol cmap, use it,
- // and use (0xf000 + char code).
- // 3. If none of these rules apply, use the first cmap and hope for
- // the best (this shouldn't happen).
- nCmaps = getUShort(pos+2);
- unicodeCmap = macRomanCmap = msSymbolCmap = -1;
- cmapOffset = 0;
- for (i = 0; i < nCmaps; ++i) {
- cmapPlatform = getUShort(pos + 4 + 8*i);
- cmapEncoding = getUShort(pos + 4 + 8*i + 2);
- if (cmapPlatform == 3 && cmapEncoding == 1) {
- unicodeCmap = i;
- } else if (cmapPlatform == 1 && cmapEncoding == 0) {
- macRomanCmap = i;
- } else if (cmapPlatform == 3 && cmapEncoding == 0) {
- msSymbolCmap = i;
- }
- }
- i = 0;
- mode = t42FontModeCharCode;
- if (pdfFontHasEncoding) {
- if (unicodeCmap >= 0) {
- i = unicodeCmap;
- mode = t42FontModeUnicode;
- } else if (macRomanCmap >= 0) {
- i = macRomanCmap;
- mode = t42FontModeMacRoman;
- }
- } else {
- if (macRomanCmap >= 0) {
- i = macRomanCmap;
- mode = t42FontModeCharCode;
- } else if (msSymbolCmap >= 0) {
- i = msSymbolCmap;
- mode = t42FontModeCharCodeOffset;
- cmapOffset = 0xf000;
- }
- }
- cmapPlatform = getUShort(pos + 4 + 8*i);
- cmapEncoding = getUShort(pos + 4 + 8*i + 2);
- pos += getULong(pos + 4 + 8*i + 4);
- cmapFmt = getUShort(pos);
- if (cmapFmt != 0 && cmapFmt != 4 && cmapFmt != 6) {
- error(-1, "Unimplemented cmap format (%d) in TrueType font file",
- cmapFmt);