beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / splash / SplashFTFontEngine.cc
blob9fef8f007d11650e4c58b6f2008d8d23cabe027e
1 //========================================================================
2 //
3 // SplashFTFontEngine.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, 2011, 2012 Albert Astals Cid <aacid@kde.org>
16 // Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
17 // Copyright (C) 2011 Andreas Hartmetz <ahartmetz@gmail.com>
19 // To see a description of the changes please see the Changelog file that
20 // came with your tarball or type make ChangeLog if you are building from git
22 //========================================================================
24 #include <config.h>
26 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
28 #ifdef USE_GCC_PRAGMAS
29 #pragma implementation
30 #endif
32 #include <stdio.h>
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36 #include "goo/gmem.h"
37 #include "goo/GooString.h"
38 #include "goo/gfile.h"
39 #include "fofi/FoFiTrueType.h"
40 #include "fofi/FoFiType1C.h"
41 #include "SplashFTFontFile.h"
42 #include "SplashFTFontEngine.h"
44 #ifdef VMS
45 #if (__VMS_VER < 70000000)
46 extern "C" int unlink(char *filename);
47 #endif
48 #endif
50 //------------------------------------------------------------------------
51 // SplashFTFontEngine
52 //------------------------------------------------------------------------
54 SplashFTFontEngine::SplashFTFontEngine(GBool aaA, GBool enableFreeTypeHintingA,
55 GBool enableSlightHintingA, FT_Library libA) {
56 FT_Int major, minor, patch;
58 aa = aaA;
59 enableFreeTypeHinting = enableFreeTypeHintingA;
60 enableSlightHinting = enableSlightHintingA;
61 lib = libA;
63 // as of FT 2.1.8, CID fonts are indexed by CID instead of GID
64 FT_Library_Version(lib, &major, &minor, &patch);
65 useCIDs = major > 2 ||
66 (major == 2 && (minor > 1 || (minor == 1 && patch > 7)));
69 SplashFTFontEngine *SplashFTFontEngine::init(GBool aaA, GBool enableFreeTypeHintingA,
70 GBool enableSlightHintingA) {
71 FT_Library libA;
73 if (FT_Init_FreeType(&libA)) {
74 return NULL;
76 return new SplashFTFontEngine(aaA, enableFreeTypeHintingA, enableSlightHintingA, libA);
79 SplashFTFontEngine::~SplashFTFontEngine() {
80 FT_Done_FreeType(lib);
83 SplashFontFile *SplashFTFontEngine::loadType1Font(SplashFontFileID *idA,
84 SplashFontSrc *src,
85 const char **enc) {
86 return SplashFTFontFile::loadType1Font(this, idA, src, enc);
89 SplashFontFile *SplashFTFontEngine::loadType1CFont(SplashFontFileID *idA,
90 SplashFontSrc *src,
91 const char **enc) {
92 return SplashFTFontFile::loadType1Font(this, idA, src, enc);
95 SplashFontFile *SplashFTFontEngine::loadOpenTypeT1CFont(SplashFontFileID *idA,
96 SplashFontSrc *src,
97 const char **enc) {
98 return SplashFTFontFile::loadType1Font(this, idA, src, enc);
101 SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
102 SplashFontSrc *src) {
103 FoFiType1C *ff;
104 int *cidToGIDMap;
105 int nCIDs;
106 SplashFontFile *ret;
108 // check for a CFF font
109 if (useCIDs) {
110 cidToGIDMap = NULL;
111 nCIDs = 0;
112 } else {
113 if (src->isFile) {
114 ff = FoFiType1C::load(src->fileName->getCString());
115 } else {
116 ff = FoFiType1C::make(src->buf, src->bufLen);
118 if (ff) {
119 cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
120 delete ff;
121 } else {
122 cidToGIDMap = NULL;
123 nCIDs = 0;
126 ret = SplashFTFontFile::loadCIDFont(this, idA, src, cidToGIDMap, nCIDs);
127 if (!ret) {
128 gfree(cidToGIDMap);
130 return ret;
133 SplashFontFile *SplashFTFontEngine::loadOpenTypeCFFFont(SplashFontFileID *idA,
134 SplashFontSrc *src,
135 int *codeToGID,
136 int codeToGIDLen) {
137 FoFiTrueType *ff;
138 int *cidToGIDMap;
139 int nCIDs;
140 SplashFontFile *ret;
142 cidToGIDMap = NULL;
143 nCIDs = 0;
144 if (!codeToGID) {
145 if (!useCIDs) {
146 if (src->isFile) {
147 ff = FoFiTrueType::load(src->fileName->getCString());
148 } else {
149 ff = FoFiTrueType::make(src->buf, src->bufLen);
151 if (ff) {
152 if (ff->isOpenTypeCFF()) {
153 cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
155 delete ff;
159 ret = SplashFTFontFile::loadCIDFont(this, idA, src,
160 codeToGID ? codeToGID : cidToGIDMap,
161 codeToGID ? codeToGIDLen : nCIDs);
162 if (!ret) {
163 gfree(cidToGIDMap);
165 return ret;
168 SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
169 SplashFontSrc *src,
170 int *codeToGID,
171 int codeToGIDLen,
172 int faceIndex) {
173 SplashFontFile *ret;
174 ret = SplashFTFontFile::loadTrueTypeFont(this, idA, src,
175 codeToGID, codeToGIDLen,
176 faceIndex);
177 return ret;
180 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H