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 17:08:57
nit: maybe put this and your int's below into name
dsinclair
2015/10/27 17:15:17
Done.
| |
| 108 return (type > static_cast<int>(kInvalidShading) && | |
| 109 type < static_cast<int>(kMaxShading)) | |
| 110 ? static_cast<ShadingType>(type) | |
| 111 : kInvalidShading; | |
| 112 } | |
| 113 | |
| 106 FX_BOOL CPDF_ShadingPattern::Load() { | 114 FX_BOOL CPDF_ShadingPattern::Load() { |
| 107 if (m_ShadingType != 0) { | 115 if (m_ShadingType != kInvalidShading) |
| 108 return TRUE; | 116 return TRUE; |
| 109 } | 117 |
| 110 CPDF_Dictionary* pShadingDict = | 118 CPDF_Dictionary* pShadingDict = |
| 111 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; | 119 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; |
| 112 if (pShadingDict == NULL) { | 120 if (pShadingDict == NULL) { |
| 113 return FALSE; | 121 return FALSE; |
| 114 } | 122 } |
| 115 if (m_nFuncs) { | 123 if (m_nFuncs) { |
| 116 for (int i = 0; i < m_nFuncs; i++) | 124 for (int i = 0; i < m_nFuncs; i++) |
| 117 delete m_pFunctions[i]; | 125 delete m_pFunctions[i]; |
| 118 m_nFuncs = 0; | 126 m_nFuncs = 0; |
| 119 } | 127 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 132 } | 140 } |
| 133 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); | 141 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); |
| 134 if (pCSObj == NULL) { | 142 if (pCSObj == NULL) { |
| 135 return FALSE; | 143 return FALSE; |
| 136 } | 144 } |
| 137 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 145 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
| 138 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); | 146 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); |
| 139 if (m_pCS) { | 147 if (m_pCS) { |
| 140 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); | 148 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); |
| 141 } | 149 } |
| 142 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); | 150 |
| 151 m_ShadingType = | |
| 152 ToShadingType(pShadingDict->GetInteger(FX_BSTRC("ShadingType"))); | |
| 143 | 153 |
| 144 // We expect to have a stream if our shading type is a mesh. | 154 // We expect to have a stream if our shading type is a mesh. |
| 145 if (m_ShadingType >= 4 && !ToStream(m_pShadingObj)) | 155 if (IsMeshShading() && !ToStream(m_pShadingObj)) |
| 146 return FALSE; | 156 return FALSE; |
| 147 | 157 |
| 148 return TRUE; | 158 return TRUE; |
| 149 } | 159 } |
| 150 FX_BOOL CPDF_ShadingPattern::Reload() { | 160 FX_BOOL CPDF_ShadingPattern::Reload() { |
| 151 Clear(); | 161 Clear(); |
| 152 return Load(); | 162 return Load(); |
| 153 } | 163 } |
| 154 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, | 164 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
| 155 CPDF_Function** pFuncs, | 165 CPDF_Function** pFuncs, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 if (m_BitStream.IsEOF()) { | 256 if (m_BitStream.IsEOF()) { |
| 247 return FALSE; | 257 return FALSE; |
| 248 } | 258 } |
| 249 GetCoords(vertex[i].x, vertex[i].y); | 259 GetCoords(vertex[i].x, vertex[i].y); |
| 250 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); | 260 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); |
| 251 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); | 261 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); |
| 252 m_BitStream.ByteAlign(); | 262 m_BitStream.ByteAlign(); |
| 253 } | 263 } |
| 254 return TRUE; | 264 return TRUE; |
| 255 } | 265 } |
| 256 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, | 266 |
| 257 int type, | 267 static int kSingleCoordinatePair = 1; |
|
Tom Sepez
2015/10/27 17:07:51
nit: const int.
dsinclair
2015/10/27 17:15:17
Done.
| |
| 258 const CFX_AffineMatrix* pMatrix, | 268 static int kTensorCoordinatePairs = 16; |
| 259 CPDF_Function** pFuncs, | 269 static int kCoonsCoordinatePairs = 12; |
| 260 int nFuncs, | 270 |
| 261 CPDF_ColorSpace* pCS) { | 271 static int kSingleColorPerPatch = 1; |
| 272 static int kQuadColorsPerPatch = 4; | |
| 273 | |
| 274 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream, | |
| 275 ShadingType type, | |
| 276 const CFX_AffineMatrix* pMatrix, | |
| 277 CPDF_Function** pFuncs, | |
| 278 int nFuncs, | |
| 279 CPDF_ColorSpace* pCS) { | |
| 262 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) | 280 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) |
| 263 return CFX_FloatRect(0, 0, 0, 0); | 281 return CFX_FloatRect(0, 0, 0, 0); |
| 264 | 282 |
| 265 CPDF_MeshStream stream; | 283 CPDF_MeshStream stream; |
| 266 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) | 284 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) |
| 267 return CFX_FloatRect(0, 0, 0, 0); | 285 return CFX_FloatRect(0, 0, 0, 0); |
| 268 | 286 |
| 269 CFX_FloatRect rect; | 287 CFX_FloatRect rect; |
| 270 FX_BOOL bStarted = FALSE; | 288 FX_BOOL bStarted = FALSE; |
| 271 FX_BOOL bGouraud = type == 4 || type == 5; | 289 FX_BOOL bGouraud = type == kFreeFormGouraudTriangleMeshShading || |
| 272 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); | 290 type == kLatticeFormGouraudTriangleMeshShading; |
| 273 int full_color_count = (type == 6 || type == 7) ? 4 : 1; | 291 |
| 292 int point_count = kSingleCoordinatePair; | |
| 293 if (type == kTensorProductPatchMeshShading) | |
| 294 point_count = kTensorCoordinatePairs; | |
| 295 else if (type == kCoonsPatchMeshShading) | |
| 296 point_count = kCoonsCoordinatePairs; | |
| 297 | |
| 298 int color_count = kSingleColorPerPatch; | |
| 299 if (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading) | |
| 300 color_count = kQuadColorsPerPatch; | |
| 301 | |
| 274 while (!stream.m_BitStream.IsEOF()) { | 302 while (!stream.m_BitStream.IsEOF()) { |
| 275 FX_DWORD flag = 0; | 303 FX_DWORD flag = 0; |
| 276 if (type != 5) { | 304 if (type != kLatticeFormGouraudTriangleMeshShading) |
| 277 flag = stream.GetFlag(); | 305 flag = stream.GetFlag(); |
| 278 } | 306 |
| 279 int point_count = full_point_count, color_count = full_color_count; | |
| 280 if (!bGouraud && flag) { | 307 if (!bGouraud && flag) { |
| 281 point_count -= 4; | 308 point_count -= 4; |
| 282 color_count -= 2; | 309 color_count -= 2; |
| 283 } | 310 } |
| 311 | |
| 284 for (int i = 0; i < point_count; i++) { | 312 for (int i = 0; i < point_count; i++) { |
| 285 FX_FLOAT x, y; | 313 FX_FLOAT x, y; |
| 286 stream.GetCoords(x, y); | 314 stream.GetCoords(x, y); |
| 287 if (bStarted) { | 315 if (bStarted) { |
| 288 rect.UpdateRect(x, y); | 316 rect.UpdateRect(x, y); |
| 289 } else { | 317 } else { |
| 290 rect.InitRect(x, y); | 318 rect.InitRect(x, y); |
| 291 bStarted = TRUE; | 319 bStarted = TRUE; |
| 292 } | 320 } |
| 293 } | 321 } |
| 294 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 322 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * |
| 295 color_count); | 323 color_count); |
| 296 if (bGouraud) | 324 if (bGouraud) |
| 297 stream.m_BitStream.ByteAlign(); | 325 stream.m_BitStream.ByteAlign(); |
| 298 } | 326 } |
| 299 rect.Transform(pMatrix); | 327 rect.Transform(pMatrix); |
| 300 return rect; | 328 return rect; |
| 301 } | 329 } |
| OLD | NEW |