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

Side by Side Diff: core/fpdfdoc/cpdf_interform.cpp

Issue 2190983002: Splitting fpdfdoc/doc_* part III. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@fpdf_doc_IV
Patch Set: Rebase to master Created 4 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 <vector> 7 #include <vector>
8 8
9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
9 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
10 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" 11 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
11 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" 12 #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
15 #include "core/fpdfdoc/include/cpdf_filespec.h" 16 #include "core/fpdfdoc/include/cpdf_filespec.h"
16 #include "core/fpdfdoc/include/cpdf_formcontrol.h" 17 #include "core/fpdfdoc/include/cpdf_formcontrol.h"
17 #include "core/fpdfdoc/include/cpdf_interform.h" 18 #include "core/fpdfdoc/include/cpdf_interform.h"
18 #include "core/fpdfdoc/doc_utils.h" 19 #include "core/fxge/include/fx_font.h"
19 #include "third_party/base/stl_util.h" 20 #include "third_party/base/stl_util.h"
20 21
21 namespace { 22 namespace {
22 23
23 const int nMaxRecursion = 32; 24 const int nMaxRecursion = 32;
24 25
25 const struct SupportFieldEncoding { 26 const struct SupportFieldEncoding {
26 const FX_CHAR* m_name; 27 const FX_CHAR* m_name;
27 uint16_t m_codePage; 28 uint16_t m_codePage;
28 } g_fieldEncoding[] = { 29 } g_fieldEncoding[] = {
29 {"BigFive", 950}, 30 {"BigFive", 950},
30 {"GBK", 936}, 31 {"GBK", 936},
31 {"Shift-JIS", 932}, 32 {"Shift-JIS", 932},
32 {"UHC", 949}, 33 {"UHC", 949},
33 }; 34 };
34 35
35 CFX_WideString FPDFDOC_FDF_GetFieldValue(const CPDF_Dictionary& pFieldDict, 36 CFX_WideString GetFieldValue(const CPDF_Dictionary& pFieldDict,
36 const CFX_ByteString& bsEncoding) { 37 const CFX_ByteString& bsEncoding) {
37 const CFX_ByteString csBValue = pFieldDict.GetStringBy("V"); 38 const CFX_ByteString csBValue = pFieldDict.GetStringBy("V");
38 for (const auto& encoding : g_fieldEncoding) { 39 for (const auto& encoding : g_fieldEncoding) {
39 if (bsEncoding == encoding.m_name) 40 if (bsEncoding == encoding.m_name)
40 return CFX_WideString::FromCodePage(csBValue.AsStringC(), 41 return CFX_WideString::FromCodePage(csBValue.AsStringC(),
41 encoding.m_codePage); 42 encoding.m_codePage);
42 } 43 }
43 CFX_ByteString csTemp = csBValue.Left(2); 44 CFX_ByteString csTemp = csBValue.Left(2);
44 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") 45 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF")
45 return PDF_DecodeText(csBValue); 46 return PDF_DecodeText(csBValue);
46 return CFX_WideString::FromLocal(csBValue.AsStringC()); 47 return CFX_WideString::FromLocal(csBValue.AsStringC());
47 } 48 }
48 49
49 } // namespace 50 void AddFont(CPDF_Dictionary*& pFormDict,
51 CPDF_Document* pDocument,
52 const CPDF_Font* pFont,
53 CFX_ByteString& csNameTag);
54
55 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
56 if (!pDocument)
57 return;
58
59 if (!pFormDict) {
60 pFormDict = new CPDF_Dictionary;
61 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict);
62 CPDF_Dictionary* pRoot = pDocument->GetRoot();
63 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum);
64 }
65
66 CFX_ByteString csDA;
67 if (!pFormDict->KeyExist("DR")) {
68 CFX_ByteString csBaseName;
69 CFX_ByteString csDefault;
70 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
71 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
72 if (pFont) {
73 AddFont(pFormDict, pDocument, pFont, csBaseName);
74 csDefault = csBaseName;
75 }
76 if (charSet != FXFONT_ANSI_CHARSET) {
77 CFX_ByteString csFontName =
78 CPDF_InterForm::GetNativeFont(charSet, nullptr);
79 if (!pFont || csFontName != "Helvetica") {
80 pFont = CPDF_InterForm::AddNativeFont(pDocument);
81 if (pFont) {
82 csBaseName = "";
83 AddFont(pFormDict, pDocument, pFont, csBaseName);
84 csDefault = csBaseName;
85 }
86 }
87 }
88 if (pFont)
89 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf";
90 }
91 if (!csDA.IsEmpty())
92 csDA += " ";
93
94 csDA += "0 g";
95 if (!pFormDict->KeyExist("DA"))
96 pFormDict->SetAtString("DA", csDA);
97 }
98
99 uint32_t CountFonts(CPDF_Dictionary* pFormDict) {
100 if (!pFormDict)
101 return 0;
102
103 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
104 if (!pDR)
105 return 0;
106
107 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
108 if (!pFonts)
109 return 0;
110
111 uint32_t dwCount = 0;
112 for (const auto& it : *pFonts) {
113 CPDF_Object* pObj = it.second;
114 if (!pObj)
115 continue;
116
117 if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) {
118 if (pDirect->GetStringBy("Type") == "Font")
119 dwCount++;
120 }
121 }
122 return dwCount;
123 }
124
125 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict,
126 CPDF_Document* pDocument,
127 uint32_t index,
128 CFX_ByteString& csNameTag) {
129 if (!pFormDict)
130 return nullptr;
131
132 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
133 if (!pDR)
134 return nullptr;
135
136 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
137 if (!pFonts)
138 return nullptr;
139
140 uint32_t dwCount = 0;
141 for (const auto& it : *pFonts) {
142 const CFX_ByteString& csKey = it.first;
143 CPDF_Object* pObj = it.second;
144 if (!pObj)
145 continue;
146
147 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
148 if (!pElement)
149 continue;
150 if (pElement->GetStringBy("Type") != "Font")
151 continue;
152 if (dwCount == index) {
153 csNameTag = csKey;
154 return pDocument->LoadFont(pElement);
155 }
156 dwCount++;
157 }
158 return nullptr;
159 }
160
161 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict,
162 CPDF_Document* pDocument,
163 CFX_ByteString csNameTag) {
164 CFX_ByteString csAlias = PDF_NameDecode(csNameTag);
165 if (!pFormDict || csAlias.IsEmpty())
166 return nullptr;
167
168 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
169 if (!pDR)
170 return nullptr;
171
172 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
173 if (!pFonts)
174 return nullptr;
175
176 CPDF_Dictionary* pElement = pFonts->GetDictBy(csAlias);
177 if (!pElement)
178 return nullptr;
179
180 if (pElement->GetStringBy("Type") == "Font")
181 return pDocument->LoadFont(pElement);
182 return nullptr;
183 }
184
185 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict,
186 CPDF_Document* pDocument,
187 CFX_ByteString csFontName,
188 CFX_ByteString& csNameTag) {
189 if (!pFormDict || csFontName.IsEmpty())
190 return nullptr;
191
192 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
193 if (!pDR)
194 return nullptr;
195
196 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
197 if (!pFonts)
198 return nullptr;
199
200 for (const auto& it : *pFonts) {
201 const CFX_ByteString& csKey = it.first;
202 CPDF_Object* pObj = it.second;
203 if (!pObj)
204 continue;
205
206 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
207 if (!pElement)
208 continue;
209 if (pElement->GetStringBy("Type") != "Font")
210 continue;
211
212 CPDF_Font* pFind = pDocument->LoadFont(pElement);
213 if (!pFind)
214 continue;
215
216 CFX_ByteString csBaseFont;
217 csBaseFont = pFind->GetBaseFont();
218 csBaseFont.Remove(' ');
219 if (csBaseFont == csFontName) {
220 csNameTag = csKey;
221 return pFind;
222 }
223 }
224 return nullptr;
225 }
226
227 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict,
228 CPDF_Document* pDocument,
229 uint8_t charSet,
230 CFX_ByteString& csNameTag) {
231 if (!pFormDict)
232 return nullptr;
233
234 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
235 if (!pDR)
236 return nullptr;
237
238 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
239 if (!pFonts)
240 return nullptr;
241
242 for (const auto& it : *pFonts) {
243 const CFX_ByteString& csKey = it.first;
244 CPDF_Object* pObj = it.second;
245 if (!pObj)
246 continue;
247
248 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
249 if (!pElement)
250 continue;
251 if (pElement->GetStringBy("Type") != "Font")
252 continue;
253 CPDF_Font* pFind = pDocument->LoadFont(pElement);
254 if (!pFind)
255 continue;
256
257 CFX_SubstFont* pSubst = pFind->GetSubstFont();
258 if (!pSubst)
259 continue;
260
261 if (pSubst->m_Charset == (int)charSet) {
262 csNameTag = csKey;
263 return pFind;
264 }
265 }
266 return nullptr;
267 }
268
269 CPDF_Font* GetDefaultFont(CPDF_Dictionary* pFormDict,
270 CPDF_Document* pDocument) {
271 if (!pFormDict)
272 return nullptr;
273
274 CPDF_DefaultAppearance cDA(pFormDict->GetStringBy("DA"));
275 CFX_ByteString csFontNameTag;
276 FX_FLOAT fFontSize;
277 cDA.GetFont(csFontNameTag, fFontSize);
278 return GetFont(pFormDict, pDocument, csFontNameTag);
279 }
280
281 FX_BOOL FindFont(CPDF_Dictionary* pFormDict,
282 const CPDF_Font* pFont,
283 CFX_ByteString& csNameTag) {
284 if (!pFormDict || !pFont)
285 return FALSE;
286
287 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
288 if (!pDR)
289 return FALSE;
290
291 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
292 if (!pFonts)
293 return FALSE;
294
295 for (const auto& it : *pFonts) {
296 const CFX_ByteString& csKey = it.first;
297 CPDF_Object* pObj = it.second;
298 if (!pObj)
299 continue;
300
301 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
302 if (!pElement)
303 continue;
304 if (pElement->GetStringBy("Type") != "Font")
305 continue;
306 if (pFont->GetFontDict() == pElement) {
307 csNameTag = csKey;
308 return TRUE;
309 }
310 }
311 return FALSE;
312 }
313
314 CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict,
315 CPDF_Document* pDocument,
316 CFX_ByteString& csNameTag) {
317 csNameTag.clear();
318 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
319 CPDF_Font* pFont = GetDefaultFont(pFormDict, pDocument);
320 if (pFont) {
321 CFX_SubstFont* pSubst = pFont->GetSubstFont();
322 if (pSubst && pSubst->m_Charset == (int)charSet) {
323 FindFont(pFormDict, pFont, csNameTag);
324 return pFont;
325 }
326 }
327 return GetNativeFont(pFormDict, pDocument, charSet, csNameTag);
328 }
329
330 FX_BOOL FindFont(CPDF_Dictionary* pFormDict,
331 CPDF_Document* pDocument,
332 CFX_ByteString csFontName,
333 CPDF_Font*& pFont,
334 CFX_ByteString& csNameTag) {
335 if (!pFormDict)
336 return FALSE;
337
338 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
339 if (!pDR)
340 return FALSE;
341
342 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
343 if (!pFonts)
344 return FALSE;
345 if (csFontName.GetLength() > 0)
346 csFontName.Remove(' ');
347
348 for (const auto& it : *pFonts) {
349 const CFX_ByteString& csKey = it.first;
350 CPDF_Object* pObj = it.second;
351 if (!pObj)
352 continue;
353
354 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
355 if (!pElement)
356 continue;
357 if (pElement->GetStringBy("Type") != "Font")
358 continue;
359
360 pFont = pDocument->LoadFont(pElement);
361 if (!pFont)
362 continue;
363
364 CFX_ByteString csBaseFont;
365 csBaseFont = pFont->GetBaseFont();
366 csBaseFont.Remove(' ');
367 if (csBaseFont == csFontName) {
368 csNameTag = csKey;
369 return TRUE;
370 }
371 }
372 return FALSE;
373 }
374
375 void AddFont(CPDF_Dictionary*& pFormDict,
376 CPDF_Document* pDocument,
377 const CPDF_Font* pFont,
378 CFX_ByteString& csNameTag) {
379 if (!pFont)
380 return;
381 if (!pFormDict)
382 InitDict(pFormDict, pDocument);
383
384 CFX_ByteString csTag;
385 if (FindFont(pFormDict, pFont, csTag)) {
386 csNameTag = csTag;
387 return;
388 }
389 if (!pFormDict)
390 InitDict(pFormDict, pDocument);
391
392 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
393 if (!pDR) {
394 pDR = new CPDF_Dictionary;
395 pFormDict->SetAt("DR", pDR);
396 }
397 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
398 if (!pFonts) {
399 pFonts = new CPDF_Dictionary;
400 pDR->SetAt("Font", pFonts);
401 }
402 if (csNameTag.IsEmpty())
403 csNameTag = pFont->GetBaseFont();
404
405 csNameTag.Remove(' ');
406 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
407 csNameTag.c_str());
408 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict());
409 }
410
411 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict,
412 CPDF_Document* pDocument,
413 uint8_t charSet,
414 CFX_ByteString& csNameTag) {
415 if (!pFormDict)
416 InitDict(pFormDict, pDocument);
417
418 CFX_ByteString csTemp;
419 CPDF_Font* pFont = GetNativeFont(pFormDict, pDocument, charSet, csTemp);
420 if (pFont) {
421 csNameTag = csTemp;
422 return pFont;
423 }
424 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet);
425 if (!csFontName.IsEmpty() &&
426 FindFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) {
427 return pFont;
428 }
429 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument);
430 if (pFont)
431 AddFont(pFormDict, pDocument, pFont, csNameTag);
432
433 return pFont;
434 }
435
436 void RemoveFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) {
437 if (!pFormDict || !pFont)
438 return;
439
440 CFX_ByteString csTag;
441 if (!FindFont(pFormDict, pFont, csTag))
442 return;
443
444 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
445 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
446 pFonts->RemoveAt(csTag);
447 }
448
449 void RemoveFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) {
450 if (!pFormDict || csNameTag.IsEmpty())
451 return;
452
453 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
454 if (!pDR)
455 return;
456
457 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
458 if (!pFonts)
459 return;
460
461 pFonts->RemoveAt(csNameTag);
462 }
50 463
51 class CFieldNameExtractor { 464 class CFieldNameExtractor {
52 public: 465 public:
53 explicit CFieldNameExtractor(const CFX_WideString& full_name) 466 explicit CFieldNameExtractor(const CFX_WideString& full_name)
54 : m_FullName(full_name) { 467 : m_FullName(full_name) {
55 m_pCur = m_FullName.c_str(); 468 m_pCur = m_FullName.c_str();
56 m_pEnd = m_pCur + m_FullName.GetLength(); 469 m_pEnd = m_pCur + m_FullName.GetLength();
57 } 470 }
58 471
59 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { 472 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) {
60 pSubName = m_pCur; 473 pSubName = m_pCur;
61 while (m_pCur < m_pEnd && m_pCur[0] != L'.') { 474 while (m_pCur < m_pEnd && m_pCur[0] != L'.')
62 m_pCur++; 475 m_pCur++;
63 } 476
64 size = (FX_STRSIZE)(m_pCur - pSubName); 477 size = (FX_STRSIZE)(m_pCur - pSubName);
65 if (m_pCur < m_pEnd && m_pCur[0] == L'.') { 478 if (m_pCur < m_pEnd && m_pCur[0] == L'.')
66 m_pCur++; 479 m_pCur++;
67 }
68 } 480 }
69 481
70 protected: 482 protected:
71 CFX_WideString m_FullName; 483 CFX_WideString m_FullName;
72 const FX_WCHAR* m_pCur; 484 const FX_WCHAR* m_pCur;
73 const FX_WCHAR* m_pEnd; 485 const FX_WCHAR* m_pEnd;
74 }; 486 };
75 487
488 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
489 FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) {
490 PDF_FONTDATA fd;
491 memset(&fd, 0, sizeof(PDF_FONTDATA));
492 HDC hDC = ::GetDC(nullptr);
493 EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd,
494 0);
495 ::ReleaseDC(nullptr, hDC);
496 if (fd.bFind)
497 memcpy(&lf, &fd.lf, sizeof(LOGFONTA));
498
499 return fd.bFind;
500 }
501
502 FX_BOOL RetrieveSpecificFont(uint8_t charSet,
503 uint8_t pitchAndFamily,
504 LPCSTR pcsFontName,
505 LOGFONTA& lf) {
506 memset(&lf, 0, sizeof(LOGFONTA));
507 lf.lfCharSet = charSet;
508 lf.lfPitchAndFamily = pitchAndFamily;
509 if (pcsFontName) {
510 // TODO(dsinclair): Should this be strncpy?
511 strcpy(lf.lfFaceName, pcsFontName);
512 }
513 return RetrieveSpecificFont(lf);
514 }
515 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
516
517 } // namespace
518
76 class CFieldTree { 519 class CFieldTree {
77 public: 520 public:
78 struct _Node { 521 struct Node {
79 _Node* parent; 522 Node* parent;
80 CFX_ArrayTemplate<_Node*> children; 523 CFX_ArrayTemplate<Node*> children;
81 CFX_WideString short_name; 524 CFX_WideString short_name;
82 CPDF_FormField* field_ptr; 525 CPDF_FormField* field_ptr;
83 int CountFields(int nLevel = 0) { 526 int CountFields(int nLevel = 0) {
84 if (nLevel > nMaxRecursion) { 527 if (nLevel > nMaxRecursion)
85 return 0; 528 return 0;
86 } 529 if (field_ptr)
87 if (field_ptr) {
88 return 1; 530 return 1;
89 } 531
90 int count = 0; 532 int count = 0;
91 for (int i = 0; i < children.GetSize(); i++) { 533 for (int i = 0; i < children.GetSize(); i++)
92 count += children.GetAt(i)->CountFields(nLevel + 1); 534 count += children.GetAt(i)->CountFields(nLevel + 1);
93 }
94 return count; 535 return count;
95 } 536 }
537
96 CPDF_FormField* GetField(int* fields_to_go) { 538 CPDF_FormField* GetField(int* fields_to_go) {
97 if (field_ptr) { 539 if (field_ptr) {
98 if (*fields_to_go == 0) { 540 if (*fields_to_go == 0)
99 return field_ptr; 541 return field_ptr;
100 } 542
101 --*fields_to_go; 543 --*fields_to_go;
102 return nullptr; 544 return nullptr;
103 } 545 }
104 for (int i = 0; i < children.GetSize(); i++) { 546 for (int i = 0; i < children.GetSize(); i++) {
105 if (CPDF_FormField* pField = children.GetAt(i)->GetField(fields_to_go)) 547 if (CPDF_FormField* pField = children.GetAt(i)->GetField(fields_to_go))
106 return pField; 548 return pField;
107 } 549 }
108 return nullptr; 550 return nullptr;
109 } 551 }
552
110 CPDF_FormField* GetField(int index) { 553 CPDF_FormField* GetField(int index) {
111 int fields_to_go = index; 554 int fields_to_go = index;
112 return GetField(&fields_to_go); 555 return GetField(&fields_to_go);
113 } 556 }
114 }; 557 };
558
115 CFieldTree(); 559 CFieldTree();
116 ~CFieldTree(); 560 ~CFieldTree();
561
117 void SetField(const CFX_WideString& full_name, CPDF_FormField* field_ptr); 562 void SetField(const CFX_WideString& full_name, CPDF_FormField* field_ptr);
118 CPDF_FormField* GetField(const CFX_WideString& full_name); 563 CPDF_FormField* GetField(const CFX_WideString& full_name);
119 CPDF_FormField* RemoveField(const CFX_WideString& full_name); 564 CPDF_FormField* RemoveField(const CFX_WideString& full_name);
120 void RemoveAll(); 565 void RemoveAll();
121 _Node* FindNode(const CFX_WideString& full_name); 566
122 _Node* AddChild(_Node* pParent, 567 Node* FindNode(const CFX_WideString& full_name);
123 const CFX_WideString& short_name, 568 Node* AddChild(Node* pParent,
124 CPDF_FormField* field_ptr); 569 const CFX_WideString& short_name,
125 void RemoveNode(_Node* pNode, int nLevel = 0); 570 CPDF_FormField* field_ptr);
126 _Node* _Lookup(_Node* pParent, const CFX_WideString& short_name); 571 void RemoveNode(Node* pNode, int nLevel = 0);
127 _Node m_Root; 572
573 Node* Lookup(Node* pParent, const CFX_WideString& short_name);
574
575 Node m_Root;
128 }; 576 };
577
129 CFieldTree::CFieldTree() { 578 CFieldTree::CFieldTree() {
130 m_Root.parent = nullptr; 579 m_Root.parent = nullptr;
131 m_Root.field_ptr = nullptr; 580 m_Root.field_ptr = nullptr;
132 } 581 }
582
133 CFieldTree::~CFieldTree() { 583 CFieldTree::~CFieldTree() {
134 RemoveAll(); 584 RemoveAll();
135 } 585 }
136 CFieldTree::_Node* CFieldTree::AddChild(_Node* pParent, 586
137 const CFX_WideString& short_name, 587 CFieldTree::Node* CFieldTree::AddChild(Node* pParent,
138 CPDF_FormField* field_ptr) { 588 const CFX_WideString& short_name,
139 if (!pParent) { 589 CPDF_FormField* field_ptr) {
590 if (!pParent)
140 return nullptr; 591 return nullptr;
141 } 592
142 _Node* pNode = new _Node; 593 Node* pNode = new Node;
143 pNode->parent = pParent; 594 pNode->parent = pParent;
144 pNode->short_name = short_name; 595 pNode->short_name = short_name;
145 pNode->field_ptr = field_ptr; 596 pNode->field_ptr = field_ptr;
146 pParent->children.Add(pNode); 597 pParent->children.Add(pNode);
147 return pNode; 598 return pNode;
148 } 599 }
149 void CFieldTree::RemoveNode(_Node* pNode, int nLevel) { 600
150 if (!pNode) { 601 void CFieldTree::RemoveNode(Node* pNode, int nLevel) {
602 if (!pNode)
151 return; 603 return;
152 }
153 if (nLevel <= nMaxRecursion) { 604 if (nLevel <= nMaxRecursion) {
154 for (int i = 0; i < pNode->children.GetSize(); i++) { 605 for (int i = 0; i < pNode->children.GetSize(); i++)
155 RemoveNode(pNode->children[i], nLevel + 1); 606 RemoveNode(pNode->children[i], nLevel + 1);
156 }
157 } 607 }
158 delete pNode; 608 delete pNode;
159 } 609 }
160 CFieldTree::_Node* CFieldTree::_Lookup(_Node* pParent, 610
161 const CFX_WideString& short_name) { 611 CFieldTree::Node* CFieldTree::Lookup(Node* pParent,
162 if (!pParent) { 612 const CFX_WideString& short_name) {
613 if (!pParent)
163 return nullptr; 614 return nullptr;
164 } 615
165 for (int i = 0; i < pParent->children.GetSize(); i++) { 616 for (int i = 0; i < pParent->children.GetSize(); i++) {
166 _Node* pNode = pParent->children[i]; 617 Node* pNode = pParent->children[i];
167 if (pNode->short_name.GetLength() == short_name.GetLength() && 618 if (pNode->short_name.GetLength() == short_name.GetLength() &&
168 FXSYS_memcmp(pNode->short_name.c_str(), short_name.c_str(), 619 FXSYS_memcmp(pNode->short_name.c_str(), short_name.c_str(),
169 short_name.GetLength() * sizeof(FX_WCHAR)) == 0) { 620 short_name.GetLength() * sizeof(FX_WCHAR)) == 0) {
170 return pNode; 621 return pNode;
171 } 622 }
172 } 623 }
173 return nullptr; 624 return nullptr;
174 } 625 }
626
175 void CFieldTree::RemoveAll() { 627 void CFieldTree::RemoveAll() {
176 for (int i = 0; i < m_Root.children.GetSize(); i++) { 628 for (int i = 0; i < m_Root.children.GetSize(); i++)
177 RemoveNode(m_Root.children[i]); 629 RemoveNode(m_Root.children[i]);
178 }
179 } 630 }
631
180 void CFieldTree::SetField(const CFX_WideString& full_name, 632 void CFieldTree::SetField(const CFX_WideString& full_name,
181 CPDF_FormField* field_ptr) { 633 CPDF_FormField* field_ptr) {
182 if (full_name == L"") { 634 if (full_name == L"")
183 return; 635 return;
184 } 636
185 CFieldNameExtractor name_extractor(full_name); 637 CFieldNameExtractor name_extractor(full_name);
186 const FX_WCHAR* pName; 638 const FX_WCHAR* pName;
187 FX_STRSIZE nLength; 639 FX_STRSIZE nLength;
188 name_extractor.GetNext(pName, nLength); 640 name_extractor.GetNext(pName, nLength);
189 _Node *pNode = &m_Root, *pLast = nullptr; 641 Node* pNode = &m_Root;
642 Node* pLast = nullptr;
190 while (nLength > 0) { 643 while (nLength > 0) {
191 pLast = pNode; 644 pLast = pNode;
192 CFX_WideString name = CFX_WideString(pName, nLength); 645 CFX_WideString name = CFX_WideString(pName, nLength);
193 pNode = _Lookup(pLast, name); 646 pNode = Lookup(pLast, name);
194 if (!pNode) { 647 if (!pNode)
195 pNode = AddChild(pLast, name, nullptr); 648 pNode = AddChild(pLast, name, nullptr);
196 } 649
197 name_extractor.GetNext(pName, nLength); 650 name_extractor.GetNext(pName, nLength);
198 } 651 }
199 if (pNode != &m_Root) { 652 if (pNode != &m_Root)
200 pNode->field_ptr = field_ptr; 653 pNode->field_ptr = field_ptr;
201 }
202 } 654 }
655
203 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) { 656 CPDF_FormField* CFieldTree::GetField(const CFX_WideString& full_name) {
204 if (full_name == L"") { 657 if (full_name == L"")
205 return nullptr; 658 return nullptr;
206 } 659
207 CFieldNameExtractor name_extractor(full_name); 660 CFieldNameExtractor name_extractor(full_name);
208 const FX_WCHAR* pName; 661 const FX_WCHAR* pName;
209 FX_STRSIZE nLength; 662 FX_STRSIZE nLength;
210 name_extractor.GetNext(pName, nLength); 663 name_extractor.GetNext(pName, nLength);
211 _Node *pNode = &m_Root, *pLast = nullptr; 664 Node* pNode = &m_Root;
665 Node* pLast = nullptr;
212 while (nLength > 0 && pNode) { 666 while (nLength > 0 && pNode) {
213 pLast = pNode; 667 pLast = pNode;
214 CFX_WideString name = CFX_WideString(pName, nLength); 668 CFX_WideString name = CFX_WideString(pName, nLength);
215 pNode = _Lookup(pLast, name); 669 pNode = Lookup(pLast, name);
216 name_extractor.GetNext(pName, nLength); 670 name_extractor.GetNext(pName, nLength);
217 } 671 }
218 return pNode ? pNode->field_ptr : nullptr; 672 return pNode ? pNode->field_ptr : nullptr;
219 } 673 }
674
220 CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) { 675 CPDF_FormField* CFieldTree::RemoveField(const CFX_WideString& full_name) {
221 if (full_name == L"") { 676 if (full_name == L"")
222 return nullptr; 677 return nullptr;
223 } 678
224 CFieldNameExtractor name_extractor(full_name); 679 CFieldNameExtractor name_extractor(full_name);
225 const FX_WCHAR* pName; 680 const FX_WCHAR* pName;
226 FX_STRSIZE nLength; 681 FX_STRSIZE nLength;
227 name_extractor.GetNext(pName, nLength); 682 name_extractor.GetNext(pName, nLength);
228 _Node* pNode = &m_Root; 683 Node* pNode = &m_Root;
229 _Node* pLast = nullptr; 684 Node* pLast = nullptr;
230 while (nLength > 0 && pNode) { 685 while (nLength > 0 && pNode) {
231 pLast = pNode; 686 pLast = pNode;
232 CFX_WideString name = CFX_WideString(pName, nLength); 687 CFX_WideString name = CFX_WideString(pName, nLength);
233 pNode = _Lookup(pLast, name); 688 pNode = Lookup(pLast, name);
234 name_extractor.GetNext(pName, nLength); 689 name_extractor.GetNext(pName, nLength);
235 } 690 }
691
236 if (pNode && pNode != &m_Root) { 692 if (pNode && pNode != &m_Root) {
237 for (int i = 0; i < pLast->children.GetSize(); i++) { 693 for (int i = 0; i < pLast->children.GetSize(); i++) {
238 if (pNode == pLast->children[i]) { 694 if (pNode == pLast->children[i]) {
239 pLast->children.RemoveAt(i); 695 pLast->children.RemoveAt(i);
240 break; 696 break;
241 } 697 }
242 } 698 }
243 CPDF_FormField* pField = pNode->field_ptr; 699 CPDF_FormField* pField = pNode->field_ptr;
244 RemoveNode(pNode); 700 RemoveNode(pNode);
245 return pField; 701 return pField;
246 } 702 }
247 return nullptr; 703 return nullptr;
248 } 704 }
249 CFieldTree::_Node* CFieldTree::FindNode(const CFX_WideString& full_name) { 705
250 if (full_name == L"") { 706 CFieldTree::Node* CFieldTree::FindNode(const CFX_WideString& full_name) {
707 if (full_name == L"")
251 return nullptr; 708 return nullptr;
252 } 709
253 CFieldNameExtractor name_extractor(full_name); 710 CFieldNameExtractor name_extractor(full_name);
254 const FX_WCHAR* pName; 711 const FX_WCHAR* pName;
255 FX_STRSIZE nLength; 712 FX_STRSIZE nLength;
256 name_extractor.GetNext(pName, nLength); 713 name_extractor.GetNext(pName, nLength);
257 _Node *pNode = &m_Root, *pLast = nullptr; 714 Node* pNode = &m_Root;
715 Node* pLast = nullptr;
258 while (nLength > 0 && pNode) { 716 while (nLength > 0 && pNode) {
259 pLast = pNode; 717 pLast = pNode;
260 CFX_WideString name = CFX_WideString(pName, nLength); 718 CFX_WideString name = CFX_WideString(pName, nLength);
261 pNode = _Lookup(pLast, name); 719 pNode = Lookup(pLast, name);
262 name_extractor.GetNext(pName, nLength); 720 name_extractor.GetNext(pName, nLength);
263 } 721 }
264 return pNode; 722 return pNode;
265 } 723 }
266 724
725 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
726 typedef struct {
727 FX_BOOL bFind;
728 LOGFONTA lf;
729 } PDF_FONTDATA;
730 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXA* lpelfe,
731 NEWTEXTMETRICEX* lpntme,
732 DWORD FontType,
733 LPARAM lParam) {
734 if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@'))
735 return 1;
736
737 PDF_FONTDATA* pData = (PDF_FONTDATA*)lParam;
738 memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
739 pData->bFind = TRUE;
740 return 0;
741 }
742 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
743
744 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
745 CPDF_Document* pDocument,
746 CFX_ByteString& csNameTag) {
747 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
748 return AddNativeFont(pFormDict, pDocument, charSet, csNameTag);
749 }
750
751 // static
752 uint8_t CPDF_InterForm::GetNativeCharSet() {
753 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
754 uint8_t charSet = ANSI_CHARSET;
755 UINT iCodePage = ::GetACP();
756 switch (iCodePage) {
757 case 932:
758 charSet = SHIFTJIS_CHARSET;
759 break;
760 case 936:
761 charSet = GB2312_CHARSET;
762 break;
763 case 950:
764 charSet = CHINESEBIG5_CHARSET;
765 break;
766 case 1252:
767 charSet = ANSI_CHARSET;
768 break;
769 case 874:
770 charSet = THAI_CHARSET;
771 break;
772 case 949:
773 charSet = HANGUL_CHARSET;
774 break;
775 case 1200:
776 charSet = ANSI_CHARSET;
777 break;
778 case 1250:
779 charSet = EASTEUROPE_CHARSET;
780 break;
781 case 1251:
782 charSet = RUSSIAN_CHARSET;
783 break;
784 case 1253:
785 charSet = GREEK_CHARSET;
786 break;
787 case 1254:
788 charSet = TURKISH_CHARSET;
789 break;
790 case 1255:
791 charSet = HEBREW_CHARSET;
792 break;
793 case 1256:
794 charSet = ARABIC_CHARSET;
795 break;
796 case 1257:
797 charSet = BALTIC_CHARSET;
798 break;
799 case 1258:
800 charSet = VIETNAMESE_CHARSET;
801 break;
802 case 1361:
803 charSet = JOHAB_CHARSET;
804 break;
805 }
806 return charSet;
807 #else
808 return 0;
809 #endif
810 }
811
267 CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument) 812 CPDF_InterForm::CPDF_InterForm(CPDF_Document* pDocument)
268 : m_pDocument(pDocument), 813 : m_pDocument(pDocument),
269 m_pFormDict(nullptr), 814 m_pFormDict(nullptr),
270 m_pFieldTree(new CFieldTree), 815 m_pFieldTree(new CFieldTree),
271 m_pFormNotify(nullptr) { 816 m_pFormNotify(nullptr) {
272 CPDF_Dictionary* pRoot = m_pDocument->GetRoot(); 817 CPDF_Dictionary* pRoot = m_pDocument->GetRoot();
273 if (!pRoot) 818 if (!pRoot)
274 return; 819 return;
275 820
276 m_pFormDict = pRoot->GetDictBy("AcroForm"); 821 m_pFormDict = pRoot->GetDictBy("AcroForm");
277 if (!m_pFormDict) 822 if (!m_pFormDict)
278 return; 823 return;
279 824
280 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields"); 825 CPDF_Array* pFields = m_pFormDict->GetArrayBy("Fields");
281 if (!pFields) 826 if (!pFields)
282 return; 827 return;
283 828
284 for (size_t i = 0; i < pFields->GetCount(); i++) 829 for (size_t i = 0; i < pFields->GetCount(); i++)
285 LoadField(pFields->GetDictAt(i)); 830 LoadField(pFields->GetDictAt(i));
286 } 831 }
287 832
288 CPDF_InterForm::~CPDF_InterForm() { 833 CPDF_InterForm::~CPDF_InterForm() {
289 for (auto it : m_ControlMap) 834 for (auto it : m_ControlMap)
290 delete it.second; 835 delete it.second;
291 836
292 int nCount = m_pFieldTree->m_Root.CountFields(); 837 int nCount = m_pFieldTree->m_Root.CountFields();
293 for (int i = 0; i < nCount; ++i) { 838 for (int i = 0; i < nCount; ++i)
294 delete m_pFieldTree->m_Root.GetField(i); 839 delete m_pFieldTree->m_Root.GetField(i);
295 }
296 } 840 }
297 841
298 FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE; 842 FX_BOOL CPDF_InterForm::s_bUpdateAP = TRUE;
299 843
300 FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() { 844 FX_BOOL CPDF_InterForm::IsUpdateAPEnabled() {
301 return s_bUpdateAP; 845 return s_bUpdateAP;
302 } 846 }
303 847
304 void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) { 848 void CPDF_InterForm::SetUpdateAP(FX_BOOL bUpdateAP) {
305 s_bUpdateAP = bUpdateAP; 849 s_bUpdateAP = bUpdateAP;
306 } 850 }
307 851
308 CFX_ByteString CPDF_InterForm::GenerateNewResourceName( 852 CFX_ByteString CPDF_InterForm::GenerateNewResourceName(
309 const CPDF_Dictionary* pResDict, 853 const CPDF_Dictionary* pResDict,
310 const FX_CHAR* csType, 854 const FX_CHAR* csType,
311 int iMinLen, 855 int iMinLen,
312 const FX_CHAR* csPrefix) { 856 const FX_CHAR* csPrefix) {
313 CFX_ByteString csStr = csPrefix; 857 CFX_ByteString csStr = csPrefix;
314 CFX_ByteString csBType = csType; 858 CFX_ByteString csBType = csType;
315 if (csStr.IsEmpty()) { 859 if (csStr.IsEmpty()) {
316 if (csBType == "ExtGState") { 860 if (csBType == "ExtGState")
317 csStr = "GS"; 861 csStr = "GS";
318 } else if (csBType == "ColorSpace") { 862 else if (csBType == "ColorSpace")
319 csStr = "CS"; 863 csStr = "CS";
320 } else if (csBType == "Font") { 864 else if (csBType == "Font")
321 csStr = "ZiTi"; 865 csStr = "ZiTi";
322 } else { 866 else
323 csStr = "Res"; 867 csStr = "Res";
324 }
325 } 868 }
326 CFX_ByteString csTmp = csStr; 869 CFX_ByteString csTmp = csStr;
327 int iCount = csStr.GetLength(); 870 int iCount = csStr.GetLength();
328 int m = 0; 871 int m = 0;
329 if (iMinLen > 0) { 872 if (iMinLen > 0) {
330 csTmp = ""; 873 csTmp = "";
331 while (m < iMinLen && m < iCount) { 874 while (m < iMinLen && m < iCount)
332 csTmp += csStr[m++]; 875 csTmp += csStr[m++];
333 }
334 while (m < iMinLen) { 876 while (m < iMinLen) {
335 csTmp += '0' + m % 10; 877 csTmp += '0' + m % 10;
336 m++; 878 m++;
337 } 879 }
338 } else { 880 } else {
339 m = iCount; 881 m = iCount;
340 } 882 }
341 if (!pResDict) { 883 if (!pResDict)
342 return csTmp; 884 return csTmp;
343 } 885
344 CPDF_Dictionary* pDict = pResDict->GetDictBy(csType); 886 CPDF_Dictionary* pDict = pResDict->GetDictBy(csType);
345 if (!pDict) { 887 if (!pDict)
346 return csTmp; 888 return csTmp;
347 } 889
348 int num = 0; 890 int num = 0;
349 CFX_ByteString bsNum; 891 CFX_ByteString bsNum;
350 while (TRUE) { 892 while (TRUE) {
351 CFX_ByteString csKey = csTmp + bsNum; 893 CFX_ByteString csKey = csTmp + bsNum;
352 if (!pDict->KeyExist(csKey)) { 894 if (!pDict->KeyExist(csKey))
353 return csKey; 895 return csKey;
354 } 896 if (m < iCount)
355 if (m < iCount) {
356 csTmp += csStr[m++]; 897 csTmp += csStr[m++];
357 } else { 898 else
358 bsNum.Format("%d", num++); 899 bsNum.Format("%d", num++);
359 } 900
360 m++; 901 m++;
361 } 902 }
362 return csTmp; 903 return csTmp;
363 } 904 }
364 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
365 typedef struct PDF_FONTDATA_ {
366 FX_BOOL bFind;
367 LOGFONTA lf;
368 } PDF_FONTDATA, FAR* LPDF_FONTDATA;
369 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXA* lpelfe,
370 NEWTEXTMETRICEX* lpntme,
371 DWORD FontType,
372 LPARAM lParam) {
373 if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@')) {
374 return 1;
375 }
376 LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam;
377 memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
378 pData->bFind = TRUE;
379 return 0;
380 }
381 static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) {
382 PDF_FONTDATA fd;
383 memset(&fd, 0, sizeof(PDF_FONTDATA));
384 HDC hDC = ::GetDC(nullptr);
385 EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd,
386 0);
387 ::ReleaseDC(nullptr, hDC);
388 if (fd.bFind) {
389 memcpy(&lf, &fd.lf, sizeof(LOGFONTA));
390 }
391 return fd.bFind;
392 }
393 static FX_BOOL RetrieveSpecificFont(uint8_t charSet,
394 uint8_t pitchAndFamily,
395 LPCSTR pcsFontName,
396 LOGFONTA& lf) {
397 memset(&lf, 0, sizeof(LOGFONTA));
398 lf.lfCharSet = charSet;
399 lf.lfPitchAndFamily = pitchAndFamily;
400 if (pcsFontName) {
401 // TODO(dsinclair): Should this be strncpy?
402 strcpy(lf.lfFaceName, pcsFontName);
403 }
404 return RetrieveSpecificFont(lf);
405 }
406 #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
407 905
408 CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument, 906 CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument,
409 CFX_ByteString csFontName) { 907 CFX_ByteString csFontName) {
410 if (!pDocument || csFontName.IsEmpty()) 908 if (!pDocument || csFontName.IsEmpty())
411 return nullptr; 909 return nullptr;
412 910
413 if (csFontName == "ZapfDingbats") 911 if (csFontName == "ZapfDingbats")
414 return pDocument->AddStandardFont(csFontName.c_str(), nullptr); 912 return pDocument->AddStandardFont(csFontName.c_str(), nullptr);
415 913
416 CPDF_FontEncoding encoding(PDFFONT_ENCODING_WINANSI); 914 CPDF_FontEncoding encoding(PDFFONT_ENCODING_WINANSI);
(...skipping 25 matching lines...) Expand all
442 } 940 }
443 if (!bRet) { 941 if (!bRet) {
444 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, 942 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE,
445 "Microsoft Sans Serif", lf); 943 "Microsoft Sans Serif", lf);
446 } 944 }
447 if (!bRet) { 945 if (!bRet) {
448 bRet = 946 bRet =
449 RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, nullptr, lf); 947 RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, nullptr, lf);
450 } 948 }
451 if (bRet) { 949 if (bRet) {
452 if (pLogFont) { 950 if (pLogFont)
453 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); 951 memcpy(pLogFont, &lf, sizeof(LOGFONTA));
454 } 952
455 csFontName = lf.lfFaceName; 953 csFontName = lf.lfFaceName;
456 return csFontName; 954 return csFontName;
457 } 955 }
458 #endif 956 #endif
459 return csFontName; 957 return csFontName;
460 } 958 }
461 959
462 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) { 960 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) {
463 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 961 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
464 return GetNativeFont(GetNativeCharSet(), pLogFont); 962 return GetNativeFont(GetNativeCharSet(), pLogFont);
465 #else 963 #else
466 return CFX_ByteString(); 964 return CFX_ByteString();
467 #endif 965 #endif
468 } 966 }
469 967
470 // static
471 uint8_t CPDF_InterForm::GetNativeCharSet() {
472 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
473 uint8_t charSet = ANSI_CHARSET;
474 UINT iCodePage = ::GetACP();
475 switch (iCodePage) {
476 case 932:
477 charSet = SHIFTJIS_CHARSET;
478 break;
479 case 936:
480 charSet = GB2312_CHARSET;
481 break;
482 case 950:
483 charSet = CHINESEBIG5_CHARSET;
484 break;
485 case 1252:
486 charSet = ANSI_CHARSET;
487 break;
488 case 874:
489 charSet = THAI_CHARSET;
490 break;
491 case 949:
492 charSet = HANGUL_CHARSET;
493 break;
494 case 1200:
495 charSet = ANSI_CHARSET;
496 break;
497 case 1250:
498 charSet = EASTEUROPE_CHARSET;
499 break;
500 case 1251:
501 charSet = RUSSIAN_CHARSET;
502 break;
503 case 1253:
504 charSet = GREEK_CHARSET;
505 break;
506 case 1254:
507 charSet = TURKISH_CHARSET;
508 break;
509 case 1255:
510 charSet = HEBREW_CHARSET;
511 break;
512 case 1256:
513 charSet = ARABIC_CHARSET;
514 break;
515 case 1257:
516 charSet = BALTIC_CHARSET;
517 break;
518 case 1258:
519 charSet = VIETNAMESE_CHARSET;
520 break;
521 case 1361:
522 charSet = JOHAB_CHARSET;
523 break;
524 }
525 return charSet;
526 #else
527 return 0;
528 #endif
529 }
530
531 CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet, 968 CPDF_Font* CPDF_InterForm::AddNativeFont(uint8_t charSet,
532 CPDF_Document* pDocument) { 969 CPDF_Document* pDocument) {
533 if (!pDocument) 970 if (!pDocument)
534 return nullptr; 971 return nullptr;
535 972
536 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 973 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
537 LOGFONTA lf; 974 LOGFONTA lf;
538 CFX_ByteString csFontName = GetNativeFont(charSet, &lf); 975 CFX_ByteString csFontName = GetNativeFont(charSet, &lf);
539 if (!csFontName.IsEmpty()) { 976 if (!csFontName.IsEmpty()) {
540 if (csFontName == "Helvetica") 977 if (csFontName == "Helvetica")
541 return AddStandardFont(pDocument, csFontName); 978 return AddStandardFont(pDocument, csFontName);
542 return pDocument->AddWindowsFont(&lf, FALSE, TRUE); 979 return pDocument->AddWindowsFont(&lf, FALSE, TRUE);
543 } 980 }
544 #endif 981 #endif
545 return nullptr; 982 return nullptr;
546 } 983 }
547 984
548 CPDF_Font* CPDF_InterForm::AddNativeFont(CPDF_Document* pDocument) { 985 CPDF_Font* CPDF_InterForm::AddNativeFont(CPDF_Document* pDocument) {
549 return pDocument ? AddNativeFont(GetNativeCharSet(), pDocument) : nullptr; 986 return pDocument ? AddNativeFont(GetNativeCharSet(), pDocument) : nullptr;
550 } 987 }
551 988
552 FX_BOOL CPDF_InterForm::ValidateFieldName( 989 FX_BOOL CPDF_InterForm::ValidateFieldName(
553 CFX_WideString& csNewFieldName, 990 CFX_WideString& csNewFieldName,
554 int iType, 991 int iType,
555 const CPDF_FormField* pExcludedField, 992 const CPDF_FormField* pExcludedField,
556 const CPDF_FormControl* pExcludedControl) { 993 const CPDF_FormControl* pExcludedControl) {
557 if (csNewFieldName.IsEmpty()) { 994 if (csNewFieldName.IsEmpty())
558 return FALSE; 995 return FALSE;
559 } 996
560 int iPos = 0; 997 int iPos = 0;
561 int iLength = csNewFieldName.GetLength(); 998 int iLength = csNewFieldName.GetLength();
562 CFX_WideString csSub; 999 CFX_WideString csSub;
563 while (TRUE) { 1000 while (TRUE) {
564 while (iPos < iLength && 1001 while (iPos < iLength &&
565 (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) { 1002 (csNewFieldName[iPos] == L'.' || csNewFieldName[iPos] == L' ')) {
566 iPos++; 1003 iPos++;
567 } 1004 }
568 if (iPos < iLength && !csSub.IsEmpty()) { 1005 if (iPos < iLength && !csSub.IsEmpty())
569 csSub += L'.'; 1006 csSub += L'.';
570 } 1007 while (iPos < iLength && csNewFieldName[iPos] != L'.')
571 while (iPos < iLength && csNewFieldName[iPos] != L'.') {
572 csSub += csNewFieldName[iPos++]; 1008 csSub += csNewFieldName[iPos++];
573 }
574 for (int i = csSub.GetLength() - 1; i > -1; i--) { 1009 for (int i = csSub.GetLength() - 1; i > -1; i--) {
575 if (csSub[i] == L' ' || csSub[i] == L'.') { 1010 if (csSub[i] == L' ' || csSub[i] == L'.')
576 csSub.SetAt(i, L'\0'); 1011 csSub.SetAt(i, L'\0');
577 } else { 1012 else
578 break; 1013 break;
579 }
580 } 1014 }
581 uint32_t dwCount = m_pFieldTree->m_Root.CountFields(); 1015 uint32_t dwCount = m_pFieldTree->m_Root.CountFields();
582 for (uint32_t m = 0; m < dwCount; m++) { 1016 for (uint32_t m = 0; m < dwCount; m++) {
583 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); 1017 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m);
584 if (!pField) { 1018 if (!pField)
585 continue; 1019 continue;
586 }
587 if (pField == pExcludedField) { 1020 if (pField == pExcludedField) {
588 if (pExcludedControl) { 1021 if (pExcludedControl) {
589 if (pField->CountControls() < 2) { 1022 if (pField->CountControls() < 2)
590 continue; 1023 continue;
591 }
592 } else { 1024 } else {
593 continue; 1025 continue;
594 } 1026 }
595 } 1027 }
596 CFX_WideString csFullName = pField->GetFullName(); 1028 CFX_WideString csFullName = pField->GetFullName();
597 int iRet = CompareFieldName(csSub, csFullName); 1029 int iRet = CompareFieldName(csSub, csFullName);
598 if (iRet == 1) { 1030 if (iRet == 1) {
599 if (pField->GetFieldType() != iType) { 1031 if (pField->GetFieldType() != iType)
600 return FALSE; 1032 return FALSE;
601 }
602 } else if (iRet == 2 && csSub == csNewFieldName) { 1033 } else if (iRet == 2 && csSub == csNewFieldName) {
603 if (csFullName[iPos] == L'.') { 1034 if (csFullName[iPos] == L'.')
604 return FALSE; 1035 return FALSE;
605 }
606 } else if (iRet == 3 && csSub == csNewFieldName) { 1036 } else if (iRet == 3 && csSub == csNewFieldName) {
607 if (csNewFieldName[csFullName.GetLength()] == L'.') { 1037 if (csNewFieldName[csFullName.GetLength()] == L'.')
608 return FALSE; 1038 return FALSE;
609 }
610 } 1039 }
611 } 1040 }
612 if (iPos >= iLength) { 1041 if (iPos >= iLength)
613 break; 1042 break;
614 }
615 } 1043 }
616 if (csSub.IsEmpty()) { 1044 if (csSub.IsEmpty())
617 return FALSE; 1045 return FALSE;
618 } 1046
619 csNewFieldName = csSub; 1047 csNewFieldName = csSub;
620 return TRUE; 1048 return TRUE;
621 } 1049 }
1050
622 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName, 1051 FX_BOOL CPDF_InterForm::ValidateFieldName(CFX_WideString& csNewFieldName,
623 int iType) { 1052 int iType) {
624 return ValidateFieldName(csNewFieldName, iType, nullptr, nullptr); 1053 return ValidateFieldName(csNewFieldName, iType, nullptr, nullptr);
625 } 1054 }
1055
626 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField, 1056 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormField* pField,
627 CFX_WideString& csNewFieldName) { 1057 CFX_WideString& csNewFieldName) {
628 return pField && !csNewFieldName.IsEmpty() && 1058 return pField && !csNewFieldName.IsEmpty() &&
629 ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, 1059 ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField,
630 nullptr); 1060 nullptr);
631 } 1061 }
1062
632 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl, 1063 FX_BOOL CPDF_InterForm::ValidateFieldName(const CPDF_FormControl* pControl,
633 CFX_WideString& csNewFieldName) { 1064 CFX_WideString& csNewFieldName) {
634 if (!pControl || csNewFieldName.IsEmpty()) { 1065 if (!pControl || csNewFieldName.IsEmpty())
635 return FALSE; 1066 return FALSE;
636 } 1067
637 CPDF_FormField* pField = pControl->GetField(); 1068 CPDF_FormField* pField = pControl->GetField();
638 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField, 1069 return ValidateFieldName(csNewFieldName, pField->GetFieldType(), pField,
639 pControl); 1070 pControl);
640 } 1071 }
1072
641 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1, 1073 int CPDF_InterForm::CompareFieldName(const CFX_ByteString& name1,
642 const CFX_ByteString& name2) { 1074 const CFX_ByteString& name2) {
643 if (name1.GetLength() == name2.GetLength()) { 1075 if (name1.GetLength() == name2.GetLength())
644 return name1 == name2 ? 1 : 0; 1076 return name1 == name2 ? 1 : 0;
645 } 1077
646 const FX_CHAR* ptr1 = name1.c_str(); 1078 const FX_CHAR* ptr1 = name1.c_str();
647 const FX_CHAR* ptr2 = name2.c_str(); 1079 const FX_CHAR* ptr2 = name2.c_str();
648 int i = 0; 1080 int i = 0;
649 while (ptr1[i] == ptr2[i]) { 1081 while (ptr1[i] == ptr2[i])
650 i++; 1082 i++;
651 } 1083 if (i == name1.GetLength())
652 if (i == name1.GetLength()) {
653 return 2; 1084 return 2;
654 } 1085 if (i == name2.GetLength())
655 if (i == name2.GetLength()) {
656 return 3; 1086 return 3;
657 }
658 return 0; 1087 return 0;
659 } 1088 }
1089
660 int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1, 1090 int CPDF_InterForm::CompareFieldName(const CFX_WideString& name1,
661 const CFX_WideString& name2) { 1091 const CFX_WideString& name2) {
662 const FX_WCHAR* ptr1 = name1.c_str(); 1092 const FX_WCHAR* ptr1 = name1.c_str();
663 const FX_WCHAR* ptr2 = name2.c_str(); 1093 const FX_WCHAR* ptr2 = name2.c_str();
664 if (name1.GetLength() == name2.GetLength()) { 1094 if (name1.GetLength() == name2.GetLength())
665 return name1 == name2 ? 1 : 0; 1095 return name1 == name2 ? 1 : 0;
666 } 1096
667 int i = 0; 1097 int i = 0;
668 while (ptr1[i] == ptr2[i]) { 1098 while (ptr1[i] == ptr2[i])
669 i++; 1099 i++;
670 } 1100 if (i == name1.GetLength())
671 if (i == name1.GetLength()) {
672 return 2; 1101 return 2;
673 } 1102 if (i == name2.GetLength())
674 if (i == name2.GetLength()) {
675 return 3; 1103 return 3;
676 }
677 return 0; 1104 return 0;
678 } 1105 }
1106
679 uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) { 1107 uint32_t CPDF_InterForm::CountFields(const CFX_WideString& csFieldName) {
680 if (csFieldName.IsEmpty()) { 1108 if (csFieldName.IsEmpty())
681 return (uint32_t)m_pFieldTree->m_Root.CountFields(); 1109 return (uint32_t)m_pFieldTree->m_Root.CountFields();
682 } 1110
683 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName); 1111 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName);
684 return pNode ? pNode->CountFields() : 0; 1112 return pNode ? pNode->CountFields() : 0;
685 } 1113 }
1114
686 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index, 1115 CPDF_FormField* CPDF_InterForm::GetField(uint32_t index,
687 const CFX_WideString& csFieldName) { 1116 const CFX_WideString& csFieldName) {
688 if (csFieldName == L"") { 1117 if (csFieldName == L"")
689 return m_pFieldTree->m_Root.GetField(index); 1118 return m_pFieldTree->m_Root.GetField(index);
690 } 1119
691 CFieldTree::_Node* pNode = m_pFieldTree->FindNode(csFieldName); 1120 CFieldTree::Node* pNode = m_pFieldTree->FindNode(csFieldName);
692 return pNode ? pNode->GetField(index) : nullptr; 1121 return pNode ? pNode->GetField(index) : nullptr;
693 } 1122 }
694 1123
695 CPDF_FormField* CPDF_InterForm::GetFieldByDict( 1124 CPDF_FormField* CPDF_InterForm::GetFieldByDict(
696 CPDF_Dictionary* pFieldDict) const { 1125 CPDF_Dictionary* pFieldDict) const {
697 if (!pFieldDict) { 1126 if (!pFieldDict)
698 return nullptr; 1127 return nullptr;
699 } 1128
700 CFX_WideString csWName = GetFullName(pFieldDict); 1129 CFX_WideString csWName = FPDF_GetFullName(pFieldDict);
701 return m_pFieldTree->GetField(csWName); 1130 return m_pFieldTree->GetField(csWName);
702 } 1131 }
703 1132
704 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage, 1133 CPDF_FormControl* CPDF_InterForm::GetControlAtPoint(CPDF_Page* pPage,
705 FX_FLOAT pdf_x, 1134 FX_FLOAT pdf_x,
706 FX_FLOAT pdf_y, 1135 FX_FLOAT pdf_y,
707 int* z_order) const { 1136 int* z_order) const {
708 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots"); 1137 CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArrayBy("Annots");
709 if (!pAnnotList) 1138 if (!pAnnotList)
710 return nullptr; 1139 return nullptr;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { 1193 int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) {
765 if (!m_pFormDict || !pField) 1194 if (!m_pFormDict || !pField)
766 return -1; 1195 return -1;
767 1196
768 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO"); 1197 CPDF_Array* pArray = m_pFormDict->GetArrayBy("CO");
769 if (!pArray) 1198 if (!pArray)
770 return -1; 1199 return -1;
771 1200
772 for (size_t i = 0; i < pArray->GetCount(); i++) { 1201 for (size_t i = 0; i < pArray->GetCount(); i++) {
773 CPDF_Object* pElement = pArray->GetDirectObjectAt(i); 1202 CPDF_Object* pElement = pArray->GetDirectObjectAt(i);
774 if (pElement == pField->m_pDict) { 1203 if (pElement == pField->m_pDict)
775 return i; 1204 return i;
776 }
777 } 1205 }
778 return -1; 1206 return -1;
779 } 1207 }
780 1208
781 uint32_t CPDF_InterForm::CountFormFonts() { 1209 uint32_t CPDF_InterForm::CountFormFonts() {
782 return CountInterFormFonts(m_pFormDict); 1210 return CountFonts(m_pFormDict);
783 } 1211 }
784 1212
785 CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index, 1213 CPDF_Font* CPDF_InterForm::GetFormFont(uint32_t index,
786 CFX_ByteString& csNameTag) { 1214 CFX_ByteString& csNameTag) {
787 return GetInterFormFont(m_pFormDict, m_pDocument, index, csNameTag); 1215 return GetFont(m_pFormDict, m_pDocument, index, csNameTag);
788 } 1216 }
1217
789 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { 1218 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) {
790 return GetInterFormFont(m_pFormDict, m_pDocument, csNameTag); 1219 return GetFont(m_pFormDict, m_pDocument, csNameTag);
791 } 1220 }
1221
792 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName, 1222 CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csFontName,
793 CFX_ByteString& csNameTag) { 1223 CFX_ByteString& csNameTag) {
794 return GetInterFormFont(m_pFormDict, m_pDocument, csFontName, csNameTag); 1224 return GetFont(m_pFormDict, m_pDocument, csFontName, csNameTag);
795 } 1225 }
1226
796 CPDF_Font* CPDF_InterForm::GetNativeFormFont(uint8_t charSet, 1227 CPDF_Font* CPDF_InterForm::GetNativeFormFont(uint8_t charSet,
797 CFX_ByteString& csNameTag) { 1228 CFX_ByteString& csNameTag) {
798 return GetNativeInterFormFont(m_pFormDict, m_pDocument, charSet, csNameTag); 1229 return ::GetNativeFont(m_pFormDict, m_pDocument, charSet, csNameTag);
799 } 1230 }
1231
800 CPDF_Font* CPDF_InterForm::GetNativeFormFont(CFX_ByteString& csNameTag) { 1232 CPDF_Font* CPDF_InterForm::GetNativeFormFont(CFX_ByteString& csNameTag) {
801 return GetNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); 1233 return ::GetNativeFont(m_pFormDict, m_pDocument, csNameTag);
802 } 1234 }
1235
803 FX_BOOL CPDF_InterForm::FindFormFont(const CPDF_Font* pFont, 1236 FX_BOOL CPDF_InterForm::FindFormFont(const CPDF_Font* pFont,
804 CFX_ByteString& csNameTag) { 1237 CFX_ByteString& csNameTag) {
805 return FindInterFormFont(m_pFormDict, pFont, csNameTag); 1238 return FindFont(m_pFormDict, pFont, csNameTag);
806 } 1239 }
1240
807 FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName, 1241 FX_BOOL CPDF_InterForm::FindFormFont(CFX_ByteString csFontName,
808 CPDF_Font*& pFont, 1242 CPDF_Font*& pFont,
809 CFX_ByteString& csNameTag) { 1243 CFX_ByteString& csNameTag) {
810 return FindInterFormFont(m_pFormDict, m_pDocument, csFontName, pFont, 1244 return FindFont(m_pFormDict, m_pDocument, csFontName, pFont, csNameTag);
811 csNameTag);
812 } 1245 }
1246
813 void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont, 1247 void CPDF_InterForm::AddFormFont(const CPDF_Font* pFont,
814 CFX_ByteString& csNameTag) { 1248 CFX_ByteString& csNameTag) {
815 AddInterFormFont(m_pFormDict, m_pDocument, pFont, csNameTag); 1249 AddFont(m_pFormDict, m_pDocument, pFont, csNameTag);
816 } 1250 }
817 1251
818 CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet, 1252 CPDF_Font* CPDF_InterForm::AddNativeFormFont(uint8_t charSet,
819 CFX_ByteString& csNameTag) { 1253 CFX_ByteString& csNameTag) {
820 return AddNativeInterFormFont(m_pFormDict, m_pDocument, charSet, csNameTag); 1254 return ::AddNativeFont(m_pFormDict, m_pDocument, charSet, csNameTag);
821 } 1255 }
822 1256
823 CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) { 1257 CPDF_Font* CPDF_InterForm::AddNativeFormFont(CFX_ByteString& csNameTag) {
824 return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag); 1258 return AddNativeInterFormFont(m_pFormDict, m_pDocument, csNameTag);
825 } 1259 }
826 1260
827 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) { 1261 void CPDF_InterForm::RemoveFormFont(const CPDF_Font* pFont) {
828 RemoveInterFormFont(m_pFormDict, pFont); 1262 RemoveFont(m_pFormDict, pFont);
829 } 1263 }
830 1264
831 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) { 1265 void CPDF_InterForm::RemoveFormFont(CFX_ByteString csNameTag) {
832 RemoveInterFormFont(m_pFormDict, csNameTag); 1266 RemoveFont(m_pFormDict, csNameTag);
833 } 1267 }
834 1268
835 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() { 1269 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() {
836 if (!m_pFormDict) 1270 if (!m_pFormDict)
837 return CPDF_DefaultAppearance(); 1271 return CPDF_DefaultAppearance();
838 return CPDF_DefaultAppearance(m_pFormDict->GetStringBy("DA")); 1272 return CPDF_DefaultAppearance(m_pFormDict->GetStringBy("DA"));
839 } 1273 }
840 1274
841 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() { 1275 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() {
842 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); 1276 return GetDefaultFont(m_pFormDict, m_pDocument);
843 } 1277 }
1278
844 int CPDF_InterForm::GetFormAlignment() { 1279 int CPDF_InterForm::GetFormAlignment() {
845 return m_pFormDict ? m_pFormDict->GetIntegerBy("Q", 0) : 0; 1280 return m_pFormDict ? m_pFormDict->GetIntegerBy("Q", 0) : 0;
846 } 1281 }
847 1282
848 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields, 1283 bool CPDF_InterForm::ResetForm(const std::vector<CPDF_FormField*>& fields,
849 bool bIncludeOrExclude, 1284 bool bIncludeOrExclude,
850 bool bNotify) { 1285 bool bNotify) {
851 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0) 1286 if (bNotify && m_pFormNotify && m_pFormNotify->BeforeFormReset(this) < 0)
852 return false; 1287 return false;
853 1288
(...skipping 22 matching lines...) Expand all
876 continue; 1311 continue;
877 1312
878 pField->ResetField(bNotify); 1313 pField->ResetField(bNotify);
879 } 1314 }
880 if (bNotify && m_pFormNotify) 1315 if (bNotify && m_pFormNotify)
881 m_pFormNotify->AfterFormReset(this); 1316 m_pFormNotify->AfterFormReset(this);
882 return true; 1317 return true;
883 } 1318 }
884 1319
885 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) { 1320 void CPDF_InterForm::LoadField(CPDF_Dictionary* pFieldDict, int nLevel) {
886 if (nLevel > nMaxRecursion) { 1321 if (nLevel > nMaxRecursion)
887 return; 1322 return;
888 } 1323 if (!pFieldDict)
889 if (!pFieldDict) {
890 return; 1324 return;
891 } 1325
892 uint32_t dwParentObjNum = pFieldDict->GetObjNum(); 1326 uint32_t dwParentObjNum = pFieldDict->GetObjNum();
893 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); 1327 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
894 if (!pKids) { 1328 if (!pKids) {
895 AddTerminalField(pFieldDict); 1329 AddTerminalField(pFieldDict);
896 return; 1330 return;
897 } 1331 }
1332
898 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0); 1333 CPDF_Dictionary* pFirstKid = pKids->GetDictAt(0);
899 if (!pFirstKid) { 1334 if (!pFirstKid)
900 return; 1335 return;
901 } 1336
902 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) { 1337 if (pFirstKid->KeyExist("T") || pFirstKid->KeyExist("Kids")) {
903 for (size_t i = 0; i < pKids->GetCount(); i++) { 1338 for (size_t i = 0; i < pKids->GetCount(); i++) {
904 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i); 1339 CPDF_Dictionary* pChildDict = pKids->GetDictAt(i);
905 if (pChildDict) { 1340 if (pChildDict) {
906 if (pChildDict->GetObjNum() != dwParentObjNum) { 1341 if (pChildDict->GetObjNum() != dwParentObjNum)
907 LoadField(pChildDict, nLevel + 1); 1342 LoadField(pChildDict, nLevel + 1);
908 }
909 } 1343 }
910 } 1344 }
911 } else { 1345 } else {
912 AddTerminalField(pFieldDict); 1346 AddTerminalField(pFieldDict);
913 } 1347 }
914 } 1348 }
1349
915 FX_BOOL CPDF_InterForm::HasXFAForm() const { 1350 FX_BOOL CPDF_InterForm::HasXFAForm() const {
916 return m_pFormDict && m_pFormDict->GetArrayBy("XFA"); 1351 return m_pFormDict && m_pFormDict->GetArrayBy("XFA");
917 } 1352 }
1353
918 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { 1354 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
919 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; 1355 CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
920 if (!pPageDict) { 1356 if (!pPageDict)
921 return; 1357 return;
922 } 1358
923 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots"); 1359 CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots");
924 if (!pAnnots) { 1360 if (!pAnnots)
925 return; 1361 return;
926 } 1362
927 for (size_t i = 0; i < pAnnots->GetCount(); i++) { 1363 for (size_t i = 0; i < pAnnots->GetCount(); i++) {
928 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i); 1364 CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i);
929 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget") { 1365 if (pAnnot && pAnnot->GetStringBy("Subtype") == "Widget")
930 LoadField(pAnnot); 1366 LoadField(pAnnot);
931 }
932 } 1367 }
933 } 1368 }
1369
934 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { 1370 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
935 if (!pFieldDict->KeyExist("T")) { 1371 if (!pFieldDict->KeyExist("T"))
936 return nullptr; 1372 return nullptr;
937 } 1373
938 CPDF_Dictionary* pDict = pFieldDict; 1374 CPDF_Dictionary* pDict = pFieldDict;
939 CFX_WideString csWName = GetFullName(pFieldDict); 1375 CFX_WideString csWName = FPDF_GetFullName(pFieldDict);
940 if (csWName.IsEmpty()) { 1376 if (csWName.IsEmpty())
941 return nullptr; 1377 return nullptr;
942 } 1378
943 CPDF_FormField* pField = nullptr; 1379 CPDF_FormField* pField = nullptr;
944 pField = m_pFieldTree->GetField(csWName); 1380 pField = m_pFieldTree->GetField(csWName);
945 if (!pField) { 1381 if (!pField) {
946 CPDF_Dictionary* pParent = pFieldDict; 1382 CPDF_Dictionary* pParent = pFieldDict;
947 if (!pFieldDict->KeyExist("T") && 1383 if (!pFieldDict->KeyExist("T") &&
948 pFieldDict->GetStringBy("Subtype") == "Widget") { 1384 pFieldDict->GetStringBy("Subtype") == "Widget") {
949 pParent = pFieldDict->GetDictBy("Parent"); 1385 pParent = pFieldDict->GetDictBy("Parent");
950 if (!pParent) { 1386 if (!pParent)
951 pParent = pFieldDict; 1387 pParent = pFieldDict;
952 }
953 } 1388 }
1389
954 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { 1390 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) {
955 if (pFieldDict->KeyExist("FT")) { 1391 if (pFieldDict->KeyExist("FT")) {
956 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectBy("FT"); 1392 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectBy("FT");
957 if (pFTValue) { 1393 if (pFTValue)
958 pParent->SetAt("FT", pFTValue->Clone()); 1394 pParent->SetAt("FT", pFTValue->Clone());
959 }
960 } 1395 }
1396
961 if (pFieldDict->KeyExist("Ff")) { 1397 if (pFieldDict->KeyExist("Ff")) {
962 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectBy("Ff"); 1398 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectBy("Ff");
963 if (pFfValue) { 1399 if (pFfValue)
964 pParent->SetAt("Ff", pFfValue->Clone()); 1400 pParent->SetAt("Ff", pFfValue->Clone());
965 }
966 } 1401 }
967 } 1402 }
1403
968 pField = new CPDF_FormField(this, pParent); 1404 pField = new CPDF_FormField(this, pParent);
969 CPDF_Object* pTObj = pDict->GetObjectBy("T"); 1405 CPDF_Object* pTObj = pDict->GetObjectBy("T");
970 if (ToReference(pTObj)) { 1406 if (ToReference(pTObj)) {
971 CPDF_Object* pClone = pTObj->Clone(TRUE); 1407 CPDF_Object* pClone = pTObj->Clone(TRUE);
972 if (pClone) 1408 if (pClone)
973 pDict->SetAt("T", pClone); 1409 pDict->SetAt("T", pClone);
974 else 1410 else
975 pDict->SetAtName("T", ""); 1411 pDict->SetAtName("T", "");
976 } 1412 }
977 m_pFieldTree->SetField(csWName, pField); 1413 m_pFieldTree->SetField(csWName, pField);
978 } 1414 }
1415
979 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); 1416 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
980 if (!pKids) { 1417 if (!pKids) {
981 if (pFieldDict->GetStringBy("Subtype") == "Widget") { 1418 if (pFieldDict->GetStringBy("Subtype") == "Widget")
982 AddControl(pField, pFieldDict); 1419 AddControl(pField, pFieldDict);
983 }
984 } else { 1420 } else {
985 for (size_t i = 0; i < pKids->GetCount(); i++) { 1421 for (size_t i = 0; i < pKids->GetCount(); i++) {
986 CPDF_Dictionary* pKid = pKids->GetDictAt(i); 1422 CPDF_Dictionary* pKid = pKids->GetDictAt(i);
987 if (!pKid) { 1423 if (!pKid)
988 continue; 1424 continue;
989 } 1425 if (pKid->GetStringBy("Subtype") != "Widget")
990 if (pKid->GetStringBy("Subtype") != "Widget") {
991 continue; 1426 continue;
992 } 1427
993 AddControl(pField, pKid); 1428 AddControl(pField, pKid);
994 } 1429 }
995 } 1430 }
996 return pField; 1431 return pField;
997 } 1432 }
1433
998 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, 1434 CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField,
999 CPDF_Dictionary* pWidgetDict) { 1435 CPDF_Dictionary* pWidgetDict) {
1000 const auto it = m_ControlMap.find(pWidgetDict); 1436 const auto it = m_ControlMap.find(pWidgetDict);
1001 if (it != m_ControlMap.end()) 1437 if (it != m_ControlMap.end())
1002 return it->second; 1438 return it->second;
1003 1439
1004 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict); 1440 CPDF_FormControl* pControl = new CPDF_FormControl(pField, pWidgetDict);
1005 m_ControlMap[pWidgetDict] = pControl; 1441 m_ControlMap[pWidgetDict] = pControl;
1006 pField->m_ControlList.Add(pControl); 1442 pField->m_ControlList.Add(pControl);
1007 return pControl; 1443 return pControl;
(...skipping 16 matching lines...) Expand all
1024 uint32_t dwFlags = pField->GetFieldFlags(); 1460 uint32_t dwFlags = pField->GetFieldFlags();
1025 // TODO(thestig): Look up these magic numbers and add constants for them. 1461 // TODO(thestig): Look up these magic numbers and add constants for them.
1026 if (dwFlags & 0x04) 1462 if (dwFlags & 0x04)
1027 continue; 1463 continue;
1028 1464
1029 bool bFind = true; 1465 bool bFind = true;
1030 if (fields) 1466 if (fields)
1031 bFind = pdfium::ContainsValue(*fields, pField); 1467 bFind = pdfium::ContainsValue(*fields, pField);
1032 if (bIncludeOrExclude == bFind) { 1468 if (bIncludeOrExclude == bFind) {
1033 CPDF_Dictionary* pFieldDict = pField->m_pDict; 1469 CPDF_Dictionary* pFieldDict = pField->m_pDict;
1034 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringBy("V").IsEmpty()) { 1470 if ((dwFlags & 0x02) != 0 && pFieldDict->GetStringBy("V").IsEmpty())
1035 return pField; 1471 return pField;
1036 }
1037 } 1472 }
1038 } 1473 }
1039 return nullptr; 1474 return nullptr;
1040 } 1475 }
1041 1476
1042 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, 1477 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path,
1043 bool bSimpleFileSpec) const { 1478 bool bSimpleFileSpec) const {
1044 std::vector<CPDF_FormField*> fields; 1479 std::vector<CPDF_FormField*> fields;
1045 int nCount = m_pFieldTree->m_Root.CountFields(); 1480 int nCount = m_pFieldTree->m_Root.CountFields();
1046 for (int i = 0; i < nCount; ++i) 1481 for (int i = 0; i < nCount; ++i)
1047 fields.push_back(m_pFieldTree->m_Root.GetField(i)); 1482 fields.push_back(m_pFieldTree->m_Root.GetField(i));
1048 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec); 1483 return ExportToFDF(pdf_path, fields, true, bSimpleFileSpec);
1049 } 1484 }
1050 1485
1051 CFDF_Document* CPDF_InterForm::ExportToFDF( 1486 CFDF_Document* CPDF_InterForm::ExportToFDF(
1052 const CFX_WideStringC& pdf_path, 1487 const CFX_WideStringC& pdf_path,
1053 const std::vector<CPDF_FormField*>& fields, 1488 const std::vector<CPDF_FormField*>& fields,
1054 bool bIncludeOrExclude, 1489 bool bIncludeOrExclude,
1055 bool bSimpleFileSpec) const { 1490 bool bSimpleFileSpec) const {
1056 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1491 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
1057 if (!pDoc) { 1492 if (!pDoc)
1058 return nullptr; 1493 return nullptr;
1059 } 1494
1060 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictBy("FDF"); 1495 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictBy("FDF");
1061 if (!pdf_path.IsEmpty()) { 1496 if (!pdf_path.IsEmpty()) {
1062 if (bSimpleFileSpec) { 1497 if (bSimpleFileSpec) {
1063 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); 1498 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path);
1064 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath)); 1499 pMainDict->SetAtString("F", CFX_ByteString::FromUnicode(wsFilePath));
1065 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath)); 1500 pMainDict->SetAtString("UF", PDF_EncodeText(wsFilePath));
1066 } else { 1501 } else {
1067 CPDF_FileSpec filespec; 1502 CPDF_FileSpec filespec;
1068 filespec.SetFileName(pdf_path); 1503 filespec.SetFileName(pdf_path);
1069 pMainDict->SetAt("F", filespec.GetObj()); 1504 pMainDict->SetAt("F", filespec.GetObj());
1070 } 1505 }
1071 } 1506 }
1507
1072 CPDF_Array* pFields = new CPDF_Array; 1508 CPDF_Array* pFields = new CPDF_Array;
1073 pMainDict->SetAt("Fields", pFields); 1509 pMainDict->SetAt("Fields", pFields);
1074 int nCount = m_pFieldTree->m_Root.CountFields(); 1510 int nCount = m_pFieldTree->m_Root.CountFields();
1075 for (int i = 0; i < nCount; i++) { 1511 for (int i = 0; i < nCount; i++) {
1076 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); 1512 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i);
1077 if (!pField || pField->GetType() == CPDF_FormField::PushButton) { 1513 if (!pField || pField->GetType() == CPDF_FormField::PushButton)
1078 continue; 1514 continue;
1079 } 1515
1080 uint32_t dwFlags = pField->GetFieldFlags(); 1516 uint32_t dwFlags = pField->GetFieldFlags();
1081 if (dwFlags & 0x04) 1517 if (dwFlags & 0x04)
1082 continue; 1518 continue;
1083 1519
1084 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { 1520 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) {
1085 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringBy("V").IsEmpty()) 1521 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringBy("V").IsEmpty())
1086 continue; 1522 continue;
1087 1523
1088 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); 1524 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict());
1089 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; 1525 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary;
1090 pFieldDict->SetAt("T", new CPDF_String(fullname)); 1526 pFieldDict->SetAt("T", new CPDF_String(fullname));
1091 if (pField->GetType() == CPDF_FormField::CheckBox || 1527 if (pField->GetType() == CPDF_FormField::CheckBox ||
1092 pField->GetType() == CPDF_FormField::RadioButton) { 1528 pField->GetType() == CPDF_FormField::RadioButton) {
1093 CFX_WideString csExport = pField->GetCheckValue(FALSE); 1529 CFX_WideString csExport = pField->GetCheckValue(FALSE);
1094 CFX_ByteString csBExport = PDF_EncodeText(csExport); 1530 CFX_ByteString csBExport = PDF_EncodeText(csExport);
1095 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); 1531 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt");
1096 if (pOpt) 1532 if (pOpt)
1097 pFieldDict->SetAtString("V", csBExport); 1533 pFieldDict->SetAtString("V", csBExport);
1098 else 1534 else
1099 pFieldDict->SetAtName("V", csBExport); 1535 pFieldDict->SetAtName("V", csBExport);
1100 } else { 1536 } else {
1101 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); 1537 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V");
1102 if (pV) 1538 if (pV)
1103 pFieldDict->SetAt("V", pV->Clone(TRUE)); 1539 pFieldDict->SetAt("V", pV->Clone(TRUE));
1104 } 1540 }
1105 pFields->Add(pFieldDict); 1541 pFields->Add(pFieldDict);
1106 } 1542 }
1107 } 1543 }
1108 return pDoc; 1544 return pDoc;
1109 } 1545 }
1110 1546
1111 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, 1547 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
1112 const CFX_WideString& parent_name, 1548 const CFX_WideString& parent_name,
1113 FX_BOOL bNotify, 1549 FX_BOOL bNotify,
1114 int nLevel) { 1550 int nLevel) {
1115 CFX_WideString name; 1551 CFX_WideString name;
1116 if (!parent_name.IsEmpty()) { 1552 if (!parent_name.IsEmpty())
1117 name = parent_name + L"."; 1553 name = parent_name + L".";
1118 } 1554
1119 name += pFieldDict->GetUnicodeTextBy("T"); 1555 name += pFieldDict->GetUnicodeTextBy("T");
1120 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); 1556 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
1121 if (pKids) { 1557 if (pKids) {
1122 for (size_t i = 0; i < pKids->GetCount(); i++) { 1558 for (size_t i = 0; i < pKids->GetCount(); i++) {
1123 CPDF_Dictionary* pKid = pKids->GetDictAt(i); 1559 CPDF_Dictionary* pKid = pKids->GetDictAt(i);
1124 if (!pKid) { 1560 if (!pKid)
1125 continue; 1561 continue;
1126 } 1562 if (nLevel <= nMaxRecursion)
1127 if (nLevel <= nMaxRecursion) {
1128 FDF_ImportField(pKid, name, bNotify, nLevel + 1); 1563 FDF_ImportField(pKid, name, bNotify, nLevel + 1);
1129 }
1130 } 1564 }
1131 return; 1565 return;
1132 } 1566 }
1133 if (!pFieldDict->KeyExist("V")) { 1567 if (!pFieldDict->KeyExist("V"))
1134 return; 1568 return;
1135 } 1569
1136 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1570 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1137 if (!pField) { 1571 if (!pField)
1138 return; 1572 return;
1139 } 1573
1140 CFX_WideString csWValue = 1574 CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding);
1141 FPDFDOC_FDF_GetFieldValue(*pFieldDict, m_bsEncoding);
1142 int iType = pField->GetFieldType(); 1575 int iType = pField->GetFieldType();
1143 if (bNotify && m_pFormNotify) { 1576 if (bNotify && m_pFormNotify) {
1144 int iRet = 0; 1577 int iRet = 0;
1145 if (iType == FIELDTYPE_LISTBOX) { 1578 if (iType == FIELDTYPE_LISTBOX)
1146 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1579 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
1147 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1580 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
1148 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); 1581 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue);
1149 } 1582
1150 if (iRet < 0) { 1583 if (iRet < 0)
1151 return; 1584 return;
1152 }
1153 } 1585 }
1586
1154 pField->SetValue(csWValue); 1587 pField->SetValue(csWValue);
1155 CPDF_FormField::Type eType = pField->GetType(); 1588 CPDF_FormField::Type eType = pField->GetType();
1156 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && 1589 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) &&
1157 pFieldDict->KeyExist("Opt")) { 1590 pFieldDict->KeyExist("Opt")) {
1158 pField->m_pDict->SetAt("Opt", 1591 pField->m_pDict->SetAt("Opt",
1159 pFieldDict->GetDirectObjectBy("Opt")->Clone(TRUE)); 1592 pFieldDict->GetDirectObjectBy("Opt")->Clone(TRUE));
1160 } 1593 }
1594
1161 if (bNotify && m_pFormNotify) { 1595 if (bNotify && m_pFormNotify) {
1162 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { 1596 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON)
1163 m_pFormNotify->AfterCheckedStatusChange(pField); 1597 m_pFormNotify->AfterCheckedStatusChange(pField);
1164 } else if (iType == FIELDTYPE_LISTBOX) { 1598 else if (iType == FIELDTYPE_LISTBOX)
1165 m_pFormNotify->AfterSelectionChange(pField); 1599 m_pFormNotify->AfterSelectionChange(pField);
1166 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1600 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
1167 m_pFormNotify->AfterValueChange(pField); 1601 m_pFormNotify->AfterValueChange(pField);
1168 }
1169 } 1602 }
1170 } 1603 }
1171 1604
1172 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, 1605 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
1173 FX_BOOL bNotify) { 1606 FX_BOOL bNotify) {
1174 if (!pFDF) 1607 if (!pFDF)
1175 return FALSE; 1608 return FALSE;
1176 1609
1177 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); 1610 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF");
1178 if (!pMainDict) 1611 if (!pMainDict)
(...skipping 15 matching lines...) Expand all
1194 FDF_ImportField(pField, L"", bNotify); 1627 FDF_ImportField(pField, L"", bNotify);
1195 } 1628 }
1196 if (bNotify && m_pFormNotify) 1629 if (bNotify && m_pFormNotify)
1197 m_pFormNotify->AfterFormImportData(this); 1630 m_pFormNotify->AfterFormImportData(this);
1198 return TRUE; 1631 return TRUE;
1199 } 1632 }
1200 1633
1201 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { 1634 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) {
1202 m_pFormNotify = pNotify; 1635 m_pFormNotify = pNotify;
1203 } 1636 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698