• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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 #ifndef CORE_FXGE_CFX_FACE_H_
6 #define CORE_FXGE_CFX_FACE_H_
7 
8 #include <stdint.h>
9 
10 #include <array>
11 #include <memory>
12 #include <optional>
13 #include <vector>
14 
15 #include "build/build_config.h"
16 #include "core/fxcrt/bytestring.h"
17 #include "core/fxcrt/fx_coordinates.h"
18 #include "core/fxcrt/observed_ptr.h"
19 #include "core/fxcrt/retain_ptr.h"
20 #include "core/fxcrt/span.h"
21 #include "core/fxge/freetype/fx_freetype.h"
22 
23 namespace fxge {
24 enum class FontEncoding : uint32_t;
25 }
26 
27 class CFX_Font;
28 class CFX_GlyphBitmap;
29 class CFX_Path;
30 class CFX_SubstFont;
31 
32 class CFX_Face final : public Retainable, public Observable {
33  public:
34   using CharMap = void*;
35 
36   struct CharCodeAndIndex {
37     uint32_t char_code;
38     uint32_t glyph_index;
39   };
40 
41   static RetainPtr<CFX_Face> New(FT_Library library,
42                                  RetainPtr<Retainable> pDesc,
43                                  pdfium::span<const FT_Byte> data,
44                                  FT_Long face_index);
45 
46   static RetainPtr<CFX_Face> Open(FT_Library library,
47                                   const FT_Open_Args* args,
48                                   FT_Long face_index);
49 
50   bool HasGlyphNames() const;
51   bool IsTtOt() const;
52   bool IsTricky() const;
53   bool IsFixedWidth() const;
54 
55 #if defined(PDF_ENABLE_XFA)
56   bool IsScalable() const;
57   void ClearExternalStream();
58 #endif
59 
60   bool IsItalic() const;
61   bool IsBold() const;
62 
63   ByteString GetFamilyName() const;
64   ByteString GetStyleName() const;
65 
66   FX_RECT GetBBox() const;
67   uint16_t GetUnitsPerEm() const;
68   int16_t GetAscender() const;
69   int16_t GetDescender() const;
70 #if BUILDFLAG(IS_ANDROID)
71   int16_t GetHeight() const;
72 #endif
73 
74   pdfium::span<uint8_t> GetData() const;
75 
76   // Returns the size of the data, or 0 on failure. Only write into `buffer` if
77   // it is large enough to hold the data.
78   size_t GetSfntTable(uint32_t table, pdfium::span<uint8_t> buffer);
79 
80   std::optional<std::array<uint32_t, 4>> GetOs2UnicodeRange();
81   std::optional<std::array<uint32_t, 2>> GetOs2CodePageRange();
82   std::optional<std::array<uint8_t, 2>> GetOs2Panose();
83 
84   int GetGlyphCount() const;
85   // TODO(crbug.com/pdfium/2037): Can this method be private?
86   FX_RECT GetGlyphBBox() const;
87   std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont,
88                                                uint32_t glyph_index,
89                                                bool bFontStyle,
90                                                const CFX_Matrix& matrix,
91                                                int dest_width,
92                                                int anti_alias);
93   std::unique_ptr<CFX_Path> LoadGlyphPath(uint32_t glyph_index,
94                                           int dest_width,
95                                           bool is_vertical,
96                                           const CFX_SubstFont* subst_font);
97   int GetGlyphWidth(uint32_t glyph_index,
98                     int dest_width,
99                     int weight,
100                     const CFX_SubstFont* subst_font);
101   ByteString GetGlyphName(uint32_t glyph_index);
102 
103   int GetCharIndex(uint32_t code);
104   int GetNameIndex(const char* name);
105 
106   FX_RECT GetCharBBox(uint32_t code, int glyph_index);
107 
108   std::vector<CharCodeAndIndex> GetCharCodesAndIndices(char32_t max_char);
109 
110   CharMap GetCurrentCharMap() const;
111   std::optional<fxge::FontEncoding> GetCurrentCharMapEncoding() const;
112   int GetCharMapPlatformIdByIndex(size_t index) const;
113   int GetCharMapEncodingIdByIndex(size_t index) const;
114   fxge::FontEncoding GetCharMapEncodingByIndex(size_t index) const;
115   size_t GetCharMapCount() const;
116   void SetCharMap(CharMap map);
117   void SetCharMapByIndex(size_t index);
118   bool SelectCharMap(fxge::FontEncoding encoding);
119 
120   bool SetPixelSize(uint32_t width, uint32_t height);
121 
122 #if BUILDFLAG(IS_WIN)
123   bool CanEmbed();
124 #endif
125 
GetRec()126   FXFT_FaceRec* GetRec() { return m_pRec.get(); }
GetRec()127   const FXFT_FaceRec* GetRec() const { return m_pRec.get(); }
128 
129  private:
130   CFX_Face(FXFT_FaceRec* pRec, RetainPtr<Retainable> pDesc);
131   ~CFX_Face() override;
132 
133   void AdjustVariationParams(int glyph_index, int dest_width, int weight);
134 
135   ScopedFXFTFaceRec const m_pRec;
136   RetainPtr<Retainable> const m_pDesc;
137 };
138 
139 #endif  // CORE_FXGE_CFX_FACE_H_
140