Coverage Report

Created: 2026-02-04 06:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/xpdf-4.06/splash/SplashFTFontFile.cc
Line
Count
Source
1
//========================================================================
2
//
3
// SplashFTFontFile.cc
4
//
5
// Copyright 2003-2013 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#include <aconf.h>
10
11
#if HAVE_FREETYPE_H
12
13
#include "gmem.h"
14
#include "gmempp.h"
15
#include "GString.h"
16
#include "SplashFTFontEngine.h"
17
#include "SplashFTFont.h"
18
#include "SplashFTFontFile.h"
19
20
//------------------------------------------------------------------------
21
// SplashFTFontFile
22
//------------------------------------------------------------------------
23
24
SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA,
25
            SplashFontFileID *idA,
26
            SplashFontType fontTypeA,
27
#if LOAD_FONTS_FROM_MEM
28
            GString *fontBufA,
29
#else
30
            char *fileNameA,
31
            GBool deleteFileA,
32
#endif
33
2.10k
            const char **encA) {
34
2.10k
  FT_Face faceA;
35
2.10k
  int *codeToGIDA;
36
2.10k
  const char *name;
37
2.10k
  int i;
38
39
#if LOAD_FONTS_FROM_MEM
40
  if (FT_New_Memory_Face(engineA->lib, (FT_Byte *)fontBufA->getCString(),
41
       fontBufA->getLength(), 0, &faceA)) {
42
#else
43
2.10k
  if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
44
1.07k
#endif
45
1.07k
    return NULL;
46
1.07k
  }
47
1.03k
  codeToGIDA = (int *)gmallocn(256, sizeof(int));
48
265k
  for (i = 0; i < 256; ++i) {
49
264k
    codeToGIDA[i] = 0;
50
264k
    if ((name = encA[i])) {
51
198k
      codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);
52
198k
    }
53
264k
  }
54
55
1.03k
  return new SplashFTFontFile(engineA, idA, fontTypeA,
56
#if LOAD_FONTS_FROM_MEM
57
            fontBufA,
58
#else
59
1.03k
            fileNameA, deleteFileA,
60
1.03k
#endif
61
1.03k
            faceA, codeToGIDA, 256);
62
2.10k
}
63
64
SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA,
65
                SplashFontFileID *idA,
66
                SplashFontType fontTypeA,
67
#if LOAD_FONTS_FROM_MEM
68
                GString *fontBufA,
69
#else
70
                char *fileNameA,
71
                GBool deleteFileA,
72
#endif
73
                int *codeToGIDA,
74
19
                int codeToGIDLenA) {
75
19
  FT_Face faceA;
76
77
#if LOAD_FONTS_FROM_MEM
78
  if (FT_New_Memory_Face(engineA->lib, (FT_Byte *)fontBufA->getCString(),
79
       fontBufA->getLength(), 0, &faceA)) {
80
#else
81
19
  if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
82
4
#endif
83
4
    return NULL;
84
4
  }
85
86
15
  return new SplashFTFontFile(engineA, idA, fontTypeA,
87
#if LOAD_FONTS_FROM_MEM
88
            fontBufA,
89
#else
90
15
            fileNameA, deleteFileA,
91
15
#endif
92
15
            faceA, codeToGIDA, codeToGIDLenA);
93
19
}
94
95
SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
96
               SplashFontFileID *idA,
97
               SplashFontType fontTypeA,
98
#if LOAD_FONTS_FROM_MEM
99
               GString *fontBufA,
100
#else
101
               char *fileNameA,
102
               GBool deleteFileA,
103
#endif
104
               int fontNum,
105
               int *codeToGIDA,
106
1.53k
               int codeToGIDLenA) {
107
1.53k
  FT_Face faceA;
108
109
#if LOAD_FONTS_FROM_MEM
110
  if (FT_New_Memory_Face(engineA->lib, (FT_Byte *)fontBufA->getCString(),
111
       fontBufA->getLength(), fontNum, &faceA)) {
112
#else
113
1.53k
  if (FT_New_Face(engineA->lib, fileNameA, fontNum, &faceA)) {
114
78
#endif
115
78
    return NULL;
116
78
  }
117
118
1.45k
  return new SplashFTFontFile(engineA, idA, fontTypeA,
119
#if LOAD_FONTS_FROM_MEM
120
            fontBufA,
121
#else
122
1.45k
            fileNameA, deleteFileA,
123
1.45k
#endif
124
1.45k
            faceA, codeToGIDA, codeToGIDLenA);
125
1.53k
}
126
127
SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA,
128
           SplashFontFileID *idA,
129
           SplashFontType fontTypeA,
130
#if LOAD_FONTS_FROM_MEM
131
           GString *fontBufA,
132
#else
133
           char *fileNameA, GBool deleteFileA,
134
#endif
135
           FT_Face faceA,
136
           int *codeToGIDA, int codeToGIDLenA):
137
#if LOAD_FONTS_FROM_MEM
138
  SplashFontFile(idA, fontTypeA, fontBufA)
139
#else
140
2.50k
  SplashFontFile(idA, fontTypeA, fileNameA, deleteFileA)
141
#endif
142
2.50k
{
143
2.50k
  engine = engineA;
144
2.50k
  face = faceA;
145
2.50k
  codeToGID = codeToGIDA;
146
2.50k
  codeToGIDLen = codeToGIDLenA;
147
2.50k
}
148
149
2.50k
SplashFTFontFile::~SplashFTFontFile() {
150
2.50k
  if (face) {
151
2.50k
    FT_Done_Face(face);
152
2.50k
  }
153
2.50k
  if (codeToGID) {
154
2.16k
    gfree(codeToGID);
155
2.16k
  }
156
2.50k
}
157
158
SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat,
159
2.57k
               SplashCoord *textMat) {
160
2.57k
  SplashFont *font;
161
162
2.57k
  font = new SplashFTFont(this, mat, textMat);
163
2.57k
  font->initCache();
164
2.57k
  return font;
165
2.57k
}
166
167
#endif // HAVE_FREETYPE_H