~ubuntu-branches/ubuntu/natty/luatex/natty

« back to all changes in this revision

Viewing changes to source/libs/xpdf/xpdf-3.02/splash/SplashFontEngine.cc

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2010-12-13 23:22:59 UTC
  • mfrom: (0.2.1) (1.5.4) (4.3.12 experimental)
  • Revision ID: package-import@ubuntu.com-20101213232259-nqq2mq5z5x6qldw3
Tags: 0.65.0-1
* new upstream release
* ship two source packages as they are distributed by upstream, only
  renamed to match source package requirements. Fix debian/rules
  to install the manual pdf from the right place

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//========================================================================
2
 
//
3
 
// SplashFontEngine.cc
4
 
//
5
 
//========================================================================
6
 
 
7
 
#include <aconf.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 "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
 
 
32
 
#ifdef VMS
33
 
#if (__VMS_VER < 70000000)
34
 
extern "C" int unlink(char *filename);
35
 
#endif
36
 
#endif
37
 
 
38
 
//------------------------------------------------------------------------
39
 
// SplashFontEngine
40
 
//------------------------------------------------------------------------
41
 
 
42
 
SplashFontEngine::SplashFontEngine(
43
 
#if HAVE_T1LIB_H
44
 
                                   GBool enableT1lib,
45
 
#endif
46
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
47
 
                                   GBool enableFreeType,
48
 
#endif
49
 
                                   GBool aa) {
50
 
  int i;
51
 
 
52
 
  for (i = 0; i < splashFontCacheSize; ++i) {
53
 
    fontCache[i] = NULL;
54
 
  }
55
 
 
56
 
#if HAVE_T1LIB_H
57
 
  if (enableT1lib) {
58
 
    t1Engine = SplashT1FontEngine::init(aa);
59
 
  } else {
60
 
    t1Engine = NULL;
61
 
  }
62
 
#endif
63
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
64
 
  if (enableFreeType) {
65
 
    ftEngine = SplashFTFontEngine::init(aa);
66
 
  } else {
67
 
    ftEngine = NULL;
68
 
  }
69
 
#endif
70
 
}
71
 
 
72
 
SplashFontEngine::~SplashFontEngine() {
73
 
  int i;
74
 
 
75
 
  for (i = 0; i < splashFontCacheSize; ++i) {
76
 
    if (fontCache[i]) {
77
 
      delete fontCache[i];
78
 
    }
79
 
  }
80
 
 
81
 
#if HAVE_T1LIB_H
82
 
  if (t1Engine) {
83
 
    delete t1Engine;
84
 
  }
85
 
#endif
86
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
87
 
  if (ftEngine) {
88
 
    delete ftEngine;
89
 
  }
90
 
#endif
91
 
}
92
 
 
93
 
SplashFontFile *SplashFontEngine::getFontFile(SplashFontFileID *id) {
94
 
  SplashFontFile *fontFile;
95
 
  int i;
96
 
 
97
 
  for (i = 0; i < splashFontCacheSize; ++i) {
98
 
    if (fontCache[i]) {
99
 
      fontFile = fontCache[i]->getFontFile();
100
 
      if (fontFile && fontFile->getID()->matches(id)) {
101
 
        return fontFile;
102
 
      }
103
 
    }
104
 
  }
105
 
  return NULL;
106
 
}
107
 
 
108
 
SplashFontFile *SplashFontEngine::loadType1Font(SplashFontFileID *idA,
109
 
                                                char *fileName,
110
 
                                                GBool deleteFile, char **enc) {
111
 
  SplashFontFile *fontFile;
112
 
 
113
 
  fontFile = NULL;
114
 
#if HAVE_T1LIB_H
115
 
  if (!fontFile && t1Engine) {
116
 
    fontFile = t1Engine->loadType1Font(idA, fileName, deleteFile, enc);
117
 
  }
118
 
#endif
119
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
120
 
  if (!fontFile && ftEngine) {
121
 
    fontFile = ftEngine->loadType1Font(idA, fileName, deleteFile, enc);
122
 
  }
123
 
#endif
124
 
 
125
 
#ifndef WIN32
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)
130
 
  if (deleteFile) {
131
 
    unlink(fontFile ? fontFile->fileName->getCString() : fileName);
132
 
  }
133
 
#endif
134
 
 
135
 
  return fontFile;
136
 
}
137
 
 
138
 
SplashFontFile *SplashFontEngine::loadType1CFont(SplashFontFileID *idA,
139
 
                                                 char *fileName,
140
 
                                                 GBool deleteFile,
141
 
                                                 char **enc) {
142
 
  SplashFontFile *fontFile;
143
 
 
144
 
  fontFile = NULL;
145
 
#if HAVE_T1LIB_H
146
 
  if (!fontFile && t1Engine) {
147
 
    fontFile = t1Engine->loadType1CFont(idA, fileName, deleteFile, enc);
148
 
  }
149
 
#endif
150
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
151
 
  if (!fontFile && ftEngine) {
152
 
    fontFile = ftEngine->loadType1CFont(idA, fileName, deleteFile, enc);
153
 
  }
154
 
#endif
155
 
 
156
 
#ifndef WIN32
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)
161
 
  if (deleteFile) {
162
 
    unlink(fontFile ? fontFile->fileName->getCString() : fileName);
163
 
  }
164
 
#endif
165
 
 
166
 
  return fontFile;
167
 
}
168
 
 
169
 
SplashFontFile *SplashFontEngine::loadOpenTypeT1CFont(SplashFontFileID *idA,
170
 
                                                      char *fileName,
171
 
                                                      GBool deleteFile,
172
 
                                                      char **enc) {
173
 
  SplashFontFile *fontFile;
174
 
 
175
 
  fontFile = NULL;
176
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
177
 
  if (!fontFile && ftEngine) {
178
 
    fontFile = ftEngine->loadOpenTypeT1CFont(idA, fileName, deleteFile, enc);
179
 
  }
180
 
#endif
181
 
 
182
 
#ifndef WIN32
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)
187
 
  if (deleteFile) {
188
 
    unlink(fontFile ? fontFile->fileName->getCString() : fileName);
189
 
  }
190
 
#endif
191
 
 
192
 
  return fontFile;
193
 
}
194
 
 
195
 
SplashFontFile *SplashFontEngine::loadCIDFont(SplashFontFileID *idA,
196
 
                                              char *fileName,
197
 
                                              GBool deleteFile) {
198
 
  SplashFontFile *fontFile;
199
 
 
200
 
  fontFile = NULL;
201
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
202
 
  if (!fontFile && ftEngine) {
203
 
    fontFile = ftEngine->loadCIDFont(idA, fileName, deleteFile);
204
 
  }
205
 
#endif
206
 
 
207
 
#ifndef WIN32
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)
212
 
  if (deleteFile) {
213
 
    unlink(fontFile ? fontFile->fileName->getCString() : fileName);
214
 
  }
215
 
#endif
216
 
 
217
 
  return fontFile;
218
 
}
219
 
 
220
 
SplashFontFile *SplashFontEngine::loadOpenTypeCFFFont(SplashFontFileID *idA,
221
 
                                                      char *fileName,
222
 
                                                      GBool deleteFile) {
223
 
  SplashFontFile *fontFile;
224
 
 
225
 
  fontFile = NULL;
226
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
227
 
  if (!fontFile && ftEngine) {
228
 
    fontFile = ftEngine->loadOpenTypeCFFFont(idA, fileName, deleteFile);
229
 
  }
230
 
#endif
231
 
 
232
 
#ifndef WIN32
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)
237
 
  if (deleteFile) {
238
 
    unlink(fontFile ? fontFile->fileName->getCString() : fileName);
239
 
  }
240
 
#endif
241
 
 
242
 
  return fontFile;
243
 
}
244
 
 
245
 
SplashFontFile *SplashFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
246
 
                                                   char *fileName,
247
 
                                                   GBool deleteFile,
248
 
                                                   Gushort *codeToGID,
249
 
                                                   int codeToGIDLen) {
250
 
  SplashFontFile *fontFile;
251
 
 
252
 
  fontFile = NULL;
253
 
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
254
 
  if (!fontFile && ftEngine) {
255
 
    fontFile = ftEngine->loadTrueTypeFont(idA, fileName, deleteFile,
256
 
                                          codeToGID, codeToGIDLen);
257
 
  }
258
 
#endif
259
 
 
260
 
  if (!fontFile) {
261
 
    gfree(codeToGID);
262
 
  }
263
 
 
264
 
#ifndef WIN32
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)
269
 
  if (deleteFile) {
270
 
    unlink(fontFile ? fontFile->fileName->getCString() : fileName);
271
 
  }
272
 
#endif
273
 
 
274
 
  return fontFile;
275
 
}
276
 
 
277
 
SplashFont *SplashFontEngine::getFont(SplashFontFile *fontFile,
278
 
                                      SplashCoord *textMat,
279
 
                                      SplashCoord *ctm) {
280
 
  SplashCoord mat[4];
281
 
  SplashFont *font;
282
 
  int i, j;
283
 
 
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;
292
 
  }
293
 
 
294
 
  font = fontCache[0];
295
 
  if (font && font->matches(fontFile, mat, textMat)) {
296
 
    return font;
297
 
  }
298
 
  for (i = 1; i < splashFontCacheSize; ++i) {
299
 
    font = fontCache[i];
300
 
    if (font && font->matches(fontFile, mat, textMat)) {
301
 
      for (j = i; j > 0; --j) {
302
 
        fontCache[j] = fontCache[j-1];
303
 
      }
304
 
      fontCache[0] = font;
305
 
      return font;
306
 
    }
307
 
  }
308
 
  font = fontFile->makeFont(mat, textMat);
309
 
  if (fontCache[splashFontCacheSize - 1]) {
310
 
    delete fontCache[splashFontCacheSize - 1];
311
 
  }
312
 
  for (j = splashFontCacheSize - 1; j > 0; --j) {
313
 
    fontCache[j] = fontCache[j-1];
314
 
  }
315
 
  fontCache[0] = font;
316
 
  return font;
317
 
}