Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1802)

Unified Diff: core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp

Issue 1418623011: Give names to the shading types (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
index 7b04d8cd3375139136db8654b8e5e67a247964c5..1120aab4713a00fc4aa5175cf40b4c351c14f426 100644
--- a/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
+++ b/core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp
@@ -78,7 +78,7 @@ CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc,
} else {
m_pShadingObj = pPatternObj;
}
- m_ShadingType = 0;
+ m_ShadingType = kInvalidShading;
m_pCS = NULL;
m_nFuncs = 0;
for (int i = 0; i < 4; i++) {
@@ -98,15 +98,22 @@ void CPDF_ShadingPattern::Clear() {
if (pCS && m_pDocument) {
m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
}
- m_ShadingType = 0;
+ m_ShadingType = kInvalidShading;
m_pCS = NULL;
m_pCountedCS = NULL;
m_nFuncs = 0;
}
+
+static ShadingType ToShadingType(int type) {
+ ShadingType st = static_cast<ShadingType>(type);
+ ASSERT(st > kInvalidShading && st < kMaxShading);
Tom Sepez 2015/10/27 16:20:16 We need something stronger than an assert here, si
dsinclair 2015/10/27 17:00:37 Done.
+ return st;
+}
+
FX_BOOL CPDF_ShadingPattern::Load() {
- if (m_ShadingType != 0) {
+ if (m_ShadingType != kInvalidShading)
return TRUE;
- }
+
CPDF_Dictionary* pShadingDict =
m_pShadingObj ? m_pShadingObj->GetDict() : NULL;
if (pShadingDict == NULL) {
@@ -139,7 +146,9 @@ FX_BOOL CPDF_ShadingPattern::Load() {
if (m_pCS) {
m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
}
- m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType"));
+ m_ShadingType =
+ ToShadingType(pShadingDict->GetInteger(FX_BSTRC("ShadingType")));
+
return TRUE;
}
FX_BOOL CPDF_ShadingPattern::Reload() {
@@ -248,12 +257,12 @@ FX_BOOL CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex,
}
return TRUE;
}
-CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
- int type,
- const CFX_AffineMatrix* pMatrix,
- CPDF_Function** pFuncs,
- int nFuncs,
- CPDF_ColorSpace* pCS) {
+CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
+ ShadingType type,
+ const CFX_AffineMatrix* pMatrix,
+ CPDF_Function** pFuncs,
+ int nFuncs,
+ CPDF_ColorSpace* pCS) {
if (!pStream || !pStream->IsStream() || !pFuncs || !pCS)
return CFX_FloatRect(0, 0, 0, 0);
@@ -263,14 +272,20 @@ CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream,
CFX_FloatRect rect;
FX_BOOL bStarted = FALSE;
- FX_BOOL bGouraud = type == 4 || type == 5;
- int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1);
- int full_color_count = (type == 6 || type == 7) ? 4 : 1;
+ FX_BOOL bGouraud = type == kFreeFormGouraudTriangleMeshShading ||
Tom Sepez 2015/10/27 16:20:16 nit: did clang-format do this? sigh. Maybe helpe
dsinclair 2015/10/27 17:00:37 How's this? I named the magic numbers and turned i
Tom Sepez 2015/10/27 17:04:25 swell.
+ type == kLatticeFormGouraudTriangleMeshShading;
+ int full_point_count = type == kTensorProductPatchMeshShading
+ ? 16
+ : (type == kCoonsPatchMeshShading ? 12 : 1);
+ int full_color_count =
+ (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading)
+ ? 4
+ : 1;
while (!stream.m_BitStream.IsEOF()) {
FX_DWORD flag = 0;
- if (type != 5) {
+ if (type != kLatticeFormGouraudTriangleMeshShading)
flag = stream.GetFlag();
- }
+
int point_count = full_point_count, color_count = full_color_count;
Tom Sepez 2015/10/27 16:20:16 nit: do we need these locals?
dsinclair 2015/10/27 17:00:37 Nope, did the math on the full_* versions and used
if (!bGouraud && flag) {
point_count -= 4;
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp ('k') | core/src/fpdfapi/fpdf_render/fpdf_render_pattern.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698