summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp78
-rw-r--r--core/fpdfapi/font/cpdf_font.h5
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.cpp83
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.h5
4 files changed, 88 insertions, 83 deletions
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 110770a604..a243ceb334 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -39,17 +39,6 @@ const uint8_t kChineseFontNames[][kChineseFontNameSize] = {
{0xB7, 0xC2, 0xCB, 0xCE},
{0xD0, 0xC2, 0xCB, 0xCE}};
-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_Font::CPDF_Font(CPDF_Document* pDocument, CPDF_Dictionary* pFontDict)
@@ -350,73 +339,6 @@ uint32_t CPDF_Font::GetNextChar(const ByteStringView& pString,
return static_cast<uint32_t>(ch);
}
-void CPDF_Font::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();
- }
- }
-}
-
bool CPDF_Font::IsStandardFont() const {
if (!IsType1Font())
return false;
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index c3194110cb..0174a67ef8 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -96,11 +96,6 @@ class CPDF_Font {
virtual bool Load() = 0;
void LoadUnicodeMap() const; // logically const only.
- void LoadPDFEncoding(CPDF_Object* pEncoding,
- int& iBaseEncoding,
- std::vector<ByteString>* pCharNames,
- bool bEmbedded,
- bool bTrueType);
void LoadFontDescriptor(const CPDF_Dictionary* pDict);
void CheckFontMetrics();
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;
diff --git a/core/fpdfapi/font/cpdf_simplefont.h b/core/fpdfapi/font/cpdf_simplefont.h
index 77df55bf99..659ad0fa68 100644
--- a/core/fpdfapi/font/cpdf_simplefont.h
+++ b/core/fpdfapi/font/cpdf_simplefont.h
@@ -37,6 +37,11 @@ class CPDF_SimpleFont : public CPDF_Font {
bool LoadCommon();
void LoadSubstFont();
void LoadCharMetrics(int charcode);
+ void LoadPDFEncoding(CPDF_Object* pEncoding,
+ int& iBaseEncoding,
+ std::vector<ByteString>* pCharNames,
+ bool bEmbedded,
+ bool bTrueType);
CPDF_FontEncoding m_Encoding;
int m_BaseEncoding = PDFFONT_ENCODING_BUILTIN;