From 4734512572776f8fc705e28fba8a46d981372e99 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 24 May 2017 14:07:18 -0700 Subject: Convert to CFX_UnownedPtr, part 8 Change-Id: I99d6b4df72e369652301c36e4046f03ef95ed07d Reviewed-on: https://pdfium-review.googlesource.com/5837 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 13 ++++++----- core/fpdfapi/edit/cpdf_pagecontentgenerator.h | 7 +++--- core/fpdfapi/page/cpdf_color.cpp | 31 +++++++++++++++---------- core/fpdfapi/page/cpdf_colorspace.h | 7 +++--- core/fpdfapi/page/cpdf_docpagedata.cpp | 19 ++++++++------- core/fpdfapi/page/cpdf_docpagedata.h | 3 ++- core/fpdfapi/page/cpdf_image.cpp | 10 ++++---- core/fpdfapi/page/cpdf_image.h | 9 +++---- core/fpdfapi/parser/cpdf_hint_tables.h | 5 ++-- 9 files changed, 58 insertions(+), 46 deletions(-) diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 8238414e64..fe65e5916c 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -52,7 +52,7 @@ CPDF_PageContentGenerator::CPDF_PageContentGenerator(CPDF_Page* pPage) : m_pPage(pPage), m_pDocument(m_pPage->m_pDocument.Get()) { for (const auto& pObj : *pPage->GetPageObjectList()) { if (pObj) - m_pageObjects.push_back(pObj.get()); + m_pageObjects.emplace_back(pObj.get()); } } @@ -60,7 +60,7 @@ CPDF_PageContentGenerator::~CPDF_PageContentGenerator() {} void CPDF_PageContentGenerator::GenerateContent() { CFX_ByteTextBuf buf; - for (CPDF_PageObject* pPageObj : m_pageObjects) { + for (auto& pPageObj : m_pageObjects) { if (CPDF_ImageObject* pImageObject = pPageObj->AsImage()) ProcessImage(&buf, pImageObject); else if (CPDF_PathObject* pPathObj = pPageObj->AsPath()) @@ -76,7 +76,7 @@ void CPDF_PageContentGenerator::GenerateContent() { CPDF_Stream* pStream = m_pDocument->NewIndirect(); pStream->SetData(buf.GetBuffer(), buf.GetLength()); - pPageDict->SetNewFor("Contents", m_pDocument, + pPageDict->SetNewFor("Contents", m_pDocument.Get(), pStream->GetObjNum()); } @@ -87,7 +87,7 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( if (!m_pPage->m_pResources) { m_pPage->m_pResources = m_pDocument->NewIndirect(); m_pPage->m_pFormDict->SetNewFor( - "Resources", m_pDocument, m_pPage->m_pResources->GetObjNum()); + "Resources", m_pDocument.Get(), m_pPage->m_pResources->GetObjNum()); } CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType); if (!pResList) @@ -102,7 +102,8 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( } idnum++; } - pResList->SetNewFor(name, m_pDocument, dwResourceObjNum); + pResList->SetNewFor(name, m_pDocument.Get(), + dwResourceObjNum); return name; } @@ -246,7 +247,7 @@ void CPDF_PageContentGenerator::ProcessText(CFX_ByteTextBuf* buf, *buf << "BT " << pTextObj->GetTextMatrix() << " Tm "; CPDF_Font* pFont = pTextObj->GetFont(); if (!pFont) - pFont = CPDF_Font::GetStockFont(m_pDocument, "Helvetica"); + pFont = CPDF_Font::GetStockFont(m_pDocument.Get(), "Helvetica"); FontData fontD; if (pFont->IsType1Font()) fontD.type = "Type1"; diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h index 73e75187e4..6c54d3130e 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h @@ -9,6 +9,7 @@ #include +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_system.h" @@ -36,9 +37,9 @@ class CPDF_PageContentGenerator { CFX_ByteString RealizeResource(uint32_t dwResourceObjNum, const CFX_ByteString& bsType); - CPDF_Page* const m_pPage; - CPDF_Document* const m_pDocument; - std::vector m_pageObjects; + CFX_UnownedPtr const m_pPage; + CFX_UnownedPtr const m_pDocument; + std::vector> m_pageObjects; }; #endif // CORE_FPDFAPI_EDIT_CPDF_PAGECONTENTGENERATOR_H_ diff --git a/core/fpdfapi/page/cpdf_color.cpp b/core/fpdfapi/page/cpdf_color.cpp index ca0e621530..7e0675df15 100644 --- a/core/fpdfapi/page/cpdf_color.cpp +++ b/core/fpdfapi/page/cpdf_color.cpp @@ -42,12 +42,17 @@ void CPDF_Color::ReleaseBuffer() { } void CPDF_Color::ReleaseColorSpace() { - if (!m_pCS || !m_pCS->m_pDocument) + if (!m_pCS) + return; + + CPDF_Document* pDoc = m_pCS->GetDocument(); + if (!pDoc) return; - auto* pPageData = m_pCS->m_pDocument->GetPageData(); + auto* pPageData = pDoc->GetPageData(); if (pPageData) pPageData->ReleaseColorSpace(m_pCS->GetArray()); + m_pCS = nullptr; } @@ -111,16 +116,17 @@ void CPDF_Color::SetValue(CPDF_Pattern* pPattern, float* comps, int ncomps) { void CPDF_Color::Copy(const CPDF_Color* pSrc) { ReleaseBuffer(); ReleaseColorSpace(); - m_pCS = pSrc->m_pCS; - if (m_pCS && m_pCS->m_pDocument) { - CPDF_Array* pArray = m_pCS->GetArray(); - if (pArray) - m_pCS = m_pCS->m_pDocument->GetPageData()->GetCopiedColorSpace(pArray); - } if (!m_pCS) return; + CPDF_Document* pDoc = m_pCS->GetDocument(); + CPDF_Array* pArray = m_pCS->GetArray(); + if (pDoc && pArray) { + m_pCS = pDoc->GetPageData()->GetCopiedColorSpace(pArray); + if (!m_pCS) + return; + } m_pBuffer = m_pCS->CreateBuf(); memcpy(m_pBuffer, pSrc->m_pBuffer, m_pCS->GetBufSize()); if (m_pCS->GetFamily() != PDFCS_PATTERN) @@ -128,10 +134,11 @@ void CPDF_Color::Copy(const CPDF_Color* pSrc) { PatternValue* pValue = reinterpret_cast(m_pBuffer); CPDF_Pattern* pPattern = pValue->m_pPattern; - if (pPattern) { - pValue->m_pPattern = pPattern->document()->GetPageData()->GetPattern( - pPattern->pattern_obj(), false, pPattern->parent_matrix()); - } + if (!pPattern) + return; + + pValue->m_pPattern = pPattern->document()->GetPageData()->GetPattern( + pPattern->pattern_obj(), false, pPattern->parent_matrix()); } bool CPDF_Color::GetRGB(int* R, int* G, int* B) const { diff --git a/core/fpdfapi/page/cpdf_colorspace.h b/core/fpdfapi/page/cpdf_colorspace.h index 15029026c2..9e1c4dea18 100644 --- a/core/fpdfapi/page/cpdf_colorspace.h +++ b/core/fpdfapi/page/cpdf_colorspace.h @@ -61,13 +61,11 @@ class CPDF_ColorSpace { int image_width, int image_height, bool bTransMask) const; - - CPDF_Array* GetArray() const { return m_pArray.Get(); } virtual CPDF_ColorSpace* GetBaseCS() const; - virtual void EnableStdConversion(bool bEnabled); - CPDF_Document* const m_pDocument; + CPDF_Array* GetArray() const { return m_pArray.Get(); } + CPDF_Document* GetDocument() const { return m_pDocument.Get(); } protected: CPDF_ColorSpace(CPDF_Document* pDoc, int family, uint32_t nComponents); @@ -81,6 +79,7 @@ class CPDF_ColorSpace { float* k) const; virtual bool v_SetCMYK(float* pBuf, float c, float m, float y, float k) const; + CFX_UnownedPtr const m_pDocument; int m_Family; uint32_t m_nComponents; CFX_UnownedPtr m_pArray; diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp index 58e81559ea..435b0f2eec 100644 --- a/core/fpdfapi/page/cpdf_docpagedata.cpp +++ b/core/fpdfapi/page/cpdf_docpagedata.cpp @@ -28,7 +28,7 @@ #include "third_party/base/stl_util.h" CPDF_DocPageData::CPDF_DocPageData(CPDF_Document* pPDFDoc) - : m_pPDFDoc(pPDFDoc), m_bForceClear(false) { + : m_bForceClear(false), m_pPDFDoc(pPDFDoc) { assert(m_pPDFDoc); } @@ -117,7 +117,8 @@ CPDF_Font* CPDF_DocPageData::GetFont(CPDF_Dictionary* pFontDict) { return pFontData->AddRef(); } } - std::unique_ptr pFont = CPDF_Font::Create(m_pPDFDoc, pFontDict); + std::unique_ptr pFont = + CPDF_Font::Create(m_pPDFDoc.Get(), pFontDict); if (!pFont) return nullptr; @@ -165,7 +166,7 @@ CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName, pEncoding->Realize(m_pPDFDoc->GetByteStringPool())); } - std::unique_ptr pFont = CPDF_Font::Create(m_pPDFDoc, pDict); + std::unique_ptr pFont = CPDF_Font::Create(m_pPDFDoc.Get(), pDict); if (!pFont) return nullptr; @@ -268,7 +269,7 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceImpl( } std::unique_ptr pCS = - CPDF_ColorSpace::Load(m_pPDFDoc, pArray); + CPDF_ColorSpace::Load(m_pPDFDoc.Get(), pArray); if (!pCS) return nullptr; @@ -329,18 +330,18 @@ CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, } std::unique_ptr pPattern; if (bShading) { - pPattern = pdfium::MakeUnique(m_pPDFDoc, pPatternObj, - true, matrix); + pPattern = pdfium::MakeUnique( + m_pPDFDoc.Get(), pPatternObj, true, matrix); } else { CPDF_Dictionary* pDict = pPatternObj->GetDict(); if (pDict) { int type = pDict->GetIntegerFor("PatternType"); if (type == CPDF_Pattern::TILING) { - pPattern = pdfium::MakeUnique(m_pPDFDoc, + pPattern = pdfium::MakeUnique(m_pPDFDoc.Get(), pPatternObj, matrix); } else if (type == CPDF_Pattern::SHADING) { pPattern = pdfium::MakeUnique( - m_pPDFDoc, pPatternObj, false, matrix); + m_pPDFDoc.Get(), pPatternObj, false, matrix); } } } @@ -382,7 +383,7 @@ CFX_RetainPtr CPDF_DocPageData::GetImage(uint32_t dwStreamObjNum) { if (it != m_ImageMap.end()) return it->second; - auto pImage = pdfium::MakeRetain(m_pPDFDoc, dwStreamObjNum); + auto pImage = pdfium::MakeRetain(m_pPDFDoc.Get(), dwStreamObjNum); m_ImageMap[dwStreamObjNum] = pImage; return pImage; } diff --git a/core/fpdfapi/page/cpdf_docpagedata.h b/core/fpdfapi/page/cpdf_docpagedata.h index f5ac303290..32d220b756 100644 --- a/core/fpdfapi/page/cpdf_docpagedata.h +++ b/core/fpdfapi/page/cpdf_docpagedata.h @@ -11,6 +11,7 @@ #include #include "core/fpdfapi/page/cpdf_countedobject.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" @@ -66,8 +67,8 @@ class CPDF_DocPageData { const CPDF_Dictionary* pResources, std::set* pVisited); - CPDF_Document* const m_pPDFDoc; bool m_bForceClear; + CFX_UnownedPtr const m_pPDFDoc; std::map m_HashProfileMap; std::map m_ColorSpaceMap; std::map> m_FontFileMap; diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 7d16dd9618..efdd66b442 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -234,8 +234,8 @@ void CPDF_Image::SetImage(const CFX_RetainPtr& pBitmap) { pdfium::MakeUnique(m_pDocument->GetByteStringPool()); CPDF_Stream* pCTS = m_pDocument->NewIndirect( std::move(pColorTable), iPalette * 3, std::move(pNewDict)); - pCS->AddNew(m_pDocument, pCTS->GetObjNum()); - pDict->SetNewFor("ColorSpace", m_pDocument, + pCS->AddNew(m_pDocument.Get(), pCTS->GetObjNum()); + pDict->SetNewFor("ColorSpace", m_pDocument.Get(), pCS->GetObjNum()); } else { pDict->SetNewFor("ColorSpace", "DeviceGray"); @@ -277,7 +277,7 @@ void CPDF_Image::SetImage(const CFX_RetainPtr& pBitmap) { pMaskDict->SetNewFor("Length", mask_size); CPDF_Stream* pNewStream = m_pDocument->NewIndirect( std::move(mask_buf), mask_size, std::move(pMaskDict)); - pDict->SetNewFor("SMask", m_pDocument, + pDict->SetNewFor("SMask", m_pDocument.Get(), pNewStream->GetObjNum()); } @@ -329,7 +329,7 @@ void CPDF_Image::ResetCache(CPDF_Page* pPage, CFX_RetainPtr CPDF_Image::LoadDIBSource() const { auto source = pdfium::MakeRetain(); - if (!source->Load(m_pDocument, m_pStream.Get())) + if (!source->Load(m_pDocument.Get(), m_pStream.Get())) return nullptr; return source; @@ -349,7 +349,7 @@ bool CPDF_Image::StartLoadDIBSource(CPDF_Dictionary* pFormResource, uint32_t GroupFamily, bool bLoadMask) { auto source = pdfium::MakeRetain(); - int ret = source->StartLoadDIBSource(m_pDocument, m_pStream.Get(), true, + int ret = source->StartLoadDIBSource(m_pDocument.Get(), m_pStream.Get(), true, pFormResource, pPageResource, bStdCS, GroupFamily, bLoadMask); if (!ret) { diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h index 7b7e090b49..c09ce1a46d 100644 --- a/core/fpdfapi/page/cpdf_image.h +++ b/core/fpdfapi/page/cpdf_image.h @@ -12,6 +12,7 @@ #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxcrt/cfx_maybe_owned.h" #include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_system.h" class CFX_DIBSource; @@ -33,8 +34,8 @@ class CPDF_Image : public CFX_Retainable { CPDF_Dictionary* GetDict() const { return m_pStream ? m_pStream->GetDict() : nullptr; } - CPDF_Dictionary* GetOC() const { return m_pOC; } - CPDF_Document* GetDocument() const { return m_pDocument; } + CPDF_Dictionary* GetOC() const { return m_pOC.Get(); } + CPDF_Document* GetDocument() const { return m_pDocument.Get(); } int32_t GetPixelHeight() const { return m_Height; } int32_t GetPixelWidth() const { return m_Width; } @@ -78,10 +79,10 @@ class CPDF_Image : public CFX_Retainable { bool m_bIsInline = false; bool m_bIsMask = false; bool m_bInterpolate = false; - CPDF_Document* const m_pDocument; + CFX_UnownedPtr const m_pDocument; CFX_MaybeOwned m_pStream; CFX_MaybeOwned m_pDict; - CPDF_Dictionary* m_pOC = nullptr; + CFX_UnownedPtr m_pOC; }; #endif // CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_ diff --git a/core/fpdfapi/parser/cpdf_hint_tables.h b/core/fpdfapi/parser/cpdf_hint_tables.h index e0bc6e0751..25f276ce55 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.h +++ b/core/fpdfapi/parser/cpdf_hint_tables.h @@ -10,6 +10,7 @@ #include #include "core/fpdfapi/parser/cpdf_data_avail.h" +#include "core/fxcrt/cfx_unowned_ptr.h" #include "core/fxcrt/fx_basic.h" #include "core/fxcrt/fx_stream.h" @@ -51,10 +52,10 @@ class CPDF_HintTables { const std::vector& szArray); // Owner, outlives this object. - CPDF_DataAvail* const m_pDataAvail; + CFX_UnownedPtr const m_pDataAvail; // Owned by |m_pDataAvail|. - CPDF_LinearizedHeader* const m_pLinearized; + CFX_UnownedPtr const m_pLinearized; uint32_t m_nFirstPageSharedObjs; FX_FILESIZE m_szFirstPageObjOffset; -- cgit v1.2.3