From 3db36ef21df4187877f50212aec43ad865abb42c Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 14 Sep 2018 23:19:51 +0000 Subject: Add CPDF_Document::StockFontClearer. So CPDF_Document's dtor does not have to do any explicit cleanup. Change-Id: Iaec7d18f67422914542fc1dc5f3b1b5a9cf5ffc5 Reviewed-on: https://pdfium-review.googlesource.com/42551 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- core/fpdfapi/parser/cpdf_document.cpp | 16 ++++++++++------ core/fpdfapi/parser/cpdf_document.h | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index 233b98e3af..c82112e044 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -185,13 +185,10 @@ std::unique_ptr CalculateFontDesc( CPDF_Document::CPDF_Document() : m_pDocPage(pdfium::MakeUnique(this)), - m_pDocRender(pdfium::MakeUnique(this)) {} + m_pDocRender(pdfium::MakeUnique(this)), + m_StockFontClearer(this) {} -CPDF_Document::~CPDF_Document() { - // Destroy the extension before doing any non-extension teardown. - m_pExtension.reset(); - CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(this); -} +CPDF_Document::~CPDF_Document() = default; std::unique_ptr CPDF_Document::ParseIndirectObject( uint32_t objnum) { @@ -883,3 +880,10 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont) { return LoadFont(pBaseDict); } #endif // _FX_PLATFORM_ == _FX_PLATFORM_WINDOWS_ + +CPDF_Document::StockFontClearer::StockFontClearer(CPDF_Document* pDoc) + : m_pDoc(pDoc) {} + +CPDF_Document::StockFontClearer::~StockFontClearer() { + CPDF_ModuleMgr::Get()->GetPageModule()->ClearStockFont(m_pDoc.Get()); +} diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index 09bfb21550..be3f30ce5d 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -125,6 +125,15 @@ class CPDF_Document : public Observable, #endif protected: + class StockFontClearer { + public: + explicit StockFontClearer(CPDF_Document* pDoc); + ~StockFontClearer(); + + private: + UnownedPtr const m_pDoc; + }; + // Retrieve page count information by getting count value from the tree nodes int RetrievePageCount(); // When this method is called, m_pTreeTraversal[level] exists. @@ -171,6 +180,11 @@ class CPDF_Document : public Observable, std::unique_ptr m_pCodecContext; std::unique_ptr m_pLinksContext; std::vector m_PageList; // Page number to page's dict objnum. + + // Must be second to last. + StockFontClearer m_StockFontClearer; + + // Must be last. Destroy the extension before any non-extension teardown. std::unique_ptr m_pExtension; }; -- cgit v1.2.3