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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_pattern.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 months 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 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) : 10 CPDF_Pattern::CPDF_Pattern(const CFX_AffineMatrix* pParentMatrix) :
11 m_pPatternObj(NULL), m_PatternType(PATTERN_TILING), m_pDocument(NULL), m_bFo rceClear(FALSE) 11 m_pPatternObj(NULL), m_PatternType(PATTERN_TILING), m_pDocument(NULL), m_bFo rceClear(false)
12 { 12 {
13 if (pParentMatrix) { 13 if (pParentMatrix) {
14 m_ParentMatrix = *pParentMatrix; 14 m_ParentMatrix = *pParentMatrix;
15 } 15 }
16 } 16 }
17 CPDF_Pattern::~CPDF_Pattern() 17 CPDF_Pattern::~CPDF_Pattern()
18 { 18 {
19 } 19 }
20 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatter nObj, const CFX_AffineMatrix* parentMatrix) : 20 CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatter nObj, const CFX_AffineMatrix* parentMatrix) :
21 CPDF_Pattern(parentMatrix) 21 CPDF_Pattern(parentMatrix)
22 { 22 {
23 m_PatternType = PATTERN_TILING; 23 m_PatternType = PATTERN_TILING;
24 m_pPatternObj = pPatternObj; 24 m_pPatternObj = pPatternObj;
25 m_pDocument = pDoc; 25 m_pDocument = pDoc;
26 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 26 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
27 ASSERT(pDict != NULL); 27 ASSERT(pDict != NULL);
28 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); 28 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix"));
29 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; 29 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
30 if (parentMatrix) { 30 if (parentMatrix) {
31 m_Pattern2Form.Concat(*parentMatrix); 31 m_Pattern2Form.Concat(*parentMatrix);
32 } 32 }
33 m_pForm = NULL; 33 m_pForm = NULL;
34 } 34 }
35 CPDF_TilingPattern::~CPDF_TilingPattern() 35 CPDF_TilingPattern::~CPDF_TilingPattern()
36 { 36 {
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 bool CPDF_TilingPattern::Load()
41 { 41 {
42 if (m_pForm != NULL) { 42 if (m_pForm != NULL) {
43 return TRUE; 43 return true;
44 } 44 }
45 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 45 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
46 if (pDict == NULL) { 46 if (pDict == NULL) {
47 return FALSE; 47 return false;
48 } 48 }
49 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1; 49 m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
50 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep"))); 50 m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep")));
51 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep"))); 51 m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep")));
52 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) { 52 if (m_pPatternObj->GetType() != PDFOBJ_STREAM) {
53 return FALSE; 53 return false;
54 } 54 }
55 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj; 55 CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj;
56 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream); 56 m_pForm = new CPDF_Form(m_pDocument, NULL, pStream);
57 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL); 57 m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL);
58 m_BBox = pDict->GetRect(FX_BSTRC("BBox")); 58 m_BBox = pDict->GetRect(FX_BSTRC("BBox"));
59 return TRUE; 59 return true;
60 } 60 }
61 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatt ernObj, FX_BOOL bShading, const CFX_AffineMatrix* parentMatrix) : CPDF_Pattern(p arentMatrix) 61 CPDF_ShadingPattern::CPDF_ShadingPattern(CPDF_Document* pDoc, CPDF_Object* pPatt ernObj, bool bShading, const CFX_AffineMatrix* parentMatrix) : CPDF_Pattern(pare ntMatrix)
62 { 62 {
63 m_PatternType = PATTERN_SHADING; 63 m_PatternType = PATTERN_SHADING;
64 m_pPatternObj = bShading ? NULL : pPatternObj; 64 m_pPatternObj = bShading ? NULL : pPatternObj;
65 m_pDocument = pDoc; 65 m_pDocument = pDoc;
66 m_bShadingObj = bShading; 66 m_bShadingObj = bShading;
67 if (!bShading) { 67 if (!bShading) {
68 CPDF_Dictionary* pDict = m_pPatternObj->GetDict(); 68 CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
69 ASSERT(pDict != NULL); 69 ASSERT(pDict != NULL);
70 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix")); 70 m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix"));
71 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading")); 71 m_pShadingObj = pDict->GetElementValue(FX_BSTRC("Shading"));
(...skipping 23 matching lines...) Expand all
95 } 95 }
96 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL; 96 CPDF_ColorSpace* pCS = m_pCountedCS ? m_pCountedCS->get() : NULL;
97 if (pCS && m_pDocument) { 97 if (pCS && m_pDocument) {
98 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray()); 98 m_pDocument->GetPageData()->ReleaseColorSpace(pCS->GetArray());
99 } 99 }
100 m_ShadingType = 0; 100 m_ShadingType = 0;
101 m_pCS = NULL; 101 m_pCS = NULL;
102 m_pCountedCS = NULL; 102 m_pCountedCS = NULL;
103 m_nFuncs = 0; 103 m_nFuncs = 0;
104 } 104 }
105 FX_BOOL CPDF_ShadingPattern::Load() 105 bool CPDF_ShadingPattern::Load()
106 { 106 {
107 if (m_ShadingType != 0) { 107 if (m_ShadingType != 0) {
108 return TRUE; 108 return true;
109 } 109 }
110 CPDF_Dictionary* pShadingDict = m_pShadingObj ? m_pShadingObj->GetDict() : N ULL; 110 CPDF_Dictionary* pShadingDict = m_pShadingObj ? m_pShadingObj->GetDict() : N ULL;
111 if (pShadingDict == NULL) { 111 if (pShadingDict == NULL) {
112 return FALSE; 112 return false;
113 } 113 }
114 if (m_nFuncs) { 114 if (m_nFuncs) {
115 for (int i = 0; i < m_nFuncs; i ++) 115 for (int i = 0; i < m_nFuncs; i ++)
116 delete m_pFunctions[i]; 116 delete m_pFunctions[i];
117 m_nFuncs = 0; 117 m_nFuncs = 0;
118 } 118 }
119 CPDF_Object* pFunc = pShadingDict->GetElementValue(FX_BSTRC("Function")); 119 CPDF_Object* pFunc = pShadingDict->GetElementValue(FX_BSTRC("Function"));
120 if (pFunc) { 120 if (pFunc) {
121 if (pFunc->GetType() == PDFOBJ_ARRAY) { 121 if (pFunc->GetType() == PDFOBJ_ARRAY) {
122 m_nFuncs = ((CPDF_Array*)pFunc)->GetCount(); 122 m_nFuncs = ((CPDF_Array*)pFunc)->GetCount();
123 if (m_nFuncs > 4) { 123 if (m_nFuncs > 4) {
124 m_nFuncs = 4; 124 m_nFuncs = 4;
125 } 125 }
126 for (int i = 0; i < m_nFuncs; i ++) { 126 for (int i = 0; i < m_nFuncs; i ++) {
127 m_pFunctions[i] = CPDF_Function::Load(((CPDF_Array*)pFunc)->GetE lementValue(i)); 127 m_pFunctions[i] = CPDF_Function::Load(((CPDF_Array*)pFunc)->GetE lementValue(i));
128 } 128 }
129 } else { 129 } else {
130 m_pFunctions[0] = CPDF_Function::Load(pFunc); 130 m_pFunctions[0] = CPDF_Function::Load(pFunc);
131 m_nFuncs = 1; 131 m_nFuncs = 1;
132 } 132 }
133 } 133 }
134 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace")); 134 CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace"));
135 if (pCSObj == NULL) { 135 if (pCSObj == NULL) {
136 return FALSE; 136 return false;
137 } 137 }
138 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData(); 138 CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData();
139 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL); 139 m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL);
140 if (m_pCS) { 140 if (m_pCS) {
141 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray()); 141 m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
142 } 142 }
143 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType")); 143 m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType"));
144 return TRUE; 144 return true;
145 } 145 }
146 FX_BOOL CPDF_ShadingPattern::Reload() 146 bool CPDF_ShadingPattern::Reload()
147 { 147 {
148 Clear(); 148 Clear();
149 return Load(); 149 return Load();
150 } 150 }
151 FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, CPDF_Function** pFunc s, int nFuncs, CPDF_ColorSpace* pCS) 151 bool CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS)
152 { 152 {
153 m_Stream.LoadAllData(pShadingStream); 153 m_Stream.LoadAllData(pShadingStream);
154 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize()); 154 m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize());
155 m_pFuncs = pFuncs; 155 m_pFuncs = pFuncs;
156 m_nFuncs = nFuncs; 156 m_nFuncs = nFuncs;
157 m_pCS = pCS; 157 m_pCS = pCS;
158 CPDF_Dictionary* pDict = pShadingStream->GetDict(); 158 CPDF_Dictionary* pDict = pShadingStream->GetDict();
159 m_nCoordBits = pDict->GetInteger(FX_BSTRC("BitsPerCoordinate")); 159 m_nCoordBits = pDict->GetInteger(FX_BSTRC("BitsPerCoordinate"));
160 m_nCompBits = pDict->GetInteger(FX_BSTRC("BitsPerComponent")); 160 m_nCompBits = pDict->GetInteger(FX_BSTRC("BitsPerComponent"));
161 m_nFlagBits = pDict->GetInteger(FX_BSTRC("BitsPerFlag")); 161 m_nFlagBits = pDict->GetInteger(FX_BSTRC("BitsPerFlag"));
162 if (!m_nCoordBits || !m_nCompBits) { 162 if (!m_nCoordBits || !m_nCompBits) {
163 return FALSE; 163 return false;
164 } 164 }
165 int nComps = pCS->CountComponents(); 165 int nComps = pCS->CountComponents();
166 if (nComps > 8) { 166 if (nComps > 8) {
167 return FALSE; 167 return false;
168 } 168 }
169 m_nComps = nFuncs ? 1 : nComps; 169 m_nComps = nFuncs ? 1 : nComps;
170 if (((int)m_nComps < 0) || m_nComps > 8) { 170 if (((int)m_nComps < 0) || m_nComps > 8) {
171 return FALSE; 171 return false;
172 } 172 }
173 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1; 173 m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1;
174 m_CompMax = (1 << m_nCompBits) - 1; 174 m_CompMax = (1 << m_nCompBits) - 1;
175 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode")); 175 CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode"));
176 if (pDecode == NULL || pDecode->GetCount() != 4 + m_nComps * 2) { 176 if (pDecode == NULL || pDecode->GetCount() != 4 + m_nComps * 2) {
177 return FALSE; 177 return false;
178 } 178 }
179 m_xmin = pDecode->GetNumber(0); 179 m_xmin = pDecode->GetNumber(0);
180 m_xmax = pDecode->GetNumber(1); 180 m_xmax = pDecode->GetNumber(1);
181 m_ymin = pDecode->GetNumber(2); 181 m_ymin = pDecode->GetNumber(2);
182 m_ymax = pDecode->GetNumber(3); 182 m_ymax = pDecode->GetNumber(3);
183 for (FX_DWORD i = 0; i < m_nComps; i ++) { 183 for (FX_DWORD i = 0; i < m_nComps; i ++) {
184 m_ColorMin[i] = pDecode->GetNumber(i * 2 + 4); 184 m_ColorMin[i] = pDecode->GetNumber(i * 2 + 4);
185 m_ColorMax[i] = pDecode->GetNumber(i * 2 + 5); 185 m_ColorMax[i] = pDecode->GetNumber(i * 2 + 5);
186 } 186 }
187 return TRUE; 187 return true;
188 } 188 }
189 FX_DWORD CPDF_MeshStream::GetFlag() 189 FX_DWORD CPDF_MeshStream::GetFlag()
190 { 190 {
191 return m_BitStream.GetBits(m_nFlagBits) & 0x03; 191 return m_BitStream.GetBits(m_nFlagBits) & 0x03;
192 } 192 }
193 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y) 193 void CPDF_MeshStream::GetCoords(FX_FLOAT& x, FX_FLOAT& y)
194 { 194 {
195 if (m_nCoordBits == 32) { 195 if (m_nCoordBits == 32) {
196 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_ xmin) / (double)m_CoordMax); 196 x = m_xmin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * (m_xmax - m_ xmin) / (double)m_CoordMax);
197 y = m_ymin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ ymin) / (double)m_CoordMax); 197 y = m_ymin + (FX_FLOAT)(m_BitStream.GetBits(m_nCoordBits) * (m_ymax - m_ ymin) / (double)m_CoordMax);
(...skipping 26 matching lines...) Expand all
224 } 224 }
225 FX_DWORD CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex, CFX_AffineMatrix* p Object2Bitmap) 225 FX_DWORD CPDF_MeshStream::GetVertex(CPDF_MeshVertex& vertex, CFX_AffineMatrix* p Object2Bitmap)
226 { 226 {
227 FX_DWORD flag = GetFlag(); 227 FX_DWORD flag = GetFlag();
228 GetCoords(vertex.x, vertex.y); 228 GetCoords(vertex.x, vertex.y);
229 pObject2Bitmap->Transform(vertex.x, vertex.y); 229 pObject2Bitmap->Transform(vertex.x, vertex.y);
230 GetColor(vertex.r, vertex.g, vertex.b); 230 GetColor(vertex.r, vertex.g, vertex.b);
231 m_BitStream.ByteAlign(); 231 m_BitStream.ByteAlign();
232 return flag; 232 return flag;
233 } 233 }
234 FX_BOOL CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex, int count, CFX_Af fineMatrix* pObject2Bitmap) 234 bool CPDF_MeshStream::GetVertexRow(CPDF_MeshVertex* vertex, int count, CFX_Affin eMatrix* pObject2Bitmap)
235 { 235 {
236 for (int i = 0; i < count; i ++) { 236 for (int i = 0; i < count; i ++) {
237 if (m_BitStream.IsEOF()) { 237 if (m_BitStream.IsEOF()) {
238 return FALSE; 238 return false;
239 } 239 }
240 GetCoords(vertex[i].x, vertex[i].y); 240 GetCoords(vertex[i].x, vertex[i].y);
241 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y); 241 pObject2Bitmap->Transform(vertex[i].x, vertex[i].y);
242 GetColor(vertex[i].r, vertex[i].g, vertex[i].b); 242 GetColor(vertex[i].r, vertex[i].g, vertex[i].b);
243 m_BitStream.ByteAlign(); 243 m_BitStream.ByteAlign();
244 } 244 }
245 return TRUE; 245 return true;
246 } 246 }
247 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, int type, const CFX_AffineMa trix* pMatrix, 247 CFX_FloatRect _GetShadingBBox(CPDF_Stream* pStream, int type, const CFX_AffineMa trix* pMatrix,
248 CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpac e* pCS) 248 CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpac e* pCS)
249 { 249 {
250 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM || pFuncs == NULL || pCS == NULL) { 250 if (pStream == NULL || pStream->GetType() != PDFOBJ_STREAM || pFuncs == NULL || pCS == NULL) {
251 return CFX_FloatRect(0, 0, 0, 0); 251 return CFX_FloatRect(0, 0, 0, 0);
252 } 252 }
253 CPDF_MeshStream stream; 253 CPDF_MeshStream stream;
254 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) { 254 if (!stream.Load(pStream, pFuncs, nFuncs, pCS)) {
255 return CFX_FloatRect(0, 0, 0, 0); 255 return CFX_FloatRect(0, 0, 0, 0);
256 } 256 }
257 CFX_FloatRect rect; 257 CFX_FloatRect rect;
258 FX_BOOL bStarted = FALSE; 258 bool bStarted = false;
259 FX_BOOL bGouraud = type == 4 || type == 5; 259 bool bGouraud = type == 4 || type == 5;
260 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1); 260 int full_point_count = type == 7 ? 16 : (type == 6 ? 12 : 1);
261 int full_color_count = (type == 6 || type == 7) ? 4 : 1; 261 int full_color_count = (type == 6 || type == 7) ? 4 : 1;
262 while (!stream.m_BitStream.IsEOF()) { 262 while (!stream.m_BitStream.IsEOF()) {
263 FX_DWORD flag = 0; 263 FX_DWORD flag = 0;
264 if (type != 5) { 264 if (type != 5) {
265 flag = stream.GetFlag(); 265 flag = stream.GetFlag();
266 } 266 }
267 int point_count = full_point_count, color_count = full_color_count; 267 int point_count = full_point_count, color_count = full_color_count;
268 if (!bGouraud && flag) { 268 if (!bGouraud && flag) {
269 point_count -= 4; 269 point_count -= 4;
270 color_count -= 2; 270 color_count -= 2;
271 } 271 }
272 for (int i = 0; i < point_count; i ++) { 272 for (int i = 0; i < point_count; i ++) {
273 FX_FLOAT x, y; 273 FX_FLOAT x, y;
274 stream.GetCoords(x, y); 274 stream.GetCoords(x, y);
275 if (bStarted) { 275 if (bStarted) {
276 rect.UpdateRect(x, y); 276 rect.UpdateRect(x, y);
277 } else { 277 } else {
278 rect.InitRect(x, y); 278 rect.InitRect(x, y);
279 bStarted = TRUE; 279 bStarted = true;
280 } 280 }
281 } 281 }
282 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * color _count); 282 stream.m_BitStream.SkipBits(stream.m_nComps * stream.m_nCompBits * color _count);
283 if (bGouraud) { 283 if (bGouraud) {
284 stream.m_BitStream.ByteAlign(); 284 stream.m_BitStream.ByteAlign();
285 } 285 }
286 } 286 }
287 rect.Transform(pMatrix); 287 rect.Transform(pMatrix);
288 return rect; 288 return rect;
289 } 289 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp ('k') | core/src/fpdfapi/fpdf_page/pageint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698