1 //========================================================================
2 //
3 // SplashFTFontFile.cc
4 //
5 //========================================================================
6 
7 //========================================================================
8 //
9 // Modified under the Poppler project - http://poppler.freedesktop.org
10 //
11 // All changes made under the Poppler project to this file are licensed
12 // under GPL version 2 or later
13 //
14 // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
15 // Copyright (C) 2014 Adrian Johnson <ajohnson@redneon.com>
16 //
17 // To see a description of the changes please see the Changelog file that
18 // came with your tarball or type make ChangeLog if you are building from git
19 //
20 //========================================================================
21 
22 #include <config.h>
23 
24 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
25 
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
28 #endif
29 
30 #include "goo/gmem.h"
31 #include "goo/GooString.h"
32 #include "poppler/GfxFont.h"
33 #include "SplashFTFontEngine.h"
34 #include "SplashFTFont.h"
35 #include "SplashFTFontFile.h"
36 
37 //------------------------------------------------------------------------
38 // SplashFTFontFile
39 //------------------------------------------------------------------------
40 
loadType1Font(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,const char ** encA)41 SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
42 						SplashFontFileID *idA,
43 						SplashFontSrc *src,
44 						const char **encA) {
45   FT_Face faceA;
46   int *codeToGIDA;
47   const char *name;
48   int i;
49 
50   if (src->isFile) {
51     if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
52       return NULL;
53   } else {
54     if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
55       return NULL;
56   }
57   codeToGIDA = (int *)gmallocn(256, sizeof(int));
58   for (i = 0; i < 256; ++i) {
59     codeToGIDA[i] = 0;
60     if ((name = encA[i])) {
61       codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);
62       if (codeToGIDA[i] == 0) {
63 	name = GfxFont::getAlternateName(name);
64 	if (name) {
65 	  codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name);
66 	}
67       }
68     }
69   }
70 
71   return new SplashFTFontFile(engineA, idA, src,
72 			      faceA, codeToGIDA, 256, gFalse, gTrue);
73 }
74 
loadCIDFont(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,int * codeToGIDA,int codeToGIDLenA)75 SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA,
76 					      SplashFontFileID *idA,
77 					      SplashFontSrc *src,
78 					      int *codeToGIDA,
79 					      int codeToGIDLenA) {
80   FT_Face faceA;
81 
82   if (src->isFile) {
83     if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
84       return NULL;
85   } else {
86     if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
87       return NULL;
88   }
89 
90   return new SplashFTFontFile(engineA, idA, src,
91 			      faceA, codeToGIDA, codeToGIDLenA, gFalse, gFalse);
92 }
93 
loadTrueTypeFont(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,int * codeToGIDA,int codeToGIDLenA,int faceIndexA)94 SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
95 						   SplashFontFileID *idA,
96 						   SplashFontSrc *src,
97 						   int *codeToGIDA,
98 						   int codeToGIDLenA,
99 						   int faceIndexA) {
100   FT_Face faceA;
101 
102   if (src->isFile) {
103     if (FT_New_Face(engineA->lib, src->fileName->getCString(), faceIndexA, &faceA))
104       return NULL;
105   } else {
106     if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, faceIndexA, &faceA))
107       return NULL;
108   }
109 
110   return new SplashFTFontFile(engineA, idA, src,
111 			      faceA, codeToGIDA, codeToGIDLenA, gTrue, gFalse);
112 }
113 
SplashFTFontFile(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,FT_Face faceA,int * codeToGIDA,int codeToGIDLenA,GBool trueTypeA,GBool type1A)114 SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA,
115 				   SplashFontFileID *idA,
116 				   SplashFontSrc *src,
117 				   FT_Face faceA,
118 				   int *codeToGIDA, int codeToGIDLenA,
119 				   GBool trueTypeA, GBool type1A):
120   SplashFontFile(idA, src)
121 {
122   engine = engineA;
123   face = faceA;
124   codeToGID = codeToGIDA;
125   codeToGIDLen = codeToGIDLenA;
126   trueType = trueTypeA;
127   type1 = type1A;
128 }
129 
~SplashFTFontFile()130 SplashFTFontFile::~SplashFTFontFile() {
131   if (face) {
132     FT_Done_Face(face);
133   }
134   if (codeToGID) {
135     gfree(codeToGID);
136   }
137 }
138 
makeFont(SplashCoord * mat,SplashCoord * textMat)139 SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat,
140 				       SplashCoord *textMat) {
141   SplashFont *font;
142 
143   font = new SplashFTFont(this, mat, textMat);
144   font->initCache();
145   return font;
146 }
147 
148 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
149