| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fpdfapi/fpdf_font/font_int.h" | 7 #include "core/fpdfapi/fpdf_font/font_int.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" | 9 #include "core/fpdfapi/fpdf_page/cpdf_pagemodule.h" |
| 10 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 | 87 |
| 88 | 88 |
| 89 short TT2PDF(int m, FXFT_Face face) { | 89 short TT2PDF(int m, FXFT_Face face) { |
| 90 int upm = FXFT_Get_Face_UnitsPerEM(face); | 90 int upm = FXFT_Get_Face_UnitsPerEM(face); |
| 91 if (upm == 0) | 91 if (upm == 0) |
| 92 return (short)m; | 92 return (short)m; |
| 93 return (m * 1000 + upm / 2) / upm; | 93 return (m * 1000 + upm / 2) / upm; |
| 94 } | 94 } |
| 95 | 95 |
| 96 CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) { | 96 CFX_WideString CPDF_ToUnicodeMap::Lookup(uint32_t charcode) const { |
| 97 auto it = m_Map.find(charcode); | 97 auto it = m_Map.find(charcode); |
| 98 if (it != m_Map.end()) { | 98 if (it != m_Map.end()) { |
| 99 uint32_t value = it->second; | 99 uint32_t value = it->second; |
| 100 FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff); | 100 FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff); |
| 101 if (unicode != 0xffff) { | 101 if (unicode != 0xffff) { |
| 102 return unicode; | 102 return unicode; |
| 103 } | 103 } |
| 104 const FX_WCHAR* buf = m_MultiCharBuf.GetBuffer(); | 104 const FX_WCHAR* buf = m_MultiCharBuf.GetBuffer(); |
| 105 uint32_t buf_len = m_MultiCharBuf.GetLength(); | 105 uint32_t buf_len = m_MultiCharBuf.GetLength(); |
| 106 if (!buf || buf_len == 0) { | 106 if (!buf || buf_len == 0) { |
| 107 return CFX_WideString(); | 107 return CFX_WideString(); |
| 108 } | 108 } |
| 109 uint32_t index = value >> 16; | 109 uint32_t index = value >> 16; |
| 110 if (index >= buf_len) { | 110 if (index >= buf_len) { |
| 111 return CFX_WideString(); | 111 return CFX_WideString(); |
| 112 } | 112 } |
| 113 uint32_t len = buf[index]; | 113 uint32_t len = buf[index]; |
| 114 if (index + len < index || index + len >= buf_len) { | 114 if (index + len < index || index + len >= buf_len) { |
| 115 return CFX_WideString(); | 115 return CFX_WideString(); |
| 116 } | 116 } |
| 117 return CFX_WideString(buf + index + 1, len); | 117 return CFX_WideString(buf + index + 1, len); |
| 118 } | 118 } |
| 119 if (m_pBaseMap) { | 119 if (m_pBaseMap) { |
| 120 return m_pBaseMap->UnicodeFromCID((uint16_t)charcode); | 120 return m_pBaseMap->UnicodeFromCID((uint16_t)charcode); |
| 121 } | 121 } |
| 122 return CFX_WideString(); | 122 return CFX_WideString(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 uint32_t CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) { | 125 uint32_t CPDF_ToUnicodeMap::ReverseLookup(FX_WCHAR unicode) const { |
| 126 for (const auto& pair : m_Map) { | 126 for (const auto& pair : m_Map) { |
| 127 if (pair.second == static_cast<uint32_t>(unicode)) | 127 if (pair.second == static_cast<uint32_t>(unicode)) |
| 128 return pair.first; | 128 return pair.first; |
| 129 } | 129 } |
| 130 return 0; | 130 return 0; |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Static. | 133 // Static. |
| 134 uint32_t CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { | 134 uint32_t CPDF_ToUnicodeMap::StringToCode(const CFX_ByteStringC& str) { |
| 135 int len = str.GetLength(); | 135 int len = str.GetLength(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 result += ch; | 186 result += ch; |
| 187 byte_pos = 0; | 187 byte_pos = 0; |
| 188 ch = 0; | 188 ch = 0; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 return result; | 191 return result; |
| 192 } | 192 } |
| 193 return result; | 193 return result; |
| 194 } | 194 } |
| 195 | 195 |
| 196 CPDF_ToUnicodeMap::CPDF_ToUnicodeMap() : m_pBaseMap(nullptr) {} |
| 197 |
| 198 CPDF_ToUnicodeMap::~CPDF_ToUnicodeMap() {} |
| 199 |
| 196 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { | 200 void CPDF_ToUnicodeMap::Load(CPDF_Stream* pStream) { |
| 197 CIDSet cid_set = CIDSET_UNKNOWN; | 201 CIDSet cid_set = CIDSET_UNKNOWN; |
| 198 CPDF_StreamAcc stream; | 202 CPDF_StreamAcc stream; |
| 199 stream.LoadAllData(pStream, FALSE); | 203 stream.LoadAllData(pStream, FALSE); |
| 200 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); | 204 CPDF_SimpleParser parser(stream.GetData(), stream.GetSize()); |
| 201 while (1) { | 205 while (1) { |
| 202 CFX_ByteStringC word = parser.GetWord(); | 206 CFX_ByteStringC word = parser.GetWord(); |
| 203 if (word.IsEmpty()) { | 207 if (word.IsEmpty()) { |
| 204 break; | 208 break; |
| 205 } | 209 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 297 } |
| 294 if (cid_set) { | 298 if (cid_set) { |
| 295 m_pBaseMap = CPDF_ModuleMgr::Get() | 299 m_pBaseMap = CPDF_ModuleMgr::Get() |
| 296 ->GetPageModule() | 300 ->GetPageModule() |
| 297 ->GetFontGlobals() | 301 ->GetFontGlobals() |
| 298 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE); | 302 ->m_CMapManager.GetCID2UnicodeMap(cid_set, FALSE); |
| 299 } else { | 303 } else { |
| 300 m_pBaseMap = nullptr; | 304 m_pBaseMap = nullptr; |
| 301 } | 305 } |
| 302 } | 306 } |
| OLD | NEW |