Nest CTTFontDesc inside CFX_FontMgr. Resolves one inconsistently named class. The class is only used by CFX_FontMgr as a cache element, so it might as well provide it itself. Change-Id: Ic2b4a340a8187ec2171baa7092d5b165f4a6fd71 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56570 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index 1dcf751..00db31c 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn
@@ -54,8 +54,6 @@ "cfx_substfont.h", "cfx_unicodeencoding.cpp", "cfx_unicodeencoding.h", - "cttfontdesc.cpp", - "cttfontdesc.h", "dib/cfx_bitmapcomposer.cpp", "dib/cfx_bitmapcomposer.h", "dib/cfx_bitmapstorer.cpp",
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp index 749aa4d..fb88b3c 100644 --- a/core/fxge/cfx_fontmapper.cpp +++ b/core/fxge/cfx_fontmapper.cpp
@@ -17,7 +17,6 @@ #include "core/fxcrt/fx_codepage.h" #include "core/fxge/cfx_fontmgr.h" #include "core/fxge/cfx_substfont.h" -#include "core/fxge/cttfontdesc.h" #include "core/fxge/fx_font.h" #include "core/fxge/systemfontinfo_iface.h" #include "third_party/base/stl_util.h" @@ -683,7 +682,8 @@ for (int i = 0; i < 256; i++) checksum += pBuffer[i]; } - CTTFontDesc* pFontDesc = m_pFontMgr->GetCachedTTCFontDesc(ttc_size, checksum); + CFX_FontMgr::FontDesc* pFontDesc = + m_pFontMgr->GetCachedTTCFontDesc(ttc_size, checksum); if (!pFontDesc) { std::unique_ptr<uint8_t, FxFreeDeleter> pFontData( FX_Alloc(uint8_t, ttc_size)); @@ -713,7 +713,7 @@ int weight, bool bItalic, uint32_t font_size) { - CTTFontDesc* pFontDesc = + CFX_FontMgr::FontDesc* pFontDesc = m_pFontMgr->GetCachedFontDesc(SubstName, weight, bItalic); if (!pFontDesc) { std::unique_ptr<uint8_t, FxFreeDeleter> pFontData(
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp index 746c8ba..f47f055 100644 --- a/core/fxge/cfx_fontmgr.cpp +++ b/core/fxge/cfx_fontmgr.cpp
@@ -9,9 +9,9 @@ #include <memory> #include <utility> +#include "core/fxge/cfx_face.h" #include "core/fxge/cfx_fontmapper.h" #include "core/fxge/cfx_substfont.h" -#include "core/fxge/cttfontdesc.h" #include "core/fxge/fontdata/chromefontdata/chromefontdata.h" #include "core/fxge/fx_font.h" #include "core/fxge/systemfontinfo_iface.h" @@ -68,6 +68,22 @@ } // namespace +CFX_FontMgr::FontDesc::FontDesc(std::unique_ptr<uint8_t, FxFreeDeleter> pData, + size_t size) + : m_Size(size), m_pFontData(std::move(pData)) {} + +CFX_FontMgr::FontDesc::~FontDesc() = default; + +void CFX_FontMgr::FontDesc::SetFace(size_t index, CFX_Face* face) { + ASSERT(index < FX_ArraySize(m_TTCFaces)); + m_TTCFaces[index].Reset(face); +} + +CFX_Face* CFX_FontMgr::FontDesc::GetFace(size_t index) const { + ASSERT(index < FX_ArraySize(m_TTCFaces)); + return m_TTCFaces[index].Get(); +} + CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(FTLibraryInitHelper()), m_pBuiltinMapper(pdfium::MakeUnique<CFX_FontMapper>(this)), @@ -92,37 +108,38 @@ italic_angle, CharsetCP, pSubstFont); } -CTTFontDesc* CFX_FontMgr::GetCachedFontDesc(const ByteString& face_name, - int weight, - bool bItalic) { +CFX_FontMgr::FontDesc* CFX_FontMgr::GetCachedFontDesc( + const ByteString& face_name, + int weight, + bool bItalic) { auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); return it != m_FaceMap.end() ? it->second.get() : nullptr; } -CTTFontDesc* CFX_FontMgr::AddCachedFontDesc( +CFX_FontMgr::FontDesc* CFX_FontMgr::AddCachedFontDesc( const ByteString& face_name, int weight, bool bItalic, std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size) { - auto pFontDesc = pdfium::MakeUnique<CTTFontDesc>(std::move(pData), size); + auto pFontDesc = pdfium::MakeUnique<FontDesc>(std::move(pData), size); auto* result = pFontDesc.get(); m_FaceMap[KeyNameFromFace(face_name, weight, bItalic)] = std::move(pFontDesc); return result; } -CTTFontDesc* CFX_FontMgr::GetCachedTTCFontDesc(int ttc_size, - uint32_t checksum) { +CFX_FontMgr::FontDesc* CFX_FontMgr::GetCachedTTCFontDesc(int ttc_size, + uint32_t checksum) { auto it = m_FaceMap.find(KeyNameFromSize(ttc_size, checksum)); return it != m_FaceMap.end() ? it->second.get() : nullptr; } -CTTFontDesc* CFX_FontMgr::AddCachedTTCFontDesc( +CFX_FontMgr::FontDesc* CFX_FontMgr::AddCachedTTCFontDesc( int ttc_size, uint32_t checksum, std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size) { - auto pNewDesc = pdfium::MakeUnique<CTTFontDesc>(std::move(pData), size); + auto pNewDesc = pdfium::MakeUnique<FontDesc>(std::move(pData), size); auto* pResult = pNewDesc.get(); m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = std::move(pNewDesc); return pResult;
diff --git a/core/fxge/cfx_fontmgr.h b/core/fxge/cfx_fontmgr.h index 64138c4..0db8fa3 100644 --- a/core/fxge/cfx_fontmgr.h +++ b/core/fxge/cfx_fontmgr.h
@@ -12,39 +12,56 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_string.h" +#include "core/fxcrt/observed_ptr.h" #include "core/fxge/cfx_face.h" #include "core/fxge/fx_freetype.h" #include "third_party/base/optional.h" #include "third_party/base/span.h" +class CFX_Face; class CFX_FontMapper; class CFX_SubstFont; -class CTTFontDesc; class SystemFontInfoIface; class CFX_FontMgr { public: + class FontDesc { + public: + FontDesc(std::unique_ptr<uint8_t, FxFreeDeleter> pData, size_t size); + ~FontDesc(); + + pdfium::span<uint8_t> FontData() const { + return {m_pFontData.get(), m_Size}; + } + void SetFace(size_t index, CFX_Face* face); + CFX_Face* GetFace(size_t index) const; + + private: + const size_t m_Size; + std::unique_ptr<uint8_t, FxFreeDeleter> const m_pFontData; + ObservedPtr<CFX_Face> m_TTCFaces[16]; + }; + static Optional<pdfium::span<const uint8_t>> GetBuiltinFont(size_t index); CFX_FontMgr(); ~CFX_FontMgr(); - CTTFontDesc* GetCachedFontDesc(const ByteString& face_name, - int weight, - bool bItalic); - CTTFontDesc* AddCachedFontDesc(const ByteString& face_name, - int weight, - bool bItalic, + FontDesc* GetCachedFontDesc(const ByteString& face_name, + int weight, + bool bItalic); + FontDesc* AddCachedFontDesc(const ByteString& face_name, + int weight, + bool bItalic, + std::unique_ptr<uint8_t, FxFreeDeleter> pData, + uint32_t size); + + FontDesc* GetCachedTTCFontDesc(int ttc_size, uint32_t checksum); + FontDesc* AddCachedTTCFontDesc(int ttc_size, + uint32_t checksum, std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size); - CTTFontDesc* GetCachedTTCFontDesc(int ttc_size, uint32_t checksum); - CTTFontDesc* AddCachedTTCFontDesc( - int ttc_size, - uint32_t checksum, - std::unique_ptr<uint8_t, FxFreeDeleter> pData, - uint32_t size); - RetainPtr<CFX_Face> NewFixedFace(pdfium::span<const uint8_t> span, int face_index); RetainPtr<CFX_Face> FindSubstFont(const ByteString& face_name, @@ -70,7 +87,7 @@ // Must come before |m_pBuiltinMapper| and |m_FaceMap|. ScopedFXFTLibraryRec const m_FTLibrary; std::unique_ptr<CFX_FontMapper> m_pBuiltinMapper; - std::map<ByteString, std::unique_ptr<CTTFontDesc>> m_FaceMap; + std::map<ByteString, std::unique_ptr<FontDesc>> m_FaceMap; const bool m_FTLibrarySupportsHinting; };
diff --git a/core/fxge/cttfontdesc.cpp b/core/fxge/cttfontdesc.cpp deleted file mode 100644 index 42c8a60..0000000 --- a/core/fxge/cttfontdesc.cpp +++ /dev/null
@@ -1,27 +0,0 @@ -// 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/cttfontdesc.h" - -#include <utility> - -#include "core/fxge/cfx_face.h" - -CTTFontDesc::CTTFontDesc(std::unique_ptr<uint8_t, FxFreeDeleter> pData, - size_t size) - : m_pFontData(std::move(pData)), m_Size(size) {} - -CTTFontDesc::~CTTFontDesc() = default; - -void CTTFontDesc::SetFace(size_t index, CFX_Face* face) { - ASSERT(index < FX_ArraySize(m_TTCFaces)); - m_TTCFaces[index].Reset(face); -} - -CFX_Face* CTTFontDesc::GetFace(size_t index) const { - ASSERT(index < FX_ArraySize(m_TTCFaces)); - return m_TTCFaces[index].Get(); -}
diff --git a/core/fxge/cttfontdesc.h b/core/fxge/cttfontdesc.h deleted file mode 100644 index ac57d69..0000000 --- a/core/fxge/cttfontdesc.h +++ /dev/null
@@ -1,36 +0,0 @@ -// 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_CTTFONTDESC_H_ -#define CORE_FXGE_CTTFONTDESC_H_ - -#include <memory> - -#include "core/fxcrt/fx_memory.h" -#include "core/fxcrt/fx_system.h" -#include "core/fxcrt/observed_ptr.h" -#include "third_party/base/span.h" - -class CFX_Face; - -class CTTFontDesc { - public: - CTTFontDesc(std::unique_ptr<uint8_t, FxFreeDeleter> pData, size_t size); - ~CTTFontDesc(); - - pdfium::span<const uint8_t> FontData() const { - return {m_pFontData.get(), m_Size}; - } - void SetFace(size_t index, CFX_Face* face); - CFX_Face* GetFace(size_t index) const; - - private: - std::unique_ptr<uint8_t, FxFreeDeleter> const m_pFontData; - const size_t m_Size; - ObservedPtr<CFX_Face> m_TTCFaces[16]; -}; - -#endif // CORE_FXGE_CTTFONTDESC_H_