diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-07-10 15:14:26 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-07-10 19:28:59 +0000 |
commit | 92e2276a8be492fd2be8e44a5d62e8a5879644d8 (patch) | |
tree | 0945f5edda0fbfb461ca1cae89a20adb583242e4 /core/fxge/cfx_fontcache.cpp | |
parent | 1437643bfaca635d52f4cb9ec41e3075cf893f79 (diff) | |
download | pdfium-92e2276a8be492fd2be8e44a5d62e8a5879644d8.tar.xz |
Move core/fxge/ge to core/fxge.
This brings the cpp and h files together and removes the
redundant ge/ path.
Change-Id: I36594b8ae719d362768ba4c2e4ce173e287363eb
Reviewed-on: https://pdfium-review.googlesource.com/7452
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge/cfx_fontcache.cpp')
-rw-r--r-- | core/fxge/cfx_fontcache.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/core/fxge/cfx_fontcache.cpp b/core/fxge/cfx_fontcache.cpp new file mode 100644 index 0000000000..5ccac8cfbc --- /dev/null +++ b/core/fxge/cfx_fontcache.cpp @@ -0,0 +1,70 @@ +// 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/cfx_fontcache.h" + +#include <memory> +#include <utility> + +#include "core/fxge/cfx_facecache.h" +#include "core/fxge/fx_font.h" +#include "core/fxge/fx_freetype.h" +#include "third_party/base/ptr_util.h" + +CFX_FontCache::CountedFaceCache::CountedFaceCache() {} + +CFX_FontCache::CountedFaceCache::~CountedFaceCache() {} + +CFX_FontCache::CFX_FontCache() {} + +CFX_FontCache::~CFX_FontCache() { + ASSERT(m_ExtFaceMap.empty()); + ASSERT(m_FTFaceMap.empty()); +} + +CFX_FaceCache* CFX_FontCache::GetCachedFace(const 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()) { + CountedFaceCache* counted_face_cache = it->second.get(); + counted_face_cache->m_nCount++; + return counted_face_cache->m_Obj.get(); + } + + auto counted_face_cache = pdfium::MakeUnique<CountedFaceCache>(); + counted_face_cache->m_nCount = 2; + auto new_cache = + pdfium::MakeUnique<CFX_FaceCache>(bExternal ? nullptr : face); + CFX_FaceCache* face_cache = new_cache.get(); + counted_face_cache->m_Obj = std::move(new_cache); + map[face] = std::move(counted_face_cache); + return face_cache; +} + +#ifdef _SKIA_SUPPORT_ +CFX_TypeFace* CFX_FontCache::GetDeviceCache(const CFX_Font* pFont) { + return GetCachedFace(pFont)->GetDeviceCache(pFont); +} +#endif + +void CFX_FontCache::ReleaseCachedFace(const 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; + + CountedFaceCache* counted_face_cache = it->second.get(); + if (counted_face_cache->m_nCount > 2) { + counted_face_cache->m_nCount--; + } else { + map.erase(it); + } +} |