Coverage Report

Created: 2026-08-31 06:45

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