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) { | |
|
Tom Sepez
2015/10/27 00:43:16
Can we avoid this?
dsinclair
2015/10/27 02:11:30
Done.
| |
| 108 switch (type) { | |
| 109 case 1: | |
| 110 return kFunctionBasedShading; | |
| 111 case 2: | |
| 112 return kAxialShading; | |
| 113 case 3: | |
| 114 return kRadialShading; | |
| 115 case 4: | |
| 116 return kFreeFormGouraudTriangleMeshShading; | |
| 117 case 5: | |
| 118 return kLatticeFormGouraudTriangleMeshShading; | |
| 119 case 6: | |
| 120 return kCoonsPatchMeshShading; | |
| 121 case 7: | |
| 122 return kTensorProductPatchMeshShading; | |
| 123 default: | |
| 124 return kInvalidShading; | |
| 125 } | |
| 126 } | |
| 127 | |
| 106 FX_BOOL CPDF_ShadingPattern::Load() { | 128 FX_BOOL CPDF_ShadingPattern::Load() { |
| 107 if (m_ShadingType != 0) { | 129 if (m_ShadingType != kInvalidShading) |
| 108 return TRUE; | 130 return TRUE; |
| 109 } | 131 |
| 110 CPDF_Dictionary* pShadingDict = | 132 CPDF_Dictionary* pShadingDict = |
| 111 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; | 133 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; |
| 112 if (pShadingDict == NULL) { | 134 if (pShadingDict == NULL) { |
| 113 return FALSE; | 135 return FALSE; |
| 114 } | 136 } |
| 115 if (m_nFuncs) { | 137 if (m_nFuncs) { |
| 116 for (int i = 0; i < m_nFuncs; i++) | 138 for (int i = 0; i < m_nFuncs; i++) |
| 117 delete m_pFunctions[i]; | 139 delete m_pFunctions[i]; |
| 118 m_nFuncs = 0; | 140 m_nFuncs = 0; |
| 119 } | 141 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 132 } | 154 } |
| 133 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); | 155 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); |
| 134 if (pCSObj == NULL) { | 156 if (pCSObj == NULL) { |
| 135 return FALSE; | 157 return FALSE; |
| 136 } | 158 } |
| 137 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 159 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
| 138 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); | 160 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); |
| 139 if (m_pCS) { | 161 if (m_pCS) { |
| 140 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); | 162 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); |
| 141 } | 163 } |
| 142 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); | 164 m_ShadingType = |
| 165 ToShadingType(pShadingDict->GetInteger(FX_BSTRC("ShadingType"))); | |
| 166 | |
| 143 return TRUE; | 167 return TRUE; |
| 144 } | 168 } |
| 145 FX_BOOL CPDF_ShadingPattern::Reload() { | 169 FX_BOOL CPDF_ShadingPattern::Reload() { |
| 146 Clear(); | 170 Clear(); |
| 147 return Load(); | 171 return Load(); |
| 148 } | 172 } |
| 149 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, | 173 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
| 150 CPDF_Function** pFuncs, | 174 CPDF_Function** pFuncs, |
| 151 int nFuncs, | 175 int nFuncs, |
| 152 CPDF_ColorSpace* pCS) { | 176 CPDF_ColorSpace* pCS) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 if (m_BitStream.IsEOF()) { | 265 if (m_BitStream.IsEOF()) { |
| 242 return FALSE; | 266 return FALSE; |
| 243 } | 267 } |
| 244 GetCoords(vertex[i].x, vertex[i].y); | 268 GetCoords(vertex[i].x, vertex[i].y); |
| 245 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); | 269 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); |
| 246 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); | 270 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); |
| 247 m_BitStream.ByteAlign(); | 271 m_BitStream.ByteAlign(); |
| 248 } | 272 } |
| 249 return TRUE; | 273 return TRUE; |
| 250 } | 274 } |
| 251 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, | 275 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, |
| 252 int type, | 276 ShadingType type, |
| 253 const CFX_AffineMatrix* pMatrix, | 277 const CFX_AffineMatrix* pMatrix, |
| 254 CPDF_Function** pFuncs, | 278 CPDF_Function** pFuncs, |
| 255 int nFuncs, | 279 int nFuncs, |
| 256 CPDF_ColorSpace* pCS) { | 280 CPDF_ColorSpace* pCS) { |
| 257 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) | 281 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) |
| 258 return CFX_FloatRect(0, 0, 0, 0); | 282 return CFX_FloatRect(0, 0, 0, 0); |
| 259 | 283 |
| 260 CPDF_MeshStream stream; | 284 CPDF_MeshStream stream; |
| 261 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) | 285 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) |
| 262 return CFX_FloatRect(0, 0, 0, 0); | 286 return CFX_FloatRect(0, 0, 0, 0); |
| 263 | 287 |
| 264 CFX_FloatRect rect; | 288 CFX_FloatRect rect; |
| 265 FX_BOOL bStarted = FALSE; | 289 FX_BOOL bStarted = FALSE; |
| 266 FX_BOOL bGouraud = type == 4 || type == 5; | 290 FX_BOOL bGouraud = type == kFreeFormGouraudTriangleMeshShading || |
| 267 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); | 291 type == kLatticeFormGouraudTriangleMeshShading; |
| 268 int full_color_count = (type == 6 || type == 7) ? 4 : 1; | 292 int full_point_count = type == kTensorProductPatchMeshShading |
| 293 ? 16 | |
| 294 : (type == kCoonsPatchMeshShading ? 12 : 1); | |
| 295 int full_color_count = | |
| 296 (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading) | |
| 297 ? 4 | |
| 298 : 1; | |
| 269 while (!stream.m_BitStream.IsEOF()) { | 299 while (!stream.m_BitStream.IsEOF()) { |
| 270 FX_DWORD flag = 0; | 300 FX_DWORD flag = 0; |
| 271 if (type != 5) { | 301 if (type != kLatticeFormGouraudTriangleMeshShading) |
| 272 flag = stream.GetFlag(); | 302 flag = stream.GetFlag(); |
| 273 } | 303 |
| 274 int point_count = full_point_count, color_count = full_color_count; | 304 int point_count = full_point_count, color_count = full_color_count; |
| 275 if (!bGouraud && flag) { | 305 if (!bGouraud && flag) { |
| 276 point_count -= 4; | 306 point_count -= 4; |
| 277 color_count -= 2; | 307 color_count -= 2; |
| 278 } | 308 } |
| 279 for (int i = 0; i < point_count; i++) { | 309 for (int i = 0; i < point_count; i++) { |
| 280 FX_FLOAT x, y; | 310 FX_FLOAT x, y; |
| 281 stream.GetCoords(x, y); | 311 stream.GetCoords(x, y); |
| 282 if (bStarted) { | 312 if (bStarted) { |
| 283 rect.UpdateRect(x, y); | 313 rect.UpdateRect(x, y); |
| 284 } else { | 314 } else { |
| 285 rect.InitRect(x, y); | 315 rect.InitRect(x, y); |
| 286 bStarted = TRUE; | 316 bStarted = TRUE; |
| 287 } | 317 } |
| 288 } | 318 } |
| 289 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 319 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * |
| 290 color_count); | 320 color_count); |
| 291 if (bGouraud) | 321 if (bGouraud) |
| 292 stream.m_BitStream.ByteAlign(); | 322 stream.m_BitStream.ByteAlign(); |
| 293 } | 323 } |
| 294 rect.Transform(pMatrix); | 324 rect.Transform(pMatrix); |
| 295 return rect; | 325 return rect; |
| 296 } | 326 } |
| OLD | NEW |