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

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

Issue 1239313005: Merge to XFA - else after returns. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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 "../../public/fpdf_ppo.h" 7 #include "../../public/fpdf_ppo.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" 9 #include "../include/fpdfxfa/fpdfxfa_doc.h"
10 10
11 class CPDF_PageOrganizer 11 class CPDF_PageOrganizer
12 { 12 {
13 public: 13 public:
14 » CPDF_PageOrganizer(); 14 CPDF_PageOrganizer();
15 » ~CPDF_PageOrganizer(); 15 ~CPDF_PageOrganizer();
16 16
17 public: 17 public:
18 » FX_BOOL»» » » PDFDocInit(CPDF_Document *pDestPDFDoc, C PDF_Document *pSrcPDFDoc); 18 FX_BOOL PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pS rcPDFDoc);
19 » FX_BOOL»» » » ExportPage(CPDF_Document *pSrcPDFDoc, CF X_WordArray* nPageNum, CPDF_Document *pDestPDFDoc, int nIndex); 19 FX_BOOL ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPa geNum, CPDF_Document *pDestPDFDoc, int nIndex);
20 » CPDF_Object*» » PageDictGetInheritableTag(CPDF_Dictionary *pDict , CFX_ByteString nSrctag); 20 CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary *pDict, CFX_By teString nSrctag);
21 » FX_BOOL»» » » UpdateReference(CPDF_Object *pObj, CPDF_ Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr); 21 FX_BOOL UpdateReference(CPDF_Object *pObj, CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr);
22 » int» » » » » GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPtrToPtr, CPDF_Reference *pRef); 22 int GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPt rToPtr, CPDF_Reference *pRef);
23 23
24 }; 24 };
25 25
26 26
27 CPDF_PageOrganizer::CPDF_PageOrganizer() 27 CPDF_PageOrganizer::CPDF_PageOrganizer()
28 { 28 {
29 29
30 } 30 }
31 31
32 CPDF_PageOrganizer::~CPDF_PageOrganizer() 32 CPDF_PageOrganizer::~CPDF_PageOrganizer()
33 { 33 {
34 34
35 } 35 }
36 36
37 FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc) 37 FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document *pDestPDFDoc, CPDF_Document *pSrcPDFDoc)
38 { 38 {
39 » if(!pDestPDFDoc || !pSrcPDFDoc) 39 if(!pDestPDFDoc || !pSrcPDFDoc)
40 » » return false; 40 return false;
41 41
42 » CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot(); 42 CPDF_Dictionary* pNewRoot = pDestPDFDoc->GetRoot();
43 » if(!pNewRoot)» return FALSE; 43 if(!pNewRoot) return FALSE;
44 44
45 » //Set the document information////////////////////////////////////////// // 45 //Set the document information////////////////////////////////////////////
46 46
47 » CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo(); 47 CPDF_Dictionary* DInfoDict = pDestPDFDoc->GetInfo();
48 48
49 » if(!DInfoDict) 49 if(!DInfoDict)
50 » » return FALSE; 50 return FALSE;
51 51
52 » CFX_ByteString producerstr; 52 CFX_ByteString producerstr;
53 » producerstr.Format("PDFium"); 53 producerstr.Format("PDFium");
54 » DInfoDict->SetAt("Producer", new CPDF_String(producerstr)); 54 DInfoDict->SetAt("Producer", new CPDF_String(producerstr));
55 55
56 » //Set type////////////////////////////////////////////////////////////// // 56 //Set type////////////////////////////////////////////////////////////////
57 » CFX_ByteString cbRootType = pNewRoot->GetString("Type",""); 57 CFX_ByteString cbRootType = pNewRoot->GetString("Type","");
58 » if( cbRootType.Equal("") ) 58 if( cbRootType.Equal("") )
59 » { 59 {
60 » » pNewRoot->SetAt("Type", new CPDF_Name("Catalog")); 60 pNewRoot->SetAt("Type", new CPDF_Name("Catalog"));
61 » } 61 }
62 62
63 » CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)(pNewRoot->GetElement("Pa ges")? pNewRoot->GetElement("Pages")->GetDirect() : NULL); 63 CPDF_Dictionary* pNewPages = (CPDF_Dictionary*)(pNewRoot->GetElement("Pages" )? pNewRoot->GetElement("Pages")->GetDirect() : NULL);
64 » if(!pNewPages) 64 if(!pNewPages)
65 » { 65 {
66 » » pNewPages = new CPDF_Dictionary; 66 pNewPages = new CPDF_Dictionary;
67 » » FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages); 67 FX_DWORD NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
68 » » pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPage sON)); 68 pNewRoot->SetAt("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
69 » } 69 }
70 70
71 » CFX_ByteString cbPageType = pNewPages->GetString("Type",""); 71 CFX_ByteString cbPageType = pNewPages->GetString("Type","");
72 » if(cbPageType.Equal("")) 72 if(cbPageType.Equal(""))
73 » { 73 {
74 » » pNewPages->SetAt("Type", new CPDF_Name("Pages")); 74 pNewPages->SetAt("Type", new CPDF_Name("Pages"));
75 » } 75 }
76 76
77 » CPDF_Array* pKeysArray = pNewPages->GetArray("Kids"); 77 CPDF_Array* pKeysArray = pNewPages->GetArray("Kids");
78 » if(pKeysArray == NULL) 78 if(pKeysArray == NULL)
79 » { 79 {
80 » » CPDF_Array* pNewKids = new CPDF_Array; 80 CPDF_Array* pNewKids = new CPDF_Array;
81 » » FX_DWORD Kidsobjnum = -1; 81 FX_DWORD Kidsobjnum = -1;
82 » » Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);//, Kidsob jnum, Kidsgennum); 82 Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);//, Kidsobjnum, Ki dsgennum);
83 83
84 » » pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobj num));//, Kidsgennum)); 84 pNewPages->SetAt("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum));// , Kidsgennum));
85 » » pNewPages->SetAt("Count", new CPDF_Number(0)); 85 pNewPages->SetAt("Count", new CPDF_Number(0));
86 » } 86 }
87 87
88 » return true; 88 return true;
89 } 89 }
90 90
91 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum, 91 FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document *pSrcPDFDoc, CFX_WordArray* nPageNum,
92 » » » » » » » » » » » » CPDF_Document *pDestPDFDoc,int nIndex) 92 CPDF_Document *pDestPDFDoc,int n Index)
93 { 93 {
94 » int curpage =nIndex; 94 int curpage =nIndex;
95 95
96 » CFX_MapPtrToPtr* pMapPtrToPtr = new CFX_MapPtrToPtr; 96 CFX_MapPtrToPtr* pMapPtrToPtr = new CFX_MapPtrToPtr;
97 » pMapPtrToPtr->InitHashTable(1001); 97 pMapPtrToPtr->InitHashTable(1001);
98 98
99 » for(int i=0; i<nPageNum->GetSize(); i++) 99 for(int i=0; i<nPageNum->GetSize(); i++)
100 » { 100 {
101 101
102 » » CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpa ge); 102 CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
103 » » CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->Ge tAt(i)-1); 103 CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i)-1 );
104 » » if(!pSrcPageDict || !pCurPageDict) 104 if(!pSrcPageDict || !pCurPageDict)
105 » » { 105 {
106 » » » delete pMapPtrToPtr; 106 delete pMapPtrToPtr;
107 » » » return FALSE; 107 return FALSE;
108 » » } 108 }
109 109
110 » » // Clone the page dictionary/////////// 110 // Clone the page dictionary///////////
111 » » FX_POSITION» SrcPos = pSrcPageDict->GetStartPos(); 111 FX_POSITION SrcPos = pSrcPageDict->GetStartPos();
112 » » while (SrcPos) 112 while (SrcPos)
113 » » { 113 {
114 » » » CFX_ByteString cbSrcKeyStr; 114 CFX_ByteString cbSrcKeyStr;
115 » » » CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr); 115 CPDF_Object* pObj = pSrcPageDict->GetNextElement(SrcPos, cbSrcKeyStr );
116 » » » if(cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare( ("Parent"))) 116 if(cbSrcKeyStr.Compare(("Type")) && cbSrcKeyStr.Compare(("Parent")))
117 » » » { 117 {
118 » » » » if(pCurPageDict->KeyExist(cbSrcKeyStr)) 118 if(pCurPageDict->KeyExist(cbSrcKeyStr))
119 » » » » » pCurPageDict->RemoveAt(cbSrcKeyStr); 119 pCurPageDict->RemoveAt(cbSrcKeyStr);
120 » » » » pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone()); 120 pCurPageDict->SetAt(cbSrcKeyStr, pObj->Clone());
121 » » » } 121 }
122 » » } 122 }
123 123
124 » » //inheritable item/////////////////////// 124 //inheritable item///////////////////////
125 » » CPDF_Object* pInheritable = NULL; 125 CPDF_Object* pInheritable = NULL;
126 » » //1» MediaBox //required 126 //1 MediaBox //required
127 » » if(!pCurPageDict->KeyExist("MediaBox")) 127 if(!pCurPageDict->KeyExist("MediaBox"))
128 » » { 128 {
129 129
130 » » » pInheritable = PageDictGetInheritableTag(pSrcPageDict, " MediaBox"); 130 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "MediaBox");
131 » » » if(!pInheritable) 131 if(!pInheritable)
132 » » » { 132 {
133 » » » » //Search the "CropBox" from source page dictiona ry, if not exists,we take the letter size. 133 //Search the "CropBox" from source page dictionary, if not exist s,we take the letter size.
134 » » » » pInheritable = PageDictGetInheritableTag(pSrcPag eDict, "CropBox"); 134 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox" );
135 » » » » if(pInheritable) 135 if(pInheritable)
136 » » » » » pCurPageDict->SetAt("MediaBox", pInherit able->Clone()); 136 pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
137 » » » » else 137 else
138 » » » » { 138 {
139 » » » » » //Make the default size to be letter siz e (8.5'x11') 139 //Make the default size to be letter size (8.5'x11')
140 » » » » » CPDF_Array* pArray = new CPDF_Array; 140 CPDF_Array* pArray = new CPDF_Array;
141 » » » » » pArray->AddNumber(0); 141 pArray->AddNumber(0);
142 » » » » » pArray->AddNumber(0); 142 pArray->AddNumber(0);
143 » » » » » pArray->AddNumber(612); 143 pArray->AddNumber(612);
144 » » » » » pArray->AddNumber(792); 144 pArray->AddNumber(792);
145 » » » » » pCurPageDict->SetAt("MediaBox", pArray); 145 pCurPageDict->SetAt("MediaBox", pArray);
146 » » » » } 146 }
147 » » » } 147 }
148 » » » else 148 else
149 » » » » pCurPageDict->SetAt("MediaBox", pInheritable->Cl one()); 149 pCurPageDict->SetAt("MediaBox", pInheritable->Clone());
150 » » } 150 }
151 » » //2 Resources //required 151 //2 Resources //required
152 » » if(!pCurPageDict->KeyExist("Resources")) 152 if(!pCurPageDict->KeyExist("Resources"))
153 » » { 153 {
154 » » » pInheritable = PageDictGetInheritableTag(pSrcPageDict, " Resources"); 154 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Resources");
155 » » » if(!pInheritable) 155 if(!pInheritable)
156 » » » { 156 {
157 » » » » delete pMapPtrToPtr; 157 delete pMapPtrToPtr;
158 » » » » return FALSE; 158 return FALSE;
159 » » » } 159 }
160 » » » pCurPageDict->SetAt("Resources", pInheritable->Clone()); 160 pCurPageDict->SetAt("Resources", pInheritable->Clone());
161 » » } 161 }
162 » » //3 CropBox //Optional 162 //3 CropBox //Optional
163 » » if(!pCurPageDict->KeyExist("CropBox")) 163 if(!pCurPageDict->KeyExist("CropBox"))
164 » » { 164 {
165 » » » pInheritable = PageDictGetInheritableTag(pSrcPageDict, " CropBox"); 165 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "CropBox");
166 » » » if(pInheritable) 166 if(pInheritable)
167 » » » » pCurPageDict->SetAt("CropBox", pInheritable->Clo ne()); 167 pCurPageDict->SetAt("CropBox", pInheritable->Clone());
168 » » } 168 }
169 » » //4 Rotate //Optional 169 //4 Rotate //Optional
170 » » if(!pCurPageDict->KeyExist("Rotate")) 170 if(!pCurPageDict->KeyExist("Rotate"))
171 » » { 171 {
172 » » » pInheritable = PageDictGetInheritableTag(pSrcPageDict, " Rotate"); 172 pInheritable = PageDictGetInheritableTag(pSrcPageDict, "Rotate");
173 » » » if(pInheritable) 173 if(pInheritable)
174 » » » » pCurPageDict->SetAt("Rotate", pInheritable->Clon e()); 174 pCurPageDict->SetAt("Rotate", pInheritable->Clone());
175 » » } 175 }
176 176
177 » » ///////////////////////////////////////////// 177 /////////////////////////////////////////////
178 » » //Update the reference 178 //Update the reference
179 » » FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum(); 179 FX_DWORD dwOldPageObj = pSrcPageDict->GetObjNum();
180 » » FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum(); 180 FX_DWORD dwNewPageObj = pCurPageDict->GetObjNum();
181 181
182 » » pMapPtrToPtr->SetAt((void*)(uintptr_t)dwOldPageObj, (void*)(uint ptr_t)dwNewPageObj); 182 pMapPtrToPtr->SetAt((void*)(uintptr_t)dwOldPageObj, (void*)(uintptr_t)dw NewPageObj);
183 183
184 » » UpdateReference(pCurPageDict, pDestPDFDoc, pMapPtrToPtr); 184 UpdateReference(pCurPageDict, pDestPDFDoc, pMapPtrToPtr);
185 » » curpage++; 185 curpage++;
186 » } 186 }
187 187
188 » delete pMapPtrToPtr; 188 delete pMapPtrToPtr;
189 » return TRUE; 189 return TRUE;
190 } 190 }
191 191
192 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(CPDF_Dictionary *pDic t, CFX_ByteString nSrctag) 192 CPDF_Object* CPDF_PageOrganizer::PageDictGetInheritableTag(CPDF_Dictionary *pDic t, CFX_ByteString nSrctag)
193 { 193 {
194 » if(!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty()) 194 if(!pDict || !pDict->KeyExist("Type") || nSrctag.IsEmpty())
195 » » return NULL; 195 return NULL;
196 196
197 » CPDF_Object* pType = pDict->GetElement("Type")->GetDirect(); 197 CPDF_Object* pType = pDict->GetElement("Type")->GetDirect();
198 » if(!pType || pType->GetType() != PDFOBJ_NAME)» return NULL; 198 if(!pType || pType->GetType() != PDFOBJ_NAME) return NULL;
199 199
200 » if(pType->GetString().Compare("Page"))» return NULL; 200 if(pType->GetString().Compare("Page")) return NULL;
201 201
202 » if(!pDict->KeyExist("Parent"))» return NULL; 202 if(!pDict->KeyExist("Parent")) return NULL;
203 » CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect(); 203 CPDF_Object* pParent = pDict->GetElement("Parent")->GetDirect();
204 » if(!pParent || pParent->GetType() != PDFOBJ_DICTIONARY)»return NULL; 204 if(!pParent || pParent->GetType() != PDFOBJ_DICTIONARY) return NULL;
205 205
206 » CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent; 206 CPDF_Dictionary* pp = (CPDF_Dictionary*)pParent;
207 207
208 » if(pDict->KeyExist((const char*)nSrctag)) 208 if(pDict->KeyExist((const char*)nSrctag))
209 » » return pDict->GetElement((const char*)nSrctag); 209 return pDict->GetElement((const char*)nSrctag);
210 » while (pp) 210 while (pp)
211 » { 211 {
212 » » if(pp->KeyExist((const char*)nSrctag)) 212 if(pp->KeyExist((const char*)nSrctag))
213 » » » return pp->GetElement((const char*)nSrctag); 213 return pp->GetElement((const char*)nSrctag);
214 » » else if (pp->KeyExist("Parent")) 214 else if (pp->KeyExist("Parent"))
Lei Zhang 2015/07/23 02:01:02 else-if after return here.
Tom Sepez 2015/07/23 16:17:41 Done.
215 » » { 215 {
216 » » » pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDire ct(); 216 pp = (CPDF_Dictionary*)pp->GetElement("Parent")->GetDirect();
217 » » » if (pp->GetType() == PDFOBJ_NULL) break; 217 if (pp->GetType() == PDFOBJ_NULL) break;
218 » » } 218 }
219 » » else break; 219 else break;
220 » } 220 }
221 221
222 » return NULL; 222 return NULL;
223 } 223 }
224 224
225 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object *pObj, CPDF_Document *pD oc, 225 FX_BOOL CPDF_PageOrganizer::UpdateReference(CPDF_Object *pObj, CPDF_Document *pD oc,
226 » » » » » » » » » » CFX_MapPtrToPtr* pMapPtrToPtr) 226 CFX_MapPtrToPtr* pMapPtrToPtr)
227 { 227 {
228 » switch (pObj->GetType()) 228 switch (pObj->GetType())
229 » { 229 {
230 » case PDFOBJ_REFERENCE: 230 case PDFOBJ_REFERENCE:
231 » » { 231 {
232 » » » CPDF_Reference* pReference = (CPDF_Reference*)pObj; 232 CPDF_Reference* pReference = (CPDF_Reference*)pObj;
233 » » » int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReferen ce); 233 int newobjnum = GetNewObjId(pDoc, pMapPtrToPtr, pReference);
234 » » » if (newobjnum == 0) return FALSE; 234 if (newobjnum == 0) return FALSE;
235 » » » pReference->SetRef(pDoc, newobjnum);//, 0); 235 pReference->SetRef(pDoc, newobjnum);//, 0);
236 » » » break; 236 break;
237 » » } 237 }
238 » case PDFOBJ_DICTIONARY: 238 case PDFOBJ_DICTIONARY:
239 » » { 239 {
240 » » » CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj; 240 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pObj;
241 241
242 » » » FX_POSITION pos = pDict->GetStartPos(); 242 FX_POSITION pos = pDict->GetStartPos();
243 » » » while(pos) 243 while(pos)
244 » » » { 244 {
245 » » » » CFX_ByteString key(""); 245 CFX_ByteString key("");
246 » » » » CPDF_Object* pNextObj = pDict->GetNextElement(po s, key); 246 CPDF_Object* pNextObj = pDict->GetNextElement(pos, key);
247 » » » » if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcm p(key, "Prev") || !FXSYS_strcmp(key, "First")) 247 if (!FXSYS_strcmp(key, "Parent") || !FXSYS_strcmp(key, "Prev") | | !FXSYS_strcmp(key, "First"))
248 » » » » » continue; 248 continue;
249 » » » » if(pNextObj) 249 if(pNextObj)
250 » » » » { 250 {
251 » » » » » if(!UpdateReference(pNextObj, pDoc, pMap PtrToPtr)) 251 if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
252 » » » » » » pDict->RemoveAt(key); 252 pDict->RemoveAt(key);
253 » » » » } 253 }
254 » » » » else 254 else
255 » » » » » return FALSE; 255 return FALSE;
256 » » » } 256 }
257 » » » break; 257 break;
258 » » } 258 }
259 » case» PDFOBJ_ARRAY: 259 case PDFOBJ_ARRAY:
260 » » { 260 {
261 » » » CPDF_Array* pArray = (CPDF_Array*)pObj; 261 CPDF_Array* pArray = (CPDF_Array*)pObj;
262 » » » FX_DWORD count = pArray->GetCount(); 262 FX_DWORD count = pArray->GetCount();
263 » » » for(FX_DWORD i = 0; i < count; i ++) 263 for(FX_DWORD i = 0; i < count; i ++)
Lei Zhang 2015/07/23 02:01:02 Check this block against master.
Tom Sepez 2015/07/23 16:17:41 Perhaps your https://pdfium.googlesource.com/pdfi
Lei Zhang 2015/07/23 20:36:18 Right. There's more CFX_MapPtrToPtr usage on XFA s
264 » » » { 264 {
265 » » » » CPDF_Object* pNextObj = pArray->GetElement(i); 265 CPDF_Object* pNextObj = pArray->GetElement(i);
266 » » » » if(pNextObj) 266 if(pNextObj)
267 » » » » { 267 {
268 » » » » » if(!UpdateReference(pNextObj, pDoc, pMap PtrToPtr)) 268 if(!UpdateReference(pNextObj, pDoc, pMapPtrToPtr))
269 » » » » » » return FALSE; 269 return FALSE;
270 » » » » } 270 }
271 » » » » else 271 else
272 » » » » » return FALSE; 272 return FALSE;
273 » » » } 273 }
274 » » » break; 274 break;
275 » » } 275 }
276 » case» PDFOBJ_STREAM: 276 case PDFOBJ_STREAM:
277 » » { 277 {
278 » » » CPDF_Stream* pStream = (CPDF_Stream*)pObj; 278 CPDF_Stream* pStream = (CPDF_Stream*)pObj;
279 » » » CPDF_Dictionary* pDict = pStream->GetDict(); 279 CPDF_Dictionary* pDict = pStream->GetDict();
280 » » » if(pDict) 280 if(pDict)
281 » » » { 281 {
282 » » » » if(!UpdateReference(pDict, pDoc, pMapPtrToPtr)) 282 if(!UpdateReference(pDict, pDoc, pMapPtrToPtr))
283 » » » » » return FALSE; 283 return FALSE;
284 » » » } 284 }
285 » » » else 285 else
286 » » » » return FALSE; 286 return FALSE;
287 » » » break; 287 break;
288 » » } 288 }
289 » default:» break; 289 default: break;
290 » } 290 }
291 291
292 » return TRUE; 292 return TRUE;
293 } 293 }
294 294
295 int» CPDF_PageOrganizer::GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pM apPtrToPtr, 295 int CPDF_PageOrganizer::GetNewObjId(CPDF_Document *pDoc, CFX_MapPtrToPtr* pMapPt rToPtr,
296 » » » » » » » » » CPDF_Ref erence *pRef) 296 CPDF_Reference *pRef)
297 { 297 {
298 » size_t dwObjnum = 0; 298 size_t dwObjnum = 0;
299 » if(!pRef) 299 if(!pRef)
300 » » return 0; 300 return 0;
301 » dwObjnum = pRef->GetRefObjNum(); 301 dwObjnum = pRef->GetRefObjNum();
302 302
303 » size_t dwNewObjNum = 0; 303 size_t dwNewObjNum = 0;
304 304
305 » pMapPtrToPtr->Lookup((void*)dwObjnum, (void*&)dwNewObjNum); 305 pMapPtrToPtr->Lookup((void*)dwObjnum, (void*&)dwNewObjNum);
306 » if(dwNewObjNum) 306 if(dwNewObjNum)
307 » { 307 {
308 » » return (int)dwNewObjNum; 308 return (int)dwNewObjNum;
309 » } 309 }
310 » else 310 else
Lei Zhang 2015/07/23 02:01:02 Also here.
Tom Sepez 2015/07/23 16:17:41 Done.
311 » { 311 {
312 » » CPDF_Object* pDirect = pRef->GetDirect(); 312 CPDF_Object* pDirect = pRef->GetDirect();
313 » » if(!pDirect) 313 if(!pDirect)
314 » » { 314 {
315 » » » return 0; 315 return 0;
316 » » } 316 }
317 317
318 » » CPDF_Object* pClone = pDirect->Clone(); 318 CPDF_Object* pClone = pDirect->Clone();
319 » » if(!pClone) 319 if(!pClone)
320 » » { 320 {
321 » » » return 0; 321 return 0;
322 » » } 322 }
323 323
324 » » if(pClone->GetType() == PDFOBJ_DICTIONARY) 324 if(pClone->GetType() == PDFOBJ_DICTIONARY)
325 » » { 325 {
326 » » » CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone; 326 CPDF_Dictionary* pDictClone = (CPDF_Dictionary*)pClone;
327 » » » if(pDictClone->KeyExist("Type")) 327 if(pDictClone->KeyExist("Type"))
328 » » » { 328 {
329 » » » » CFX_ByteString strType = pDictClone->GetString(" Type"); 329 CFX_ByteString strType = pDictClone->GetString("Type");
330 » » » » if(!FXSYS_stricmp(strType, "Pages")) 330 if(!FXSYS_stricmp(strType, "Pages"))
331 » » » » { 331 {
332 » » » » » pDictClone->Release(); 332 pDictClone->Release();
333 » » » » » return 4; 333 return 4;
334 » » » » } 334 }
335 » » » » else if(!FXSYS_stricmp(strType, "Page")) 335 else if(!FXSYS_stricmp(strType, "Page"))
336 » » » » { 336 {
337 » » » » » pDictClone->Release(); 337 pDictClone->Release();
338 » » » » » return 0; 338 return 0;
339 » » » » } 339 }
340 » » » } 340 }
341 » » } 341 }
342 » » dwNewObjNum = pDoc->AddIndirectObject(pClone);//, onum, gnum); 342 dwNewObjNum = pDoc->AddIndirectObject(pClone);//, onum, gnum);
343 » » pMapPtrToPtr->SetAt((void*)dwObjnum, (void*)dwNewObjNum); 343 pMapPtrToPtr->SetAt((void*)dwObjnum, (void*)dwNewObjNum);
344 344
345 » » if(!UpdateReference(pClone, pDoc, pMapPtrToPtr)) 345 if(!UpdateReference(pClone, pDoc, pMapPtrToPtr))
346 » » { 346 {
347 » » » pClone->Release(); 347 pClone->Release();
348 » » » return 0; 348 return 0;
349 » » } 349 }
350 » » return (int)dwNewObjNum; 350 return (int)dwNewObjNum;
351 » } 351 }
352 » return 0; 352 return 0;
353 } 353 }
354 354
355 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, CFX_WordArray* pageAr ray,int nCount) 355 FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring, CFX_WordArray* pageAr ray,int nCount)
356 { 356 {
357 357 if(rangstring.GetLength() != 0)
358 » if(rangstring.GetLength() != 0) 358 {
359 » { 359 rangstring.Remove(' ');
360 » » rangstring.Remove(' '); 360 int nLength = rangstring.GetLength();
361 » » int nLength = rangstring.GetLength(); 361 CFX_ByteString cbCompareString("0123456789-,");
362 » » CFX_ByteString cbCompareString("0123456789-,"); 362 for(int i=0; i<nLength; i++)
363 » » for(int i=0; i<nLength; i++) 363 {
364 » » { 364 if(cbCompareString.Find(rangstring[i]) == -1)
365 » » » if(cbCompareString.Find(rangstring[i]) == -1) 365 return FALSE;
366 » » » » return FALSE; 366 }
367 » » } 367 CFX_ByteString cbMidRange;
368 » » CFX_ByteString cbMidRange; 368 int nStringFrom = 0;
369 » » int nStringFrom = 0; 369 int nStringTo=0;
370 » » int nStringTo=0; 370 while(nStringTo < nLength)
371 » » while(nStringTo < nLength) 371 {
372 » » { 372 nStringTo = rangstring.Find(',',nStringFrom);
373 » » » nStringTo = rangstring.Find(',',nStringFrom); 373 if(nStringTo == -1)
374 » » » if(nStringTo == -1) 374 {
375 » » » { 375 nStringTo = nLength;
376 » » » » nStringTo = nLength; 376 }
377 » » » } 377 cbMidRange = rangstring.Mid(nStringFrom,nStringTo-nStringFrom);
378 » » » cbMidRange = rangstring.Mid(nStringFrom,nStringTo-nStrin gFrom); 378
379 379 int nMid = cbMidRange.Find('-');
380 » » » int nMid = cbMidRange.Find('-'); 380 if(nMid == -1)
381 » » » if(nMid == -1) 381 {
382 » » » { 382 long lPageNum = atol(cbMidRange);
383 » » » » long lPageNum = atol(cbMidRange); 383 if(lPageNum <= 0 || lPageNum > nCount)
384 » » » » if(lPageNum <= 0 || lPageNum > nCount) 384 return FALSE;
385 » » » » » return FALSE; 385 pageArray->Add((FX_WORD)lPageNum);
386 » » » » pageArray->Add((FX_WORD)lPageNum); 386 }
387 » » » } 387 else
388 » » » else 388 {
389 » » » { 389 int nStartPageNum = atol(cbMidRange.Mid(0,nMid));
390 » » » » int nStartPageNum = atol(cbMidRange.Mid(0,nMid)) ; 390 if (nStartPageNum ==0)
391 » » » » if (nStartPageNum ==0) 391 {
392 » » » » { 392 return FALSE;
393 » » » » » return FALSE; 393 }
394 » » » » } 394
395 395
396 396 nMid = nMid+1;
397 » » » » nMid = nMid+1; 397 int nEnd = cbMidRange.GetLength()-nMid;
398 » » » » int nEnd = cbMidRange.GetLength()-nMid; 398
399 399 if(nEnd ==0)return FALSE;
400 » » » » if(nEnd ==0)return FALSE; 400
401 401 // int nEndPageNum = (nEnd == 0)?nCount:atol(cbMidR ange.Mid(nMid,nEnd));
402 » » » » //» » » » int nEndPageNum = (nEnd == 0)?nCount:atol(cbMidRange.Mid(nMid,nEnd)); 402 int nEndPageNum = atol(cbMidRange.Mid(nMid,nEnd));
403 » » » » int nEndPageNum = atol(cbMidRange.Mid(nMid,nEnd) ); 403
404 404 if(nStartPageNum < 0 ||nStartPageNum >nEndPageNum|| nEndPageNum > nCount)
405 » » » » if(nStartPageNum < 0 ||nStartPageNum >nEndPageNu m|| nEndPageNum > nCount) 405 {
406 » » » » { 406 return FALSE;
407 » » » » » return FALSE; 407 }
408 » » » » } 408 else
Lei Zhang 2015/07/23 02:01:02 And here.
Tom Sepez 2015/07/23 16:17:41 Done.
409 » » » » else 409 {
410 » » » » { 410 for(int nIndex=nStartPageNum; nIndex <= nEndPageNum; nIndex ++)
411 » » » » » for(int nIndex=nStartPageNum; nIndex <= nEndPageNum; nIndex ++) 411 pageArray->Add(nIndex);
412 » » » » » » pageArray->Add(nIndex); 412 }
413 » » » » } 413 }
414 » » » } 414 nStringFrom = nStringTo +1;
415 » » » nStringFrom = nStringTo +1; 415 }
416 » » } 416 }
417 » } 417 return TRUE;
418 » return TRUE;
419 } 418 }
420 419
421 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMEN T src_doc, 420 DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMEN T src_doc,
422 » » » » » » » » » » » FPDF_BYTESTRING pagerange, int index) 421 FPDF_BYTESTRING pagerange, int inde x)
423 { 422 {
424 » if(dest_doc == NULL || src_doc == NULL ) 423 if(dest_doc == NULL || src_doc == NULL )
425 » » return FALSE; 424 return FALSE;
426 » CFX_WordArray pageArray; 425 CFX_WordArray pageArray;
427 » CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc; 426 CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
428 » CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc(); 427 CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
429 » int nCount = pSrcPDFDoc->GetPageCount(); 428 int nCount = pSrcPDFDoc->GetPageCount();
430 » if(pagerange) 429 if(pagerange)
431 » { 430 {
432 » » if(ParserPageRangeString(pagerange,&pageArray,nCount) == FALSE) 431 if(ParserPageRangeString(pagerange,&pageArray,nCount) == FALSE)
433 » » » return FALSE; 432 return FALSE;
434 » } 433 }
435 » else 434 else
436 » { 435 {
437 » » for(int i=1; i<=nCount; i++) 436 for(int i=1; i<=nCount; i++)
438 » » { 437 {
439 » » » pageArray.Add(i); 438 pageArray.Add(i);
440 » » } 439 }
441 » } 440 }
442 441
443 » CPDFXFA_Document* pDestDoc = (CPDFXFA_Document*)dest_doc; 442 CPDFXFA_Document* pDestDoc = (CPDFXFA_Document*)dest_doc;
444 » CPDF_Document* pDestPDFDoc = pDestDoc->GetPDFDoc(); 443 CPDF_Document* pDestPDFDoc = pDestDoc->GetPDFDoc();
445 » CPDF_PageOrganizer pageOrg; 444 CPDF_PageOrganizer pageOrg;
446 445
447 » pageOrg.PDFDocInit(pDestPDFDoc,pSrcPDFDoc); 446 pageOrg.PDFDocInit(pDestPDFDoc,pSrcPDFDoc);
448 447
449 » if(pageOrg.ExportPage(pSrcPDFDoc,&pageArray,pDestPDFDoc,index)) 448 if(pageOrg.ExportPage(pSrcPDFDoc,&pageArray,pDestPDFDoc,index))
450 » » return TRUE; 449 return TRUE;
451 » return FALSE; 450 return FALSE;
452 } 451 }
453 452
454 DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, F PDF_DOCUMENT src_doc) 453 DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, F PDF_DOCUMENT src_doc)
455 { 454 {
456 » if(src_doc == NULL || dest_doc == NULL) 455 if(src_doc == NULL || dest_doc == NULL)
457 » » return false; 456 return false;
458 » CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc; 457 CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
459 » CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc(); 458 CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
460 » CPDF_Dictionary* pSrcDict = pSrcPDFDoc->GetRoot(); 459 CPDF_Dictionary* pSrcDict = pSrcPDFDoc->GetRoot();
461 » pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences")); 460 pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));
462 » if(!pSrcDict) 461 if(!pSrcDict)
463 » » return FALSE; 462 return FALSE;
464 » CPDFXFA_Document* pDstDoc = (CPDFXFA_Document*)dest_doc; 463 CPDFXFA_Document* pDstDoc = (CPDFXFA_Document*)dest_doc;
465 » CPDF_Document* pDstPDFDoc = pDstDoc->GetPDFDoc(); 464 CPDF_Document* pDstPDFDoc = pDstDoc->GetPDFDoc();
466 » CPDF_Dictionary* pDstDict = pDstPDFDoc->GetRoot(); 465 CPDF_Dictionary* pDstDict = pDstPDFDoc->GetRoot();
467 » if(!pDstDict) 466 if(!pDstDict)
468 » » return FALSE; 467 return FALSE;
469 » pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE)); 468 pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
470 » return TRUE; 469 return TRUE;
471 } 470 }
472 471
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698