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

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

Issue 1512763013: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits 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
« no previous file with comments | « core/src/fpdfdoc/doc_basic.cpp ('k') | core/src/fpdfdoc/doc_formfield.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 "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 #endif 363 #endif
364 364
365 CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument, 365 CPDF_Font* CPDF_InterForm::AddStandardFont(CPDF_Document* pDocument,
366 CFX_ByteString csFontName) { 366 CFX_ByteString csFontName) {
367 if (!pDocument || csFontName.IsEmpty()) 367 if (!pDocument || csFontName.IsEmpty())
368 return nullptr; 368 return nullptr;
(...skipping 30 matching lines...) Expand all
399 "Arial Unicode MS", lf); 399 "Arial Unicode MS", lf);
400 } 400 }
401 if (!bRet) { 401 if (!bRet) {
402 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, 402 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE,
403 "Microsoft Sans Serif", lf); 403 "Microsoft Sans Serif", lf);
404 } 404 }
405 if (!bRet) { 405 if (!bRet) {
406 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, NULL, lf); 406 bRet = RetrieveSpecificFont(charSet, DEFAULT_PITCH | FF_DONTCARE, NULL, lf);
407 } 407 }
408 if (bRet) { 408 if (bRet) {
409 if (pLogFont != NULL) { 409 if (pLogFont) {
410 memcpy(pLogFont, &lf, sizeof(LOGFONTA)); 410 memcpy(pLogFont, &lf, sizeof(LOGFONTA));
411 } 411 }
412 csFontName = lf.lfFaceName; 412 csFontName = lf.lfFaceName;
413 return csFontName; 413 return csFontName;
414 } 414 }
415 #endif 415 #endif
416 return csFontName; 416 return csFontName;
417 } 417 }
418 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) { 418 CFX_ByteString CPDF_InterForm::GetNativeFont(void* pLogFont) {
419 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 419 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 break; 533 break;
534 } 534 }
535 } 535 }
536 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields(); 536 FX_DWORD dwCount = m_pFieldTree->m_Root.CountFields();
537 for (FX_DWORD m = 0; m < dwCount; m++) { 537 for (FX_DWORD m = 0; m < dwCount; m++) {
538 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m); 538 CPDF_FormField* pField = m_pFieldTree->m_Root.GetField(m);
539 if (pField == NULL) { 539 if (pField == NULL) {
540 continue; 540 continue;
541 } 541 }
542 if (pField == pExcludedField) { 542 if (pField == pExcludedField) {
543 if (pExcludedControl != NULL) { 543 if (pExcludedControl) {
544 if (pField->CountControls() < 2) { 544 if (pField->CountControls() < 2) {
545 continue; 545 continue;
546 } 546 }
547 } else { 547 } else {
548 continue; 548 continue;
549 } 549 }
550 } 550 }
551 CFX_WideString csFullName = pField->GetFullName(); 551 CFX_WideString csFullName = pField->GetFullName();
552 int iRet = CompareFieldName(csSub, csFullName); 552 int iRet = CompareFieldName(csSub, csFullName);
553 if (iRet == 1) { 553 if (iRet == 1) {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 if (pChildDict->GetObjNum() != dwParentObjNum) { 897 if (pChildDict->GetObjNum() != dwParentObjNum) {
898 LoadField(pChildDict, nLevel + 1); 898 LoadField(pChildDict, nLevel + 1);
899 } 899 }
900 } 900 }
901 } 901 }
902 } else { 902 } else {
903 AddTerminalField(pFieldDict); 903 AddTerminalField(pFieldDict);
904 } 904 }
905 } 905 }
906 FX_BOOL CPDF_InterForm::HasXFAForm() const { 906 FX_BOOL CPDF_InterForm::HasXFAForm() const {
907 return m_pFormDict && m_pFormDict->GetArray("XFA") != NULL; 907 return m_pFormDict && m_pFormDict->GetArray("XFA");
908 } 908 }
909 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) { 909 void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
910 ASSERT(pPage != NULL);
911 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; 910 CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
912 if (pPageDict == NULL) { 911 if (pPageDict == NULL) {
913 return; 912 return;
914 } 913 }
915 CPDF_Array* pAnnots = pPageDict->GetArray("Annots"); 914 CPDF_Array* pAnnots = pPageDict->GetArray("Annots");
916 if (pAnnots == NULL) { 915 if (pAnnots == NULL) {
917 return; 916 return;
918 } 917 }
919 int iAnnotCount = pAnnots->GetCount(); 918 int iAnnotCount = pAnnots->GetCount();
920 for (int i = 0; i < iAnnotCount; i++) { 919 for (int i = 0; i < iAnnotCount; i++) {
921 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i); 920 CPDF_Dictionary* pAnnot = pAnnots->GetDict(i);
922 if (pAnnot != NULL && pAnnot->GetString("Subtype") == "Widget") { 921 if (pAnnot && pAnnot->GetString("Subtype") == "Widget") {
923 LoadField(pAnnot); 922 LoadField(pAnnot);
924 } 923 }
925 } 924 }
926 } 925 }
927 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { 926 CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) {
928 if (!pFieldDict->KeyExist("T")) { 927 if (!pFieldDict->KeyExist("T")) {
929 return NULL; 928 return NULL;
930 } 929 }
931 CPDF_Dictionary* pDict = pFieldDict; 930 CPDF_Dictionary* pDict = pFieldDict;
932 CFX_WideString csWName = GetFullName(pFieldDict); 931 CFX_WideString csWName = GetFullName(pFieldDict);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 int32_t m_codePage; 1119 int32_t m_codePage;
1121 } g_fieldEncoding[] = { 1120 } g_fieldEncoding[] = {
1122 {"BigFive", 950}, 1121 {"BigFive", 950},
1123 {"GBK", 936}, 1122 {"GBK", 936},
1124 {"Shift-JIS", 932}, 1123 {"Shift-JIS", 932},
1125 {"UHC", 949}, 1124 {"UHC", 949},
1126 }; 1125 };
1127 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict, 1126 static void FPDFDOC_FDF_GetFieldValue(CPDF_Dictionary* pFieldDict,
1128 CFX_WideString& csValue, 1127 CFX_WideString& csValue,
1129 CFX_ByteString& bsEncoding) { 1128 CFX_ByteString& bsEncoding) {
1130 ASSERT(pFieldDict != NULL);
1131 CFX_ByteString csBValue = pFieldDict->GetString("V"); 1129 CFX_ByteString csBValue = pFieldDict->GetString("V");
1132 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]); 1130 int32_t iCount = sizeof(g_fieldEncoding) / sizeof(g_fieldEncoding[0]);
1133 int32_t i = 0; 1131 int32_t i = 0;
1134 for (; i < iCount; ++i) 1132 for (; i < iCount; ++i)
1135 if (bsEncoding == g_fieldEncoding[i].m_name) { 1133 if (bsEncoding == g_fieldEncoding[i].m_name) {
1136 break; 1134 break;
1137 } 1135 }
1138 if (i < iCount) { 1136 if (i < iCount) {
1139 CFX_CharMap* pCharMap = 1137 CFX_CharMap* pCharMap =
1140 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage); 1138 CFX_CharMap::GetDefaultMapper(g_fieldEncoding[i].m_codePage);
1141 FXSYS_assert(pCharMap != NULL); 1139 FXSYS_assert(pCharMap);
1142 csValue.ConvertFrom(csBValue, pCharMap); 1140 csValue.ConvertFrom(csBValue, pCharMap);
1143 return; 1141 return;
1144 } 1142 }
1145 CFX_ByteString csTemp = csBValue.Left(2); 1143 CFX_ByteString csTemp = csBValue.Left(2);
1146 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") { 1144 if (csTemp == "\xFF\xFE" || csTemp == "\xFE\xFF") {
1147 csValue = PDF_DecodeText(csBValue); 1145 csValue = PDF_DecodeText(csBValue);
1148 } else { 1146 } else {
1149 csValue = CFX_WideString::FromLocal(csBValue); 1147 csValue = CFX_WideString::FromLocal(csBValue);
1150 } 1148 }
1151 } 1149 }
(...skipping 22 matching lines...) Expand all
1174 if (!pFieldDict->KeyExist("V")) { 1172 if (!pFieldDict->KeyExist("V")) {
1175 return; 1173 return;
1176 } 1174 }
1177 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1175 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1178 if (pField == NULL) { 1176 if (pField == NULL) {
1179 return; 1177 return;
1180 } 1178 }
1181 CFX_WideString csWValue; 1179 CFX_WideString csWValue;
1182 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding); 1180 FPDFDOC_FDF_GetFieldValue(pFieldDict, csWValue, m_bsEncoding);
1183 int iType = pField->GetFieldType(); 1181 int iType = pField->GetFieldType();
1184 if (bNotify && m_pFormNotify != NULL) { 1182 if (bNotify && m_pFormNotify) {
1185 int iRet = 0; 1183 int iRet = 0;
1186 if (iType == FIELDTYPE_LISTBOX) { 1184 if (iType == FIELDTYPE_LISTBOX) {
1187 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1185 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue);
1188 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1186 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1189 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); 1187 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue);
1190 } 1188 }
1191 if (iRet < 0) { 1189 if (iRet < 0) {
1192 return; 1190 return;
1193 } 1191 }
1194 } 1192 }
1195 CFX_ByteArray statusArray; 1193 CFX_ByteArray statusArray;
1196 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { 1194 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) {
1197 SaveCheckedFieldStatus(pField, statusArray); 1195 SaveCheckedFieldStatus(pField, statusArray);
1198 } 1196 }
1199 pField->SetValue(csWValue); 1197 pField->SetValue(csWValue);
1200 CPDF_FormField::Type eType = pField->GetType(); 1198 CPDF_FormField::Type eType = pField->GetType();
1201 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && 1199 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) &&
1202 pFieldDict->KeyExist("Opt")) { 1200 pFieldDict->KeyExist("Opt")) {
1203 pField->m_pDict->SetAt("Opt", 1201 pField->m_pDict->SetAt("Opt",
1204 pFieldDict->GetElementValue("Opt")->Clone(TRUE)); 1202 pFieldDict->GetElementValue("Opt")->Clone(TRUE));
1205 } 1203 }
1206 if (bNotify && m_pFormNotify != NULL) { 1204 if (bNotify && m_pFormNotify) {
1207 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) { 1205 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) {
1208 m_pFormNotify->AfterCheckedStatusChange(pField, statusArray); 1206 m_pFormNotify->AfterCheckedStatusChange(pField, statusArray);
1209 } else if (iType == FIELDTYPE_LISTBOX) { 1207 } else if (iType == FIELDTYPE_LISTBOX) {
1210 m_pFormNotify->AfterSelectionChange(pField); 1208 m_pFormNotify->AfterSelectionChange(pField);
1211 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { 1209 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1212 m_pFormNotify->AfterValueChange(pField); 1210 m_pFormNotify->AfterValueChange(pField);
1213 } 1211 }
1214 } 1212 }
1215 if (CPDF_InterForm::m_bUpdateAP) { 1213 if (CPDF_InterForm::m_bUpdateAP) {
1216 pField->UpdateAP(NULL); 1214 pField->UpdateAP(NULL);
1217 } 1215 }
1218 } 1216 }
1219 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF, 1217 FX_BOOL CPDF_InterForm::ImportFromFDF(const CFDF_Document* pFDF,
1220 FX_BOOL bNotify) { 1218 FX_BOOL bNotify) {
1221 if (pFDF == NULL) { 1219 if (pFDF == NULL) {
1222 return FALSE; 1220 return FALSE;
1223 } 1221 }
1224 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); 1222 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
1225 if (pMainDict == NULL) { 1223 if (pMainDict == NULL) {
1226 return FALSE; 1224 return FALSE;
1227 } 1225 }
1228 CPDF_Array* pFields = pMainDict->GetArray("Fields"); 1226 CPDF_Array* pFields = pMainDict->GetArray("Fields");
1229 if (pFields == NULL) { 1227 if (pFields == NULL) {
1230 return FALSE; 1228 return FALSE;
1231 } 1229 }
1232 m_bsEncoding = pMainDict->GetString("Encoding"); 1230 m_bsEncoding = pMainDict->GetString("Encoding");
1233 if (bNotify && m_pFormNotify != NULL) { 1231 if (bNotify && m_pFormNotify) {
1234 int iRet = m_pFormNotify->BeforeFormImportData(this); 1232 int iRet = m_pFormNotify->BeforeFormImportData(this);
1235 if (iRet < 0) { 1233 if (iRet < 0) {
1236 return FALSE; 1234 return FALSE;
1237 } 1235 }
1238 } 1236 }
1239 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { 1237 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
1240 CPDF_Dictionary* pField = pFields->GetDict(i); 1238 CPDF_Dictionary* pField = pFields->GetDict(i);
1241 if (pField == NULL) { 1239 if (pField == NULL) {
1242 continue; 1240 continue;
1243 } 1241 }
1244 FDF_ImportField(pField, L"", bNotify); 1242 FDF_ImportField(pField, L"", bNotify);
1245 } 1243 }
1246 if (bNotify && m_pFormNotify != NULL) { 1244 if (bNotify && m_pFormNotify) {
1247 m_pFormNotify->AfterFormImportData(this); 1245 m_pFormNotify->AfterFormImportData(this);
1248 } 1246 }
1249 return TRUE; 1247 return TRUE;
1250 } 1248 }
1251 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) { 1249 void CPDF_InterForm::SetFormNotify(const CPDF_FormNotify* pNotify) {
1252 m_pFormNotify = (CPDF_FormNotify*)pNotify; 1250 m_pFormNotify = (CPDF_FormNotify*)pNotify;
1253 } 1251 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_basic.cpp ('k') | core/src/fpdfdoc/doc_formfield.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698