• 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(PDF_USE_SKIA)
20 #include "core/fxge/fx_font.h"
21 #include "third_party/skia/include/core/SkRefCnt.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 
34   const CFX_GlyphBitmap* LoadGlyphBitmap(const CFX_Font* pFont,
35                                          uint32_t glyph_index,
36                                          bool bFontStyle,
37                                          const CFX_Matrix& matrix,
38                                          int dest_width,
39                                          int anti_alias,
40                                          CFX_TextRenderOptions* text_options);
41   const CFX_Path* LoadGlyphPath(const CFX_Font* pFont,
42                                 uint32_t glyph_index,
43                                 int dest_width);
44   int GetGlyphWidth(const CFX_Font* font,
45                     uint32_t glyph_index,
46                     int dest_width,
47                     int weight);
48 
GetFace()49   RetainPtr<CFX_Face> GetFace() { return m_Face; }
50 
51 #if defined(PDF_USE_SKIA)
52   CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont);
53   static void InitializeGlobals();
54   static void DestroyGlobals();
55 #endif
56 
57  private:
58   explicit CFX_GlyphCache(RetainPtr<CFX_Face> face);
59   ~CFX_GlyphCache() override;
60 
61   using SizeGlyphCache = std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>>;
62   // <glyph_index, width, weight, angle, vertical>
63   using PathMapKey = std::tuple<uint32_t, int, int, int, bool>;
64   // <glyph_index, dest_width, weight>
65   using WidthMapKey = std::tuple<uint32_t, int, int>;
66 
67   std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont,
68                                                uint32_t glyph_index,
69                                                bool bFontStyle,
70                                                const CFX_Matrix& matrix,
71                                                int dest_width,
72                                                int anti_alias);
73   std::unique_ptr<CFX_GlyphBitmap> RenderGlyph_Nativetext(
74       const CFX_Font* pFont,
75       uint32_t glyph_index,
76       const CFX_Matrix& matrix,
77       int dest_width,
78       int anti_alias);
79   CFX_GlyphBitmap* LookUpGlyphBitmap(const CFX_Font* pFont,
80                                      const CFX_Matrix& matrix,
81                                      const ByteString& FaceGlyphsKey,
82                                      uint32_t glyph_index,
83                                      bool bFontStyle,
84                                      int dest_width,
85                                      int anti_alias);
86   RetainPtr<CFX_Face> const m_Face;
87   std::map<ByteString, SizeGlyphCache> m_SizeMap;
88   std::map<PathMapKey, std::unique_ptr<CFX_Path>> m_PathMap;
89   std::map<WidthMapKey, int> m_WidthMap;
90 #if defined(PDF_USE_SKIA)
91   sk_sp<SkTypeface> m_pTypeface;
92 #endif
93 };
94 
95 #endif  //  CORE_FXGE_CFX_GLYPHCACHE_H_
96