From cc4802edc4faee4bafae5219e94a5a22bfbb684b Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Wed, 20 Jun 2018 20:56:14 +0000 Subject: Fix a couple of CPDF_DefaultAppearance::GetFont usages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 853238 Change-Id: I133be340fd877e9acd2733845d454924dc86d295 Reviewed-on: https://pdfium-review.googlesource.com/35711 Reviewed-by: Henrique Nakashima Commit-Queue: Nicolás Peña Moreno --- core/fpdfdoc/cpvt_generateap.cpp | 25 ++++++++++--------------- fpdfsdk/formfiller/cba_fontmap.cpp | 7 +------ 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp index a582feb2cb..28598c1959 100644 --- a/core/fpdfdoc/cpvt_generateap.cpp +++ b/core/fpdfdoc/cpvt_generateap.cpp @@ -929,10 +929,7 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, if (!font) return; - ByteString sFontName = PDF_NameDecode(font->AsStringView()); - if (sFontName.IsEmpty()) - return; - + ByteString font_name = *font; CFX_Color crText = CFX_Color::ParseColor(DA); CPDF_Dictionary* pDRDict = pFormDict->GetDictFor("DR"); if (!pDRDict) @@ -942,16 +939,14 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, if (!pDRFontDict) return; - CPDF_Dictionary* pFontDict = - pDRFontDict->GetDictFor(sFontName.Right(sFontName.GetLength() - 1)); + CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(font_name); if (!pFontDict) { pFontDict = pDoc->NewIndirect(); pFontDict->SetNewFor("Type", "Font"); pFontDict->SetNewFor("Subtype", "Type1"); pFontDict->SetNewFor("BaseFont", CFX_Font::kDefaultAnsiFontName); pFontDict->SetNewFor("Encoding", "WinAnsiEncoding"); - pDRFontDict->SetFor(sFontName.Right(sFontName.GetLength() - 1), - pFontDict->MakeReference(pDoc)); + pDRFontDict->SetFor(font_name, pFontDict->MakeReference(pDoc)); } CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict); if (!pDefFont) @@ -1071,8 +1066,8 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); if (!pStreamResFontList) pStreamResFontList = pStreamResList->SetNewFor("Font"); - if (!pStreamResFontList->KeyExist(sFontName)) { - pStreamResFontList->SetFor(sFontName, pFontDict->MakeReference(pDoc)); + if (!pStreamResFontList->KeyExist(font_name)) { + pStreamResFontList->SetFor(font_name, pFontDict->MakeReference(pDoc)); } } else { pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); @@ -1097,7 +1092,7 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, : 0; CPVT_FontMap map( pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, - pDefFont, sFontName.Right(sFontName.GetLength() - 1)); + pDefFont, font_name); CPDF_VariableText::Provider prd(&map); CPDF_VariableText vt; vt.SetProvider(&prd); @@ -1158,7 +1153,7 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, : WideString(); CPVT_FontMap map( pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, - pDefFont, sFontName.Right(sFontName.GetLength() - 1)); + pDefFont, font_name); CPDF_VariableText::Provider prd(&map); CPDF_VariableText vt; vt.SetProvider(&prd); @@ -1226,7 +1221,7 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, case CPVT_GenerateAP::kListBox: { CPVT_FontMap map( pDoc, pStreamDict ? pStreamDict->GetDictFor("Resources") : nullptr, - pDefFont, sFontName.Right(sFontName.GetLength() - 1)); + pDefFont, font_name); CPDF_VariableText::Provider prd(&map); CPDF_Array* pOpts = ToArray(FPDF_GetFieldAttr(pAnnotDict, "Opt")); CPDF_Array* pSels = ToArray(FPDF_GetFieldAttr(pAnnotDict, "I")); @@ -1318,8 +1313,8 @@ void CPVT_GenerateAP::GenerateFormAP(Type type, pStreamResFontList = pStreamResList->SetNewFor("Font"); } - if (!pStreamResFontList->KeyExist(sFontName)) { - pStreamResFontList->SetFor(sFontName, pFontDict->MakeReference(pDoc)); + if (!pStreamResFontList->KeyExist(font_name)) { + pStreamResFontList->SetFor(font_name, pFontDict->MakeReference(pDoc)); } } else { pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone()); diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index d8d7dffd69..08a3021a73 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -218,12 +218,7 @@ CPDF_Font* CBA_FontMap::GetAnnotDefaultFont(ByteString* sAlias) { CPDF_DefaultAppearance appearance(sDA); float font_size; Optional font = appearance.GetFont(&font_size); - if (font) { - ByteString sDecodedFontName = PDF_NameDecode(font->AsStringView()); - *sAlias = sDecodedFontName.Right(sDecodedFontName.GetLength() - 1); - } else { - *sAlias = ByteString(); - } + *sAlias = font.value_or(ByteString()); CPDF_Dictionary* pFontDict = nullptr; if (CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP")) { -- cgit v1.2.3