]> www.fi.muni.cz Git - evince.git/blob - pdf/splash/SplashFTFontEngine.cc
Fix several bugs with find
[evince.git] / pdf / splash / SplashFTFontEngine.cc
1 //========================================================================
2 //
3 // SplashFTFontEngine.cc
4 //
5 //========================================================================
6
7 #include <aconf.h>
8
9 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <stdio.h>
16 #ifndef WIN32
17 #  include <unistd.h>
18 #endif
19 #include "gmem.h"
20 #include "GString.h"
21 #include "gfile.h"
22 #include "FoFiTrueType.h"
23 #include "FoFiType1C.h"
24 #include "SplashFTFontFile.h"
25 #include "SplashFTFontEngine.h"
26
27 #ifdef VMS
28 #if (__VMS_VER < 70000000)
29 extern "C" int unlink(char *filename);
30 #endif
31 #endif
32
33 //------------------------------------------------------------------------
34
35 static void fileWrite(void *stream, char *data, int len) {
36   fwrite(data, 1, len, (FILE *)stream);
37 }
38
39 //------------------------------------------------------------------------
40 // SplashFTFontEngine
41 //------------------------------------------------------------------------
42
43 SplashFTFontEngine::SplashFTFontEngine(GBool aaA, FT_Library libA) {
44   aa = aaA;
45   lib = libA;
46 }
47
48 SplashFTFontEngine *SplashFTFontEngine::init(GBool aaA) {
49   FT_Library libA;
50
51   if (FT_Init_FreeType(&libA)) {
52     return NULL;
53   }
54   return new SplashFTFontEngine(aaA, libA);
55 }
56
57 SplashFTFontEngine::~SplashFTFontEngine() {
58   FT_Done_FreeType(lib);
59 }
60
61 SplashFontFile *SplashFTFontEngine::loadType1Font(SplashFontFileID *idA,
62                                                   char *fileName,
63                                                   GBool deleteFile,
64                                                   char **enc) {
65   return SplashFTFontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
66 }
67
68 SplashFontFile *SplashFTFontEngine::loadType1CFont(SplashFontFileID *idA,
69                                                    char *fileName,
70                                                    GBool deleteFile,
71                                                    char **enc) {
72   return SplashFTFontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
73 }
74
75 SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
76                                                 char *fileName,
77                                                 GBool deleteFile) {
78   FoFiType1C *ff;
79   Gushort *cidToGIDMap;
80   int nCIDs;
81   SplashFontFile *ret;
82
83   // check for a CFF font
84 #if HAVE_FREETYPE_217_OR_OLDER
85   if ((ff = FoFiType1C::load(fileName))) {
86     cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
87     delete ff;
88   } else {
89     cidToGIDMap = NULL;
90     nCIDs = 0;
91   }
92 #else
93   // No need to check for CFF Font, freetype treats all CID fonts the same way
94   cidToGIDMap = NULL;
95   nCIDs = 0;
96 #endif
97
98   ret = SplashFTFontFile::loadCIDFont(this, idA, fileName, deleteFile,
99                                       cidToGIDMap, nCIDs);
100   if (!ret) {
101     gfree(cidToGIDMap);
102   }
103   return ret;
104 }
105
106 SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
107                                                      char *fileName,
108                                                      GBool deleteFile,
109                                                      Gushort *codeToGID,
110                                                      int codeToGIDLen) {
111   FoFiTrueType *ff;
112   GString *tmpFileName;
113   FILE *tmpFile;
114   SplashFontFile *ret;
115
116   if (!(ff = FoFiTrueType::load(fileName))) {
117     return NULL;
118   }
119   tmpFileName = NULL;
120   if (!openTempFile(&tmpFileName, &tmpFile, "wb", NULL)) {
121     delete ff;
122     return NULL;
123   }
124   ff->writeTTF(&fileWrite, tmpFile);
125   delete ff;
126   fclose(tmpFile);
127   ret = SplashFTFontFile::loadTrueTypeFont(this, idA,
128                                            tmpFileName->getCString(),
129                                            gTrue, codeToGID, codeToGIDLen);
130   if (ret) {
131     if (deleteFile) {
132       unlink(fileName);
133     }
134   } else {
135     unlink(tmpFileName->getCString());
136   }
137   delete tmpFileName;
138   return ret;
139 }
140
141 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H