diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fxge/ge/DEPS | 3 | ||||
-rw-r--r-- | core/fxge/ge/fx_ge_text.cpp | 32 | ||||
-rw-r--r-- | core/fxge/skia/fx_skia_device.cpp | 3 | ||||
-rw-r--r-- | core/include/fxge/fx_font.h | 16 |
4 files changed, 51 insertions, 3 deletions
diff --git a/core/fxge/ge/DEPS b/core/fxge/ge/DEPS new file mode 100644 index 0000000000..6492756b7e --- /dev/null +++ b/core/fxge/ge/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + '+third_party/skia/include' +] diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index 1d18ecd377..0815bfaa67 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -9,6 +9,11 @@ #include "core/include/fxge/fx_freetype.h" #include "core/include/fxge/fx_ge.h" +#ifdef _SKIA_SUPPORT_ +#include "third_party/skia/include/core/SkStream.h" +#include "third_party/skia/include/core/SkTypeface.h" +#endif + #undef FX_GAMMA #undef FX_GAMMA_INVERSE #define FX_GAMMA(value) (value) @@ -1198,6 +1203,20 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { return face_cache; } +#ifdef _SKIA_SUPPORT_ +CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) { + return GetCachedFace(pFont)->GetDeviceCache(pFont); +} + +CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) { + if (!m_pTypeface) { + m_pTypeface = SkTypeface::CreateFromStream( + new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())); + } + return m_pTypeface; +} +#endif + void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { FXFT_Face internal_face = pFont->GetFace(); const bool bExternal = !internal_face; @@ -1237,7 +1256,14 @@ void CFX_FontCache::FreeCache(FX_BOOL bRelease) { } } -CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) {} +CFX_FaceCache::CFX_FaceCache(FXFT_Face face) + : m_Face(face) +#ifdef _SKIA_SUPPORT_ + , + m_pTypeface(nullptr) +#endif +{ +} CFX_FaceCache::~CFX_FaceCache() { for (const auto& pair : m_SizeMap) { @@ -1248,7 +1274,11 @@ CFX_FaceCache::~CFX_FaceCache() { delete pair.second; } m_PathMap.clear(); +#ifdef _SKIA_SUPPORT_ + SkSafeUnref(m_pTypeface); +#endif } + #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ void CFX_FaceCache::InitPlatform() {} #endif diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 745c9b50fd..e61dda68d4 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -320,8 +320,7 @@ FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, uint32_t color, int alpha_flag, void* pIccTransform) { - SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromStream( - new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))); + CFX_TypeFace* typeface = pCache->GetDeviceCache(pFont); SkPaint paint; paint.setAntiAlias(true); paint.setColor(color); diff --git a/core/include/fxge/fx_font.h b/core/include/fxge/fx_font.h index c52e614e97..4e2b97e677 100644 --- a/core/include/fxge/fx_font.h +++ b/core/include/fxge/fx_font.h @@ -27,6 +27,12 @@ class CFX_SubstFont; class CTTFontDesc; class IFX_SystemFontInfo; +#ifdef _SKIA_SUPPORT_ +class SkTypeface; + +using CFX_TypeFace = SkTypeface; +#endif + #define FXFONT_FIXED_PITCH 0x01 #define FXFONT_SERIF 0x02 #define FXFONT_SYMBOLIC 0x04 @@ -452,6 +458,9 @@ class CFX_FontCache { CFX_FaceCache* GetCachedFace(CFX_Font* pFont); void ReleaseCachedFace(CFX_Font* pFont); void FreeCache(FX_BOOL bRelease = FALSE); +#ifdef _SKIA_SUPPORT_ + CFX_TypeFace* GetDeviceCache(CFX_Font* pFont); +#endif private: using CFX_FTCacheMap = std::map<FXFT_Face, CFX_CountedFaceCache*>; @@ -490,6 +499,10 @@ class CFX_FaceCache { uint32_t glyph_index, int dest_width); +#ifdef _SKIA_SUPPORT_ + CFX_TypeFace* GetDeviceCache(CFX_Font* pFont); +#endif + private: CFX_GlyphBitmap* RenderGlyph(CFX_Font* pFont, uint32_t glyph_index, @@ -516,6 +529,9 @@ class CFX_FaceCache { std::map<CFX_ByteString, CFX_SizeGlyphCache*> m_SizeMap; std::map<uint32_t, CFX_PathData*> m_PathMap; CFX_DIBitmap* m_pBitmap; +#ifdef _SKIA_SUPPORT_ + CFX_TypeFace* m_pTypeface; +#endif }; struct FXTEXT_GLYPHPOS { |