diff options
author | Wei Li <weili@chromium.org> | 2016-02-19 11:53:03 -0800 |
---|---|---|
committer | Wei Li <weili@chromium.org> | 2016-02-19 11:53:03 -0800 |
commit | 7cf13c9c8b9b69b01e5debb5e8dc8b265983dfa8 (patch) | |
tree | 3a5b016ba365f11d775df0009c51b5a554ec302e /core/src/fpdfapi/fpdf_render | |
parent | 31c7b73b71bd7352f96a82716b5e81d7fa24f37f (diff) | |
download | pdfium-7cf13c9c8b9b69b01e5debb5e8dc8b265983dfa8.tar.xz |
Remove PageObject's m_Type and add As<Type> functions
For CPDF_PageObject and its subclasses, remove m_Type and use GetType() instead. Also, add As<Type> functions to avoid casting all over the places.
BUG=pdfium:397
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1709393002 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_render')
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render.cpp | 71 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 2 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 22 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp | 7 | ||||
-rw-r--r-- | core/src/fpdfapi/fpdf_render/render_int.h | 22 |
5 files changed, 60 insertions, 64 deletions
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp index 8e205df281..a470e94b86 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render.cpp @@ -306,8 +306,8 @@ FX_BOOL CPDF_RenderStatus::ContinueSingleObject(const CPDF_PageObject* pObj, if (ProcessTransparency(pObj, pObj2Device)) return FALSE; - if (pObj->m_Type == CPDF_PageObject::IMAGE) { - m_pObjectRenderer.reset(IPDF_ObjectRenderer::Create(pObj->m_Type)); + if (pObj->IsImage()) { + m_pObjectRenderer.reset(IPDF_ObjectRenderer::Create()); if (!m_pObjectRenderer->Start(this, pObj, pObj2Device, FALSE)) { if (!m_pObjectRenderer->m_Result) DrawObjWithBackground(pObj, pObj2Device); @@ -321,12 +321,10 @@ FX_BOOL CPDF_RenderStatus::ContinueSingleObject(const CPDF_PageObject* pObj, return FALSE; } -IPDF_ObjectRenderer* IPDF_ObjectRenderer::Create(int type) { - if (type != CPDF_PageObject::IMAGE) { - return NULL; - } +IPDF_ObjectRenderer* IPDF_ObjectRenderer::Create() { return new CPDF_ImageRenderer; } + FX_BOOL CPDF_RenderStatus::GetObjectClippedRect(const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device, FX_BOOL bLogical, @@ -374,21 +372,21 @@ void CPDF_RenderStatus::DitherObjectArea(const CPDF_PageObject* pObj, void CPDF_RenderStatus::ProcessObjectNoClip(const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device) { FX_BOOL bRet = FALSE; - switch (pObj->m_Type) { + switch (pObj->GetType()) { case CPDF_PageObject::TEXT: - bRet = ProcessText((CPDF_TextObject*)pObj, pObj2Device, NULL); + bRet = ProcessText(pObj->AsText(), pObj2Device, NULL); break; case CPDF_PageObject::PATH: - bRet = ProcessPath((CPDF_PathObject*)pObj, pObj2Device); + bRet = ProcessPath(pObj->AsPath(), pObj2Device); break; case CPDF_PageObject::IMAGE: - bRet = ProcessImage((CPDF_ImageObject*)pObj, pObj2Device); + bRet = ProcessImage(pObj->AsImage(), pObj2Device); break; case CPDF_PageObject::SHADING: - bRet = ProcessShading((CPDF_ShadingObject*)pObj, pObj2Device); + bRet = ProcessShading(pObj->AsShading(), pObj2Device); break; case CPDF_PageObject::FORM: - bRet = ProcessForm((CPDF_FormObject*)pObj, pObj2Device); + bRet = ProcessForm(pObj->AsForm(), pObj2Device); break; } if (!bRet) { @@ -398,15 +396,15 @@ void CPDF_RenderStatus::ProcessObjectNoClip(const CPDF_PageObject* pObj, FX_BOOL CPDF_RenderStatus::DrawObjWithBlend(const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device) { FX_BOOL bRet = FALSE; - switch (pObj->m_Type) { + switch (pObj->GetType()) { case CPDF_PageObject::PATH: - bRet = ProcessPath((CPDF_PathObject*)pObj, pObj2Device); + bRet = ProcessPath(pObj->AsPath(), pObj2Device); break; case CPDF_PageObject::IMAGE: - bRet = ProcessImage((CPDF_ImageObject*)pObj, pObj2Device); + bRet = ProcessImage(pObj->AsImage(), pObj2Device); break; case CPDF_PageObject::FORM: - bRet = ProcessForm((CPDF_FormObject*)pObj, pObj2Device); + bRet = ProcessForm(pObj->AsForm(), pObj2Device); break; default: break; @@ -425,7 +423,7 @@ void CPDF_RenderStatus::DrawObjWithBackground(const CPDF_PageObject* pObj, return; } int res = 300; - if (pObj->m_Type == CPDF_PageObject::IMAGE && + if (pObj->IsImage() && m_pDevice->GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { res = 0; } @@ -437,8 +435,8 @@ void CPDF_RenderStatus::DrawObjWithBackground(const CPDF_PageObject* pObj, matrix.Concat(*buffer.GetMatrix()); GetScaledMatrix(matrix); CPDF_Dictionary* pFormResource = NULL; - if (pObj->m_Type == CPDF_PageObject::FORM) { - CPDF_FormObject* pFormObj = (CPDF_FormObject*)pObj; + if (pObj->IsForm()) { + const CPDF_FormObject* pFormObj = pObj->AsForm(); if (pFormObj->m_pForm && pFormObj->m_pForm->m_pFormDict) { pFormResource = pFormObj->m_pForm->m_pFormDict->GetDictBy("Resources"); } @@ -450,7 +448,7 @@ void CPDF_RenderStatus::DrawObjWithBackground(const CPDF_PageObject* pObj, status.RenderSingleObject(pObj, &matrix); buffer.OutputToDevice(); } -FX_BOOL CPDF_RenderStatus::ProcessForm(CPDF_FormObject* pFormObj, +FX_BOOL CPDF_RenderStatus::ProcessForm(const CPDF_FormObject* pFormObj, const CFX_Matrix* pObj2Device) { CPDF_Dictionary* pOC = pFormObj->m_pForm->m_pFormDict->GetDictBy("OC"); if (pOC && m_Options.m_pOCContext && @@ -483,7 +481,7 @@ FX_BOOL IsAvailableMatrix(const CFX_Matrix& matrix) { } return TRUE; } -FX_BOOL CPDF_RenderStatus::ProcessPath(CPDF_PathObject* pPathObj, +FX_BOOL CPDF_RenderStatus::ProcessPath(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device) { int FillType = pPathObj->m_FillType; FX_BOOL bStroke = pPathObj->m_bStroke; @@ -691,7 +689,7 @@ void CPDF_RenderStatus::DrawClipPath(CPDF_ClipPath ClipPath, fill_mode); } } -FX_BOOL CPDF_RenderStatus::SelectClipPath(CPDF_PathObject* pPathObj, +FX_BOOL CPDF_RenderStatus::SelectClipPath(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke) { CFX_Matrix path_matrix = pPathObj->m_Matrix; @@ -721,8 +719,8 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, CPDF_Dictionary* pSMaskDict = pGeneralState ? ToDictionary(pGeneralState->m_pSoftMask) : NULL; if (pSMaskDict) { - if (pPageObj->m_Type == CPDF_PageObject::IMAGE && - ((CPDF_ImageObject*)pPageObj)->m_pImage->GetDict()->KeyExist("SMask")) { + if (pPageObj->IsImage() && + pPageObj->AsImage()->m_pImage->GetDict()->KeyExist("SMask")) { pSMaskDict = NULL; } } @@ -730,8 +728,8 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, FX_FLOAT group_alpha = 1.0f; int Transparency = m_Transparency; FX_BOOL bGroupTransparent = FALSE; - if (pPageObj->m_Type == CPDF_PageObject::FORM) { - CPDF_FormObject* pFormObj = (CPDF_FormObject*)pPageObj; + if (pPageObj->IsForm()) { + const CPDF_FormObject* pFormObj = pPageObj->AsForm(); const CPDF_GeneralStateData* pStateData = pFormObj->m_GeneralState.GetObject(); if (pStateData) { @@ -749,22 +747,20 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, !(m_pDevice->GetDeviceCaps(FXDC_RENDER_CAPS) & FXRC_SOFT_CLIP)) { bTextClip = TRUE; } - if ((m_Options.m_Flags & RENDER_OVERPRINT) && - pPageObj->m_Type == CPDF_PageObject::IMAGE && pGeneralState && - pGeneralState->m_FillOP && pGeneralState->m_StrokeOP) { + if ((m_Options.m_Flags & RENDER_OVERPRINT) && pPageObj->IsImage() && + pGeneralState && pGeneralState->m_FillOP && pGeneralState->m_StrokeOP) { CPDF_Document* pDocument = NULL; CPDF_Page* pPage = NULL; if (m_pContext->GetPageCache()) { pPage = m_pContext->GetPageCache()->GetPage(); pDocument = pPage->m_pDocument; } else { - pDocument = ((CPDF_ImageObject*)pPageObj)->m_pImage->GetDocument(); + pDocument = pPageObj->AsImage()->m_pImage->GetDocument(); } CPDF_Dictionary* pPageResources = pPage ? pPage->m_pPageResources : NULL; - CPDF_Object* pCSObj = ((CPDF_ImageObject*)pPageObj) - ->m_pImage->GetStream() - ->GetDict() - ->GetElementValue("ColorSpace"); + CPDF_Object* pCSObj = + pPageObj->AsImage()->m_pImage->GetStream()->GetDict()->GetElementValue( + "ColorSpace"); CPDF_ColorSpace* pColorSpace = pDocument->LoadColorSpace(pCSObj, pPageResources); if (pColorSpace) { @@ -870,7 +866,7 @@ FX_BOOL CPDF_RenderStatus::ProcessTransparency(const CPDF_PageObject* pPageObj, bitmap->MultiplyAlpha((int32_t)(group_alpha * 255)); } Transparency = m_Transparency; - if (pPageObj->m_Type == CPDF_PageObject::FORM) { + if (pPageObj->IsForm()) { Transparency |= PDFTRANS_GROUP; } CompositeDIBitmap(bitmap, rect.left, rect.top, 0, 255, blend_type, @@ -1088,13 +1084,12 @@ void CPDF_ProgressiveRenderer::Continue(IFX_Pause* pPause) { pCurObj, &m_pCurrentLayer->m_Matrix, pPause)) { return; } - if (pCurObj->m_Type == CPDF_PageObject::IMAGE && + if (pCurObj->IsImage() && m_pRenderStatus->m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE) { m_pContext->GetPageCache()->CacheOptimization( m_pRenderStatus->m_Options.m_dwLimitCacheSize); } - if (pCurObj->m_Type == CPDF_PageObject::FORM || - pCurObj->m_Type == CPDF_PageObject::SHADING) { + if (pCurObj->IsForm() || pCurObj->IsShading()) { nObjsToGo = 0; } else { --nObjsToGo; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index 2bd3e91935..acfc083e0e 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -17,7 +17,7 @@ #include "core/include/fxge/fx_ge.h" #include "core/src/fpdfapi/fpdf_page/pageint.h" -FX_BOOL CPDF_RenderStatus::ProcessImage(CPDF_ImageObject* pImageObj, +FX_BOOL CPDF_RenderStatus::ProcessImage(const CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device) { CPDF_ImageRenderer render; if (render.Start(this, pImageObj, pObj2Device, m_bStdCS, m_curBlend)) { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 7284b627b5..f4ade7d48d 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -912,19 +912,19 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, buffer.OutputToDevice(); } void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern, - CPDF_PageObject* pPageObj, + const CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke) { if (!pattern->Load()) { return; } m_pDevice->SaveState(); - if (pPageObj->m_Type == CPDF_PageObject::PATH) { - if (!SelectClipPath((CPDF_PathObject*)pPageObj, pObj2Device, bStroke)) { + if (pPageObj->IsPath()) { + if (!SelectClipPath(pPageObj->AsPath(), pObj2Device, bStroke)) { m_pDevice->RestoreState(); return; } - } else if (pPageObj->m_Type == CPDF_PageObject::IMAGE) { + } else if (pPageObj->IsImage()) { FX_RECT rect = pPageObj->GetBBox(pObj2Device); m_pDevice->SetClip_Rect(&rect); } else { @@ -943,7 +943,7 @@ void CPDF_RenderStatus::DrawShadingPattern(CPDF_ShadingPattern* pattern, m_Options.m_ColorMode == RENDER_COLOR_ALPHA); m_pDevice->RestoreState(); } -FX_BOOL CPDF_RenderStatus::ProcessShading(CPDF_ShadingObject* pShadingObj, +FX_BOOL CPDF_RenderStatus::ProcessShading(const CPDF_ShadingObject* pShadingObj, const CFX_Matrix* pObj2Device) { FX_RECT rect = pShadingObj->GetBBox(pObj2Device); FX_RECT clip_box = m_pDevice->GetClipBox(); @@ -994,19 +994,19 @@ static CFX_DIBitmap* DrawPatternBitmap(CPDF_Document* pDoc, return pBitmap; } void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, - CPDF_PageObject* pPageObj, + const CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke) { if (!pPattern->Load()) { return; } m_pDevice->SaveState(); - if (pPageObj->m_Type == CPDF_PageObject::PATH) { - if (!SelectClipPath((CPDF_PathObject*)pPageObj, pObj2Device, bStroke)) { + if (pPageObj->IsPath()) { + if (!SelectClipPath(pPageObj->AsPath(), pObj2Device, bStroke)) { m_pDevice->RestoreState(); return; } - } else if (pPageObj->m_Type == CPDF_PageObject::IMAGE) { + } else if (pPageObj->IsImage()) { FX_RECT rect = pPageObj->GetBBox(pObj2Device); m_pDevice->SetClip_Rect(&rect); } else { @@ -1179,7 +1179,7 @@ void CPDF_RenderStatus::DrawTilingPattern(CPDF_TilingPattern* pPattern, m_pDevice->RestoreState(); delete pPatternBitmap; } -void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, +void CPDF_RenderStatus::DrawPathWithPattern(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, CPDF_Color* pColor, FX_BOOL bStroke) { @@ -1195,7 +1195,7 @@ void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, pObj2Device, bStroke); } } -void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj, +void CPDF_RenderStatus::ProcessPathPattern(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, int& filltype, FX_BOOL& bStroke) { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp index d2faac3b7e..769ee05dc9 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_text.cpp @@ -318,10 +318,9 @@ FX_BOOL CPDF_Type3Char::LoadBitmap(CPDF_RenderContext* pContext) { } if (m_pForm->GetPageObjectList()->size() == 1 && !m_bColored) { auto& pPageObj = m_pForm->GetPageObjectList()->front(); - if (pPageObj->m_Type == CPDF_PageObject::IMAGE) { - CPDF_ImageObject* pImage = static_cast<CPDF_ImageObject*>(pPageObj.get()); - m_ImageMatrix = pImage->m_Matrix; - const CFX_DIBSource* pSource = pImage->m_pImage->LoadDIBSource(); + if (pPageObj->IsImage()) { + const CFX_DIBSource* pSource = + pPageObj->AsImage()->m_pImage->LoadDIBSource(); if (pSource) { m_pBitmap = pSource->Clone(); delete pSource; diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h index 9a262ea6fc..5af5909d2e 100644 --- a/core/src/fpdfapi/fpdf_render/render_int.h +++ b/core/src/fpdfapi/fpdf_render/render_int.h @@ -94,7 +94,7 @@ class CPDF_DocRenderData { class IPDF_ObjectRenderer { public: - static IPDF_ObjectRenderer* Create(int type); + static IPDF_ObjectRenderer* Create(); virtual ~IPDF_ObjectRenderer() {} virtual FX_BOOL Start(CPDF_RenderStatus* pRenderStatus, const CPDF_PageObject* pObj, @@ -151,27 +151,28 @@ class CPDF_RenderStatus { const CFX_Matrix* pObj2Device); FX_BOOL DrawObjWithBlend(const CPDF_PageObject* pObj, const CFX_Matrix* pObj2Device); - FX_BOOL ProcessPath(CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device); - void ProcessPathPattern(CPDF_PathObject* pPathObj, + FX_BOOL ProcessPath(const CPDF_PathObject* pPathObj, + const CFX_Matrix* pObj2Device); + void ProcessPathPattern(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, int& filltype, FX_BOOL& bStroke); - void DrawPathWithPattern(CPDF_PathObject* pPathObj, + void DrawPathWithPattern(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, CPDF_Color* pColor, FX_BOOL bStroke); void DrawTilingPattern(CPDF_TilingPattern* pPattern, - CPDF_PageObject* pPageObj, + const CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke); void DrawShadingPattern(CPDF_ShadingPattern* pPattern, - CPDF_PageObject* pPageObj, + const CPDF_PageObject* pPageObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke); - FX_BOOL SelectClipPath(CPDF_PathObject* pPathObj, + FX_BOOL SelectClipPath(const CPDF_PathObject* pPathObj, const CFX_Matrix* pObj2Device, FX_BOOL bStroke); - FX_BOOL ProcessImage(CPDF_ImageObject* pImageObj, + FX_BOOL ProcessImage(const CPDF_ImageObject* pImageObj, const CFX_Matrix* pObj2Device); FX_BOOL OutputBitmapAlpha(CPDF_ImageObject* pImageObj, const CFX_Matrix* pImage2Device); @@ -190,7 +191,7 @@ class CPDF_RenderStatus { int bitmap_alpha, int blend_mode, int bIsolated); - FX_BOOL ProcessShading(CPDF_ShadingObject* pShadingObj, + FX_BOOL ProcessShading(const CPDF_ShadingObject* pShadingObj, const CFX_Matrix* pObj2Device); void DrawShading(CPDF_ShadingPattern* pPattern, CFX_Matrix* pMatrix, @@ -209,7 +210,8 @@ class CPDF_RenderStatus { const CFX_Matrix* pTextMatrix, FX_BOOL bFill, FX_BOOL bStroke); - FX_BOOL ProcessForm(CPDF_FormObject* pFormObj, const CFX_Matrix* pObj2Device); + FX_BOOL ProcessForm(const CPDF_FormObject* pFormObj, + const CFX_Matrix* pObj2Device); CFX_DIBitmap* GetBackdrop(const CPDF_PageObject* pObj, const FX_RECT& rect, int& left, |