1
//========================================================================
3
// SplashFTFontEngine.cc
5
//========================================================================
7
//========================================================================
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>
16
// Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
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
21
//========================================================================
25
#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
27
#ifdef USE_GCC_PRAGMAS
28
#pragma implementation
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"
44
#if (__VMS_VER < 70000000)
45
extern "C" int unlink(char *filename);
49
//------------------------------------------------------------------------
52
static void fileWrite(void *stream, char *data, int len) {
53
fwrite(data, 1, len, (FILE *)stream);
57
//------------------------------------------------------------------------
59
//------------------------------------------------------------------------
61
SplashFTFontEngine::SplashFTFontEngine(GBool aaA, GBool enableFreeTypeHintingA, FT_Library libA) {
62
FT_Int major, minor, patch;
65
enableFreeTypeHinting = enableFreeTypeHintingA;
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)));
74
SplashFTFontEngine *SplashFTFontEngine::init(GBool aaA, GBool enableFreeTypeHintingA) {
77
if (FT_Init_FreeType(&libA)) {
80
return new SplashFTFontEngine(aaA, enableFreeTypeHintingA, libA);
83
SplashFTFontEngine::~SplashFTFontEngine() {
84
FT_Done_FreeType(lib);
87
SplashFontFile *SplashFTFontEngine::loadType1Font(SplashFontFileID *idA,
90
return SplashFTFontFile::loadType1Font(this, idA, src, enc);
93
SplashFontFile *SplashFTFontEngine::loadType1CFont(SplashFontFileID *idA,
96
return SplashFTFontFile::loadType1Font(this, idA, src, enc);
99
SplashFontFile *SplashFTFontEngine::loadOpenTypeT1CFont(SplashFontFileID *idA,
102
return SplashFTFontFile::loadType1Font(this, idA, src, enc);
105
SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
106
SplashFontSrc *src) {
108
Gushort *cidToGIDMap;
112
// check for a CFF font
118
ff = FoFiType1C::load(src->fileName->getCString());
120
ff = FoFiType1C::make(src->buf, src->bufLen);
123
cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
130
ret = SplashFTFontFile::loadCIDFont(this, idA, src, cidToGIDMap, nCIDs);
137
SplashFontFile *SplashFTFontEngine::loadOpenTypeCFFFont(SplashFontFileID *idA,
138
SplashFontSrc *src) {
141
Gushort *cidToGIDMap;
150
ff = FoFiTrueType::load(src->fileName->getCString());
152
ff = FoFiTrueType::make(src->buf, src->bufLen);
155
if (ff->isOpenTypeCFF()) {
156
cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
161
ret = SplashFTFontFile::loadCIDFont(this, idA, src,
169
SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
176
GooString *tmpFileName;
180
if (!(ff = FoFiTrueType::load(fileName))) {
184
if (!openTempFile(&tmpFileName, &tmpFile, "wb")) {
188
ff->writeTTF(&fileWrite, tmpFile);
191
ret = SplashFTFontFile::loadTrueTypeFont(this, idA,
192
tmpFileName->getCString(),
193
gTrue, codeToGID, codeToGIDLen,
200
unlink(tmpFileName->getCString());
206
ret = SplashFTFontFile::loadTrueTypeFont(this, idA, src,
207
codeToGID, codeToGIDLen,
213
#endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H