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 //
16 // To see a description of the changes please see the Changelog file that
17 // came with your tarball or type make ChangeLog if you are building from git
18 //
19 //========================================================================
20
21 #include <config.h>
22
23 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
24
25 #ifdef USE_GCC_PRAGMAS
26 #pragma implementation
27 #endif
28
29 #include "goo/gmem.h"
30 #include "goo/GooString.h"
31 #include "SplashFTFontEngine.h"
32 #include "SplashFTFont.h"
33 #include "SplashFTFontFile.h"
34
35 //------------------------------------------------------------------------
36 // SplashFTFontFile
37 //------------------------------------------------------------------------
38
loadType1Font(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,char ** encA)39 SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
40 SplashFontFileID *idA,
41 SplashFontSrc *src,
42 char **encA) {
43 FT_Face faceA;
44 Gushort *codeToGIDA;
45 char *name;
46 int i;
47
48 if (src->isFile) {
49 if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
50 return NULL;
51 } else {
52 if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
53 return NULL;
54 }
55 codeToGIDA = (Gushort *)gmallocn(256, sizeof(int));
56 for (i = 0; i < 256; ++i) {
57 codeToGIDA[i] = 0;
58 if ((name = encA[i])) {
59 codeToGIDA[i] = (Gushort)FT_Get_Name_Index(faceA, name);
60 }
61 }
62
63 return new SplashFTFontFile(engineA, idA, src,
64 faceA, codeToGIDA, 256, gFalse);
65 }
66
loadCIDFont(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,Gushort * codeToGIDA,int codeToGIDLenA)67 SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA,
68 SplashFontFileID *idA,
69 SplashFontSrc *src,
70 Gushort *codeToGIDA,
71 int codeToGIDLenA) {
72 FT_Face faceA;
73
74 if (src->isFile) {
75 if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
76 return NULL;
77 } else {
78 if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
79 return NULL;
80 }
81
82 return new SplashFTFontFile(engineA, idA, src,
83 faceA, codeToGIDA, codeToGIDLenA, gFalse);
84 }
85
loadTrueTypeFont(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,Gushort * codeToGIDA,int codeToGIDLenA,int faceIndexA)86 SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
87 SplashFontFileID *idA,
88 SplashFontSrc *src,
89 Gushort *codeToGIDA,
90 int codeToGIDLenA,
91 int faceIndexA) {
92 FT_Face faceA;
93
94 if (src->isFile) {
95 if (FT_New_Face(engineA->lib, src->fileName->getCString(), faceIndexA, &faceA))
96 return NULL;
97 } else {
98 if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, faceIndexA, &faceA))
99 return NULL;
100 }
101
102 return new SplashFTFontFile(engineA, idA, src,
103 faceA, codeToGIDA, codeToGIDLenA, gTrue);
104 }
105
SplashFTFontFile(SplashFTFontEngine * engineA,SplashFontFileID * idA,SplashFontSrc * src,FT_Face faceA,Gushort * codeToGIDA,int codeToGIDLenA,GBool trueTypeA)106 SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA,
107 SplashFontFileID *idA,
108 SplashFontSrc *src,
109 FT_Face faceA,
110 Gushort *codeToGIDA, int codeToGIDLenA,
111 GBool trueTypeA):
112 SplashFontFile(idA, src)
113 {
114 engine = engineA;
115 face = faceA;
116 codeToGID = codeToGIDA;
117 codeToGIDLen = codeToGIDLenA;
118 trueType = trueTypeA;
119 }
120
~SplashFTFontFile()121 SplashFTFontFile::~SplashFTFontFile() {
122 if (face) {
123 FT_Done_Face(face);
124 }
125 if (codeToGID) {
126 gfree(codeToGID);
127 }
128 }
129
makeFont(SplashCoord * mat,SplashCoord * textMat)130 SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat,
131 SplashCoord *textMat) {
132 SplashFont *font;
133
134 font = new SplashFTFont(this, mat, textMat);
135 font->initCache();
136 return font;
137 }
138
139 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
140