| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/include/cpdf_font.h" | 7 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 int len = AppendChar(buf, charcode); | 158 int len = AppendChar(buf, charcode); |
| 159 if (len == 1) { | 159 if (len == 1) { |
| 160 str += buf[0]; | 160 str += buf[0]; |
| 161 } else { | 161 } else { |
| 162 str += CFX_ByteString(buf, len); | 162 str += CFX_ByteString(buf, len); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 CFX_WideString CPDF_Font::UnicodeFromCharCode(uint32_t charcode) const { | 166 CFX_WideString CPDF_Font::UnicodeFromCharCode(uint32_t charcode) const { |
| 167 if (!m_bToUnicodeLoaded) | 167 if (!m_bToUnicodeLoaded) |
| 168 ((CPDF_Font*)this)->LoadUnicodeMap(); | 168 LoadUnicodeMap(); |
| 169 | 169 |
| 170 if (m_pToUnicodeMap) | 170 if (m_pToUnicodeMap) |
| 171 return m_pToUnicodeMap->Lookup(charcode); | 171 return m_pToUnicodeMap->Lookup(charcode); |
| 172 return CFX_WideString(); | 172 return CFX_WideString(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 uint32_t CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { | 175 uint32_t CPDF_Font::CharCodeFromUnicode(FX_WCHAR unicode) const { |
| 176 if (!m_bToUnicodeLoaded) | 176 if (!m_bToUnicodeLoaded) |
| 177 ((CPDF_Font*)this)->LoadUnicodeMap(); | 177 LoadUnicodeMap(); |
| 178 | 178 |
| 179 if (m_pToUnicodeMap) | 179 if (m_pToUnicodeMap) |
| 180 return m_pToUnicodeMap->ReverseLookup(unicode); | 180 return m_pToUnicodeMap->ReverseLookup(unicode); |
| 181 return 0; | 181 return 0; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { | 184 void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { |
| 185 m_Flags = pFontDesc->GetIntegerBy("Flags", PDFFONT_NONSYMBOLIC); | 185 m_Flags = pFontDesc->GetIntegerBy("Flags", PDFFONT_NONSYMBOLIC); |
| 186 int ItalicAngle = 0; | 186 int ItalicAngle = 0; |
| 187 FX_BOOL bExistItalicAngle = FALSE; | 187 FX_BOOL bExistItalicAngle = FALSE; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 if (m_Ascent == 0 && m_Descent == 0) { | 289 if (m_Ascent == 0 && m_Descent == 0) { |
| 290 FX_RECT rect = GetCharBBox('A'); | 290 FX_RECT rect = GetCharBBox('A'); |
| 291 m_Ascent = rect.bottom == rect.top ? m_FontBBox.top : rect.top; | 291 m_Ascent = rect.bottom == rect.top ? m_FontBBox.top : rect.top; |
| 292 rect = GetCharBBox('g'); | 292 rect = GetCharBBox('g'); |
| 293 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom; | 293 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom; |
| 294 } | 294 } |
| 295 } | 295 } |
| 296 | 296 |
| 297 void CPDF_Font::LoadUnicodeMap() { | 297 void CPDF_Font::LoadUnicodeMap() const { |
| 298 m_bToUnicodeLoaded = TRUE; | 298 m_bToUnicodeLoaded = TRUE; |
| 299 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode"); | 299 CPDF_Stream* pStream = m_pFontDict->GetStreamBy("ToUnicode"); |
| 300 if (!pStream) { | 300 if (!pStream) { |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 m_pToUnicodeMap = new CPDF_ToUnicodeMap; | 303 m_pToUnicodeMap = new CPDF_ToUnicodeMap; |
| 304 m_pToUnicodeMap->Load(pStream); | 304 m_pToUnicodeMap->Load(pStream); |
| 305 } | 305 } |
| 306 | 306 |
| 307 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { | 307 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 if (charcode < 0 || charcode >= 256) | 462 if (charcode < 0 || charcode >= 256) |
| 463 return nullptr; | 463 return nullptr; |
| 464 | 464 |
| 465 const FX_CHAR* name = nullptr; | 465 const FX_CHAR* name = nullptr; |
| 466 if (pCharNames) | 466 if (pCharNames) |
| 467 name = pCharNames[charcode].c_str(); | 467 name = pCharNames[charcode].c_str(); |
| 468 if ((!name || name[0] == 0) && iBaseEncoding) | 468 if ((!name || name[0] == 0) && iBaseEncoding) |
| 469 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode); | 469 name = PDF_CharNameFromPredefinedCharSet(iBaseEncoding, charcode); |
| 470 return name && name[0] ? name : nullptr; | 470 return name && name[0] ? name : nullptr; |
| 471 } | 471 } |
| OLD | NEW |