]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/FTFont.cc
disable font embedding hack introduced on 2002-12-09 to fix build with
[evince.git] / pdf / xpdf / FTFont.cc
1 //========================================================================
2 //
3 // FTFont.cc
4 //
5 // Copyright 2001-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #ifdef __GNUC__
10 #pragma implementation
11 #endif
12
13 #include <aconf.h>
14
15 #if FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)
16
17 #include <math.h>
18 #include <string.h>
19 #include "gmem.h"
20 #include "freetype/ftoutln.h"
21 #include "freetype/internal/ftobjs.h"
22 #if 1 //~ cff cid->gid map
23 #include "freetype/internal/cfftypes.h"
24 #include "freetype/internal/tttypes.h"
25 #endif
26 #include "GlobalParams.h"
27 #include "GfxState.h"
28 #include "FTFont.h"
29
30 //------------------------------------------------------------------------
31
32 FTFontEngine::FTFontEngine(Display *displayA, Visual *visualA, int depthA,
33                            Colormap colormapA, GBool aaA):
34   SFontEngine(displayA, visualA, depthA, colormapA) {
35
36   ok = gFalse;
37   if (FT_Init_FreeType(&lib)) {
38     return;
39   }
40   aa = aaA;
41   ok = gTrue;
42 }
43
44 FTFontEngine::~FTFontEngine() {
45   FT_Done_FreeType(lib);
46 }
47
48 //------------------------------------------------------------------------
49
50 FTFontFile::FTFontFile(FTFontEngine *engineA, char *fontFileName,
51                        char **fontEnc, GBool pdfFontHasEncoding) {
52   char *name;
53   int unicodeCmap, macRomanCmap, msSymbolCmap;
54   int i, j;
55
56   ok = gFalse;
57   engine = engineA;
58   codeMap = NULL;
59   if (FT_New_Face(engine->lib, fontFileName, 0, &face)) {
60     return;
61   }
62
63   if (!strcmp(face->driver->root.clazz->module_name, "type1") ||
64       !strcmp(face->driver->root.clazz->module_name, "cff")) {
65
66     mode = ftFontModeCodeMapDirect;
67     codeMap = (Guint *)gmalloc(256 * sizeof(Guint));
68     for (i = 0; i < 256; ++i) {
69       codeMap[i] = 0;
70       if ((name = fontEnc[i])) {
71         codeMap[i] = FT_Get_Name_Index(face, name);
72       }
73     }
74
75   } else {
76
77     // To match up with the Adobe-defined behaviour, we choose a cmap
78     // like this:
79     // 1. If the PDF font has an encoding:
80     //    1a. If the TrueType font has a Microsoft Unicode cmap, use it,
81     //        and use the Unicode indexes, not the char codes.
82     //    1b. If the TrueType font has a Macintosh Roman cmap, use it,
83     //        and reverse map the char names through MacRomanEncoding to
84     //        get char codes.
85     // 2. If the PDF font does not have an encoding:
86     //    2a. If the TrueType font has a Macintosh Roman cmap, use it,
87     //        and use char codes directly.
88     //    2b. If the TrueType font has a Microsoft Symbol cmap, use it,
89     //        and use (0xf000 + char code).
90     // 3. If none of these rules apply, use the first cmap and hope for
91     //    the best (this shouldn't happen).
92     unicodeCmap = macRomanCmap = msSymbolCmap = 0xffff;
93     for (i = 0; i < face->num_charmaps; ++i) {
94       if (face->charmaps[i]->platform_id == 3 &&
95           face->charmaps[i]->encoding_id == 1) {
96         unicodeCmap = i;
97       } else if (face->charmaps[i]->platform_id == 1 &&
98                  face->charmaps[i]->encoding_id == 0) {
99         macRomanCmap = i;
100       } else if (face->charmaps[i]->platform_id == 3 &&
101                  face->charmaps[i]->encoding_id == 0) {
102         msSymbolCmap = i;
103       }
104     }
105     i = 0;
106     mode = ftFontModeCharCode;
107     charMapOffset = 0;
108     if (pdfFontHasEncoding) {
109       if (unicodeCmap != 0xffff) {
110         i = unicodeCmap;
111         mode = ftFontModeUnicode;
112       } else if (macRomanCmap != 0xffff) {
113         i = macRomanCmap;
114         mode = ftFontModeCodeMap;
115         codeMap = (Guint *)gmalloc(256 * sizeof(Guint));
116         for (j = 0; j < 256; ++j) {
117           if (fontEnc[j]) {
118             codeMap[j] = globalParams->getMacRomanCharCode(fontEnc[j]);
119           } else {
120             codeMap[j] = 0;
121           }
122         }
123       }
124     } else {
125       if (macRomanCmap != 0xffff) {
126         i = macRomanCmap;
127         mode = ftFontModeCharCode;
128       } else if (msSymbolCmap != 0xffff) {
129         i = msSymbolCmap;
130         mode = ftFontModeCharCodeOffset;
131         charMapOffset = 0xf000;
132       }
133     }
134     if (FT_Set_Charmap(face, face->charmaps[i])) {
135       return;
136     }
137   }
138
139   ok = gTrue;
140 }
141
142 FTFontFile::FTFontFile(FTFontEngine *engineA, char *fontFileName,
143                        Gushort *cidToGIDA, int cidToGIDLenA) {
144   ok = gFalse;
145   engine = engineA;
146   codeMap = NULL;
147   if (FT_New_Face(engine->lib, fontFileName, 0, &face)) {
148     return;
149   }
150   cidToGID = cidToGIDA;
151   cidToGIDLen = cidToGIDLenA;
152   mode = ftFontModeCIDToGIDMap;
153   ok = gTrue;
154 }
155
156 FTFontFile::FTFontFile(FTFontEngine *engineA, char *fontFileName) {
157   ok = gFalse;
158   engine = engineA;
159   codeMap = NULL;
160   if (FT_New_Face(engine->lib, fontFileName, 0, &face)) {
161     return;
162   }
163   cidToGID = NULL;
164   cidToGIDLen = 0;
165   mode = ftFontModeCFFCharset;
166   ok = gTrue;
167 }
168
169 FTFontFile::~FTFontFile() {
170   if (face) {
171     FT_Done_Face(face);
172   }
173   if (codeMap) {
174     gfree(codeMap);
175   }
176 }
177
178 //------------------------------------------------------------------------
179
180 FTFont::FTFont(FTFontFile *fontFileA, double *m) {
181   FTFontEngine *engine;
182   FT_Face face;
183   double size, div;
184   int x, xMin, xMax;
185   int y, yMin, yMax;
186   int i;
187
188   ok = gFalse;
189   fontFile = fontFileA;
190   engine = fontFile->engine;
191   face = fontFile->face;
192   if (FT_New_Size(face, &sizeObj)) {
193     return;
194   }
195   face->size = sizeObj;
196   size = sqrt(m[2]*m[2] + m[3]*m[3]);
197   if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
198     return;
199   }
200
201   div = face->bbox.xMax > 20000 ? 65536 : 1;
202
203   // transform the four corners of the font bounding box -- the min
204   // and max values form the bounding box of the transformed font
205   x = (int)((m[0] * face->bbox.xMin + m[2] * face->bbox.yMin) /
206             (div * face->units_per_EM));
207   xMin = xMax = x;
208   y = (int)((m[1] * face->bbox.xMin + m[3] * face->bbox.yMin) /
209             (div * face->units_per_EM));
210   yMin = yMax = y;
211   x = (int)((m[0] * face->bbox.xMin + m[2] * face->bbox.yMax) /
212             (div * face->units_per_EM));
213   if (x < xMin) {
214     xMin = x;
215   } else if (x > xMax) {
216     xMax = x;
217   }
218   y = (int)((m[1] * face->bbox.xMin + m[3] * face->bbox.yMax) /
219             (div * face->units_per_EM));
220   if (y < yMin) {
221     yMin = y;
222   } else if (y > yMax) {
223     yMax = y;
224   }
225   x = (int)((m[0] * face->bbox.xMax + m[2] * face->bbox.yMin) /
226             (div * face->units_per_EM));
227   if (x < xMin) {
228     xMin = x;
229   } else if (x > xMax) {
230     xMax = x;
231   }
232   y = (int)((m[1] * face->bbox.xMax + m[3] * face->bbox.yMin) /
233             (div * face->units_per_EM));
234   if (y < yMin) {
235     yMin = y;
236   } else if (y > yMax) {
237     yMax = y;
238   }
239   x = (int)((m[0] * face->bbox.xMax + m[2] * face->bbox.yMax) /
240             (div * face->units_per_EM));
241   if (x < xMin) {
242     xMin = x;
243   } else if (x > xMax) {
244     xMax = x;
245   }
246   y = (int)((m[1] * face->bbox.xMax + m[3] * face->bbox.yMax) /
247             (div * face->units_per_EM));
248   if (y < yMin) {
249     yMin = y;
250   } else if (y > yMax) {
251     yMax = y;
252   }
253   // This is a kludge: some buggy PDF generators embed fonts with
254   // zero bounding boxes.
255   if (xMax == xMin) {
256     xMin = 0;
257     xMax = (int)size;
258   }
259   if (yMax == yMin) {
260     yMin = 0;
261     yMax = (int)(1.2 * size);
262   }
263   // this should be (max - min + 1), but we add some padding to
264   // deal with rounding errors
265   glyphW = xMax - xMin + 3;
266   glyphH = yMax - yMin + 3;
267   // another kludge: some CJK TT fonts have bogus bboxes, so add more
268   // padding
269   if (face->num_glyphs > 1000) {
270     glyphW += glyphW >> 1;
271     glyphH += glyphH >> 1;
272   }
273   if (engine->aa) {
274     glyphSize = glyphW * glyphH;
275   } else {
276     glyphSize = ((glyphW + 7) >> 3) * glyphH;
277   }
278
279   // set up the glyph pixmap cache
280   cacheAssoc = 8;
281   if (glyphSize <= 256) {
282     cacheSets = 8;
283   } else if (glyphSize <= 512) {
284     cacheSets = 4;
285   } else if (glyphSize <= 1024) {
286     cacheSets = 2;
287   } else {
288     cacheSets = 1;
289   }
290   cache = (Guchar *)gmalloc(cacheSets * cacheAssoc * glyphSize);
291   cacheTags = (FTFontCacheTag *)gmalloc(cacheSets * cacheAssoc *
292                                         sizeof(FTFontCacheTag));
293   for (i = 0; i < cacheSets * cacheAssoc; ++i) {
294     cacheTags[i].mru = i & (cacheAssoc - 1);
295   }
296
297   // create the XImage
298   if (!(image = XCreateImage(engine->display, engine->visual, engine->depth,
299                              ZPixmap, 0, NULL, glyphW, glyphH, 8, 0))) {
300     return;
301   }
302   image->data = (char *)gmalloc(glyphH * image->bytes_per_line);
303
304   // compute the transform matrix
305   matrix.xx = (FT_Fixed)((m[0] / size) * 65536);
306   matrix.yx = (FT_Fixed)((m[1] / size) * 65536);
307   matrix.xy = (FT_Fixed)((m[2] / size) * 65536);
308   matrix.yy = (FT_Fixed)((m[3] / size) * 65536);
309
310   ok = gTrue;
311 }
312
313 FTFont::~FTFont() {
314   gfree(cacheTags);
315   gfree(cache);
316   gfree(image->data);
317   image->data = NULL;
318   XDestroyImage(image);
319 }
320
321 GBool FTFont::drawChar(Drawable d, int w, int h, GC gc,
322                        int x, int y, int r, int g, int b,
323                        CharCode c, Unicode u) {
324   FTFontEngine *engine;
325   XColor xcolor;
326   int bgR, bgG, bgB;
327   Gulong colors[5];
328   Guchar *p;
329   int pix;
330   int xOffset, yOffset, x0, y0, x1, y1, gw, gh, w0, h0;
331   int xx, yy, xx1;
332
333   engine = fontFile->engine;
334
335   // no Unicode index for this char - don't draw anything
336   if (fontFile->mode == ftFontModeUnicode && u == 0) {
337     return gFalse;
338   }
339
340   // generate the glyph pixmap
341   if (!(p = getGlyphPixmap(c, u, &xOffset, &yOffset, &gw, &gh))) {
342     return gFalse;
343   }
344
345   // compute: (x0,y0) = position in destination drawable
346   //          (x1,y1) = position in glyph image
347   //          (w0,h0) = size of image transfer
348   x0 = x - xOffset;
349   y0 = y - yOffset;
350   x1 = 0;
351   y1 = 0;
352   w0 = gw;
353   h0 = gh;
354   if (x0 < 0) {
355     x1 = -x0;
356     w0 += x0;
357     x0 = 0;
358   }
359   if (x0 + w0 > w) {
360     w0 = w - x0;
361   }
362   if (w0 < 0) {
363     return gTrue;
364   }
365   if (y0 < 0) {
366     y1 = -y0;
367     h0 += y0;
368     y0 = 0;
369   }
370   if (y0 + h0 > h) {
371     h0 = h - y0;
372   }
373   if (h0 < 0) {
374     return gTrue;
375   }
376
377   // read the X image
378   XGetSubImage(engine->display, d, x0, y0, w0, h0, (1 << engine->depth) - 1,
379                ZPixmap, image, x1, y1);
380
381   if (engine->aa) {
382
383     // compute the colors
384     xcolor.pixel = XGetPixel(image, x1 + w0/2, y1 + h0/2);
385     XQueryColor(engine->display, engine->colormap, &xcolor);
386     bgR = xcolor.red;
387     bgG = xcolor.green;
388     bgB = xcolor.blue;
389     colors[1] = engine->findColor((r + 3*bgR) / 4,
390                                   (g + 3*bgG) / 4,
391                                   (b + 3*bgB) / 4);
392     colors[2] = engine->findColor((r + bgR) / 2,
393                                   (g + bgG) / 2,
394                                   (b + bgB) / 2);
395     colors[3] = engine->findColor((3*r + bgR) / 4,
396                                   (3*g + bgG) / 4,
397                                   (3*b + bgB) / 4);
398     colors[4] = engine->findColor(r, g, b);
399
400     // stuff the glyph pixmap into the X image
401     for (yy = 0; yy < gh; ++yy) {
402       for (xx = 0; xx < gw; ++xx) {
403         pix = *p++ & 0xff;
404         // this is a heuristic which seems to produce decent
405         // results -- the linear mapping would be:
406         // pix = (pix * 5) / 256;
407         pix = ((pix + 10) * 5) / 256;
408         if (pix > 4) {
409           pix = 4;
410         }
411         if (pix > 0) {
412           XPutPixel(image, xx, yy, colors[pix]);
413         }
414       }
415     }
416
417   } else {
418
419     // one color
420     colors[1] = engine->findColor(r, g, b);
421
422     // stuff the glyph bitmap into the X image
423     for (yy = 0; yy < gh; ++yy) {
424       for (xx = 0; xx < gw; xx += 8) {
425         pix = *p++;
426         for (xx1 = xx; xx1 < xx + 8 && xx1 < gw; ++xx1) {
427           if (pix & 0x80) {
428             XPutPixel(image, xx1, yy, colors[1]);
429           }
430           pix <<= 1;
431         }
432       }
433     }
434
435   }
436
437   // draw the X image
438   XPutImage(engine->display, d, gc, image, x1, y1, x0, y0, w0, h0);
439
440   return gTrue;
441 }
442
443 Guchar *FTFont::getGlyphPixmap(CharCode c, Unicode u,
444                                int *x, int *y, int *w, int *h) {
445   FT_GlyphSlot slot;
446   FT_UInt idx;
447   int gSize;
448   int i, j, k;
449   Guchar *ret;
450
451   // check the cache
452   i = (c & (cacheSets - 1)) * cacheAssoc;
453   for (j = 0; j < cacheAssoc; ++j) {
454     if ((cacheTags[i+j].mru & 0x8000) && cacheTags[i+j].code == c) {
455       *x = cacheTags[i+j].x;
456       *y = cacheTags[i+j].y;
457       *w = cacheTags[i+j].w;
458       *h = cacheTags[i+j].h;
459       for (k = 0; k < cacheAssoc; ++k) {
460         if (k != j &&
461             (cacheTags[i+k].mru & 0x7fff) < (cacheTags[i+j].mru & 0x7fff)) {
462           ++cacheTags[i+k].mru;
463         }
464       }
465       cacheTags[i+j].mru = 0x8000;
466       return cache + (i+j) * glyphSize;
467     }
468   }
469
470   // generate the glyph pixmap or bitmap
471   fontFile->face->size = sizeObj;
472   FT_Set_Transform(fontFile->face, &matrix, NULL);
473   slot = fontFile->face->glyph;
474   idx = getGlyphIndex(c, u);
475   // if we have the FT2 bytecode interpreter, autohinting won't be used
476 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
477   if (FT_Load_Glyph(fontFile->face, idx, FT_LOAD_DEFAULT)) {
478     return gFalse;
479   }
480 #else
481   // FT2's autohinting doesn't always work very well (especially with
482   // font subsets), so turn it off if anti-aliasing is enabled; if
483   // anti-aliasing is disabled, this seems to be a tossup - some fonts
484   // look better with hinting, some without, so leave hinting on
485   if (FT_Load_Glyph(fontFile->face, idx,
486                     fontFile->engine->aa ? FT_LOAD_NO_HINTING
487                                          : FT_LOAD_DEFAULT)) {
488     return gFalse;
489   }
490 #endif
491   if (FT_Render_Glyph(slot,
492                       fontFile->engine->aa ? ft_render_mode_normal :
493                                              ft_render_mode_mono)) {
494     return gFalse;
495   }
496   *x = -slot->bitmap_left;
497   *y = slot->bitmap_top;
498   *w = slot->bitmap.width;
499   *h = slot->bitmap.rows;
500   if (*w > glyphW || *h > glyphH) {
501 #if 1 //~ debug
502     fprintf(stderr, "Weird FreeType glyph size: %d > %d or %d > %d\n",
503             *w, glyphW, *h, glyphH);
504 #endif
505     return NULL;
506   }
507
508   // store glyph pixmap in cache
509   ret = NULL;
510   for (j = 0; j < cacheAssoc; ++j) {
511     if ((cacheTags[i+j].mru & 0x7fff) == cacheAssoc - 1) {
512       cacheTags[i+j].mru = 0x8000;
513       cacheTags[i+j].code = c;
514       cacheTags[i+j].x = *x;
515       cacheTags[i+j].y = *y;
516       cacheTags[i+j].w = *w;
517       cacheTags[i+j].h = *h;
518       if (fontFile->engine->aa) {
519         gSize = *w * *h;
520       } else {
521         gSize = ((*w + 7) >> 3) * *h;
522       }
523       ret = cache + (i+j) * glyphSize;
524       memcpy(ret, slot->bitmap.buffer, gSize);
525     } else {
526       ++cacheTags[i+j].mru;
527     }
528   }
529   return ret;
530 }
531
532 GBool FTFont::getCharPath(CharCode c, Unicode u, GfxState *state) {
533   static FT_Outline_Funcs outlineFuncs = {
534     &charPathMoveTo,
535     &charPathLineTo,
536     &charPathConicTo,
537     &charPathCubicTo,
538     0, 0
539   };
540   FT_GlyphSlot slot;
541   FT_UInt idx;
542   FT_Glyph glyph;
543
544   fontFile->face->size = sizeObj;
545   FT_Set_Transform(fontFile->face, &matrix, NULL);
546   slot = fontFile->face->glyph;
547   idx = getGlyphIndex(c, u);
548 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
549   if (FT_Load_Glyph(fontFile->face, idx, FT_LOAD_DEFAULT)) {
550     return gFalse;
551   }
552 #else
553   // FT2's autohinting doesn't always work very well (especially with
554   // font subsets), so turn it off if anti-aliasing is enabled; if
555   // anti-aliasing is disabled, this seems to be a tossup - some fonts
556   // look better with hinting, some without, so leave hinting on
557   if (FT_Load_Glyph(fontFile->face, idx,
558                     fontFile->engine->aa ? FT_LOAD_NO_HINTING
559                                          : FT_LOAD_DEFAULT)) {
560     return gFalse;
561   }
562 #endif
563   if (FT_Get_Glyph(slot, &glyph)) {
564     return gFalse;
565   }
566   FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
567                        &outlineFuncs, state);
568   return gTrue;
569 }
570
571 int FTFont::charPathMoveTo(FT_Vector *pt, void *state) {
572   ((GfxState *)state)->moveTo(pt->x / 64.0, -pt->y / 64.0);
573   return 0;
574 }
575
576 int FTFont::charPathLineTo(FT_Vector *pt, void *state) {
577   ((GfxState *)state)->lineTo(pt->x / 64.0, -pt->y / 64.0);
578   return 0;
579 }
580
581 int FTFont::charPathConicTo(FT_Vector *ctrl, FT_Vector *pt, void *state) {
582   double x0, y0, x1, y1, x2, y2, x3, y3, xc, yc;
583
584   x0 = ((GfxState *)state)->getCurX();
585   y0 = ((GfxState *)state)->getCurY();
586   xc = ctrl->x / 64.0;
587   yc = -ctrl->y / 64.0;
588   x3 = pt->x / 64.0;
589   y3 = -pt->y / 64.0;
590
591   // A second-order Bezier curve is defined by two endpoints, p0 and
592   // p3, and one control point, pc:
593   //
594   //     p(t) = (1-t)^2*p0 + t*(1-t)*pc + t^2*p3
595   //
596   // A third-order Bezier curve is defined by the same two endpoints,
597   // p0 and p3, and two control points, p1 and p2:
598   //
599   //     p(t) = (1-t)^3*p0 + 3t*(1-t)^2*p1 + 3t^2*(1-t)*p2 + t^3*p3
600   //
601   // Applying some algebra, we can convert a second-order curve to a
602   // third-order curve:
603   //
604   //     p1 = (1/3) * (p0 + 2pc)
605   //     p2 = (1/3) * (2pc + p3)
606
607   x1 = (1.0 / 3.0) * (x0 + 2 * xc);
608   y1 = (1.0 / 3.0) * (y0 + 2 * yc);
609   x2 = (1.0 / 3.0) * (2 * xc + x3);
610   y2 = (1.0 / 3.0) * (2 * yc + y3);
611
612   ((GfxState *)state)->curveTo(x1, y1, x2, y2, x3, y3);
613   return 0;
614 }
615
616 int FTFont::charPathCubicTo(FT_Vector *ctrl1, FT_Vector *ctrl2,
617                             FT_Vector *pt, void *state) {
618   ((GfxState *)state)->curveTo(ctrl1->x / 64.0, -ctrl1->y / 64.0,
619                                ctrl2->x / 64.0, -ctrl2->y / 64.0,
620                                pt->x / 64.0, -pt->y / 64.0);
621   return 0;
622 }
623
624 FT_UInt FTFont::getGlyphIndex(CharCode c, Unicode u) {
625   FT_UInt idx;
626   int j;
627
628   idx = 0; // make gcc happy
629   switch (fontFile->mode) {
630   case ftFontModeUnicode:
631     idx = FT_Get_Char_Index(fontFile->face, (FT_ULong)u);
632     break;
633   case ftFontModeCharCode:
634     idx = FT_Get_Char_Index(fontFile->face, (FT_ULong)c);
635     break;
636   case ftFontModeCharCodeOffset:
637     idx = FT_Get_Char_Index(fontFile->face,
638                             (FT_ULong)(c + fontFile->charMapOffset));
639     break;
640   case ftFontModeCodeMap:
641     if (c <= 0xff) {
642       idx = FT_Get_Char_Index(fontFile->face, (FT_ULong)fontFile->codeMap[c]);
643     } else {
644       idx = 0;
645     }
646     break;
647   case ftFontModeCodeMapDirect:
648     if (c <= 0xff) {
649       idx = (FT_UInt)fontFile->codeMap[c];
650     } else {
651       idx = 0;
652     }
653     break;
654   case ftFontModeCIDToGIDMap:
655     if (fontFile->cidToGIDLen) {
656       if ((int)c < fontFile->cidToGIDLen) {
657         idx = (FT_UInt)fontFile->cidToGID[c];
658       } else {
659         idx = (FT_UInt)0;
660       }
661     } else {
662       idx = (FT_UInt)c;
663     }
664     break;
665   case ftFontModeCFFCharset:
666 #if 1 //~ cff cid->gid map
667 #if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 0
668     CFF_Font *cff = (CFF_Font *)((TT_Face)fontFile->face)->extra.data;
669 #else
670     CFF_Font cff = (CFF_Font)((TT_Face)fontFile->face)->extra.data;
671 #endif
672     idx = 0;
673     for (j = 0; j < (int)cff->num_glyphs; ++j) {
674       if (cff->charset.sids[j] == c) {
675         idx = j;
676         break;
677       }
678     }
679 #endif
680     break;
681   }
682   return idx;
683 }
684
685 #endif // FREETYPE2 && (HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H)