]> www.fi.muni.cz Git - evince.git/blob - pdf/splash/SplashFTFontEngine.cc
added.
[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 ((ff = FoFiType1C::load(fileName))) {
85     cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
86     delete ff;
87   } else {
88     cidToGIDMap = NULL;
89     nCIDs = 0;
90   }
91   ret = SplashFTFontFile::loadCIDFont(this, idA, fileName, deleteFile,
92                                       cidToGIDMap, nCIDs);
93   if (!ret) {
94     gfree(cidToGIDMap);
95   }
96   return ret;
97 }
98
99 SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
100                                                      char *fileName,
101                                                      GBool deleteFile,
102                                                      Gushort *codeToGID,
103                                                      int codeToGIDLen) {
104   FoFiTrueType *ff;
105   GString *tmpFileName;
106   FILE *tmpFile;
107   SplashFontFile *ret;
108
109   if (!(ff = FoFiTrueType::load(fileName))) {
110     return NULL;
111   }
112   tmpFileName = NULL;
113   if (!openTempFile(&tmpFileName, &tmpFile, "wb", NULL)) {
114     delete ff;
115     return NULL;
116   }
117   ff->writeTTF(&fileWrite, tmpFile);
118   delete ff;
119   fclose(tmpFile);
120   ret = SplashFTFontFile::loadTrueTypeFont(this, idA,
121                                            tmpFileName->getCString(),
122                                            gTrue, codeToGID, codeToGIDLen);
123   if (ret) {
124     if (deleteFile) {
125       unlink(fileName);
126     }
127   } else {
128     unlink(tmpFileName->getCString());
129   }
130   delete tmpFileName;
131   return ret;
132 }
133
134 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H