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"
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
fontFile = ftEngine->loadType1Font(idA, fileName, deleteFile, enc);
126
// delete the (temporary) font file -- with Unix hard link
127
// semantics, this will remove the last link; otherwise it will
128
// return an error, leaving the file to be deleted later (if
129
// loadXYZFont failed, the file will always be deleted)
131
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
138
SplashFontFile *SplashFontEngine::loadType1CFont(SplashFontFileID *idA,
142
SplashFontFile *fontFile;
146
if (!fontFile && t1Engine) {
147
fontFile = t1Engine->loadType1CFont(idA, fileName, deleteFile, enc);
150
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
151
if (!fontFile && ftEngine) {
152
fontFile = ftEngine->loadType1CFont(idA, fileName, deleteFile, enc);
157
// delete the (temporary) font file -- with Unix hard link
158
// semantics, this will remove the last link; otherwise it will
159
// return an error, leaving the file to be deleted later (if
160
// loadXYZFont failed, the file will always be deleted)
162
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
169
SplashFontFile *SplashFontEngine::loadOpenTypeT1CFont(SplashFontFileID *idA,
173
SplashFontFile *fontFile;
176
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
177
if (!fontFile && ftEngine) {
178
fontFile = ftEngine->loadOpenTypeT1CFont(idA, fileName, deleteFile, enc);
183
// delete the (temporary) font file -- with Unix hard link
184
// semantics, this will remove the last link; otherwise it will
185
// return an error, leaving the file to be deleted later (if
186
// loadXYZFont failed, the file will always be deleted)
188
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
195
SplashFontFile *SplashFontEngine::loadCIDFont(SplashFontFileID *idA,
198
SplashFontFile *fontFile;
201
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
202
if (!fontFile && ftEngine) {
203
fontFile = ftEngine->loadCIDFont(idA, fileName, deleteFile);
208
// delete the (temporary) font file -- with Unix hard link
209
// semantics, this will remove the last link; otherwise it will
210
// return an error, leaving the file to be deleted later (if
211
// loadXYZFont failed, the file will always be deleted)
213
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
220
SplashFontFile *SplashFontEngine::loadOpenTypeCFFFont(SplashFontFileID *idA,
223
SplashFontFile *fontFile;
226
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
227
if (!fontFile && ftEngine) {
228
fontFile = ftEngine->loadOpenTypeCFFFont(idA, fileName, deleteFile);
233
// delete the (temporary) font file -- with Unix hard link
234
// semantics, this will remove the last link; otherwise it will
235
// return an error, leaving the file to be deleted later (if
236
// loadXYZFont failed, the file will always be deleted)
238
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
245
SplashFontFile *SplashFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
250
SplashFontFile *fontFile;
253
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
254
if (!fontFile && ftEngine) {
255
fontFile = ftEngine->loadTrueTypeFont(idA, fileName, deleteFile,
256
codeToGID, codeToGIDLen);
265
// delete the (temporary) font file -- with Unix hard link
266
// semantics, this will remove the last link; otherwise it will
267
// return an error, leaving the file to be deleted later (if
268
// loadXYZFont failed, the file will always be deleted)
270
unlink(fontFile ? fontFile->fileName->getCString() : fileName);
277
SplashFont *SplashFontEngine::getFont(SplashFontFile *fontFile,
278
SplashCoord *textMat,
284
mat[0] = textMat[0] * ctm[0] + textMat[1] * ctm[2];
285
mat[1] = -(textMat[0] * ctm[1] + textMat[1] * ctm[3]);
286
mat[2] = textMat[2] * ctm[0] + textMat[3] * ctm[2];
287
mat[3] = -(textMat[2] * ctm[1] + textMat[3] * ctm[3]);
288
if (splashAbs(mat[0] * mat[3] - mat[1] * mat[2]) < 0.01) {
289
// avoid a singular (or close-to-singular) matrix
290
mat[0] = 0.01; mat[1] = 0;
291
mat[2] = 0; mat[3] = 0.01;
295
if (font && font->matches(fontFile, mat, textMat)) {
298
for (i = 1; i < splashFontCacheSize; ++i) {
300
if (font && font->matches(fontFile, mat, textMat)) {
301
for (j = i; j > 0; --j) {
302
fontCache[j] = fontCache[j-1];
308
font = fontFile->makeFont(mat, textMat);
309
if (fontCache[splashFontCacheSize - 1]) {
310
delete fontCache[splashFontCacheSize - 1];
312
for (j = splashFontCacheSize - 1; j > 0; --j) {
313
fontCache[j] = fontCache[j-1];