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

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

Issue 2083943003: Use FXFONT defines in place of integers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 4 years, 6 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/doc_form.cpp ('k') | core/fpdfdoc/include/cpdf_variabletext.h » ('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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 10 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 CPDF_SimpleParser syntax(m_csDA.AsStringC()); 260 CPDF_SimpleParser syntax(m_csDA.AsStringC());
261 if (syntax.FindTagParamFromStart("Tm", 6)) { 261 if (syntax.FindTagParamFromStart("Tm", 6)) {
262 FX_FLOAT f[6]; 262 FX_FLOAT f[6];
263 for (int i = 0; i < 6; i++) { 263 for (int i = 0; i < 6; i++) {
264 f[i] = FX_atof(syntax.GetWord()); 264 f[i] = FX_atof(syntax.GetWord());
265 } 265 }
266 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]); 266 tm.Set(f[0], f[1], f[2], f[3], f[4], f[5]);
267 } 267 }
268 return tm; 268 return tm;
269 } 269 }
270
270 void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { 271 void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
271 if (!pDocument) { 272 if (!pDocument)
272 return; 273 return;
273 } 274
274 if (!pFormDict) { 275 if (!pFormDict) {
275 pFormDict = new CPDF_Dictionary; 276 pFormDict = new CPDF_Dictionary;
276 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict); 277 uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict);
277 CPDF_Dictionary* pRoot = pDocument->GetRoot(); 278 CPDF_Dictionary* pRoot = pDocument->GetRoot();
278 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum); 279 pRoot->SetAtReference("AcroForm", pDocument, dwObjNum);
279 } 280 }
280 CFX_ByteString csDA; 281 CFX_ByteString csDA;
281 if (!pFormDict->KeyExist("DR")) { 282 if (!pFormDict->KeyExist("DR")) {
282 CFX_ByteString csBaseName; 283 CFX_ByteString csBaseName;
283 CFX_ByteString csDefault; 284 CFX_ByteString csDefault;
284 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 285 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
285 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); 286 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
286 if (pFont) { 287 if (pFont) {
287 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); 288 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName);
288 csDefault = csBaseName; 289 csDefault = csBaseName;
289 } 290 }
290 if (charSet != 0) { 291 if (charSet != FXFONT_ANSI_CHARSET) {
291 CFX_ByteString csFontName = 292 CFX_ByteString csFontName =
292 CPDF_InterForm::GetNativeFont(charSet, nullptr); 293 CPDF_InterForm::GetNativeFont(charSet, nullptr);
293 if (!pFont || csFontName != "Helvetica") { 294 if (!pFont || csFontName != "Helvetica") {
294 pFont = CPDF_InterForm::AddNativeFont(pDocument); 295 pFont = CPDF_InterForm::AddNativeFont(pDocument);
295 if (pFont) { 296 if (pFont) {
296 csBaseName = ""; 297 csBaseName = "";
297 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName); 298 AddInterFormFont(pFormDict, pDocument, pFont, csBaseName);
298 csDefault = csBaseName; 299 csDefault = csBaseName;
299 } 300 }
300 } 301 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 if (!pSubst) { 472 if (!pSubst) {
472 continue; 473 continue;
473 } 474 }
474 if (pSubst->m_Charset == (int)charSet) { 475 if (pSubst->m_Charset == (int)charSet) {
475 csNameTag = csKey; 476 csNameTag = csKey;
476 return pFind; 477 return pFind;
477 } 478 }
478 } 479 }
479 return nullptr; 480 return nullptr;
480 } 481 }
482
481 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict, 483 CPDF_Font* GetNativeInterFormFont(CPDF_Dictionary* pFormDict,
482 CPDF_Document* pDocument, 484 CPDF_Document* pDocument,
483 CFX_ByteString& csNameTag) { 485 CFX_ByteString& csNameTag) {
484 csNameTag = ""; 486 csNameTag.clear();
485 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 487 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
486 CFX_SubstFont* pSubst;
487 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument); 488 CPDF_Font* pFont = GetDefaultInterFormFont(pFormDict, pDocument);
488 if (pFont) { 489 if (pFont) {
489 pSubst = pFont->GetSubstFont(); 490 CFX_SubstFont* pSubst = pFont->GetSubstFont();
490 if (pSubst && pSubst->m_Charset == (int)charSet) { 491 if (pSubst && pSubst->m_Charset == (int)charSet) {
491 FindInterFormFont(pFormDict, pFont, csNameTag); 492 FindInterFormFont(pFormDict, pFont, csNameTag);
492 return pFont; 493 return pFont;
493 } 494 }
494 } 495 }
495 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); 496 return GetNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag);
496 } 497 }
498
497 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict, 499 FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
498 const CPDF_Font* pFont, 500 const CPDF_Font* pFont,
499 CFX_ByteString& csNameTag) { 501 CFX_ByteString& csNameTag) {
500 if (!pFormDict || !pFont) { 502 if (!pFormDict || !pFont) {
501 return FALSE; 503 return FALSE;
502 } 504 }
503 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); 505 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
504 if (!pDR) { 506 if (!pDR) {
505 return FALSE; 507 return FALSE;
506 } 508 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 InitInterFormDict(pFormDict, pDocument); 618 InitInterFormDict(pFormDict, pDocument);
617 } 619 }
618 CFX_ByteString csTemp; 620 CFX_ByteString csTemp;
619 CPDF_Font* pFont = 621 CPDF_Font* pFont =
620 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp); 622 GetNativeInterFormFont(pFormDict, pDocument, charSet, csTemp);
621 if (pFont) { 623 if (pFont) {
622 csNameTag = csTemp; 624 csNameTag = csTemp;
623 return pFont; 625 return pFont;
624 } 626 }
625 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet); 627 CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet);
626 if (!csFontName.IsEmpty()) { 628 if (!csFontName.IsEmpty() &&
627 if (FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) { 629 FindInterFormFont(pFormDict, pDocument, csFontName, pFont, csNameTag)) {
628 return pFont; 630 return pFont;
629 }
630 } 631 }
631 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument); 632 pFont = CPDF_InterForm::AddNativeFont(charSet, pDocument);
632 if (pFont) { 633 if (pFont) {
633 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag); 634 AddInterFormFont(pFormDict, pDocument, pFont, csNameTag);
634 } 635 }
635 return pFont; 636 return pFont;
636 } 637 }
637 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, 638 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict,
638 CPDF_Document* pDocument, 639 CPDF_Document* pDocument,
639 CFX_ByteString& csNameTag) { 640 CFX_ByteString& csNameTag) {
640 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 641 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
641 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag); 642 return AddNativeInterFormFont(pFormDict, pDocument, charSet, csNameTag);
642 } 643 }
643 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) { 644 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, const CPDF_Font* pFont) {
644 if (!pFormDict || !pFont) { 645 if (!pFormDict || !pFont) {
645 return; 646 return;
646 } 647 }
647 CFX_ByteString csTag; 648 CFX_ByteString csTag;
648 if (!FindInterFormFont(pFormDict, pFont, csTag)) { 649 if (!FindInterFormFont(pFormDict, pFont, csTag)) {
649 return; 650 return;
650 } 651 }
651 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); 652 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
652 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); 653 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
653 pFonts->RemoveAt(csTag); 654 pFonts->RemoveAt(csTag);
654 } 655 }
656
655 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) { 657 void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) {
656 if (!pFormDict || csNameTag.IsEmpty()) { 658 if (!pFormDict || csNameTag.IsEmpty()) {
657 return; 659 return;
658 } 660 }
659 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR"); 661 CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
660 if (!pDR) { 662 if (!pDR) {
661 return; 663 return;
662 } 664 }
663 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font"); 665 CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
664 if (!pFonts) { 666 if (!pFonts) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name); 746 CPDF_Object* pAttr = pFieldDict->GetDirectObjectBy(name);
745 if (pAttr) { 747 if (pAttr) {
746 return pAttr; 748 return pAttr;
747 } 749 }
748 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent"); 750 CPDF_Dictionary* pParent = pFieldDict->GetDictBy("Parent");
749 if (!pParent) { 751 if (!pParent) {
750 return nullptr; 752 return nullptr;
751 } 753 }
752 return FPDF_GetFieldAttr(pParent, name, nLevel + 1); 754 return FPDF_GetFieldAttr(pParent, name, nLevel + 1);
753 } 755 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/doc_form.cpp ('k') | core/fpdfdoc/include/cpdf_variabletext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698