| 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 "doc_utils.h" | 8 #include "doc_utils.h" |
| 9 | 9 |
| 10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; | 10 static const int FPDFDOC_UTILS_MAXRECURSION = 32; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (syntax.FindTagParam("Tm", 6)) { | 217 if (syntax.FindTagParam("Tm", 6)) { |
| 218 FX_FLOAT f[6]; | 218 FX_FLOAT f[6]; |
| 219 for (int i = 0; i < 6; i++) { | 219 for (int i = 0; i < 6; i++) { |
| 220 f[i] = FX_atof((CFX_ByteString)syntax.GetWord()); | 220 f[i] = FX_atof((CFX_ByteString)syntax.GetWord()); |
| 221 } | 221 } |
| 222 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); | 222 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); |
| 223 } | 223 } |
| 224 return tm; | 224 return tm; |
| 225 } | 225 } |
| 226 void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { | 226 void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
| 227 if (pDocument == NULL) { | 227 if (!pDocument) { |
| 228 return; | 228 return; |
| 229 } | 229 } |
| 230 if (pFormDict == NULL) { | 230 if (!pFormDict) { |
| 231 pFormDict = CPDF_Dictionary::Create(); | 231 pFormDict = CPDF_Dictionary::Create(); |
| 232 if (pFormDict == NULL) { | |
| 233 return; | |
| 234 } | |
| 235 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); | 232 FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict); |
| 236 CPDF_Dictionary* pRoot = pDocument->GetRoot(); | 233 CPDF_Dictionary* pRoot = pDocument->GetRoot(); |
| 237 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); | 234 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); |
| 238 } | 235 } |
| 239 CFX_ByteString csDA; | 236 CFX_ByteString csDA; |
| 240 if (!pFormDict->KeyExist("DR")) { | 237 if (!pFormDict->KeyExist("DR")) { |
| 241 CPDF_Font* pFont = NULL; | 238 CPDF_Font* pFont = NULL; |
| 242 CFX_ByteString csBaseName, csDefault; | 239 CFX_ByteString csBaseName, csDefault; |
| 243 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 240 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 244 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); | 241 pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); |
| 245 if (pFont) { | 242 if (pFont) { |
| 246 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 243 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
| 247 csDefault = csBaseName; | 244 csDefault = csBaseName; |
| 248 } | 245 } |
| 249 if (charSet != 0) { | 246 if (charSet != 0) { |
| 250 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL); | 247 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL); |
| 251 if (pFont == NULL || csFontName != "Helvetica") { | 248 if (!pFont || csFontName != "Helvetica") { |
| 252 pFont = CPDF_InterForm::AddNativeFont(pDocument); | 249 pFont = CPDF_InterForm::AddNativeFont(pDocument); |
| 253 if (pFont) { | 250 if (pFont) { |
| 254 csBaseName = ""; | 251 csBaseName = ""; |
| 255 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); | 252 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); |
| 256 csDefault = csBaseName; | 253 csDefault = csBaseName; |
| 257 } | 254 } |
| 258 } | 255 } |
| 259 } | 256 } |
| 260 if (pFont) { | 257 if (pFont) { |
| 261 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; | 258 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; |
| 262 } | 259 } |
| 263 } | 260 } |
| 264 if (!csDA.IsEmpty()) { | 261 if (!csDA.IsEmpty()) { |
| 265 csDA += " "; | 262 csDA += " "; |
| 266 } | 263 } |
| 267 csDA += "0 g"; | 264 csDA += "0 g"; |
| 268 if (!pFormDict->KeyExist("DA")) { | 265 if (!pFormDict->KeyExist("DA")) { |
| 269 pFormDict->SetAtString("DA", csDA); | 266 pFormDict->SetAtString("DA", csDA); |
| 270 } | 267 } |
| 271 } | 268 } |
| 272 FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) { | 269 FX_DWORD CountInterFormFonts(CPDF_Dictionary* pFormDict) { |
| 273 if (pFormDict == NULL) { | 270 if (!pFormDict) { |
| 274 return 0; | 271 return 0; |
| 275 } | 272 } |
| 276 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 273 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 277 if (pDR == NULL) { | 274 if (!pDR) { |
| 278 return 0; | 275 return 0; |
| 279 } | 276 } |
| 280 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 277 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 281 if (pFonts == NULL) { | 278 if (!pFonts) { |
| 282 return 0; | 279 return 0; |
| 283 } | 280 } |
| 284 FX_DWORD dwCount = 0; | 281 FX_DWORD dwCount = 0; |
| 285 FX_POSITION pos = pFonts->GetStartPos(); | 282 FX_POSITION pos = pFonts->GetStartPos(); |
| 286 while (pos) { | 283 while (pos) { |
| 287 CPDF_Object* pObj = NULL; | 284 CPDF_Object* pObj = NULL; |
| 288 CFX_ByteString csKey; | 285 CFX_ByteString csKey; |
| 289 pObj = pFonts->GetNextElement(pos, csKey); | 286 pObj = pFonts->GetNextElement(pos, csKey); |
| 290 if (pObj == NULL) { | 287 if (!pObj) { |
| 291 continue; | 288 continue; |
| 292 } | 289 } |
| 293 if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { | 290 if (CPDF_Dictionary* pDirect = ToDictionary(pObj->GetDirect())) { |
| 294 if (pDirect->GetString("Type") == "Font") { | 291 if (pDirect->GetString("Type") == "Font") { |
| 295 dwCount++; | 292 dwCount++; |
| 296 } | 293 } |
| 297 } | 294 } |
| 298 } | 295 } |
| 299 return dwCount; | 296 return dwCount; |
| 300 } | 297 } |
| 301 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, | 298 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
| 302 CPDF_Document* pDocument, | 299 CPDF_Document* pDocument, |
| 303 FX_DWORD index, | 300 FX_DWORD index, |
| 304 CFX_ByteString& csNameTag) { | 301 CFX_ByteString& csNameTag) { |
| 305 if (pFormDict == NULL) { | 302 if (!pFormDict) { |
| 306 return NULL; | 303 return NULL; |
| 307 } | 304 } |
| 308 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 305 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 309 if (pDR == NULL) { | 306 if (!pDR) { |
| 310 return NULL; | 307 return NULL; |
| 311 } | 308 } |
| 312 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 309 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 313 if (pFonts == NULL) { | 310 if (!pFonts) { |
| 314 return NULL; | 311 return NULL; |
| 315 } | 312 } |
| 316 FX_DWORD dwCount = 0; | 313 FX_DWORD dwCount = 0; |
| 317 FX_POSITION pos = pFonts->GetStartPos(); | 314 FX_POSITION pos = pFonts->GetStartPos(); |
| 318 while (pos) { | 315 while (pos) { |
| 319 CPDF_Object* pObj = NULL; | 316 CPDF_Object* pObj = NULL; |
| 320 CFX_ByteString csKey; | 317 CFX_ByteString csKey; |
| 321 pObj = pFonts->GetNextElement(pos, csKey); | 318 pObj = pFonts->GetNextElement(pos, csKey); |
| 322 if (pObj == NULL) { | 319 if (!pObj) { |
| 323 continue; | 320 continue; |
| 324 } | 321 } |
| 325 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 322 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 326 if (!pElement) | 323 if (!pElement) |
| 327 continue; | 324 continue; |
| 328 if (pElement->GetString("Type") != "Font") | 325 if (pElement->GetString("Type") != "Font") |
| 329 continue; | 326 continue; |
| 330 if (dwCount == index) { | 327 if (dwCount == index) { |
| 331 csNameTag = csKey; | 328 csNameTag = csKey; |
| 332 return pDocument->LoadFont(pElement); | 329 return pDocument->LoadFont(pElement); |
| 333 } | 330 } |
| 334 dwCount++; | 331 dwCount++; |
| 335 } | 332 } |
| 336 return NULL; | 333 return NULL; |
| 337 } | 334 } |
| 338 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, | 335 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
| 339 CPDF_Document* pDocument, | 336 CPDF_Document* pDocument, |
| 340 CFX_ByteString csNameTag) { | 337 CFX_ByteString csNameTag) { |
| 341 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); | 338 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); |
| 342 if (pFormDict == NULL || csAlias.IsEmpty()) { | 339 if (!pFormDict || csAlias.IsEmpty()) { |
| 343 return NULL; | 340 return NULL; |
| 344 } | 341 } |
| 345 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 342 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 346 if (pDR == NULL) { | 343 if (!pDR) { |
| 347 return NULL; | 344 return NULL; |
| 348 } | 345 } |
| 349 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 346 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 350 if (pFonts == NULL) { | 347 if (!pFonts) { |
| 351 return NULL; | 348 return NULL; |
| 352 } | 349 } |
| 353 CPDF_Dictionary* pElement = pFonts->GetDict(csAlias); | 350 CPDF_Dictionary* pElement = pFonts->GetDict(csAlias); |
| 354 if (pElement == NULL) { | 351 if (!pElement) { |
| 355 return NULL; | 352 return NULL; |
| 356 } | 353 } |
| 357 if (pElement->GetString("Type") == "Font") { | 354 if (pElement->GetString("Type") == "Font") { |
| 358 return pDocument->LoadFont(pElement); | 355 return pDocument->LoadFont(pElement); |
| 359 } | 356 } |
| 360 return NULL; | 357 return NULL; |
| 361 } | 358 } |
| 362 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, | 359 CPDF_Font* GetInterFormFont(CPDF_Dictionary* pFormDict, |
| 363 CPDF_Document* pDocument, | 360 CPDF_Document* pDocument, |
| 364 CFX_ByteString csFontName, | 361 CFX_ByteString csFontName, |
| 365 CFX_ByteString& csNameTag) { | 362 CFX_ByteString& csNameTag) { |
| 366 if (pFormDict == NULL || csFontName.IsEmpty()) { | 363 if (!pFormDict || csFontName.IsEmpty()) { |
| 367 return NULL; | 364 return NULL; |
| 368 } | 365 } |
| 369 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 366 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 370 if (pDR == NULL) { | 367 if (!pDR) { |
| 371 return NULL; | 368 return NULL; |
| 372 } | 369 } |
| 373 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 370 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 374 if (pFonts == NULL) { | 371 if (!pFonts) { |
| 375 return NULL; | 372 return NULL; |
| 376 } | 373 } |
| 377 FX_POSITION pos = pFonts->GetStartPos(); | 374 FX_POSITION pos = pFonts->GetStartPos(); |
| 378 while (pos) { | 375 while (pos) { |
| 379 CPDF_Object* pObj = NULL; | 376 CPDF_Object* pObj = NULL; |
| 380 CFX_ByteString csKey; | 377 CFX_ByteString csKey; |
| 381 pObj = pFonts->GetNextElement(pos, csKey); | 378 pObj = pFonts->GetNextElement(pos, csKey); |
| 382 if (pObj == NULL) { | 379 if (!pObj) { |
| 383 continue; | 380 continue; |
| 384 } | 381 } |
| 385 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 382 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 386 if (!pElement) | 383 if (!pElement) |
| 387 continue; | 384 continue; |
| 388 if (pElement->GetString("Type") != "Font") | 385 if (pElement->GetString("Type") != "Font") |
| 389 continue; | 386 continue; |
| 390 | 387 |
| 391 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 388 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
| 392 if (!pFind) | 389 if (!pFind) |
| 393 continue; | 390 continue; |
| 394 | 391 |
| 395 CFX_ByteString csBaseFont; | 392 CFX_ByteString csBaseFont; |
| 396 csBaseFont = pFind->GetBaseFont(); | 393 csBaseFont = pFind->GetBaseFont(); |
| 397 csBaseFont.Remove(' '); | 394 csBaseFont.Remove(' '); |
| 398 if (csBaseFont == csFontName) { | 395 if (csBaseFont == csFontName) { |
| 399 csNameTag = csKey; | 396 csNameTag = csKey; |
| 400 return pFind; | 397 return pFind; |
| 401 } | 398 } |
| 402 } | 399 } |
| 403 return NULL; | 400 return NULL; |
| 404 } | 401 } |
| 405 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, | 402 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, |
| 406 CPDF_Document* pDocument, | 403 CPDF_Document* pDocument, |
| 407 uint8_t charSet, | 404 uint8_t charSet, |
| 408 CFX_ByteString& csNameTag) { | 405 CFX_ByteString& csNameTag) { |
| 409 if (pFormDict == NULL) { | 406 if (!pFormDict) { |
| 410 return NULL; | 407 return NULL; |
| 411 } | 408 } |
| 412 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 409 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 413 if (pDR == NULL) { | 410 if (!pDR) { |
| 414 return NULL; | 411 return NULL; |
| 415 } | 412 } |
| 416 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 413 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 417 if (pFonts == NULL) { | 414 if (!pFonts) { |
| 418 return NULL; | 415 return NULL; |
| 419 } | 416 } |
| 420 FX_POSITION pos = pFonts->GetStartPos(); | 417 FX_POSITION pos = pFonts->GetStartPos(); |
| 421 while (pos) { | 418 while (pos) { |
| 422 CPDF_Object* pObj = NULL; | 419 CPDF_Object* pObj = NULL; |
| 423 CFX_ByteString csKey; | 420 CFX_ByteString csKey; |
| 424 pObj = pFonts->GetNextElement(pos, csKey); | 421 pObj = pFonts->GetNextElement(pos, csKey); |
| 425 if (pObj == NULL) { | 422 if (!pObj) { |
| 426 continue; | 423 continue; |
| 427 } | 424 } |
| 428 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 425 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 429 if (!pElement) | 426 if (!pElement) |
| 430 continue; | 427 continue; |
| 431 if (pElement->GetString("Type") != "Font") | 428 if (pElement->GetString("Type") != "Font") |
| 432 continue; | 429 continue; |
| 433 CPDF_Font* pFind = pDocument->LoadFont(pElement); | 430 CPDF_Font* pFind = pDocument->LoadFont(pElement); |
| 434 if (pFind == NULL) { | 431 if (!pFind) { |
| 435 continue; | 432 continue; |
| 436 } | 433 } |
| 437 CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); | 434 CFX_SubstFont* pSubst = (CFX_SubstFont*)pFind->GetSubstFont(); |
| 438 if (pSubst == NULL) { | 435 if (!pSubst) { |
| 439 continue; | 436 continue; |
| 440 } | 437 } |
| 441 if (pSubst->m_Charset == (int)charSet) { | 438 if (pSubst->m_Charset == (int)charSet) { |
| 442 csNameTag = csKey; | 439 csNameTag = csKey; |
| 443 return pFind; | 440 return pFind; |
| 444 } | 441 } |
| 445 } | 442 } |
| 446 return NULL; | 443 return NULL; |
| 447 } | 444 } |
| 448 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, | 445 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, |
| 449 CPDF_Document* pDocument, | 446 CPDF_Document* pDocument, |
| 450 CFX_ByteString& csNameTag) { | 447 CFX_ByteString& csNameTag) { |
| 451 csNameTag = ""; | 448 csNameTag = ""; |
| 452 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 449 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 453 CFX_SubstFont* pSubst; | 450 CFX_SubstFont* pSubst; |
| 454 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); | 451 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); |
| 455 if (pFont) { | 452 if (pFont) { |
| 456 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); | 453 pSubst = (CFX_SubstFont*)pFont->GetSubstFont(); |
| 457 if (pSubst && pSubst->m_Charset == (int)charSet) { | 454 if (pSubst && pSubst->m_Charset == (int)charSet) { |
| 458 FindInterFormFont(pFormDict, pFont, csNameTag); | 455 FindInterFormFont(pFormDict, pFont, csNameTag); |
| 459 return pFont; | 456 return pFont; |
| 460 } | 457 } |
| 461 } | 458 } |
| 462 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); | 459 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); |
| 463 } | 460 } |
| 464 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, | 461 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, |
| 465 const CPDF_Font* pFont, | 462 const CPDF_Font* pFont, |
| 466 CFX_ByteString& csNameTag) { | 463 CFX_ByteString& csNameTag) { |
| 467 if (pFormDict == NULL || pFont == NULL) { | 464 if (!pFormDict || !pFont) { |
| 468 return FALSE; | 465 return FALSE; |
| 469 } | 466 } |
| 470 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 467 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 471 if (pDR == NULL) { | 468 if (!pDR) { |
| 472 return FALSE; | 469 return FALSE; |
| 473 } | 470 } |
| 474 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 471 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 475 if (pFonts == NULL) { | 472 if (!pFonts) { |
| 476 return FALSE; | 473 return FALSE; |
| 477 } | 474 } |
| 478 FX_POSITION pos = pFonts->GetStartPos(); | 475 FX_POSITION pos = pFonts->GetStartPos(); |
| 479 while (pos) { | 476 while (pos) { |
| 480 CPDF_Object* pObj = NULL; | 477 CPDF_Object* pObj = NULL; |
| 481 CFX_ByteString csKey; | 478 CFX_ByteString csKey; |
| 482 pObj = pFonts->GetNextElement(pos, csKey); | 479 pObj = pFonts->GetNextElement(pos, csKey); |
| 483 if (pObj == NULL) { | 480 if (!pObj) { |
| 484 continue; | 481 continue; |
| 485 } | 482 } |
| 486 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 483 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 487 if (!pElement) | 484 if (!pElement) |
| 488 continue; | 485 continue; |
| 489 if (pElement->GetString("Type") != "Font") { | 486 if (pElement->GetString("Type") != "Font") { |
| 490 continue; | 487 continue; |
| 491 } | 488 } |
| 492 if (pFont->GetFontDict() == pElement) { | 489 if (pFont->GetFontDict() == pElement) { |
| 493 csNameTag = csKey; | 490 csNameTag = csKey; |
| 494 return TRUE; | 491 return TRUE; |
| 495 } | 492 } |
| 496 } | 493 } |
| 497 return FALSE; | 494 return FALSE; |
| 498 } | 495 } |
| 499 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, | 496 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, |
| 500 CPDF_Document* pDocument, | 497 CPDF_Document* pDocument, |
| 501 CFX_ByteString csFontName, | 498 CFX_ByteString csFontName, |
| 502 CPDF_Font*& pFont, | 499 CPDF_Font*& pFont, |
| 503 CFX_ByteString& csNameTag) { | 500 CFX_ByteString& csNameTag) { |
| 504 if (pFormDict == NULL) { | 501 if (!pFormDict) { |
| 505 return FALSE; | 502 return FALSE; |
| 506 } | 503 } |
| 507 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 504 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 508 if (pDR == NULL) { | 505 if (!pDR) { |
| 509 return FALSE; | 506 return FALSE; |
| 510 } | 507 } |
| 511 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 508 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 512 if (pFonts == NULL) { | 509 if (!pFonts) { |
| 513 return FALSE; | 510 return FALSE; |
| 514 } | 511 } |
| 515 if (csFontName.GetLength() > 0) { | 512 if (csFontName.GetLength() > 0) { |
| 516 csFontName.Remove(' '); | 513 csFontName.Remove(' '); |
| 517 } | 514 } |
| 518 FX_POSITION pos = pFonts->GetStartPos(); | 515 FX_POSITION pos = pFonts->GetStartPos(); |
| 519 while (pos) { | 516 while (pos) { |
| 520 CPDF_Object* pObj = NULL; | 517 CPDF_Object* pObj = NULL; |
| 521 CFX_ByteString csKey, csTmp; | 518 CFX_ByteString csKey, csTmp; |
| 522 pObj = pFonts->GetNextElement(pos, csKey); | 519 pObj = pFonts->GetNextElement(pos, csKey); |
| 523 if (pObj == NULL) { | 520 if (!pObj) { |
| 524 continue; | 521 continue; |
| 525 } | 522 } |
| 526 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); | 523 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
| 527 if (!pElement) | 524 if (!pElement) |
| 528 continue; | 525 continue; |
| 529 if (pElement->GetString("Type") != "Font") { | 526 if (pElement->GetString("Type") != "Font") { |
| 530 continue; | 527 continue; |
| 531 } | 528 } |
| 532 pFont = pDocument->LoadFont(pElement); | 529 pFont = pDocument->LoadFont(pElement); |
| 533 if (pFont == NULL) { | 530 if (!pFont) { |
| 534 continue; | 531 continue; |
| 535 } | 532 } |
| 536 CFX_ByteString csBaseFont; | 533 CFX_ByteString csBaseFont; |
| 537 csBaseFont = pFont->GetBaseFont(); | 534 csBaseFont = pFont->GetBaseFont(); |
| 538 csBaseFont.Remove(' '); | 535 csBaseFont.Remove(' '); |
| 539 if (csBaseFont == csFontName) { | 536 if (csBaseFont == csFontName) { |
| 540 csNameTag = csKey; | 537 csNameTag = csKey; |
| 541 return TRUE; | 538 return TRUE; |
| 542 } | 539 } |
| 543 } | 540 } |
| 544 return FALSE; | 541 return FALSE; |
| 545 } | 542 } |
| 546 void AddInterFormFont(CPDF_Dictionary*& pFormDict, | 543 void AddInterFormFont(CPDF_Dictionary*& pFormDict, |
| 547 CPDF_Document* pDocument, | 544 CPDF_Document* pDocument, |
| 548 const CPDF_Font* pFont, | 545 const CPDF_Font* pFont, |
| 549 CFX_ByteString& csNameTag) { | 546 CFX_ByteString& csNameTag) { |
| 550 if (pFont == NULL) { | 547 if (!pFont) { |
| 551 return; | 548 return; |
| 552 } | 549 } |
| 553 if (pFormDict == NULL) { | 550 if (!pFormDict) { |
| 554 InitInterFormDict(pFormDict, pDocument); | 551 InitInterFormDict(pFormDict, pDocument); |
| 555 } | 552 } |
| 556 CFX_ByteString csTag; | 553 CFX_ByteString csTag; |
| 557 if (FindInterFormFont(pFormDict, pFont, csTag)) { | 554 if (FindInterFormFont(pFormDict, pFont, csTag)) { |
| 558 csNameTag = csTag; | 555 csNameTag = csTag; |
| 559 return; | 556 return; |
| 560 } | 557 } |
| 561 if (pFormDict == NULL) { | 558 if (!pFormDict) { |
| 562 InitInterFormDict(pFormDict, pDocument); | 559 InitInterFormDict(pFormDict, pDocument); |
| 563 } | 560 } |
| 564 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 561 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 565 if (pDR == NULL) { | 562 if (!pDR) { |
| 566 pDR = CPDF_Dictionary::Create(); | 563 pDR = CPDF_Dictionary::Create(); |
| 567 if (pDR == NULL) { | |
| 568 return; | |
| 569 } | |
| 570 pFormDict->SetAt("DR", pDR); | 564 pFormDict->SetAt("DR", pDR); |
| 571 } | 565 } |
| 572 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 566 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 573 if (pFonts == NULL) { | 567 if (!pFonts) { |
| 574 pFonts = CPDF_Dictionary::Create(); | 568 pFonts = CPDF_Dictionary::Create(); |
| 575 pDR->SetAt("Font", pFonts); | 569 pDR->SetAt("Font", pFonts); |
| 576 } | 570 } |
| 577 if (csNameTag.IsEmpty()) { | 571 if (csNameTag.IsEmpty()) { |
| 578 csNameTag = pFont->GetBaseFont(); | 572 csNameTag = pFont->GetBaseFont(); |
| 579 } | 573 } |
| 580 csNameTag.Remove(' '); | 574 csNameTag.Remove(' '); |
| 581 csNameTag = | 575 csNameTag = |
| 582 CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, csNameTag); | 576 CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, csNameTag); |
| 583 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); | 577 pFonts->SetAtReference(csNameTag, pDocument, pFont->GetFontDict()); |
| 584 } | 578 } |
| 585 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, | 579 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, |
| 586 CPDF_Document* pDocument, | 580 CPDF_Document* pDocument, |
| 587 uint8_t charSet, | 581 uint8_t charSet, |
| 588 CFX_ByteString& csNameTag) { | 582 CFX_ByteString& csNameTag) { |
| 589 if (pFormDict == NULL) { | 583 if (!pFormDict) { |
| 590 InitInterFormDict(pFormDict, pDocument); | 584 InitInterFormDict(pFormDict, pDocument); |
| 591 } | 585 } |
| 592 CFX_ByteString csTemp; | 586 CFX_ByteString csTemp; |
| 593 CPDF_Font* pFont = | 587 CPDF_Font* pFont = |
| 594 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp); | 588 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp); |
| 595 if (pFont) { | 589 if (pFont) { |
| 596 csNameTag = csTemp; | 590 csNameTag = csTemp; |
| 597 return pFont; | 591 return pFont; |
| 598 } | 592 } |
| 599 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); | 593 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); |
| 600 if (!csFontName.IsEmpty()) { | 594 if (!csFontName.IsEmpty()) { |
| 601 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { | 595 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { |
| 602 return pFont; | 596 return pFont; |
| 603 } | 597 } |
| 604 } | 598 } |
| 605 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); | 599 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); |
| 606 if (pFont) { | 600 if (pFont) { |
| 607 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); | 601 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); |
| 608 } | 602 } |
| 609 return pFont; | 603 return pFont; |
| 610 } | 604 } |
| 611 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, | 605 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, |
| 612 CPDF_Document* pDocument, | 606 CPDF_Document* pDocument, |
| 613 CFX_ByteString& csNameTag) { | 607 CFX_ByteString& csNameTag) { |
| 614 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); | 608 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); |
| 615 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); | 609 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); |
| 616 } | 610 } |
| 617 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { | 611 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { |
| 618 if (pFormDict == NULL || pFont == NULL) { | 612 if (!pFormDict || !pFont) { |
| 619 return; | 613 return; |
| 620 } | 614 } |
| 621 CFX_ByteString csTag; | 615 CFX_ByteString csTag; |
| 622 if (!FindInterFormFont(pFormDict, pFont, csTag)) { | 616 if (!FindInterFormFont(pFormDict, pFont, csTag)) { |
| 623 return; | 617 return; |
| 624 } | 618 } |
| 625 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 619 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 626 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 620 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 627 pFonts->RemoveAt(csTag); | 621 pFonts->RemoveAt(csTag); |
| 628 } | 622 } |
| 629 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { | 623 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { |
| 630 if (pFormDict == NULL || csNameTag.IsEmpty()) { | 624 if (!pFormDict || csNameTag.IsEmpty()) { |
| 631 return; | 625 return; |
| 632 } | 626 } |
| 633 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); | 627 CPDF_Dictionary* pDR = pFormDict->GetDict("DR"); |
| 634 if (pDR == NULL) { | 628 if (!pDR) { |
| 635 return; | 629 return; |
| 636 } | 630 } |
| 637 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); | 631 CPDF_Dictionary* pFonts = pDR->GetDict("Font"); |
| 638 if (pFonts == NULL) { | 632 if (!pFonts) { |
| 639 return; | 633 return; |
| 640 } | 634 } |
| 641 pFonts->RemoveAt(csNameTag); | 635 pFonts->RemoveAt(csNameTag); |
| 642 } | 636 } |
| 643 CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, | 637 CPDF_Font* GetDefaultInterFormFont(CPDF_Dictionary* pFormDict, |
| 644 CPDF_Document* pDocument) { | 638 CPDF_Document* pDocument) { |
| 645 if (pFormDict == NULL) { | 639 if (!pFormDict) { |
| 646 return NULL; | 640 return NULL; |
| 647 } | 641 } |
| 648 CPDF_DefaultAppearance cDA = pFormDict->GetString("DA"); | 642 CPDF_DefaultAppearance cDA = pFormDict->GetString("DA"); |
| 649 CFX_ByteString csFontNameTag; | 643 CFX_ByteString csFontNameTag; |
| 650 FX_FLOAT fFontSize; | 644 FX_FLOAT fFontSize; |
| 651 cDA.GetFont(csFontNameTag, fFontSize); | 645 cDA.GetFont(csFontNameTag, fFontSize); |
| 652 return GetInterFormFont(pFormDict, pDocument, csFontNameTag); | 646 return GetInterFormFont(pFormDict, pDocument, csFontNameTag); |
| 653 } | 647 } |
| 654 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() { | 648 CPDF_IconFit::ScaleMethod CPDF_IconFit::GetScaleMethod() { |
| 655 if (!m_pDict) { | 649 if (!m_pDict) { |
| 656 return Always; | 650 return Always; |
| 657 } | 651 } |
| 658 CFX_ByteString csSW = m_pDict->GetString("SW", "A"); | 652 CFX_ByteString csSW = m_pDict->GetString("SW", "A"); |
| 659 if (csSW == "B") { | 653 if (csSW == "B") { |
| 660 return Bigger; | 654 return Bigger; |
| 661 } | 655 } |
| 662 if (csSW == "S") { | 656 if (csSW == "S") { |
| 663 return Smaller; | 657 return Smaller; |
| 664 } | 658 } |
| 665 if (csSW == "N") { | 659 if (csSW == "N") { |
| 666 return Never; | 660 return Never; |
| 667 } | 661 } |
| 668 return Always; | 662 return Always; |
| 669 } | 663 } |
| 670 FX_BOOL CPDF_IconFit::IsProportionalScale() { | 664 FX_BOOL CPDF_IconFit::IsProportionalScale() { |
| 671 if (m_pDict == NULL) { | 665 if (!m_pDict) { |
| 672 return TRUE; | 666 return TRUE; |
| 673 } | 667 } |
| 674 return m_pDict->GetString("S", "P") != "A"; | 668 return m_pDict->GetString("S", "P") != "A"; |
| 675 } | 669 } |
| 676 void CPDF_IconFit::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { | 670 void CPDF_IconFit::GetIconPosition(FX_FLOAT& fLeft, FX_FLOAT& fBottom) { |
| 677 fLeft = fBottom = 0.5; | 671 fLeft = fBottom = 0.5; |
| 678 if (m_pDict == NULL) { | 672 if (!m_pDict) { |
| 679 return; | 673 return; |
| 680 } | 674 } |
| 681 CPDF_Array* pA = m_pDict->GetArray("A"); | 675 CPDF_Array* pA = m_pDict->GetArray("A"); |
| 682 if (pA) { | 676 if (pA) { |
| 683 FX_DWORD dwCount = pA->GetCount(); | 677 FX_DWORD dwCount = pA->GetCount(); |
| 684 if (dwCount > 0) { | 678 if (dwCount > 0) { |
| 685 fLeft = pA->GetNumber(0); | 679 fLeft = pA->GetNumber(0); |
| 686 } | 680 } |
| 687 if (dwCount > 1) { | 681 if (dwCount > 1) { |
| 688 fBottom = pA->GetNumber(1); | 682 fBottom = pA->GetNumber(1); |
| 689 } | 683 } |
| 690 } | 684 } |
| 691 } | 685 } |
| 692 FX_BOOL CPDF_IconFit::GetFittingBounds() { | 686 FX_BOOL CPDF_IconFit::GetFittingBounds() { |
| 693 if (m_pDict == NULL) { | 687 if (!m_pDict) { |
| 694 return FALSE; | 688 return FALSE; |
| 695 } | 689 } |
| 696 return m_pDict->GetBoolean("FB"); | 690 return m_pDict->GetBoolean("FB"); |
| 697 } | 691 } |
| 698 void SaveCheckedFieldStatus(CPDF_FormField* pField, | 692 void SaveCheckedFieldStatus(CPDF_FormField* pField, |
| 699 CFX_ByteArray& statusArray) { | 693 CFX_ByteArray& statusArray) { |
| 700 int iCount = pField->CountControls(); | 694 int iCount = pField->CountControls(); |
| 701 for (int i = 0; i < iCount; i++) { | 695 for (int i = 0; i < iCount; i++) { |
| 702 CPDF_FormControl* pControl = pField->GetControl(i); | 696 CPDF_FormControl* pControl = pField->GetControl(i); |
| 703 if (pControl == NULL) { | 697 if (!pControl) { |
| 704 continue; | 698 continue; |
| 705 } | 699 } |
| 706 statusArray.Add(pControl->IsChecked() ? 1 : 0); | 700 statusArray.Add(pControl->IsChecked() ? 1 : 0); |
| 707 } | 701 } |
| 708 } | 702 } |
| 709 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, | 703 CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, |
| 710 const FX_CHAR* name, | 704 const FX_CHAR* name, |
| 711 int nLevel) { | 705 int nLevel) { |
| 712 if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { | 706 if (nLevel > FPDFDOC_UTILS_MAXRECURSION) { |
| 713 return NULL; | 707 return NULL; |
| 714 } | 708 } |
| 715 if (pFieldDict == NULL) { | 709 if (!pFieldDict) { |
| 716 return NULL; | 710 return NULL; |
| 717 } | 711 } |
| 718 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); | 712 CPDF_Object* pAttr = pFieldDict->GetElementValue(name); |
| 719 if (pAttr) { | 713 if (pAttr) { |
| 720 return pAttr; | 714 return pAttr; |
| 721 } | 715 } |
| 722 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); | 716 CPDF_Dictionary* pParent = pFieldDict->GetDict("Parent"); |
| 723 if (pParent == NULL) { | 717 if (!pParent) { |
| 724 return NULL; | 718 return NULL; |
| 725 } | 719 } |
| 726 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); | 720 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); |
| 727 } | 721 } |
| OLD | NEW |