diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fxge/android/cfpf_skiafont.cpp | 10 | ||||
-rw-r--r-- | core/fxge/android/cfpf_skiafontmgr.cpp | 42 | ||||
-rw-r--r-- | core/fxge/android/cfpf_skiapathfont.cpp | 34 | ||||
-rw-r--r-- | core/fxge/android/cfpf_skiapathfont.h | 29 |
4 files changed, 57 insertions, 58 deletions
diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp index 0118f9512e..242ddfd3bb 100644 --- a/core/fxge/android/cfpf_skiafont.cpp +++ b/core/fxge/android/cfpf_skiafont.cpp @@ -151,11 +151,9 @@ int32_t CFPF_SkiaFont::GetItalicAngle() const { if (!m_Face) return 0; - TT_Postscript* ttInfo = - (TT_Postscript*)FT_Get_Sfnt_Table(m_Face, ft_sfnt_post); - if (ttInfo) - return ttInfo->italicAngle; - return 0; + auto* info = + static_cast<TT_Postscript*>(FT_Get_Sfnt_Table(m_Face, ft_sfnt_post)); + return info ? info->italicAngle : 0; } uint32_t CFPF_SkiaFont::GetFontData(uint32_t dwTable, @@ -178,7 +176,7 @@ bool CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr* pFontMgr, if (!pFontMgr || !pFont) return false; - m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceIndex); + m_Face = pFontMgr->GetFontFace(pFont->path(), pFont->face_index()); if (!m_Face) return false; diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index 6edc334a9d..08b6fc5835 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp @@ -280,24 +280,24 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const ByteStringView& bsFamilyname, int32_t nGlyphNum = 0; for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) { const CFPF_SkiaPathFont* pFont = it->get(); - if (!(pFont->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) + if (!(pFont->charsets() & FPF_SkiaGetCharset(uCharset))) continue; int32_t nFind = 0; - uint32_t dwSysFontName = FPF_SKIANormalizeFontName(pFont->m_pFamily); + uint32_t dwSysFontName = FPF_SKIANormalizeFontName(pFont->family()); if (dwFaceName == dwSysFontName) nFind += FPF_SKIAMATCHWEIGHT_NAME1; bool bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); - if (FontStyleIsBold(dwStyle) == FontStyleIsBold(pFont->m_dwStyle)) + if (FontStyleIsBold(dwStyle) == FontStyleIsBold(pFont->style())) nFind += FPF_SKIAMATCHWEIGHT_1; - if (FontStyleIsItalic(dwStyle) == FontStyleIsItalic(pFont->m_dwStyle)) + if (FontStyleIsItalic(dwStyle) == FontStyleIsItalic(pFont->style())) nFind += FPF_SKIAMATCHWEIGHT_1; if (FontStyleIsFixedPitch(dwStyle) == - FontStyleIsFixedPitch(pFont->m_dwStyle)) { + FontStyleIsFixedPitch(pFont->style())) { nFind += FPF_SKIAMATCHWEIGHT_2; } - if (FontStyleIsSerif(dwStyle) == FontStyleIsSerif(pFont->m_dwStyle)) + if (FontStyleIsSerif(dwStyle) == FontStyleIsSerif(pFont->style())) nFind += FPF_SKIAMATCHWEIGHT_1; - if (FontStyleIsScript(dwStyle) == FontStyleIsScript(pFont->m_dwStyle)) + if (FontStyleIsScript(dwStyle) == FontStyleIsScript(pFont->style())) nFind += FPF_SKIAMATCHWEIGHT_2; if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) { nFind += FPF_SKIAMATCHWEIGHT_NAME2; @@ -309,9 +309,9 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const ByteStringView& bsFamilyname, pBestFont = it->get(); } } else if (FPF_SkiaIsCJK(uCharset)) { - if (bMatchedName || pFont->m_iGlyphNum > nGlyphNum) { + if (bMatchedName || pFont->glyph_num() > nGlyphNum) { pBestFont = it->get(); - nGlyphNum = pFont->m_iGlyphNum; + nGlyphNum = pFont->glyph_num(); } } else if (nFind > nMax) { nMax = nFind; @@ -388,29 +388,27 @@ void CFPF_SkiaFontMgr::ScanFile(const ByteString& file) { std::unique_ptr<CFPF_SkiaPathFont> CFPF_SkiaFontMgr::ReportFace( FXFT_Face face, const ByteString& file) { - auto pFont = pdfium::MakeUnique<CFPF_SkiaPathFont>(); - pFont->SetPath(file.c_str()); - pFont->SetFamily(FXFT_Get_Face_Family_Name(face)); + uint32_t dwStyle = 0; if (FXFT_Is_Face_Bold(face)) - pFont->m_dwStyle |= FXFONT_BOLD; + dwStyle |= FXFONT_BOLD; if (FXFT_Is_Face_Italic(face)) - pFont->m_dwStyle |= FXFONT_ITALIC; + dwStyle |= FXFONT_ITALIC; if (FT_IS_FIXED_WIDTH(face)) - pFont->m_dwStyle |= FXFONT_FIXED_PITCH; + dwStyle |= FXFONT_FIXED_PITCH; TT_OS2* pOS2 = static_cast<TT_OS2*>(FT_Get_Sfnt_Table(face, ft_sfnt_os2)); if (pOS2) { if (pOS2->ulCodePageRange1 & (1 << 31)) - pFont->m_dwStyle |= FXFONT_SYMBOLIC; + dwStyle |= FXFONT_SYMBOLIC; if (pOS2->panose[0] == 2) { uint8_t uSerif = pOS2->panose[1]; if ((uSerif > 1 && uSerif < 10) || uSerif > 13) - pFont->m_dwStyle |= FXFONT_SERIF; + dwStyle |= FXFONT_SERIF; } } if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) - pFont->m_dwStyle |= FXFONT_SYMBOLIC; - pFont->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); - pFont->m_iFaceIndex = face->face_index; - pFont->m_iGlyphNum = face->num_glyphs; - return pFont; + dwStyle |= FXFONT_SYMBOLIC; + + return pdfium::MakeUnique<CFPF_SkiaPathFont>( + file, FXFT_Get_Face_Family_Name(face), dwStyle, face->face_index, + FPF_SkiaGetFaceCharset(pOS2), face->num_glyphs); } diff --git a/core/fxge/android/cfpf_skiapathfont.cpp b/core/fxge/android/cfpf_skiapathfont.cpp index 063729f7e5..7fb797876d 100644 --- a/core/fxge/android/cfpf_skiapathfont.cpp +++ b/core/fxge/android/cfpf_skiapathfont.cpp @@ -8,25 +8,17 @@ #include "core/fxcrt/fx_memory.h" -CFPF_SkiaPathFont::CFPF_SkiaPathFont() {} +CFPF_SkiaPathFont::CFPF_SkiaPathFont(const ByteString& path, + const char* pFamily, + uint32_t dwStyle, + int32_t iFaceIndex, + uint32_t dwCharsets, + int32_t iGlyphNum) + : m_bsPath(path), + m_bsFamily(pFamily), + m_dwStyle(dwStyle), + m_iFaceIndex(iFaceIndex), + m_dwCharsets(dwCharsets), + m_iGlyphNum(iGlyphNum) {} -CFPF_SkiaPathFont::~CFPF_SkiaPathFont() { - FX_Free(m_pFamily); - FX_Free(m_pPath); -} - -void CFPF_SkiaPathFont::SetPath(const char* pPath) { - FX_Free(m_pPath); - int32_t iSize = strlen(pPath); - m_pPath = FX_Alloc(char, iSize + 1); - memcpy(m_pPath, pPath, iSize * sizeof(char)); - m_pPath[iSize] = 0; -} - -void CFPF_SkiaPathFont::SetFamily(const char* pFamily) { - FX_Free(m_pFamily); - int32_t iSize = strlen(pFamily); - m_pFamily = FX_Alloc(char, iSize + 1); - memcpy(m_pFamily, pFamily, iSize * sizeof(char)); - m_pFamily[iSize] = 0; -} +CFPF_SkiaPathFont::~CFPF_SkiaPathFont() = default; diff --git a/core/fxge/android/cfpf_skiapathfont.h b/core/fxge/android/cfpf_skiapathfont.h index e1d8994768..d091dc91c8 100644 --- a/core/fxge/android/cfpf_skiapathfont.h +++ b/core/fxge/android/cfpf_skiapathfont.h @@ -7,22 +7,33 @@ #ifndef CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_ #define CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_ +#include "core/fxcrt/bytestring.h" #include "core/fxcrt/fx_system.h" class CFPF_SkiaPathFont { public: - CFPF_SkiaPathFont(); + CFPF_SkiaPathFont(const ByteString& path, + const char* pFamily, + uint32_t dwStyle, + int32_t iFaceIndex, + uint32_t dwCharsets, + int32_t iGlyphNum); ~CFPF_SkiaPathFont(); - void SetPath(const char* pPath); - void SetFamily(const char* pFamily); + const char* path() const { return m_bsPath.c_str(); } + const char* family() const { return m_bsFamily.c_str(); } + uint32_t style() const { return m_dwStyle; } + int32_t face_index() const { return m_iFaceIndex; } + uint32_t charsets() const { return m_dwCharsets; } + int32_t glyph_num() const { return m_iGlyphNum; } - char* m_pPath = nullptr; - char* m_pFamily = nullptr; - uint32_t m_dwStyle = 0; - int32_t m_iFaceIndex = 0; - uint32_t m_dwCharsets = 0; - int32_t m_iGlyphNum = 0; + private: + const ByteString m_bsPath; + const ByteString m_bsFamily; + const uint32_t m_dwStyle; + const int32_t m_iFaceIndex; + const uint32_t m_dwCharsets; + const int32_t m_iGlyphNum; }; #endif // CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_ |