]> git.ipfire.org Git - thirdparty/cups.git/blame - pdftops/SplashFTFontEngine.cxx
Load cups into easysw/current.
[thirdparty/cups.git] / pdftops / SplashFTFontEngine.cxx
CommitLineData
ef416fc2 1//========================================================================
2//
3// SplashFTFontEngine.cc
4//
5//========================================================================
6
7#include <config.h>
8
9#if HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H
10
11#ifdef USE_GCC_PRAGMAS
12#pragma implementation
13#endif
14
15#include <stdio.h>
16#ifndef WIN32
17# include <unistd.h>
18#endif
19#include "gmem.h"
20#include "GString.h"
21#include "gfile.h"
22#include "FoFiTrueType.h"
23#include "FoFiType1C.h"
24#include "SplashFTFontFile.h"
25#include "SplashFTFontEngine.h"
26
27#ifdef VMS
28#if (__VMS_VER < 70000000)
29extern "C" int unlink(char *filename);
30#endif
31#endif
32
33//------------------------------------------------------------------------
34
35static void fileWrite(void *stream, char *data, int len) {
36 fwrite(data, 1, len, (FILE *)stream);
37}
38
39//------------------------------------------------------------------------
40// SplashFTFontEngine
41//------------------------------------------------------------------------
42
43SplashFTFontEngine::SplashFTFontEngine(GBool aaA, FT_Library libA) {
44 FT_Int major, minor, patch;
45
46 aa = aaA;
47 lib = libA;
48
49 // as of FT 2.1.8, CID fonts are indexed by CID instead of GID
50 FT_Library_Version(lib, &major, &minor, &patch);
51 useCIDs = major > 2 ||
52 (major == 2 && (minor > 1 || (minor == 1 && patch > 7)));
53}
54
55SplashFTFontEngine *SplashFTFontEngine::init(GBool aaA) {
56 FT_Library libA;
57
58 if (FT_Init_FreeType(&libA)) {
59 return NULL;
60 }
61 return new SplashFTFontEngine(aaA, libA);
62}
63
64SplashFTFontEngine::~SplashFTFontEngine() {
65 FT_Done_FreeType(lib);
66}
67
68SplashFontFile *SplashFTFontEngine::loadType1Font(SplashFontFileID *idA,
69 char *fileName,
70 GBool deleteFile,
71 char **enc) {
72 return SplashFTFontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
73}
74
75SplashFontFile *SplashFTFontEngine::loadType1CFont(SplashFontFileID *idA,
76 char *fileName,
77 GBool deleteFile,
78 char **enc) {
79 return SplashFTFontFile::loadType1Font(this, idA, fileName, deleteFile, enc);
80}
81
82SplashFontFile *SplashFTFontEngine::loadCIDFont(SplashFontFileID *idA,
83 char *fileName,
84 GBool deleteFile) {
85 FoFiType1C *ff;
86 Gushort *cidToGIDMap;
87 int nCIDs;
88 SplashFontFile *ret;
89
90 // check for a CFF font
91 if (useCIDs) {
92 cidToGIDMap = NULL;
93 nCIDs = 0;
94 } else if ((ff = FoFiType1C::load(fileName))) {
95 cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
96 delete ff;
97 } else {
98 cidToGIDMap = NULL;
99 nCIDs = 0;
100 }
101 ret = SplashFTFontFile::loadCIDFont(this, idA, fileName, deleteFile,
102 cidToGIDMap, nCIDs);
103 if (!ret) {
104 gfree(cidToGIDMap);
105 }
106 return ret;
107}
108
109SplashFontFile *SplashFTFontEngine::loadTrueTypeFont(SplashFontFileID *idA,
110 char *fileName,
111 GBool deleteFile,
112 Gushort *codeToGID,
113 int codeToGIDLen) {
114 FoFiTrueType *ff;
115 GString *tmpFileName;
116 FILE *tmpFile;
117 SplashFontFile *ret;
118
119 if (!(ff = FoFiTrueType::load(fileName))) {
120 return NULL;
121 }
122 tmpFileName = NULL;
123 if (!openTempFile(&tmpFileName, &tmpFile, "wb", NULL)) {
124 delete ff;
125 return NULL;
126 }
127 ff->writeTTF(&fileWrite, tmpFile);
128 delete ff;
129 fclose(tmpFile);
130 ret = SplashFTFontFile::loadTrueTypeFont(this, idA,
131 tmpFileName->getCString(),
132 gTrue, codeToGID, codeToGIDLen);
133 if (ret) {
134 if (deleteFile) {
135 unlink(fileName);
136 }
137 } else {
138 unlink(tmpFileName->getCString());
139 }
140 delete tmpFileName;
141 return ret;
142}
143
144#endif // HAVE_FREETYPE_FREETYPE_H || HAVE_FREETYPE_H