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 <vector> 11 12 #include "core/fxcrt/bytestring.h" 13 #include "core/fxcrt/fx_coordinates.h" 14 #include "third_party/base/span.h" 15 16 /* Font pitch and family flags */ 17 #define FXFONT_FF_FIXEDPITCH (1 << 0) 18 #define FXFONT_FF_ROMAN (1 << 4) 19 #define FXFONT_FF_SCRIPT (4 << 4) 20 21 /* Typical weight values */ 22 #define FXFONT_FW_NORMAL 400 23 #define FXFONT_FW_BOLD 700 24 #define FXFONT_FW_BOLD_BOLD 900 25 26 /* Font styles as defined in PDF 1.7 Table 5.20 */ 27 #define FXFONT_NORMAL (0) 28 #define FXFONT_FIXED_PITCH (1 << 0) 29 #define FXFONT_SERIF (1 << 1) 30 #define FXFONT_SYMBOLIC (1 << 2) 31 #define FXFONT_SCRIPT (1 << 3) 32 #define FXFONT_NONSYMBOLIC (1 << 5) 33 #define FXFONT_ITALIC (1 << 6) 34 #define FXFONT_ALLCAP (1 << 16) 35 #define FXFONT_SMALLCAP (1 << 17) 36 #define FXFONT_FORCE_BOLD (1 << 18) 37 38 /* Other font flags */ 39 #define FXFONT_USEEXTERNATTR 0x80000 40 41 // These numbers come from the OpenType name table specification. 42 constexpr uint16_t kNamePlatformAppleUnicode = 0; 43 constexpr uint16_t kNamePlatformMac = 1; 44 constexpr uint16_t kNamePlatformWindows = 3; 45 46 #if defined(_SKIA_SUPPORT_) 47 class SkTypeface; 48 49 using CFX_TypeFace = SkTypeface; 50 #endif 51 52 class TextGlyphPos; 53 54 FX_RECT GetGlyphsBBox(const std::vector<TextGlyphPos>& glyphs, int anti_alias); 55 56 ByteString GetNameFromTT(pdfium::span<const uint8_t> name_table, uint32_t name); 57 size_t GetTTCIndex(pdfium::span<const uint8_t> pFontData, size_t font_offset); 58 FontStyleIsForceBold(uint32_t style)59inline bool FontStyleIsForceBold(uint32_t style) { 60 return !!(style & FXFONT_FORCE_BOLD); 61 } FontStyleIsItalic(uint32_t style)62inline bool FontStyleIsItalic(uint32_t style) { 63 return !!(style & FXFONT_ITALIC); 64 } FontStyleIsFixedPitch(uint32_t style)65inline bool FontStyleIsFixedPitch(uint32_t style) { 66 return !!(style & FXFONT_FIXED_PITCH); 67 } FontStyleIsSymbolic(uint32_t style)68inline bool FontStyleIsSymbolic(uint32_t style) { 69 return !!(style & FXFONT_SYMBOLIC); 70 } FontStyleIsNonSymbolic(uint32_t style)71inline bool FontStyleIsNonSymbolic(uint32_t style) { 72 return !!(style & FXFONT_NONSYMBOLIC); 73 } FontStyleIsAllCaps(uint32_t style)74inline bool FontStyleIsAllCaps(uint32_t style) { 75 return !!(style & FXFONT_ALLCAP); 76 } FontStyleIsSerif(uint32_t style)77inline bool FontStyleIsSerif(uint32_t style) { 78 return !!(style & FXFONT_SERIF); 79 } FontStyleIsScript(uint32_t style)80inline bool FontStyleIsScript(uint32_t style) { 81 return !!(style & FXFONT_SCRIPT); 82 } 83 FontFamilyIsFixedPitch(uint32_t family)84inline bool FontFamilyIsFixedPitch(uint32_t family) { 85 return !!(family & FXFONT_FF_FIXEDPITCH); 86 } FontFamilyIsRoman(uint32_t family)87inline bool FontFamilyIsRoman(uint32_t family) { 88 return !!(family & FXFONT_FF_ROMAN); 89 } FontFamilyIsScript(int32_t family)90inline bool FontFamilyIsScript(int32_t family) { 91 return !!(family & FXFONT_FF_SCRIPT); 92 } 93 94 wchar_t UnicodeFromAdobeName(const char* name); 95 ByteString AdobeNameFromUnicode(wchar_t unicode); 96 97 #endif // CORE_FXGE_FX_FONT_H_ 98