~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/splash/SplashT1FontEngine.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// SplashT1FontEngine.cc
 
4
//
 
5
//========================================================================
 
6
 
 
7
//========================================================================
 
8
//
 
9
// Modified under the Poppler project - http://poppler.freedesktop.org
 
10
//
 
11
// All changes made under the Poppler project to this file are licensed
 
12
// under GPL version 2 or later
 
13
//
 
14
// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
 
15
// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org>
 
16
//
 
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
 
19
//
 
20
//========================================================================
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#if HAVE_T1LIB_H
 
25
 
 
26
#ifdef USE_GCC_PRAGMAS
 
27
#pragma implementation
 
28
#endif
 
29
 
 
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"
 
41
 
 
42
#ifdef VMS
 
43
#if (__VMS_VER < 70000000)
 
44
extern "C" int unlink(char *filename);
 
45
#endif
 
46
#endif
 
47
 
 
48
//------------------------------------------------------------------------
 
49
 
 
50
int SplashT1FontEngine::t1libInitCount = 0;
 
51
 
 
52
//------------------------------------------------------------------------
 
53
 
 
54
static void fileWrite(void *stream, char *data, int len) {
 
55
  fwrite(data, 1, len, (FILE *)stream);
 
56
}
 
57
 
 
58
//------------------------------------------------------------------------
 
59
// SplashT1FontEngine
 
60
//------------------------------------------------------------------------
 
61
 
 
62
SplashT1FontEngine::SplashT1FontEngine(GBool aaA) {
 
63
  aa = aaA;
 
64
}
 
65
 
 
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
 
70
  };
 
71
 
 
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;
 
78
    }
 
79
    if (aaA) {
 
80
      T1_AASetBitsPerPixel(8);
 
81
      T1_AASetLevel(T1_AA_HIGH);
 
82
      T1_AAHSetGrayValues(grayVals);
 
83
    } else {
 
84
      T1_AANSetGrayValues(0, 1);
 
85
    }
 
86
  }
 
87
  ++t1libInitCount;
 
88
 
 
89
  return new SplashT1FontEngine(aaA);
 
90
}
 
91
 
 
92
SplashT1FontEngine::~SplashT1FontEngine() {
 
93
  //~ for multithreading: need a mutex here
 
94
  if (--t1libInitCount == 0) {
 
95
    T1_CloseLib();
 
96
  }
 
97
}
 
98
 
 
99
SplashFontFile *SplashT1FontEngine::loadType1Font(SplashFontFileID *idA,
 
100
                                                  SplashFontSrc *src,
 
101
                                                  char **enc) {
 
102
  return SplashT1FontFile::loadType1Font(this, idA, src, enc);
 
103
}
 
104
 
 
105
SplashFontFile *SplashT1FontEngine::loadType1CFont(SplashFontFileID *idA,
 
106
                                                   SplashFontSrc *src,
 
107
                                                   char **enc) {
 
108
  FoFiType1C *ff;
 
109
  GooString *tmpFileName;
 
110
  FILE *tmpFile;
 
111
  SplashFontFile *ret;
 
112
 
 
113
  SplashFontSrc *newsrc;
 
114
  
 
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;
 
121
 
 
122
  tmpFileName = NULL;
 
123
  if (!openTempFile(&tmpFileName, &tmpFile, "wb")) {
 
124
    delete ff;
 
125
    return NULL;
 
126
  }
 
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;
 
136
}
 
137
 
 
138
#endif // HAVE_T1LIB_H