diff options
author | npm <npm@chromium.org> | 2016-08-17 13:22:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-17 13:22:16 -0700 |
commit | d691899dbff8a8aa024596302fcea1f7d7935252 (patch) | |
tree | 6f94904e752a859614da0edc5c2bd84184909bbb /core | |
parent | 260f5fbf3553a96fa49b029cc050220039c30e2a (diff) | |
download | pdfium-d691899dbff8a8aa024596302fcea1f7d7935252.tar.xz |
Split fx_font into multiple files, part 1.
Moved classes CFX_FontCache and CFX_AutoFontCache into a separate file.
Review-Url: https://codereview.chromium.org/2246223002
Diffstat (limited to 'core')
22 files changed, 172 insertions, 92 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp index 1f04373e3b..0274f10273 100644 --- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp +++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp @@ -21,6 +21,7 @@ #include "core/fpdfapi/fpdf_render/render_int.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" #include "core/fxcodec/include/JBig2_DocumentContext.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/fx_font.h" #include "third_party/base/stl_util.h" diff --git a/core/fpdfapi/fpdf_render/fpdf_render.cpp b/core/fpdfapi/fpdf_render/fpdf_render.cpp index b736a1fc78..576be6a8d4 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render.cpp @@ -30,6 +30,7 @@ #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" #include "core/fpdfapi/include/cpdf_modulemgr.h" #include "core/fpdfdoc/include/cpdf_occontext.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_graphstatedata.h" #include "core/fxge/include/cfx_pathdata.h" diff --git a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp index 222fbcb625..549e592c43 100644 --- a/core/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -22,6 +22,8 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" +#include "core/fxge/include/cfx_autofontcache.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_gemodule.h" #include "core/fxge/include/cfx_graphstatedata.h" diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp index c9f8bb4374..cf0fd90917 100644 --- a/core/fxge/agg/fx_agg_driver.cpp +++ b/core/fxge/agg/fx_agg_driver.cpp @@ -13,6 +13,7 @@ #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/cfx_cliprgn.h" #include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_gemodule.h" #include "core/fxge/include/cfx_graphstatedata.h" diff --git a/core/fxge/agg/fx_agg_driver.h b/core/fxge/agg/fx_agg_driver.h index 8d6aec12dc..db6807cb3d 100644 --- a/core/fxge/agg/fx_agg_driver.h +++ b/core/fxge/agg/fx_agg_driver.h @@ -16,6 +16,7 @@ #include "third_party/agg23/agg_rasterizer_scanline_aa.h" class CFX_ClipRgn; +class CFX_FontCache; class CFX_GraphStateData; class CFX_Matrix; class CFX_PathData; diff --git a/core/fxge/apple/apple_int.h b/core/fxge/apple/apple_int.h index b81f7835d8..a401086f35 100644 --- a/core/fxge/apple/apple_int.h +++ b/core/fxge/apple/apple_int.h @@ -21,6 +21,8 @@ #include <Carbon/Carbon.h> #endif +class CFX_FontCache; + class CQuartz2D { public: void* createGraphics(CFX_DIBitmap* bitmap); diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp index c02e8ae354..fed24cf86b 100644 --- a/core/fxge/apple/fx_apple_platform.cpp +++ b/core/fxge/apple/fx_apple_platform.cpp @@ -17,6 +17,7 @@ #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/cfx_cliprgn.h" #include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_gemodule.h" #include "core/fxge/include/cfx_renderdevice.h" #include "core/fxge/include/fx_freetype.h" diff --git a/core/fxge/apple/fx_quartz_device.cpp b/core/fxge/apple/fx_quartz_device.cpp index c877715d11..400e29085c 100644 --- a/core/fxge/apple/fx_quartz_device.cpp +++ b/core/fxge/apple/fx_quartz_device.cpp @@ -13,6 +13,7 @@ #include "core/fxcrt/include/fx_memory.h" #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_gemodule.h" #include "core/fxge/include/cfx_graphstatedata.h" #include "core/fxge/include/cfx_pathdata.h" diff --git a/core/fxge/ge/cfx_autofontcache.cpp b/core/fxge/ge/cfx_autofontcache.cpp new file mode 100644 index 0000000000..871f207c17 --- /dev/null +++ b/core/fxge/ge/cfx_autofontcache.cpp @@ -0,0 +1,17 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/include/cfx_autofontcache.h" + +#include "core/fxge/include/cfx_fontcache.h" +#include "core/fxge/include/fx_font.h" + +CFX_AutoFontCache::CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont) + : m_pFontCache(pFontCache), m_pFont(pFont) {} + +CFX_AutoFontCache::~CFX_AutoFontCache() { + m_pFontCache->ReleaseCachedFace(m_pFont); +} diff --git a/core/fxge/ge/cfx_fontcache.cpp b/core/fxge/ge/cfx_fontcache.cpp new file mode 100644 index 0000000000..a183711a18 --- /dev/null +++ b/core/fxge/ge/cfx_fontcache.cpp @@ -0,0 +1,78 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/include/cfx_fontcache.h" + +#include "core/fxge/include/fx_font.h" +#include "core/fxge/include/fx_freetype.h" + +CFX_FontCache::CFX_FontCache() {} + +CFX_FontCache::~CFX_FontCache() { + FreeCache(TRUE); +} + +CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { + FXFT_Face face = pFont->GetFace(); + const bool bExternal = !face; + CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; + auto it = map.find(face); + if (it != map.end()) { + CFX_CountedFaceCache* counted_face_cache = it->second; + counted_face_cache->m_nCount++; + return counted_face_cache->m_Obj; + } + + CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); + CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; + counted_face_cache->m_nCount = 2; + counted_face_cache->m_Obj = face_cache; + map[face] = counted_face_cache; + return face_cache; +} + +#ifdef _SKIA_SUPPORT_ +CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) { + return GetCachedFace(pFont)->GetDeviceCache(pFont); +} +#endif + +void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { + FXFT_Face face = pFont->GetFace(); + const bool bExternal = !face; + CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; + + auto it = map.find(face); + if (it == map.end()) + return; + + CFX_CountedFaceCache* counted_face_cache = it->second; + if (counted_face_cache->m_nCount > 1) { + counted_face_cache->m_nCount--; + } +} + +void CFX_FontCache::FreeCache(FX_BOOL bRelease) { + for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) { + auto curr_it = it++; + CFX_CountedFaceCache* cache = curr_it->second; + if (bRelease || cache->m_nCount < 2) { + delete cache->m_Obj; + delete cache; + m_FTFaceMap.erase(curr_it); + } + } + + for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) { + auto curr_it = it++; + CFX_CountedFaceCache* cache = curr_it->second; + if (bRelease || cache->m_nCount < 2) { + delete cache->m_Obj; + delete cache; + m_ExtFaceMap.erase(curr_it); + } + } +} diff --git a/core/fxge/ge/cfx_gemodule.cpp b/core/fxge/ge/cfx_gemodule.cpp index 73189b75d5..4eb4094304 100644 --- a/core/fxge/ge/cfx_gemodule.cpp +++ b/core/fxge/ge/cfx_gemodule.cpp @@ -8,6 +8,7 @@ #include "core/fxge/ge/cfx_folderfontinfo.h" #include "core/fxge/ge/fx_text_int.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fontmgr.h" namespace { diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index fcb99f79c2..1890b52021 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -7,6 +7,8 @@ #include "core/fxge/include/cfx_renderdevice.h" #include "core/fxcrt/include/fx_safe_types.h" +#include "core/fxge/include/cfx_autofontcache.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_graphstatedata.h" #include "core/fxge/include/cfx_pathdata.h" diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index 9ed751b708..8e16c17784 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -106,36 +106,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector<FXTEXT_GLYPHPOS>& glyphs, return rect; } -CFX_FontCache::CFX_FontCache() {} - -CFX_FontCache::~CFX_FontCache() { - FreeCache(TRUE); -} - -CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) { - FXFT_Face face = pFont->GetFace(); - const bool bExternal = !face; - CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; - auto it = map.find(face); - if (it != map.end()) { - CFX_CountedFaceCache* counted_face_cache = it->second; - counted_face_cache->m_nCount++; - return counted_face_cache->m_Obj; - } - - CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); - CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; - counted_face_cache->m_nCount = 2; - counted_face_cache->m_Obj = face_cache; - map[face] = counted_face_cache; - 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 = @@ -147,43 +118,6 @@ CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) { } #endif -void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { - FXFT_Face face = pFont->GetFace(); - const bool bExternal = !face; - CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; - - auto it = map.find(face); - if (it == map.end()) - return; - - CFX_CountedFaceCache* counted_face_cache = it->second; - if (counted_face_cache->m_nCount > 1) { - counted_face_cache->m_nCount--; - } -} - -void CFX_FontCache::FreeCache(FX_BOOL bRelease) { - for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) { - auto curr_it = it++; - CFX_CountedFaceCache* cache = curr_it->second; - if (bRelease || cache->m_nCount < 2) { - delete cache->m_Obj; - delete cache; - m_FTFaceMap.erase(curr_it); - } - } - - for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) { - auto curr_it = it++; - CFX_CountedFaceCache* cache = curr_it->second; - if (bRelease || cache->m_nCount < 2) { - delete cache->m_Obj; - delete cache; - m_ExtFaceMap.erase(curr_it); - } - } -} - CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) #ifdef _SKIA_SUPPORT_ diff --git a/core/fxge/ifx_renderdevicedriver.cpp b/core/fxge/ifx_renderdevicedriver.cpp index 25c3a4a23c..69b8ac903d 100644 --- a/core/fxge/ifx_renderdevicedriver.cpp +++ b/core/fxge/ifx_renderdevicedriver.cpp @@ -10,6 +10,8 @@ #include "core/fxge/include/cfx_pathdata.h" #include "core/fxge/include/cfx_renderdevice.h" +class CFX_FontCache; + IFX_RenderDeviceDriver::~IFX_RenderDeviceDriver() {} CFX_Matrix IFX_RenderDeviceDriver::GetCTM() const { diff --git a/core/fxge/include/cfx_autofontcache.h b/core/fxge/include/cfx_autofontcache.h new file mode 100644 index 0000000000..c1ef079d4f --- /dev/null +++ b/core/fxge/include/cfx_autofontcache.h @@ -0,0 +1,23 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_INCLUDE_CFX_AUTOFONTCACHE_H_ +#define CORE_FXGE_INCLUDE_CFX_AUTOFONTCACHE_H_ + +#include "core/fxge/include/cfx_fontcache.h" +#include "core/fxge/include/fx_font.h" + +class CFX_AutoFontCache { + public: + CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont); + ~CFX_AutoFontCache(); + + private: + CFX_FontCache* m_pFontCache; + CFX_Font* m_pFont; +}; + +#endif // CORE_FXGE_INCLUDE_CFX_AUTOFONTCACHE_H_ diff --git a/core/fxge/include/cfx_fontcache.h b/core/fxge/include/cfx_fontcache.h new file mode 100644 index 0000000000..3aee20755d --- /dev/null +++ b/core/fxge/include/cfx_fontcache.h @@ -0,0 +1,33 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_INCLUDE_CFX_FONTCACHE_H_ +#define CORE_FXGE_INCLUDE_CFX_FONTCACHE_H_ + +#include <map> + +#include "core/fxcrt/include/fx_system.h" +#include "core/fxge/include/fx_font.h" +#include "core/fxge/include/fx_freetype.h" + +class CFX_FontCache { + public: + CFX_FontCache(); + ~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*>; + CFX_FTCacheMap m_FTFaceMap; + CFX_FTCacheMap m_ExtFaceMap; +}; + +#endif // CORE_FXGE_INCLUDE_CFX_FONTCACHE_H_ diff --git a/core/fxge/include/fx_font.h b/core/fxge/include/fx_font.h index 8c7928199b..bb7632d1db 100644 --- a/core/fxge/include/fx_font.h +++ b/core/fxge/include/fx_font.h @@ -19,6 +19,7 @@ typedef struct FT_FaceRec_* FXFT_Face; typedef void* FXFT_Library; class CFX_FaceCache; +class CFX_FontCache; class CFX_PathData; class CFX_SizeGlyphCache; class CFX_SubstFont; @@ -289,32 +290,6 @@ class CFX_CountedFaceCache { uint32_t m_nCount; }; -class CFX_FontCache { - public: - CFX_FontCache(); - ~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*>; - CFX_FTCacheMap m_FTFaceMap; - CFX_FTCacheMap m_ExtFaceMap; -}; - -class CFX_AutoFontCache { - public: - CFX_AutoFontCache(CFX_FontCache* pFontCache, CFX_Font* pFont) - : m_pFontCache(pFontCache), m_pFont(pFont) {} - ~CFX_AutoFontCache() { m_pFontCache->ReleaseCachedFace(m_pFont); } - CFX_FontCache* m_pFontCache; - CFX_Font* m_pFont; -}; - class CFX_GlyphBitmap { public: int m_Top; diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 32e90e1bcb..fd4f73972f 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -14,6 +14,7 @@ #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_gemodule.h" #include "core/fxge/include/cfx_graphstatedata.h" diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index 6e112f5f62..8a1bf690b2 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h @@ -10,6 +10,7 @@ #include "core/fxge/include/cfx_pathdata.h" #include "core/fxge/include/ifx_renderdevicedriver.h" +class CFX_FontCache; class SkCanvas; class SkMatrix; class SkPaint; diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp index 456bea05ad..77d6576228 100644 --- a/core/fxge/skia/fx_skia_device_unittest.cpp +++ b/core/fxge/skia/fx_skia_device_unittest.cpp @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_fxgedevice.h" #include "core/fxge/include/cfx_graphstatedata.h" #include "core/fxge/include/cfx_pathdata.h" diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index 207ff24552..6b9c2cce35 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -15,6 +15,7 @@ #include "core/fxge/dib/dib_int.h" #include "core/fxge/ge/fx_text_int.h" #include "core/fxge/include/fx_freetype.h" +#include "core/fxge/include/cfx_fontcache.h" #include "core/fxge/include/cfx_renderdevice.h" #include "core/fxge/include/cfx_windowsdevice.h" #include "core/fxge/win32/win32_int.h" diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h index 094e3efbb2..8c3443b3fd 100644 --- a/core/fxge/win32/win32_int.h +++ b/core/fxge/win32/win32_int.h @@ -11,6 +11,7 @@ #include "core/fxge/include/ifx_renderdevicedriver.h" #include "core/fxge/win32/dwrite_int.h" +class CFX_FontCache; struct FXTEXT_CHARPOS; struct WINDIB_Open_Args_; |