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