Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfx_font.h
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#ifndef CORE_FXGE_CFX_FONT_H_
8#define CORE_FXGE_CFX_FONT_H_
9
10#include <stdint.h>
11
12#include <memory>
13
14#include "build/build_config.h"
15#include "core/fxcrt/bytestring.h"
16#include "core/fxcrt/data_vector.h"
17#include "core/fxcrt/fx_codepage_forward.h"
18#include "core/fxcrt/fx_coordinates.h"
19#include "core/fxcrt/retain_ptr.h"
20#include "core/fxcrt/unowned_ptr_exclusion.h"
21#include "core/fxge/cfx_face.h"
22#include "core/fxge/freetype/fx_freetype.h"
23#include "third_party/abseil-cpp/absl/types/optional.h"
24#include "third_party/base/containers/span.h"
25
26#if defined(PDF_USE_SKIA)
27#include "core/fxge/fx_font.h"
28#endif
29
30class CFX_GlyphBitmap;
31class CFX_GlyphCache;
32class CFX_Path;
33class CFX_SubstFont;
36
37class CFX_Font {
38 public:
39 // This struct should be the same as FPDF_CharsetFontMap.
41 int charset; // Character Set Enum value, see FX_Charset::kXXX.
42 const char* fontname; // Name of default font to use with that charset.
43 };
44
45 enum class FontType {
48 };
49
50 // Pointer to the default character set to TT Font name map. The map is an
51 // array of CharsetFontMap structs, with its end indicated by a {-1, nullptr}
52 // entry.
53 static const CharsetFontMap kDefaultTTFMap[];
54
55 // Used when the font name is empty.
56 static const char kUntitledFontName[];
57
58 static const char kDefaultAnsiFontName[];
59 static const char kUniversalDefaultFontName[];
60
61 static ByteString GetDefaultFontNameByCharset(FX_Charset nCharset);
62 static FX_Charset GetCharSetFromUnicode(uint16_t word);
63
65 ~CFX_Font();
66
67 void LoadSubst(const ByteString& face_name,
68 bool bTrueType,
69 uint32_t flags,
70 int weight,
71 int italic_angle,
72 FX_CodePage code_page,
73 bool bVertical);
74
75 bool LoadEmbedded(pdfium::span<const uint8_t> src_span,
76 bool force_vertical,
77 uint64_t object_tag);
78 RetainPtr<CFX_Face> GetFace() const { return m_Face; }
79 FXFT_FaceRec* GetFaceRec() const {
80 return m_Face ? m_Face->GetRec() : nullptr;
81 }
82 CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); }
83 int GetSubstFontItalicAngle() const;
84
85#if defined(PDF_ENABLE_XFA)
87
88#if !BUILDFLAG(IS_WIN)
92#endif // !BUILDFLAG(IS_WIN)
93#endif // defined(PDF_ENABLE_XFA)
94
96 uint32_t glyph_index,
97 bool bFontStyle,
98 const CFX_Matrix& matrix,
99 int dest_width,
100 int anti_alias,
101 CFX_TextRenderOptions* text_options) const;
102 const CFX_Path* LoadGlyphPath(uint32_t glyph_index, int dest_width) const;
103 int GetGlyphWidth(uint32_t glyph_index) const;
104 int GetGlyphWidth(uint32_t glyph_index, int dest_width, int weight) const;
105 int GetAscent() const;
106 int GetDescent() const;
107 absl::optional<FX_RECT> GetGlyphBBox(uint32_t glyph_index);
108 bool IsItalic() const;
109 bool IsBold() const;
110 bool IsFixedWidth() const;
111 bool IsVertical() const { return m_bVertical; }
112 ByteString GetPsName() const;
113 ByteString GetFamilyName() const;
114 ByteString GetFaceName() const;
115 ByteString GetBaseFontName() const;
116 bool IsTTFont() const;
117
118 // Raw bounding box.
120
121 // Bounding box adjusted for font units.
122 absl::optional<FX_RECT> GetBBox() const;
123
124 bool IsEmbedded() const { return m_bEmbedded; }
125 FontType GetFontType() const { return m_FontType; }
126 void SetFontType(FontType type) { m_FontType = type; }
127 uint64_t GetObjectTag() const { return m_ObjectTag; }
128 pdfium::span<uint8_t> GetFontSpan() const { return m_FontData; }
129 std::unique_ptr<CFX_Path> LoadGlyphPathImpl(uint32_t glyph_index,
130 int dest_width) const;
131 int GetGlyphWidthImpl(uint32_t glyph_index, int dest_width, int weight) const;
132
133#if defined(PDF_USE_SKIA)
135 bool IsSubstFontBold() const;
136#endif
137
138#if BUILDFLAG(IS_APPLE)
139 void* GetPlatformFont() const { return m_pPlatformFont; }
140 void SetPlatformFont(void* font) { m_pPlatformFont = font; }
141#endif
142
143 private:
144 RetainPtr<CFX_GlyphCache> GetOrCreateGlyphCache() const;
145 void ClearGlyphCache();
146#if BUILDFLAG(IS_APPLE)
148#endif
149 ByteString GetFamilyNameOrUntitled() const;
150
151#if defined(PDF_ENABLE_XFA)
152 // |m_pOwnedFile| must outlive |m_pOwnedStreamRec|.
154 std::unique_ptr<FXFT_StreamRec> m_pOwnedStreamRec; // Must outlive |m_Face|.
155#endif
156
157 mutable RetainPtr<CFX_Face> m_Face;
158 mutable RetainPtr<CFX_GlyphCache> m_GlyphCache;
159 std::unique_ptr<CFX_SubstFont> m_pSubstFont;
160 DataVector<uint8_t> m_FontDataAllocation;
161 pdfium::span<uint8_t> m_FontData;
162 FontType m_FontType = FontType::kUnknown;
163 uint64_t m_ObjectTag = 0;
164 bool m_bEmbedded = false;
165 bool m_bVertical = false;
166#if BUILDFLAG(IS_APPLE)
168#endif
169};
170
171#endif // CORE_FXGE_CFX_FONT_H_
static ByteString GetDefaultFontNameByCharset(FX_Charset nCharset)
Definition cfx_font.cpp:103
int GetSubstFontItalicAngle() const
Definition cfx_font.cpp:164
int GetGlyphWidth(uint32_t glyph_index, int dest_width, int weight) const
Definition cfx_font.cpp:243
const CFX_GlyphBitmap * LoadGlyphBitmap(uint32_t glyph_index, bool bFontStyle, const CFX_Matrix &matrix, int dest_width, int anti_alias, CFX_TextRenderOptions *text_options) const
Definition cfx_font.cpp:453
const CFX_Path * LoadGlyphPath(uint32_t glyph_index, int dest_width) const
Definition cfx_font.cpp:465
absl::optional< FX_RECT > GetBBox() const
Definition cfx_font.cpp:418
int GetGlyphWidth(uint32_t glyph_index) const
Definition cfx_font.cpp:239
static const CharsetFontMap kDefaultTTFMap[]
Definition cfx_font.h:78
std::unique_ptr< CFX_Path > LoadGlyphPathImpl(uint32_t glyph_index, int dest_width) const
Definition cfx_font.cpp:444
absl::optional< FX_RECT > GetRawBBox() const
Definition cfx_font.cpp:412
ByteString GetPsName() const
Definition cfx_font.cpp:358
void SetFontType(FontType type)
Definition cfx_font.h:126
int GetDescent() const
Definition cfx_font.cpp:281
ByteString GetBaseFontName() const
Definition cfx_font.cpp:394
bool IsEmbedded() const
Definition cfx_font.h:124
bool IsItalic() const
Definition cfx_font.cpp:331
bool IsTTFont() const
Definition cfx_font.cpp:273
absl::optional< FX_RECT > GetGlyphBBox(uint32_t glyph_index)
Definition cfx_font.cpp:285
bool IsFixedWidth() const
Definition cfx_font.cpp:347
bool LoadEmbedded(pdfium::span< const uint8_t > src_span, bool force_vertical, uint64_t object_tag)
Definition cfx_font.cpp:260
pdfium::span< uint8_t > GetFontSpan() const
Definition cfx_font.h:128
int GetGlyphWidthImpl(uint32_t glyph_index, int dest_width, int weight) const
Definition cfx_font.cpp:250
static const char kDefaultAnsiFontName[]
Definition cfx_font.h:58
ByteString GetFaceName() const
Definition cfx_font.cpp:381
static const char kUniversalDefaultFontName[]
Definition cfx_font.h:59
static FX_Charset GetCharSetFromUnicode(uint16_t word)
Definition cfx_font.cpp:112
static const char kUntitledFontName[]
Definition cfx_font.h:56
FXFT_FaceRec * GetFaceRec() const
Definition cfx_font.h:79
bool IsVertical() const
Definition cfx_font.h:111
int GetAscent() const
Definition cfx_font.cpp:277
void LoadSubst(const ByteString &face_name, bool bTrueType, uint32_t flags, int weight, int italic_angle, FX_CodePage code_page, bool bVertical)
Definition cfx_font.cpp:220
CFX_SubstFont * GetSubstFont() const
Definition cfx_font.h:82
uint64_t GetObjectTag() const
Definition cfx_font.h:127
RetainPtr< CFX_Face > GetFace() const
Definition cfx_font.h:78
bool IsBold() const
Definition cfx_font.cpp:343
FontType GetFontType() const
Definition cfx_font.h:125
ByteString GetFamilyName() const
Definition cfx_font.cpp:368
float GetLineDashPhase() const
float GetLineWidth() const
CFX_GraphStateData::LineCap GetLineCap() const
CFX_GraphStateData::LineJoin GetLineJoin() const
bool HasRef() const
const CPDF_Color * GetStrokeColor() const
const CPDF_Color * GetFillColor() const
bool GetRGB(int *R, int *G, int *B) const
bool IsColorSpaceRGB() const
const ByteString & GetName() const
const ByteString & GetPropertyName() const
ParamType GetParamType() const
virtual ~FormFactoryIface()=default
virtual std::unique_ptr< FormIface > CreateForm(CPDF_Document *pDocument, RetainPtr< CPDF_Dictionary > pPageResources, RetainPtr< CPDF_Stream > pFormStream)=0
virtual ~FormIface()=default
virtual CFX_FloatRect CalcBoundingBox() const =0
virtual void ParseContentForType3Char(CPDF_Type3Char *pChar)=0
virtual absl::optional< std::pair< RetainPtr< CFX_DIBitmap >, CFX_Matrix > > GetBitmapAndMatrixFromSoleImageOfForm() const =0
virtual bool HasPageObjects() const =0
int GetItalicAngle() const
Definition cpdf_font.h:120
virtual FX_RECT GetCharBBox(uint32_t charcode)=0
virtual bool IsTrueTypeFont() const
Definition cpdf_font.cpp:67
virtual const CPDF_CIDFont * AsCIDFont() const
UnownedPtr< CPDF_Document > const m_pDocument
Definition cpdf_font.h:169
int m_ItalicAngle
Definition cpdf_font.h:182
virtual int GetCharWidthF(uint32_t charcode)=0
const FX_RECT & GetFontBBox() const
Definition cpdf_font.h:113
virtual void WillBeDestroyed()
int GetTypeDescent() const
Definition cpdf_font.h:115
static bool UseTTCharmapMSSymbol(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:149
int FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode)
void LoadFontDescriptor(const CPDF_Dictionary *pFontDesc)
virtual CPDF_CIDFont * AsCIDFont()
RetainPtr< CPDF_Dictionary > m_pFontDict
Definition cpdf_font.h:174
static constexpr uint32_t kInvalidCharCode
Definition cpdf_font.h:63
static int TT2PDF(FT_Pos m, const RetainPtr< CFX_Face > &face)
void ClearFontDict()
Definition cpdf_font.h:108
absl::optional< FX_Charset > GetSubstFontCharset() const
virtual bool IsType1Font() const
Definition cpdf_font.cpp:63
virtual bool IsVertWriting() const
RetainPtr< CPDF_StreamAcc > m_pFontFile
Definition cpdf_font.h:173
CPDF_Font(CPDF_Document *pDocument, RetainPtr< CPDF_Dictionary > pFontDict)
Definition cpdf_font.cpp:52
~CPDF_Font() override
Definition cpdf_font.cpp:58
void LoadUnicodeMap() const
static RetainPtr< CPDF_Font > Create(CPDF_Document *pDoc, RetainPtr< CPDF_Dictionary > pFontDict, FormFactoryIface *pFactory)
virtual uint32_t CharCodeFromUnicode(wchar_t Unicode) const
virtual int GlyphFromCharCode(uint32_t charcode, bool *pVertGlyph)=0
static bool UseTTCharmapMacRoman(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:152
const CFX_Font * GetFont() const
Definition cpdf_font.h:131
static bool UseTTCharmapMSUnicode(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:146
virtual const CPDF_TrueTypeFont * AsTrueTypeFont() const
Definition cpdf_font.cpp:87
virtual const CPDF_Type1Font * AsType1Font() const
Definition cpdf_font.cpp:79
std::unique_ptr< CPDF_ToUnicodeMap > m_pToUnicodeMap
Definition cpdf_font.h:176
int m_Flags
Definition cpdf_font.h:178
RetainPtr< const CPDF_Dictionary > GetFontDict() const
Definition cpdf_font.h:103
void SetResourceName(const ByteString &name)
Definition cpdf_font.h:136
virtual bool IsCIDFont() const
Definition cpdf_font.cpp:75
std::vector< std::unique_ptr< CFX_Font > > m_FontFallbacks
Definition cpdf_font.h:172
int m_StemV
Definition cpdf_font.h:179
virtual WideString UnicodeFromCharCode(uint32_t charcode) const
CFX_Font * GetFont()
Definition cpdf_font.h:130
virtual const CPDF_Type3Font * AsType3Font() const
Definition cpdf_font.cpp:95
static RetainPtr< CPDF_Font > GetStockFont(CPDF_Document *pDoc, ByteStringView fontname)
static bool UseTTCharmap(const RetainPtr< CFX_Face > &face, int platform_id, int encoding_id)
virtual size_t CountChar(ByteStringView pString) const
void AppendChar(ByteString *str, uint32_t charcode) const
int GetStringWidth(ByteStringView pString)
RetainPtr< CPDF_Dictionary > GetMutableFontDict()
Definition cpdf_font.h:102
virtual CPDF_Type1Font * AsType1Font()
Definition cpdf_font.cpp:83
ByteString m_BaseFontName
Definition cpdf_font.h:175
ByteString GetBaseFontName() const
Definition cpdf_font.h:99
virtual bool HasFontWidths() const
virtual bool IsType3Font() const
Definition cpdf_font.cpp:71
virtual CPDF_Type3Font * AsType3Font()
Definition cpdf_font.cpp:99
bool FontDictIs(const CPDF_Dictionary *pThat) const
Definition cpdf_font.h:105
static const char * GetAdobeCharName(FontEncoding base_encoding, const std::vector< ByteString > &charnames, uint32_t charcode)
ByteString m_ResourceName
Definition cpdf_font.h:170
virtual CPDF_TrueTypeFont * AsTrueTypeFont()
Definition cpdf_font.cpp:91
const ByteString & GetResourceName() const
Definition cpdf_font.h:135
FX_RECT m_FontBBox
Definition cpdf_font.h:183
int GetFontWeight() const
bool HasFace() const
Definition cpdf_font.h:110
virtual int AppendChar(char *buf, uint32_t charcode) const
int m_Ascent
Definition cpdf_font.h:180
int m_Descent
Definition cpdf_font.h:181
uint32_t GetFontDictObjNum() const
Definition cpdf_font.h:104
virtual uint32_t GetNextChar(ByteStringView pString, size_t *pOffset) const
virtual bool Load()=0
bool m_bToUnicodeLoaded
Definition cpdf_font.h:177
uint32_t FallbackFontFromCharcode(uint32_t charcode)
virtual bool IsUnicodeCompatible() const =0
bool IsStandardFont() const
static FX_RECT GetCharBBoxForFace(const RetainPtr< CFX_Face > &face)
CPDF_Document * GetDocument() const
Definition cpdf_font.h:128
void CheckFontMetrics()
CFX_Font m_Font
Definition cpdf_font.h:171
bool IsEmbedded() const
Definition cpdf_font.h:101
int GetTypeAscent() const
Definition cpdf_font.h:114
int GetFontFlags() const
Definition cpdf_font.h:119
CFX_Font * GetFontFallback(int position)
const CFX_Matrix & form_matrix() const
float GetStrokeAlpha() const
BlendMode GetBlendType() const
ByteString GetBlendMode() const
void SetImage(RetainPtr< CPDF_Image > pImage)
const CFX_Matrix & matrix() const
bool ProcessPageObjects(fxcrt::ostringstream *buf)
CPDF_PageContentGenerator(CPDF_PageObjectHolder *pObjHolder)
void UpdateStream(size_t stream_index, fxcrt::ostringstream *buf)
size_t AddStream(fxcrt::ostringstream *buf)
CPDF_PageContentManager(CPDF_PageObjectHolder *page_obj_holder, CPDF_Document *document)
const CPDF_ColorState & color_state() const
void SetDirty(bool value)
const CPDF_GeneralState & general_state() const
const ByteString & GetResourceName() const
const CPDF_ClipPath & clip_path() const
virtual Type GetType() const =0
CPDF_GeneralState & mutable_general_state()
const CPDF_ContentMarks * GetContentMarks() const
void SetResourceName(const ByteString &resource_name)
const CFX_GraphState & graph_state() const
bool has_winding_filltype() const
bool stroke() const
const CFX_Matrix & matrix() const
bool has_alternate_filltype() const
bool has_no_filltype() const
bool IsRect() const
Definition cpdf_path.cpp:37
CPDF_SimpleFont(CPDF_Document *pDocument, RetainPtr< CPDF_Dictionary > pFontDict)
std::vector< ByteString > m_CharNames
~CPDF_SimpleFont() override
uint16_t m_GlyphIndex[kInternalTableSize]
int GlyphFromCharCode(uint32_t charcode, bool *pVertGlyph) override
static constexpr size_t kInternalTableSize
int GetCharWidthF(uint32_t charcode) override
void LoadCharMetrics(int charcode)
CPDF_FontEncoding m_Encoding
uint32_t CharCodeFromUnicode(wchar_t Unicode) const override
bool IsUnicodeCompatible() const override
void LoadCharWidths(const CPDF_Dictionary *font_desc)
FX_RECT m_CharBBox[kInternalTableSize]
FX_RECT GetCharBBox(uint32_t charcode) override
void LoadPDFEncoding(bool bEmbedded, bool bTrueType)
uint16_t m_CharWidth[kInternalTableSize]
FontEncoding m_BaseEncoding
bool HasFontWidths() const override
void LoadDifferences(const CPDF_Dictionary *encoding)
const CPDF_FontEncoding * GetEncoding() const
WideString UnicodeFromCharCode(uint32_t charcode) const override
virtual void LoadGlyphMap()=0
ByteString GetImageDecoder() const
ByteString ComputeDigest() const
void LoadAllDataFilteredWithEstimatedSize(uint32_t estimated_size)
CPDF_StreamAcc & operator=(const CPDF_StreamAcc &)=delete
pdfium::span< const uint8_t > GetSpan() const
CPDF_StreamAcc(const CPDF_StreamAcc &)=delete
uint64_t KeyForCache() const
int GetLength1ForTest() const
uint32_t GetSize() const
~CPDF_StreamAcc() override
void LoadAllDataImageAcc(uint32_t estimated_size)
RetainPtr< const CPDF_Dictionary > GetImageParam() const
RetainPtr< const CPDF_Stream > GetStream() const
DataVector< uint8_t > DetachData()
~CPDF_StringArchiveStream() override
CPDF_StringArchiveStream(fxcrt::ostringstream *stream)
FX_FILESIZE CurrentOffset() const override
bool WriteBlock(pdfium::span< const uint8_t > buffer) override
CFX_Matrix GetTextMatrix() const
float GetFontSize() const
TextRenderingMode GetTextRenderMode() const
bool IsTrueTypeFont() const override
void LoadGlyphMap() override
CPDF_TrueTypeFont * AsTrueTypeFont() override
const CPDF_TrueTypeFont * AsTrueTypeFont() const override
~CPDF_TrueTypeFont() override
static ByteString Format(const char *pFormat,...)
ByteString & operator=(ByteString &&that) noexcept
bool IsEmpty() const
Definition bytestring.h:119
CharType operator[](const size_t index) const
Definition bytestring.h:150
FontEncoding
ByteString PDF_NameEncode(const ByteString &orig)
FX_Charset
Definition fx_codepage.h:70
FX_CodePage
Definition fx_codepage.h:18
BlendMode
Definition fx_dib.h:49
#define FX_FILESIZE
Definition fx_types.h:19
#define CHECK(cvref)
#define CONSTRUCT_VIA_MAKE_RETAIN
Definition retain_ptr.h:224
const char * fontname
Definition cfx_font.h:42