]> git.ipfire.org Git - thirdparty/cups.git/blame - pdftops/SplashFontEngine.cxx
Load cups into easysw/current.
[thirdparty/cups.git] / pdftops / SplashFontEngine.cxx
CommitLineData
ef416fc2 1//========================================================================
2//
3// SplashFontEngine.cc
4//
5//========================================================================
6
7#include <config.h>
8
9#ifdef USE_GCC_PRAGMAS
10#pragma implementation
11#endif
12
13#if HAVE_T1LIB_H
14#include <t1lib.h>
15#endif
16
17#include <stdlib.h>
18#include <stdio.h>
19#ifndef WIN32
20# include <unistd.h>
21#endif
22#include "gmem.h"
23#include "GString.h"
24#include "SplashT1FontEngine.h"
25#include "SplashFTFontEngine.h"
26#include "SplashFontFile.h"
27#include "SplashFontFileID.h"
28#include "SplashFont.h"
29#include "SplashFontEngine.h"
30
31#ifdef VMS
32#if (__VMS_VER < 70000000)
33extern "C" int unlink(char *filename);
34#endif
35#endif
36
37//------------------------------------------------------------------------
38// SplashFontEngine
39//------------------------------------------------------------------------
40
41SplashFontEngine::SplashFontEngine(
42#if HAVE_T1LIB_H
43 GBool enableT1lib,
44#endif
45#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
46 GBool enableFreeType,
47#endif
48 GBool aa) {
49 int i;
50
51 for (i = 0; i < splashFontCacheSize; ++i) {
52 fontCache[i] = NULL;
53 }
54
55#if HAVE_T1LIB_H
56 if (enableT1lib) {
57 t1Engine = SplashT1FontEngine::init(aa);
58 } else {
59 t1Engine = NULL;
60 }
61#endif
62#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
63 if (enableFreeType) {
64 ftEngine = SplashFTFontEngine::init(aa);
65 } else {
66 ftEngine = NULL;
67 }
68#endif
69}
70
71SplashFontEngine::~SplashFontEngine() {
72 int i;
73
74 for (i = 0; i < splashFontCacheSize; ++i) {
75 if (fontCache[i]) {
76 delete fontCache[i];
77 }
78 }
79
80#if HAVE_T1LIB_H
81 if (t1Engine) {
82 delete t1Engine;
83 }
84#endif
85#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
86 if (ftEngine) {
87 delete ftEngine;
88 }
89#endif
90}
91
92SplashFontFile *SplashFontEngine::getFontFile(SplashFontFileID *id) {
93 SplashFontFile *fontFile;
94 int i;
95
96 for (i = 0; i < splashFontCacheSize; ++i) {
97 if (fontCache[i]) {
98 fontFile = fontCache[i]->getFontFile();
99 if (fontFile && fontFile->getID()->matches(id)) {
100 return fontFile;
101 }
102 }
103 }
104 return NULL;
105}
106
107SplashFontFile *SplashFontEngine::loadType1Font(SplashFontFileID *idA,
108 char *fileName,
109 GBool deleteFile, char **enc) {
110 SplashFontFile *fontFile;
111
112 fontFile = NULL;
113#if HAVE_T1LIB_H
114 if (!fontFile && t1Engine) {
115 fontFile = t1Engine->loadType1Font(idA, fileName, deleteFile, enc);
116 }
117#endif
118#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
119 if (!fontFile && ftEngine) {
120 fontFile = ftEngine->loadType1Font(idA, fileName, deleteFile, enc);
121 }
122#endif
123
124#ifndef WIN32
125 // delete the (temporary) font file -- with Unix hard link
126 // semantics, this will remove the last link; otherwise it will
127 // return an error, leaving the file to be deleted later (if
128 // loadXYZFont failed, the file will always be deleted)
129 if (deleteFile) {
130 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
131 }
132#endif
133
134 return fontFile;
135}
136
137SplashFontFile *SplashFontEngine::loadType1CFont(SplashFontFileID *idA,
138 char *fileName,
139 GBool deleteFile,
140 char **enc) {
141 SplashFontFile *fontFile;
142
143 fontFile = NULL;
144#if HAVE_T1LIB_H
145 if (!fontFile && t1Engine) {
146 fontFile = t1Engine->loadType1CFont(idA, fileName, deleteFile, enc);
147 }
148#endif
149#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
150 if (!fontFile && ftEngine) {
151 fontFile = ftEngine->loadType1CFont(idA, fileName, deleteFile, enc);
152 }
153#endif
154
155#ifndef WIN32
156 // delete the (temporary) font file -- with Unix hard link
157 // semantics, this will remove the last link; otherwise it will
158 // return an error, leaving the file to be deleted later (if
159 // loadXYZFont failed, the file will always be deleted)
160 if (deleteFile) {
161 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
162 }
163#endif
164
165 return fontFile;
166}
167
168SplashFontFile *SplashFontEngine::loadCIDFont(SplashFontFileID *idA,
169 char *fileName,
170 GBool deleteFile) {
171 SplashFontFile *fontFile;
172
173 fontFile = NULL;
174#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
175 if (!fontFile && ftEngine) {
176 fontFile = ftEngine->loadCIDFont(idA, fileName, deleteFile);
177 }
178#endif
179
180#ifndef WIN32
181 // delete the (temporary) font file -- with Unix hard link
182 // semantics, this will remove the last link; otherwise it will
183 // return an error, leaving the file to be deleted later (if
184 // loadXYZFont failed, the file will always be deleted)
185 if (deleteFile) {
186 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
187 }
188#endif
189
190 return fontFile;
191}
192
193SplashFontFile *SplashFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
194 char *fileName,
195 GBool deleteFile,
196 Gushort *codeToGID,
197 int codeToGIDLen) {
198 SplashFontFile *fontFile;
199
200 fontFile = NULL;
201#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
202 if (!fontFile && ftEngine) {
203 fontFile = ftEngine->loadTrueTypeFont(idA, fileName, deleteFile,
204 codeToGID, codeToGIDLen);
205 }
206#endif
207
208 if (!fontFile) {
209 gfree(codeToGID);
210 }
211
212#ifndef WIN32
213 // delete the (temporary) font file -- with Unix hard link
214 // semantics, this will remove the last link; otherwise it will
215 // return an error, leaving the file to be deleted later (if
216 // loadXYZFont failed, the file will always be deleted)
217 if (deleteFile) {
218 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
219 }
220#endif
221
222 return fontFile;
223}
224
225SplashFont *SplashFontEngine::getFont(SplashFontFile *fontFile,
226 SplashCoord *mat) {
227 SplashFont *font;
228 int i, j;
229
230 font = fontCache[0];
231 if (font && font->matches(fontFile, mat)) {
232 return font;
233 }
234 for (i = 1; i < splashFontCacheSize; ++i) {
235 font = fontCache[i];
236 if (font && font->matches(fontFile, mat)) {
237 for (j = i; j > 0; --j) {
238 fontCache[j] = fontCache[j-1];
239 }
240 fontCache[0] = font;
241 return font;
242 }
243 }
244 font = fontFile->makeFont(mat);
245 if (fontCache[splashFontCacheSize - 1]) {
246 delete fontCache[splashFontCacheSize - 1];
247 }
248 for (j = splashFontCacheSize - 1; j > 0; --j) {
249 fontCache[j] = fontCache[j-1];
250 }
251 fontCache[0] = font;
252 return font;
253}