| 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/src/fpdfapi/fpdf_font/font_int.h" | 7 #include "core/src/fpdfapi/fpdf_font/font_int.h" |
| 8 | 8 |
| 9 #include "core/include/fpdfapi/fpdf_module.h" | 9 #include "core/include/fpdfapi/fpdf_module.h" |
| 10 #include "core/include/fpdfapi/fpdf_page.h" | 10 #include "core/include/fpdfapi/fpdf_page.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 m_StockMap.erase(pDoc); | 81 m_StockMap.erase(pDoc); |
| 82 } | 82 } |
| 83 | 83 |
| 84 CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { | 84 CPDF_Font::CPDF_Font(int fonttype) : m_FontType(fonttype) { |
| 85 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; | 85 m_FontBBox.left = m_FontBBox.right = m_FontBBox.top = m_FontBBox.bottom = 0; |
| 86 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; | 86 m_StemV = m_Ascent = m_Descent = m_ItalicAngle = 0; |
| 87 m_pFontFile = NULL; | 87 m_pFontFile = NULL; |
| 88 m_Flags = 0; | 88 m_Flags = 0; |
| 89 m_pToUnicodeMap = NULL; | 89 m_pToUnicodeMap = NULL; |
| 90 m_bToUnicodeLoaded = FALSE; | 90 m_bToUnicodeLoaded = FALSE; |
| 91 m_pCharMap = new CPDF_FontCharMap(this); | |
| 92 } | 91 } |
| 93 CPDF_Font::~CPDF_Font() { | 92 CPDF_Font::~CPDF_Font() { |
| 94 delete m_pCharMap; | |
| 95 m_pCharMap = NULL; | |
| 96 | |
| 97 delete m_pToUnicodeMap; | 93 delete m_pToUnicodeMap; |
| 98 m_pToUnicodeMap = NULL; | 94 m_pToUnicodeMap = NULL; |
| 99 | 95 |
| 100 if (m_pFontFile) { | 96 if (m_pFontFile) { |
| 101 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( | 97 m_pDocument->GetPageData()->ReleaseFontFileStreamAcc( |
| 102 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); | 98 const_cast<CPDF_Stream*>(m_pFontFile->GetStream()->AsStream())); |
| 103 } | 99 } |
| 104 } | 100 } |
| 105 FX_BOOL CPDF_Font::IsVertWriting() const { | 101 FX_BOOL CPDF_Font::IsVertWriting() const { |
| 106 FX_BOOL bVertWriting = FALSE; | 102 FX_BOOL bVertWriting = FALSE; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 ((CPDF_Font*)this)->LoadUnicodeMap(); | 151 ((CPDF_Font*)this)->LoadUnicodeMap(); |
| 156 } | 152 } |
| 157 if (m_pToUnicodeMap) { | 153 if (m_pToUnicodeMap) { |
| 158 FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode); | 154 FX_DWORD charcode = m_pToUnicodeMap->ReverseLookup(unicode); |
| 159 if (charcode) { | 155 if (charcode) { |
| 160 return charcode; | 156 return charcode; |
| 161 } | 157 } |
| 162 } | 158 } |
| 163 return _CharCodeFromUnicode(unicode); | 159 return _CharCodeFromUnicode(unicode); |
| 164 } | 160 } |
| 165 CFX_WideString CPDF_Font::DecodeString(const CFX_ByteString& str) const { | |
| 166 CFX_WideString result; | |
| 167 int src_len = str.GetLength(); | |
| 168 result.Reserve(src_len); | |
| 169 const FX_CHAR* src_buf = str; | |
| 170 int src_pos = 0; | |
| 171 while (src_pos < src_len) { | |
| 172 FX_DWORD charcode = GetNextChar(src_buf, src_len, src_pos); | |
| 173 CFX_WideString unicode = UnicodeFromCharCode(charcode); | |
| 174 if (!unicode.IsEmpty()) { | |
| 175 result += unicode; | |
| 176 } else { | |
| 177 result += (FX_WCHAR)charcode; | |
| 178 } | |
| 179 } | |
| 180 return result; | |
| 181 } | |
| 182 CFX_ByteString CPDF_Font::EncodeString(const CFX_WideString& str) const { | |
| 183 CFX_ByteString result; | |
| 184 int src_len = str.GetLength(); | |
| 185 FX_CHAR* dest_buf = result.GetBuffer(src_len * 2); | |
| 186 const FX_WCHAR* src_buf = str.c_str(); | |
| 187 int dest_pos = 0; | |
| 188 for (int src_pos = 0; src_pos < src_len; src_pos++) { | |
| 189 FX_DWORD charcode = CharCodeFromUnicode(src_buf[src_pos]); | |
| 190 dest_pos += AppendChar(dest_buf + dest_pos, charcode); | |
| 191 } | |
| 192 result.ReleaseBuffer(dest_pos); | |
| 193 return result; | |
| 194 } | |
| 195 | 161 |
| 196 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { | 162 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { |
| 197 m_Flags = pFontDesc->GetIntegerBy("Flags", PDFFONT_NONSYMBOLIC); | 163 m_Flags = pFontDesc->GetIntegerBy("Flags", PDFFONT_NONSYMBOLIC); |
| 198 int ItalicAngle = 0; | 164 int ItalicAngle = 0; |
| 199 FX_BOOL bExistItalicAngle = FALSE; | 165 FX_BOOL bExistItalicAngle = FALSE; |
| 200 if (pFontDesc->KeyExist("ItalicAngle")) { | 166 if (pFontDesc->KeyExist("ItalicAngle")) { |
| 201 ItalicAngle = pFontDesc->GetIntegerBy("ItalicAngle"); | 167 ItalicAngle = pFontDesc->GetIntegerBy("ItalicAngle"); |
| 202 bExistItalicAngle = TRUE; | 168 bExistItalicAngle = TRUE; |
| 203 } | 169 } |
| 204 if (ItalicAngle < 0) { | 170 if (ItalicAngle < 0) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 if (!m_pFontDict) { | 398 if (!m_pFontDict) { |
| 433 return FALSE; | 399 return FALSE; |
| 434 } | 400 } |
| 435 CFX_ByteString type = m_pFontDict->GetStringBy("Subtype"); | 401 CFX_ByteString type = m_pFontDict->GetStringBy("Subtype"); |
| 436 m_BaseFont = m_pFontDict->GetStringBy("BaseFont"); | 402 m_BaseFont = m_pFontDict->GetStringBy("BaseFont"); |
| 437 if (type == "MMType1") { | 403 if (type == "MMType1") { |
| 438 type = "Type1"; | 404 type = "Type1"; |
| 439 } | 405 } |
| 440 return _Load(); | 406 return _Load(); |
| 441 } | 407 } |
| 442 static CFX_WideString _FontMap_GetWideString(CFX_CharMap* pMap, | 408 |
| 443 const CFX_ByteString& bytestr) { | |
| 444 return ((CPDF_FontCharMap*)pMap)->m_pFont->DecodeString(bytestr); | |
| 445 } | |
| 446 static CFX_ByteString _FontMap_GetByteString(CFX_CharMap* pMap, | |
| 447 const CFX_WideString& widestr) { | |
| 448 return ((CPDF_FontCharMap*)pMap)->m_pFont->EncodeString(widestr); | |
| 449 } | |
| 450 CPDF_FontCharMap::CPDF_FontCharMap(CPDF_Font* pFont) { | |
| 451 m_GetByteString = _FontMap_GetByteString; | |
| 452 m_GetWideString = _FontMap_GetWideString; | |
| 453 m_pFont = pFont; | |
| 454 } | |
| 455 CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode) { | 409 CFX_WideString CPDF_ToUnicodeMap::Lookup(FX_DWORD charcode) { |
| 456 auto it = m_Map.find(charcode); | 410 auto it = m_Map.find(charcode); |
| 457 if (it != m_Map.end()) { | 411 if (it != m_Map.end()) { |
| 458 FX_DWORD value = it->second; | 412 FX_DWORD value = it->second; |
| 459 FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff); | 413 FX_WCHAR unicode = (FX_WCHAR)(value & 0xffff); |
| 460 if (unicode != 0xffff) { | 414 if (unicode != 0xffff) { |
| 461 return unicode; | 415 return unicode; |
| 462 } | 416 } |
| 463 const FX_WCHAR* buf = m_MultiCharBuf.GetBuffer(); | 417 const FX_WCHAR* buf = m_MultiCharBuf.GetBuffer(); |
| 464 FX_DWORD buf_len = m_MultiCharBuf.GetLength(); | 418 FX_DWORD buf_len = m_MultiCharBuf.GetLength(); |
| (...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1736 rect = pChar->m_BBox; | 1690 rect = pChar->m_BBox; |
| 1737 } | 1691 } |
| 1738 | 1692 |
| 1739 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) | 1693 CPDF_Type3Char::CPDF_Type3Char(CPDF_Form* pForm) |
| 1740 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} | 1694 : m_pForm(pForm), m_pBitmap(nullptr), m_bColored(FALSE) {} |
| 1741 | 1695 |
| 1742 CPDF_Type3Char::~CPDF_Type3Char() { | 1696 CPDF_Type3Char::~CPDF_Type3Char() { |
| 1743 delete m_pForm; | 1697 delete m_pForm; |
| 1744 delete m_pBitmap; | 1698 delete m_pBitmap; |
| 1745 } | 1699 } |
| OLD | NEW |