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_FACECACHE_H_ 8 #define CORE_FXGE_CFX_FACECACHE_H_ 9 10 #include <map> 11 #include <memory> 12 #include <tuple> 13 14 #include "core/fxcrt/unowned_ptr.h" 15 #include "core/fxge/fx_font.h" 16 #include "core/fxge/fx_freetype.h" 17 18 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ 19 #include "third_party/skia/include/core/SkTypeface.h" 20 #endif 21 22 class CFX_Font; 23 class CFX_PathData; 24 25 class CFX_FaceCache { 26 public: 27 explicit CFX_FaceCache(FXFT_Face face); 28 ~CFX_FaceCache(); 29 const CFX_GlyphBitmap* LoadGlyphBitmap(const CFX_Font* pFont, 30 uint32_t glyph_index, 31 bool bFontStyle, 32 const CFX_Matrix* pMatrix, 33 int dest_width, 34 int anti_alias, 35 int& text_flags); 36 const CFX_PathData* LoadGlyphPath(const CFX_Font* pFont, 37 uint32_t glyph_index, 38 int dest_width); 39 40 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ 41 CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont); 42 #endif 43 44 private: 45 using SizeGlyphCache = std::map<uint32_t, std::unique_ptr<CFX_GlyphBitmap>>; 46 // <glyph_index, width, weight, angle, vertical> 47 using PathMapKey = std::tuple<uint32_t, int, int, int, bool>; 48 49 std::unique_ptr<CFX_GlyphBitmap> RenderGlyph(const CFX_Font* pFont, 50 uint32_t glyph_index, 51 bool bFontStyle, 52 const CFX_Matrix* pMatrix, 53 int dest_width, 54 int anti_alias); 55 std::unique_ptr<CFX_GlyphBitmap> RenderGlyph_Nativetext( 56 const CFX_Font* pFont, 57 uint32_t glyph_index, 58 const CFX_Matrix* pMatrix, 59 int dest_width, 60 int anti_alias); 61 CFX_GlyphBitmap* LookUpGlyphBitmap(const CFX_Font* pFont, 62 const CFX_Matrix* pMatrix, 63 const ByteString& FaceGlyphsKey, 64 uint32_t glyph_index, 65 bool bFontStyle, 66 int dest_width, 67 int anti_alias); 68 void InitPlatform(); 69 void DestroyPlatform(); 70 71 FXFT_Face const m_Face; 72 std::map<ByteString, SizeGlyphCache> m_SizeMap; 73 std::map<PathMapKey, std::unique_ptr<CFX_PathData>> m_PathMap; 74 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ 75 sk_sp<SkTypeface> m_pTypeface; 76 #endif 77 }; 78 79 #endif // CORE_FXGE_CFX_FACECACHE_H_ 80