From aa435ba7fe0aacd9102e8c73311c5382ca112439 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 22 Oct 2015 16:45:48 -0400 Subject: Merge to XFA: Add type cast definitions for CPDF_Stream. This Cl adds ToStream, CPDF_Object::AsStream and CPDF_Object::IsStream and updates the src to use them as needed. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1402413004 . (cherry picked from commit 338805f1366dcdf9a5b48cf591541cf98d7490f1) Review URL: https://codereview.chromium.org/1422513004 . --- core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp | 5 +- .../fpdfapi/fpdf_render/fpdf_render_loadimage.cpp | 36 ++--- .../fpdfapi/fpdf_render/fpdf_render_pattern.cpp | 161 ++++++++++----------- core/src/fpdfapi/fpdf_render/render_int.h | 2 +- 4 files changed, 93 insertions(+), 111 deletions(-) (limited to 'core/src/fpdfapi/fpdf_render') diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp index 2754223f3e..0acaeba14c 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp @@ -1055,10 +1055,9 @@ CFX_DIBitmap* CPDF_RenderStatus::LoadSMask(CPDF_Dictionary* pSMaskDict, } CPDF_Function* pFunc = NULL; CPDF_Object* pFuncObj = pSMaskDict->GetElementValue(FX_BSTRC("TR")); - if (pFuncObj && - (pFuncObj->IsDictionary() || pFuncObj->GetType() == PDFOBJ_STREAM)) { + if (pFuncObj && (pFuncObj->IsDictionary() || pFuncObj->IsStream())) pFunc = CPDF_Function::Load(pFuncObj); - } + CFX_AffineMatrix matrix = *pMatrix; matrix.TranslateI(-pClipRect->left, -pClipRect->top); CPDF_Form form(m_pContext->m_pDocument, m_pContext->m_pPageResources, pGroup); diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp index fecd6da9b2..6af3ab4ce6 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp @@ -765,7 +765,7 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) { CPDF_Stream* pSoftMask = m_pDict->GetStream(FX_BSTRC("SMask")); if (pSoftMask) { CPDF_Array* pMatte = pSoftMask->GetDict()->GetArray(FX_BSTRC("Matte")); - if (pMatte != NULL && m_pColorSpace && + if (pMatte && m_pColorSpace && (FX_DWORD)m_pColorSpace->CountComponents() <= m_nComponents) { FX_FLOAT* pColor = FX_Alloc(FX_FLOAT, m_nComponents); for (FX_DWORD i = 0; i < m_nComponents; i++) { @@ -779,14 +779,12 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMask(FX_DWORD& MatteColor) { } return LoadMaskDIB(pSoftMask); } - CPDF_Object* pMask = m_pDict->GetElementValue(FX_BSTRC("Mask")); - if (pMask == NULL) { - return NULL; - } - if (pMask->GetType() == PDFOBJ_STREAM) { - return LoadMaskDIB((CPDF_Stream*)pMask); - } - return NULL; + + if (CPDF_Stream* pStream = + ToStream(m_pDict->GetElementValue(FX_BSTRC("Mask")))) + return LoadMaskDIB(pStream); + + return nullptr; } int CPDF_DIBSource::StratLoadMask() { m_MatteColor = 0XFFFFFFFF; @@ -807,14 +805,9 @@ int CPDF_DIBSource::StratLoadMask() { } return StartLoadMaskDIB(); } - m_pMaskStream = m_pDict->GetElementValue(FX_BSTRC("Mask")); - if (m_pMaskStream == NULL) { - return 1; - } - if (m_pMaskStream->GetType() == PDFOBJ_STREAM) { - return StartLoadMaskDIB(); - } - return 1; + + m_pMaskStream = ToStream(m_pDict->GetElementValue(FX_BSTRC("Mask"))); + return m_pMaskStream ? StartLoadMaskDIB() : 1; } int CPDF_DIBSource::ContinueLoadMaskDIB(IFX_Pause* pPause) { if (m_pMask == NULL) { @@ -849,17 +842,16 @@ CPDF_DIBSource* CPDF_DIBSource::LoadMaskDIB(CPDF_Stream* pMask) { } int CPDF_DIBSource::StartLoadMaskDIB() { m_pMask = new CPDF_DIBSource; - int ret = m_pMask->StartLoadDIBSource( - m_pDocument, (CPDF_Stream*)m_pMaskStream, FALSE, NULL, NULL, TRUE); + int ret = m_pMask->StartLoadDIBSource(m_pDocument, m_pMaskStream, FALSE, + nullptr, nullptr, TRUE); if (ret == 2) { - if (m_Status == 0) { + if (m_Status == 0) m_Status = 2; - } return 2; } if (!ret) { delete m_pMask; - m_pMask = NULL; + m_pMask = nullptr; return 1; } return 1; diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp index b64002c13e..4ed6c07675 100644 --- a/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp +++ b/core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp @@ -10,13 +10,13 @@ #include "../fpdf_page/pageint.h" #include "render_int.h" #define SHADING_STEPS 256 -static void _DrawAxialShading(CFX_DIBitmap* pBitmap, - CFX_AffineMatrix* pObject2Bitmap, - CPDF_Dictionary* pDict, - CPDF_Function** pFuncs, - int nFuncs, - CPDF_ColorSpace* pCS, - int alpha) { +static void DrawAxialShading(CFX_DIBitmap* pBitmap, + CFX_AffineMatrix* pObject2Bitmap, + CPDF_Dictionary* pDict, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS, + int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords")); if (pCoords == NULL) { @@ -101,13 +101,13 @@ static void _DrawAxialShading(CFX_DIBitmap* pBitmap, } } } -static void _DrawRadialShading(CFX_DIBitmap* pBitmap, - CFX_AffineMatrix* pObject2Bitmap, - CPDF_Dictionary* pDict, - CPDF_Function** pFuncs, - int nFuncs, - CPDF_ColorSpace* pCS, - int alpha) { +static void DrawRadialShading(CFX_DIBitmap* pBitmap, + CFX_AffineMatrix* pObject2Bitmap, + CPDF_Dictionary* pDict, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS, + int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); CPDF_Array* pCoords = pDict->GetArray(FX_BSTRC("Coords")); if (pCoords == NULL) { @@ -239,13 +239,13 @@ static void _DrawRadialShading(CFX_DIBitmap* pBitmap, } } } -static void _DrawFuncShading(CFX_DIBitmap* pBitmap, - CFX_AffineMatrix* pObject2Bitmap, - CPDF_Dictionary* pDict, - CPDF_Function** pFuncs, - int nFuncs, - CPDF_ColorSpace* pCS, - int alpha) { +static void DrawFuncShading(CFX_DIBitmap* pBitmap, + CFX_AffineMatrix* pObject2Bitmap, + CPDF_Dictionary* pDict, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS, + int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); CPDF_Array* pDomain = pDict->GetArray(FX_BSTRC("Domain")); FX_FLOAT xmin = 0, ymin = 0, xmax = 1.0f, ymax = 1.0f; @@ -323,9 +323,9 @@ FX_BOOL _GetScanlineIntersect(int y, x = x1 + FXSYS_MulDiv(x2 - x1, y - y1, y2 - y1); return TRUE; } -static void _DrawGouraud(CFX_DIBitmap* pBitmap, - int alpha, - CPDF_MeshVertex triangle[3]) { +static void DrawGouraud(CFX_DIBitmap* pBitmap, + int alpha, + CPDF_MeshVertex triangle[3]) { FX_FLOAT min_y = triangle[0].y, max_y = triangle[0].y; for (int i = 1; i < 3; i++) { if (min_y > triangle[i].y) { @@ -408,21 +408,19 @@ static void _DrawGouraud(CFX_DIBitmap* pBitmap, } } } -static void _DrawFreeGouraudShading(CFX_DIBitmap* pBitmap, - CFX_AffineMatrix* pObject2Bitmap, - CPDF_Stream* pShadingStream, - CPDF_Function** pFuncs, - int nFuncs, - CPDF_ColorSpace* pCS, - int alpha) { +static void DrawFreeGouraudShading(CFX_DIBitmap* pBitmap, + CFX_AffineMatrix* pObject2Bitmap, + CPDF_Stream* pShadingStream, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS, + int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); - if (pShadingStream->GetType() != PDFOBJ_STREAM) { - return; - } + CPDF_MeshStream stream; - if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) { + if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) return; - } + CPDF_MeshVertex triangle[3]; FXSYS_memset(triangle, 0, sizeof(triangle)); @@ -441,28 +439,26 @@ static void _DrawFreeGouraudShading(CFX_DIBitmap* pBitmap, triangle[1] = triangle[2]; triangle[2] = vertex; } - _DrawGouraud(pBitmap, alpha, triangle); + DrawGouraud(pBitmap, alpha, triangle); } } -static void _DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap, - CFX_AffineMatrix* pObject2Bitmap, - CPDF_Stream* pShadingStream, - CPDF_Function** pFuncs, - int nFuncs, - CPDF_ColorSpace* pCS, - int alpha) { +static void DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap, + CFX_AffineMatrix* pObject2Bitmap, + CPDF_Stream* pShadingStream, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS, + int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); - if (pShadingStream->GetType() != PDFOBJ_STREAM) { - return; - } + int row_verts = pShadingStream->GetDict()->GetInteger("VerticesPerRow"); - if (row_verts < 2) { + if (row_verts < 2) return; - } + CPDF_MeshStream stream; - if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) { + if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) return; - } + CPDF_MeshVertex* vertex = FX_Alloc2D(CPDF_MeshVertex, row_verts, 2); if (!stream.GetVertexRow(vertex, row_verts, pObject2Bitmap)) { FX_Free(vertex); @@ -481,9 +477,9 @@ static void _DrawLatticeGouraudShading(CFX_DIBitmap* pBitmap, triangle[0] = last_row[i]; triangle[1] = this_row[i - 1]; triangle[2] = last_row[i - 1]; - _DrawGouraud(pBitmap, alpha, triangle); + DrawGouraud(pBitmap, alpha, triangle); triangle[2] = this_row[i]; - _DrawGouraud(pBitmap, alpha, triangle); + DrawGouraud(pBitmap, alpha, triangle); } last_index = 1 - last_index; } @@ -748,29 +744,24 @@ FX_BOOL _CheckCoonTensorPara(const CPDF_MeshStream& stream) { return bCoorBits && bCompBits && bFlagBits; } -static void _DrawCoonPatchMeshes(FX_BOOL bTensor, - CFX_DIBitmap* pBitmap, - CFX_AffineMatrix* pObject2Bitmap, - CPDF_Stream* pShadingStream, - CPDF_Function** pFuncs, - int nFuncs, - CPDF_ColorSpace* pCS, - int fill_mode, - int alpha) { +static void DrawCoonPatchMeshes(FX_BOOL bTensor, + CFX_DIBitmap* pBitmap, + CFX_AffineMatrix* pObject2Bitmap, + CPDF_Stream* pShadingStream, + CPDF_Function** pFuncs, + int nFuncs, + CPDF_ColorSpace* pCS, + int fill_mode, + int alpha) { ASSERT(pBitmap->GetFormat() == FXDIB_Argb); - if (pShadingStream->GetType() != PDFOBJ_STREAM) { - return; - } + CFX_FxgeDevice device; device.Attach(pBitmap); CPDF_MeshStream stream; - if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) { + if (!stream.Load(pShadingStream, pFuncs, nFuncs, pCS)) return; - } - - if (!_CheckCoonTensorPara(stream)) { + if (!_CheckCoonTensorPara(stream)) return; - } CPDF_PatchDrawer patch; patch.alpha = alpha; @@ -878,32 +869,32 @@ void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, int fill_mode = m_Options.m_Flags; switch (pPattern->m_ShadingType) { case 1: - _DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, - pColorSpace, alpha); + DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace, + alpha); break; case 2: - _DrawAxialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, - pColorSpace, alpha); + DrawAxialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, + pColorSpace, alpha); break; case 3: - _DrawRadialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, - pColorSpace, alpha); + DrawRadialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, + pColorSpace, alpha); break; case 4: { - _DrawFreeGouraudShading(pBitmap, &FinalMatrix, - (CPDF_Stream*)pPattern->m_pShadingObj, pFuncs, - nFuncs, pColorSpace, alpha); + DrawFreeGouraudShading(pBitmap, &FinalMatrix, + ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, + pColorSpace, alpha); } break; case 5: { - _DrawLatticeGouraudShading(pBitmap, &FinalMatrix, - (CPDF_Stream*)pPattern->m_pShadingObj, pFuncs, - nFuncs, pColorSpace, alpha); + DrawLatticeGouraudShading(pBitmap, &FinalMatrix, + ToStream(pPattern->m_pShadingObj), pFuncs, + nFuncs, pColorSpace, alpha); } break; case 6: case 7: { - _DrawCoonPatchMeshes(pPattern->m_ShadingType - 6, pBitmap, &FinalMatrix, - (CPDF_Stream*)pPattern->m_pShadingObj, pFuncs, - nFuncs, pColorSpace, fill_mode, alpha); + DrawCoonPatchMeshes(pPattern->m_ShadingType - 6, pBitmap, &FinalMatrix, + ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, + pColorSpace, fill_mode, alpha); } break; } if (bAlphaMode) { diff --git a/core/src/fpdfapi/fpdf_render/render_int.h b/core/src/fpdfapi/fpdf_render/render_int.h index 4f86996589..c97cb7105d 100644 --- a/core/src/fpdfapi/fpdf_render/render_int.h +++ b/core/src/fpdfapi/fpdf_render/render_int.h @@ -547,7 +547,7 @@ class CPDF_DIBSource : public CFX_DIBSource { CPDF_StreamAcc* m_pGlobalStream; FX_BOOL m_bStdCS; int m_Status; - CPDF_Object* m_pMaskStream; + CPDF_Stream* m_pMaskStream; FX_BOOL m_bHasMask; private: -- cgit v1.2.3