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/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; } GetFaceRec()50 FXFT_FaceRec* GetFaceRec() { return m_Face ? m_Face->GetRec() : nullptr; } 51 52 #if defined(_SKIA_SUPPORT_) 53 CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont); 54 #endif 55 56 private: 57 explicit CFX_GlyphCache(RetainPtr<CFX_Face> face); 58 ~CFX_GlyphCache() override; 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