/src/poppler/splash/SplashFTFontFile.cc
Line | Count | Source |
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, 2024-2026 Albert Astals Cid <aacid@kde.org> |
18 | | // Copyright (C) 2024-2026 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk> |
19 | | // |
20 | | // To see a description of the changes please see the Changelog file that |
21 | | // came with your tarball or type make ChangeLog if you are building from git |
22 | | // |
23 | | //======================================================================== |
24 | | |
25 | | #include <config.h> |
26 | | |
27 | | #include "goo/ft_utils.h" |
28 | | #include "poppler/GfxFont.h" |
29 | | #include "SplashFTFontEngine.h" |
30 | | #include "SplashFTFont.h" |
31 | | #include "SplashFTFontFile.h" |
32 | | #include "SplashFontFileID.h" |
33 | | |
34 | | //------------------------------------------------------------------------ |
35 | | // SplashFTFontFile |
36 | | //------------------------------------------------------------------------ |
37 | | |
38 | | std::shared_ptr<SplashFontFile> SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> src, const std::array<const char *, 256> &encA, int faceIndexA) |
39 | 52.8k | { |
40 | 52.8k | FT_Face faceA; |
41 | 52.8k | const char *name; |
42 | 52.8k | int i; |
43 | | |
44 | 52.8k | if (src->isFile()) { |
45 | 0 | if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) { |
46 | 0 | return nullptr; |
47 | 0 | } |
48 | 52.8k | } else { |
49 | 52.8k | if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) { |
50 | 26.8k | return nullptr; |
51 | 26.8k | } |
52 | 52.8k | } |
53 | 25.9k | std::vector<int> codeToGIDA; |
54 | 25.9k | codeToGIDA.resize(256, 0); |
55 | 6.67M | for (i = 0; i < 256; ++i) { |
56 | 6.64M | if ((name = encA[i])) { |
57 | 4.12M | codeToGIDA[i] = static_cast<int>(FT_Get_Name_Index(faceA, const_cast<char *>(name))); |
58 | 4.12M | if (codeToGIDA[i] == 0) { |
59 | 3.09M | name = GfxFont::getAlternateName(name); |
60 | 3.09M | if (name) { |
61 | 30.3k | codeToGIDA[i] = FT_Get_Name_Index(faceA, const_cast<char *>(name)); |
62 | 30.3k | } |
63 | 3.09M | } |
64 | 4.12M | } |
65 | 6.64M | } |
66 | | |
67 | 25.9k | return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), false, true); |
68 | 52.8k | } |
69 | | |
70 | | std::shared_ptr<SplashFontFile> SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> src, std::vector<int> &&codeToGIDA, int faceIndexA) |
71 | 2.87k | { |
72 | 2.87k | FT_Face faceA; |
73 | | |
74 | 2.87k | if (src->isFile()) { |
75 | 0 | if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) { |
76 | 0 | return nullptr; |
77 | 0 | } |
78 | 2.87k | } else { |
79 | 2.87k | if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) { |
80 | 865 | return nullptr; |
81 | 865 | } |
82 | 2.87k | } |
83 | | |
84 | 2.00k | return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), false, false); |
85 | 2.87k | } |
86 | | |
87 | | std::shared_ptr<SplashFontFile> SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> src, std::vector<int> &&codeToGIDA, int faceIndexA) |
88 | 112k | { |
89 | 112k | FT_Face faceA; |
90 | | |
91 | 112k | if (src->isFile()) { |
92 | 78.5k | if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) { |
93 | 0 | return nullptr; |
94 | 0 | } |
95 | 78.5k | } else { |
96 | 34.3k | if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) { |
97 | 15.3k | return nullptr; |
98 | 15.3k | } |
99 | 34.3k | } |
100 | | |
101 | 97.5k | return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), true, false); |
102 | 112k | } |
103 | | |
104 | | SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> srcA, FT_Face faceA, std::vector<int> &&codeToGIDA, bool trueTypeA, bool type1A, PrivateTag /*unused*/) |
105 | 125k | : SplashFontFile(std::move(idA), std::move(srcA)) |
106 | 125k | { |
107 | 125k | engine = engineA; |
108 | 125k | face = faceA; |
109 | 125k | codeToGID = std::move(codeToGIDA); |
110 | 125k | trueType = trueTypeA; |
111 | 125k | type1 = type1A; |
112 | 125k | } |
113 | | |
114 | | SplashFTFontFile::~SplashFTFontFile() |
115 | 125k | { |
116 | 125k | if (face) { |
117 | 125k | FT_Done_Face(face); |
118 | 125k | } |
119 | 125k | } |
120 | | |
121 | | SplashFont *SplashFTFontFile::makeFont(const std::array<double, 4> &mat, const std::array<double, 4> &textMat) |
122 | 203k | { |
123 | 203k | SplashFont *font; |
124 | | |
125 | 203k | font = new SplashFTFont(this->shared_from_this(), mat, textMat); |
126 | 203k | font->initCache(); |
127 | 203k | return font; |
128 | 203k | } |