1 //========================================================================
5 //========================================================================
10 #pragma implementation
24 #include "SplashMath.h"
25 #include "SplashT1FontEngine.h"
26 #include "SplashFTFontEngine.h"
27 #include "SplashFontFile.h"
28 #include "SplashFontFileID.h"
29 #include "SplashFont.h"
30 #include "SplashFontEngine.h"
31 #include <aros/debug.h>
33 #if (__VMS_VER < 70000000)
34 extern "C" int unlink(char *filename
);
38 //------------------------------------------------------------------------
40 //------------------------------------------------------------------------
42 SplashFontEngine::SplashFontEngine(
46 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
52 for (i
= 0; i
< splashFontCacheSize
; ++i
) {
58 t1Engine
= SplashT1FontEngine::init(aa
);
63 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
65 ftEngine
= SplashFTFontEngine::init(aa
);
72 SplashFontEngine::~SplashFontEngine() {
75 for (i
= 0; i
< splashFontCacheSize
; ++i
) {
86 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
93 SplashFontFile
*SplashFontEngine::getFontFile(SplashFontFileID
*id
) {
94 SplashFontFile
*fontFile
;
97 for (i
= 0; i
< splashFontCacheSize
; ++i
) {
99 fontFile
= fontCache
[i
]->getFontFile();
100 if (fontFile
&& fontFile
->getID()->matches(id
)) {
108 SplashFontFile
*SplashFontEngine::loadType1Font(SplashFontFileID
*idA
,
110 GBool deleteFile
, char **enc
) {
111 SplashFontFile
*fontFile
;
115 if (!fontFile
&& t1Engine
) {
116 fontFile
= t1Engine
->loadType1Font(idA
, fileName
, deleteFile
, enc
);
119 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
120 if (!fontFile
&& ftEngine
) {
121 //here we are not sure it's loading right...
122 fontFile
= ftEngine
->loadType1Font(idA
, fileName
, deleteFile
, enc
);
127 // delete the (temporary) font file -- with Unix hard link
128 // semantics, this will remove the last link; otherwise it will
129 // return an error, leaving the file to be deleted later (if
130 // loadXYZFont failed, the file will always be deleted)
132 unlink(fontFile
? fontFile
->fileName
->getCString() : fileName
);
139 SplashFontFile
*SplashFontEngine::loadType1CFont(SplashFontFileID
*idA
,
143 SplashFontFile
*fontFile
;
147 if (!fontFile
&& t1Engine
) {
148 fontFile
= t1Engine
->loadType1CFont(idA
, fileName
, deleteFile
, enc
);
151 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
152 if (!fontFile
&& ftEngine
) {
153 fontFile
= ftEngine
->loadType1CFont(idA
, fileName
, deleteFile
, enc
);
158 // delete the (temporary) font file -- with Unix hard link
159 // semantics, this will remove the last link; otherwise it will
160 // return an error, leaving the file to be deleted later (if
161 // loadXYZFont failed, the file will always be deleted)
163 unlink(fontFile
? fontFile
->fileName
->getCString() : fileName
);
170 SplashFontFile
*SplashFontEngine::loadOpenTypeT1CFont(SplashFontFileID
*idA
,
174 SplashFontFile
*fontFile
;
177 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
178 if (!fontFile
&& ftEngine
) {
179 fontFile
= ftEngine
->loadOpenTypeT1CFont(idA
, fileName
, deleteFile
, enc
);
184 // delete the (temporary) font file -- with Unix hard link
185 // semantics, this will remove the last link; otherwise it will
186 // return an error, leaving the file to be deleted later (if
187 // loadXYZFont failed, the file will always be deleted)
189 unlink(fontFile
? fontFile
->fileName
->getCString() : fileName
);
196 SplashFontFile
*SplashFontEngine::loadCIDFont(SplashFontFileID
*idA
,
199 SplashFontFile
*fontFile
;
202 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
203 if (!fontFile
&& ftEngine
) {
204 fontFile
= ftEngine
->loadCIDFont(idA
, fileName
, deleteFile
);
209 // delete the (temporary) font file -- with Unix hard link
210 // semantics, this will remove the last link; otherwise it will
211 // return an error, leaving the file to be deleted later (if
212 // loadXYZFont failed, the file will always be deleted)
214 unlink(fontFile
? fontFile
->fileName
->getCString() : fileName
);
221 SplashFontFile
*SplashFontEngine::loadOpenTypeCFFFont(SplashFontFileID
*idA
,
224 SplashFontFile
*fontFile
;
227 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
228 if (!fontFile
&& ftEngine
) {
229 fontFile
= ftEngine
->loadOpenTypeCFFFont(idA
, fileName
, deleteFile
);
234 // delete the (temporary) font file -- with Unix hard link
235 // semantics, this will remove the last link; otherwise it will
236 // return an error, leaving the file to be deleted later (if
237 // loadXYZFont failed, the file will always be deleted)
239 unlink(fontFile
? fontFile
->fileName
->getCString() : fileName
);
246 SplashFontFile
*SplashFontEngine::loadTrueTypeFont(SplashFontFileID
*idA
,
251 SplashFontFile
*fontFile
;
254 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
255 if (!fontFile
&& ftEngine
) {
256 fontFile
= ftEngine
->loadTrueTypeFont(idA
, fileName
, deleteFile
,
257 codeToGID
, codeToGIDLen
);
266 // delete the (temporary) font file -- with Unix hard link
267 // semantics, this will remove the last link; otherwise it will
268 // return an error, leaving the file to be deleted later (if
269 // loadXYZFont failed, the file will always be deleted)
271 unlink(fontFile
? fontFile
->fileName
->getCString() : fileName
);
278 SplashFont
*SplashFontEngine::getFont(SplashFontFile
*fontFile
,
279 SplashCoord
*textMat
,
285 mat
[0] = textMat
[0] * ctm
[0] + textMat
[1] * ctm
[2];
286 mat
[1] = -(textMat
[0] * ctm
[1] + textMat
[1] * ctm
[3]);
287 mat
[2] = textMat
[2] * ctm
[0] + textMat
[3] * ctm
[2];
288 mat
[3] = -(textMat
[2] * ctm
[1] + textMat
[3] * ctm
[3]);
289 if (splashAbs(mat
[0] * mat
[3] - mat
[1] * mat
[2]) < 0.01) {
290 // avoid a singular (or close-to-singular) matrix
291 mat
[0] = 0.01; mat
[1] = 0;
292 mat
[2] = 0; mat
[3] = 0.01;
296 if (font
&& font
->matches(fontFile
, mat
, textMat
)) {
299 for (i
= 1; i
< splashFontCacheSize
; ++i
) {
301 if (font
&& font
->matches(fontFile
, mat
, textMat
)) {
302 for (j
= i
; j
> 0; --j
) {
303 fontCache
[j
] = fontCache
[j
-1];
309 font
= fontFile
->makeFont(mat
, textMat
);
310 if (fontCache
[splashFontCacheSize
- 1]) {
311 delete fontCache
[splashFontCacheSize
- 1];
313 for (j
= splashFontCacheSize
- 1; j
> 0; --j
) {
314 fontCache
[j
] = fontCache
[j
-1];