summaryrefslogtreecommitdiff
path: root/core/fpdfapi/font
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/font')
-rw-r--r--core/fpdfapi/font/cfx_cttgsubtable.cpp (renamed from core/fpdfapi/font/ttgsubtable.cpp)2
-rw-r--r--core/fpdfapi/font/cfx_cttgsubtable.h (renamed from core/fpdfapi/font/ttgsubtable.h)6
-rw-r--r--core/fpdfapi/font/cfx_stockfontarray.cpp35
-rw-r--r--core/fpdfapi/font/cfx_stockfontarray.h27
-rw-r--r--core/fpdfapi/font/cpdf_cid2unicodemap.cpp42
-rw-r--r--core/fpdfapi/font/cpdf_cid2unicodemap.h29
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp10
-rw-r--r--core/fpdfapi/font/cpdf_cmap.cpp (renamed from core/fpdfapi/font/fpdf_font_cid.cpp)270
-rw-r--r--core/fpdfapi/font/cpdf_cmap.h87
-rw-r--r--core/fpdfapi/font/cpdf_cmapmanager.cpp59
-rw-r--r--core/fpdfapi/font/cpdf_cmapmanager.h36
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser.cpp204
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser.h52
-rw-r--r--core/fpdfapi/font/cpdf_cmapparser_unittest.cpp (renamed from core/fpdfapi/font/fpdf_font_cid_unittest.cpp)7
-rw-r--r--core/fpdfapi/font/cpdf_font.cpp25
-rw-r--r--core/fpdfapi/font/cpdf_font.h4
-rw-r--r--core/fpdfapi/font/cpdf_fontglobals.cpp39
-rw-r--r--core/fpdfapi/font/cpdf_fontglobals.h45
-rw-r--r--core/fpdfapi/font/cpdf_simplefont.cpp1
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap.cpp (renamed from core/fpdfapi/font/fpdf_font.cpp)87
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap.h42
-rw-r--r--core/fpdfapi/font/cpdf_tounicodemap_unittest.cpp (renamed from core/fpdfapi/font/fpdf_font_unittest.cpp)7
-rw-r--r--core/fpdfapi/font/cpdf_truetypefont.cpp1
-rw-r--r--core/fpdfapi/font/cpdf_type1font.cpp1
-rw-r--r--core/fpdfapi/font/font_int.h229
25 files changed, 750 insertions, 597 deletions
diff --git a/core/fpdfapi/font/ttgsubtable.cpp b/core/fpdfapi/font/cfx_cttgsubtable.cpp
index b8d6946657..902957a436 100644
--- a/core/fpdfapi/font/ttgsubtable.cpp
+++ b/core/fpdfapi/font/cfx_cttgsubtable.cpp
@@ -4,7 +4,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fpdfapi/font/ttgsubtable.h"
+#include "core/fpdfapi/font/cfx_cttgsubtable.h"
#include <utility>
diff --git a/core/fpdfapi/font/ttgsubtable.h b/core/fpdfapi/font/cfx_cttgsubtable.h
index c3bff43957..aac3f86c07 100644
--- a/core/fpdfapi/font/ttgsubtable.h
+++ b/core/fpdfapi/font/cfx_cttgsubtable.h
@@ -4,8 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef CORE_FPDFAPI_FONT_TTGSUBTABLE_H_
-#define CORE_FPDFAPI_FONT_TTGSUBTABLE_H_
+#ifndef CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_
+#define CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_
#include <stdint.h>
@@ -295,4 +295,4 @@ class CFX_CTTGSUBTable {
TLookupList LookupList;
};
-#endif // CORE_FPDFAPI_FONT_TTGSUBTABLE_H_
+#endif // CORE_FPDFAPI_FONT_CFX_CTTGSUBTABLE_H_
diff --git a/core/fpdfapi/font/cfx_stockfontarray.cpp b/core/fpdfapi/font/cfx_stockfontarray.cpp
new file mode 100644
index 0000000000..0808471c82
--- /dev/null
+++ b/core/fpdfapi/font/cfx_stockfontarray.cpp
@@ -0,0 +1,35 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/font/cfx_stockfontarray.h"
+
+#include <memory>
+#include <utility>
+
+#include "core/fxcrt/fx_memory.h"
+
+CFX_StockFontArray::CFX_StockFontArray() {}
+
+CFX_StockFontArray::~CFX_StockFontArray() {
+ for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) {
+ if (m_StockFonts[i])
+ delete m_StockFonts[i]->GetFontDict();
+ }
+}
+
+CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const {
+ if (index >= FX_ArraySize(m_StockFonts))
+ return nullptr;
+ return m_StockFonts[index].get();
+}
+
+CPDF_Font* CFX_StockFontArray::SetFont(uint32_t index,
+ std::unique_ptr<CPDF_Font> pFont) {
+ CPDF_Font* result = pFont.get();
+ if (index < FX_ArraySize(m_StockFonts))
+ m_StockFonts[index] = std::move(pFont);
+ return result;
+}
diff --git a/core/fpdfapi/font/cfx_stockfontarray.h b/core/fpdfapi/font/cfx_stockfontarray.h
new file mode 100644
index 0000000000..50a13c167f
--- /dev/null
+++ b/core/fpdfapi/font/cfx_stockfontarray.h
@@ -0,0 +1,27 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CFX_STOCKFONTARRAY_H_
+#define CORE_FPDFAPI_FONT_CFX_STOCKFONTARRAY_H_
+
+#include <memory>
+
+#include "core/fpdfapi/font/cpdf_font.h"
+
+class CFX_StockFontArray {
+ public:
+ CFX_StockFontArray();
+ ~CFX_StockFontArray();
+
+ // Takes ownership of |pFont|, returns unowned pointer to it.
+ CPDF_Font* SetFont(uint32_t index, std::unique_ptr<CPDF_Font> pFont);
+ CPDF_Font* GetFont(uint32_t index) const;
+
+ private:
+ std::unique_ptr<CPDF_Font> m_StockFonts[14];
+};
+
+#endif // CORE_FPDFAPI_FONT_CFX_STOCKFONTARRAY_H_
diff --git a/core/fpdfapi/font/cpdf_cid2unicodemap.cpp b/core/fpdfapi/font/cpdf_cid2unicodemap.cpp
new file mode 100644
index 0000000000..cb378aa9d6
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cid2unicodemap.cpp
@@ -0,0 +1,42 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/font/cpdf_cid2unicodemap.h"
+
+#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/font/cpdf_cmapmanager.h"
+#include "core/fpdfapi/page/cpdf_pagemodule.h"
+
+CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() {
+ m_EmbeddedCount = 0;
+}
+
+CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() {}
+
+bool CPDF_CID2UnicodeMap::IsLoaded() {
+ return m_EmbeddedCount != 0;
+}
+
+wchar_t CPDF_CID2UnicodeMap::UnicodeFromCID(uint16_t CID) {
+ if (m_Charset == CIDSET_UNICODE) {
+ return CID;
+ }
+ if (CID < m_EmbeddedCount) {
+ return m_pEmbeddedMap[CID];
+ }
+ return 0;
+}
+
+void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr,
+ CIDSet charset,
+ bool bPromptCJK) {
+ m_Charset = charset;
+
+ CPDF_FontGlobals* pFontGlobals =
+ CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
+ m_pEmbeddedMap = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
+ m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
+}
diff --git a/core/fpdfapi/font/cpdf_cid2unicodemap.h b/core/fpdfapi/font/cpdf_cid2unicodemap.h
new file mode 100644
index 0000000000..2c3fe5b7aa
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cid2unicodemap.h
@@ -0,0 +1,29 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_
+#define CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_
+
+#include "core/fpdfapi/font/cpdf_cidfont.h"
+
+class CPDF_CMapManager;
+
+class CPDF_CID2UnicodeMap {
+ public:
+ CPDF_CID2UnicodeMap();
+ ~CPDF_CID2UnicodeMap();
+
+ bool IsLoaded();
+ void Load(CPDF_CMapManager* pMgr, CIDSet charset, bool bPromptCJK);
+ wchar_t UnicodeFromCID(uint16_t CID);
+
+ private:
+ CIDSet m_Charset;
+ const uint16_t* m_pEmbeddedMap;
+ uint32_t m_EmbeddedCount;
+};
+
+#endif // CORE_FPDFAPI_FONT_CPDF_CID2UNICODEMAP_H_
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index c41f8046f7..8cb59de739 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -12,9 +12,11 @@
#include "core/fpdfapi/cmaps/cmap_int.h"
#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/font/cfx_cttgsubtable.h"
+#include "core/fpdfapi/font/cpdf_cid2unicodemap.h"
+#include "core/fpdfapi/font/cpdf_cmap.h"
+#include "core/fpdfapi/font/cpdf_cmapparser.h"
#include "core/fpdfapi/font/cpdf_fontencoding.h"
-#include "core/fpdfapi/font/font_int.h"
-#include "core/fpdfapi/font/ttgsubtable.h"
#include "core/fpdfapi/page/cpdf_pagemodule.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -377,8 +379,8 @@ bool CPDF_CIDFont::Load() {
if (m_Charset == CIDSET_UNKNOWN) {
CPDF_Dictionary* pCIDInfo = pCIDFontDict->GetDictFor("CIDSystemInfo");
if (pCIDInfo) {
- m_Charset =
- CharsetFromOrdering(pCIDInfo->GetStringFor("Ordering").AsStringC());
+ m_Charset = CPDF_CMapParser::CharsetFromOrdering(
+ pCIDInfo->GetStringFor("Ordering").AsStringC());
}
}
if (m_Charset != CIDSET_UNKNOWN) {
diff --git a/core/fpdfapi/font/fpdf_font_cid.cpp b/core/fpdfapi/font/cpdf_cmap.cpp
index dd37551b2d..55f5ccc5c5 100644
--- a/core/fpdfapi/font/fpdf_font_cid.cpp
+++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -1,31 +1,22 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fpdfapi/font/font_int.h"
+#include "core/fpdfapi/font/cpdf_cmap.h"
#include <memory>
#include <utility>
#include <vector>
#include "core/fpdfapi/cmaps/cmap_int.h"
-#include "core/fpdfapi/cpdf_modulemgr.h"
-#include "core/fpdfapi/font/ttgsubtable.h"
-#include "core/fpdfapi/page/cpdf_pagemodule.h"
-#include "core/fpdfapi/parser/cpdf_array.h"
-#include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fpdfapi/font/cpdf_cmapmanager.h"
+#include "core/fpdfapi/font/cpdf_cmapparser.h"
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
-#include "core/fxcrt/fx_extension.h"
-#include "core/fxge/fx_freetype.h"
-#include "third_party/base/logging.h"
-#include "third_party/base/stl_util.h"
namespace {
-const char* const g_CharsetNames[CIDSET_NUM_SETS] = {nullptr, "GB1", "CNS1",
- "Japan1", "Korea1", "UCS"};
struct ByteRange {
uint8_t m_First;
uint8_t m_Last; // Inclusive.
@@ -190,20 +181,6 @@ const PredefinedCMap g_PredefinedCMaps[] = {
{"UniKS-UTF16", CIDSET_KOREA1, CIDCODING_UTF16, CPDF_CMap::TwoBytes, 0, {}},
};
-CIDSet CIDSetFromSizeT(size_t index) {
- if (index >= CIDSET_NUM_SETS) {
- NOTREACHED();
- return CIDSET_UNKNOWN;
- }
- return static_cast<CIDSet>(index);
-}
-
-CFX_ByteStringC CMap_GetString(const CFX_ByteStringC& word) {
- if (word.GetLength() <= 2)
- return CFX_ByteStringC();
- return CFX_ByteStringC(&word[1], word.GetLength() - 2);
-}
-
int CheckFourByteCodeRange(uint8_t* codes,
int size,
const std::vector<CPDF_CMap::CodeRange>& ranges) {
@@ -268,206 +245,6 @@ int GetFourByteCharSizeImpl(uint32_t charcode,
} // namespace
-CPDF_CMapManager::CPDF_CMapManager() {}
-
-CPDF_CMapManager::~CPDF_CMapManager() {}
-
-CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(
- const CFX_ByteString& name,
- bool bPromptCJK) {
- auto it = m_CMaps.find(name);
- if (it != m_CMaps.end())
- return it->second;
-
- CFX_RetainPtr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK);
- if (!name.IsEmpty())
- m_CMaps[name] = pCMap;
-
- return pCMap;
-}
-
-CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(
- const CFX_ByteString& name,
- bool bPromptCJK) {
- const char* pname = name.c_str();
- if (*pname == '/')
- pname++;
-
- auto pCMap = pdfium::MakeRetain<CPDF_CMap>();
- pCMap->LoadPredefined(this, pname, bPromptCJK);
- return pCMap;
-}
-
-CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset,
- bool bPromptCJK) {
- if (!m_CID2UnicodeMaps[charset])
- m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
-
- return m_CID2UnicodeMaps[charset].get();
-}
-
-std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap(
- CIDSet charset,
- bool bPromptCJK) {
- auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>();
- pMap->Load(this, charset, bPromptCJK);
- return pMap;
-}
-
-CPDF_CMapParser::CPDF_CMapParser(CPDF_CMap* pCMap)
- : m_pCMap(pCMap), m_Status(0), m_CodeSeq(0) {}
-
-CPDF_CMapParser::~CPDF_CMapParser() {}
-
-void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
- if (word.IsEmpty()) {
- return;
- }
- if (word == "begincidchar") {
- m_Status = 1;
- m_CodeSeq = 0;
- } else if (word == "begincidrange") {
- m_Status = 2;
- m_CodeSeq = 0;
- } else if (word == "endcidrange" || word == "endcidchar") {
- m_Status = 0;
- } else if (word == "/WMode") {
- m_Status = 6;
- } else if (word == "/Registry") {
- m_Status = 3;
- } else if (word == "/Ordering") {
- m_Status = 4;
- } else if (word == "/Supplement") {
- m_Status = 5;
- } else if (word == "begincodespacerange") {
- m_Status = 7;
- m_CodeSeq = 0;
- } else if (word == "usecmap") {
- } else if (m_Status == 1 || m_Status == 2) {
- m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
- m_CodeSeq++;
- uint32_t StartCode, EndCode;
- uint16_t StartCID;
- if (m_Status == 1) {
- if (m_CodeSeq < 2) {
- return;
- }
- EndCode = StartCode = m_CodePoints[0];
- StartCID = (uint16_t)m_CodePoints[1];
- } else {
- if (m_CodeSeq < 3) {
- return;
- }
- StartCode = m_CodePoints[0];
- EndCode = m_CodePoints[1];
- StartCID = (uint16_t)m_CodePoints[2];
- }
- if (EndCode < 0x10000) {
- for (uint32_t code = StartCode; code <= EndCode; code++) {
- m_pCMap->m_DirectCharcodeToCIDTable[code] =
- static_cast<uint16_t>(StartCID + code - StartCode);
- }
- } else {
- m_AdditionalCharcodeToCIDMappings.push_back(
- {StartCode, EndCode, StartCID});
- }
- m_CodeSeq = 0;
- } else if (m_Status == 3) {
- m_Status = 0;
- } else if (m_Status == 4) {
- m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word));
- m_Status = 0;
- } else if (m_Status == 5) {
- m_Status = 0;
- } else if (m_Status == 6) {
- m_pCMap->m_bVertical = CMap_GetCode(word) != 0;
- m_Status = 0;
- } else if (m_Status == 7) {
- if (word == "endcodespacerange") {
- uint32_t nSegs = pdfium::CollectionSize<uint32_t>(m_CodeRanges);
- if (nSegs > 1) {
- m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
- m_pCMap->m_MixedFourByteLeadingRanges = m_CodeRanges;
- } else if (nSegs == 1) {
- m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2)
- ? CPDF_CMap::TwoBytes
- : CPDF_CMap::OneByte;
- }
- m_Status = 0;
- } else {
- if (word.GetLength() == 0 || word.GetAt(0) != '<') {
- return;
- }
- if (m_CodeSeq % 2) {
- CPDF_CMap::CodeRange range;
- if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word))
- m_CodeRanges.push_back(range);
- }
- m_CodeSeq++;
- }
- }
- m_LastWord = word;
-}
-
-// Static.
-uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
- pdfium::base::CheckedNumeric<uint32_t> num = 0;
- if (word.GetAt(0) == '<') {
- for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) {
- num = num * 16 + FXSYS_HexCharToInt(word.GetAt(i));
- if (!num.IsValid())
- return 0;
- }
- return num.ValueOrDie();
- }
-
- for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) {
- num =
- num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word.GetAt(i)));
- if (!num.IsValid())
- return 0;
- }
- return num.ValueOrDie();
-}
-
-// Static.
-bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
- const CFX_ByteStringC& first,
- const CFX_ByteStringC& second) {
- if (first.GetLength() == 0 || first.GetAt(0) != '<')
- return false;
-
- int i;
- for (i = 1; i < first.GetLength(); ++i) {
- if (first.GetAt(i) == '>') {
- break;
- }
- }
- range.m_CharSize = (i - 1) / 2;
- if (range.m_CharSize > 4)
- return false;
-
- for (i = 0; i < range.m_CharSize; ++i) {
- uint8_t digit1 = first.GetAt(i * 2 + 1);
- uint8_t digit2 = first.GetAt(i * 2 + 2);
- range.m_Lower[i] =
- FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2);
- }
-
- uint32_t size = second.GetLength();
- for (i = 0; i < range.m_CharSize; ++i) {
- uint8_t digit1 = ((uint32_t)i * 2 + 1 < size)
- ? second.GetAt((FX_STRSIZE)i * 2 + 1)
- : '0';
- uint8_t digit2 = ((uint32_t)i * 2 + 2 < size)
- ? second.GetAt((FX_STRSIZE)i * 2 + 2)
- : '0';
- range.m_Upper[i] =
- FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2);
- }
- return true;
-}
-
CPDF_CMap::CPDF_CMap()
: m_bLoaded(false),
m_bVertical(false),
@@ -709,42 +486,3 @@ int CPDF_CMap::AppendChar(char* str, uint32_t charcode) const {
}
return 0;
}
-
-CPDF_CID2UnicodeMap::CPDF_CID2UnicodeMap() {
- m_EmbeddedCount = 0;
-}
-
-CPDF_CID2UnicodeMap::~CPDF_CID2UnicodeMap() {}
-
-bool CPDF_CID2UnicodeMap::IsLoaded() {
- return m_EmbeddedCount != 0;
-}
-
-wchar_t CPDF_CID2UnicodeMap::UnicodeFromCID(uint16_t CID) {
- if (m_Charset == CIDSET_UNICODE) {
- return CID;
- }
- if (CID < m_EmbeddedCount) {
- return m_pEmbeddedMap[CID];
- }
- return 0;
-}
-
-void CPDF_CID2UnicodeMap::Load(CPDF_CMapManager* pMgr,
- CIDSet charset,
- bool bPromptCJK) {
- m_Charset = charset;
-
- CPDF_FontGlobals* pFontGlobals =
- CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
- m_pEmbeddedMap = pFontGlobals->m_EmbeddedToUnicodes[charset].m_pMap;
- m_EmbeddedCount = pFontGlobals->m_EmbeddedToUnicodes[charset].m_Count;
-}
-
-CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering) {
- for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
- if (ordering == g_CharsetNames[charset])
- return CIDSetFromSizeT(charset);
- }
- return CIDSET_UNKNOWN;
-}
diff --git a/core/fpdfapi/font/cpdf_cmap.h b/core/fpdfapi/font/cpdf_cmap.h
new file mode 100644
index 0000000000..ab495efbfc
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cmap.h
@@ -0,0 +1,87 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CPDF_CMAP_H_
+#define CORE_FPDFAPI_FONT_CPDF_CMAP_H_
+
+#include <vector>
+
+#include "core/fpdfapi/font/cpdf_cidfont.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/fx_basic.h"
+
+class CPDF_CMapManager;
+struct FXCMAP_CMap;
+
+enum CIDCoding : uint8_t {
+ CIDCODING_UNKNOWN = 0,
+ CIDCODING_GB,
+ CIDCODING_BIG5,
+ CIDCODING_JIS,
+ CIDCODING_KOREA,
+ CIDCODING_UCS2,
+ CIDCODING_CID,
+ CIDCODING_UTF16,
+};
+
+class CPDF_CMap : public CFX_Retainable {
+ public:
+ enum CodingScheme : uint8_t {
+ OneByte,
+ TwoBytes,
+ MixedTwoBytes,
+ MixedFourBytes
+ };
+
+ struct CodeRange {
+ int m_CharSize;
+ uint8_t m_Lower[4];
+ uint8_t m_Upper[4];
+ };
+
+ struct CIDRange {
+ uint32_t m_StartCode;
+ uint32_t m_EndCode;
+ uint16_t m_StartCID;
+ };
+
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ void LoadPredefined(CPDF_CMapManager* pMgr,
+ const CFX_ByteString& name,
+ bool bPromptCJK);
+ void LoadEmbedded(const uint8_t* pData, uint32_t dwSize);
+
+ bool IsLoaded() const { return m_bLoaded; }
+ bool IsVertWriting() const { return m_bVertical; }
+ uint16_t CIDFromCharCode(uint32_t charcode) const;
+ int GetCharSize(uint32_t charcode) const;
+ uint32_t GetNextChar(const char* pString, int nStrLen, int& offset) const;
+ int CountChar(const char* pString, int size) const;
+ int AppendChar(char* str, uint32_t charcode) const;
+
+ private:
+ friend class CPDF_CMapParser;
+ friend class CPDF_CIDFont;
+
+ CPDF_CMap();
+ ~CPDF_CMap() override;
+
+ CFX_ByteString m_PredefinedCMap;
+ bool m_bLoaded;
+ bool m_bVertical;
+ CIDSet m_Charset;
+ CodingScheme m_CodingScheme;
+ int m_Coding;
+ std::vector<bool> m_MixedTwoByteLeadingBytes;
+ std::vector<CodeRange> m_MixedFourByteLeadingRanges;
+ std::vector<uint16_t> m_DirectCharcodeToCIDTable;
+ std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings;
+ const FXCMAP_CMap* m_pEmbedMap;
+};
+
+#endif // CORE_FPDFAPI_FONT_CPDF_CMAP_H_
diff --git a/core/fpdfapi/font/cpdf_cmapmanager.cpp b/core/fpdfapi/font/cpdf_cmapmanager.cpp
new file mode 100644
index 0000000000..040af5556a
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cmapmanager.cpp
@@ -0,0 +1,59 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/font/cpdf_cmapmanager.h"
+
+#include <utility>
+
+#include "core/fpdfapi/font/cpdf_cid2unicodemap.h"
+#include "core/fpdfapi/font/cpdf_cmap.h"
+#include "third_party/base/stl_util.h"
+
+CPDF_CMapManager::CPDF_CMapManager() {}
+
+CPDF_CMapManager::~CPDF_CMapManager() {}
+
+CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::GetPredefinedCMap(
+ const CFX_ByteString& name,
+ bool bPromptCJK) {
+ auto it = m_CMaps.find(name);
+ if (it != m_CMaps.end())
+ return it->second;
+
+ CFX_RetainPtr<CPDF_CMap> pCMap = LoadPredefinedCMap(name, bPromptCJK);
+ if (!name.IsEmpty())
+ m_CMaps[name] = pCMap;
+
+ return pCMap;
+}
+
+CFX_RetainPtr<CPDF_CMap> CPDF_CMapManager::LoadPredefinedCMap(
+ const CFX_ByteString& name,
+ bool bPromptCJK) {
+ const char* pname = name.c_str();
+ if (*pname == '/')
+ pname++;
+
+ auto pCMap = pdfium::MakeRetain<CPDF_CMap>();
+ pCMap->LoadPredefined(this, pname, bPromptCJK);
+ return pCMap;
+}
+
+CPDF_CID2UnicodeMap* CPDF_CMapManager::GetCID2UnicodeMap(CIDSet charset,
+ bool bPromptCJK) {
+ if (!m_CID2UnicodeMaps[charset])
+ m_CID2UnicodeMaps[charset] = LoadCID2UnicodeMap(charset, bPromptCJK);
+
+ return m_CID2UnicodeMaps[charset].get();
+}
+
+std::unique_ptr<CPDF_CID2UnicodeMap> CPDF_CMapManager::LoadCID2UnicodeMap(
+ CIDSet charset,
+ bool bPromptCJK) {
+ auto pMap = pdfium::MakeUnique<CPDF_CID2UnicodeMap>();
+ pMap->Load(this, charset, bPromptCJK);
+ return pMap;
+}
diff --git a/core/fpdfapi/font/cpdf_cmapmanager.h b/core/fpdfapi/font/cpdf_cmapmanager.h
new file mode 100644
index 0000000000..1bc1c6f839
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cmapmanager.h
@@ -0,0 +1,36 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CPDF_CMAPMANAGER_H_
+#define CORE_FPDFAPI_FONT_CPDF_CMAPMANAGER_H_
+
+#include <map>
+#include <memory>
+
+#include "core/fpdfapi/font/cpdf_cidfont.h"
+#include "core/fxcrt/cfx_bytestring.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
+
+class CPDF_CMapManager {
+ public:
+ CPDF_CMapManager();
+ ~CPDF_CMapManager();
+
+ CFX_RetainPtr<CPDF_CMap> GetPredefinedCMap(const CFX_ByteString& name,
+ bool bPromptCJK);
+ CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset, bool bPromptCJK);
+
+ private:
+ CFX_RetainPtr<CPDF_CMap> LoadPredefinedCMap(const CFX_ByteString& name,
+ bool bPromptCJK);
+ std::unique_ptr<CPDF_CID2UnicodeMap> LoadCID2UnicodeMap(CIDSet charset,
+ bool bPromptCJK);
+
+ std::map<CFX_ByteString, CFX_RetainPtr<CPDF_CMap>> m_CMaps;
+ std::unique_ptr<CPDF_CID2UnicodeMap> m_CID2UnicodeMaps[6];
+};
+
+#endif // CORE_FPDFAPI_FONT_CPDF_CMAPMANAGER_H_
diff --git a/core/fpdfapi/font/cpdf_cmapparser.cpp b/core/fpdfapi/font/cpdf_cmapparser.cpp
new file mode 100644
index 0000000000..0f9bca6018
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cmapparser.cpp
@@ -0,0 +1,204 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/font/cpdf_cmapparser.h"
+
+#include <vector>
+
+#include "core/fpdfapi/cmaps/cmap_int.h"
+#include "core/fpdfapi/cpdf_modulemgr.h"
+#include "core/fpdfapi/page/cpdf_pagemodule.h"
+#include "core/fpdfapi/parser/cpdf_array.h"
+#include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fpdfapi/parser/cpdf_simple_parser.h"
+#include "core/fxcrt/fx_extension.h"
+#include "core/fxge/fx_freetype.h"
+#include "third_party/base/logging.h"
+#include "third_party/base/stl_util.h"
+
+namespace {
+
+const char* const g_CharsetNames[CIDSET_NUM_SETS] = {nullptr, "GB1", "CNS1",
+ "Japan1", "Korea1", "UCS"};
+
+CIDSet CIDSetFromSizeT(size_t index) {
+ if (index >= CIDSET_NUM_SETS) {
+ NOTREACHED();
+ return CIDSET_UNKNOWN;
+ }
+ return static_cast<CIDSet>(index);
+}
+
+CFX_ByteStringC CMap_GetString(const CFX_ByteStringC& word) {
+ if (word.GetLength() <= 2)
+ return CFX_ByteStringC();
+ return CFX_ByteStringC(&word[1], word.GetLength() - 2);
+}
+
+} // namespace
+
+CPDF_CMapParser::CPDF_CMapParser(CPDF_CMap* pCMap)
+ : m_pCMap(pCMap), m_Status(0), m_CodeSeq(0) {}
+
+CPDF_CMapParser::~CPDF_CMapParser() {}
+
+void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
+ if (word.IsEmpty()) {
+ return;
+ }
+ if (word == "begincidchar") {
+ m_Status = 1;
+ m_CodeSeq = 0;
+ } else if (word == "begincidrange") {
+ m_Status = 2;
+ m_CodeSeq = 0;
+ } else if (word == "endcidrange" || word == "endcidchar") {
+ m_Status = 0;
+ } else if (word == "/WMode") {
+ m_Status = 6;
+ } else if (word == "/Registry") {
+ m_Status = 3;
+ } else if (word == "/Ordering") {
+ m_Status = 4;
+ } else if (word == "/Supplement") {
+ m_Status = 5;
+ } else if (word == "begincodespacerange") {
+ m_Status = 7;
+ m_CodeSeq = 0;
+ } else if (word == "usecmap") {
+ } else if (m_Status == 1 || m_Status == 2) {
+ m_CodePoints[m_CodeSeq] = CMap_GetCode(word);
+ m_CodeSeq++;
+ uint32_t StartCode, EndCode;
+ uint16_t StartCID;
+ if (m_Status == 1) {
+ if (m_CodeSeq < 2) {
+ return;
+ }
+ EndCode = StartCode = m_CodePoints[0];
+ StartCID = (uint16_t)m_CodePoints[1];
+ } else {
+ if (m_CodeSeq < 3) {
+ return;
+ }
+ StartCode = m_CodePoints[0];
+ EndCode = m_CodePoints[1];
+ StartCID = (uint16_t)m_CodePoints[2];
+ }
+ if (EndCode < 0x10000) {
+ for (uint32_t code = StartCode; code <= EndCode; code++) {
+ m_pCMap->m_DirectCharcodeToCIDTable[code] =
+ static_cast<uint16_t>(StartCID + code - StartCode);
+ }
+ } else {
+ m_AdditionalCharcodeToCIDMappings.push_back(
+ {StartCode, EndCode, StartCID});
+ }
+ m_CodeSeq = 0;
+ } else if (m_Status == 3) {
+ m_Status = 0;
+ } else if (m_Status == 4) {
+ m_pCMap->m_Charset = CharsetFromOrdering(CMap_GetString(word));
+ m_Status = 0;
+ } else if (m_Status == 5) {
+ m_Status = 0;
+ } else if (m_Status == 6) {
+ m_pCMap->m_bVertical = CMap_GetCode(word) != 0;
+ m_Status = 0;
+ } else if (m_Status == 7) {
+ if (word == "endcodespacerange") {
+ uint32_t nSegs = pdfium::CollectionSize<uint32_t>(m_CodeRanges);
+ if (nSegs > 1) {
+ m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
+ m_pCMap->m_MixedFourByteLeadingRanges = m_CodeRanges;
+ } else if (nSegs == 1) {
+ m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2)
+ ? CPDF_CMap::TwoBytes
+ : CPDF_CMap::OneByte;
+ }
+ m_Status = 0;
+ } else {
+ if (word.GetLength() == 0 || word.GetAt(0) != '<') {
+ return;
+ }
+ if (m_CodeSeq % 2) {
+ CPDF_CMap::CodeRange range;
+ if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word))
+ m_CodeRanges.push_back(range);
+ }
+ m_CodeSeq++;
+ }
+ }
+ m_LastWord = word;
+}
+
+// Static.
+uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
+ pdfium::base::CheckedNumeric<uint32_t> num = 0;
+ if (word.GetAt(0) == '<') {
+ for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) {
+ num = num * 16 + FXSYS_HexCharToInt(word.GetAt(i));
+ if (!num.IsValid())
+ return 0;
+ }
+ return num.ValueOrDie();
+ }
+
+ for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) {
+ num =
+ num * 10 + FXSYS_DecimalCharToInt(static_cast<wchar_t>(word.GetAt(i)));
+ if (!num.IsValid())
+ return 0;
+ }
+ return num.ValueOrDie();
+}
+
+// Static.
+bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
+ const CFX_ByteStringC& first,
+ const CFX_ByteStringC& second) {
+ if (first.GetLength() == 0 || first.GetAt(0) != '<')
+ return false;
+
+ int i;
+ for (i = 1; i < first.GetLength(); ++i) {
+ if (first.GetAt(i) == '>') {
+ break;
+ }
+ }
+ range.m_CharSize = (i - 1) / 2;
+ if (range.m_CharSize > 4)
+ return false;
+
+ for (i = 0; i < range.m_CharSize; ++i) {
+ uint8_t digit1 = first.GetAt(i * 2 + 1);
+ uint8_t digit2 = first.GetAt(i * 2 + 2);
+ range.m_Lower[i] =
+ FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2);
+ }
+
+ uint32_t size = second.GetLength();
+ for (i = 0; i < range.m_CharSize; ++i) {
+ uint8_t digit1 = ((uint32_t)i * 2 + 1 < size)
+ ? second.GetAt((FX_STRSIZE)i * 2 + 1)
+ : '0';
+ uint8_t digit2 = ((uint32_t)i * 2 + 2 < size)
+ ? second.GetAt((FX_STRSIZE)i * 2 + 2)
+ : '0';
+ range.m_Upper[i] =
+ FXSYS_HexCharToInt(digit1) * 16 + FXSYS_HexCharToInt(digit2);
+ }
+ return true;
+}
+
+// static
+CIDSet CPDF_CMapParser::CharsetFromOrdering(const CFX_ByteStringC& ordering) {
+ for (size_t charset = 1; charset < FX_ArraySize(g_CharsetNames); ++charset) {
+ if (ordering == g_CharsetNames[charset])
+ return CIDSetFromSizeT(charset);
+ }
+ return CIDSET_UNKNOWN;
+}
diff --git a/core/fpdfapi/font/cpdf_cmapparser.h b/core/fpdfapi/font/cpdf_cmapparser.h
new file mode 100644
index 0000000000..184ef75043
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_cmapparser.h
@@ -0,0 +1,52 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_
+#define CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_
+
+#include <map>
+#include <utility>
+#include <vector>
+
+#include "core/fpdfapi/font/cpdf_cidfont.h"
+#include "core/fpdfapi/font/cpdf_cmap.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
+#include "core/fxcrt/fx_basic.h"
+
+class CPDF_CMapParser {
+ public:
+ explicit CPDF_CMapParser(CPDF_CMap* pMap);
+ ~CPDF_CMapParser();
+
+ void ParseWord(const CFX_ByteStringC& str);
+ bool HasAdditionalMappings() const {
+ return !m_AdditionalCharcodeToCIDMappings.empty();
+ }
+ std::vector<CPDF_CMap::CIDRange> TakeAdditionalMappings() {
+ return std::move(m_AdditionalCharcodeToCIDMappings);
+ }
+
+ static CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering);
+
+ private:
+ friend class cpdf_cmapparser_CMap_GetCode_Test;
+ friend class cpdf_cmapparser_CMap_GetCodeRange_Test;
+
+ static uint32_t CMap_GetCode(const CFX_ByteStringC& word);
+ static bool CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
+ const CFX_ByteStringC& first,
+ const CFX_ByteStringC& second);
+
+ CFX_UnownedPtr<CPDF_CMap> const m_pCMap;
+ int m_Status;
+ int m_CodeSeq;
+ uint32_t m_CodePoints[4];
+ std::vector<CPDF_CMap::CodeRange> m_CodeRanges;
+ std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings;
+ CFX_ByteString m_LastWord;
+};
+
+#endif // CORE_FPDFAPI_FONT_CPDF_CMAPPARSER_H_
diff --git a/core/fpdfapi/font/fpdf_font_cid_unittest.cpp b/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
index 813a3a9d9b..0d55aa274d 100644
--- a/core/fpdfapi/font/fpdf_font_cid_unittest.cpp
+++ b/core/fpdfapi/font/cpdf_cmapparser_unittest.cpp
@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/fpdfapi/font/font_int.h"
+#include "core/fpdfapi/font/cpdf_cmapparser.h"
+
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -17,7 +18,7 @@ bool uint_ranges_equal(uint8_t* a, uint8_t* b, size_t count) {
} // namespace
-TEST(fpdf_font_cid, CMap_GetCode) {
+TEST(cpdf_cmapparser, CMap_GetCode) {
EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode(""));
EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<"));
EXPECT_EQ(194u, CPDF_CMapParser::CMap_GetCode("<c2"));
@@ -35,7 +36,7 @@ TEST(fpdf_font_cid, CMap_GetCode) {
EXPECT_EQ(0u, CPDF_CMapParser::CMap_GetCode("<100000000"));
}
-TEST(fpdf_font_cid, CMap_GetCodeRange) {
+TEST(cpdf_cmapparser, CMap_GetCodeRange) {
CPDF_CMap::CodeRange range;
// Must start with a <
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp
index 1a7fb60b0b..1faa4ec4be 100644
--- a/core/fpdfapi/font/cpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_font.cpp
@@ -15,7 +15,6 @@
#include "core/fpdfapi/font/cpdf_truetypefont.h"
#include "core/fpdfapi/font/cpdf_type1font.h"
#include "core/fpdfapi/font/cpdf_type3font.h"
-#include "core/fpdfapi/font/font_int.h"
#include "core/fpdfapi/page/cpdf_docpagedata.h"
#include "core/fpdfapi/page/cpdf_pagemodule.h"
#include "core/fpdfapi/parser/cpdf_array.h"
@@ -477,3 +476,27 @@ CFX_Font* CPDF_Font::GetFontFallback(int position) {
return nullptr;
return m_FontFallbacks[position].get();
}
+
+// static
+int CPDF_Font::TT2PDF(int m, FXFT_Face face) {
+ int upm = FXFT_Get_Face_UnitsPerEM(face);
+ if (upm == 0)
+ return m;
+ return pdfium::base::checked_cast<int>(
+ (static_cast<double>(m) * 1000 + upm / 2) / upm);
+}
+
+// static
+bool CPDF_Font::FT_UseTTCharmap(FXFT_Face face,
+ int platform_id,
+ int encoding_id) {
+ auto** pCharMap = FXFT_Get_Face_Charmaps(face);
+ for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
+ if (FXFT_Get_Charmap_PlatformID(pCharMap[i]) == platform_id &&
+ FXFT_Get_Charmap_EncodingID(pCharMap[i]) == encoding_id) {
+ FXFT_Set_Charmap(face, pCharMap[i]);
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h
index c8e65e26a5..1fef77b322 100644
--- a/core/fpdfapi/font/cpdf_font.h
+++ b/core/fpdfapi/font/cpdf_font.h
@@ -10,6 +10,7 @@
#include <memory>
#include <vector>
+#include "core/fpdfapi/font/cpdf_tounicodemap.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_string.h"
@@ -87,6 +88,9 @@ class CPDF_Font {
protected:
CPDF_Font();
+ static int TT2PDF(int m, FXFT_Face face);
+ static bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id);
+
virtual bool Load() = 0;
void LoadUnicodeMap() const; // logically const only.
diff --git a/core/fpdfapi/font/cpdf_fontglobals.cpp b/core/fpdfapi/font/cpdf_fontglobals.cpp
new file mode 100644
index 0000000000..ddf87b1c09
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_fontglobals.cpp
@@ -0,0 +1,39 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/fpdfapi/font/cpdf_fontglobals.h"
+
+#include <utility>
+
+#include "core/fpdfapi/parser/cpdf_document.h"
+#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
+
+CPDF_FontGlobals::CPDF_FontGlobals() {
+ memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets));
+ memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes));
+}
+
+CPDF_FontGlobals::~CPDF_FontGlobals() {}
+
+CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) {
+ auto it = m_StockMap.find(pDoc);
+ if (it == m_StockMap.end())
+ return nullptr;
+ return it->second ? it->second->GetFont(index) : nullptr;
+}
+
+CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc,
+ uint32_t index,
+ std::unique_ptr<CPDF_Font> pFont) {
+ if (!pdfium::ContainsKey(m_StockMap, pDoc))
+ m_StockMap[pDoc] = pdfium::MakeUnique<CFX_StockFontArray>();
+ return m_StockMap[pDoc]->SetFont(index, std::move(pFont));
+}
+
+void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) {
+ m_StockMap.erase(pDoc);
+}
diff --git a/core/fpdfapi/font/cpdf_fontglobals.h b/core/fpdfapi/font/cpdf_fontglobals.h
new file mode 100644
index 0000000000..b930aa2905
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_fontglobals.h
@@ -0,0 +1,45 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_
+#define CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_
+
+#include <map>
+#include <memory>
+
+#include "core/fpdfapi/cmaps/cmap_int.h"
+#include "core/fpdfapi/font/cfx_stockfontarray.h"
+#include "core/fpdfapi/font/cpdf_cmapmanager.h"
+#include "core/fxcrt/fx_basic.h"
+
+class CPDF_FontGlobals {
+ public:
+ CPDF_FontGlobals();
+ ~CPDF_FontGlobals();
+
+ void Clear(CPDF_Document* pDoc);
+ CPDF_Font* Find(CPDF_Document* pDoc, uint32_t index);
+
+ // Takes ownership of |pFont|, returns unowned pointer to it.
+ CPDF_Font* Set(CPDF_Document* key,
+ uint32_t index,
+ std::unique_ptr<CPDF_Font> pFont);
+
+ CPDF_CMapManager m_CMapManager;
+ struct {
+ CFX_UnownedPtr<const FXCMAP_CMap> m_pMapList;
+ uint32_t m_Count;
+ } m_EmbeddedCharsets[CIDSET_NUM_SETS];
+ struct {
+ const uint16_t* m_pMap;
+ uint32_t m_Count;
+ } m_EmbeddedToUnicodes[CIDSET_NUM_SETS];
+
+ private:
+ std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap;
+};
+
+#endif // CORE_FPDFAPI_FONT_CPDF_FONTGLOBALS_H_
diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp
index cb8f00a98a..ebf2cb65c7 100644
--- a/core/fpdfapi/font/cpdf_simplefont.cpp
+++ b/core/fpdfapi/font/cpdf_simplefont.cpp
@@ -6,7 +6,6 @@
#include "core/fpdfapi/font/cpdf_simplefont.h"
-#include "core/fpdfapi/font/font_int.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fxge/fx_freetype.h"
diff --git a/core/fpdfapi/font/fpdf_font.cpp b/core/fpdfapi/font/cpdf_tounicodemap.cpp
index ebdad49da7..8989f0be37 100644
--- a/core/fpdfapi/font/fpdf_font.cpp
+++ b/core/fpdfapi/font/cpdf_tounicodemap.cpp
@@ -1,99 +1,18 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include "core/fpdfapi/font/font_int.h"
-
-#include <memory>
-#include <utility>
+#include "core/fpdfapi/font/cpdf_tounicodemap.h"
#include "core/fpdfapi/cpdf_modulemgr.h"
-#include "core/fpdfapi/page/cpdf_form.h"
+#include "core/fpdfapi/font/cpdf_cid2unicodemap.h"
#include "core/fpdfapi/page/cpdf_pagemodule.h"
-#include "core/fpdfapi/parser/cpdf_array.h"
-#include "core/fpdfapi/parser/cpdf_dictionary.h"
-#include "core/fpdfapi/parser/cpdf_document.h"
-#include "core/fpdfapi/parser/cpdf_name.h"
-#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
-#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
-#include "core/fxge/fx_freetype.h"
#include "third_party/base/numerics/safe_conversions.h"
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
-
-int TT2PDF(int m, FXFT_Face face) {
- int upm = FXFT_Get_Face_UnitsPerEM(face);
- if (upm == 0)
- return m;
- return pdfium::base::checked_cast<int>(
- (static_cast<double>(m) * 1000 + upm / 2) / upm);
-}
-
-bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id) {
- auto** pCharMap = FXFT_Get_Face_Charmaps(face);
- for (int i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) {
- if (FXFT_Get_Charmap_PlatformID(pCharMap[i]) == platform_id &&
- FXFT_Get_Charmap_EncodingID(pCharMap[i]) == encoding_id) {
- FXFT_Set_Charmap(face, pCharMap[i]);
- return true;
- }
- }
- return false;
-}
-
-CFX_StockFontArray::CFX_StockFontArray() {}
-
-CFX_StockFontArray::~CFX_StockFontArray() {
- for (size_t i = 0; i < FX_ArraySize(m_StockFonts); ++i) {
- if (m_StockFonts[i])
- delete m_StockFonts[i]->GetFontDict();
- }
-}
-
-CPDF_Font* CFX_StockFontArray::GetFont(uint32_t index) const {
- if (index >= FX_ArraySize(m_StockFonts))
- return nullptr;
- return m_StockFonts[index].get();
-}
-
-CPDF_Font* CFX_StockFontArray::SetFont(uint32_t index,
- std::unique_ptr<CPDF_Font> pFont) {
- CPDF_Font* result = pFont.get();
- if (index < FX_ArraySize(m_StockFonts))
- m_StockFonts[index] = std::move(pFont);
- return result;
-}
-
-CPDF_FontGlobals::CPDF_FontGlobals() {
- memset(m_EmbeddedCharsets, 0, sizeof(m_EmbeddedCharsets));
- memset(m_EmbeddedToUnicodes, 0, sizeof(m_EmbeddedToUnicodes));
-}
-
-CPDF_FontGlobals::~CPDF_FontGlobals() {}
-
-CPDF_Font* CPDF_FontGlobals::Find(CPDF_Document* pDoc, uint32_t index) {
- auto it = m_StockMap.find(pDoc);
- if (it == m_StockMap.end())
- return nullptr;
- return it->second ? it->second->GetFont(index) : nullptr;
-}
-
-CPDF_Font* CPDF_FontGlobals::Set(CPDF_Document* pDoc,
- uint32_t index,
- std::unique_ptr<CPDF_Font> pFont) {
- if (!pdfium::ContainsKey(m_StockMap, pDoc))
- m_StockMap[pDoc] = pdfium::MakeUnique<CFX_StockFontArray>();
- return m_StockMap[pDoc]->SetFont(index, std::move(pFont));
-}
-
-void CPDF_FontGlobals::Clear(CPDF_Document* pDoc) {
- m_StockMap.erase(pDoc);
-}
CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const {
auto it = m_Map.find(charcode);
diff --git a/core/fpdfapi/font/cpdf_tounicodemap.h b/core/fpdfapi/font/cpdf_tounicodemap.h
new file mode 100644
index 0000000000..83db6e3030
--- /dev/null
+++ b/core/fpdfapi/font/cpdf_tounicodemap.h
@@ -0,0 +1,42 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_
+#define CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_
+
+#include <map>
+
+#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
+#include "core/fxcrt/fx_basic.h"
+
+class CPDF_CID2UnicodeMap;
+
+class CPDF_ToUnicodeMap {
+ public:
+ CPDF_ToUnicodeMap();
+ ~CPDF_ToUnicodeMap();
+
+ void Load(CPDF_Stream* pStream);
+
+ CFX_WideString Lookup(uint32_t charcode) const;
+ uint32_t ReverseLookup(wchar_t unicode) const;
+
+ private:
+ friend class cpdf_tounicodemap_StringToCode_Test;
+ friend class cpdf_tounicodemap_StringToWideString_Test;
+
+ static uint32_t StringToCode(const CFX_ByteStringC& str);
+ static CFX_WideString StringToWideString(const CFX_ByteStringC& str);
+
+ uint32_t GetUnicode();
+
+ std::map<uint32_t, uint32_t> m_Map;
+ CFX_UnownedPtr<CPDF_CID2UnicodeMap> m_pBaseMap;
+ CFX_WideTextBuf m_MultiCharBuf;
+};
+
+#endif // CORE_FPDFAPI_FONT_CPDF_TOUNICODEMAP_H_
diff --git a/core/fpdfapi/font/fpdf_font_unittest.cpp b/core/fpdfapi/font/cpdf_tounicodemap_unittest.cpp
index 977ae8a3bb..299f4d9b1e 100644
--- a/core/fpdfapi/font/fpdf_font_unittest.cpp
+++ b/core/fpdfapi/font/cpdf_tounicodemap_unittest.cpp
@@ -2,10 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/fpdfapi/font/font_int.h"
+#include "core/fpdfapi/font/cpdf_tounicodemap.h"
+
#include "testing/gtest/include/gtest/gtest.h"
-TEST(fpdf_font, StringToCode) {
+TEST(cpdf_tounicodemap, StringToCode) {
EXPECT_EQ(0u, CPDF_ToUnicodeMap::StringToCode(""));
EXPECT_EQ(194u, CPDF_ToUnicodeMap::StringToCode("<c2"));
EXPECT_EQ(162u, CPDF_ToUnicodeMap::StringToCode("<A2"));
@@ -14,7 +15,7 @@ TEST(fpdf_font, StringToCode) {
EXPECT_EQ(128u, CPDF_ToUnicodeMap::StringToCode("128"));
}
-TEST(fpdf_font, StringToWideString) {
+TEST(cpdf_tounicodemap, StringToWideString) {
EXPECT_EQ(L"", CPDF_ToUnicodeMap::StringToWideString(""));
EXPECT_EQ(L"", CPDF_ToUnicodeMap::StringToWideString("1234"));
diff --git a/core/fpdfapi/font/cpdf_truetypefont.cpp b/core/fpdfapi/font/cpdf_truetypefont.cpp
index 7f4512da05..5fde64693a 100644
--- a/core/fpdfapi/font/cpdf_truetypefont.cpp
+++ b/core/fpdfapi/font/cpdf_truetypefont.cpp
@@ -6,7 +6,6 @@
#include "core/fpdfapi/font/cpdf_truetypefont.h"
-#include "core/fpdfapi/font/font_int.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fxge/fx_font.h"
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index ac0aed4050..a7ac264fe0 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -6,7 +6,6 @@
#include "core/fpdfapi/font/cpdf_type1font.h"
-#include "core/fpdfapi/font/font_int.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fxge/cfx_gemodule.h"
#include "core/fxge/fx_freetype.h"
diff --git a/core/fpdfapi/font/font_int.h b/core/fpdfapi/font/font_int.h
deleted file mode 100644
index 5544a1b016..0000000000
--- a/core/fpdfapi/font/font_int.h
+++ /dev/null
@@ -1,229 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FPDFAPI_FONT_FONT_INT_H_
-#define CORE_FPDFAPI_FONT_FONT_INT_H_
-
-#include <map>
-#include <memory>
-#include <utility>
-#include <vector>
-
-#include "core/fpdfapi/font/cpdf_cidfont.h"
-#include "core/fxcrt/cfx_retain_ptr.h"
-#include "core/fxcrt/cfx_unowned_ptr.h"
-#include "core/fxcrt/fx_basic.h"
-
-class CPDF_CID2UnicodeMap;
-class CPDF_CMapManager;
-class CPDF_Font;
-class CPDF_Stream;
-struct FXCMAP_CMap;
-
-using FXFT_Library = void*;
-
-int TT2PDF(int m, FXFT_Face face);
-bool FT_UseTTCharmap(FXFT_Face face, int platform_id, int encoding_id);
-CIDSet CharsetFromOrdering(const CFX_ByteStringC& ordering);
-
-class CFX_StockFontArray {
- public:
- CFX_StockFontArray();
- ~CFX_StockFontArray();
-
- // Takes ownership of |pFont|, returns unowned pointer to it.
- CPDF_Font* SetFont(uint32_t index, std::unique_ptr<CPDF_Font> pFont);
- CPDF_Font* GetFont(uint32_t index) const;
-
- private:
- std::unique_ptr<CPDF_Font> m_StockFonts[14];
-};
-
-enum CIDCoding : uint8_t {
- CIDCODING_UNKNOWN = 0,
- CIDCODING_GB,
- CIDCODING_BIG5,
- CIDCODING_JIS,
- CIDCODING_KOREA,
- CIDCODING_UCS2,
- CIDCODING_CID,
- CIDCODING_UTF16,
-};
-
-class CPDF_CMap : public CFX_Retainable {
- public:
- enum CodingScheme : uint8_t {
- OneByte,
- TwoBytes,
- MixedTwoBytes,
- MixedFourBytes
- };
-
- struct CodeRange {
- int m_CharSize;
- uint8_t m_Lower[4];
- uint8_t m_Upper[4];
- };
-
- struct CIDRange {
- uint32_t m_StartCode;
- uint32_t m_EndCode;
- uint16_t m_StartCID;
- };
-
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
- void LoadPredefined(CPDF_CMapManager* pMgr,
- const CFX_ByteString& name,
- bool bPromptCJK);
- void LoadEmbedded(const uint8_t* pData, uint32_t dwSize);
-
- bool IsLoaded() const { return m_bLoaded; }
- bool IsVertWriting() const { return m_bVertical; }
- uint16_t CIDFromCharCode(uint32_t charcode) const;
- int GetCharSize(uint32_t charcode) const;
- uint32_t GetNextChar(const char* pString, int nStrLen, int& offset) const;
- int CountChar(const char* pString, int size) const;
- int AppendChar(char* str, uint32_t charcode) const;
-
- private:
- friend class CPDF_CMapParser;
- friend class CPDF_CIDFont;
-
- CPDF_CMap();
- ~CPDF_CMap() override;
-
- CFX_ByteString m_PredefinedCMap;
- bool m_bLoaded;
- bool m_bVertical;
- CIDSet m_Charset;
- CodingScheme m_CodingScheme;
- int m_Coding;
- std::vector<bool> m_MixedTwoByteLeadingBytes;
- std::vector<CodeRange> m_MixedFourByteLeadingRanges;
- std::vector<uint16_t> m_DirectCharcodeToCIDTable;
- std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings;
- const FXCMAP_CMap* m_pEmbedMap;
-};
-
-class CPDF_CMapManager {
- public:
- CPDF_CMapManager();
- ~CPDF_CMapManager();
-
- CFX_RetainPtr<CPDF_CMap> GetPredefinedCMap(const CFX_ByteString& name,
- bool bPromptCJK);
- CPDF_CID2UnicodeMap* GetCID2UnicodeMap(CIDSet charset, bool bPromptCJK);
-
- private:
- CFX_RetainPtr<CPDF_CMap> LoadPredefinedCMap(const CFX_ByteString& name,
- bool bPromptCJK);
- std::unique_ptr<CPDF_CID2UnicodeMap> LoadCID2UnicodeMap(CIDSet charset,
- bool bPromptCJK);
-
- std::map<CFX_ByteString, CFX_RetainPtr<CPDF_CMap>> m_CMaps;
- std::unique_ptr<CPDF_CID2UnicodeMap> m_CID2UnicodeMaps[6];
-};
-
-class CPDF_CMapParser {
- public:
- explicit CPDF_CMapParser(CPDF_CMap* pMap);
- ~CPDF_CMapParser();
-
- void ParseWord(const CFX_ByteStringC& str);
- bool HasAdditionalMappings() const {
- return !m_AdditionalCharcodeToCIDMappings.empty();
- }
- std::vector<CPDF_CMap::CIDRange> TakeAdditionalMappings() {
- return std::move(m_AdditionalCharcodeToCIDMappings);
- }
-
- private:
- friend class fpdf_font_cid_CMap_GetCode_Test;
- friend class fpdf_font_cid_CMap_GetCodeRange_Test;
-
- static uint32_t CMap_GetCode(const CFX_ByteStringC& word);
- static bool CMap_GetCodeRange(CPDF_CMap::CodeRange& range,
- const CFX_ByteStringC& first,
- const CFX_ByteStringC& second);
-
- CFX_UnownedPtr<CPDF_CMap> const m_pCMap;
- int m_Status;
- int m_CodeSeq;
- uint32_t m_CodePoints[4];
- std::vector<CPDF_CMap::CodeRange> m_CodeRanges;
- std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings;
- CFX_ByteString m_LastWord;
-};
-
-class CPDF_CID2UnicodeMap {
- public:
- CPDF_CID2UnicodeMap();
- ~CPDF_CID2UnicodeMap();
-
- bool IsLoaded();
- void Load(CPDF_CMapManager* pMgr, CIDSet charset, bool bPromptCJK);
- wchar_t UnicodeFromCID(uint16_t CID);
-
- private:
- CIDSet m_Charset;
- const uint16_t* m_pEmbeddedMap;
- uint32_t m_EmbeddedCount;
-};
-
-class CPDF_ToUnicodeMap {
- public:
- CPDF_ToUnicodeMap();
- ~CPDF_ToUnicodeMap();
-
- void Load(CPDF_Stream* pStream);
-
- CFX_WideString Lookup(uint32_t charcode) const;
- uint32_t ReverseLookup(wchar_t unicode) const;
-
- private:
- friend class fpdf_font_StringToCode_Test;
- friend class fpdf_font_StringToWideString_Test;
-
- static uint32_t StringToCode(const CFX_ByteStringC& str);
- static CFX_WideString StringToWideString(const CFX_ByteStringC& str);
-
- uint32_t GetUnicode();
-
- std::map<uint32_t, uint32_t> m_Map;
- CFX_UnownedPtr<CPDF_CID2UnicodeMap> m_pBaseMap;
- CFX_WideTextBuf m_MultiCharBuf;
-};
-
-class CPDF_FontGlobals {
- public:
- CPDF_FontGlobals();
- ~CPDF_FontGlobals();
-
- void Clear(CPDF_Document* pDoc);
- CPDF_Font* Find(CPDF_Document* pDoc, uint32_t index);
-
- // Takes ownership of |pFont|, returns unowned pointer to it.
- CPDF_Font* Set(CPDF_Document* key,
- uint32_t index,
- std::unique_ptr<CPDF_Font> pFont);
-
- CPDF_CMapManager m_CMapManager;
- struct {
- CFX_UnownedPtr<const FXCMAP_CMap> m_pMapList;
- uint32_t m_Count;
- } m_EmbeddedCharsets[CIDSET_NUM_SETS];
- struct {
- const uint16_t* m_pMap;
- uint32_t m_Count;
- } m_EmbeddedToUnicodes[CIDSET_NUM_SETS];
-
- private:
- std::map<CPDF_Document*, std::unique_ptr<CFX_StockFontArray>> m_StockMap;
-};
-
-#endif // CORE_FPDFAPI_FONT_FONT_INT_H_