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

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

Issue 1529553003: Merge to XFA: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years 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 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 "doc_utils.h" 8 #include "doc_utils.h"
9 9
10 const int nMaxRecursion = 32; 10 const int nMaxRecursion = 32;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 321 }
322 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 322 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
323 typedef struct _PDF_FONTDATA { 323 typedef struct _PDF_FONTDATA {
324 FX_BOOL bFind; 324 FX_BOOL bFind;
325 LOGFONTA lf; 325 LOGFONTA lf;
326 } PDF_FONTDATA, FAR* LPDF_FONTDATA; 326 } PDF_FONTDATA, FAR* LPDF_FONTDATA;
327 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXA* lpelfe, 327 static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEXA* lpelfe,
328 NEWTEXTMETRICEX* lpntme, 328 NEWTEXTMETRICEX* lpntme,
329 DWORD FontType, 329 DWORD FontType,
330 LPARAM lParam) { 330 LPARAM lParam) {
331 if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@') != NULL) { 331 if (FontType != 0x004 || strchr(lpelfe->elfLogFont.lfFaceName, '@')) {
332 return 1; 332 return 1;
333 } 333 }
334 LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam; 334 LPDF_FONTDATA pData = (LPDF_FONTDATA)lParam;
335 memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA)); 335 memcpy(&pData->lf, &lpelfe->elfLogFont, sizeof(LOGFONTA));
336 pData->bFind = TRUE; 336 pData->bFind = TRUE;
337 return 0; 337 return 0;
338 } 338 }
339 static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) { 339 static FX_BOOL RetrieveSpecificFont(LOGFONTA& lf) {
340 PDF_FONTDATA fd; 340 PDF_FONTDATA fd;
341 memset(&fd, 0, sizeof(PDF_FONTDATA)); 341 memset(&fd, 0, sizeof(PDF_FONTDATA));
342 HDC hDC = ::GetDC(NULL); 342 HDC hDC = ::GetDC(NULL);
343 EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd, 343 EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)EnumFontFamExProc, (LPARAM)&fd,
344 0); 344 0);
345 ::ReleaseDC(NULL, hDC); 345 ::ReleaseDC(NULL, hDC);
346 if (fd.bFind) { 346 if (fd.bFind) {
347 memcpy(&lf, &fd.lf, sizeof(LOGFONTA)); 347 memcpy(&lf, &fd.lf, sizeof(LOGFONTA));
348 } 348 }
349 return fd.bFind; 349 return fd.bFind;
350 } 350 }
351 static FX_BOOL RetrieveSpecificFont(uint8_t charSet, 351 static FX_BOOL RetrieveSpecificFont(uint8_t charSet,
352 uint8_t pitchAndFamily, 352 uint8_t pitchAndFamily,
353 LPCSTR pcsFontName, 353 LPCSTR pcsFontName,
354 LOGFONTA& lf) { 354 LOGFONTA& lf) {
355 memset(&lf, 0, sizeof(LOGFONTA)); 355 memset(&lf, 0, sizeof(LOGFONTA));
356 lf.lfCharSet = charSet; 356 lf.lfCharSet = charSet;
357 lf.lfPitchAndFamily = pitchAndFamily; 357 lf.lfPitchAndFamily = pitchAndFamily;
358 if (pcsFontName != NULL) { 358 if (pcsFontName) {
359 strcpy(lf.lfFaceName, pcsFontName); 359 strcpy(lf.lfFaceName, pcsFontName);
360 } 360 }
361 return RetrieveSpecificFont(lf); 361 return RetrieveSpecificFont(lf);
362 } 362 }
363 #ifdef PDF_ENABLE_XFA 363 #ifdef PDF_ENABLE_XFA
364 static FX_BOOL RetrieveStockFont(int iFontObject, 364 static FX_BOOL RetrieveStockFont(int iFontObject,
365 uint8_t charSet, 365 uint8_t charSet,
366 LOGFONTA& lf) { 366 LOGFONTA& lf) {
367 HFONT hFont = (HFONT)::GetStockObject(iFontObject); 367 HFONT hFont = (HFONT)::GetStockObject(iFontObject);
368 if (hFont != NULL) { 368 if (hFont != NULL) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 "Arial Unicode MS", lf); 414 "Arial Unicode MS", lf);
415 } 415 }
416 if (!bRet) { 416 if (!bRet) {
417 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, 417 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE,
418 "Microsoft Sans Serif", lf); 418 "Microsoft Sans Serif", lf);
419 } 419 }
420 if (!bRet) { 420 if (!bRet) {
421 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, NULL, lf); 421 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, NULL, lf);
422 } 422 }
423 if (bRet) { 423 if (bRet) {
424 if (pLogFont != NULL) { 424 if (pLogFont) {
425 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); 425 memcpy(pLogFont, &lf, sizeof(LOGFONTA));
426 } 426 }
427 csFontName = lf.lfFaceName; 427 csFontName = lf.lfFaceName;
428 return csFontName; 428 return csFontName;
429 } 429 }
430 #endif 430 #endif
431 return csFontName; 431 return csFontName;
432 } 432 }
433 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) { 433 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) {
434 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 434 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 break; 548 break;
549 } 549 }
550 } 550 }
551 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields(); 551 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields();
552 for (FX_DWORD m = 0; m < dwCount; m++) { 552 for (FX_DWORD m = 0; m < dwCount; m++) {
553 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); 553 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m);
554 if (pField == NULL) { 554 if (pField == NULL) {
555 continue; 555 continue;
556 } 556 }
557 if (pField == pExcludedField) { 557 if (pField == pExcludedField) {
558 if (pExcludedControl != NULL) { 558 if (pExcludedControl) {
559 if (pField->CountControls() < 2) { 559 if (pField->CountControls() < 2) {
560 continue; 560 continue;
561 } 561 }
562 } else { 562 } else {
563 continue; 563 continue;
564 } 564 }
565 } 565 }
566 CFX_WideString csFullName = pField->GetFullName(); 566 CFX_WideString csFullName = pField->GetFullName();
567 int iRet = CompareFieldName(csSub, csFullName); 567 int iRet = CompareFieldName(csSub, csFullName);
568 if (iRet == 1) { 568 if (iRet == 1) {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 if (pChildDict->GetObjNum() != dwParentObjNum) { 912 if (pChildDict->GetObjNum() != dwParentObjNum) {
913 LoadField(pChildDict, nLevel + 1); 913 LoadField(pChildDict, nLevel + 1);
914 } 914 }
915 } 915 }
916 } 916 }
917 } else { 917 } else {
918 AddTerminalField(pFieldDict); 918 AddTerminalField(pFieldDict);
919 } 919 }
920 } 920 }
921 FX_BOOL CPDF_InterForm::HasXFAForm() const { 921 FX_BOOL CPDF_InterForm::HasXFAForm() const {
922 return m_pFormDict && m_pFormDict->GetArray("XFA") != NULL; 922 return m_pFormDict && m_pFormDict->GetArray("XFA");
923 } 923 }
924 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { 924 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
925 ASSERT(pPage != NULL);
926 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; 925 CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
927 if (pPageDict == NULL) { 926 if (pPageDict == NULL) {
928 return; 927 return;
929 } 928 }
930 CPDF_Array* pAnnots = pPageDict->GetArray("Annots"); 929 CPDF_Array* pAnnots = pPageDict->GetArray("Annots");
931 if (pAnnots == NULL) { 930 if (pAnnots == NULL) {
932 return; 931 return;
933 } 932 }
934 int iAnnotCount = pAnnots->GetCount(); 933 int iAnnotCount = pAnnots->GetCount();
935 for (int i = 0; i < iAnnotCount; i++) { 934 for (int i = 0; i < iAnnotCount; i++) {
936 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); 935 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i);
937 if (pAnnot != NULL && pAnnot->GetString("Subtype") == "Widget") { 936 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") {
938 LoadField(pAnnot); 937 LoadField(pAnnot);
939 } 938 }
940 } 939 }
941 } 940 }
942 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { 941 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
943 if (!pFieldDict->KeyExist("T")) { 942 if (!pFieldDict->KeyExist("T")) {
944 return NULL; 943 return NULL;
945 } 944 }
946 CPDF_Dictionary* pDict = pFieldDict; 945 CPDF_Dictionary* pDict = pFieldDict;
947 CFX_WideString csWName = GetFullName(pFieldDict); 946 CFX_WideString csWName = GetFullName(pFieldDict);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 int32_t m_codePage; 1134 int32_t m_codePage;
1136 } g_fieldEncoding[] = { 1135 } g_fieldEncoding[] = {
1137 {"BigFive", 950}, 1136 {"BigFive", 950},
1138 {"GBK", 936}, 1137 {"GBK", 936},
1139 {"Shift-JIS", 932}, 1138 {"Shift-JIS", 932},
1140 {"UHC", 949}, 1139 {"UHC", 949},
1141 }; 1140 };
1142 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, 1141 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict,
1143 CFX_WideString& csValue, 1142 CFX_WideString& csValue,
1144 CFX_ByteString& bsEncoding) { 1143 CFX_ByteString& bsEncoding) {
1145 ASSERT(pFieldDict != NULL);
1146 CFX_ByteString csBValue = pFieldDict->GetString("V"); 1144 CFX_ByteString csBValue = pFieldDict->GetString("V");
1147 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); 1145 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]);
1148 int32_t i = 0; 1146 int32_t i = 0;
1149 for (; i < iCount; ++i) 1147 for (; i < iCount; ++i)
1150 if (bsEncoding == g_fieldEncoding[i].m_name) { 1148 if (bsEncoding == g_fieldEncoding[i].m_name) {
1151 break; 1149 break;
1152 } 1150 }
1153 if (i < iCount) { 1151 if (i < iCount) {
1154 CFX_CharMap* pCharMap = 1152 CFX_CharMap* pCharMap =
1155 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage); 1153 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage);
1156 FXSYS_assert(pCharMap != NULL); 1154 FXSYS_assert(pCharMap);
1157 csValue.ConvertFrom(csBValue, pCharMap); 1155 csValue.ConvertFrom(csBValue, pCharMap);
1158 return; 1156 return;
1159 } 1157 }
1160 CFX_ByteString csTemp = csBValue.Left(2); 1158 CFX_ByteString csTemp = csBValue.Left(2);
1161 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { 1159 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") {
1162 csValue = PDF_DecodeText(csBValue); 1160 csValue = PDF_DecodeText(csBValue);
1163 } else { 1161 } else {
1164 csValue = CFX_WideString::FromLocal(csBValue); 1162 csValue = CFX_WideString::FromLocal(csBValue);
1165 } 1163 }
1166 } 1164 }
(...skipping 22 matching lines...) Expand all
1189 if (!pFieldDict->KeyExist("V")) { 1187 if (!pFieldDict->KeyExist("V")) {
1190 return; 1188 return;
1191 } 1189 }
1192 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1190 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1193 if (pField == NULL) { 1191 if (pField == NULL) {
1194 return; 1192 return;
1195 } 1193 }
1196 CFX_WideString csWValue; 1194 CFX_WideString csWValue;
1197 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); 1195 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding);
1198 int iType = pField->GetFieldType(); 1196 int iType = pField->GetFieldType();
1199 if (bNotify && m_pFormNotify != NULL) { 1197 if (bNotify && m_pFormNotify) {
1200 int iRet = 0; 1198 int iRet = 0;
1201 if (iType == FIELDTYPE_LISTBOX) { 1199 if (iType == FIELDTYPE_LISTBOX) {
1202 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1200 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
1203 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1201 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1204 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); 1202 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue);
1205 } 1203 }
1206 if (iRet < 0) { 1204 if (iRet < 0) {
1207 return; 1205 return;
1208 } 1206 }
1209 } 1207 }
1210 CFX_ByteArray statusArray; 1208 CFX_ByteArray statusArray;
1211 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { 1209 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) {
1212 SaveCheckedFieldStatus(pField, statusArray); 1210 SaveCheckedFieldStatus(pField, statusArray);
1213 } 1211 }
1214 pField->SetValue(csWValue); 1212 pField->SetValue(csWValue);
1215 CPDF_FormField::Type eType = pField->GetType(); 1213 CPDF_FormField::Type eType = pField->GetType();
1216 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && 1214 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) &&
1217 pFieldDict->KeyExist("Opt")) { 1215 pFieldDict->KeyExist("Opt")) {
1218 pField->m_pDict->SetAt("Opt", 1216 pField->m_pDict->SetAt("Opt",
1219 pFieldDict->GetElementValue("Opt")->Clone(TRUE)); 1217 pFieldDict->GetElementValue("Opt")->Clone(TRUE));
1220 } 1218 }
1221 if (bNotify && m_pFormNotify != NULL) { 1219 if (bNotify && m_pFormNotify) {
1222 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { 1220 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) {
1223 m_pFormNotify->AfterCheckedStatusChange(pField, statusArray); 1221 m_pFormNotify->AfterCheckedStatusChange(pField, statusArray);
1224 } else if (iType == FIELDTYPE_LISTBOX) { 1222 } else if (iType == FIELDTYPE_LISTBOX) {
1225 m_pFormNotify->AfterSelectionChange(pField); 1223 m_pFormNotify->AfterSelectionChange(pField);
1226 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1224 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1227 m_pFormNotify->AfterValueChange(pField); 1225 m_pFormNotify->AfterValueChange(pField);
1228 } 1226 }
1229 } 1227 }
1230 if (CPDF_InterForm::m_bUpdateAP) { 1228 if (CPDF_InterForm::m_bUpdateAP) {
1231 pField->UpdateAP(NULL); 1229 pField->UpdateAP(NULL);
1232 } 1230 }
1233 } 1231 }
1234 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, 1232 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
1235 FX_BOOL bNotify) { 1233 FX_BOOL bNotify) {
1236 if (pFDF == NULL) { 1234 if (pFDF == NULL) {
1237 return FALSE; 1235 return FALSE;
1238 } 1236 }
1239 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); 1237 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
1240 if (pMainDict == NULL) { 1238 if (pMainDict == NULL) {
1241 return FALSE; 1239 return FALSE;
1242 } 1240 }
1243 CPDF_Array* pFields = pMainDict->GetArray("Fields"); 1241 CPDF_Array* pFields = pMainDict->GetArray("Fields");
1244 if (pFields == NULL) { 1242 if (pFields == NULL) {
1245 return FALSE; 1243 return FALSE;
1246 } 1244 }
1247 m_bsEncoding = pMainDict->GetString("Encoding"); 1245 m_bsEncoding = pMainDict->GetString("Encoding");
1248 if (bNotify && m_pFormNotify != NULL) { 1246 if (bNotify && m_pFormNotify) {
1249 int iRet = m_pFormNotify->BeforeFormImportData(this); 1247 int iRet = m_pFormNotify->BeforeFormImportData(this);
1250 if (iRet < 0) { 1248 if (iRet < 0) {
1251 return FALSE; 1249 return FALSE;
1252 } 1250 }
1253 } 1251 }
1254 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { 1252 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
1255 CPDF_Dictionary* pField = pFields->GetDict(i); 1253 CPDF_Dictionary* pField = pFields->GetDict(i);
1256 if (pField == NULL) { 1254 if (pField == NULL) {
1257 continue; 1255 continue;
1258 } 1256 }
1259 FDF_ImportField(pField, L"", bNotify); 1257 FDF_ImportField(pField, L"", bNotify);
1260 } 1258 }
1261 if (bNotify && m_pFormNotify != NULL) { 1259 if (bNotify && m_pFormNotify) {
1262 m_pFormNotify->AfterFormImportData(this); 1260 m_pFormNotify->AfterFormImportData(this);
1263 } 1261 }
1264 return TRUE; 1262 return TRUE;
1265 } 1263 }
1266 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1264 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1267 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1265 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1268 } 1266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698