diff options
author | Nicolas Pena <npm@chromium.org> | 2018-06-20 20:56:14 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-06-20 20:56:14 +0000 |
commit | cc4802edc4faee4bafae5219e94a5a22bfbb684b (patch) | |
tree | 68ac60938d559e95cc72d4b1af7f77757fbd6d90 | |
parent | c62e8489042c5efaa3b666846b38a52da3b91481 (diff) | |
download | pdfium-cc4802edc4faee4bafae5219e94a5a22bfbb684b.tar.xz |
Fix a couple of CPDF_DefaultAppearance::GetFont usageschromium/3467
Bug: 853238
Change-Id: I133be340fd877e9acd2733845d454924dc86d295
Reviewed-on: https://pdfium-review.googlesource.com/35711
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
-rw-r--r-- | core/fpdfdoc/cpvt_generateap.cpp | 25 | ||||
-rw-r--r-- | 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<CPDF_Dictionary>(); pFontDict->SetNewFor<CPDF_Name>("Type", "Font"); pFontDict->SetNewFor<CPDF_Name>("Subtype", "Type1"); pFontDict->SetNewFor<CPDF_Name>("BaseFont", CFX_Font::kDefaultAnsiFontName); pFontDict->SetNewFor<CPDF_Name>("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<CPDF_Dictionary>("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<CPDF_Dictionary>("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<ByteString> 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")) { |