/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 | 0 | { |
40 | 0 | FT_Face faceA; |
41 | 0 | const char *name; |
42 | 0 | int i; |
43 | |
|
44 | 0 | 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 | 0 | } else { |
49 | 0 | if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) { |
50 | 0 | return nullptr; |
51 | 0 | } |
52 | 0 | } |
53 | 0 | std::vector<int> codeToGIDA; |
54 | 0 | codeToGIDA.resize(256, 0); |
55 | 0 | for (i = 0; i < 256; ++i) { |
56 | 0 | if ((name = encA[i])) { |
57 | 0 | codeToGIDA[i] = static_cast<int>(FT_Get_Name_Index(faceA, const_cast<char *>(name))); |
58 | 0 | if (codeToGIDA[i] == 0) { |
59 | 0 | name = GfxFont::getAlternateName(name); |
60 | 0 | if (name) { |
61 | 0 | codeToGIDA[i] = FT_Get_Name_Index(faceA, const_cast<char *>(name)); |
62 | 0 | } |
63 | 0 | } |
64 | 0 | } |
65 | 0 | } |
66 | |
|
67 | 0 | return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), false, true); |
68 | 0 | } |
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 | 0 | { |
72 | 0 | FT_Face faceA; |
73 | |
|
74 | 0 | 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 | 0 | } else { |
79 | 0 | if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) { |
80 | 0 | return nullptr; |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | 0 | return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), false, false); |
85 | 0 | } |
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 | 0 | { |
89 | 0 | FT_Face faceA; |
90 | |
|
91 | 0 | if (src->isFile()) { |
92 | 0 | if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) { |
93 | 0 | return nullptr; |
94 | 0 | } |
95 | 0 | } else { |
96 | 0 | if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) { |
97 | 0 | return nullptr; |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | 0 | return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), true, false); |
102 | 0 | } |
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 | 0 | : SplashFontFile(std::move(idA), std::move(srcA)) |
106 | 0 | { |
107 | 0 | engine = engineA; |
108 | 0 | face = faceA; |
109 | 0 | codeToGID = std::move(codeToGIDA); |
110 | 0 | trueType = trueTypeA; |
111 | 0 | type1 = type1A; |
112 | 0 | } |
113 | | |
114 | | SplashFTFontFile::~SplashFTFontFile() |
115 | 0 | { |
116 | 0 | if (face) { |
117 | 0 | FT_Done_Face(face); |
118 | 0 | } |
119 | 0 | } |
120 | | |
121 | | SplashFont *SplashFTFontFile::makeFont(const std::array<double, 4> &mat, const std::array<double, 4> &textMat) |
122 | 0 | { |
123 | 0 | SplashFont *font; |
124 | |
|
125 | 0 | font = new SplashFTFont(this->shared_from_this(), mat, textMat); |
126 | 0 | font->initCache(); |
127 | 0 | return font; |
128 | 0 | } |