beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / splash / SplashFTFontFile.cc
blobf0dcf50384bf22b9e4f133fe4b090f765253f161
1 //========================================================================
2 //
3 // SplashFTFontFile.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) 2014 Adrian Johnson <ajohnson@redneon.com>
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
20 //========================================================================
22 #include <config.h>
24 #if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
28 #endif
30 #include "goo/gmem.h"
31 #include "goo/GooString.h"
32 #include "poppler/GfxFont.h"
33 #include "SplashFTFontEngine.h"
34 #include "SplashFTFont.h"
35 #include "SplashFTFontFile.h"
37 //------------------------------------------------------------------------
38 // SplashFTFontFile
39 //------------------------------------------------------------------------
41 SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
42 SplashFontFileID *idA,
43 SplashFontSrc *src,
44 const char **encA) {
45 FT_Face faceA;
46 int *codeToGIDA;
47 const char *name;
48 int i;
50 if (src->isFile) {
51 if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
52 return NULL;
53 } else {
54 if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
55 return NULL;
57 codeToGIDA = (int *)gmallocn(256, sizeof(int));
58 for (i = 0; i < 256; ++i) {
59 codeToGIDA[i] = 0;
60 if ((name = encA[i])) {
61 codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);
62 if (codeToGIDA[i] == 0) {
63 name = GfxFont::getAlternateName(name);
64 if (name) {
65 codeToGIDA[i] = FT_Get_Name_Index(faceA, (char *)name);
71 return new SplashFTFontFile(engineA, idA, src,
72 faceA, codeToGIDA, 256, gFalse, gTrue);
75 SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA,
76 SplashFontFileID *idA,
77 SplashFontSrc *src,
78 int *codeToGIDA,
79 int codeToGIDLenA) {
80 FT_Face faceA;
82 if (src->isFile) {
83 if (FT_New_Face(engineA->lib, src->fileName->getCString(), 0, &faceA))
84 return NULL;
85 } else {
86 if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA))
87 return NULL;
90 return new SplashFTFontFile(engineA, idA, src,
91 faceA, codeToGIDA, codeToGIDLenA, gFalse, gFalse);
94 SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
95 SplashFontFileID *idA,
96 SplashFontSrc *src,
97 int *codeToGIDA,
98 int codeToGIDLenA,
99 int faceIndexA) {
100 FT_Face faceA;
102 if (src->isFile) {
103 if (FT_New_Face(engineA->lib, src->fileName->getCString(), faceIndexA, &faceA))
104 return NULL;
105 } else {
106 if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, faceIndexA, &faceA))
107 return NULL;
110 return new SplashFTFontFile(engineA, idA, src,
111 faceA, codeToGIDA, codeToGIDLenA, gTrue, gFalse);
114 SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA,
115 SplashFontFileID *idA,
116 SplashFontSrc *src,
117 FT_Face faceA,
118 int *codeToGIDA, int codeToGIDLenA,
119 GBool trueTypeA, GBool type1A):
120 SplashFontFile(idA, src)
122 engine = engineA;
123 face = faceA;
124 codeToGID = codeToGIDA;
125 codeToGIDLen = codeToGIDLenA;
126 trueType = trueTypeA;
127 type1 = type1A;
130 SplashFTFontFile::~SplashFTFontFile() {
131 if (face) {
132 FT_Done_Face(face);
134 if (codeToGID) {
135 gfree(codeToGID);
139 SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat,
140 SplashCoord *textMat) {
141 SplashFont *font;
143 font = new SplashFTFont(this, mat, textMat);
144 font->initCache();
145 return font;
148 #endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H