From 492961df3011ccc25646eae12ac6e6dcfe7f26da Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 11 Jan 2016 09:11:09 -0800 Subject: Merge to XFA: Tidy up shading patterns Original Review URL: https://codereview.chromium.org/1570873005 . (cherry picked from commit a07804a3b16c10fa2011ef56d1dacefb7d21e4f6) TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1577893002 . --- core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 4 +- core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp | 70 ++++++++-------------- core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 12 ++-- .../fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 10 ++-- 4 files changed, 40 insertions(+), 56 deletions(-) (limited to 'core/src/fpdfapi') diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 3fbd3e486e..d3e3807046 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1100,10 +1100,10 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { if (!pPattern) { return; } - if (pPattern->m_PatternType != PATTERN_SHADING) { + if (pPattern->m_PatternType != CPDF_Pattern::SHADING) { return; } - CPDF_ShadingPattern* pShading = (CPDF_ShadingPattern*)pPattern; + CPDF_ShadingPattern* pShading = static_cast(pPattern); if (!pShading->m_bShadingObj) { return; } diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp index fc050b9369..1eae578b97 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp @@ -26,25 +26,23 @@ ShadingType ToShadingType(int type) { } // namespace -CPDF_Pattern::CPDF_Pattern(const CFX_Matrix* pParentMatrix) - : m_pPatternObj(NULL), - m_PatternType(PATTERN_TILING), - m_pDocument(NULL), +CPDF_Pattern::CPDF_Pattern(PatternType type, + CPDF_Document* pDoc, + CPDF_Object* pObj, + const CFX_Matrix* pParentMatrix) + : m_PatternType(type), + m_pDocument(pDoc), + m_pPatternObj(pObj), m_bForceClear(FALSE) { - if (pParentMatrix) { + if (pParentMatrix) m_ParentMatrix = *pParentMatrix; - } } CPDF_Pattern::~CPDF_Pattern() {} CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, const CFX_Matrix* parentMatrix) - : CPDF_Pattern(parentMatrix) { - m_PatternType = PATTERN_TILING; - m_pPatternObj = pPatternObj; - m_pDocument = pDoc; + : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); - ASSERT(pDict); m_Pattern2Form = pDict->GetMatrix("Matrix"); m_bColored = pDict->GetInteger("PaintType") == 1; if (parentMatrix) { @@ -81,46 +79,34 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_Matrix* parentMatrix) - : CPDF_Pattern(parentMatrix) { - m_PatternType = PATTERN_SHADING; - m_pPatternObj = bShading ? NULL : pPatternObj; - m_pDocument = pDoc; - m_bShadingObj = bShading; + : CPDF_Pattern(SHADING, + pDoc, + bShading ? nullptr : pPatternObj, + parentMatrix), + m_ShadingType(kInvalidShading), + m_bShadingObj(bShading), + m_pShadingObj(pPatternObj), + m_pCS(nullptr), + m_pCountedCS(nullptr), + m_nFuncs(0) { if (!bShading) { CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); - ASSERT(pDict); m_Pattern2Form = pDict->GetMatrix("Matrix"); m_pShadingObj = pDict->GetElementValue("Shading"); - if (parentMatrix) { + if (parentMatrix) m_Pattern2Form.Concat(*parentMatrix); - } - } else { - m_pShadingObj = pPatternObj; } - m_ShadingType = kInvalidShading; - m_pCS = NULL; - m_nFuncs = 0; - for (int i = 0; i < 4; i++) { - m_pFunctions[i] = NULL; - } - m_pCountedCS = NULL; + for (int i = 0; i < FX_ArraySize(m_pFunctions); ++i) + m_pFunctions[i] = nullptr; } + CPDF_ShadingPattern::~CPDF_ShadingPattern() { - Clear(); -} -void CPDF_ShadingPattern::Clear() { - for (int i = 0; i < m_nFuncs; i++) { + for (int i = 0; i < m_nFuncs; ++i) delete m_pFunctions[i]; - m_pFunctions[i] = NULL; - } + CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; - if (pCS && m_pDocument) { + if (pCS && m_pDocument) m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); - } - m_ShadingType = kInvalidShading; - m_pCS = NULL; - m_pCountedCS = NULL; - m_nFuncs = 0; } FX_BOOL CPDF_ShadingPattern::Load() { @@ -168,10 +154,6 @@ FX_BOOL CPDF_ShadingPattern::Load() { return TRUE; } -FX_BOOL CPDF_ShadingPattern::Reload() { - Clear(); - return Load(); -} FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, CPDF_Function** pFuncs, int nFuncs, diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index 640adb14da..3f7347b8f1 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -522,12 +522,14 @@ FX_BOOL CPDF_ImageRenderer::DrawPatternImage(const CFX_Matrix* pObj2Device) { m_pRenderStatus->m_bDropObjects, NULL, TRUE); CFX_Matrix patternDevice = *pObj2Device; patternDevice.Translate((FX_FLOAT)-rect.left, (FX_FLOAT)-rect.top); - if (m_pPattern->m_PatternType == PATTERN_TILING) { - bitmap_render.DrawTilingPattern((CPDF_TilingPattern*)m_pPattern, - m_pImageObject, &patternDevice, FALSE); + if (m_pPattern->m_PatternType == CPDF_Pattern::TILING) { + bitmap_render.DrawTilingPattern( + static_cast(m_pPattern), m_pImageObject, + &patternDevice, FALSE); } else { - bitmap_render.DrawShadingPattern((CPDF_ShadingPattern*)m_pPattern, - m_pImageObject, &patternDevice, FALSE); + bitmap_render.DrawShadingPattern( + static_cast(m_pPattern), m_pImageObject, + &patternDevice, FALSE); } } { diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index 718fa73009..8cee178369 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -1187,12 +1187,12 @@ void CPDF_RenderStatus::DrawPathWithPattern(CPDF_PathObject* pPathObj, if (!pattern) { return; } - if (pattern->m_PatternType == PATTERN_TILING) { - DrawTilingPattern((CPDF_TilingPattern*)pattern, pPathObj, pObj2Device, - bStroke); + if (pattern->m_PatternType == CPDF_Pattern::TILING) { + DrawTilingPattern(static_cast(pattern), pPathObj, + pObj2Device, bStroke); } else { - DrawShadingPattern((CPDF_ShadingPattern*)pattern, pPathObj, pObj2Device, - bStroke); + DrawShadingPattern(static_cast(pattern), pPathObj, + pObj2Device, bStroke); } } void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj, -- cgit v1.2.3