Coverage Report

Created: 2026-05-30 06:25

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.72k
            const char **encA) {
34
2.72k
  FT_Face faceA;
35
2.72k
  int *codeToGIDA;
36
2.72k
  const char *name;
37
2.72k
  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.72k
  if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
44
1.56k
#endif
45
1.56k
    return NULL;
46
1.56k
  }
47
1.16k
  codeToGIDA = (int *)gmallocn(256, sizeof(int));
48
299k
  for (i = 0; i < 256; ++i) {
49
298k
    codeToGIDA[i] = 0;
50
298k
    if ((name = encA[i])) {
51
216k
      codeToGIDA[i] = (int)FT_Get_Name_Index(faceA, (char *)name);
52
216k
    }
53
298k
  }
54
55
1.16k
  return new SplashFTFontFile(engineA, idA, fontTypeA,
56
#if LOAD_FONTS_FROM_MEM
57
            fontBufA,
58
#else
59
1.16k
            fileNameA, deleteFileA,
60
1.16k
#endif
61
1.16k
            faceA, codeToGIDA, 256);
62
2.72k
}
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
74
                int codeToGIDLenA) {
75
74
  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
74
  if (FT_New_Face(engineA->lib, fileNameA, 0, &faceA)) {
82
39
#endif
83
39
    return NULL;
84
39
  }
85
86
35
  return new SplashFTFontFile(engineA, idA, fontTypeA,
87
#if LOAD_FONTS_FROM_MEM
88
            fontBufA,
89
#else
90
35
            fileNameA, deleteFileA,
91
35
#endif
92
35
            faceA, codeToGIDA, codeToGIDLenA);
93
74
}
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
2.75k
               int codeToGIDLenA) {
107
2.75k
  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
2.75k
  if (FT_New_Face(engineA->lib, fileNameA, fontNum, &faceA)) {
114
203
#endif
115
203
    return NULL;
116
203
  }
117
118
2.54k
  return new SplashFTFontFile(engineA, idA, fontTypeA,
119
#if LOAD_FONTS_FROM_MEM
120
            fontBufA,
121
#else
122
2.54k
            fileNameA, deleteFileA,
123
2.54k
#endif
124
2.54k
            faceA, codeToGIDA, codeToGIDLenA);
125
2.75k
}
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
3.74k
  SplashFontFile(idA, fontTypeA, fileNameA, deleteFileA)
141
#endif
142
3.74k
{
143
3.74k
  engine = engineA;
144
3.74k
  face = faceA;
145
3.74k
  codeToGID = codeToGIDA;
146
3.74k
  codeToGIDLen = codeToGIDLenA;
147
3.74k
}
148
149
3.74k
SplashFTFontFile::~SplashFTFontFile() {
150
3.74k
  if (face) {
151
3.74k
    FT_Done_Face(face);
152
3.74k
  }
153
3.74k
  if (codeToGID) {
154
2.70k
    gfree(codeToGID);
155
2.70k
  }
156
3.74k
}
157
158
SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat,
159
6.14k
               SplashCoord *textMat) {
160
6.14k
  SplashFont *font;
161
162
6.14k
  font = new SplashFTFont(this, mat, textMat);
163
6.14k
  font->initCache();
164
6.14k
  return font;
165
6.14k
}
166
167
#endif // HAVE_FREETYPE_H