• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
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/fx_coordinates.h"
13 #include "core/fxcrt/fx_string.h"
14 #include "core/fxcrt/fx_system.h"
15 #include "core/fxge/fx_freetype.h"
16 #include "third_party/base/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 #define FXFONT_CIDFONT 0x100000
43 
44 #define GET_TT_SHORT(w) (uint16_t)(((w)[0] << 8) | (w)[1])
45 #define GET_TT_LONG(w) \
46   (uint32_t)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
47 
48 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
49 class SkTypeface;
50 
51 using CFX_TypeFace = SkTypeface;
52 #endif
53 
54 class TextGlyphPos;
55 
56 FX_RECT GetGlyphsBBox(const std::vector<TextGlyphPos>& glyphs, int anti_alias);
57 
58 ByteString GetNameFromTT(pdfium::span<const uint8_t> name_table, uint32_t name);
59 int GetTTCIndex(pdfium::span<const uint8_t> pFontData, uint32_t font_offset);
60 
FontStyleIsForceBold(uint32_t style)61 inline bool FontStyleIsForceBold(uint32_t style) {
62   return !!(style & FXFONT_FORCE_BOLD);
63 }
FontStyleIsItalic(uint32_t style)64 inline bool FontStyleIsItalic(uint32_t style) {
65   return !!(style & FXFONT_ITALIC);
66 }
FontStyleIsFixedPitch(uint32_t style)67 inline bool FontStyleIsFixedPitch(uint32_t style) {
68   return !!(style & FXFONT_FIXED_PITCH);
69 }
FontStyleIsSymbolic(uint32_t style)70 inline bool FontStyleIsSymbolic(uint32_t style) {
71   return !!(style & FXFONT_SYMBOLIC);
72 }
FontStyleIsNonSymbolic(uint32_t style)73 inline bool FontStyleIsNonSymbolic(uint32_t style) {
74   return !!(style & FXFONT_NONSYMBOLIC);
75 }
FontStyleIsAllCaps(uint32_t style)76 inline bool FontStyleIsAllCaps(uint32_t style) {
77   return !!(style & FXFONT_ALLCAP);
78 }
FontStyleIsSerif(uint32_t style)79 inline bool FontStyleIsSerif(uint32_t style) {
80   return !!(style & FXFONT_SERIF);
81 }
FontStyleIsScript(uint32_t style)82 inline bool FontStyleIsScript(uint32_t style) {
83   return !!(style & FXFONT_SCRIPT);
84 }
85 
FontFamilyIsFixedPitch(uint32_t family)86 inline bool FontFamilyIsFixedPitch(uint32_t family) {
87   return !!(family & FXFONT_FF_FIXEDPITCH);
88 }
FontFamilyIsRoman(uint32_t family)89 inline bool FontFamilyIsRoman(uint32_t family) {
90   return !!(family & FXFONT_FF_ROMAN);
91 }
FontFamilyIsScript(int32_t family)92 inline bool FontFamilyIsScript(int32_t family) {
93   return !!(family & FXFONT_FF_SCRIPT);
94 }
95 
96 wchar_t PDF_UnicodeFromAdobeName(const char* name);
97 ByteString PDF_AdobeNameFromUnicode(wchar_t unicode);
98 
99 #endif  // CORE_FXGE_FX_FONT_H_
100