summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_color.cpp31
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.h7
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp19
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.h3
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp10
-rw-r--r--core/fpdfapi/page/cpdf_image.h9
6 files changed, 44 insertions, 35 deletions
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<PatternValue*>(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<CPDF_Document> const m_pDocument;
int m_Family;
uint32_t m_nComponents;
CFX_UnownedPtr<CPDF_Array> 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<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pFontDict);
+ std::unique_ptr<CPDF_Font> 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<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pDict);
+ std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc.Get(), pDict);
if (!pFont)
return nullptr;
@@ -268,7 +269,7 @@ CPDF_ColorSpace* CPDF_DocPageData::GetColorSpaceImpl(
}
std::unique_ptr<CPDF_ColorSpace> 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<CPDF_Pattern> pPattern;
if (bShading) {
- pPattern = pdfium::MakeUnique<CPDF_ShadingPattern>(m_pPDFDoc, pPatternObj,
- true, matrix);
+ pPattern = pdfium::MakeUnique<CPDF_ShadingPattern>(
+ 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<CPDF_TilingPattern>(m_pPDFDoc,
+ pPattern = pdfium::MakeUnique<CPDF_TilingPattern>(m_pPDFDoc.Get(),
pPatternObj, matrix);
} else if (type == CPDF_Pattern::SHADING) {
pPattern = pdfium::MakeUnique<CPDF_ShadingPattern>(
- m_pPDFDoc, pPatternObj, false, matrix);
+ m_pPDFDoc.Get(), pPatternObj, false, matrix);
}
}
}
@@ -382,7 +383,7 @@ CFX_RetainPtr<CPDF_Image> CPDF_DocPageData::GetImage(uint32_t dwStreamObjNum) {
if (it != m_ImageMap.end())
return it->second;
- auto pImage = pdfium::MakeRetain<CPDF_Image>(m_pPDFDoc, dwStreamObjNum);
+ auto pImage = pdfium::MakeRetain<CPDF_Image>(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 <set>
#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<CPDF_Object*>* pVisited);
- CPDF_Document* const m_pPDFDoc;
bool m_bForceClear;
+ CFX_UnownedPtr<CPDF_Document> const m_pPDFDoc;
std::map<CFX_ByteString, CPDF_Stream*> m_HashProfileMap;
std::map<const CPDF_Object*, CPDF_CountedColorSpace*> m_ColorSpaceMap;
std::map<const CPDF_Stream*, CFX_RetainPtr<CPDF_StreamAcc>> 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<CFX_DIBitmap>& pBitmap) {
pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
CPDF_Stream* pCTS = m_pDocument->NewIndirect<CPDF_Stream>(
std::move(pColorTable), iPalette * 3, std::move(pNewDict));
- pCS->AddNew<CPDF_Reference>(m_pDocument, pCTS->GetObjNum());
- pDict->SetNewFor<CPDF_Reference>("ColorSpace", m_pDocument,
+ pCS->AddNew<CPDF_Reference>(m_pDocument.Get(), pCTS->GetObjNum());
+ pDict->SetNewFor<CPDF_Reference>("ColorSpace", m_pDocument.Get(),
pCS->GetObjNum());
} else {
pDict->SetNewFor<CPDF_Name>("ColorSpace", "DeviceGray");
@@ -277,7 +277,7 @@ void CPDF_Image::SetImage(const CFX_RetainPtr<CFX_DIBitmap>& pBitmap) {
pMaskDict->SetNewFor<CPDF_Number>("Length", mask_size);
CPDF_Stream* pNewStream = m_pDocument->NewIndirect<CPDF_Stream>(
std::move(mask_buf), mask_size, std::move(pMaskDict));
- pDict->SetNewFor<CPDF_Reference>("SMask", m_pDocument,
+ pDict->SetNewFor<CPDF_Reference>("SMask", m_pDocument.Get(),
pNewStream->GetObjNum());
}
@@ -329,7 +329,7 @@ void CPDF_Image::ResetCache(CPDF_Page* pPage,
CFX_RetainPtr<CFX_DIBSource> CPDF_Image::LoadDIBSource() const {
auto source = pdfium::MakeRetain<CPDF_DIBSource>();
- 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<CPDF_DIBSource>();
- 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<CPDF_Document> const m_pDocument;
CFX_MaybeOwned<CPDF_Stream> m_pStream;
CFX_MaybeOwned<CPDF_Dictionary> m_pDict;
- CPDF_Dictionary* m_pOC = nullptr;
+ CFX_UnownedPtr<CPDF_Dictionary> m_pOC;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_IMAGE_H_