diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfapi/font/cpdf_cidfont.cpp | 3 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_cidfont.h | 2 | ||||
-rw-r--r-- | core/fpdfapi/font/font_int.h | 18 | ||||
-rw-r--r-- | core/fpdfapi/font/fpdf_font_cid.cpp | 49 |
4 files changed, 38 insertions, 34 deletions
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index c309ac1d26..c41f8046f7 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp @@ -721,8 +721,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { if (!m_pStreamAcc) { if (m_bType1) return cid; - - if (m_pFontFile && !m_pCMap->m_pMapping) + if (m_pFontFile && m_pCMap->m_DirectCharcodeToCIDTable.empty()) return cid; if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || !FXFT_Get_Face_Charmap(m_Font.GetFace())) { diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h index cc9bec1612..0fd5e63f1c 100644 --- a/core/fpdfapi/font/cpdf_cidfont.h +++ b/core/fpdfapi/font/cpdf_cidfont.h @@ -15,7 +15,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" -enum CIDSet { +enum CIDSet : uint8_t { CIDSET_UNKNOWN, CIDSET_GB1, CIDSET_CNS1, diff --git a/core/fpdfapi/font/font_int.h b/core/fpdfapi/font/font_int.h index 8bf7ef5594..72c892fbbd 100644 --- a/core/fpdfapi/font/font_int.h +++ b/core/fpdfapi/font/font_int.h @@ -97,15 +97,15 @@ class CPDF_CMap : public CFX_Retainable { ~CPDF_CMap() override; CFX_ByteString m_PredefinedCMap; + bool m_bLoaded; bool m_bVertical; CIDSet m_Charset; - int m_Coding; CodingScheme m_CodingScheme; + int m_Coding; int m_nCodeRanges; uint8_t* m_pLeadingBytes; - uint16_t* m_pMapping; - bool m_bLoaded; - std::vector<CIDRange> m_AddMapping; + std::vector<uint16_t> m_DirectCharcodeToCIDTable; + std::vector<CIDRange> m_AdditionalCharcodeToCIDMappings; const FXCMAP_CMap* m_pEmbedMap; }; @@ -134,9 +134,11 @@ class CPDF_CMapParser { ~CPDF_CMapParser(); void ParseWord(const CFX_ByteStringC& str); - bool HasAddMaps() const { return !m_AddMaps.empty(); } - std::vector<CPDF_CMap::CIDRange> TakeAddMaps() { - return std::move(m_AddMaps); + bool HasAdditionalMappings() const { + return !m_AdditionalCharcodeToCIDMappings.empty(); + } + std::vector<CPDF_CMap::CIDRange> TakeAdditionalMappings() { + return std::move(m_AdditionalCharcodeToCIDMappings); } private: @@ -153,7 +155,7 @@ class CPDF_CMapParser { int m_CodeSeq; uint32_t m_CodePoints[4]; std::vector<CPDF_CMap::CodeRange> m_CodeRanges; - std::vector<CPDF_CMap::CIDRange> m_AddMaps; + std::vector<CPDF_CMap::CIDRange> m_AdditionalCharcodeToCIDMappings; CFX_ByteString m_LastWord; }; diff --git a/core/fpdfapi/font/fpdf_font_cid.cpp b/core/fpdfapi/font/fpdf_font_cid.cpp index 3f8e919bed..6ac9587e8f 100644 --- a/core/fpdfapi/font/fpdf_font_cid.cpp +++ b/core/fpdfapi/font/fpdf_font_cid.cpp @@ -8,6 +8,7 @@ #include <memory> #include <utility> +#include <vector> #include "core/fpdfapi/cmaps/cmap_int.h" #include "core/fpdfapi/cpdf_modulemgr.h" @@ -363,10 +364,12 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) { } if (EndCode < 0x10000) { for (uint32_t code = StartCode; code <= EndCode; code++) { - m_pCMap->m_pMapping[code] = (uint16_t)(StartCID + code - StartCode); + m_pCMap->m_DirectCharcodeToCIDTable[code] = + static_cast<uint16_t>(StartCID + code - StartCode); } } else { - m_AddMaps.push_back({StartCode, EndCode, StartCID}); + m_AdditionalCharcodeToCIDMappings.push_back( + {StartCode, EndCode, StartCID}); } m_CodeSeq = 0; } else if (m_Status == 3) { @@ -470,20 +473,17 @@ bool CPDF_CMapParser::CMap_GetCodeRange(CPDF_CMap::CodeRange& range, return true; } -CPDF_CMap::CPDF_CMap() { - m_Charset = CIDSET_UNKNOWN; - m_Coding = CIDCODING_UNKNOWN; - m_CodingScheme = TwoBytes; - m_bVertical = false; - m_bLoaded = false; - m_pMapping = nullptr; - m_pLeadingBytes = nullptr; - m_pEmbedMap = nullptr; - m_nCodeRanges = 0; -} +CPDF_CMap::CPDF_CMap() + : m_bLoaded(false), + m_bVertical(false), + m_Charset(CIDSET_UNKNOWN), + m_CodingScheme(TwoBytes), + m_Coding(CIDCODING_UNKNOWN), + m_nCodeRanges(0), + m_pLeadingBytes(nullptr), + m_pEmbedMap(nullptr) {} CPDF_CMap::~CPDF_CMap() { - FX_Free(m_pMapping); FX_Free(m_pLeadingBytes); } @@ -540,7 +540,7 @@ void CPDF_CMap::LoadPredefined(CPDF_CMapManager* pMgr, } void CPDF_CMap::LoadEmbedded(const uint8_t* pData, uint32_t size) { - m_pMapping = FX_Alloc(uint16_t, 65536); + m_DirectCharcodeToCIDTable = std::vector<uint16_t>(65536); CPDF_CMapParser parser(this); CPDF_SimpleParser syntax(pData, size); while (1) { @@ -550,10 +550,11 @@ void CPDF_CMap::LoadEmbedded(const uint8_t* pData, uint32_t size) { } parser.ParseWord(word); } - if (m_CodingScheme == MixedFourBytes && parser.HasAddMaps()) { - m_AddMapping = parser.TakeAddMaps(); + if (m_CodingScheme == MixedFourBytes && parser.HasAdditionalMappings()) { + m_AdditionalCharcodeToCIDMappings = parser.TakeAdditionalMappings(); std::sort( - m_AddMapping.begin(), m_AddMapping.end(), + m_AdditionalCharcodeToCIDMappings.begin(), + m_AdditionalCharcodeToCIDMappings.end(), [](const CPDF_CMap::CIDRange& arg1, const CPDF_CMap::CIDRange& arg2) { return arg1.m_EndCode < arg2.m_EndCode; }); @@ -567,19 +568,21 @@ uint16_t CPDF_CMap::CIDFromCharCode(uint32_t charcode) const { if (m_pEmbedMap) return FPDFAPI_CIDFromCharCode(m_pEmbedMap, charcode); - if (!m_pMapping) + if (m_DirectCharcodeToCIDTable.empty()) return static_cast<uint16_t>(charcode); if (charcode < 0x10000) - return m_pMapping[charcode]; + return m_DirectCharcodeToCIDTable[charcode]; - auto it = std::lower_bound(m_AddMapping.begin(), m_AddMapping.end(), charcode, + auto it = std::lower_bound(m_AdditionalCharcodeToCIDMappings.begin(), + m_AdditionalCharcodeToCIDMappings.end(), charcode, [](const CPDF_CMap::CIDRange& arg, uint32_t val) { return arg.m_EndCode < val; }); - if (it == m_AddMapping.end() || it->m_StartCode > charcode) + if (it == m_AdditionalCharcodeToCIDMappings.end() || + it->m_StartCode > charcode) { return 0; - + } return it->m_StartCID + charcode - it->m_StartCode; } |