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/font/cpdf_font.h" | 7 #include "core/fpdfapi/font/cpdf_font.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom; | 272 m_Descent = rect.bottom == rect.top ? m_FontBBox.bottom : rect.bottom; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 void CPDF_Font::LoadUnicodeMap() const { | 276 void CPDF_Font::LoadUnicodeMap() const { |
277 m_bToUnicodeLoaded = true; | 277 m_bToUnicodeLoaded = true; |
278 CPDF_Stream* pStream = m_pFontDict->GetStreamFor("ToUnicode"); | 278 CPDF_Stream* pStream = m_pFontDict->GetStreamFor("ToUnicode"); |
279 if (!pStream) { | 279 if (!pStream) { |
280 return; | 280 return; |
281 } | 281 } |
282 m_pToUnicodeMap.reset(new CPDF_ToUnicodeMap); | 282 m_pToUnicodeMap = pdfium::MakeUnique<CPDF_ToUnicodeMap>(); |
283 m_pToUnicodeMap->Load(pStream); | 283 m_pToUnicodeMap->Load(pStream); |
284 } | 284 } |
285 | 285 |
286 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { | 286 int CPDF_Font::GetStringWidth(const FX_CHAR* pString, int size) { |
287 int offset = 0; | 287 int offset = 0; |
288 int width = 0; | 288 int width = 0; |
289 while (offset < size) { | 289 while (offset < size) { |
290 uint32_t charcode = GetNextChar(pString, size, offset); | 290 uint32_t charcode = GetNextChar(pString, size, offset); |
291 width += GetCharWidthF(charcode); | 291 width += GetCharWidthF(charcode); |
292 } | 292 } |
(...skipping 24 matching lines...) Expand all Loading... |
317 std::unique_ptr<CPDF_Font> CPDF_Font::Create(CPDF_Document* pDoc, | 317 std::unique_ptr<CPDF_Font> CPDF_Font::Create(CPDF_Document* pDoc, |
318 CPDF_Dictionary* pFontDict) { | 318 CPDF_Dictionary* pFontDict) { |
319 CFX_ByteString type = pFontDict->GetStringFor("Subtype"); | 319 CFX_ByteString type = pFontDict->GetStringFor("Subtype"); |
320 std::unique_ptr<CPDF_Font> pFont; | 320 std::unique_ptr<CPDF_Font> pFont; |
321 if (type == "TrueType") { | 321 if (type == "TrueType") { |
322 CFX_ByteString tag = pFontDict->GetStringFor("BaseFont").Left(4); | 322 CFX_ByteString tag = pFontDict->GetStringFor("BaseFont").Left(4); |
323 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) { | 323 for (size_t i = 0; i < FX_ArraySize(kChineseFontNames); ++i) { |
324 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) { | 324 if (tag == CFX_ByteString(kChineseFontNames[i], 4)) { |
325 CPDF_Dictionary* pFontDesc = pFontDict->GetDictFor("FontDescriptor"); | 325 CPDF_Dictionary* pFontDesc = pFontDict->GetDictFor("FontDescriptor"); |
326 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) | 326 if (!pFontDesc || !pFontDesc->KeyExist("FontFile2")) |
327 pFont.reset(new CPDF_CIDFont); | 327 pFont = pdfium::MakeUnique<CPDF_CIDFont>(); |
328 break; | 328 break; |
329 } | 329 } |
330 } | 330 } |
331 if (!pFont) | 331 if (!pFont) |
332 pFont.reset(new CPDF_TrueTypeFont); | 332 pFont = pdfium::MakeUnique<CPDF_TrueTypeFont>(); |
333 } else if (type == "Type3") { | 333 } else if (type == "Type3") { |
334 pFont.reset(new CPDF_Type3Font); | 334 pFont = pdfium::MakeUnique<CPDF_Type3Font>(); |
335 } else if (type == "Type0") { | 335 } else if (type == "Type0") { |
336 pFont.reset(new CPDF_CIDFont); | 336 pFont = pdfium::MakeUnique<CPDF_CIDFont>(); |
337 } else { | 337 } else { |
338 pFont.reset(new CPDF_Type1Font); | 338 pFont = pdfium::MakeUnique<CPDF_Type1Font>(); |
339 } | 339 } |
340 pFont->m_pFontDict = pFontDict; | 340 pFont->m_pFontDict = pFontDict; |
341 pFont->m_pDocument = pDoc; | 341 pFont->m_pDocument = pDoc; |
342 pFont->m_BaseFont = pFontDict->GetStringFor("BaseFont"); | 342 pFont->m_BaseFont = pFontDict->GetStringFor("BaseFont"); |
343 return pFont->Load() ? std::move(pFont) : nullptr; | 343 return pFont->Load() ? std::move(pFont) : nullptr; |
344 } | 344 } |
345 | 345 |
346 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, | 346 uint32_t CPDF_Font::GetNextChar(const FX_CHAR* pString, |
347 int nStrLen, | 347 int nStrLen, |
348 int& offset) const { | 348 int& offset) const { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 if (fallbackFont < 0 || | 464 if (fallbackFont < 0 || |
465 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { | 465 fallbackFont >= pdfium::CollectionSize<int>(m_FontFallbacks)) { |
466 return -1; | 466 return -1; |
467 } | 467 } |
468 int glyph = | 468 int glyph = |
469 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); | 469 FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); |
470 if (glyph == 0 || glyph == 0xffff) | 470 if (glyph == 0 || glyph == 0xffff) |
471 return -1; | 471 return -1; |
472 return glyph; | 472 return glyph; |
473 } | 473 } |
OLD | NEW |