summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_parser.cpp21
-rw-r--r--core/fpdfapi/fpdf_parser/include/cpdf_parser.h4
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render_image.cpp25
-rw-r--r--core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp27
-rw-r--r--core/fpdfapi/fpdf_render/render_int.h8
5 files changed, 43 insertions, 42 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp
index 5540877642..e2c88d7e71 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_parser.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_parser.cpp
@@ -51,8 +51,7 @@ int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) {
} // namespace
CPDF_Parser::CPDF_Parser()
- : m_pDocument(nullptr),
- m_bOwnFileRead(true),
+ : m_bOwnFileRead(true),
m_FileVersion(0),
m_pTrailer(nullptr),
m_pEncryptDict(nullptr),
@@ -127,8 +126,7 @@ void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) {
void CPDF_Parser::CloseParser() {
m_bVersionUpdated = false;
- delete m_pDocument;
- m_pDocument = nullptr;
+ m_pDocument.reset();
if (m_pTrailer) {
m_pTrailer->Release();
@@ -190,7 +188,7 @@ CPDF_Parser::Error CPDF_Parser::StartParse(IFX_FileRead* pFileAccess) {
return FORMAT_ERROR;
m_pSyntax->RestorePos(m_pSyntax->m_FileLen - m_pSyntax->m_HeaderOffset - 9);
- m_pDocument = new CPDF_Document(this);
+ m_pDocument.reset(new CPDF_Document(this));
FX_BOOL bXRefRebuilt = FALSE;
if (m_pSyntax->SearchWord("startxref", TRUE, FALSE, 4096)) {
@@ -765,7 +763,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
last_obj = start_pos;
FX_FILESIZE obj_end = 0;
CPDF_Object* pObject = ParseIndirectObjectAtByStrict(
- m_pDocument, obj_pos, objnum, &obj_end);
+ m_pDocument.get(), obj_pos, objnum, &obj_end);
if (CPDF_Stream* pStream = ToStream(pObject)) {
if (CPDF_Dictionary* pDict = pStream->GetDict()) {
if ((pDict->KeyExist("Type")) &&
@@ -828,7 +826,8 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
last_trailer = pos + i - 7;
m_pSyntax->RestorePos(pos + i - m_pSyntax->m_HeaderOffset);
- CPDF_Object* pObj = m_pSyntax->GetObject(m_pDocument, 0, 0, true);
+ CPDF_Object* pObj =
+ m_pSyntax->GetObject(m_pDocument.get(), 0, 0, true);
if (pObj) {
if (!pObj->IsDictionary() && !pObj->AsStream()) {
pObj->Release();
@@ -850,7 +849,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
uint32_t dwObjNum =
pElement ? pElement->GetObjNum() : 0;
if (dwObjNum) {
- m_pTrailer->SetAtReference(key, m_pDocument,
+ m_pTrailer->SetAtReference(key, m_pDocument.get(),
dwObjNum);
} else {
m_pTrailer->SetAt(key, pElement->Clone());
@@ -974,7 +973,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
}
FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) {
- CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0);
+ CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument.get(), *pos, 0);
if (!pObject)
return FALSE;
@@ -1472,7 +1471,7 @@ CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() {
return nullptr;
std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj(
- m_pSyntax->GetObject(m_pDocument, 0, 0, true));
+ m_pSyntax->GetObject(m_pDocument.get(), 0, 0, true));
if (!ToDictionary(pObj.get()))
return nullptr;
return pObj.release()->AsDictionary();
@@ -1559,7 +1558,7 @@ CPDF_Parser::Error CPDF_Parser::StartAsyncParse(IFX_FileRead* pFileAccess) {
return StartParse(pFileAccess);
}
- m_pDocument = new CPDF_Document(this);
+ m_pDocument.reset(new CPDF_Document(this));
FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos();
FX_BOOL bXRefRebuilt = FALSE;
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_parser.h b/core/fpdfapi/fpdf_parser/include/cpdf_parser.h
index b468bead9d..1291180197 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_parser.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_parser.h
@@ -44,7 +44,7 @@ class CPDF_Parser {
CFX_ByteString GetPassword() { return m_Password; }
CPDF_Dictionary* GetTrailer() const { return m_pTrailer; }
FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; }
- CPDF_Document* GetDocument() const { return m_pDocument; }
+ CPDF_Document* GetDocument() const { return m_pDocument.get(); }
uint32_t GetRootObjNum();
uint32_t GetInfoObjNum();
@@ -118,7 +118,7 @@ class CPDF_Parser {
// the objects.
bool VerifyCrossRefV4();
- CPDF_Document* m_pDocument;
+ std::unique_ptr<CPDF_Document> m_pDocument;
std::unique_ptr<CPDF_SyntaxParser> m_pSyntax;
bool m_bOwnFileRead;
int m_FileVersion;
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
index b9826a9338..0ea4a17684 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_image.cpp
@@ -326,29 +326,26 @@ void CPDF_DIBTransferFunc::TranslateDownSamples(uint8_t* dest_buf,
#endif
}
}
+
CPDF_ImageRenderer::CPDF_ImageRenderer() {
m_pRenderStatus = nullptr;
m_pImageObject = nullptr;
m_Result = TRUE;
m_Status = 0;
- m_pTransformer = nullptr;
m_DeviceHandle = nullptr;
- m_LoadHandle = nullptr;
- m_pClone = nullptr;
m_bStdCS = FALSE;
m_bPatternColor = FALSE;
m_BlendType = FXDIB_BLEND_NORMAL;
m_pPattern = nullptr;
m_pObj2Device = nullptr;
}
+
CPDF_ImageRenderer::~CPDF_ImageRenderer() {
- delete m_pTransformer;
if (m_DeviceHandle) {
m_pRenderStatus->m_pDevice->CancelDIBits(m_DeviceHandle);
}
- delete m_LoadHandle;
- delete m_pClone;
}
+
FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() {
CFX_FloatRect image_rect_f = m_ImageMatrix.GetUnitRect();
FX_RECT image_rect = image_rect_f.GetOutterRect();
@@ -361,7 +358,7 @@ FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() {
dest_height = -dest_height;
}
if (m_Loader.Start(m_pImageObject,
- m_pRenderStatus->m_pContext->GetPageCache(), m_LoadHandle,
+ m_pRenderStatus->m_pContext->GetPageCache(), &m_LoadHandle,
m_bStdCS, m_pRenderStatus->m_GroupFamily,
m_pRenderStatus->m_bLoadMask, m_pRenderStatus, dest_width,
dest_height)) {
@@ -372,6 +369,7 @@ FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() {
}
return FALSE;
}
+
FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() {
if (!m_Loader.m_pBitmap) {
return FALSE;
@@ -416,10 +414,10 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() {
}
m_FillArgb = m_pRenderStatus->GetFillArgb(m_pImageObject);
} else if (m_pRenderStatus->m_Options.m_ColorMode == RENDER_COLOR_GRAY) {
- m_pClone = m_pDIBSource->Clone();
+ m_pClone.reset(m_pDIBSource->Clone());
m_pClone->ConvertColorScale(m_pRenderStatus->m_Options.m_BackColor,
m_pRenderStatus->m_Options.m_ForeColor);
- m_pDIBSource = m_pClone;
+ m_pDIBSource = m_pClone.get();
}
m_Flags = 0;
if (m_pRenderStatus->m_Options.m_Flags & RENDER_FORCE_DOWNSAMPLE) {
@@ -488,6 +486,7 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() {
}
return StartDIBSource();
}
+
FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
const CPDF_PageObject* pObj,
const CFX_Matrix* pObj2Device,
@@ -510,6 +509,7 @@ FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
}
return StartRenderDIBSource();
}
+
FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
const CFX_DIBSource* pDIBSource,
FX_ARGB bitmap_argb,
@@ -528,6 +528,7 @@ FX_BOOL CPDF_ImageRenderer::Start(CPDF_RenderStatus* pStatus,
m_BlendType = blendType;
return StartDIBSource();
}
+
FX_BOOL CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) {
if (m_pRenderStatus->m_bPrint &&
!(m_pRenderStatus->m_pDevice->GetRenderCaps() & FXRC_BLEND_MODE)) {
@@ -773,8 +774,8 @@ FX_BOOL CPDF_ImageRenderer::StartDIBSource() {
FX_RECT clip_box = m_pRenderStatus->m_pDevice->GetClipBox();
clip_box.Intersect(image_rect);
m_Status = 2;
- m_pTransformer = new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix,
- m_Flags, &clip_box);
+ m_pTransformer.reset(new CFX_ImageTransformer(m_pDIBSource, &m_ImageMatrix,
+ m_Flags, &clip_box));
m_pTransformer->Start();
return TRUE;
}
@@ -896,7 +897,7 @@ FX_BOOL CPDF_ImageRenderer::Continue(IFX_Pause* pPause) {
return m_pRenderStatus->m_pDevice->ContinueDIBits(m_DeviceHandle, pPause);
if (m_Status == 4) {
- if (m_Loader.Continue(m_LoadHandle, pPause))
+ if (m_Loader.Continue(m_LoadHandle.get(), pPause))
return TRUE;
if (StartRenderDIBSource())
diff --git a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index 2b829d0c56..91574345d3 100644
--- a/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -1548,21 +1548,22 @@ FX_BOOL CPDF_ImageLoaderHandle::Continue(IFX_Pause* pPause) {
return ret;
}
-FX_BOOL CPDF_ImageLoader::Start(const CPDF_ImageObject* pImage,
- CPDF_PageRenderCache* pCache,
- CPDF_ImageLoaderHandle*& LoadHandle,
- FX_BOOL bStdCS,
- uint32_t GroupFamily,
- FX_BOOL bLoadMask,
- CPDF_RenderStatus* pRenderStatus,
- int32_t nDownsampleWidth,
- int32_t nDownsampleHeight) {
+FX_BOOL CPDF_ImageLoader::Start(
+ const CPDF_ImageObject* pImage,
+ CPDF_PageRenderCache* pCache,
+ std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle,
+ FX_BOOL bStdCS,
+ uint32_t GroupFamily,
+ FX_BOOL bLoadMask,
+ CPDF_RenderStatus* pRenderStatus,
+ int32_t nDownsampleWidth,
+ int32_t nDownsampleHeight) {
m_nDownsampleWidth = nDownsampleWidth;
m_nDownsampleHeight = nDownsampleHeight;
- LoadHandle = new CPDF_ImageLoaderHandle;
- return LoadHandle->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask,
- pRenderStatus, m_nDownsampleWidth,
- m_nDownsampleHeight);
+ pLoadHandle->reset(new CPDF_ImageLoaderHandle);
+ return (*pLoadHandle)
+ ->Start(this, pImage, pCache, bStdCS, GroupFamily, bLoadMask,
+ pRenderStatus, m_nDownsampleWidth, m_nDownsampleHeight);
}
FX_BOOL CPDF_ImageLoader::Continue(CPDF_ImageLoaderHandle* LoadHandle,
diff --git a/core/fpdfapi/fpdf_render/render_int.h b/core/fpdfapi/fpdf_render/render_int.h
index d86a62ab19..99d1dfc292 100644
--- a/core/fpdfapi/fpdf_render/render_int.h
+++ b/core/fpdfapi/fpdf_render/render_int.h
@@ -293,7 +293,7 @@ class CPDF_ImageLoader {
FX_BOOL Start(const CPDF_ImageObject* pImage,
CPDF_PageRenderCache* pCache,
- CPDF_ImageLoaderHandle*& LoadHandle,
+ std::unique_ptr<CPDF_ImageLoaderHandle>* pLoadHandle,
FX_BOOL bStdCS = FALSE,
uint32_t GroupFamily = 0,
FX_BOOL bLoadMask = FALSE,
@@ -373,15 +373,15 @@ class CPDF_ImageRenderer {
CFX_Matrix m_ImageMatrix;
CPDF_ImageLoader m_Loader;
const CFX_DIBSource* m_pDIBSource;
- CFX_DIBitmap* m_pClone;
+ std::unique_ptr<CFX_DIBitmap> m_pClone;
int m_BitmapAlpha;
FX_BOOL m_bPatternColor;
CPDF_Pattern* m_pPattern;
FX_ARGB m_FillArgb;
uint32_t m_Flags;
- CFX_ImageTransformer* m_pTransformer;
+ std::unique_ptr<CFX_ImageTransformer> m_pTransformer;
void* m_DeviceHandle;
- CPDF_ImageLoaderHandle* m_LoadHandle;
+ std::unique_ptr<CPDF_ImageLoaderHandle> m_LoadHandle;
FX_BOOL m_bStdCS;
int m_BlendType;
};