]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | //======================================================================== |
2 | // | |
3 | // SplashT1FontFile.cc | |
4 | // | |
5 | //======================================================================== | |
6 | ||
7 | #include <config.h> | |
8 | ||
9 | #if HAVE_T1LIB_H | |
10 | ||
11 | #ifdef USE_GCC_PRAGMAS | |
12 | #pragma implementation | |
13 | #endif | |
14 | ||
15 | #include <string.h> | |
16 | #include <t1lib.h> | |
17 | #include "gmem.h" | |
18 | #include "SplashT1FontEngine.h" | |
19 | #include "SplashT1Font.h" | |
20 | #include "SplashT1FontFile.h" | |
21 | ||
22 | //------------------------------------------------------------------------ | |
23 | // SplashT1FontFile | |
24 | //------------------------------------------------------------------------ | |
25 | ||
26 | SplashFontFile *SplashT1FontFile::loadType1Font(SplashT1FontEngine *engineA, | |
27 | SplashFontFileID *idA, | |
28 | char *fileNameA, | |
29 | GBool deleteFileA, | |
30 | char **encA) { | |
31 | int t1libIDA; | |
32 | char **encTmp; | |
33 | char *encStrTmp; | |
34 | int encStrSize; | |
35 | char *encPtr; | |
36 | int i; | |
37 | ||
38 | // load the font file | |
39 | if ((t1libIDA = T1_AddFont(fileNameA)) < 0) { | |
40 | return NULL; | |
41 | } | |
42 | T1_LoadFont(t1libIDA); | |
43 | ||
44 | // reencode it | |
45 | encStrSize = 0; | |
46 | for (i = 0; i < 256; ++i) { | |
47 | if (encA[i]) { | |
48 | encStrSize += strlen(encA[i]) + 1; | |
49 | } | |
50 | } | |
51 | encTmp = (char **)gmallocn(257, sizeof(char *)); | |
52 | encStrTmp = (char *)gmallocn(encStrSize, sizeof(char)); | |
53 | encPtr = encStrTmp; | |
54 | for (i = 0; i < 256; ++i) { | |
55 | if (encA[i]) { | |
56 | strcpy(encPtr, encA[i]); | |
57 | encTmp[i] = encPtr; | |
58 | encPtr += strlen(encPtr) + 1; | |
59 | } else { | |
60 | encTmp[i] = ".notdef"; | |
61 | } | |
62 | } | |
63 | encTmp[256] = "custom"; | |
64 | T1_ReencodeFont(t1libIDA, encTmp); | |
65 | ||
66 | return new SplashT1FontFile(engineA, idA, fileNameA, deleteFileA, | |
67 | t1libIDA, encTmp, encStrTmp); | |
68 | } | |
69 | ||
70 | SplashT1FontFile::SplashT1FontFile(SplashT1FontEngine *engineA, | |
71 | SplashFontFileID *idA, | |
72 | char *fileNameA, GBool deleteFileA, | |
73 | int t1libIDA, char **encA, char *encStrA): | |
74 | SplashFontFile(idA, fileNameA, deleteFileA) | |
75 | { | |
76 | engine = engineA; | |
77 | t1libID = t1libIDA; | |
78 | enc = encA; | |
79 | encStr = encStrA; | |
80 | } | |
81 | ||
82 | SplashT1FontFile::~SplashT1FontFile() { | |
83 | gfree(encStr); | |
84 | gfree(enc); | |
85 | T1_DeleteFont(t1libID); | |
86 | } | |
87 | ||
88 | SplashFont *SplashT1FontFile::makeFont(SplashCoord *mat) { | |
89 | SplashFont *font; | |
90 | ||
91 | font = new SplashT1Font(this, mat); | |
92 | font->initCache(); | |
93 | return font; | |
94 | } | |
95 | ||
96 | #endif // HAVE_T1LIB_H |