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

« back to all changes in this revision

Viewing changes to tests/poppler/splash/SplashFTFontEngine.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
// SplashFTFontEngine.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
// Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
 
17
//
 
18
// To see a description of the changes please see the Changelog file that
 
19
// came with your tarball or type make ChangeLog if you are building from git
 
20
//
 
21
//========================================================================
 
22
 
 
23
#include <config.h>
 
24
 
 
25
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
 
26
 
 
27
#ifdef USE_GCC_PRAGMAS
 
28
#pragma implementation
 
29
#endif
 
30
 
 
31
#include <stdio.h>
 
32
#ifdef HAVE_UNISTD_H
 
33
#include <unistd.h>
 
34
#endif
 
35
#include "goo/gmem.h"
 
36
#include "goo/GooString.h"
 
37
#include "goo/gfile.h"
 
38
#include "fofi/FoFiTrueType.h"
 
39
#include "fofi/FoFiType1C.h"
 
40
#include "SplashFTFontFile.h"
 
41
#include "SplashFTFontEngine.h"
 
42
 
 
43
#ifdef VMS
 
44
#if (__VMS_VER < 70000000)
 
45
extern "C" int unlink(char *filename);
 
46
#endif
 
47
#endif
 
48
 
 
49
//------------------------------------------------------------------------
 
50
 
 
51
#if 0
 
52
static void fileWrite(void *stream, char *data, int len) {
 
53
  fwrite(data, 1, len, (FILE *)stream);
 
54
}
 
55
#endif
 
56
 
 
57
//------------------------------------------------------------------------
 
58
// SplashFTFontEngine
 
59
//------------------------------------------------------------------------
 
60
 
 
61
SplashFTFontEngine::SplashFTFontEngine(GBool aaA, GBool enableFreeTypeHintingA, FT_Library libA) {
 
62
  FT_Int major, minor, patch;
 
63
 
 
64
  aa = aaA;
 
65
  enableFreeTypeHinting = enableFreeTypeHintingA;
 
66
  lib = libA;
 
67
 
 
68
  // as of FT 2.1.8, CID fonts are indexed by CID instead of GID
 
69
  FT_Library_Version(lib, &major, &minor, &patch);
 
70
  useCIDs = major > 2 ||
 
71
            (major == 2 && (minor > 1 || (minor == 1 && patch > 7)));
 
72
}
 
73
 
 
74
SplashFTFontEngine *SplashFTFontEngine::init(GBool aaA, GBool enableFreeTypeHintingA) {
 
75
  FT_Library libA;
 
76
 
 
77
  if (FT_Init_FreeType(&libA)) {
 
78
    return NULL;
 
79
  }
 
80
  return new SplashFTFontEngine(aaA, enableFreeTypeHintingA, libA);
 
81
}
 
82
 
 
83
SplashFTFontEngine::~SplashFTFontEngine() {
 
84
  FT_Done_FreeType(lib);
 
85
}
 
86
 
 
87
SplashFontFile *SplashFTFontEngine::loadType1Font(SplashFontFileID *idA,
 
88
                                                  SplashFontSrc *src,
 
89
                                                  char **enc) {
 
90
  return SplashFTFontFile::loadType1Font(this, idA, src, enc);
 
91
}
 
92
 
 
93
SplashFontFile *SplashFTFontEngine::loadType1CFont(SplashFontFileID *idA,
 
94
                                                   SplashFontSrc *src,
 
95
                                                   char **enc) {
 
96
  return SplashFTFontFile::loadType1Font(this, idA, src, enc);
 
97
}
 
98
 
 
99
SplashFontFile *SplashFTFontEngine::loadOpenTypeT1CFont(SplashFontFileID *idA,
 
100
                                                        SplashFontSrc *src,
 
101
                                                        char **enc) {
 
102
  return SplashFTFontFile::loadType1Font(this, idA, src, enc);
 
103
}
 
104
 
 
105
SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
 
106
                                                SplashFontSrc *src) {
 
107
  FoFiType1C *ff;
 
108
  Gushort *cidToGIDMap;
 
109
  int nCIDs;
 
110
  SplashFontFile *ret;
 
111
 
 
112
  // check for a CFF font
 
113
  if (useCIDs) {
 
114
    cidToGIDMap = NULL;
 
115
    nCIDs = 0;
 
116
  } else {
 
117
    if (src->isFile) {
 
118
      ff = FoFiType1C::load(src->fileName->getCString());
 
119
    } else {
 
120
      ff = FoFiType1C::make(src->buf, src->bufLen);
 
121
    }
 
122
    if (ff) {
 
123
      cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
 
124
      delete ff;
 
125
    } else {
 
126
      cidToGIDMap = NULL;
 
127
      nCIDs = 0;
 
128
    }
 
129
  }
 
130
  ret = SplashFTFontFile::loadCIDFont(this, idA, src, cidToGIDMap, nCIDs);
 
131
  if (!ret) {
 
132
    gfree(cidToGIDMap);
 
133
  }
 
134
  return ret;
 
135
}
 
136
 
 
137
SplashFontFile *SplashFTFontEngine::loadOpenTypeCFFFont(SplashFontFileID *idA,
 
138
                                                        SplashFontSrc *src) {
 
139
  FoFiTrueType *ff;
 
140
  GBool isCID;
 
141
  Gushort *cidToGIDMap;
 
142
  int nCIDs;
 
143
  SplashFontFile *ret;
 
144
 
 
145
  cidToGIDMap = NULL;
 
146
  nCIDs = 0;
 
147
  isCID = gFalse;
 
148
  if (!useCIDs) {
 
149
    if (src->isFile) {
 
150
      ff = FoFiTrueType::load(src->fileName->getCString());
 
151
    } else {
 
152
      ff = FoFiTrueType::make(src->buf, src->bufLen);
 
153
    }
 
154
    if (ff) {
 
155
      if (ff->isOpenTypeCFF()) {
 
156
        cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
 
157
      }
 
158
      delete ff;
 
159
    }
 
160
  }
 
161
  ret = SplashFTFontFile::loadCIDFont(this, idA, src,
 
162
                                      cidToGIDMap, nCIDs);
 
163
  if (!ret) {
 
164
    gfree(cidToGIDMap);
 
165
  }
 
166
  return ret;
 
167
}
 
168
 
 
169
SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
 
170
                                                     SplashFontSrc *src,
 
171
                                                     Gushort *codeToGID,
 
172
                                                     int codeToGIDLen,
 
173
                                                     int faceIndex) {
 
174
#if 0
 
175
  FoFiTrueType *ff;
 
176
  GooString *tmpFileName;
 
177
  FILE *tmpFile;
 
178
  SplashFontFile *ret;
 
179
 
 
180
  if (!(ff = FoFiTrueType::load(fileName))) {
 
181
    return NULL;
 
182
  }
 
183
  tmpFileName = NULL;
 
184
  if (!openTempFile(&tmpFileName, &tmpFile, "wb")) {
 
185
    delete ff;
 
186
    return NULL;
 
187
  }
 
188
  ff->writeTTF(&fileWrite, tmpFile);
 
189
  delete ff;
 
190
  fclose(tmpFile);
 
191
  ret = SplashFTFontFile::loadTrueTypeFont(this, idA,
 
192
                                           tmpFileName->getCString(),
 
193
                                           gTrue, codeToGID, codeToGIDLen,
 
194
                                           faceIndex);
 
195
  if (ret) {
 
196
    if (deleteFile) {
 
197
      unlink(fileName);
 
198
    }
 
199
  } else {
 
200
    unlink(tmpFileName->getCString());
 
201
  }
 
202
  delete tmpFileName;
 
203
  return ret;
 
204
#else
 
205
  SplashFontFile *ret;
 
206
  ret = SplashFTFontFile::loadTrueTypeFont(this, idA, src,
 
207
                                           codeToGID, codeToGIDLen,
 
208
                                           faceIndex);
 
209
  return ret;
 
210
#endif
 
211
}
 
212
 
 
213
#endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H