From 761660c4074269ac806d06c9bef70e4e9fb0eb29 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 17 Dec 2015 13:35:22 -0800 Subject: Tidy CPDF_RenderContext - Remove unused Clear() method. - Replace Create() with actual ctors. - Avoid const casts. - Protect members. - Add missing const in adjacent code. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1536623004 . --- core/include/fpdfapi/fpdf_render.h | 28 +++++------------- core/include/fpdfdoc/fpdf_doc.h | 10 +++---- core/src/fpdfapi/fpdf_render/fpdf_render.cpp | 34 +++++++--------------- core/src/fpdfapi/fpdf_render/fpdf_render_cache.cpp | 4 +-- core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 6 ++-- .../fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 3 +- core/src/fpdfdoc/doc_annot.cpp | 13 ++++----- core/src/fpdfdoc/doc_formcontrol.cpp | 16 +++++----- fpdfsdk/src/fpdfview.cpp | 3 +- 9 files changed, 44 insertions(+), 73 deletions(-) diff --git a/core/include/fpdfapi/fpdf_render.h b/core/include/fpdfapi/fpdf_render.h index d7fdbd463d..2460849543 100644 --- a/core/include/fpdfapi/fpdf_render.h +++ b/core/include/fpdfapi/fpdf_render.h @@ -80,19 +80,10 @@ class CPDF_RenderOptions { }; class CPDF_RenderContext { public: - CPDF_RenderContext(); - - void Create(CPDF_Page* pPage, FX_BOOL bFirstLayer = TRUE); - - void Create(CPDF_Document* pDoc = NULL, - CPDF_PageRenderCache* pPageCache = NULL, - CPDF_Dictionary* pPageResources = NULL, - FX_BOOL bFirstLayer = TRUE); - + explicit CPDF_RenderContext(CPDF_Page* pPage); + CPDF_RenderContext(CPDF_Document* pDoc, CPDF_PageRenderCache* pPageCache); ~CPDF_RenderContext(); - void Clear(); - void AppendObjectList(CPDF_PageObjects* pObjs, const CFX_Matrix* pObject2Device); @@ -112,21 +103,18 @@ class CPDF_RenderContext { CPDF_PageRenderCache* GetPageCache() const { return m_pPageCache; } - CPDF_Document* m_pDocument; + protected: + void Render(CFX_RenderDevice* pDevice, + const CPDF_PageObject* pStopObj, + const CPDF_RenderOptions* pOptions, + const CFX_Matrix* pFinalMatrix); + CPDF_Document* const m_pDocument; CPDF_Dictionary* m_pPageResources; - CPDF_PageRenderCache* m_pPageCache; - - protected: CFX_ArrayTemplate m_ContentList; - FX_BOOL m_bFirstLayer; - void Render(CFX_RenderDevice* pDevice, - const CPDF_PageObject* pStopObj, - const CPDF_RenderOptions* pOptions, - const CFX_Matrix* pFinalMatrix); friend class CPDF_RenderStatus; friend class CPDF_ProgressiveRenderer; }; diff --git a/core/include/fpdfdoc/fpdf_doc.h b/core/include/fpdfdoc/fpdf_doc.h index 6163440674..4712f60706 100644 --- a/core/include/fpdfdoc/fpdf_doc.h +++ b/core/include/fpdfdoc/fpdf_doc.h @@ -400,14 +400,14 @@ class CPDF_Annot : public CFX_PrivateData { const CPDF_Dictionary* GetAnnotDict() const { return m_pAnnotDict; } CPDF_Dictionary* GetAnnotDict() { return m_pAnnotDict; } - FX_BOOL DrawAppearance(const CPDF_Page* pPage, + FX_BOOL DrawAppearance(CPDF_Page* pPage, CFX_RenderDevice* pDevice, const CFX_Matrix* pUser2Device, AppearanceMode mode, const CPDF_RenderOptions* pOptions); FX_BOOL DrawInContext(const CPDF_Page* pPage, - const CPDF_RenderContext* pContext, + CPDF_RenderContext* pContext, const CFX_Matrix* pUser2Device, AppearanceMode mode); @@ -431,7 +431,7 @@ class CPDF_AnnotList { explicit CPDF_AnnotList(CPDF_Page* pPage); ~CPDF_AnnotList(); - void DisplayAnnots(const CPDF_Page* pPage, + void DisplayAnnots(CPDF_Page* pPage, CPDF_RenderContext* pContext, FX_BOOL bPrinting, CFX_Matrix* pMatrix, @@ -440,7 +440,7 @@ class CPDF_AnnotList { DisplayAnnots(pPage, nullptr, pContext, bPrinting, pMatrix, bShowWidget ? 3 : 1, pOptions, nullptr); } - void DisplayAnnots(const CPDF_Page* pPage, + void DisplayAnnots(CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext, FX_BOOL bPrinting, @@ -454,7 +454,7 @@ class CPDF_AnnotList { CPDF_Document* GetDocument() const { return m_pDocument; } protected: - void DisplayPass(const CPDF_Page* pPage, + void DisplayPass(CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext, FX_BOOL bPrinting, diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp index bee188e049..1c46583e59 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp @@ -956,30 +956,18 @@ CPDF_GraphicStates* CPDF_RenderStatus::CloneObjStates( } return pStates; } -CPDF_RenderContext::CPDF_RenderContext() {} -void CPDF_RenderContext::Create(CPDF_Document* pDoc, - CPDF_PageRenderCache* pPageCache, - CPDF_Dictionary* pPageResources, - FX_BOOL bFirstLayer) { - m_pDocument = pDoc; - m_pPageResources = pPageResources; - m_pPageCache = pPageCache; - m_bFirstLayer = bFirstLayer; -} -void CPDF_RenderContext::Create(CPDF_Page* pPage, FX_BOOL bFirstLayer) { - m_pDocument = pPage->m_pDocument; - m_pPageResources = pPage->m_pPageResources; - m_pPageCache = pPage->GetRenderCache(); - m_bFirstLayer = bFirstLayer; -} +CPDF_RenderContext::CPDF_RenderContext(CPDF_Page* pPage) + : m_pDocument(pPage->m_pDocument), + m_pPageResources(pPage->m_pPageResources), + m_pPageCache(pPage->GetRenderCache()), + m_bFirstLayer(TRUE) {} +CPDF_RenderContext::CPDF_RenderContext(CPDF_Document* pDoc, + CPDF_PageRenderCache* pPageCache) + : m_pDocument(pDoc), + m_pPageResources(nullptr), + m_pPageCache(pPageCache), + m_bFirstLayer(TRUE) {} CPDF_RenderContext::~CPDF_RenderContext() {} -void CPDF_RenderContext::Clear() { - m_pDocument = NULL; - m_pPageResources = NULL; - m_pPageCache = NULL; - m_bFirstLayer = TRUE; - m_ContentList.RemoveAll(); -} void CPDF_RenderContext::AppendObjectList(CPDF_PageObjects* pObjs, const CFX_Matrix* pObject2Device) { _PDF_RenderItem* pItem = m_ContentList.AddSpace(); diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_cache.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_cache.cpp index babf70396b..8d0568e719 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_cache.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_cache.cpp @@ -250,7 +250,7 @@ FX_BOOL CPDF_ImageCache::GetCachedBitmap(CFX_DIBSource*& pBitmap, return FALSE; } CPDF_RenderContext* pContext = pRenderStatus->GetContext(); - CPDF_PageRenderCache* pPageRenderCache = pContext->m_pPageCache; + CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); m_dwTimeCount = pPageRenderCache->GetTimeCount(); CPDF_DIBSource* pSrc = new CPDF_DIBSource; CPDF_DIBSource* pMaskSrc = NULL; @@ -325,7 +325,7 @@ int CPDF_ImageCache::ContinueGetCachedBitmap() { m_MatteColor = ((CPDF_DIBSource*)m_pCurBitmap)->m_MatteColor; m_pCurMask = ((CPDF_DIBSource*)m_pCurBitmap)->DetachMask(); CPDF_RenderContext* pContext = m_pRenderStatus->GetContext(); - CPDF_PageRenderCache* pPageRenderCache = pContext->m_pPageCache; + CPDF_PageRenderCache* pPageRenderCache = pContext->GetPageCache(); m_dwTimeCount = pPageRenderCache->GetTimeCount(); if (m_pCurBitmap->GetPitch() * m_pCurBitmap->GetHeight() < FPDF_HUGE_IMAGE_SIZE) { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index d3390517e9..9c7b0018fa 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -340,7 +340,7 @@ FX_BOOL CPDF_ImageRenderer::StartLoadDIBSource() { dest_height = -dest_height; } if (m_Loader.StartLoadImage( - m_pImageObject, m_pRenderStatus->m_pContext->m_pPageCache, + m_pImageObject, m_pRenderStatus->m_pContext->GetPageCache(), m_LoadHandle, m_bStdCS, m_pRenderStatus->m_GroupFamily, m_pRenderStatus->m_bLoadMask, m_pRenderStatus, dest_width, dest_height)) { @@ -444,8 +444,8 @@ FX_BOOL CPDF_ImageRenderer::StartRenderDIBSource() { pGeneralState->m_StrokeAlpha == 1 && pGeneralState->m_FillAlpha == 1) { CPDF_Document* pDocument = NULL; CPDF_Page* pPage = NULL; - if (m_pRenderStatus->m_pContext->m_pPageCache) { - pPage = m_pRenderStatus->m_pContext->m_pPageCache->GetPage(); + if (m_pRenderStatus->m_pContext->GetPageCache()) { + pPage = m_pRenderStatus->m_pContext->GetPageCache()->GetPage(); pDocument = pPage->m_pDocument; } else { pDocument = m_pImageObject->m_pImage->GetDocument(); diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 9076b7ba20..718fa73009 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -988,8 +988,7 @@ static CFX_DIBitmap* DrawPatternBitmap(CPDF_Document* pDoc, } flags |= RENDER_FORCE_HALFTONE; options.m_Flags = flags; - CPDF_RenderContext context; - context.Create(pDoc, pCache, NULL); + CPDF_RenderContext context(pDoc, pCache); context.DrawObjectList(&bitmap_device, pPattern->m_pForm, &mtPattern2Bitmap, &options); return pBitmap; diff --git a/core/src/fpdfdoc/doc_annot.cpp b/core/src/fpdfdoc/doc_annot.cpp index 8f3d7f99eb..f4a75e6afc 100644 --- a/core/src/fpdfdoc/doc_annot.cpp +++ b/core/src/fpdfdoc/doc_annot.cpp @@ -46,7 +46,7 @@ CPDF_AnnotList::~CPDF_AnnotList() { delete annot; } -void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage, +void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext, FX_BOOL bPrinting, @@ -97,7 +97,7 @@ void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage, } } -void CPDF_AnnotList::DisplayAnnots(const CPDF_Page* pPage, +void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage, CFX_RenderDevice* pDevice, CPDF_RenderContext* pContext, FX_BOOL bPrinting, @@ -216,7 +216,7 @@ static CPDF_Form* FPDFDOC_Annot_GetMatrix(const CPDF_Page* pPage, matrix.Concat(*pUser2Device); return pForm; } -FX_BOOL CPDF_Annot::DrawAppearance(const CPDF_Page* pPage, +FX_BOOL CPDF_Annot::DrawAppearance(CPDF_Page* pPage, CFX_RenderDevice* pDevice, const CFX_Matrix* pUser2Device, AppearanceMode mode, @@ -227,13 +227,12 @@ FX_BOOL CPDF_Annot::DrawAppearance(const CPDF_Page* pPage, if (!pForm) { return FALSE; } - CPDF_RenderContext context; - context.Create((CPDF_Page*)pPage); + CPDF_RenderContext context(pPage); context.DrawObjectList(pDevice, pForm, &matrix, pOptions); return TRUE; } FX_BOOL CPDF_Annot::DrawInContext(const CPDF_Page* pPage, - const CPDF_RenderContext* pContext, + CPDF_RenderContext* pContext, const CFX_Matrix* pUser2Device, AppearanceMode mode) { CFX_Matrix matrix; @@ -242,7 +241,7 @@ FX_BOOL CPDF_Annot::DrawInContext(const CPDF_Page* pPage, if (!pForm) { return FALSE; } - ((CPDF_RenderContext*)pContext)->AppendObjectList(pForm, &matrix); + pContext->AppendObjectList(pForm, &matrix); return TRUE; } void CPDF_Annot::DrawBorder(CFX_RenderDevice* pDevice, diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp index fa0441cf79..93e837feaf 100644 --- a/core/src/fpdfdoc/doc_formcontrol.cpp +++ b/core/src/fpdfdoc/doc_formcontrol.cpp @@ -170,22 +170,20 @@ void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, CPDF_Form form(m_pField->m_pForm->m_pDocument, m_pField->m_pForm->m_pFormDict->GetDict("DR"), pStream); form.ParseContent(NULL, NULL, NULL, NULL); - CPDF_RenderContext context; - context.Create(pPage); + CPDF_RenderContext context(pPage); context.DrawObjectList(pDevice, &form, &matrix, pOptions); } -const FX_CHAR* g_sHighlightingMode[] = {"N", "I", "O", "P", "T", ""}; +static const FX_CHAR* const g_sHighlightingMode[] = { + // Must match order of HiglightingMode enum. + "N", "I", "O", "P", "T", nullptr}; CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() { if (!m_pWidgetDict) { return Invert; } CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); - int i = 0; - while (g_sHighlightingMode[i][0] != '\0') { - if (csH.Equal(g_sHighlightingMode[i])) { - return (HighlightingMode)i; - } - i++; + for (int i = 0; g_sHighlightingMode[i]; ++i) { + if (csH.Equal(g_sHighlightingMode[i])) + return static_cast(i); } return Invert; } diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp index c719cea9ec..daf9cfcbcf 100644 --- a/fpdfsdk/src/fpdfview.cpp +++ b/fpdfsdk/src/fpdfview.cpp @@ -736,8 +736,7 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, pContext->m_pDevice->SaveState(); pContext->m_pDevice->SetClip_Rect(&clip); - pContext->m_pContext = new CPDF_RenderContext; - pContext->m_pContext->Create(pPage); + pContext->m_pContext = new CPDF_RenderContext(pPage); pContext->m_pContext->AppendObjectList(pPage, &matrix); if (flags & FPDF_ANNOT) { -- cgit v1.2.3