• 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 <memory>
11 #include <utility>
12 #include <vector>
13 
14 #include "core/fxcrt/fx_system.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 #include "core/fxge/cfx_substfont.h"
17 #include "core/fxge/dib/cfx_dibitmap.h"
18 #include "core/fxge/fx_dib.h"
19 #include "core/fxge/fx_freetype.h"
20 
21 #if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
22 class SkTypeface;
23 
24 using CFX_TypeFace = SkTypeface;
25 #endif
26 
27 /* Font pitch and family flags */
28 #define FXFONT_FF_FIXEDPITCH (1 << 0)
29 #define FXFONT_FF_ROMAN (1 << 4)
30 #define FXFONT_FF_SCRIPT (4 << 4)
31 
32 /* Typical weight values */
33 #define FXFONT_FW_NORMAL 400
34 #define FXFONT_FW_BOLD 700
35 #define FXFONT_FW_BOLD_BOLD 900
36 
37 /* Font styles as defined in PDF 1.7 Table 5.20 */
38 #define FXFONT_NORMAL (0)
39 #define FXFONT_FIXED_PITCH (1 << 0)
40 #define FXFONT_SERIF (1 << 1)
41 #define FXFONT_SYMBOLIC (1 << 2)
42 #define FXFONT_SCRIPT (1 << 3)
43 #define FXFONT_NONSYMBOLIC (1 << 5)
44 #define FXFONT_ITALIC (1 << 6)
45 #define FXFONT_ALLCAP (1 << 16)
46 #define FXFONT_SMALLCAP (1 << 17)
47 #define FXFONT_BOLD (1 << 18)
48 
49 /* Other font flags */
50 #define FXFONT_USEEXTERNATTR 0x80000
51 #define FXFONT_CIDFONT 0x100000
52 #ifdef PDF_ENABLE_XFA
53 #define FXFONT_EXACTMATCH 0x80000000
54 #endif  // PDF_ENABLE_XFA
55 
56 #define GET_TT_SHORT(w) (uint16_t)(((w)[0] << 8) | (w)[1])
57 #define GET_TT_LONG(w) \
58   (uint32_t)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
59 
60 // Sets the given transform on the font, and resets it to the identity when it
61 // goes out of scope.
62 class ScopedFontTransform {
63  public:
64   ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix);
65   ~ScopedFontTransform();
66 
67  private:
68   FT_Face m_Face;
69 };
70 
71 class CFX_GlyphBitmap {
72  public:
73   CFX_GlyphBitmap();
74   ~CFX_GlyphBitmap();
75 
76   int m_Top;
77   int m_Left;
78   RetainPtr<CFX_DIBitmap> m_pBitmap;
79 };
80 
CFX_GlyphBitmap()81 inline CFX_GlyphBitmap::CFX_GlyphBitmap()
82     : m_pBitmap(pdfium::MakeRetain<CFX_DIBitmap>()) {}
83 
84 inline CFX_GlyphBitmap::~CFX_GlyphBitmap() = default;
85 
86 class FXTEXT_GLYPHPOS {
87  public:
88   FXTEXT_GLYPHPOS();
89   FXTEXT_GLYPHPOS(const FXTEXT_GLYPHPOS&);
90   ~FXTEXT_GLYPHPOS();
91 
92   const CFX_GlyphBitmap* m_pGlyph;
93   CFX_Point m_Origin;
94   CFX_PointF m_fOrigin;
95 };
96 
97 FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs,
98                            int anti_alias,
99                            float retinaScaleX,
100                            float retinaScaleY);
101 
102 ByteString GetNameFromTT(const uint8_t* name_table,
103                          uint32_t name_table_size,
104                          uint32_t name);
105 
106 int PDF_GetStandardFontName(ByteString* name);
107 
FontStyleIsBold(uint32_t style)108 inline bool FontStyleIsBold(uint32_t style) {
109   return !!(style & FXFONT_BOLD);
110 }
FontStyleIsItalic(uint32_t style)111 inline bool FontStyleIsItalic(uint32_t style) {
112   return !!(style & FXFONT_ITALIC);
113 }
FontStyleIsFixedPitch(uint32_t style)114 inline bool FontStyleIsFixedPitch(uint32_t style) {
115   return !!(style & FXFONT_FIXED_PITCH);
116 }
FontStyleIsSymbolic(uint32_t style)117 inline bool FontStyleIsSymbolic(uint32_t style) {
118   return !!(style & FXFONT_SYMBOLIC);
119 }
FontStyleIsNonSymbolic(uint32_t style)120 inline bool FontStyleIsNonSymbolic(uint32_t style) {
121   return !!(style & FXFONT_NONSYMBOLIC);
122 }
FontStyleIsAllCaps(uint32_t style)123 inline bool FontStyleIsAllCaps(uint32_t style) {
124   return !!(style & FXFONT_ALLCAP);
125 }
FontStyleIsSerif(uint32_t style)126 inline bool FontStyleIsSerif(uint32_t style) {
127   return !!(style & FXFONT_SERIF);
128 }
FontStyleIsScript(uint32_t style)129 inline bool FontStyleIsScript(uint32_t style) {
130   return !!(style & FXFONT_SCRIPT);
131 }
132 
FontFamilyIsFixedPitch(uint32_t family)133 inline bool FontFamilyIsFixedPitch(uint32_t family) {
134   return !!(family & FXFONT_FF_FIXEDPITCH);
135 }
FontFamilyIsRoman(uint32_t family)136 inline bool FontFamilyIsRoman(uint32_t family) {
137   return !!(family & FXFONT_FF_ROMAN);
138 }
FontFamilyIsScript(int32_t family)139 inline bool FontFamilyIsScript(int32_t family) {
140   return !!(family & FXFONT_FF_SCRIPT);
141 }
142 
143 #endif  // CORE_FXGE_FX_FONT_H_
144