Coverage Report

Created: 2026-03-31 07:04

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