OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 #include "doc_utils.h" | 8 #include "doc_utils.h" |
9 | 9 |
10 const int nMaxRecursion = 32; | 10 const int nMaxRecursion = 32; |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 { | 1124 { |
1125 m_bUpdated = TRUE; | 1125 m_bUpdated = TRUE; |
1126 RemoveInterFormFont(m_pFormDict, csNameTag); | 1126 RemoveInterFormFont(m_pFormDict, csNameTag); |
1127 } | 1127 } |
1128 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() | 1128 CPDF_DefaultAppearance CPDF_InterForm::GetDefaultAppearance() |
1129 { | 1129 { |
1130 CFX_ByteString csDA; | 1130 CFX_ByteString csDA; |
1131 if (m_pFormDict == NULL) { | 1131 if (m_pFormDict == NULL) { |
1132 return csDA; | 1132 return csDA; |
1133 } | 1133 } |
1134 csDA = m_pFormDict->GetString("DA"); | 1134 csDA = m_pFormDict->GetStringAt("DA"); |
1135 return csDA; | 1135 return csDA; |
1136 } | 1136 } |
1137 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() | 1137 CPDF_Font* CPDF_InterForm::GetDefaultFormFont() |
1138 { | 1138 { |
1139 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); | 1139 return GetDefaultInterFormFont(m_pFormDict, m_pDocument); |
1140 } | 1140 } |
1141 int CPDF_InterForm::GetFormAlignment() | 1141 int CPDF_InterForm::GetFormAlignment() |
1142 { | 1142 { |
1143 if (m_pFormDict == NULL) { | 1143 if (m_pFormDict == NULL) { |
1144 return 0; | 1144 return 0; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 if (pPageDict == NULL) { | 1267 if (pPageDict == NULL) { |
1268 return; | 1268 return; |
1269 } | 1269 } |
1270 CPDF_Array* pAnnots = pPageDict->GetArray(FX_BSTRC("Annots")); | 1270 CPDF_Array* pAnnots = pPageDict->GetArray(FX_BSTRC("Annots")); |
1271 if (pAnnots == NULL) { | 1271 if (pAnnots == NULL) { |
1272 return; | 1272 return; |
1273 } | 1273 } |
1274 int iAnnotCount = pAnnots->GetCount(); | 1274 int iAnnotCount = pAnnots->GetCount(); |
1275 for (int i = 0; i < iAnnotCount; i++) { | 1275 for (int i = 0; i < iAnnotCount; i++) { |
1276 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); | 1276 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); |
1277 if (pAnnot != NULL && pAnnot->GetString(FX_BSTRC("Subtype")) == "Widget"
) { | 1277 if (pAnnot && pAnnot->GetStringAt("Subtype") == "Widget") { |
1278 LoadField(pAnnot); | 1278 LoadField(pAnnot); |
1279 } | 1279 } |
1280 } | 1280 } |
1281 } | 1281 } |
1282 CPDF_FormField* CPDF_InterForm::AddTerminalField(const CPDF_Dictionary* pFieldDi
ct) | 1282 CPDF_FormField* CPDF_InterForm::AddTerminalField(const CPDF_Dictionary* pFieldDi
ct) |
1283 { | 1283 { |
1284 if (!pFieldDict->KeyExist(FX_BSTRC("T"))) { | 1284 if (!pFieldDict->KeyExist(FX_BSTRC("T"))) { |
1285 return NULL; | 1285 return NULL; |
1286 } | 1286 } |
1287 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFieldDict; | 1287 CPDF_Dictionary* pDict = (CPDF_Dictionary*)pFieldDict; |
1288 CFX_WideString csWName = GetFullName(pDict); | 1288 CFX_WideString csWName = GetFullName(pDict); |
1289 if (csWName.IsEmpty()) { | 1289 if (csWName.IsEmpty()) { |
1290 return NULL; | 1290 return NULL; |
1291 } | 1291 } |
1292 CPDF_FormField* pField = NULL; | 1292 CPDF_FormField* pField = NULL; |
1293 pField = m_pFieldTree->GetField(csWName); | 1293 pField = m_pFieldTree->GetField(csWName); |
1294 if (pField == NULL) { | 1294 if (pField == NULL) { |
1295 CPDF_Dictionary *pParent = (CPDF_Dictionary*)pFieldDict; | 1295 CPDF_Dictionary *pParent = (CPDF_Dictionary*)pFieldDict; |
1296 if (!pFieldDict->KeyExist(FX_BSTRC("T")) && | 1296 if (!pFieldDict->KeyExist(FX_BSTRC("T")) && |
1297 pFieldDict->GetString(FX_BSTRC("Subtype")) == FX_BSTRC("Widget")) { | 1297 pFieldDict->GetStringAt("Subtype") == "Widget") { |
1298 pParent = pFieldDict->GetDict(FX_BSTRC("Parent")); | 1298 pParent = pFieldDict->GetDict(FX_BSTRC("Parent")); |
1299 if (!pParent) { | 1299 if (!pParent) { |
1300 pParent = (CPDF_Dictionary*)pFieldDict; | 1300 pParent = (CPDF_Dictionary*)pFieldDict; |
1301 } | 1301 } |
1302 } | 1302 } |
1303 if (pParent && pParent != pFieldDict && !pParent->KeyExist(FX_BSTRC("FT"
))) { | 1303 if (pParent && pParent != pFieldDict && !pParent->KeyExist(FX_BSTRC("FT"
))) { |
1304 if (pFieldDict->KeyExist(FX_BSTRC("FT"))) { | 1304 if (pFieldDict->KeyExist(FX_BSTRC("FT"))) { |
1305 CPDF_Object *pFTValue = pFieldDict->GetElementValue(FX_BSTRC("FT
")); | 1305 CPDF_Object *pFTValue = pFieldDict->GetElementValue(FX_BSTRC("FT
")); |
1306 if (pFTValue) { | 1306 if (pFTValue) { |
1307 pParent->SetAt(FX_BSTRC("FT"), pFTValue->Clone()); | 1307 pParent->SetAt(FX_BSTRC("FT"), pFTValue->Clone()); |
(...skipping 13 matching lines...) Expand all Loading... |
1321 if (pClone) { | 1321 if (pClone) { |
1322 pDict->SetAt("T", pClone); | 1322 pDict->SetAt("T", pClone); |
1323 } else { | 1323 } else { |
1324 pDict->SetAtName("T", ""); | 1324 pDict->SetAtName("T", ""); |
1325 } | 1325 } |
1326 } | 1326 } |
1327 m_pFieldTree->SetField(csWName, pField); | 1327 m_pFieldTree->SetField(csWName, pField); |
1328 } | 1328 } |
1329 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); | 1329 CPDF_Array* pKids = pFieldDict->GetArray("Kids"); |
1330 if (pKids == NULL) { | 1330 if (pKids == NULL) { |
1331 if (pFieldDict->GetString("Subtype") == "Widget") { | 1331 if (pFieldDict->GetStringAt("Subtype") == "Widget") { |
1332 AddControl(pField, pFieldDict); | 1332 AddControl(pField, pFieldDict); |
1333 } | 1333 } |
1334 } else { | 1334 } else { |
1335 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) { | 1335 for (FX_DWORD i = 0; i < pKids->GetCount(); i ++) { |
1336 CPDF_Dictionary* pKid = pKids->GetDict(i); | 1336 CPDF_Dictionary* pKid = pKids->GetDict(i); |
1337 if (pKid == NULL) { | 1337 if (pKid == NULL) { |
1338 continue; | 1338 continue; |
1339 } | 1339 } |
1340 if (pKid->GetString("Subtype") != "Widget") { | 1340 if (pKid->GetStringAt("Subtype") != "Widget") { |
1341 continue; | 1341 continue; |
1342 } | 1342 } |
1343 AddControl(pField, pKid); | 1343 AddControl(pField, pKid); |
1344 } | 1344 } |
1345 } | 1345 } |
1346 return pField; | 1346 return pField; |
1347 } | 1347 } |
1348 CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, const
CPDF_Dictionary* pWidgetDict) | 1348 CPDF_FormControl* CPDF_InterForm::AddControl(const CPDF_FormField* pField, const
CPDF_Dictionary* pWidgetDict) |
1349 { | 1349 { |
1350 void *rValue = NULL; | 1350 void *rValue = NULL; |
(...skipping 20 matching lines...) Expand all Loading... |
1371 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1371 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1372 if (dwFlags & 0x04) { | 1372 if (dwFlags & 0x04) { |
1373 continue; | 1373 continue; |
1374 } | 1374 } |
1375 FX_BOOL bFind = TRUE; | 1375 FX_BOOL bFind = TRUE; |
1376 if (fields != NULL) { | 1376 if (fields != NULL) { |
1377 bFind = fields->Find(pField, 0) >= 0; | 1377 bFind = fields->Find(pField, 0) >= 0; |
1378 } | 1378 } |
1379 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { | 1379 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { |
1380 CPDF_Dictionary *pFieldDict = pField->m_pDict; | 1380 CPDF_Dictionary *pFieldDict = pField->m_pDict; |
1381 if ((dwFlags & 0x02) != 0 && pFieldDict->GetString("V").IsEmpty()) { | 1381 if ((dwFlags & 0x02) != 0 && |
| 1382 pFieldDict->GetStringAt("V").IsEmpty()) { |
1382 return pField; | 1383 return pField; |
1383 } | 1384 } |
1384 } | 1385 } |
1385 } | 1386 } |
1386 return NULL; | 1387 return NULL; |
1387 } | 1388 } |
1388 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, FX_B
OOL bSimpleFileSpec) const | 1389 CFDF_Document* CPDF_InterForm::ExportToFDF(const CFX_WideStringC& pdf_path, FX_B
OOL bSimpleFileSpec) const |
1389 { | 1390 { |
1390 CFX_PtrArray fields; | 1391 CFX_PtrArray fields; |
1391 int nCount = m_pFieldTree->m_Root.CountFields(); | 1392 int nCount = m_pFieldTree->m_Root.CountFields(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); | 1425 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(i); |
1425 if (pField == NULL || pField->GetType() == CPDF_FormField::PushButton) { | 1426 if (pField == NULL || pField->GetType() == CPDF_FormField::PushButton) { |
1426 continue; | 1427 continue; |
1427 } | 1428 } |
1428 FX_DWORD dwFlags = pField->GetFieldFlags(); | 1429 FX_DWORD dwFlags = pField->GetFieldFlags(); |
1429 if (dwFlags & 0x04) { | 1430 if (dwFlags & 0x04) { |
1430 continue; | 1431 continue; |
1431 } | 1432 } |
1432 FX_BOOL bFind = fields.Find(pField, 0) >= 0; | 1433 FX_BOOL bFind = fields.Find(pField, 0) >= 0; |
1433 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { | 1434 if ((bIncludeOrExclude && bFind) || (!bIncludeOrExclude && !bFind)) { |
1434 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetString("V").IsEmpty
()) { | 1435 if ((dwFlags & 0x02) != 0 && |
| 1436 pField->m_pDict->GetStringAt("V").IsEmpty()) { |
1435 continue; | 1437 continue; |
1436 } | 1438 } |
1437 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); | 1439 CFX_WideString fullname = GetFullName(pField->GetFieldDict()); |
1438 CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create(); | 1440 CPDF_Dictionary* pFieldDict = CPDF_Dictionary::Create(); |
1439 if (pFieldDict == NULL) { | 1441 if (pFieldDict == NULL) { |
1440 return NULL; | 1442 return NULL; |
1441 } | 1443 } |
1442 CPDF_String* pString = CPDF_String::Create(fullname); | 1444 CPDF_String* pString = CPDF_String::Create(fullname); |
1443 if (pString == NULL) { | 1445 if (pString == NULL) { |
1444 pFieldDict->Release(); | 1446 pFieldDict->Release(); |
(...skipping 25 matching lines...) Expand all Loading... |
1470 int32_t m_codePage; | 1472 int32_t m_codePage; |
1471 } g_fieldEncoding[] = { | 1473 } g_fieldEncoding[] = { |
1472 { "BigFive", 950 }, | 1474 { "BigFive", 950 }, |
1473 { "GBK", 936 }, | 1475 { "GBK", 936 }, |
1474 { "Shift-JIS", 932 }, | 1476 { "Shift-JIS", 932 }, |
1475 { "UHC", 949 }, | 1477 { "UHC", 949 }, |
1476 }; | 1478 }; |
1477 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary *pFieldDict, CFX_WideStrin
g &csValue, CFX_ByteString &bsEncoding) | 1479 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary *pFieldDict, CFX_WideStrin
g &csValue, CFX_ByteString &bsEncoding) |
1478 { | 1480 { |
1479 ASSERT(pFieldDict != NULL); | 1481 ASSERT(pFieldDict != NULL); |
1480 CFX_ByteString csBValue = pFieldDict->GetString("V"); | 1482 CFX_ByteString csBValue = pFieldDict->GetStringAt("V"); |
1481 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); | 1483 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); |
1482 int32_t i = 0; | 1484 int32_t i = 0; |
1483 for (; i < iCount; ++i) | 1485 for (; i < iCount; ++i) |
1484 if (bsEncoding == g_fieldEncoding[i].m_name) { | 1486 if (bsEncoding == g_fieldEncoding[i].m_name) { |
1485 break; | 1487 break; |
1486 } | 1488 } |
1487 if (i < iCount) { | 1489 if (i < iCount) { |
1488 CFX_CharMap *pCharMap = CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i]
.m_codePage); | 1490 CFX_CharMap *pCharMap = CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i]
.m_codePage); |
1489 FXSYS_assert(pCharMap != NULL); | 1491 FXSYS_assert(pCharMap != NULL); |
1490 csValue.ConvertFrom(csBValue, pCharMap); | 1492 csValue.ConvertFrom(csBValue, pCharMap); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 return FALSE; | 1568 return FALSE; |
1567 } | 1569 } |
1568 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); | 1570 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); |
1569 if (pMainDict == NULL) { | 1571 if (pMainDict == NULL) { |
1570 return FALSE; | 1572 return FALSE; |
1571 } | 1573 } |
1572 CPDF_Array* pFields = pMainDict->GetArray("Fields"); | 1574 CPDF_Array* pFields = pMainDict->GetArray("Fields"); |
1573 if (pFields == NULL) { | 1575 if (pFields == NULL) { |
1574 return FALSE; | 1576 return FALSE; |
1575 } | 1577 } |
1576 m_bsEncoding = pMainDict->GetString(FX_BSTRC("Encoding")); | 1578 m_bsEncoding = pMainDict->GetStringAt("Encoding"); |
1577 if (bNotify && m_pFormNotify != NULL) { | 1579 if (bNotify && m_pFormNotify != NULL) { |
1578 int iRet = m_pFormNotify->BeforeFormImportData(this); | 1580 int iRet = m_pFormNotify->BeforeFormImportData(this); |
1579 if (iRet < 0) { | 1581 if (iRet < 0) { |
1580 return FALSE; | 1582 return FALSE; |
1581 } | 1583 } |
1582 } | 1584 } |
1583 for (FX_DWORD i = 0; i < pFields->GetCount(); i ++) { | 1585 for (FX_DWORD i = 0; i < pFields->GetCount(); i ++) { |
1584 CPDF_Dictionary* pField = pFields->GetDict(i); | 1586 CPDF_Dictionary* pField = pFields->GetDict(i); |
1585 if (pField == NULL) { | 1587 if (pField == NULL) { |
1586 continue; | 1588 continue; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 continue; | 1634 continue; |
1633 } | 1635 } |
1634 CPDF_FormControl* pControl = NULL; | 1636 CPDF_FormControl* pControl = NULL; |
1635 if (m_ControlMap.Lookup(pAnnotDict, (void*&)pControl)) { | 1637 if (m_ControlMap.Lookup(pAnnotDict, (void*&)pControl)) { |
1636 return iNewPage; | 1638 return iNewPage; |
1637 } | 1639 } |
1638 } | 1640 } |
1639 } while (TRUE); | 1641 } while (TRUE); |
1640 return -1; | 1642 return -1; |
1641 } | 1643 } |
OLD | NEW |