Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../include/fpdfapi/fpdf_page.h" | 7 #include "../../../include/fpdfapi/fpdf_page.h" |
| 8 #include "pageint.h" | 8 #include "pageint.h" |
| 9 | 9 |
| 10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) | 10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 71 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
| 72 ASSERT(pDict != NULL); | 72 ASSERT(pDict != NULL); |
| 73 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); | 73 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); |
| 74 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); | 74 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); |
| 75 if (parentMatrix) { | 75 if (parentMatrix) { |
| 76 m_Pattern2Form.Concat(*parentMatrix); | 76 m_Pattern2Form.Concat(*parentMatrix); |
| 77 } | 77 } |
| 78 } else { | 78 } else { |
| 79 m_pShadingObj = pPatternObj; | 79 m_pShadingObj = pPatternObj; |
| 80 } | 80 } |
| 81 m_ShadingType = 0; | 81 m_ShadingType = kInvalidShading; |
| 82 m_pCS = NULL; | 82 m_pCS = NULL; |
| 83 m_nFuncs = 0; | 83 m_nFuncs = 0; |
| 84 for (int i = 0; i < 4; i++) { | 84 for (int i = 0; i < 4; i++) { |
| 85 m_pFunctions[i] = NULL; | 85 m_pFunctions[i] = NULL; |
| 86 } | 86 } |
| 87 m_pCountedCS = NULL; | 87 m_pCountedCS = NULL; |
| 88 } | 88 } |
| 89 CPDF_ShadingPattern::~CPDF_ShadingPattern() { | 89 CPDF_ShadingPattern::~CPDF_ShadingPattern() { |
| 90 Clear(); | 90 Clear(); |
| 91 } | 91 } |
| 92 void CPDF_ShadingPattern::Clear() { | 92 void CPDF_ShadingPattern::Clear() { |
| 93 for (int i = 0; i < m_nFuncs; i++) { | 93 for (int i = 0; i < m_nFuncs; i++) { |
| 94 delete m_pFunctions[i]; | 94 delete m_pFunctions[i]; |
| 95 m_pFunctions[i] = NULL; | 95 m_pFunctions[i] = NULL; |
| 96 } | 96 } |
| 97 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; | 97 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; |
| 98 if (pCS && m_pDocument) { | 98 if (pCS && m_pDocument) { |
| 99 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); | 99 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); |
| 100 } | 100 } |
| 101 m_ShadingType = 0; | 101 m_ShadingType = kInvalidShading; |
| 102 m_pCS = NULL; | 102 m_pCS = NULL; |
| 103 m_pCountedCS = NULL; | 103 m_pCountedCS = NULL; |
| 104 m_nFuncs = 0; | 104 m_nFuncs = 0; |
| 105 } | 105 } |
| 106 | |
| 107 static ShadingType ToShadingType(int type) { | |
| 108 ShadingType st = static_cast<ShadingType>(type); | |
| 109 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.
| |
| 110 return st; | |
| 111 } | |
| 112 | |
| 106 FX_BOOL CPDF_ShadingPattern::Load() { | 113 FX_BOOL CPDF_ShadingPattern::Load() { |
| 107 if (m_ShadingType != 0) { | 114 if (m_ShadingType != kInvalidShading) |
| 108 return TRUE; | 115 return TRUE; |
| 109 } | 116 |
| 110 CPDF_Dictionary* pShadingDict = | 117 CPDF_Dictionary* pShadingDict = |
| 111 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; | 118 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; |
| 112 if (pShadingDict == NULL) { | 119 if (pShadingDict == NULL) { |
| 113 return FALSE; | 120 return FALSE; |
| 114 } | 121 } |
| 115 if (m_nFuncs) { | 122 if (m_nFuncs) { |
| 116 for (int i = 0; i < m_nFuncs; i++) | 123 for (int i = 0; i < m_nFuncs; i++) |
| 117 delete m_pFunctions[i]; | 124 delete m_pFunctions[i]; |
| 118 m_nFuncs = 0; | 125 m_nFuncs = 0; |
| 119 } | 126 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 132 } | 139 } |
| 133 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); | 140 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); |
| 134 if (pCSObj == NULL) { | 141 if (pCSObj == NULL) { |
| 135 return FALSE; | 142 return FALSE; |
| 136 } | 143 } |
| 137 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 144 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
| 138 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); | 145 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); |
| 139 if (m_pCS) { | 146 if (m_pCS) { |
| 140 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); | 147 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); |
| 141 } | 148 } |
| 142 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); | 149 m_ShadingType = |
| 150 ToShadingType(pShadingDict->GetInteger(FX_BSTRC("ShadingType"))); | |
| 151 | |
| 143 return TRUE; | 152 return TRUE; |
| 144 } | 153 } |
| 145 FX_BOOL CPDF_ShadingPattern::Reload() { | 154 FX_BOOL CPDF_ShadingPattern::Reload() { |
| 146 Clear(); | 155 Clear(); |
| 147 return Load(); | 156 return Load(); |
| 148 } | 157 } |
| 149 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, | 158 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
| 150 CPDF_Function** pFuncs, | 159 CPDF_Function** pFuncs, |
| 151 int nFuncs, | 160 int nFuncs, |
| 152 CPDF_ColorSpace* pCS) { | 161 CPDF_ColorSpace* pCS) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 if (m_BitStream.IsEOF()) { | 250 if (m_BitStream.IsEOF()) { |
| 242 return FALSE; | 251 return FALSE; |
| 243 } | 252 } |
| 244 GetCoords(vertex[i].x, vertex[i].y); | 253 GetCoords(vertex[i].x, vertex[i].y); |
| 245 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); | 254 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); |
| 246 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); | 255 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); |
| 247 m_BitStream.ByteAlign(); | 256 m_BitStream.ByteAlign(); |
| 248 } | 257 } |
| 249 return TRUE; | 258 return TRUE; |
| 250 } | 259 } |
| 251 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, | 260 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, |
| 252 int type, | 261 ShadingType type, |
| 253 const CFX_AffineMatrix* pMatrix, | 262 const CFX_AffineMatrix* pMatrix, |
| 254 CPDF_Function** pFuncs, | 263 CPDF_Function** pFuncs, |
| 255 int nFuncs, | 264 int nFuncs, |
| 256 CPDF_ColorSpace* pCS) { | 265 CPDF_ColorSpace* pCS) { |
| 257 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) | 266 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) |
| 258 return CFX_FloatRect(0, 0, 0, 0); | 267 return CFX_FloatRect(0, 0, 0, 0); |
| 259 | 268 |
| 260 CPDF_MeshStream stream; | 269 CPDF_MeshStream stream; |
| 261 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) | 270 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) |
| 262 return CFX_FloatRect(0, 0, 0, 0); | 271 return CFX_FloatRect(0, 0, 0, 0); |
| 263 | 272 |
| 264 CFX_FloatRect rect; | 273 CFX_FloatRect rect; |
| 265 FX_BOOL bStarted = FALSE; | 274 FX_BOOL bStarted = FALSE; |
| 266 FX_BOOL bGouraud = type == 4 || type == 5; | 275 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.
| |
| 267 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); | 276 type == kLatticeFormGouraudTriangleMeshShading; |
| 268 int full_color_count = (type == 6 || type == 7) ? 4 : 1; | 277 int full_point_count = type == kTensorProductPatchMeshShading |
| 278 ? 16 | |
| 279 : (type == kCoonsPatchMeshShading ? 12 : 1); | |
| 280 int full_color_count = | |
| 281 (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading) | |
| 282 ? 4 | |
| 283 : 1; | |
| 269 while (!stream.m_BitStream.IsEOF()) { | 284 while (!stream.m_BitStream.IsEOF()) { |
| 270 FX_DWORD flag = 0; | 285 FX_DWORD flag = 0; |
| 271 if (type != 5) { | 286 if (type != kLatticeFormGouraudTriangleMeshShading) |
| 272 flag = stream.GetFlag(); | 287 flag = stream.GetFlag(); |
| 273 } | 288 |
| 274 int point_count = full_point_count, color_count = full_color_count; | 289 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
| |
| 275 if (!bGouraud && flag) { | 290 if (!bGouraud && flag) { |
| 276 point_count -= 4; | 291 point_count -= 4; |
| 277 color_count -= 2; | 292 color_count -= 2; |
| 278 } | 293 } |
| 279 for (int i = 0; i < point_count; i++) { | 294 for (int i = 0; i < point_count; i++) { |
| 280 FX_FLOAT x, y; | 295 FX_FLOAT x, y; |
| 281 stream.GetCoords(x, y); | 296 stream.GetCoords(x, y); |
| 282 if (bStarted) { | 297 if (bStarted) { |
| 283 rect.UpdateRect(x, y); | 298 rect.UpdateRect(x, y); |
| 284 } else { | 299 } else { |
| 285 rect.InitRect(x, y); | 300 rect.InitRect(x, y); |
| 286 bStarted = TRUE; | 301 bStarted = TRUE; |
| 287 } | 302 } |
| 288 } | 303 } |
| 289 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 304 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * |
| 290 color_count); | 305 color_count); |
| 291 if (bGouraud) | 306 if (bGouraud) |
| 292 stream.m_BitStream.ByteAlign(); | 307 stream.m_BitStream.ByteAlign(); |
| 293 } | 308 } |
| 294 rect.Transform(pMatrix); | 309 rect.Transform(pMatrix); |
| 295 return rect; | 310 return rect; |
| 296 } | 311 } |
| OLD | NEW |