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

Side by Side Diff: core/src/fpdfdoc/doc_form.cpp

Issue 1711893003: Remove CFX_{Byte,Wide}String::ConvertFrom(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: address comments Created 4 years, 10 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
« no previous file with comments | « core/src/fpdfdoc/doc_basic_unittest.cpp ('k') | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "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 CFX_WideString FPDFDOC_FDF_GetFieldValue(const CPDF_Dictionary& pFieldDict,
26 const CFX_ByteString& bsEncoding) {
27 const CFX_ByteString csBValue = pFieldDict.GetStringBy("V");
28 for (const auto& encoding : g_fieldEncoding) {
29 if (bsEncoding == encoding.m_name)
30 return CFX_WideString::FromCodePage(csBValue, encoding.m_codePage);
31 }
32 CFX_ByteString csTemp = csBValue.Left(2);
33 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF")
34 return PDF_DecodeText(csBValue);
35 return CFX_WideString::FromLocal(csBValue);
36 }
37
38 } // namespace
39
13 class CFieldNameExtractor { 40 class CFieldNameExtractor {
14 public: 41 public:
15 explicit CFieldNameExtractor(const CFX_WideString& full_name) { 42 explicit CFieldNameExtractor(const CFX_WideString& full_name) {
16 m_pStart = full_name.c_str(); 43 m_pStart = full_name.c_str();
17 m_pEnd = m_pStart + full_name.GetLength(); 44 m_pEnd = m_pStart + full_name.GetLength();
18 m_pCur = m_pStart; 45 m_pCur = m_pStart;
19 } 46 }
20 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) { 47 void GetNext(const FX_WCHAR*& pSubName, FX_STRSIZE& size) {
21 pSubName = m_pCur; 48 pSubName = m_pCur;
22 while (m_pCur < m_pEnd && m_pCur[0] != L'.') { 49 while (m_pCur < m_pEnd && m_pCur[0] != L'.') {
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 } else { 1108 } else {
1082 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); 1109 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V");
1083 if (pV) 1110 if (pV)
1084 pFieldDict->SetAt("V", pV->Clone(TRUE)); 1111 pFieldDict->SetAt("V", pV->Clone(TRUE));
1085 } 1112 }
1086 pFields->Add(pFieldDict); 1113 pFields->Add(pFieldDict);
1087 } 1114 }
1088 } 1115 }
1089 return pDoc; 1116 return pDoc;
1090 } 1117 }
1091 const struct _SupportFieldEncoding { 1118
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, 1119 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
1125 const CFX_WideString& parent_name, 1120 const CFX_WideString& parent_name,
1126 FX_BOOL bNotify, 1121 FX_BOOL bNotify,
1127 int nLevel) { 1122 int nLevel) {
1128 CFX_WideString name; 1123 CFX_WideString name;
1129 if (!parent_name.IsEmpty()) { 1124 if (!parent_name.IsEmpty()) {
1130 name = parent_name + L"."; 1125 name = parent_name + L".";
1131 } 1126 }
1132 name += pFieldDict->GetUnicodeTextBy("T"); 1127 name += pFieldDict->GetUnicodeTextBy("T");
1133 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids"); 1128 CPDF_Array* pKids = pFieldDict->GetArrayBy("Kids");
1134 if (pKids) { 1129 if (pKids) {
1135 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) { 1130 for (FX_DWORD i = 0; i < pKids->GetCount(); i++) {
1136 CPDF_Dictionary* pKid = pKids->GetDictAt(i); 1131 CPDF_Dictionary* pKid = pKids->GetDictAt(i);
1137 if (!pKid) { 1132 if (!pKid) {
1138 continue; 1133 continue;
1139 } 1134 }
1140 if (nLevel <= nMaxRecursion) { 1135 if (nLevel <= nMaxRecursion) {
1141 FDF_ImportField(pKid, name, bNotify, nLevel + 1); 1136 FDF_ImportField(pKid, name, bNotify, nLevel + 1);
1142 } 1137 }
1143 } 1138 }
1144 return; 1139 return;
1145 } 1140 }
1146 if (!pFieldDict->KeyExist("V")) { 1141 if (!pFieldDict->KeyExist("V")) {
1147 return; 1142 return;
1148 } 1143 }
1149 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1144 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1150 if (!pField) { 1145 if (!pField) {
1151 return; 1146 return;
1152 } 1147 }
1153 CFX_WideString csWValue; 1148 CFX_WideString csWValue =
1154 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); 1149 FPDFDOC_FDF_GetFieldValue(*pFieldDict, m_bsEncoding);
1155 int iType = pField->GetFieldType(); 1150 int iType = pField->GetFieldType();
1156 if (bNotify && m_pFormNotify) { 1151 if (bNotify && m_pFormNotify) {
1157 int iRet = 0; 1152 int iRet = 0;
1158 if (iType == FIELDTYPE_LISTBOX) { 1153 if (iType == FIELDTYPE_LISTBOX) {
1159 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1154 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
1160 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1155 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1161 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); 1156 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue);
1162 } 1157 }
1163 if (iRet < 0) { 1158 if (iRet < 0) {
1164 return; 1159 return;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 FDF_ImportField(pField, L"", bNotify); 1207 FDF_ImportField(pField, L"", bNotify);
1213 } 1208 }
1214 if (bNotify && m_pFormNotify) { 1209 if (bNotify && m_pFormNotify) {
1215 m_pFormNotify->AfterFormImportData(this); 1210 m_pFormNotify->AfterFormImportData(this);
1216 } 1211 }
1217 return TRUE; 1212 return TRUE;
1218 } 1213 }
1219 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1214 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1220 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1215 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1221 } 1216 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_basic_unittest.cpp ('k') | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698