1 // Copyright 2016 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_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/fx_string.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_ || _SKIA_SUPPORT_PATHS_ 20 #include "core/fxge/fx_font.h" 21 #include "third_party/skia/include/core/SkTypeface.h" 22 #endif 23 24 class CFX_Font; 25 class CFX_GlyphBitmap; 26 class CFX_Matrix; 27 class CFX_PathData; 28 29 class CFX_GlyphCache : public Retainable, public Observable { 30 public: 31 template <typename T, typename... Args> 32 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 33 34 ~CFX_GlyphCache() override; 35 36 const CFX_GlyphBitmap* LoadGlyphBitmap(const CFX_Font* pFont, 37 uint32_t glyph_index, 38 bool bFontStyle, 39 const CFX_Matrix& matrix, 40 uint32_t dest_width, 41 int anti_alias, 42 int* pTextFlags); 43 const CFX_PathData* LoadGlyphPath(const CFX_Font* pFont, 44 uint32_t glyph_index, 45 uint32_t dest_width); 46 GetFace()47 RetainPtr<CFX_Face> GetFace() { return m_Face; } GetFaceRec()48 FXFT_FaceRec* GetFaceRec() { return m_Face ? m_Face->GetRec() : nullptr; } 49 50 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ 51 CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont); 52 #endif 53 54 private: 55 explicit CFX_GlyphCache(RetainPtr<CFX_Face> face); 56 57 using SizeGlyphCache = std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>>; 58 // <glyph_index, width, weight, angle, vertical> 59 using PathMapKey = std::tuple<uint32_t, uint32_t, int, int, bool>; 60 61 std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont, 62 uint32_t glyph_index, 63 bool bFontStyle, 64 const CFX_Matrix& matrix, 65 uint32_t dest_width, 66 int anti_alias); 67 std::unique_ptr<CFX_GlyphBitmap> RenderGlyph_Nativetext( 68 const CFX_Font* pFont, 69 uint32_t glyph_index, 70 const CFX_Matrix& matrix, 71 uint32_t dest_width, 72 int anti_alias); 73 CFX_GlyphBitmap* LookUpGlyphBitmap(const CFX_Font* pFont, 74 const CFX_Matrix& matrix, 75 const ByteString& FaceGlyphsKey, 76 uint32_t glyph_index, 77 bool bFontStyle, 78 uint32_t dest_width, 79 int anti_alias); 80 void InitPlatform(); 81 void DestroyPlatform(); 82 83 RetainPtr<CFX_Face> const m_Face; 84 std::map<ByteString, SizeGlyphCache> m_SizeMap; 85 std::map<PathMapKey, std::unique_ptr<CFX_PathData>> m_PathMap; 86 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ 87 sk_sp<SkTypeface> m_pTypeface; 88 #endif 89 }; 90 91 #endif // CORE_FXGE_CFX_GLYPHCACHE_H_ 92