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
fx_font.h
Go to the documentation of this file.
1// Copyright 2014 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_FX_FONT_H_
8#define CORE_FXGE_FX_FONT_H_
9
10#include <stdint.h>
11
12#include <vector>
13
14#include "core/fxcrt/bytestring.h"
15#include "core/fxcrt/fx_coordinates.h"
16#include "core/fxcrt/span.h"
17
18/* Font pitch and family flags */
19#define FXFONT_FF_FIXEDPITCH (1 << 0)
20#define FXFONT_FF_ROMAN (1 << 4)
21#define FXFONT_FF_SCRIPT (4 << 4)
22
23/* Typical weight values */
24#define FXFONT_FW_NORMAL 400
25#define FXFONT_FW_BOLD 700
26#define FXFONT_FW_BOLD_BOLD 900
27
28/* Font styles as defined in PDF 1.7 Table 5.20 */
29#define FXFONT_NORMAL (0)
30#define FXFONT_FIXED_PITCH (1 << 0)
31#define FXFONT_SERIF (1 << 1)
32#define FXFONT_SYMBOLIC (1 << 2)
33#define FXFONT_SCRIPT (1 << 3)
34#define FXFONT_NONSYMBOLIC (1 << 5)
35#define FXFONT_ITALIC (1 << 6)
36#define FXFONT_ALLCAP (1 << 16)
37#define FXFONT_SMALLCAP (1 << 17)
38#define FXFONT_FORCE_BOLD (1 << 18)
39
40/* Other font flags */
41#define FXFONT_USEEXTERNATTR 0x80000
42
43// These numbers come from the OpenType name table specification.
44constexpr uint16_t kNamePlatformAppleUnicode = 0;
45constexpr uint16_t kNamePlatformMac = 1;
46constexpr uint16_t kNamePlatformWindows = 3;
47
48#if defined(PDF_USE_SKIA)
49class SkTypeface;
50
51using CFX_TypeFace = SkTypeface;
52#endif
53
54class TextGlyphPos;
55
56FX_RECT GetGlyphsBBox(const std::vector<TextGlyphPos>& glyphs, int anti_alias);
57
58ByteString GetNameFromTT(pdfium::span<const uint8_t> name_table, uint32_t name);
59size_t GetTTCIndex(pdfium::span<const uint8_t> pFontData, size_t font_offset);
60
61inline bool FontStyleIsForceBold(uint32_t style) {
62 return !!(style & FXFONT_FORCE_BOLD);
63}
64inline bool FontStyleIsItalic(uint32_t style) {
65 return !!(style & FXFONT_ITALIC);
66}
67inline bool FontStyleIsFixedPitch(uint32_t style) {
68 return !!(style & FXFONT_FIXED_PITCH);
69}
70inline bool FontStyleIsSymbolic(uint32_t style) {
71 return !!(style & FXFONT_SYMBOLIC);
72}
73inline bool FontStyleIsNonSymbolic(uint32_t style) {
74 return !!(style & FXFONT_NONSYMBOLIC);
75}
76inline bool FontStyleIsAllCaps(uint32_t style) {
77 return !!(style & FXFONT_ALLCAP);
78}
79inline bool FontStyleIsSerif(uint32_t style) {
80 return !!(style & FXFONT_SERIF);
81}
82inline bool FontStyleIsScript(uint32_t style) {
83 return !!(style & FXFONT_SCRIPT);
84}
85
86inline bool FontFamilyIsFixedPitch(uint32_t family) {
87 return !!(family & FXFONT_FF_FIXEDPITCH);
88}
89inline bool FontFamilyIsRoman(uint32_t family) {
90 return !!(family & FXFONT_FF_ROMAN);
91}
92inline bool FontFamilyIsScript(int32_t family) {
93 return !!(family & FXFONT_FF_SCRIPT);
94}
95
96wchar_t UnicodeFromAdobeName(const char* name);
97ByteString AdobeNameFromUnicode(wchar_t unicode);
98
99// Take a font metric `value` and scale it down by the font's `upem`. If the
100// font is not scalable, i.e. `upem` is 0, then return `value` as is.
101// If the computed result is excessively large and does not fit in an int,
102// NormalizeFontMetric() handles that with `saturated_cast()`.
103int NormalizeFontMetric(int64_t value, uint16_t upem);
104
105#endif // CORE_FXGE_FX_FONT_H_
fxcrt::ByteString ByteString
Definition bytestring.h:180
#define DCHECK
Definition check.h:33
#define DCHECK_EQ(x, y)
Definition check_op.h:17
CFX_FloatRect(const FX_RECT &rect)
FX_RECT GetOuterRect() const
static constexpr uint32_t MakeTag(char c1, char c2, char c3, char c4)
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
constexpr CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
std::vector< RetainPtr< CPDF_Object > >::const_iterator const_iterator
Definition cpdf_array.h:29
~CPDF_CIDFont() override
size_t CountChar(ByteStringView pString) const override
uint32_t GetNextChar(ByteStringView pString, size_t *pOffset) const override
bool IsCIDFont() const override
bool IsUnicodeCompatible() const override
CFX_Point16 GetVertOrigin(uint16_t cid) const
int GetCharWidthF(uint32_t charcode) override
const CPDF_CIDFont * AsCIDFont() const override
uint16_t CIDFromCharCode(uint32_t charcode) const
bool Load() override
const CIDTransform * GetCIDTransform(uint16_t cid) const
int GlyphFromCharCode(uint32_t charcode, bool *pVertGlyph) override
int16_t GetVertWidth(uint16_t cid) const
FX_RECT GetCharBBox(uint32_t charcode) override
static float CIDTransformToFloat(uint8_t ch)
void AppendChar(ByteString *str, uint32_t charcode) const override
bool IsVertWriting() const override
uint32_t CharCodeFromUnicode(wchar_t Unicode) const override
int GetCharSize(uint32_t charcode) const
WideString UnicodeFromCharCode(uint32_t charcode) const override
CPDF_CIDFont * AsCIDFont() override
static CIDSet CharsetFromOrdering(ByteStringView ordering)
CPDF_CMapParser(CPDF_CMap *pCMap)
void ParseWord(ByteStringView word)
bool IsVertWriting() const
Definition cpdf_cmap.h:62
void SetVertical(bool vert)
Definition cpdf_cmap.h:71
~CPDF_CMap() override
static constexpr size_t kDirectMapTableSize
Definition cpdf_cmap.h:38
CIDCoding GetCoding() const
Definition cpdf_cmap.h:76
size_t CountChar(ByteStringView pString) const
uint32_t GetNextChar(ByteStringView pString, size_t *pOffset) const
void SetCharset(CIDSet set)
Definition cpdf_cmap.h:79
bool IsLoaded() const
Definition cpdf_cmap.h:61
@ MixedTwoBytes
Definition cpdf_cmap.h:43
@ MixedFourBytes
Definition cpdf_cmap.h:44
const fxcmap::CMap * GetEmbedMap() const
Definition cpdf_cmap.h:77
uint16_t CIDFromCharCode(uint32_t charcode) const
void SetAdditionalMappings(std::vector< CIDRange > mappings)
int GetCharSize(uint32_t charcode) const
bool IsDirectCharcodeToCIDTableIsEmpty() const
Definition cpdf_cmap.h:84
void AppendChar(ByteString *str, uint32_t charcode) const
void SetMixedFourByteLeadingRanges(std::vector< CodeRange > ranges)
CIDSet GetCharset() const
Definition cpdf_cmap.h:78
void SetDirectCharcodeToCIDTableRange(uint32_t start_code, uint32_t end_code, uint16_t start_cid)
void SetCodingScheme(CodingScheme scheme)
Definition cpdf_cmap.h:72
std::map< ByteString, RetainPtr< CPDF_Object >, std::less<> > DictMap
static CPDF_FontGlobals * GetInstance()
void LoadFontDescriptor(const CPDF_Dictionary *pFontDesc)
virtual uint32_t CharCodeFromUnicode(wchar_t Unicode) const
static bool UseTTCharmapMacRoman(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:147
static bool UseTTCharmapMSUnicode(const RetainPtr< CFX_Face > &face)
Definition cpdf_font.h:141
virtual WideString UnicodeFromCharCode(uint32_t charcode) const
void CheckFontMetrics()
bool IsEmbedded() const
Definition cpdf_font.h:100
bool operator==(const char *ptr) const
WideString(wchar_t ch)
WideString()=default
CIDSet
@ CIDSET_JAPAN1
@ CIDSET_UNKNOWN
@ CIDSET_GB1
@ CIDSET_NUM_SETS
CIDCoding
Definition cpdf_cmap.h:25
uint32_t CharCodeFromUnicodeForEncoding(fxge::FontEncoding encoding, wchar_t unicode)
FontEncoding
FX_CodePage FX_GetCodePageFromCharset(FX_Charset charset)
size_t FX_WideCharToMultiByte(FX_CodePage codepage, WideStringView wstr, pdfium::span< char > buf)
FX_Charset
Definition fx_codepage.h:71
@ kChineseTraditional
Definition fx_codepage.h:91
@ kMSWin_EasternEuropean
@ kChineseSimplified
Definition fx_codepage.h:90
@ kMAC_ChineseTraditional
Definition fx_codepage.h:79
@ kMAC_ChineseSimplified
Definition fx_codepage.h:78
@ kMAC_EasternEuropean
Definition fx_codepage.h:85
@ kMSWin_Vietnamese
Definition fx_codepage.h:94
size_t FX_MultiByteToWideChar(FX_CodePage codepage, ByteStringView bstr, pdfium::span< wchar_t > buf)
const std::array< FX_CharsetUnicodes, 8 > kFX_CharsetUnicodes
FX_Charset FX_GetCharsetFromCodePage(FX_CodePage codepage)
FX_CodePage FX_GetACP()
FX_Charset FX_GetCharsetFromInt(int value)
FX_CodePage
Definition fx_codepage.h:19
@ kChineseTraditional
Definition fx_codepage.h:42
@ kMSWin_EasternEuropean
Definition fx_codepage.h:45
@ kMAC_ChineseTraditional
Definition fx_codepage.h:57
@ kMAC_ChineseSimplified
Definition fx_codepage.h:63
@ kMAC_EasternEuropean
Definition fx_codepage.h:65
@ kMSDOS_EasternEuropean
Definition fx_codepage.h:27
@ kMSDOS_FrenchCanadian
Definition fx_codepage.h:33
@ kMSWin_WesternEuropean
Definition fx_codepage.h:47
@ kMSDOS_WesternEuropean
Definition fx_codepage.h:26
bool FX_CharSetIsCJK(FX_Charset uCharset)
CFX_PTemplate< int16_t > CFX_Point16
bool FontFamilyIsFixedPitch(uint32_t family)
Definition fx_font.h:86
constexpr uint16_t kNamePlatformMac
Definition fx_font.h:45
int NormalizeFontMetric(int64_t value, uint16_t upem)
Definition fx_font.cpp:150
#define FXFONT_FF_SCRIPT
Definition fx_font.h:21
#define FXFONT_FF_ROMAN
Definition fx_font.h:20
ByteString GetNameFromTT(pdfium::span< const uint8_t > name_table, uint32_t name)
Definition fx_font.cpp:81
bool FontStyleIsSerif(uint32_t style)
Definition fx_font.h:79
bool FontStyleIsFixedPitch(uint32_t style)
Definition fx_font.h:67
#define FXFONT_NONSYMBOLIC
Definition fx_font.h:34
#define FXFONT_SERIF
Definition fx_font.h:31
wchar_t UnicodeFromAdobeName(const char *name)
Definition fx_font.cpp:140
#define FXFONT_FW_NORMAL
Definition fx_font.h:24
FX_RECT GetGlyphsBBox(const std::vector< TextGlyphPos > &glyphs, int anti_alias)
Definition fx_font.cpp:37
bool FontFamilyIsScript(int32_t family)
Definition fx_font.h:92
#define FXFONT_ITALIC
Definition fx_font.h:35
bool FontStyleIsNonSymbolic(uint32_t style)
Definition fx_font.h:73
bool FontStyleIsSymbolic(uint32_t style)
Definition fx_font.h:70
bool FontFamilyIsRoman(uint32_t family)
Definition fx_font.h:89
#define FXFONT_SYMBOLIC
Definition fx_font.h:32
bool FontStyleIsItalic(uint32_t style)
Definition fx_font.h:64
#define FXFONT_SCRIPT
Definition fx_font.h:33
#define FXFONT_FORCE_BOLD
Definition fx_font.h:38
size_t GetTTCIndex(pdfium::span< const uint8_t > pFontData, size_t font_offset)
Definition fx_font.cpp:128
constexpr uint16_t kNamePlatformAppleUnicode
Definition fx_font.h:44
bool FontStyleIsAllCaps(uint32_t style)
Definition fx_font.h:76
ByteString AdobeNameFromUnicode(wchar_t unicode)
Definition fx_font.cpp:144
#define FXFONT_FF_FIXEDPITCH
Definition fx_font.h:19
#define FXFONT_ALLCAP
Definition fx_font.h:36
constexpr uint16_t kNamePlatformWindows
Definition fx_font.h:46
bool FontStyleIsScript(uint32_t style)
Definition fx_font.h:82
bool FontStyleIsForceBold(uint32_t style)
Definition fx_font.h:61
#define FXFONT_FIXED_PITCH
Definition fx_font.h:30
pdfium::CheckedNumeric< int32_t > FX_SAFE_INT32
FX_BIDICLASS
Definition fx_unicode.h:13
constexpr wchar_t kBoxDrawingsLightVerical
Definition fx_unicode.h:102
wchar_t GetMirrorChar(wchar_t wch)
constexpr wchar_t kZeroWidthNoBreakSpace
Definition fx_unicode.h:103
constexpr wchar_t kRightSingleQuotationMark
Definition fx_unicode.h:99
constexpr wchar_t kLineSeparator
Definition fx_unicode.h:100
FX_BIDICLASS GetBidiClass(wchar_t wch)
constexpr wchar_t kParagraphSeparator
Definition fx_unicode.h:101
#define CONSTRUCT_VIA_MAKE_RETAIN
Definition retain_ptr.h:222
fxcrt::ByteStringView ByteStringView
fxcrt::WideStringView WideStringView
uint16_t cid
uint16_t m_StartCID
Definition cpdf_cmap.h:56
uint32_t m_StartCode
Definition cpdf_cmap.h:54
std::array< uint8_t, 4 > m_Upper
Definition cpdf_cmap.h:50
std::array< uint8_t, 4 > m_Lower
Definition cpdf_cmap.h:49
FX_Charset m_Charset
pdfium::span< const uint16_t > m_pUnicodes
FX_RECT & operator=(const FX_RECT &that)=default
fxcrt::WideString WideString
Definition widestring.h:207