beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / splash / SplashT1FontFile.cc
blob1832a916d9ae3730e9f95501737bd98ff6622c7a
1 //========================================================================
2 //
3 // SplashT1FontFile.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 Albert Astals Cid <aacid@kde.org>
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_T1LIB_H
26 #ifdef USE_GCC_PRAGMAS
27 #pragma implementation
28 #endif
30 #include <string.h>
31 #include <t1lib.h>
32 #include "goo/GooString.h"
33 #include "goo/gfile.h"
34 #include "goo/gmem.h"
35 #include "SplashT1FontEngine.h"
36 #include "SplashT1Font.h"
37 #include "SplashT1FontFile.h"
39 //------------------------------------------------------------------------
40 // SplashT1FontFile
41 //------------------------------------------------------------------------
43 SplashFontFile *SplashT1FontFile::loadType1Font(SplashT1FontEngine *engineA,
44 SplashFontFileID *idA,
45 SplashFontSrc *src,
46 const char **encA) {
47 int t1libIDA;
48 const char **encTmp;
49 char *encStrTmp;
50 int encStrSize;
51 char *encPtr;
52 int i;
54 GooString *fileNameA;
55 SplashFontSrc *newsrc = NULL;
56 SplashFontFile *ff;
58 if (! src->isFile) {
59 GooString *tmpFileName;
60 FILE *tmpFile;
61 if (!openTempFile(&tmpFileName, &tmpFile, "wb"))
62 return NULL;
63 fwrite(src->buf, 1, src->bufLen, tmpFile);
64 fclose(tmpFile);
65 newsrc = new SplashFontSrc;
66 newsrc->setFile(tmpFileName, gTrue);
67 src = newsrc;
68 delete tmpFileName;
70 fileNameA = src->fileName;
71 // load the font file
72 if ((t1libIDA = T1_AddFont(fileNameA->getCString())) < 0) {
73 delete newsrc;
74 return NULL;
76 T1_LoadFont(t1libIDA);
78 // reencode it
79 encStrSize = 0;
80 for (i = 0; i < 256; ++i) {
81 if (encA[i]) {
82 encStrSize += strlen(encA[i]) + 1;
85 encTmp = (const char **)gmallocn(257, sizeof(char *));
86 encStrTmp = (char *)gmallocn(encStrSize, sizeof(char));
87 encPtr = encStrTmp;
88 for (i = 0; i < 256; ++i) {
89 if (encA[i]) {
90 strcpy(encPtr, encA[i]);
91 encTmp[i] = encPtr;
92 encPtr += strlen(encPtr) + 1;
93 } else {
94 encTmp[i] = ".notdef";
97 encTmp[256] = "custom";
98 T1_ReencodeFont(t1libIDA, (char **)encTmp);
100 ff = new SplashT1FontFile(engineA, idA, src,
101 t1libIDA, encTmp, encStrTmp);
102 if (newsrc)
103 newsrc->unref();
104 return ff;
107 SplashT1FontFile::SplashT1FontFile(SplashT1FontEngine *engineA,
108 SplashFontFileID *idA,
109 SplashFontSrc *srcA,
110 int t1libIDA, const char **encA, char *encStrA):
111 SplashFontFile(idA, srcA)
113 engine = engineA;
114 t1libID = t1libIDA;
115 enc = encA;
116 encStr = encStrA;
119 SplashT1FontFile::~SplashT1FontFile() {
120 gfree(encStr);
121 gfree(enc);
122 T1_DeleteFont(t1libID);
125 SplashFont *SplashT1FontFile::makeFont(SplashCoord *mat,
126 SplashCoord *textMat) {
127 SplashFont *font;
129 font = new SplashT1Font(this, mat, textMat);
130 font->initCache();
131 return font;
134 #endif // HAVE_T1LIB_H