beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / splash / SplashT1FontEngine.cc
blobfb4b38dae88ac9c9132829bb52d418bbc39079fd
1 //========================================================================
2 //
3 // SplashT1FontEngine.cc
4 //
5 //========================================================================
7 //========================================================================
8 //
9 // Modified under the Poppler project - http://poppler.freedesktop.org
11 // All changes made under the Poppler project to this file are licensed
12 // under GPL version 2 or later
14 // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
15 // Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
17 // To see a description of the changes please see the Changelog file that
18 // came with your tarball or type make ChangeLog if you are building from git
20 //========================================================================
22 #include <config.h>
24 #if HAVE_T1LIB_H
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
28 #endif
30 #include <stdlib.h>
31 #include <stdio.h>
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
35 #include <t1lib.h>
36 #include "goo/GooString.h"
37 #include "goo/gfile.h"
38 #include "fofi/FoFiType1C.h"
39 #include "SplashT1FontFile.h"
40 #include "SplashT1FontEngine.h"
42 #ifdef VMS
43 #if (__VMS_VER < 70000000)
44 extern "C" int unlink(char *filename);
45 #endif
46 #endif
48 //------------------------------------------------------------------------
50 int SplashT1FontEngine::t1libInitCount = 0;
52 //------------------------------------------------------------------------
54 static void fileWrite(void *stream, const char *data, int len) {
55 fwrite(data, 1, len, (FILE *)stream);
58 //------------------------------------------------------------------------
59 // SplashT1FontEngine
60 //------------------------------------------------------------------------
62 SplashT1FontEngine::SplashT1FontEngine(GBool aaA) {
63 aa = aaA;
66 SplashT1FontEngine *SplashT1FontEngine::init(GBool aaA) {
67 // grayVals[i] = round(i * 255 / 16)
68 static unsigned long grayVals[17] = {
69 0, 16, 32, 48, 64, 80, 96, 112, 128, 143, 159, 175, 191, 207, 223, 239, 255
72 //~ for multithreading: need a mutex here
73 if (t1libInitCount == 0) {
74 T1_SetBitmapPad(8);
75 if (!T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE |
76 T1_NO_AFM)) {
77 return NULL;
79 if (aaA) {
80 T1_AASetBitsPerPixel(8);
81 T1_AASetLevel(T1_AA_HIGH);
82 T1_AAHSetGrayValues(grayVals);
83 } else {
84 T1_AANSetGrayValues(0, 1);
87 ++t1libInitCount;
89 return new SplashT1FontEngine(aaA);
92 SplashT1FontEngine::~SplashT1FontEngine() {
93 //~ for multithreading: need a mutex here
94 if (--t1libInitCount == 0) {
95 T1_CloseLib();
99 SplashFontFile *SplashT1FontEngine::loadType1Font(SplashFontFileID *idA,
100 SplashFontSrc *src,
101 const char **enc) {
102 return SplashT1FontFile::loadType1Font(this, idA, src, enc);
105 SplashFontFile *SplashT1FontEngine::loadType1CFont(SplashFontFileID *idA,
106 SplashFontSrc *src,
107 const char **enc) {
108 FoFiType1C *ff;
109 GooString *tmpFileName;
110 FILE *tmpFile;
111 SplashFontFile *ret;
113 SplashFontSrc *newsrc;
115 if (src->isFile)
116 ff = FoFiType1C::load(src->fileName->getCString());
117 else
118 ff = FoFiType1C::make(src->buf, src->bufLen);
119 if (! ff)
120 return NULL;
122 tmpFileName = NULL;
123 if (!openTempFile(&tmpFileName, &tmpFile, "wb")) {
124 delete ff;
125 return NULL;
127 ff->convertToType1(NULL, NULL, gTrue, &fileWrite, tmpFile);
128 delete ff;
129 fclose(tmpFile);
130 newsrc = new SplashFontSrc;
131 newsrc->setFile(tmpFileName, gTrue);
132 delete tmpFileName;
133 ret = SplashT1FontFile::loadType1Font(this, idA, newsrc, enc);
134 newsrc->unref();
135 return ret;
138 #endif // HAVE_T1LIB_H