diff options
Diffstat (limited to 'core/fpdfapi/font/cpdf_simplefont.cpp')
-rw-r--r-- | core/fpdfapi/font/cpdf_simplefont.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp index e646c14ba8..76f1c7cbd1 100644 --- a/core/fpdfapi/font/cpdf_simplefont.cpp +++ b/core/fpdfapi/font/cpdf_simplefont.cpp @@ -8,9 +8,25 @@ #include "core/fpdfapi/parser/cpdf_array.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_name.h" #include "core/fxge/fx_freetype.h" #include "third_party/base/numerics/safe_math.h" +namespace { + +void GetPredefinedEncoding(const ByteString& value, int* basemap) { + if (value == "WinAnsiEncoding") + *basemap = PDFFONT_ENCODING_WINANSI; + else if (value == "MacRomanEncoding") + *basemap = PDFFONT_ENCODING_MACROMAN; + else if (value == "MacExpertEncoding") + *basemap = PDFFONT_ENCODING_MACEXPERT; + else if (value == "PDFDocEncoding") + *basemap = PDFFONT_ENCODING_PDFDOC; +} + +} // namespace + CPDF_SimpleFont::CPDF_SimpleFont(CPDF_Document* pDocument, CPDF_Dictionary* pFontDict) : CPDF_Font(pDocument, pFontDict) { @@ -82,6 +98,73 @@ void CPDF_SimpleFont::LoadCharMetrics(int charcode) { } } +void CPDF_SimpleFont::LoadPDFEncoding(CPDF_Object* pEncoding, + int& iBaseEncoding, + std::vector<ByteString>* pCharNames, + bool bEmbedded, + bool bTrueType) { + if (!pEncoding) { + if (m_BaseFont == "Symbol") { + iBaseEncoding = bTrueType ? PDFFONT_ENCODING_MS_SYMBOL + : PDFFONT_ENCODING_ADOBE_SYMBOL; + } else if (!bEmbedded && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) { + iBaseEncoding = PDFFONT_ENCODING_WINANSI; + } + return; + } + if (pEncoding->IsName()) { + if (iBaseEncoding == PDFFONT_ENCODING_ADOBE_SYMBOL || + iBaseEncoding == PDFFONT_ENCODING_ZAPFDINGBATS) { + return; + } + if (FontStyleIsSymbolic(m_Flags) && m_BaseFont == "Symbol") { + if (!bTrueType) + iBaseEncoding = PDFFONT_ENCODING_ADOBE_SYMBOL; + return; + } + ByteString bsEncoding = pEncoding->GetString(); + if (bsEncoding.Compare("MacExpertEncoding") == 0) { + bsEncoding = "WinAnsiEncoding"; + } + GetPredefinedEncoding(bsEncoding, &iBaseEncoding); + return; + } + + CPDF_Dictionary* pDict = pEncoding->AsDictionary(); + if (!pDict) + return; + + if (iBaseEncoding != PDFFONT_ENCODING_ADOBE_SYMBOL && + iBaseEncoding != PDFFONT_ENCODING_ZAPFDINGBATS) { + ByteString bsEncoding = pDict->GetStringFor("BaseEncoding"); + if (bTrueType && bsEncoding.Compare("MacExpertEncoding") == 0) + bsEncoding = "WinAnsiEncoding"; + GetPredefinedEncoding(bsEncoding, &iBaseEncoding); + } + if ((!bEmbedded || bTrueType) && iBaseEncoding == PDFFONT_ENCODING_BUILTIN) + iBaseEncoding = PDFFONT_ENCODING_STANDARD; + + CPDF_Array* pDiffs = pDict->GetArrayFor("Differences"); + if (!pDiffs) + return; + + pCharNames->resize(256); + uint32_t cur_code = 0; + for (uint32_t i = 0; i < pDiffs->GetCount(); i++) { + CPDF_Object* pElement = pDiffs->GetDirectObjectAt(i); + if (!pElement) + continue; + + if (CPDF_Name* pName = pElement->AsName()) { + if (cur_code < 256) + (*pCharNames)[cur_code] = pName->GetString(); + cur_code++; + } else { + cur_code = pElement->GetInteger(); + } + } +} + uint32_t CPDF_SimpleFont::GetCharWidthF(uint32_t charcode) { if (charcode > 0xff) charcode = 0; |