summaryrefslogtreecommitdiff
path: root/core/fpdfapi/font/cpdf_simplefont.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-07 23:36:56 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-07 23:36:56 +0000
commitf90277e7f4bd99bba419b53341c6c7bdca478eed (patch)
treedeee5f1b80610ef68440dd4924a44a75c1cdab50 /core/fpdfapi/font/cpdf_simplefont.cpp
parent52c0fcbaf99940a51a1179f035949eab7fc67352 (diff)
downloadpdfium-f90277e7f4bd99bba419b53341c6c7bdca478eed.tar.xz
Move CPDF_Font::LoadPDFEncoding() to CPDF_SimpleFont.
It is not used in the CPDF_Font base class. Change-Id: I6033a5dd422179eb95f19a2f2ecf06d007f3223f Reviewed-on: https://pdfium-review.googlesource.com/39493 Reviewed-by: Nicolás Peña Moreno <npm@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'core/fpdfapi/font/cpdf_simplefont.cpp')
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.cpp83
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;