| 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/fxge/fx_font.h" | 7 #include "core/fxge/fx_font.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 unsigned long FTStreamRead(FXFT_Stream stream, | 41 unsigned long FTStreamRead(FXFT_Stream stream, |
| 42 unsigned long offset, | 42 unsigned long offset, |
| 43 unsigned char* buffer, | 43 unsigned char* buffer, |
| 44 unsigned long count) { | 44 unsigned long count) { |
| 45 if (count == 0) | 45 if (count == 0) |
| 46 return 0; | 46 return 0; |
| 47 | 47 |
| 48 IFX_SeekableReadStream* pFile = | 48 IFX_SeekableReadStream* pFile = |
| 49 static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer); | 49 static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer); |
| 50 return pFile->ReadBlock(buffer, offset, count) ? count : 0; | 50 if (!pFile) |
| 51 return 0; |
| 52 |
| 53 if (!pFile->ReadBlock(buffer, offset, count)) |
| 54 return 0; |
| 55 |
| 56 return count; |
| 51 } | 57 } |
| 52 | 58 |
| 53 void FTStreamClose(FXFT_Stream stream) {} | 59 void FTStreamClose(FXFT_Stream stream) {} |
| 54 | 60 |
| 55 bool LoadFileImp(FXFT_Library library, | 61 bool LoadFileImp(FXFT_Library library, |
| 56 FXFT_Face* Face, | 62 FXFT_Face* Face, |
| 57 IFX_SeekableReadStream* pFile, | 63 const CFX_RetainPtr<IFX_SeekableReadStream>& pFile, |
| 58 int32_t faceIndex, | 64 int32_t faceIndex, |
| 59 std::unique_ptr<FXFT_StreamRec>* stream) { | 65 std::unique_ptr<FXFT_StreamRec>* stream) { |
| 60 std::unique_ptr<FXFT_StreamRec> stream1(new FXFT_StreamRec()); | 66 auto stream1 = pdfium::MakeUnique<FXFT_StreamRec>(); |
| 61 stream1->base = nullptr; | 67 stream1->base = nullptr; |
| 62 stream1->size = static_cast<unsigned long>(pFile->GetSize()); | 68 stream1->size = static_cast<unsigned long>(pFile->GetSize()); |
| 63 stream1->pos = 0; | 69 stream1->pos = 0; |
| 64 stream1->descriptor.pointer = pFile; | 70 stream1->descriptor.pointer = static_cast<void*>(pFile.Get()); |
| 65 stream1->close = FTStreamClose; | 71 stream1->close = FTStreamClose; |
| 66 stream1->read = FTStreamRead; | 72 stream1->read = FTStreamRead; |
| 67 FXFT_Open_Args args; | 73 FXFT_Open_Args args; |
| 68 args.flags = FT_OPEN_STREAM; | 74 args.flags = FT_OPEN_STREAM; |
| 69 args.stream = stream1.get(); | 75 args.stream = stream1.get(); |
| 70 if (FXFT_Open_Face(library, &args, faceIndex, Face)) | 76 if (FXFT_Open_Face(library, &args, faceIndex, Face)) |
| 71 return false; | 77 return false; |
| 72 if (stream) | 78 if (stream) |
| 73 *stream = std::move(stream1); | 79 *stream = std::move(stream1); |
| 74 return true; | 80 return true; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( | 337 m_Face = CFX_GEModule::Get()->GetFontMgr()->FindSubstFont( |
| 332 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, | 338 face_name, bTrueType, flags, weight, italic_angle, CharsetCP, |
| 333 m_pSubstFont.get()); | 339 m_pSubstFont.get()); |
| 334 if (m_Face) { | 340 if (m_Face) { |
| 335 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); | 341 m_pFontData = FXFT_Get_Face_Stream_Base(m_Face); |
| 336 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); | 342 m_dwSize = FXFT_Get_Face_Stream_Size(m_Face); |
| 337 } | 343 } |
| 338 } | 344 } |
| 339 | 345 |
| 340 #ifdef PDF_ENABLE_XFA | 346 #ifdef PDF_ENABLE_XFA |
| 341 bool CFX_Font::LoadFile(IFX_SeekableReadStream* pFile, | 347 bool CFX_Font::LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile, |
| 342 int nFaceIndex, | 348 int nFaceIndex, |
| 343 int* pFaceCount) { | 349 int* pFaceCount) { |
| 344 m_bEmbedded = false; | 350 m_bEmbedded = false; |
| 345 | 351 |
| 346 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | 352 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); |
| 347 pFontMgr->InitFTLibrary(); | 353 pFontMgr->InitFTLibrary(); |
| 354 |
| 348 FXFT_Library library = pFontMgr->GetFTLibrary(); | 355 FXFT_Library library = pFontMgr->GetFTLibrary(); |
| 349 | |
| 350 std::unique_ptr<FXFT_StreamRec> stream; | 356 std::unique_ptr<FXFT_StreamRec> stream; |
| 351 if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream)) | 357 if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream)) |
| 352 return false; | 358 return false; |
| 353 | 359 |
| 354 if (pFaceCount) | 360 if (pFaceCount) |
| 355 *pFaceCount = (int)m_Face->num_faces; | 361 *pFaceCount = (int)m_Face->num_faces; |
| 356 m_pOwnedStream = stream.release(); | 362 m_pOwnedStream = stream.release(); |
| 357 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 363 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
| 358 return true; | 364 return true; |
| 359 } | 365 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, | 719 const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, |
| 714 int dest_width) const { | 720 int dest_width) const { |
| 715 return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width); | 721 return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width); |
| 716 } | 722 } |
| 717 | 723 |
| 718 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ | 724 #if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ |
| 719 CFX_TypeFace* CFX_Font::GetDeviceCache() const { | 725 CFX_TypeFace* CFX_Font::GetDeviceCache() const { |
| 720 return GetFaceCache()->GetDeviceCache(this); | 726 return GetFaceCache()->GetDeviceCache(this); |
| 721 } | 727 } |
| 722 #endif | 728 #endif |
| OLD | NEW |