PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfFontMetricsFreetype.h
1
7#ifndef PDF_FONT_METRICS_FREETYPE_H
8#define PDF_FONT_METRICS_FREETYPE_H
9
10#include "PdfDeclarations.h"
11
12#include "PdfFontMetrics.h"
13#include "PdfString.h"
14
15namespace PoDoFo {
16
17struct PdfEncodingLimits;
18
19class PODOFO_API PdfFontMetricsFreetype final : public PdfFontMetrics
20{
21 friend class PdfFontMetrics;
22
23public:
24 ~PdfFontMetricsFreetype();
25
26 std::unique_ptr<PdfCMapEncoding> CreateToUnicodeMap(const PdfEncodingLimits& limitHints) const override;
27
28 bool HasUnicodeMapping() const override;
29
30 bool TryGetGID(char32_t codePoint, unsigned& gid) const override;
31
32 double GetDefaultWidthRaw() const override;
33
34 double GetLineSpacing() const override;
35
36 double GetUnderlineThickness() const override;
37
38 double GetUnderlinePosition() const override;
39
40 double GetStrikeThroughPosition() const override;
41
42 double GetStrikeThroughThickness() const override;
43
44 std::string_view GetFontName() const override;
45
46 std::string_view GetFontFamilyName() const override;
47
48 unsigned char GetSubsetPrefixLength() const override;
49
50 PdfFontStretch GetFontStretch() const override;
51
52 bool TryGetFlags(PdfFontDescriptorFlags& value) const override;
53
54 bool TryGetBoundingBox(Corners& value) const override;
55
56 bool TryGetItalicAngle(double& value) const override;
57
58 bool TryGetAscent(double& value) const override;
59
60 bool TryGetDescent(double& value) const override;
61
62 bool TryGetCapHeight(double& value) const override;
63
64 bool TryGetStemV(double& value) const override;
65
66 double GetLeadingRaw() const override;
67
68 int GetWeightRaw() const override;
69
70 double GetXHeightRaw() const override;
71
72 double GetStemHRaw() const override;
73
74 double GetAvgWidthRaw() const override;
75
76 double GetMaxWidthRaw() const override;
77
78 PdfFontFileType GetFontFileType() const override;
79
80 unsigned GetFontFileLength1() const override;
81
82 unsigned GetFontFileLength2() const override;
83
84 unsigned GetFontFileLength3() const override;
85
86 const datahandle& GetFontFileDataHandle() const override;
87
88 FT_Face GetFaceHandle() const override;
89
90protected:
91 std::string_view GetBaseFontName() const override;
92
93 unsigned GetGlyphCountFontProgram() const override;
94
95 bool TryGetGlyphWidthFontProgram(unsigned gid, double& width) const override;
96
97 bool getIsBoldHint() const override;
98
99 bool getIsItalicHint() const override;
100
101 const PdfCIDToGIDMapConstPtr& getCIDToGIDMap() const override;
102
103private:
104 PdfFontMetricsFreetype(FT_Face face, const datahandle& data, const PdfFontMetrics* refMetrics = nullptr);
105
106 void init(const PdfFontMetrics* refMetrics);
107
108 void ensureLengthsReady();
109
110 void initType1Lengths(const bufferview& view);
111
112 bool tryBuildFallbackUnicodeMap();
113
114private:
115 FT_Face m_Face;
116 datahandle m_Data;
117 PdfCIDToGIDMapConstPtr m_CIDToGIDMap;
118 PdfFontFileType m_FontFileType;
119
120 unsigned char m_SubsetPrefixLength;
121 bool m_HasUnicodeMapping;
122 std::unique_ptr<std::unordered_map<uint32_t, unsigned>> m_fallbackUnicodeMap;
123
124 std::string m_FontBaseName;
125 std::string m_FontName;
126 std::string m_FontFamilyName;
127
128 // Conditionally required metrics
130 Corners m_BBox;
131 double m_ItalicAngle;
132 double m_Ascent;
133 double m_Descent;
134 double m_CapHeight;
135 double m_StemV;
136
137 // Optional metrics
138 PdfFontStretch m_FontStretch;
139 int m_Weight;
140 double m_Leading;
141 double m_XHeight;
142 double m_StemH;
143 double m_AvgWidth;
144 double m_MaxWidth;
145 double m_DefaultWidth;
146
147 // Computed metrics
148 double m_LineSpacing;
149 double m_UnderlineThickness;
150 double m_UnderlinePosition;
151 double m_StrikeThroughThickness;
152 double m_StrikeThroughPosition;
153
154 bool m_LengthsReady;
155 unsigned m_Length1;
156 unsigned m_Length2;
157 unsigned m_Length3;
158};
159
160};
161
162#endif // PDF_FONT_METRICS_FREETYPE_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
PdfFontFileType
Definition PdfDeclarations.h:296
PdfFontDescriptorFlags
Enum for the font descriptor flags.
Definition PdfDeclarations.h:252