summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/cpdf_pagerendercontext.cpp5
-rw-r--r--core/fpdfapi/render/cpdf_renderoptions.cpp7
-rw-r--r--core/fpdfapi/render/cpdf_renderoptions.h8
-rw-r--r--core/fpdfdoc/cpdf_annotlist.cpp2
-rw-r--r--core/fpdfdoc/cpdf_occontext.h12
-rw-r--r--fpdfsdk/fpdfformfill.cpp9
-rw-r--r--fpdfsdk/fpdfview.cpp2
7 files changed, 24 insertions, 21 deletions
diff --git a/core/fpdfapi/cpdf_pagerendercontext.cpp b/core/fpdfapi/cpdf_pagerendercontext.cpp
index 91ebc5e7b7..39a881c3b4 100644
--- a/core/fpdfapi/cpdf_pagerendercontext.cpp
+++ b/core/fpdfapi/cpdf_pagerendercontext.cpp
@@ -15,7 +15,4 @@
CPDF_PageRenderContext::CPDF_PageRenderContext() {}
-CPDF_PageRenderContext::~CPDF_PageRenderContext() {
- if (m_pOptions)
- delete m_pOptions->m_pOCContext;
-}
+CPDF_PageRenderContext::~CPDF_PageRenderContext() {}
diff --git a/core/fpdfapi/render/cpdf_renderoptions.cpp b/core/fpdfapi/render/cpdf_renderoptions.cpp
index ea11d7f5ee..717e036fea 100644
--- a/core/fpdfapi/render/cpdf_renderoptions.cpp
+++ b/core/fpdfapi/render/cpdf_renderoptions.cpp
@@ -11,7 +11,6 @@ CPDF_RenderOptions::CPDF_RenderOptions()
m_Flags(RENDER_CLEARTYPE),
m_Interpolation(0),
m_AddFlags(0),
- m_pOCContext(nullptr),
m_dwLimitCacheSize(1024 * 1024 * 100),
m_HalftoneLimit(-1),
m_bDrawAnnots(false) {}
@@ -23,10 +22,12 @@ CPDF_RenderOptions::CPDF_RenderOptions(const CPDF_RenderOptions& rhs)
m_Flags(rhs.m_Flags),
m_Interpolation(rhs.m_Interpolation),
m_AddFlags(rhs.m_AddFlags),
- m_pOCContext(rhs.m_pOCContext),
m_dwLimitCacheSize(rhs.m_dwLimitCacheSize),
m_HalftoneLimit(rhs.m_HalftoneLimit),
- m_bDrawAnnots(rhs.m_bDrawAnnots) {}
+ m_bDrawAnnots(rhs.m_bDrawAnnots),
+ m_pOCContext(rhs.m_pOCContext) {}
+
+CPDF_RenderOptions::~CPDF_RenderOptions() {}
FX_ARGB CPDF_RenderOptions::TranslateColor(FX_ARGB argb) const {
if (m_ColorMode == RENDER_COLOR_NORMAL)
diff --git a/core/fpdfapi/render/cpdf_renderoptions.h b/core/fpdfapi/render/cpdf_renderoptions.h
index 95651d9d7f..b934941d00 100644
--- a/core/fpdfapi/render/cpdf_renderoptions.h
+++ b/core/fpdfapi/render/cpdf_renderoptions.h
@@ -7,11 +7,11 @@
#ifndef CORE_FPDFAPI_RENDER_CPDF_RENDEROPTIONS_H_
#define CORE_FPDFAPI_RENDER_CPDF_RENDEROPTIONS_H_
+#include "core/fpdfdoc/cpdf_occontext.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/fx_dib.h"
-class CPDF_OCContext;
-
#define RENDER_COLOR_NORMAL 0
#define RENDER_COLOR_GRAY 1
#define RENDER_COLOR_TWOCOLOR 2
@@ -37,6 +37,8 @@ class CPDF_RenderOptions {
public:
CPDF_RenderOptions();
CPDF_RenderOptions(const CPDF_RenderOptions& rhs);
+ ~CPDF_RenderOptions();
+
FX_ARGB TranslateColor(FX_ARGB argb) const;
int m_ColorMode;
@@ -45,10 +47,10 @@ class CPDF_RenderOptions {
uint32_t m_Flags;
int m_Interpolation;
uint32_t m_AddFlags;
- CPDF_OCContext* m_pOCContext;
uint32_t m_dwLimitCacheSize;
int m_HalftoneLimit;
bool m_bDrawAnnots;
+ CFX_RetainPtr<CPDF_OCContext> m_pOCContext;
};
#endif // CORE_FPDFAPI_RENDER_CPDF_RENDEROPTIONS_H_
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 1ad6ab23a6..b1bc4c9ca9 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -126,7 +126,7 @@ void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
continue;
if (pOptions) {
- CPDF_OCContext* pOCContext = pOptions->m_pOCContext;
+ CFX_RetainPtr<CPDF_OCContext> pOCContext = pOptions->m_pOCContext;
CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
if (pOCContext && pAnnotDict &&
!pOCContext->CheckOCGVisible(pAnnotDict->GetDictFor("OC"))) {
diff --git a/core/fpdfdoc/cpdf_occontext.h b/core/fpdfdoc/cpdf_occontext.h
index 49bbd76d0c..ecdcfae31b 100644
--- a/core/fpdfdoc/cpdf_occontext.h
+++ b/core/fpdfdoc/cpdf_occontext.h
@@ -9,6 +9,7 @@
#include <unordered_map>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_string.h"
class CPDF_Array;
@@ -16,17 +17,20 @@ class CPDF_Dictionary;
class CPDF_Document;
class CPDF_PageObject;
-class CPDF_OCContext {
+class CPDF_OCContext : public CFX_Retainable {
public:
- enum UsageType { View = 0, Design, Print, Export };
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
- CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType);
- ~CPDF_OCContext();
+ enum UsageType { View = 0, Design, Print, Export };
bool CheckOCGVisible(const CPDF_Dictionary* pOCGDict);
bool CheckObjectVisible(const CPDF_PageObject* pObj);
private:
+ CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType);
+ ~CPDF_OCContext() override;
+
bool LoadOCGStateFromConfig(const CFX_ByteString& csConfig,
const CPDF_Dictionary* pOCGDict) const;
bool LoadOCGState(const CPDF_Dictionary* pOCGDict) const;
diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp
index 6b8cbaa59d..beebe65dbb 100644
--- a/fpdfsdk/fpdfformfill.cpp
+++ b/fpdfsdk/fpdfformfill.cpp
@@ -127,12 +127,13 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
options.m_bDrawAnnots = flags & FPDF_ANNOT;
#ifdef PDF_ENABLE_XFA
- options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View);
+ options.m_pOCContext =
+ pdfium::MakeRetain<CPDF_OCContext>(pPDFDoc, CPDF_OCContext::View);
if (CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, true))
pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip);
#else // PDF_ENABLE_XFA
- options.m_pOCContext =
- new CPDF_OCContext(pPage->m_pDocument, CPDF_OCContext::View);
+ options.m_pOCContext = pdfium::MakeRetain<CPDF_OCContext>(
+ pPage->m_pDocument, CPDF_OCContext::View);
if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage))
pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options);
#endif // PDF_ENABLE_XFA
@@ -142,8 +143,6 @@ void FFLCommon(FPDF_FORMHANDLE hHandle,
pDevice->Flush();
CFXBitmapFromFPDFBitmap(bitmap)->UnPreMultiply();
#endif
- delete options.m_pOCContext;
- options.m_pOCContext = nullptr;
}
} // namespace
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index ff4d46e357..c1dc0df73e 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -94,7 +94,7 @@ void RenderPageImpl(CPDF_PageRenderContext* pContext,
(flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View;
pContext->m_pOptions->m_AddFlags = flags >> 8;
pContext->m_pOptions->m_pOCContext =
- new CPDF_OCContext(pPage->m_pDocument, usage);
+ pdfium::MakeRetain<CPDF_OCContext>(pPage->m_pDocument, usage);
pContext->m_pDevice->SaveState();
pContext->m_pDevice->SetClip_Rect(clipping_rect);