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 "pageint.h" | 7 #include "pageint.h" |
8 | 8 |
9 #include "core/include/fpdfapi/fpdf_page.h" | 9 #include "core/include/fpdfapi/fpdf_page.h" |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 m_bForceClear(FALSE) { | 36 m_bForceClear(FALSE) { |
37 if (pParentMatrix) | 37 if (pParentMatrix) |
38 m_ParentMatrix = *pParentMatrix; | 38 m_ParentMatrix = *pParentMatrix; |
39 } | 39 } |
40 CPDF_Pattern::~CPDF_Pattern() {} | 40 CPDF_Pattern::~CPDF_Pattern() {} |
41 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, | 41 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, |
42 CPDF_Object* pPatternObj, | 42 CPDF_Object* pPatternObj, |
43 const CFX_Matrix* parentMatrix) | 43 const CFX_Matrix* parentMatrix) |
44 : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { | 44 : CPDF_Pattern(TILING, pDoc, pPatternObj, parentMatrix) { |
45 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 45 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
46 m_Pattern2Form = pDict->GetMatrix("Matrix"); | 46 m_Pattern2Form = pDict->GetMatrixBy("Matrix"); |
47 m_bColored = pDict->GetInteger("PaintType") == 1; | 47 m_bColored = pDict->GetIntegerBy("PaintType") == 1; |
48 if (parentMatrix) { | 48 if (parentMatrix) { |
49 m_Pattern2Form.Concat(*parentMatrix); | 49 m_Pattern2Form.Concat(*parentMatrix); |
50 } | 50 } |
51 m_pForm = NULL; | 51 m_pForm = NULL; |
52 } | 52 } |
53 CPDF_TilingPattern::~CPDF_TilingPattern() { | 53 CPDF_TilingPattern::~CPDF_TilingPattern() { |
54 delete m_pForm; | 54 delete m_pForm; |
55 m_pForm = NULL; | 55 m_pForm = NULL; |
56 } | 56 } |
57 FX_BOOL CPDF_TilingPattern::Load() { | 57 FX_BOOL CPDF_TilingPattern::Load() { |
58 if (m_pForm) | 58 if (m_pForm) |
59 return TRUE; | 59 return TRUE; |
60 | 60 |
61 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 61 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
62 if (!pDict) | 62 if (!pDict) |
63 return FALSE; | 63 return FALSE; |
64 | 64 |
65 m_bColored = pDict->GetInteger("PaintType") == 1; | 65 m_bColored = pDict->GetIntegerBy("PaintType") == 1; |
66 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber("XStep")); | 66 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberBy("XStep")); |
67 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber("YStep")); | 67 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumberBy("YStep")); |
68 | 68 |
69 CPDF_Stream* pStream = m_pPatternObj->AsStream(); | 69 CPDF_Stream* pStream = m_pPatternObj->AsStream(); |
70 if (!pStream) | 70 if (!pStream) |
71 return FALSE; | 71 return FALSE; |
72 | 72 |
73 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); | 73 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); |
74 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); | 74 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); |
75 m_BBox = pDict->GetRect("BBox"); | 75 m_BBox = pDict->GetRectBy("BBox"); |
76 return TRUE; | 76 return TRUE; |
77 } | 77 } |
78 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, | 78 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, |
79 CPDF_Object* pPatternObj, | 79 CPDF_Object* pPatternObj, |
80 FX_BOOL bShading, | 80 FX_BOOL bShading, |
81 const CFX_Matrix* parentMatrix) | 81 const CFX_Matrix* parentMatrix) |
82 : CPDF_Pattern(SHADING, | 82 : CPDF_Pattern(SHADING, |
83 pDoc, | 83 pDoc, |
84 bShading ? nullptr : pPatternObj, | 84 bShading ? nullptr : pPatternObj, |
85 parentMatrix), | 85 parentMatrix), |
86 m_ShadingType(kInvalidShading), | 86 m_ShadingType(kInvalidShading), |
87 m_bShadingObj(bShading), | 87 m_bShadingObj(bShading), |
88 m_pShadingObj(pPatternObj), | 88 m_pShadingObj(pPatternObj), |
89 m_pCS(nullptr), | 89 m_pCS(nullptr), |
90 m_pCountedCS(nullptr), | 90 m_pCountedCS(nullptr), |
91 m_nFuncs(0) { | 91 m_nFuncs(0) { |
92 if (!bShading) { | 92 if (!bShading) { |
93 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); | 93 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); |
94 m_Pattern2Form = pDict->GetMatrix("Matrix"); | 94 m_Pattern2Form = pDict->GetMatrixBy("Matrix"); |
95 m_pShadingObj = pDict->GetElementValue("Shading"); | 95 m_pShadingObj = pDict->GetElementValue("Shading"); |
96 if (parentMatrix) | 96 if (parentMatrix) |
97 m_Pattern2Form.Concat(*parentMatrix); | 97 m_Pattern2Form.Concat(*parentMatrix); |
98 } | 98 } |
99 for (int i = 0; i < FX_ArraySize(m_pFunctions); ++i) | 99 for (int i = 0; i < FX_ArraySize(m_pFunctions); ++i) |
100 m_pFunctions[i] = nullptr; | 100 m_pFunctions[i] = nullptr; |
101 } | 101 } |
102 | 102 |
103 CPDF_ShadingPattern::~CPDF_ShadingPattern() { | 103 CPDF_ShadingPattern::~CPDF_ShadingPattern() { |
104 for (int i = 0; i < m_nFuncs; ++i) | 104 for (int i = 0; i < m_nFuncs; ++i) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 CPDF_Object* pCSObj = pShadingDict->GetElementValue("ColorSpace"); | 139 CPDF_Object* pCSObj = pShadingDict->GetElementValue("ColorSpace"); |
140 if (!pCSObj) { | 140 if (!pCSObj) { |
141 return FALSE; | 141 return FALSE; |
142 } | 142 } |
143 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); | 143 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); |
144 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); | 144 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); |
145 if (m_pCS) { | 145 if (m_pCS) { |
146 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); | 146 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); |
147 } | 147 } |
148 | 148 |
149 m_ShadingType = ToShadingType(pShadingDict->GetInteger("ShadingType")); | 149 m_ShadingType = ToShadingType(pShadingDict->GetIntegerBy("ShadingType")); |
150 | 150 |
151 // We expect to have a stream if our shading type is a mesh. | 151 // We expect to have a stream if our shading type is a mesh. |
152 if (IsMeshShading() && !ToStream(m_pShadingObj)) | 152 if (IsMeshShading() && !ToStream(m_pShadingObj)) |
153 return FALSE; | 153 return FALSE; |
154 | 154 |
155 return TRUE; | 155 return TRUE; |
156 } | 156 } |
157 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, | 157 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, |
158 CPDF_Function** pFuncs, | 158 CPDF_Function** pFuncs, |
159 int nFuncs, | 159 int nFuncs, |
160 CPDF_ColorSpace* pCS) { | 160 CPDF_ColorSpace* pCS) { |
161 m_Stream.LoadAllData(pShadingStream); | 161 m_Stream.LoadAllData(pShadingStream); |
162 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); | 162 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); |
163 m_pFuncs = pFuncs; | 163 m_pFuncs = pFuncs; |
164 m_nFuncs = nFuncs; | 164 m_nFuncs = nFuncs; |
165 m_pCS = pCS; | 165 m_pCS = pCS; |
166 CPDF_Dictionary* pDict = pShadingStream->GetDict(); | 166 CPDF_Dictionary* pDict = pShadingStream->GetDict(); |
167 m_nCoordBits = pDict->GetInteger("BitsPerCoordinate"); | 167 m_nCoordBits = pDict->GetIntegerBy("BitsPerCoordinate"); |
168 m_nCompBits = pDict->GetInteger("BitsPerComponent"); | 168 m_nCompBits = pDict->GetIntegerBy("BitsPerComponent"); |
169 m_nFlagBits = pDict->GetInteger("BitsPerFlag"); | 169 m_nFlagBits = pDict->GetIntegerBy("BitsPerFlag"); |
170 if (!m_nCoordBits || !m_nCompBits) { | 170 if (!m_nCoordBits || !m_nCompBits) { |
171 return FALSE; | 171 return FALSE; |
172 } | 172 } |
173 int nComps = pCS->CountComponents(); | 173 int nComps = pCS->CountComponents(); |
174 if (nComps > 8) { | 174 if (nComps > 8) { |
175 return FALSE; | 175 return FALSE; |
176 } | 176 } |
177 m_nComps = nFuncs ? 1 : nComps; | 177 m_nComps = nFuncs ? 1 : nComps; |
178 if (((int)m_nComps < 0) || m_nComps > 8) { | 178 if (((int)m_nComps < 0) || m_nComps > 8) { |
179 return FALSE; | 179 return FALSE; |
180 } | 180 } |
181 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; | 181 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; |
182 m_CompMax = (1 << m_nCompBits) - 1; | 182 m_CompMax = (1 << m_nCompBits) - 1; |
183 CPDF_Array* pDecode = pDict->GetArray("Decode"); | 183 CPDF_Array* pDecode = pDict->GetArrayBy("Decode"); |
184 if (!pDecode || pDecode->GetCount() != 4 + m_nComps * 2) { | 184 if (!pDecode || pDecode->GetCount() != 4 + m_nComps * 2) { |
185 return FALSE; | 185 return FALSE; |
186 } | 186 } |
187 m_xmin = pDecode->GetNumber(0); | 187 m_xmin = pDecode->GetNumberAt(0); |
188 m_xmax = pDecode->GetNumber(1); | 188 m_xmax = pDecode->GetNumberAt(1); |
189 m_ymin = pDecode->GetNumber(2); | 189 m_ymin = pDecode->GetNumberAt(2); |
190 m_ymax = pDecode->GetNumber(3); | 190 m_ymax = pDecode->GetNumberAt(3); |
191 for (FX_DWORD i = 0; i < m_nComps; i++) { | 191 for (FX_DWORD i = 0; i < m_nComps; i++) { |
192 m_ColorMin[i] = pDecode->GetNumber(i * 2 + 4); | 192 m_ColorMin[i] = pDecode->GetNumberAt(i * 2 + 4); |
193 m_ColorMax[i] = pDecode->GetNumber(i * 2 + 5); | 193 m_ColorMax[i] = pDecode->GetNumberAt(i * 2 + 5); |
194 } | 194 } |
195 return TRUE; | 195 return TRUE; |
196 } | 196 } |
197 FX_DWORD CPDF_MeshStream::GetFlag() { | 197 FX_DWORD CPDF_MeshStream::GetFlag() { |
198 return m_BitStream.GetBits(m_nFlagBits) & 0x03; | 198 return m_BitStream.GetBits(m_nFlagBits) & 0x03; |
199 } | 199 } |
200 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) { | 200 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) { |
201 if (m_nCoordBits == 32) { | 201 if (m_nCoordBits == 32) { |
202 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * | 202 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * |
203 (m_xmax - m_xmin) / (double)m_CoordMax); | 203 (m_xmax - m_xmin) / (double)m_CoordMax); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 } | 306 } |
307 } | 307 } |
308 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * | 308 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * |
309 color_count); | 309 color_count); |
310 if (bGouraud) | 310 if (bGouraud) |
311 stream.m_BitStream.ByteAlign(); | 311 stream.m_BitStream.ByteAlign(); |
312 } | 312 } |
313 rect.Transform(pMatrix); | 313 rect.Transform(pMatrix); |
314 return rect; | 314 return rect; |
315 } | 315 } |
OLD | NEW |