From 07388cae6fb525ccecc20f66ce530ac52d30d754 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 30 Aug 2018 20:24:22 +0000 Subject: Use span<> in CFX_FontMgr Change-Id: I3f811b20399efac1b511e75d950699eee7192c65 Reviewed-on: https://pdfium-review.googlesource.com/41650 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fxge/cfx_font.cpp | 4 ++-- core/fxge/cfx_fontmapper.cpp | 28 ++++++++++++---------------- core/fxge/cfx_fontmgr.cpp | 32 ++++++++++++++++---------------- core/fxge/cfx_fontmgr.h | 6 ++++-- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp index 3c2b48d4a3..4276d834fe 100644 --- a/core/fxge/cfx_font.cpp +++ b/core/fxge/cfx_font.cpp @@ -381,8 +381,8 @@ uint32_t CFX_Font::GetGlyphWidth(uint32_t glyph_index) { bool CFX_Font::LoadEmbedded(pdfium::span src_span) { m_pFontDataAllocation = std::vector(src_span.begin(), src_span.end()); - m_Face = CFX_GEModule::Get()->GetFontMgr()->GetFixedFace( - m_pFontDataAllocation.data(), m_pFontDataAllocation.size(), 0); + m_Face = + CFX_GEModule::Get()->GetFontMgr()->GetFixedFace(m_pFontDataAllocation, 0); m_bEmbedded = true; m_FontData = m_pFontDataAllocation; return !!m_Face; diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp index 461094d81e..0a38952d61 100644 --- a/core/fxge/cfx_fontmapper.cpp +++ b/core/fxge/cfx_fontmapper.cpp @@ -357,10 +357,10 @@ FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, if (iBaseFont < kNumStandardFonts) { if (m_FoxitFaces[iBaseFont]) return m_FoxitFaces[iBaseFont]; - const uint8_t* pFontData = nullptr; - uint32_t size = 0; - if (m_pFontMgr->GetBuiltinFont(iBaseFont, &pFontData, &size)) { - m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(pFontData, size, 0); + Optional> font_data = + m_pFontMgr->GetBuiltinFont(iBaseFont); + if (font_data.has_value()) { + m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(font_data.value(), 0); return m_FoxitFaces[iBaseFont]; } } @@ -371,21 +371,17 @@ FXFT_Face CFX_FontMapper::UseInternalSubst(CFX_SubstFont* pSubstFont, if (FontFamilyIsRoman(pitch_family)) { pSubstFont->m_Weight = pSubstFont->m_Weight * 4 / 5; pSubstFont->m_Family = "Chrome Serif"; - if (m_MMFaces[1]) - return m_MMFaces[1]; - const uint8_t* pFontData = nullptr; - uint32_t size = 0; - m_pFontMgr->GetBuiltinFont(14, &pFontData, &size); - m_MMFaces[1] = m_pFontMgr->GetFixedFace(pFontData, size, 0); + if (!m_MMFaces[1]) { + m_MMFaces[1] = + m_pFontMgr->GetFixedFace(m_pFontMgr->GetBuiltinFont(14).value(), 0); + } return m_MMFaces[1]; } pSubstFont->m_Family = "Chrome Sans"; - if (m_MMFaces[0]) - return m_MMFaces[0]; - const uint8_t* pFontData = nullptr; - uint32_t size = 0; - m_pFontMgr->GetBuiltinFont(15, &pFontData, &size); - m_MMFaces[0] = m_pFontMgr->GetFixedFace(pFontData, size, 0); + if (!m_MMFaces[0]) { + m_MMFaces[0] = + m_pFontMgr->GetFixedFace(m_pFontMgr->GetBuiltinFont(15).value(), 0); + } return m_MMFaces[0]; } diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp index 85999a1976..0a19156b46 100644 --- a/core/fxge/cfx_fontmgr.cpp +++ b/core/fxge/cfx_fontmgr.cpp @@ -167,8 +167,9 @@ FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, *pFontData = pFontDesc->FontData(); int face_index = GetTTCIndex(pFontDesc->FontData(), ttc_size, font_offset); if (!pFontDesc->GetFace(face_index)) { - pFontDesc->SetFace( - face_index, GetFixedFace(pFontDesc->FontData(), ttc_size, face_index)); + pFontDesc->SetFace(face_index, GetFixedFace({pFontDesc->FontData(), + static_cast(ttc_size)}, + face_index)); } pFontDesc->AddRef(); return pFontDesc->GetFace(face_index); @@ -181,20 +182,22 @@ FXFT_Face CFX_FontMgr::AddCachedTTCFace( uint32_t size, int font_offset) { int face_index = GetTTCIndex(pData.get(), ttc_size, font_offset); - FXFT_Face face = GetFixedFace(pData.get(), ttc_size, face_index); + FXFT_Face face = + GetFixedFace({pData.get(), static_cast(ttc_size)}, face_index); auto pFontDesc = pdfium::MakeUnique(std::move(pData)); pFontDesc->SetFace(face_index, face); m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = std::move(pFontDesc); return face; } -FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData, - uint32_t size, +FXFT_Face CFX_FontMgr::GetFixedFace(pdfium::span span, int face_index) { InitFTLibrary(); FXFT_Face face = nullptr; - if (FXFT_New_Memory_Face(m_FTLibrary, pData, size, face_index, &face)) + if (FXFT_New_Memory_Face(m_FTLibrary, span.data(), span.size(), face_index, + &face)) { return nullptr; + } return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face; } @@ -223,21 +226,18 @@ void CFX_FontMgr::ReleaseFace(FXFT_Face face) { FXFT_Done_Face(face); } -bool CFX_FontMgr::GetBuiltinFont(size_t index, - const uint8_t** pFontData, - uint32_t* size) { +Optional> CFX_FontMgr::GetBuiltinFont( + size_t index) { if (index < FX_ArraySize(g_FoxitFonts)) { - *pFontData = g_FoxitFonts[index].m_pFontData; - *size = g_FoxitFonts[index].m_dwSize; - return true; + return pdfium::make_span(g_FoxitFonts[index].m_pFontData, + g_FoxitFonts[index].m_dwSize); } size_t mm_index = index - FX_ArraySize(g_FoxitFonts); if (mm_index < FX_ArraySize(g_MMFonts)) { - *pFontData = g_MMFonts[mm_index].m_pFontData; - *size = g_MMFonts[mm_index].m_dwSize; - return true; + return pdfium::make_span(g_MMFonts[mm_index].m_pFontData, + g_MMFonts[mm_index].m_dwSize); } - return false; + return {}; } bool CFX_FontMgr::FreeTypeVersionSupportsHinting() const { diff --git a/core/fxge/cfx_fontmgr.h b/core/fxge/cfx_fontmgr.h index 24c5ad3b6f..5ac8305d9a 100644 --- a/core/fxge/cfx_fontmgr.h +++ b/core/fxge/cfx_fontmgr.h @@ -12,6 +12,8 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxge/fx_font.h" +#include "third_party/base/optional.h" +#include "third_party/base/span.h" class CFX_FontMapper; class CFX_SubstFont; @@ -45,7 +47,7 @@ class CFX_FontMgr { uint32_t size, int font_offset); FXFT_Face GetFileFace(const char* filename, int face_index); - FXFT_Face GetFixedFace(const uint8_t* pData, uint32_t size, int face_index); + FXFT_Face GetFixedFace(pdfium::span span, int face_index); void ReleaseFace(FXFT_Face face); void SetSystemFontInfo(std::unique_ptr pFontInfo); FXFT_Face FindSubstFont(const ByteString& face_name, @@ -55,7 +57,7 @@ class CFX_FontMgr { int italic_angle, int CharsetCP, CFX_SubstFont* pSubstFont); - bool GetBuiltinFont(size_t index, const uint8_t** pFontData, uint32_t* size); + Optional> GetBuiltinFont(size_t index); CFX_FontMapper* GetBuiltinMapper() const { return m_pBuiltinMapper.get(); } FXFT_Library GetFTLibrary() const { return m_FTLibrary; } bool FTLibrarySupportsHinting() const { return m_FTLibrarySupportsHinting; } -- cgit v1.2.3