]> www.fi.muni.cz Git - evince.git/blob - pdf/splash/SplashT1FontEngine.cc
a1c9342b195f6a5be448612f93f81c0153513899
[evince.git] / pdf / splash / SplashT1FontEngine.cc
1 //========================================================================
2 //
3 // SplashT1FontEngine.cc
4 //
5 //========================================================================
6
7 #include <aconf.h>
8
9 #if HAVE_T1LIB_H
10
11 #ifdef USE_GCC_PRAGMAS
12 #pragma implementation
13 #endif
14
15 #include <stdlib.h>
16 #include <stdio.h>
17 #ifndef WIN32
18 #  include <unistd.h>
19 #endif
20 #include <t1lib.h>
21 #include "GString.h"
22 #include "gfile.h"
23 #include "FoFiType1C.h"
24 #include "SplashT1FontFile.h"
25 #include "SplashT1FontEngine.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 int SplashT1FontEngine::t1libInitCount = 0;
36
37 //------------------------------------------------------------------------
38
39 static void fileWrite(void *stream, char *data, int len) {
40   fwrite(data, 1, len, (FILE *)stream);
41 }
42
43 //------------------------------------------------------------------------
44 // SplashT1FontEngine
45 //------------------------------------------------------------------------
46
47 SplashT1FontEngine::SplashT1FontEngine(GBool aaA) {
48   aa = aaA;
49 }
50
51 SplashT1FontEngine *SplashT1FontEngine::init(GBool aaA) {
52   // grayVals[i] = round(i * 255 / 16)
53   static unsigned long grayVals[17] = {
54     0, 16, 32, 48, 64, 80, 96, 112, 128, 143, 159, 175, 191, 207, 223, 239, 255
55   };
56
57   //~ for multithreading: need a mutex here
58   if (t1libInitCount == 0) {
59     T1_SetBitmapPad(8);
60     if (!T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE |
61                     T1_NO_AFM)) {
62       return NULL;
63     }
64     if (aaA) {
65       T1_AASetBitsPerPixel(8);
66       T1_AASetLevel(T1_AA_HIGH);
67       T1_AAHSetGrayValues(grayVals);
68     } else {
69       T1_AANSetGrayValues(0, 1);
70     }
71   }
72   ++t1libInitCount;
73
74   return new SplashT1FontEngine(aaA);
75 }
76
77 SplashT1FontEngine::~SplashT1FontEngine() {
78   //~ for multithreading: need a mutex here
79   if (--t1libInitCount == 0) {
80     T1_CloseLib();
81   }
82 }
83
84 SplashFontFile *SplashT1FontEngine::loadType1Font(SplashFontFileID *idA,
85                                                   char *fileName,
86                                                   GBool deleteFile,
87                                                   char **enc) {
88   return SplashT1FontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
89 }
90
91 SplashFontFile *SplashT1FontEngine::loadType1CFont(SplashFontFileID *idA,
92                                                    char *fileName,
93                                                    GBool deleteFile,
94                                                    char **enc) {
95   FoFiType1C *ff;
96   GString *tmpFileName;
97   FILE *tmpFile;
98   SplashFontFile *ret;
99
100   if (!(ff = FoFiType1C::load(fileName))) {
101     return NULL;
102   }
103   tmpFileName = NULL;
104   if (!openTempFile(&tmpFileName, &tmpFile, "wb", NULL)) {
105     delete ff;
106     return NULL;
107   }
108   ff->convertToType1(NULL, gTrue, &fileWrite, tmpFile);
109   delete ff;
110   fclose(tmpFile);
111   ret = SplashT1FontFile::loadType1Font(this, idA, tmpFileName->getCString(),
112                                         gTrue, enc);
113   if (ret) {
114     if (deleteFile) {
115       unlink(fileName);
116     }
117   } else {
118     unlink(tmpFileName->getCString());
119   }
120   delete tmpFileName;
121   return ret;
122 }
123
124 #endif // HAVE_T1LIB_H