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 20 matching lines...) Expand all Loading... |
31 if (parentMatrix) { | 31 if (parentMatrix) { |
32 m_Pattern2Form.Concat(*parentMatrix); | 32 m_Pattern2Form.Concat(*parentMatrix); |
33 } | 33 } |
34 m_pForm = NULL; | 34 m_pForm = NULL; |
35 } | 35 } |
36 CPDF_TilingPattern::~CPDF_TilingPattern() { | 36 CPDF_TilingPattern::~CPDF_TilingPattern() { |
37 delete m_pForm; | 37 delete m_pForm; |
38 m_pForm = NULL; | 38 m_pForm = NULL; |
39 } | 39 } |
40 FX_BOOL CPDF_TilingPattern::Load() { | 40 FX_BOOL CPDF_TilingPattern::Load() { |
41 if (m_pForm != NULL) { | 41 if (m_pForm) |
42 return TRUE; | 42 return TRUE; |
43 } | 43 |
44 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 44 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
45 if (pDict == NULL) { | 45 if (!pDict) |
46 return FALSE; | 46 return FALSE; |
47 } | 47 |
48 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; | 48 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; |
49 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); | 49 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); |
50 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); | 50 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); |
51 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) { | 51 |
| 52 CPDF_Stream* pStream = m_pPatternObj->AsStream(); |
| 53 if (!pStream) |
52 return FALSE; | 54 return FALSE; |
53 } | 55 |
54 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj; | |
55 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); | 56 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); |
56 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); | 57 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); |
57 m_BBox = pDict->GetRect(FX_BSTRC("BBox")); | 58 m_BBox = pDict->GetRect(FX_BSTRC("BBox")); |
58 return TRUE; | 59 return TRUE; |
59 } | 60 } |
60 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, | 61 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, |
61 CPDF_Object* pPatternObj, | 62 CPDF_Object* pPatternObj, |
62 FX_BOOL bShading, | 63 FX_BOOL bShading, |
63 const CFX_AffineMatrix* parentMatrix) | 64 const CFX_AffineMatrix* parentMatrix) |
64 : CPDF_Pattern(parentMatrix) { | 65 : CPDF_Pattern(parentMatrix) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 m_BitStream.ByteAlign(); | 247 m_BitStream.ByteAlign(); |
247 } | 248 } |
248 return TRUE; | 249 return TRUE; |
249 } | 250 } |
250 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, | 251 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, |
251 int type, | 252 int type, |
252 const CFX_AffineMatrix* pMatrix, | 253 const CFX_AffineMatrix* pMatrix, |
253 CPDF_Function** pFuncs, | 254 CPDF_Function** pFuncs, |
254 int nFuncs, | 255 int nFuncs, |
255 CPDF_ColorSpace* pCS) { | 256 CPDF_ColorSpace* pCS) { |
256 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM || | 257 if (!pStream || !pStream->IsStream() || !pFuncs || !pCS) |
257 pFuncs == NULL || pCS == NULL) { | |
258 return CFX_FloatRect(0, 0, 0, 0); | 258 return CFX_FloatRect(0, 0, 0, 0); |
259 } | 259 |
260 CPDF_MeshStream stream; | 260 CPDF_MeshStream stream; |
261 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) { | 261 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) |
262 return CFX_FloatRect(0, 0, 0, 0); | 262 return CFX_FloatRect(0, 0, 0, 0); |
263 } | 263 |
264 CFX_FloatRect rect; | 264 CFX_FloatRect rect; |
265 FX_BOOL bStarted = FALSE; | 265 FX_BOOL bStarted = FALSE; |
266 FX_BOOL bGouraud = type == 4 || type == 5; | 266 FX_BOOL bGouraud = type == 4 || type == 5; |
267 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); | 267 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); |
268 int full_color_count = (type == 6 || type == 7) ? 4 : 1; | 268 int full_color_count = (type == 6 || type == 7) ? 4 : 1; |
269 while (!stream.m_BitStream.IsEOF()) { | 269 while (!stream.m_BitStream.IsEOF()) { |
270 FX_DWORD flag = 0; | 270 FX_DWORD flag = 0; |
271 if (type != 5) { | 271 if (type != 5) { |
272 flag = stream.GetFlag(); | 272 flag = stream.GetFlag(); |
273 } | 273 } |
274 int point_count = full_point_count, color_count = full_color_count; | 274 int point_count = full_point_count, color_count = full_color_count; |
275 if (!bGouraud && flag) { | 275 if (!bGouraud && flag) { |
276 point_count -= 4; | 276 point_count -= 4; |
277 color_count -= 2; | 277 color_count -= 2; |
278 } | 278 } |
279 for (int i = 0; i < point_count; i++) { | 279 for (int i = 0; i < point_count; i++) { |
280 FX_FLOAT x, y; | 280 FX_FLOAT x, y; |
281 stream.GetCoords(x, y); | 281 stream.GetCoords(x, y); |
282 if (bStarted) { | 282 if (bStarted) { |
283 rect.UpdateRect(x, y); | 283 rect.UpdateRect(x, y); |
284 } else { | 284 } else { |
285 rect.InitRect(x, y); | 285 rect.InitRect(x, y); |
286 bStarted = TRUE; | 286 bStarted = TRUE; |
287 } | 287 } |
288 } | 288 } |
289 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 289 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * |
290 color_count); | 290 color_count); |
291 if (bGouraud) { | 291 if (bGouraud) |
292 stream.m_BitStream.ByteAlign(); | 292 stream.m_BitStream.ByteAlign(); |
293 } | |
294 } | 293 } |
295 rect.Transform(pMatrix); | 294 rect.Transform(pMatrix); |
296 return rect; | 295 return rect; |
297 } | 296 } |
OLD | NEW |