1//========================================================================
2//
3// SplashFTFontFile.cc
4//
5//========================================================================
6
7//========================================================================
8//
9// Modified under the Poppler project - http://poppler.freedesktop.org
10//
11// All changes made under the Poppler project to this file are licensed
12// under GPL version 2 or later
13//
14// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
15// Copyright (C) 2014, 2017, 2022 Adrian Johnson <ajohnson@redneon.com>
16// Copyright (C) 2017, 2018, 2022 Oliver Sander <oliver.sander@tu-dresden.de>
17// Copyright (C) 2018 Albert Astals Cid <aacid@kde.org>
18//
19// To see a description of the changes please see the Changelog file that
20// came with your tarball or type make ChangeLog if you are building from git
21//
22//========================================================================
23
24#include <config.h>
25
26#include "goo/ft_utils.h"
27#include "goo/gmem.h"
28#include "goo/GooString.h"
29#include "poppler/GfxFont.h"
30#include "SplashFTFontEngine.h"
31#include "SplashFTFont.h"
32#include "SplashFTFontFile.h"
33
34//------------------------------------------------------------------------
35// SplashFTFontFile
36//------------------------------------------------------------------------
37
38SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, SplashFontFileID *idA, SplashFontSrc *src, const char **encA)
39{
40 FT_Face faceA;
41 int *codeToGIDA;
42 const char *name;
43 int i;
44
45 if (src->isFile) {
46 if (ft_new_face_from_file(library: engineA->lib, filename_utf8: src->fileName.c_str(), face_index: 0, aface: &faceA)) {
47 return nullptr;
48 }
49 } else {
50 if (FT_New_Memory_Face(library: engineA->lib, file_base: (const FT_Byte *)src->buf.data(), file_size: src->buf.size(), face_index: 0, aface: &faceA)) {
51 return nullptr;
52 }
53 }
54 codeToGIDA = (int *)gmallocn(count: 256, size: sizeof(int));
55 for (i = 0; i < 256; ++i) {
56 codeToGIDA[i] = 0;
57 if ((name = encA[i])) {
58 codeToGIDA[i] = (int)FT_Get_Name_Index(face: faceA, glyph_name: (char *)name);
59 if (codeToGIDA[i] == 0) {
60 name = GfxFont::getAlternateName(name);
61 if (name) {
62 codeToGIDA[i] = FT_Get_Name_Index(face: faceA, glyph_name: (char *)name);
63 }
64 }
65 }
66 }
67
68 return new SplashFTFontFile(engineA, idA, src, faceA, codeToGIDA, 256, false, true);
69}
70
71SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, SplashFontFileID *idA, SplashFontSrc *src, int *codeToGIDA, int codeToGIDLenA)
72{
73 FT_Face faceA;
74
75 if (src->isFile) {
76 if (ft_new_face_from_file(library: engineA->lib, filename_utf8: src->fileName.c_str(), face_index: 0, aface: &faceA)) {
77 return nullptr;
78 }
79 } else {
80 if (FT_New_Memory_Face(library: engineA->lib, file_base: (const FT_Byte *)src->buf.data(), file_size: src->buf.size(), face_index: 0, aface: &faceA)) {
81 return nullptr;
82 }
83 }
84
85 return new SplashFTFontFile(engineA, idA, src, faceA, codeToGIDA, codeToGIDLenA, false, false);
86}
87
88SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA, SplashFontFileID *idA, SplashFontSrc *src, int *codeToGIDA, int codeToGIDLenA, int faceIndexA)
89{
90 FT_Face faceA;
91
92 if (src->isFile) {
93 if (ft_new_face_from_file(library: engineA->lib, filename_utf8: src->fileName.c_str(), face_index: faceIndexA, aface: &faceA)) {
94 return nullptr;
95 }
96 } else {
97 if (FT_New_Memory_Face(library: engineA->lib, file_base: (const FT_Byte *)src->buf.data(), file_size: src->buf.size(), face_index: faceIndexA, aface: &faceA)) {
98 return nullptr;
99 }
100 }
101
102 return new SplashFTFontFile(engineA, idA, src, faceA, codeToGIDA, codeToGIDLenA, true, false);
103}
104
105SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA, SplashFontFileID *idA, SplashFontSrc *srcA, FT_Face faceA, int *codeToGIDA, int codeToGIDLenA, bool trueTypeA, bool type1A) : SplashFontFile(idA, srcA)
106{
107 engine = engineA;
108 face = faceA;
109 codeToGID = codeToGIDA;
110 codeToGIDLen = codeToGIDLenA;
111 trueType = trueTypeA;
112 type1 = type1A;
113}
114
115SplashFTFontFile::~SplashFTFontFile()
116{
117 if (face) {
118 FT_Done_Face(face);
119 }
120 if (codeToGID) {
121 gfree(p: codeToGID);
122 }
123}
124
125SplashFont *SplashFTFontFile::makeFont(SplashCoord *mat, const SplashCoord *textMat)
126{
127 SplashFont *font;
128
129 font = new SplashFTFont(this, mat, textMat);
130 font->initCache();
131 return font;
132}
133

source code of poppler/splash/SplashFTFontFile.cc