source: trunk/poppler/mypoppler/splash/SplashT1FontEngine.cc @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 15 years ago

First import

File size: 2.9 KB
Line 
1//========================================================================
2//
3// SplashT1FontEngine.cc
4//
5//========================================================================
6
7#include <config.h>
8
9#if HAVE_T1LIB_H
10
11#ifdef USE_GCC_PRAGMAS
12#pragma implementation
13#endif
14
15#include <stdlib.h>
16#include <stdio.h>
17#ifndef WIN32
18#  include <unistd.h>
19#endif
20#include <t1lib.h>
21#include "goo/GooString.h"
22#include "goo/gfile.h"
23#include "fofi/FoFiType1C.h"
24#include "SplashT1FontFile.h"
25#include "SplashT1FontEngine.h"
26
27#ifdef VMS
28#if (__VMS_VER < 70000000)
29extern "C" int unlink(char *filename);
30#endif
31#endif
32
33//------------------------------------------------------------------------
34
35int SplashT1FontEngine::t1libInitCount = 0;
36
37//------------------------------------------------------------------------
38
39static void fileWrite(void *stream, char *data, int len) {
40  fwrite(data, 1, len, (FILE *)stream);
41}
42
43//------------------------------------------------------------------------
44// SplashT1FontEngine
45//------------------------------------------------------------------------
46
47SplashT1FontEngine::SplashT1FontEngine(GBool aaA) {
48  aa = aaA;
49}
50
51SplashT1FontEngine *SplashT1FontEngine::init(GBool aaA) {
52  // grayVals[i] = round(i * 255 / 16)
53  static unsigned long grayVals[17] = {
54    0, 16, 32, 48, 64, 80, 96, 112, 128, 143, 159, 175, 191, 207, 223, 239, 255
55  };
56
57  //~ for multithreading: need a mutex here
58  if (t1libInitCount == 0) {
59    T1_SetBitmapPad(8);
60    if (!T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE |
61                    T1_NO_AFM)) {
62      return NULL;
63    }
64    if (aaA) {
65      T1_AASetBitsPerPixel(8);
66      T1_AASetLevel(T1_AA_HIGH);
67      T1_AAHSetGrayValues(grayVals);
68    } else {
69      T1_AANSetGrayValues(0, 1);
70    }
71  }
72  ++t1libInitCount;
73
74  return new SplashT1FontEngine(aaA);
75}
76
77SplashT1FontEngine::~SplashT1FontEngine() {
78  //~ for multithreading: need a mutex here
79  if (--t1libInitCount == 0) {
80    T1_CloseLib();
81  }
82}
83
84SplashFontFile *SplashT1FontEngine::loadType1Font(SplashFontFileID *idA,
85                                                  SplashFontSrc *src,
86                                                  char **enc) {
87  return SplashT1FontFile::loadType1Font(this, idA, src, enc);
88}
89
90SplashFontFile *SplashT1FontEngine::loadType1CFont(SplashFontFileID *idA,
91                                                   SplashFontSrc *src,
92                                                   char **enc) {
93  FoFiType1C *ff;
94  GooString *tmpFileName;
95  FILE *tmpFile;
96  SplashFontFile *ret;
97
98  SplashFontSrc *newsrc;
99 
100  if (src->isFile)
101    ff = FoFiType1C::load(src->fileName);
102  else
103    ff = new FoFiType1C(src->buf, src->bufLen, gFalse);
104  if (! ff)
105    return NULL;
106  }
107  tmpFileName = NULL;
108  if (!openTempFile(&tmpFileName, &tmpFile, "wb", NULL)) {
109    delete ff;
110    return NULL;
111  }
112  ff->convertToType1(NULL, gTrue, &fileWrite, tmpFile);
113  delete ff;
114  fclose(tmpFile);
115  newsrc = new SplashFontSrc;
116  newsrc->setFile(tmpFileName, gTrue);
117  delete tmpFileName;
118  ret = SplashT1FontFile::loadType1Font(this, idA, newsrc, enc);
119  newsrc->unref();
120  return ret;
121}
122
123#endif // HAVE_T1LIB_H
Note: See TracBrowser for help on using the repository browser.