• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_CFX_GLYPHCACHE_H_
8 #define CORE_FXGE_CFX_GLYPHCACHE_H_
9 
10 #include <map>
11 #include <memory>
12 #include <tuple>
13 
14 #include "core/fxcrt/bytestring.h"
15 #include "core/fxcrt/observed_ptr.h"
16 #include "core/fxcrt/retain_ptr.h"
17 #include "core/fxge/cfx_face.h"
18 
19 #if defined(_SKIA_SUPPORT_)
20 #include "core/fxge/fx_font.h"
21 #include "third_party/skia/include/core/SkTypeface.h"  // nogncheck
22 #endif
23 
24 class CFX_Font;
25 class CFX_GlyphBitmap;
26 class CFX_Matrix;
27 class CFX_Path;
28 struct CFX_TextRenderOptions;
29 
30 class CFX_GlyphCache final : public Retainable, public Observable {
31  public:
32   CONSTRUCT_VIA_MAKE_RETAIN;
33   ~CFX_GlyphCache() override;
34 
35   const CFX_GlyphBitmap* LoadGlyphBitmap(const CFX_Font* pFont,
36                                          uint32_t glyph_index,
37                                          bool bFontStyle,
38                                          const CFX_Matrix& matrix,
39                                          int dest_width,
40                                          int anti_alias,
41                                          CFX_TextRenderOptions* text_options);
42   const CFX_Path* LoadGlyphPath(const CFX_Font* pFont,
43                                 uint32_t glyph_index,
44                                 int dest_width);
45   int GetGlyphWidth(const CFX_Font* font,
46                     uint32_t glyph_index,
47                     int dest_width,
48                     int weight);
49 
GetFace()50   RetainPtr<CFX_Face> GetFace() { return m_Face; }
GetFaceRec()51   FXFT_FaceRec* GetFaceRec() { return m_Face ? m_Face->GetRec() : nullptr; }
52 
53 #if defined(_SKIA_SUPPORT_)
54   CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont);
55 #endif
56 
57  private:
58   explicit CFX_GlyphCache(RetainPtr<CFX_Face> face);
59 
60   using SizeGlyphCache = std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>>;
61   // <glyph_index, width, weight, angle, vertical>
62   using PathMapKey = std::tuple<uint32_t, int, int, int, bool>;
63   // <glyph_index, dest_width, weight>
64   using WidthMapKey = std::tuple<uint32_t, int, int>;
65 
66   std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont,
67                                                uint32_t glyph_index,
68                                                bool bFontStyle,
69                                                const CFX_Matrix& matrix,
70                                                int dest_width,
71                                                int anti_alias);
72   std::unique_ptr<CFX_GlyphBitmap> RenderGlyph_Nativetext(
73       const CFX_Font* pFont,
74       uint32_t glyph_index,
75       const CFX_Matrix& matrix,
76       int dest_width,
77       int anti_alias);
78   CFX_GlyphBitmap* LookUpGlyphBitmap(const CFX_Font* pFont,
79                                      const CFX_Matrix& matrix,
80                                      const ByteString& FaceGlyphsKey,
81                                      uint32_t glyph_index,
82                                      bool bFontStyle,
83                                      int dest_width,
84                                      int anti_alias);
85   RetainPtr<CFX_Face> const m_Face;
86   std::map<ByteString, SizeGlyphCache> m_SizeMap;
87   std::map<PathMapKey, std::unique_ptr<CFX_Path>> m_PathMap;
88   std::map<WidthMapKey, int> m_WidthMap;
89 #if defined(_SKIA_SUPPORT_)
90   sk_sp<SkTypeface> m_pTypeface;
91 #endif
92 };
93 
94 #endif  //  CORE_FXGE_CFX_GLYPHCACHE_H_
95