summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-01-11 09:11:09 -0800
committerTom Sepez <tsepez@chromium.org>2016-01-11 09:11:09 -0800
commit492961df3011ccc25646eae12ac6e6dcfe7f26da (patch)
tree0d0e5f5155becdb51f70243a7821b0bbc44014fb
parent3f1c71f5a6ea058e3eec611c9dcc759b374dcb80 (diff)
downloadpdfium-492961df3011ccc25646eae12ac6e6dcfe7f26da.tar.xz
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 .
-rw-r--r--core/include/fpdfapi/fpdf_resource.h42
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp4
-rw-r--r--core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp70
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_image.cpp12
-rw-r--r--core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp10
5 files changed, 58 insertions, 80 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index d6d43ee9a7..b10a01c14d 100644
--- a/core/include/fpdfapi/fpdf_resource.h
+++ b/core/include/fpdfapi/fpdf_resource.h
@@ -636,24 +636,27 @@ class CPDF_Color {
void ReleaseColorSpace();
FX_FLOAT* m_pBuffer;
};
-#define PATTERN_TILING 1
-#define PATTERN_SHADING 2
+
class CPDF_Pattern {
public:
- virtual ~CPDF_Pattern();
- void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; }
+ enum PatternType { TILING = 1, SHADING };
- CPDF_Object* m_pPatternObj;
+ virtual ~CPDF_Pattern();
- int m_PatternType;
+ void SetForceClear(FX_BOOL bForceClear) { m_bForceClear = bForceClear; }
+ const PatternType m_PatternType;
+ CPDF_Document* const m_pDocument;
+ CPDF_Object* const m_pPatternObj;
CFX_Matrix m_Pattern2Form;
CFX_Matrix m_ParentMatrix;
- CPDF_Document* m_pDocument;
-
protected:
- CPDF_Pattern(const CFX_Matrix* pParentMatrix);
+ CPDF_Pattern(PatternType type,
+ CPDF_Document* pDoc,
+ CPDF_Object* pObj,
+ const CFX_Matrix* pParentMatrix);
+
FX_BOOL m_bForceClear;
};
@@ -705,30 +708,21 @@ class CPDF_ShadingPattern : public CPDF_Pattern {
m_ShadingType == kCoonsPatchMeshShading ||
m_ShadingType == kTensorProductPatchMeshShading;
}
-
- CPDF_Object* m_pShadingObj;
-
- FX_BOOL m_bShadingObj;
-
FX_BOOL Load();
- FX_BOOL Reload();
-
ShadingType m_ShadingType;
+ FX_BOOL m_bShadingObj;
+ CPDF_Object* m_pShadingObj;
- CPDF_ColorSpace* m_pCS; // Still keep m_pCS as some CPDF_ColorSpace (name
- // object) are not managed as counted objects. Refer
- // to CPDF_DocPageData::GetColorSpace.
+ // Still keep |m_pCS| as some CPDF_ColorSpace (name object) are not managed
+ // as counted objects. Refer to CPDF_DocPageData::GetColorSpace.
+ CPDF_ColorSpace* m_pCS;
CPDF_CountedColorSpace* m_pCountedCS;
-
CPDF_Function* m_pFunctions[4];
-
int m_nFuncs;
-
- protected:
- void Clear();
};
+
struct CPDF_MeshVertex {
FX_FLOAT x, y;
FX_FLOAT r, g, b;
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<CPDF_ShadingPattern*>(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<CPDF_TilingPattern*>(m_pPattern), m_pImageObject,
+ &patternDevice, FALSE);
} else {
- bitmap_render.DrawShadingPattern((CPDF_ShadingPattern*)m_pPattern,
- m_pImageObject, &patternDevice, FALSE);
+ bitmap_render.DrawShadingPattern(
+ static_cast<CPDF_ShadingPattern*>(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<CPDF_TilingPattern*>(pattern), pPathObj,
+ pObj2Device, bStroke);
} else {
- DrawShadingPattern((CPDF_ShadingPattern*)pattern, pPathObj, pObj2Device,
- bStroke);
+ DrawShadingPattern(static_cast<CPDF_ShadingPattern*>(pattern), pPathObj,
+ pObj2Device, bStroke);
}
}
void CPDF_RenderStatus::ProcessPathPattern(CPDF_PathObject* pPathObj,