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 "../../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; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 if (IsValiableRect(rect, pPageDic->GetRect("MediaBox"))) | 80 if (IsValiableRect(rect, pPageDic->GetRect("MediaBox"))) |
81 pRectArray->Add(rect); | 81 pRectArray->Add(rect); |
82 | 82 |
83 pObjectArray->Add(pStream); | 83 pObjectArray->Add(pStream); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_Re ctArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage) | 87 int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_Re ctArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage) |
88 { | 88 { |
89 » if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL; | 89 if (!pSourceDoc || !pPageDic) |
90 » | 90 return FLATTEN_FAIL; |
91 » GetContentsRect( pSourceDoc, pPageDic, pRectArray ); | |
92 » CPDF_Array* pAnnots = pPageDic->GetArray("Annots"); | |
93 » if (pAnnots) | |
94 » { | |
95 » » FX_DWORD dwSize = pAnnots->GetCount(); | |
96 » » | |
97 » » for (int i = 0; i < (int)dwSize; i++) | |
98 » » { | |
99 » » » CPDF_Object* pObj = pAnnots->GetElementValue(i); | |
100 » » » | |
101 » » » if (!pObj)continue; | |
102 » » » | |
103 » » » if (pObj->GetType() == PDFOBJ_DICTIONARY) | |
104 » » » { | |
105 » » » » CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)p Obj; | |
106 » » » » CFX_ByteString sSubtype = pAnnotDic->GetString(" Subtype"); | |
107 » » » » if (sSubtype == "Popup")continue; | |
108 | 91 |
109 » » » » int nAnnotFlag = pAnnotDic->GetInteger("F"); | 92 GetContentsRect( pSourceDoc, pPageDic, pRectArray ); |
93 CPDF_Array* pAnnots = pPageDic->GetArray("Annots"); | |
94 if (pAnnots) | |
95 { | |
96 FX_DWORD dwSize = pAnnots->GetCount(); | |
97 for (int i = 0; i < (int)dwSize; i++) | |
98 { | |
99 CPDF_Object* pObj = pAnnots->GetElementValue(i); | |
100 if (!pObj) | |
101 continue; | |
110 | 102 |
111 » » » » if(nAnnotFlag & ANNOTFLAG_HIDDEN) | 103 if (pObj->GetType() == PDFOBJ_DICTIONARY) |
112 » » » » » continue; | 104 { |
113 » » » » if(nUsage == FLAT_NORMALDISPLAY) | 105 CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj; |
114 » » » » { | 106 CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype"); |
115 » » » » » if(nAnnotFlag & ANNOTFLAG_INVISIBLE) | 107 if (sSubtype == "Popup") |
116 » » » » » » continue; | 108 continue; |
117 » » » » » ParserStream( pPageDic, pAnnotDic, pRect Array, pObjectArray );» » | 109 |
118 » » » » } | 110 int nAnnotFlag = pAnnotDic->GetInteger("F"); |
119 » » » » else | 111 if (nAnnotFlag & ANNOTFLAG_HIDDEN) |
120 » » » » { | 112 continue; |
121 » » » » » if(nAnnotFlag & ANNOTFLAG_PRINT) | 113 |
122 » » » » » » ParserStream( pPageDic, pAnnotDi c, pRectArray, pObjectArray ); | 114 if(nUsage == FLAT_NORMALDISPLAY) |
123 » » » » }» » » | 115 { |
124 » » » } | 116 if (nAnnotFlag & ANNOTFLAG_INVISIBLE) |
125 » » } | 117 continue; |
126 » » return FLATTEN_SUCCESS; | 118 |
127 » }else{ | 119 ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray ); |
128 » » return FLATTEN_NOTINGTODO; | 120 } |
129 » } | 121 else |
122 { | |
123 if (nAnnotFlag & ANNOTFLAG_PRINT) | |
124 ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectAr ray ); | |
125 } | |
126 } | |
127 } | |
128 return FLATTEN_SUCCESS; | |
129 } | |
130 return FLATTEN_NOTHINGTODO; | |
Lei Zhang
2015/05/19 20:20:37
Can we just do:
if (!pAnnots)
return FLATTEN_NO
Tom Sepez
2015/05/19 21:36:38
Done.
| |
130 } | 131 } |
131 | 132 |
132 | 133 |
133 FX_FLOAT GetMinMaxValue( CPDF_RectArray& array, FPDF_TYPE type, FPDF_VALUE value ) | 134 FX_FLOAT GetMinMaxValue( CPDF_RectArray& array, FPDF_TYPE type, FPDF_VALUE value ) |
134 { | 135 { |
135 int nRects = array.GetSize(); | 136 int nRects = array.GetSize(); |
136 FX_FLOAT fRet = 0.0f; | 137 FX_FLOAT fRet = 0.0f; |
137 | 138 |
138 if (nRects <= 0)return 0.0f; | 139 if (nRects <= 0)return 0.0f; |
139 | 140 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 if ( !pDocument || !pPageDict ) | 339 if ( !pDocument || !pPageDict ) |
339 { | 340 { |
340 return FLATTEN_FAIL; | 341 return FLATTEN_FAIL; |
341 } | 342 } |
342 | 343 |
343 CPDF_ObjectArray ObjectArray; | 344 CPDF_ObjectArray ObjectArray; |
344 CPDF_RectArray RectArray; | 345 CPDF_RectArray RectArray; |
345 | 346 |
346 int iRet = FLATTEN_FAIL; | 347 int iRet = FLATTEN_FAIL; |
347 iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFl ag); | 348 iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFl ag); |
348 » if (iRet == FLATTEN_NOTINGTODO) | 349 » if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL) |
349 » { | 350 » » return iret; |
350 » » return FLATTEN_NOTINGTODO; | 351 |
351 » }else if (iRet == FLATTEN_FAIL) | |
352 » { | |
353 » » return FLATTEN_FAIL; | |
354 » } | |
355 » | |
356 CPDF_Rect rcOriginalCB; | 352 CPDF_Rect rcOriginalCB; |
357 CPDF_Rect rcMerger = CalculateRect( &RectArray ); | 353 CPDF_Rect rcMerger = CalculateRect( &RectArray ); |
358 CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox"); | 354 CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox"); |
359 | 355 |
360 if (pPageDict->KeyExist("CropBox")) | 356 if (pPageDict->KeyExist("CropBox")) |
361 rcOriginalMB = pPageDict->GetRect("CropBox"); | 357 rcOriginalMB = pPageDict->GetRect("CropBox"); |
362 | 358 |
363 if (rcOriginalMB.IsEmpty()) | 359 if (rcOriginalMB.IsEmpty()) |
364 { | 360 { |
365 rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f); | 361 rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 | 544 |
549 pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), F ALSE, FALSE); | 545 pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), F ALSE, FALSE); |
550 } | 546 } |
551 pPageDict->RemoveAt( "Annots" ); | 547 pPageDict->RemoveAt( "Annots" ); |
552 | 548 |
553 ObjectArray.RemoveAll(); | 549 ObjectArray.RemoveAll(); |
554 RectArray.RemoveAll(); | 550 RectArray.RemoveAll(); |
555 | 551 |
556 return FLATTEN_SUCCESS; | 552 return FLATTEN_SUCCESS; |
557 } | 553 } |
OLD | NEW |