1 //========================================================================
5 //========================================================================
10 #pragma implementation
24 #include "SplashT1FontEngine.h"
25 #include "SplashFTFontEngine.h"
26 #include "SplashFontFile.h"
27 #include "SplashFontFileID.h"
28 #include "SplashFont.h"
29 #include "SplashFontEngine.h"
32 #if (__VMS_VER < 70000000)
33 extern "C" int unlink(char *filename);
37 //------------------------------------------------------------------------
39 //------------------------------------------------------------------------
41 SplashFontEngine::SplashFontEngine(
45 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
51 for (i = 0; i < splashFontCacheSize; ++i) {
57 t1Engine = SplashT1FontEngine::init(aa);
62 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
64 ftEngine = SplashFTFontEngine::init(aa);
71 SplashFontEngine::~SplashFontEngine() {
74 for (i = 0; i < splashFontCacheSize; ++i) {
85 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
92 SplashFontFile *SplashFontEngine::getFontFile(SplashFontFileID *id) {
93 SplashFontFile *fontFile;
96 for (i = 0; i < splashFontCacheSize; ++i) {
98 fontFile = fontCache[i]->getFontFile();
99 if (fontFile && fontFile->getID()->matches(id)) {
107 SplashFontFile *SplashFontEngine::loadType1Font(SplashFontFileID *idA,
109 GBool deleteFile, char **enc) {
110 SplashFontFile *fontFile;
114 if (!fontFile && t1Engine) {
115 fontFile = t1Engine->loadType1Font(idA, fileName, deleteFile, enc);
118 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
119 if (!fontFile && ftEngine) {
120 fontFile = ftEngine->loadType1Font(idA, fileName, deleteFile, enc);
124 // delete the (temporary) font file -- with Unix hard link
125 // semantics, this will remove the last link; otherwise it will
126 // return an error, leaving the file to be deleted later (if
127 // loadXYZFont failed, the file will always be deleted)
129 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
135 SplashFontFile *SplashFontEngine::loadType1CFont(SplashFontFileID *idA,
139 SplashFontFile *fontFile;
143 if (!fontFile && t1Engine) {
144 fontFile = t1Engine->loadType1CFont(idA, fileName, deleteFile, enc);
147 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
148 if (!fontFile && ftEngine) {
149 fontFile = ftEngine->loadType1CFont(idA, fileName, deleteFile, enc);
153 // delete the (temporary) font file -- with Unix hard link
154 // semantics, this will remove the last link; otherwise it will
155 // return an error, leaving the file to be deleted later (if
156 // loadXYZFont failed, the file will always be deleted)
158 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
164 SplashFontFile *SplashFontEngine::loadCIDFont(SplashFontFileID *idA,
167 SplashFontFile *fontFile;
170 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
171 if (!fontFile && ftEngine) {
172 fontFile = ftEngine->loadCIDFont(idA, fileName, deleteFile);
176 // delete the (temporary) font file -- with Unix hard link
177 // semantics, this will remove the last link; otherwise it will
178 // return an error, leaving the file to be deleted later (if
179 // loadXYZFont failed, the file will always be deleted)
181 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
187 SplashFontFile *SplashFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
192 SplashFontFile *fontFile;
195 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
196 if (!fontFile && ftEngine) {
197 fontFile = ftEngine->loadTrueTypeFont(idA, fileName, deleteFile,
198 codeToGID, codeToGIDLen);
206 // delete the (temporary) font file -- with Unix hard link
207 // semantics, this will remove the last link; otherwise it will
208 // return an error, leaving the file to be deleted later (if
209 // loadXYZFont failed, the file will always be deleted)
211 unlink(fontFile ? fontFile->fileName->getCString() : fileName);
217 SplashFont *SplashFontEngine::getFont(SplashFontFile *fontFile,
223 if (font && font->matches(fontFile, mat)) {
226 for (i = 1; i < splashFontCacheSize; ++i) {
228 if (font && font->matches(fontFile, mat)) {
229 for (j = i; j > 0; --j) {
230 fontCache[j] = fontCache[j-1];
236 font = fontFile->makeFont(mat);
237 if (fontCache[splashFontCacheSize - 1]) {
238 delete fontCache[splashFontCacheSize - 1];
240 for (j = splashFontCacheSize - 1; j > 0; --j) {
241 fontCache[j] = fontCache[j-1];