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

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

Issue 2345063002: Use string pools in some dictionaries (Closed)
Patch Set: windows compile Created 4 years, 2 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/fpdfdoc/cpdf_formfield_unittest.cpp ('k') | core/fpdfdoc/cpvt_generateap.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 2016 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_font.h"
10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h" 10 #include "core/fpdfapi/fpdf_font/include/cpdf_fontencoding.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void AddFont(CPDF_Dictionary*& pFormDict, 51 void AddFont(CPDF_Dictionary*& pFormDict,
52 CPDF_Document* pDocument, 52 CPDF_Document* pDocument,
53 const CPDF_Font* pFont, 53 const CPDF_Font* pFont,
54 CFX_ByteString& csNameTag); 54 CFX_ByteString& csNameTag);
55 55
56 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { 56 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
57 if (!pDocument) 57 if (!pDocument)
58 return; 58 return;
59 59
60 if (!pFormDict) { 60 if (!pFormDict) {
61 pFormDict = new CPDF_Dictionary; 61 pFormDict = new CPDF_Dictionary(pDocument->GetByteStringPool());
62 pDocument->GetRoot()->SetReferenceFor( 62 pDocument->GetRoot()->SetReferenceFor(
63 "AcroForm", pDocument, pDocument->AddIndirectObject(pFormDict)); 63 "AcroForm", pDocument, pDocument->AddIndirectObject(pFormDict));
64 } 64 }
65 65
66 CFX_ByteString csDA; 66 CFX_ByteString csDA;
67 if (!pFormDict->KeyExist("DR")) { 67 if (!pFormDict->KeyExist("DR")) {
68 CFX_ByteString csBaseName; 68 CFX_ByteString csBaseName;
69 CFX_ByteString csDefault; 69 CFX_ByteString csDefault;
70 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 70 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
71 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); 71 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 CFX_ByteString csTag; 252 CFX_ByteString csTag;
253 if (FindFont(pFormDict, pFont, csTag)) { 253 if (FindFont(pFormDict, pFont, csTag)) {
254 csNameTag = csTag; 254 csNameTag = csTag;
255 return; 255 return;
256 } 256 }
257 if (!pFormDict) 257 if (!pFormDict)
258 InitDict(pFormDict, pDocument); 258 InitDict(pFormDict, pDocument);
259 259
260 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); 260 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
261 if (!pDR) { 261 if (!pDR) {
262 pDR = new CPDF_Dictionary; 262 pDR = new CPDF_Dictionary(pDocument->GetByteStringPool());
263 pFormDict->SetFor("DR", pDR); 263 pFormDict->SetFor("DR", pDR);
264 } 264 }
265 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); 265 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
266 if (!pFonts) { 266 if (!pFonts) {
267 pFonts = new CPDF_Dictionary; 267 pFonts = new CPDF_Dictionary(pDocument->GetByteStringPool());
268 pDR->SetFor("Font", pFonts); 268 pDR->SetFor("Font", pFonts);
269 } 269 }
270 if (csNameTag.IsEmpty()) 270 if (csNameTag.IsEmpty())
271 csNameTag = pFont->GetBaseFont(); 271 csNameTag = pFont->GetBaseFont();
272 272
273 csNameTag.Remove(' '); 273 csNameTag.Remove(' ');
274 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, 274 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
275 csNameTag.c_str()); 275 csNameTag.c_str());
276 pFonts->SetReferenceFor(csNameTag, pDocument, 276 pFonts->SetReferenceFor(csNameTag, pDocument,
277 pFont->GetFontDict()->GetObjNum()); 277 pFont->GetFontDict()->GetObjNum());
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 if (!pDoc) 1205 if (!pDoc)
1206 return nullptr; 1206 return nullptr;
1207 1207
1208 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); 1208 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF");
1209 if (!pdf_path.IsEmpty()) { 1209 if (!pdf_path.IsEmpty()) {
1210 if (bSimpleFileSpec) { 1210 if (bSimpleFileSpec) {
1211 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); 1211 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path);
1212 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); 1212 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath));
1213 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); 1213 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath));
1214 } else { 1214 } else {
1215 CPDF_FileSpec filespec; 1215 CPDF_FileSpec filespec(pDoc->GetByteStringPool());
1216 filespec.SetFileName(pdf_path); 1216 filespec.SetFileName(pdf_path);
1217 pMainDict->SetFor("F", filespec.GetObj()); 1217 pMainDict->SetFor("F", filespec.GetObj());
1218 } 1218 }
1219 } 1219 }
1220 1220
1221 CPDF_Array* pFields = new CPDF_Array; 1221 CPDF_Array* pFields = new CPDF_Array;
1222 pMainDict->SetFor("Fields", pFields); 1222 pMainDict->SetFor("Fields", pFields);
1223 size_t nCount = m_pFieldTree->m_Root.CountFields(); 1223 size_t nCount = m_pFieldTree->m_Root.CountFields();
1224 for (size_t i = 0; i < nCount; ++i) { 1224 for (size_t i = 0; i < nCount; ++i) {
1225 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); 1225 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i);
1226 if (!pField || pField->GetType() == CPDF_FormField::PushButton) 1226 if (!pField || pField->GetType() == CPDF_FormField::PushButton)
1227 continue; 1227 continue;
1228 1228
1229 uint32_t dwFlags = pField->GetFieldFlags(); 1229 uint32_t dwFlags = pField->GetFieldFlags();
1230 if (dwFlags & 0x04) 1230 if (dwFlags & 0x04)
1231 continue; 1231 continue;
1232 1232
1233 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { 1233 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) {
1234 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) 1234 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty())
1235 continue; 1235 continue;
1236 1236
1237 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); 1237 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict());
1238 CPDF_Dictionary* pFieldDict = new CPDF_Dictionary; 1238 CPDF_Dictionary* pFieldDict =
1239 new CPDF_Dictionary(pDoc->GetByteStringPool());
1239 pFieldDict->SetFor("T", new CPDF_String(fullname)); 1240 pFieldDict->SetFor("T", new CPDF_String(fullname));
1240 if (pField->GetType() == CPDF_FormField::CheckBox || 1241 if (pField->GetType() == CPDF_FormField::CheckBox ||
1241 pField->GetType() == CPDF_FormField::RadioButton) { 1242 pField->GetType() == CPDF_FormField::RadioButton) {
1242 CFX_WideString csExport = pField->GetCheckValue(FALSE); 1243 CFX_WideString csExport = pField->GetCheckValue(FALSE);
1243 CFX_ByteString csBExport = PDF_EncodeText(csExport); 1244 CFX_ByteString csBExport = PDF_EncodeText(csExport);
1244 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); 1245 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt");
1245 if (pOpt) 1246 if (pOpt)
1246 pFieldDict->SetStringFor("V", csBExport); 1247 pFieldDict->SetStringFor("V", csBExport);
1247 else 1248 else
1248 pFieldDict->SetNameFor("V", csBExport); 1249 pFieldDict->SetNameFor("V", csBExport);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 else if (iType == FIELDTYPE_LISTBOX) 1312 else if (iType == FIELDTYPE_LISTBOX)
1312 m_pFormNotify->AfterSelectionChange(pField); 1313 m_pFormNotify->AfterSelectionChange(pField);
1313 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) 1314 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
1314 m_pFormNotify->AfterValueChange(pField); 1315 m_pFormNotify->AfterValueChange(pField);
1315 } 1316 }
1316 } 1317 }
1317 1318
1318 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { 1319 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) {
1319 m_pFormNotify = pNotify; 1320 m_pFormNotify = pNotify;
1320 } 1321 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/cpdf_formfield_unittest.cpp ('k') | core/fpdfdoc/cpvt_generateap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698