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

Side by Side 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, 1 month 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 unified diff | Download patch
OLDNEW
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 namespace {
11
12 const int kSingleCoordinatePair = 1;
13 const int kTensorCoordinatePairs = 16;
14 const int kCoonsCoordinatePairs = 12;
15
16 const int kSingleColorPerPatch = 1;
17 const int kQuadColorsPerPatch = 4;
18
19 ShadingType ToShadingType(int type) {
20 return (type > static_cast<int>(kInvalidShading) &&
21 type < static_cast<int>(kMaxShading))
22 ? static_cast<ShadingType>(type)
23 : kInvalidShading;
24 }
25
26 } // namespace
27
10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) 28 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix)
11 : m_pPatternObj(NULL), 29 : m_pPatternObj(NULL),
12 m_PatternType(PATTERN_TILING), 30 m_PatternType(PATTERN_TILING),
13 m_pDocument(NULL), 31 m_pDocument(NULL),
14 m_bForceClear(FALSE) { 32 m_bForceClear(FALSE) {
15 if (pParentMatrix) { 33 if (pParentMatrix) {
16 m_ParentMatrix = *pParentMatrix; 34 m_ParentMatrix = *pParentMatrix;
17 } 35 }
18 } 36 }
19 CPDF_Pattern::~CPDF_Pattern() {} 37 CPDF_Pattern::~CPDF_Pattern() {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 89 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
72 ASSERT(pDict != NULL); 90 ASSERT(pDict != NULL);
73 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); 91 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix"));
74 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); 92 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading"));
75 if (parentMatrix) { 93 if (parentMatrix) {
76 m_Pattern2Form.Concat(*parentMatrix); 94 m_Pattern2Form.Concat(*parentMatrix);
77 } 95 }
78 } else { 96 } else {
79 m_pShadingObj = pPatternObj; 97 m_pShadingObj = pPatternObj;
80 } 98 }
81 m_ShadingType = 0; 99 m_ShadingType = kInvalidShading;
82 m_pCS = NULL; 100 m_pCS = NULL;
83 m_nFuncs = 0; 101 m_nFuncs = 0;
84 for (int i = 0; i < 4; i++) { 102 for (int i = 0; i < 4; i++) {
85 m_pFunctions[i] = NULL; 103 m_pFunctions[i] = NULL;
86 } 104 }
87 m_pCountedCS = NULL; 105 m_pCountedCS = NULL;
88 } 106 }
89 CPDF_ShadingPattern::~CPDF_ShadingPattern() { 107 CPDF_ShadingPattern::~CPDF_ShadingPattern() {
90 Clear(); 108 Clear();
91 } 109 }
92 void CPDF_ShadingPattern::Clear() { 110 void CPDF_ShadingPattern::Clear() {
93 for (int i = 0; i < m_nFuncs; i++) { 111 for (int i = 0; i < m_nFuncs; i++) {
94 delete m_pFunctions[i]; 112 delete m_pFunctions[i];
95 m_pFunctions[i] = NULL; 113 m_pFunctions[i] = NULL;
96 } 114 }
97 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; 115 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL;
98 if (pCS && m_pDocument) { 116 if (pCS && m_pDocument) {
99 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); 117 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
100 } 118 }
101 m_ShadingType = 0; 119 m_ShadingType = kInvalidShading;
102 m_pCS = NULL; 120 m_pCS = NULL;
103 m_pCountedCS = NULL; 121 m_pCountedCS = NULL;
104 m_nFuncs = 0; 122 m_nFuncs = 0;
105 } 123 }
124
106 FX_BOOL CPDF_ShadingPattern::Load() { 125 FX_BOOL CPDF_ShadingPattern::Load() {
107 if (m_ShadingType != 0) { 126 if (m_ShadingType != kInvalidShading)
108 return TRUE; 127 return TRUE;
109 } 128
110 CPDF_Dictionary* pShadingDict = 129 CPDF_Dictionary* pShadingDict =
111 m_pShadingObj ? m_pShadingObj->GetDict() : NULL; 130 m_pShadingObj ? m_pShadingObj->GetDict() : NULL;
112 if (pShadingDict == NULL) { 131 if (pShadingDict == NULL) {
113 return FALSE; 132 return FALSE;
114 } 133 }
115 if (m_nFuncs) { 134 if (m_nFuncs) {
116 for (int i = 0; i < m_nFuncs; i++) 135 for (int i = 0; i < m_nFuncs; i++)
117 delete m_pFunctions[i]; 136 delete m_pFunctions[i];
118 m_nFuncs = 0; 137 m_nFuncs = 0;
119 } 138 }
(...skipping 12 matching lines...) Expand all
132 } 151 }
133 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); 152 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace"));
134 if (pCSObj == NULL) { 153 if (pCSObj == NULL) {
135 return FALSE; 154 return FALSE;
136 } 155 }
137 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); 156 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData();
138 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); 157 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL);
139 if (m_pCS) { 158 if (m_pCS) {
140 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); 159 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
141 } 160 }
142 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); 161
162 m_ShadingType =
163 ToShadingType(pShadingDict->GetInteger(FX_BSTRC("ShadingType")));
143 164
144 // We expect to have a stream if our shading type is a mesh. 165 // We expect to have a stream if our shading type is a mesh.
145 if (m_ShadingType >= 4 && !ToStream(m_pShadingObj)) 166 if (IsMeshShading() && !ToStream(m_pShadingObj))
146 return FALSE; 167 return FALSE;
147 168
148 return TRUE; 169 return TRUE;
149 } 170 }
150 FX_BOOL CPDF_ShadingPattern::Reload() { 171 FX_BOOL CPDF_ShadingPattern::Reload() {
151 Clear(); 172 Clear();
152 return Load(); 173 return Load();
153 } 174 }
154 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, 175 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream,
155 CPDF_Function** pFuncs, 176 CPDF_Function** pFuncs,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 if (m_BitStream.IsEOF()) { 267 if (m_BitStream.IsEOF()) {
247 return FALSE; 268 return FALSE;
248 } 269 }
249 GetCoords(vertex[i].x, vertex[i].y); 270 GetCoords(vertex[i].x, vertex[i].y);
250 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); 271 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y);
251 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); 272 GetColor(vertex[i].r, vertex[i].g, vertex[i].b);
252 m_BitStream.ByteAlign(); 273 m_BitStream.ByteAlign();
253 } 274 }
254 return TRUE; 275 return TRUE;
255 } 276 }
256 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, 277
257 int type, 278 CFX_FloatRect GetShadingBBox(CPDF_Stream* pStream,
258 const CFX_AffineMatrix* pMatrix, 279 ShadingType type,
259 CPDF_Function** pFuncs, 280 const CFX_AffineMatrix* pMatrix,
260 int nFuncs, 281 CPDF_Function** pFuncs,
261 CPDF_ColorSpace* pCS) { 282 int nFuncs,
283 CPDF_ColorSpace* pCS) {
262 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) 284 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS)
263 return CFX_FloatRect(0, 0, 0, 0); 285 return CFX_FloatRect(0, 0, 0, 0);
264 286
265 CPDF_MeshStream stream; 287 CPDF_MeshStream stream;
266 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) 288 if (!stream.Load(pStream, pFuncs, nFuncs, pCS))
267 return CFX_FloatRect(0, 0, 0, 0); 289 return CFX_FloatRect(0, 0, 0, 0);
268 290
269 CFX_FloatRect rect; 291 CFX_FloatRect rect;
270 FX_BOOL bStarted = FALSE; 292 FX_BOOL bStarted = FALSE;
271 FX_BOOL bGouraud = type == 4 || type == 5; 293 FX_BOOL bGouraud = type == kFreeFormGouraudTriangleMeshShading ||
272 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); 294 type == kLatticeFormGouraudTriangleMeshShading;
273 int full_color_count = (type == 6 || type == 7) ? 4 : 1; 295
296 int point_count = kSingleCoordinatePair;
297 if (type == kTensorProductPatchMeshShading)
298 point_count = kTensorCoordinatePairs;
299 else if (type == kCoonsPatchMeshShading)
300 point_count = kCoonsCoordinatePairs;
301
302 int color_count = kSingleColorPerPatch;
303 if (type == kCoonsPatchMeshShading || type == kTensorProductPatchMeshShading)
304 color_count = kQuadColorsPerPatch;
305
274 while (!stream.m_BitStream.IsEOF()) { 306 while (!stream.m_BitStream.IsEOF()) {
275 FX_DWORD flag = 0; 307 FX_DWORD flag = 0;
276 if (type != 5) { 308 if (type != kLatticeFormGouraudTriangleMeshShading)
277 flag = stream.GetFlag(); 309 flag = stream.GetFlag();
278 } 310
279 int point_count = full_point_count, color_count = full_color_count;
280 if (!bGouraud && flag) { 311 if (!bGouraud && flag) {
281 point_count -= 4; 312 point_count -= 4;
282 color_count -= 2; 313 color_count -= 2;
283 } 314 }
315
284 for (int i = 0; i < point_count; i++) { 316 for (int i = 0; i < point_count; i++) {
285 FX_FLOAT x, y; 317 FX_FLOAT x, y;
286 stream.GetCoords(x, y); 318 stream.GetCoords(x, y);
287 if (bStarted) { 319 if (bStarted) {
288 rect.UpdateRect(x, y); 320 rect.UpdateRect(x, y);
289 } else { 321 } else {
290 rect.InitRect(x, y); 322 rect.InitRect(x, y);
291 bStarted = TRUE; 323 bStarted = TRUE;
292 } 324 }
293 } 325 }
294 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * 326 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits *
295 color_count); 327 color_count);
296 if (bGouraud) 328 if (bGouraud)
297 stream.m_BitStream.ByteAlign(); 329 stream.m_BitStream.ByteAlign();
298 } 330 }
299 rect.Transform(pMatrix); 331 rect.Transform(pMatrix);
300 return rect; 332 return rect;
301 } 333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698