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 "core/include/fpdfdoc/fpdf_doc.h" | 7 #include "core/include/fpdfdoc/fpdf_doc.h" |
8 #include "core/src/fpdfdoc/doc_utils.h" | 8 #include "core/src/fpdfdoc/doc_utils.h" |
9 #include "third_party/base/stl_util.h" | 9 #include "third_party/base/stl_util.h" |
10 | 10 |
11 namespace { | |
12 | |
11 const int nMaxRecursion = 32; | 13 const int nMaxRecursion = 32; |
12 | 14 |
15 const struct SupportFieldEncoding { | |
16 const FX_CHAR* m_name; | |
17 FX_WORD m_codePage; | |
18 } g_fieldEncoding[] = { | |
19 {"BigFive", 950}, | |
20 {"GBK", 936}, | |
21 {"Shift-JIS", 932}, | |
22 {"UHC", 949}, | |
23 }; | |
24 | |
25 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, | |
Tom Sepez
2016/02/19 17:02:47
Nit: need not be static now that namespace'd anon.
Lei Zhang
2016/02/19 18:48:34
Done.
| |
26 CFX_WideString& csValue, | |
27 CFX_ByteString& bsEncoding) { | |
28 CFX_ByteString csBValue = pFieldDict->GetStringBy("V"); | |
29 const size_t iCount = FX_ArraySize(g_fieldEncoding); | |
30 size_t i = 0; | |
Tom Sepez
2016/02/19 17:02:47
Nit: maybe range-based for-loop.
Lei Zhang
2016/02/19 18:48:34
Done, and more.
| |
31 for (; i < iCount; ++i) | |
32 if (bsEncoding == g_fieldEncoding[i].m_name) { | |
33 break; | |
Tom Sepez
2016/02/19 17:02:47
Nit: maybe do line 36 here and return rather than
Lei Zhang
2016/02/19 18:48:34
Done.
| |
34 } | |
35 if (i < iCount) { | |
36 csValue = | |
37 CFX_WideString::FromCodePage(csBValue, g_fieldEncoding[i].m_codePage); | |
38 return; | |
39 } | |
40 CFX_ByteString csTemp = csBValue.Left(2); | |
41 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { | |
42 csValue = PDF_DecodeText(csBValue); | |
43 } else { | |
44 csValue = CFX_WideString::FromLocal(csBValue); | |
45 } | |
46 } | |
47 | |
48 } // namespace | |
49 | |
13 class CFieldNameExtractor { | 50 class CFieldNameExtractor { |
14 public: | 51 public: |
15 explicit CFieldNameExtractor(const CFX_WideString& full_name) { | 52 explicit CFieldNameExtractor(const CFX_WideString& full_name) { |
16 m_pStart = full_name.c_str(); | 53 m_pStart = full_name.c_str(); |
17 m_pEnd = m_pStart + full_name.GetLength(); | 54 m_pEnd = m_pStart + full_name.GetLength(); |
18 m_pCur = m_pStart; | 55 m_pCur = m_pStart; |
19 } | 56 } |
20 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { | 57 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { |
21 pSubName = m_pCur; | 58 pSubName = m_pCur; |
22 while (m_pCur < m_pEnd && m_pCur[0] != L'.') { | 59 while (m_pCur < m_pEnd && m_pCur[0] != L'.') { |
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 } else { | 1118 } else { |
1082 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); | 1119 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); |
1083 if (pV) | 1120 if (pV) |
1084 pFieldDict->SetAt("V", pV->Clone(TRUE)); | 1121 pFieldDict->SetAt("V", pV->Clone(TRUE)); |
1085 } | 1122 } |
1086 pFields->Add(pFieldDict); | 1123 pFields->Add(pFieldDict); |
1087 } | 1124 } |
1088 } | 1125 } |
1089 return pDoc; | 1126 return pDoc; |
1090 } | 1127 } |
1091 const struct _SupportFieldEncoding { | 1128 |
1092 const FX_CHAR* m_name; | |
1093 int32_t m_codePage; | |
1094 } g_fieldEncoding[] = { | |
1095 {"BigFive", 950}, | |
1096 {"GBK", 936}, | |
1097 {"Shift-JIS", 932}, | |
1098 {"UHC", 949}, | |
1099 }; | |
1100 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, | |
1101 CFX_WideString& csValue, | |
1102 CFX_ByteString& bsEncoding) { | |
1103 CFX_ByteString csBValue = pFieldDict->GetStringBy("V"); | |
1104 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); | |
1105 int32_t i = 0; | |
1106 for (; i < iCount; ++i) | |
1107 if (bsEncoding == g_fieldEncoding[i].m_name) { | |
1108 break; | |
1109 } | |
1110 if (i < iCount) { | |
1111 CFX_CharMap* pCharMap = | |
1112 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage); | |
1113 FXSYS_assert(pCharMap); | |
1114 csValue.ConvertFrom(csBValue, pCharMap); | |
1115 return; | |
1116 } | |
1117 CFX_ByteString csTemp = csBValue.Left(2); | |
1118 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { | |
1119 csValue = PDF_DecodeText(csBValue); | |
1120 } else { | |
1121 csValue = CFX_WideString::FromLocal(csBValue); | |
1122 } | |
1123 } | |
1124 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, | 1129 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, |
1125 const CFX_WideString& parent_name, | 1130 const CFX_WideString& parent_name, |
1126 FX_BOOL bNotify, | 1131 FX_BOOL bNotify, |
1127 int nLevel) { | 1132 int nLevel) { |
1128 CFX_WideString name; | 1133 CFX_WideString name; |
1129 if (!parent_name.IsEmpty()) { | 1134 if (!parent_name.IsEmpty()) { |
1130 name = parent_name + L"."; | 1135 name = parent_name + L"."; |
1131 } | 1136 } |
1132 name += pFieldDict->GetUnicodeTextBy("T"); | 1137 name += pFieldDict->GetUnicodeTextBy("T"); |
1133 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); | 1138 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1212 FDF_ImportField(pField, L"", bNotify); | 1217 FDF_ImportField(pField, L"", bNotify); |
1213 } | 1218 } |
1214 if (bNotify && m_pFormNotify) { | 1219 if (bNotify && m_pFormNotify) { |
1215 m_pFormNotify->AfterFormImportData(this); | 1220 m_pFormNotify->AfterFormImportData(this); |
1216 } | 1221 } |
1217 return TRUE; | 1222 return TRUE; |
1218 } | 1223 } |
1219 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { | 1224 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { |
1220 m_pFormNotify = (CPDF_FormNotify*)pNotify; | 1225 m_pFormNotify = (CPDF_FormNotify*)pNotify; |
1221 } | 1226 } |
OLD | NEW |