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

Side by Side Diff: fpdfsdk/src/fpdf_flatten.cpp

Issue 1254703002: FX_BOOL considered harmful, part 2. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « fpdfsdk/src/fpdf_ext.cpp ('k') | fpdfsdk/src/fpdf_progressive.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "../../public/fpdf_flatten.h" 7 #include "../../public/fpdf_flatten.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 9
10 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray; 10 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
11 typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray; 11 typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray;
12 12
13 enum FPDF_TYPE { MAX, MIN }; 13 enum FPDF_TYPE { MAX, MIN };
14 enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM }; 14 enum FPDF_VALUE { TOP, LEFT, RIGHT, BOTTOM };
15 15
16 FX_BOOL IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage) 16 bool IsValiableRect(CPDF_Rect rect, CPDF_Rect rcPage)
17 { 17 {
18 if ( rect.left - rect.right > 0.000001f || 18 if ( rect.left - rect.right > 0.000001f ||
19 rect.bottom - rect.top > 0.000001f) 19 rect.bottom - rect.top > 0.000001f)
20 » » return FALSE; 20 » » return false;
21 21
22 if (rect.left == 0.0f && 22 if (rect.left == 0.0f &&
23 rect.top == 0.0f && 23 rect.top == 0.0f &&
24 rect.right == 0.0f && 24 rect.right == 0.0f &&
25 rect.bottom == 0.0f) 25 rect.bottom == 0.0f)
26 » » return FALSE; 26 » » return false;
27 27
28 if (!rcPage.IsEmpty()) 28 if (!rcPage.IsEmpty())
29 { 29 {
30 if (rect.left - rcPage.left < -10.000001f || 30 if (rect.left - rcPage.left < -10.000001f ||
31 rect.right - rcPage.right > 10.000001f || 31 rect.right - rcPage.right > 10.000001f ||
32 rect.top - rcPage.top > 10.000001f || 32 rect.top - rcPage.top > 10.000001f ||
33 rect.bottom - rcPage.bottom < -10.000001f) 33 rect.bottom - rcPage.bottom < -10.000001f)
34 » » » return FALSE; 34 » » » return false;
35 } 35 }
36 36
37 » return TRUE; 37 » return true;
38 } 38 }
39 39
40 40
41 FX_BOOL GetContentsRect( CPDF_Document * pDoc, CPDF_Dictionary* pDict, CPDF_Rect Array * pRectArray ) 41 bool GetContentsRect( CPDF_Document * pDoc, CPDF_Dictionary* pDict, CPDF_RectArr ay * pRectArray )
42 { 42 {
43 CPDF_Page* pPDFPage = new CPDF_Page; 43 CPDF_Page* pPDFPage = new CPDF_Page;
44 » pPDFPage->Load( pDoc, pDict, FALSE ); 44 » pPDFPage->Load( pDoc, pDict, false );
45 pPDFPage->ParseContent(); 45 pPDFPage->ParseContent();
46 46
47 FX_POSITION pos = pPDFPage->GetFirstObjectPosition(); 47 FX_POSITION pos = pPDFPage->GetFirstObjectPosition();
48 48
49 while (pos) 49 while (pos)
50 { 50 {
51 CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos); 51 CPDF_PageObject* pPageObject = pPDFPage->GetNextObject(pos);
52 if (!pPageObject)continue; 52 if (!pPageObject)continue;
53 53
54 CPDF_Rect rc; 54 CPDF_Rect rc;
55 rc.left = pPageObject->m_Left; 55 rc.left = pPageObject->m_Left;
56 rc.right = pPageObject->m_Right; 56 rc.right = pPageObject->m_Right;
57 rc.bottom = pPageObject->m_Bottom; 57 rc.bottom = pPageObject->m_Bottom;
58 rc.top = pPageObject->m_Top; 58 rc.top = pPageObject->m_Top;
59 59
60 if (IsValiableRect(rc, pDict->GetRect("MediaBox"))) 60 if (IsValiableRect(rc, pDict->GetRect("MediaBox")))
61 { 61 {
62 pRectArray->Add(rc); 62 pRectArray->Add(rc);
63 } 63 }
64 } 64 }
65 65
66 delete pPDFPage; 66 delete pPDFPage;
67 » return TRUE; 67 » return true;
68 } 68 }
69 69
70 70
71 void ParserStream( CPDF_Dictionary * pPageDic, CPDF_Dictionary* pStream, CPDF_Re ctArray * pRectArray, CPDF_ObjectArray * pObjectArray ) 71 void ParserStream( CPDF_Dictionary * pPageDic, CPDF_Dictionary* pStream, CPDF_Re ctArray * pRectArray, CPDF_ObjectArray * pObjectArray )
72 { 72 {
73 if (!pStream)return; 73 if (!pStream)return;
74 CPDF_Rect rect; 74 CPDF_Rect rect;
75 if (pStream->KeyExist("Rect")) 75 if (pStream->KeyExist("Rect"))
76 rect = pStream->GetRect("Rect"); 76 rect = pStream->GetRect("Rect");
77 else if (pStream->KeyExist("BBox")) 77 else if (pStream->KeyExist("BBox"))
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 if (!pContentsObj) 210 if (!pContentsObj)
211 { 211 {
212 //Create a new contents dictionary 212 //Create a new contents dictionary
213 if (!key.IsEmpty()) 213 if (!key.IsEmpty())
214 { 214 {
215 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary); 215 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary);
216 pPage->SetAtReference("Contents", pDocument, pDocument-> AddIndirectObject(pNewContents)); 216 pPage->SetAtReference("Contents", pDocument, pDocument-> AddIndirectObject(pNewContents));
217 217
218 CFX_ByteString sStream; 218 CFX_ByteString sStream;
219 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()) ; 219 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()) ;
220 » » » pNewContents->SetData((const uint8_t*)sStream, sStream.G etLength(), FALSE, FALSE); 220 » » » pNewContents->SetData((const uint8_t*)sStream, sStream.G etLength(), false, false);
221 } 221 }
222 return; 222 return;
223 } 223 }
224 224
225 int iType = pContentsObj->GetType(); 225 int iType = pContentsObj->GetType();
226 CPDF_Array* pContentsArray = NULL; 226 CPDF_Array* pContentsArray = NULL;
227 227
228 switch(iType) 228 switch(iType)
229 { 229 {
230 case PDFOBJ_STREAM: 230 case PDFOBJ_STREAM:
231 { 231 {
232 pContentsArray = new CPDF_Array; 232 pContentsArray = new CPDF_Array;
233 CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj; 233 CPDF_Stream* pContents = (CPDF_Stream*)pContentsObj;
234 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pConten ts); 234 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pConten ts);
235 CPDF_StreamAcc acc; 235 CPDF_StreamAcc acc;
236 acc.LoadAllData(pContents); 236 acc.LoadAllData(pContents);
237 CFX_ByteString sStream = "q\n"; 237 CFX_ByteString sStream = "q\n";
238 CFX_ByteString sBody = CFX_ByteString((const FX_CHAR*)ac c.GetData(), acc.GetSize()); 238 CFX_ByteString sBody = CFX_ByteString((const FX_CHAR*)ac c.GetData(), acc.GetSize());
239 sStream = sStream + sBody + "\nQ"; 239 sStream = sStream + sBody + "\nQ";
240 » » » pContents->SetData((const uint8_t*)sStream, sStream.GetL ength(), FALSE, FALSE); 240 » » » pContents->SetData((const uint8_t*)sStream, sStream.GetL ength(), false, false);
241 pContentsArray->AddReference(pDocument, dwObjNum); 241 pContentsArray->AddReference(pDocument, dwObjNum);
242 break; 242 break;
243 } 243 }
244 244
245 case PDFOBJ_ARRAY: 245 case PDFOBJ_ARRAY:
246 { 246 {
247 pContentsArray = (CPDF_Array*)pContentsObj; 247 pContentsArray = (CPDF_Array*)pContentsObj;
248 break; 248 break;
249 } 249 }
250 default: 250 default:
251 break; 251 break;
252 } 252 }
253 253
254 if (!pContentsArray)return; 254 if (!pContentsArray)return;
255 255
256 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray); 256 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pContentsArray);
257 pPage->SetAtReference("Contents", pDocument, dwObjNum); 257 pPage->SetAtReference("Contents", pDocument, dwObjNum);
258 258
259 if (!key.IsEmpty()) 259 if (!key.IsEmpty())
260 { 260 {
261 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Di ctionary); 261 CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Di ctionary);
262 dwObjNum = pDocument->AddIndirectObject(pNewContents); 262 dwObjNum = pDocument->AddIndirectObject(pNewContents);
263 pContentsArray->AddReference(pDocument, dwObjNum); 263 pContentsArray->AddReference(pDocument, dwObjNum);
264 264
265 CFX_ByteString sStream; 265 CFX_ByteString sStream;
266 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); 266 sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
267 » » pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength (), FALSE, FALSE); 267 » » pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength (), false, false);
268 } 268 }
269 } 269 }
270 270
271 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatr ix matrix) 271 CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatr ix matrix)
272 { 272 {
273 if(rcStream.IsEmpty()) 273 if(rcStream.IsEmpty())
274 return CFX_AffineMatrix(); 274 return CFX_AffineMatrix();
275 275
276 matrix.TransformRect(rcStream); 276 matrix.TransformRect(rcStream);
277 rcStream.Normalize(); 277 rcStream.Normalize();
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 matrix.c = 0.0f; 531 matrix.c = 0.0f;
532 matrix.d = 1.0f; 532 matrix.d = 1.0f;
533 matrix.e = 0.0f; 533 matrix.e = 0.0f;
534 matrix.f = 0.0f; 534 matrix.f = 0.0f;
535 } 535 }
536 536
537 CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix); 537 CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix);
538 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m .f, sFormName.c_str()); 538 sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m .f, sFormName.c_str());
539 sStream += sTemp; 539 sStream += sTemp;
540 540
541 » » pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength( ), FALSE, FALSE); 541 » » pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength( ), false, false);
542 } 542 }
543 pPageDict->RemoveAt( "Annots" ); 543 pPageDict->RemoveAt( "Annots" );
544 544
545 ObjectArray.RemoveAll(); 545 ObjectArray.RemoveAll();
546 RectArray.RemoveAll(); 546 RectArray.RemoveAll();
547 547
548 return FLATTEN_SUCCESS; 548 return FLATTEN_SUCCESS;
549 } 549 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdf_ext.cpp ('k') | fpdfsdk/src/fpdf_progressive.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698