From cfcc11e53a60b3f56a9bbe13718ecb9b997384da Mon Sep 17 00:00:00 2001 From: npm Date: Tue, 25 Oct 2016 14:26:39 -0700 Subject: Name core/fxge/android files appropriately and use one file per class - Rename files so that they correspond to class names. - Remove OS_Android ifs, since they are unneeded. - Split fpf_skiafontmgr.h into classes, one per file. Review-Url: https://codereview.chromium.org/2448293002 --- BUILD.gn | 18 ++- core/fxge/android/cfpf_skiabufferfont.h | 25 ++++ core/fxge/android/cfpf_skiadevicemodule.cpp | 41 ++++++ core/fxge/android/cfpf_skiadevicemodule.h | 26 ++++ core/fxge/android/cfpf_skiafilefont.h | 25 ++++ core/fxge/android/cfpf_skiafont.cpp | 219 ++++++++++++++++++++++++++++ core/fxge/android/cfpf_skiafont.h | 53 +++++++ core/fxge/android/cfpf_skiafontdescriptor.h | 40 +++++ core/fxge/android/cfpf_skiafontmgr.cpp | 10 +- core/fxge/android/cfpf_skiafontmgr.h | 52 +++++++ core/fxge/android/cfpf_skiapathfont.h | 33 +++++ core/fxge/android/cfx_androidfontinfo.cpp | 87 +++++++++++ core/fxge/android/cfx_androidfontinfo.h | 45 ++++++ core/fxge/android/fpf_skiafont.cpp | 215 --------------------------- core/fxge/android/fpf_skiafont.h | 53 ------- core/fxge/android/fpf_skiafontmgr.h | 124 ---------------- core/fxge/android/fpf_skiamodule.cpp | 46 ------ core/fxge/android/fpf_skiamodule.h | 34 ----- core/fxge/android/fx_android_font.cpp | 91 ------------ core/fxge/android/fx_android_font.h | 50 ------- core/fxge/android/fx_android_imp.cpp | 11 +- 21 files changed, 666 insertions(+), 632 deletions(-) create mode 100644 core/fxge/android/cfpf_skiabufferfont.h create mode 100644 core/fxge/android/cfpf_skiadevicemodule.cpp create mode 100644 core/fxge/android/cfpf_skiadevicemodule.h create mode 100644 core/fxge/android/cfpf_skiafilefont.h create mode 100644 core/fxge/android/cfpf_skiafont.cpp create mode 100644 core/fxge/android/cfpf_skiafont.h create mode 100644 core/fxge/android/cfpf_skiafontdescriptor.h create mode 100644 core/fxge/android/cfpf_skiafontmgr.h create mode 100644 core/fxge/android/cfpf_skiapathfont.h create mode 100644 core/fxge/android/cfx_androidfontinfo.cpp create mode 100644 core/fxge/android/cfx_androidfontinfo.h delete mode 100644 core/fxge/android/fpf_skiafont.cpp delete mode 100644 core/fxge/android/fpf_skiafont.h delete mode 100644 core/fxge/android/fpf_skiafontmgr.h delete mode 100644 core/fxge/android/fpf_skiamodule.cpp delete mode 100644 core/fxge/android/fpf_skiamodule.h delete mode 100644 core/fxge/android/fx_android_font.cpp delete mode 100644 core/fxge/android/fx_android_font.h diff --git a/BUILD.gn b/BUILD.gn index 05408e0712..a77ea4c6b2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -746,14 +746,18 @@ static_library("fxcrt") { static_library("fxge") { sources = [ + "core/fxge/android/cfpf_skiabufferfont.h", + "core/fxge/android/cfpf_skiadevicemodule.cpp", + "core/fxge/android/cfpf_skiadevicemodule.h", + "core/fxge/android/cfpf_skiafilefont.h", + "core/fxge/android/cfpf_skiafont.cpp", + "core/fxge/android/cfpf_skiafont.h", + "core/fxge/android/cfpf_skiafontdescriptor.h", "core/fxge/android/cfpf_skiafontmgr.cpp", - "core/fxge/android/fpf_skiafont.cpp", - "core/fxge/android/fpf_skiafont.h", - "core/fxge/android/fpf_skiafontmgr.h", - "core/fxge/android/fpf_skiamodule.cpp", - "core/fxge/android/fpf_skiamodule.h", - "core/fxge/android/fx_android_font.cpp", - "core/fxge/android/fx_android_font.h", + "core/fxge/android/cfpf_skiafontmgr.h", + "core/fxge/android/cfpf_skiapathfont.h", + "core/fxge/android/cfx_androidfontinfo.cpp", + "core/fxge/android/cfx_androidfontinfo.h", "core/fxge/android/fx_android_imp.cpp", "core/fxge/apple/apple_int.h", "core/fxge/apple/cfx_quartzdevice.h", diff --git a/core/fxge/android/cfpf_skiabufferfont.h b/core/fxge/android/cfpf_skiabufferfont.h new file mode 100644 index 0000000000..02fdadea1e --- /dev/null +++ b/core/fxge/android/cfpf_skiabufferfont.h @@ -0,0 +1,25 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIABUFFERFONT_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIABUFFERFONT_H_ + +#include "core/fxge/android/cfpf_skiafontdescriptor.h" + +#define FPF_SKIAFONTTYPE_Buffer 3 + +class CFPF_SkiaBufferFont : public CFPF_SkiaFontDescriptor { + public: + CFPF_SkiaBufferFont() : m_pBuffer(nullptr), m_szBuffer(0) {} + + // CFPF_SkiaFontDescriptor + int32_t GetType() const override { return FPF_SKIAFONTTYPE_Buffer; } + + void* m_pBuffer; + size_t m_szBuffer; +}; + +#endif // CORE_FXGE_ANDROID_CFPF_SKIABUFFERFONT_H_ diff --git a/core/fxge/android/cfpf_skiadevicemodule.cpp b/core/fxge/android/cfpf_skiadevicemodule.cpp new file mode 100644 index 0000000000..7bdf64666f --- /dev/null +++ b/core/fxge/android/cfpf_skiadevicemodule.cpp @@ -0,0 +1,41 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/android/cfpf_skiadevicemodule.h" + +#include "core/fxge/android/cfpf_skiafontmgr.h" + +namespace { + +CFPF_SkiaDeviceModule* gs_pPFModule = nullptr; + +} // namespace + +CFPF_SkiaDeviceModule* CFPF_GetSkiaDeviceModule() { + if (!gs_pPFModule) + gs_pPFModule = new CFPF_SkiaDeviceModule; + return gs_pPFModule; +} + +CFPF_SkiaDeviceModule::~CFPF_SkiaDeviceModule() { + delete m_pFontMgr; +} + +void CFPF_SkiaDeviceModule::Destroy() { + delete gs_pPFModule; + gs_pPFModule = nullptr; +} + +CFPF_SkiaFontMgr* CFPF_SkiaDeviceModule::GetFontMgr() { + if (!m_pFontMgr) { + m_pFontMgr = new CFPF_SkiaFontMgr; + if (!m_pFontMgr->InitFTLibrary()) { + delete m_pFontMgr; + return nullptr; + } + } + return m_pFontMgr; +} diff --git a/core/fxge/android/cfpf_skiadevicemodule.h b/core/fxge/android/cfpf_skiadevicemodule.h new file mode 100644 index 0000000000..3261820039 --- /dev/null +++ b/core/fxge/android/cfpf_skiadevicemodule.h @@ -0,0 +1,26 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIADEVICEMODULE_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIADEVICEMODULE_H_ + +class CFPF_SkiaFontMgr; + +class CFPF_SkiaDeviceModule { + public: + CFPF_SkiaDeviceModule() : m_pFontMgr(nullptr) {} + ~CFPF_SkiaDeviceModule(); + + void Destroy(); + CFPF_SkiaFontMgr* GetFontMgr(); + + protected: + CFPF_SkiaFontMgr* m_pFontMgr; +}; + +CFPF_SkiaDeviceModule* CFPF_GetSkiaDeviceModule(); + +#endif // CORE_FXGE_ANDROID_CFPF_SKIADEVICEMODULE_H_ diff --git a/core/fxge/android/cfpf_skiafilefont.h b/core/fxge/android/cfpf_skiafilefont.h new file mode 100644 index 0000000000..b6657bf978 --- /dev/null +++ b/core/fxge/android/cfpf_skiafilefont.h @@ -0,0 +1,25 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_ + +#include "core/fxge/android/cfpf_skiafontdescriptor.h" + +class IFX_SeekableReadStream; + +#define FPF_SKIAFONTTYPE_File 2 + +class CFPF_SkiaFileFont : public CFPF_SkiaFontDescriptor { + public: + CFPF_SkiaFileFont() : m_pFile(nullptr) {} + + // CFPF_SkiaFontDescriptor + int32_t GetType() const override { return FPF_SKIAFONTTYPE_File; } + IFX_SeekableReadStream* m_pFile; +}; + +#endif // CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_ diff --git a/core/fxge/android/cfpf_skiafont.cpp b/core/fxge/android/cfpf_skiafont.cpp new file mode 100644 index 0000000000..c7cfd4d324 --- /dev/null +++ b/core/fxge/android/cfpf_skiafont.cpp @@ -0,0 +1,219 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/android/cfpf_skiafont.h" + +#include + +#include "core/fxcrt/fx_system.h" +#include "core/fxge/android/cfpf_skiabufferfont.h" +#include "core/fxge/android/cfpf_skiafilefont.h" +#include "core/fxge/android/cfpf_skiafontdescriptor.h" +#include "core/fxge/android/cfpf_skiafontmgr.h" +#include "core/fxge/android/cfpf_skiapathfont.h" +#include "core/fxge/fx_freetype.h" + +#define FPF_EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) + +CFPF_SkiaFont::CFPF_SkiaFont() + : m_pFontMgr(nullptr), + m_pFontDes(nullptr), + m_Face(nullptr), + m_dwStyle(0), + m_uCharset(0), + m_dwRefCount(0) {} + +CFPF_SkiaFont::~CFPF_SkiaFont() { + if (m_Face) + FXFT_Done_Face(m_Face); +} + +void CFPF_SkiaFont::Release() { + if (--m_dwRefCount == 0) + delete this; +} + +CFPF_SkiaFont* CFPF_SkiaFont::Retain() { + m_dwRefCount++; + return this; +} + +CFX_ByteString CFPF_SkiaFont::GetFamilyName() { + if (!m_Face) + return CFX_ByteString(); + return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); +} + +CFX_ByteString CFPF_SkiaFont::GetPsName() { + if (!m_Face) + return CFX_ByteString(); + return FXFT_Get_Postscript_Name(m_Face); +} + +int32_t CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) { + if (!m_Face) + return wUnicode; + if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE)) + return 0; + return FXFT_Get_Char_Index(m_Face, wUnicode); +} + +int32_t CFPF_SkiaFont::GetGlyphWidth(int32_t iGlyphIndex) { + if (!m_Face) + return 0; + if (FXFT_Load_Glyph( + m_Face, iGlyphIndex, + FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { + return 0; + } + return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Glyph_HoriAdvance(m_Face)); +} + +int32_t CFPF_SkiaFont::GetAscent() const { + if (!m_Face) + return 0; + return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_Ascender(m_Face)); +} + +int32_t CFPF_SkiaFont::GetDescent() const { + if (!m_Face) + return 0; + return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_Descender(m_Face)); +} + +FX_BOOL CFPF_SkiaFont::GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox) { + if (!m_Face) + return FALSE; + if (FXFT_Is_Face_Tricky(m_Face)) { + if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) + return FALSE; + if (FXFT_Load_Glyph(m_Face, iGlyphIndex, + FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { + FXFT_Set_Pixel_Sizes(m_Face, 0, 64); + return FALSE; + } + FXFT_Glyph glyph; + if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { + FXFT_Set_Pixel_Sizes(m_Face, 0, 64); + return FALSE; + } + FXFT_BBox cbox; + FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); + int32_t x_ppem = m_Face->size->metrics.x_ppem; + int32_t y_ppem = m_Face->size->metrics.y_ppem; + rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); + rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); + rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); + rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); + rtBBox.top = std::min(rtBBox.top, GetAscent()); + rtBBox.bottom = std::max(rtBBox.bottom, GetDescent()); + FXFT_Done_Glyph(glyph); + return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; + } + if (FXFT_Load_Glyph( + m_Face, iGlyphIndex, + FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { + return FALSE; + } + rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Glyph_HoriBearingX(m_Face)); + rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Glyph_HoriBearingY(m_Face)); + rtBBox.right = FPF_EM_ADJUST( + FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); + rtBBox.top = FPF_EM_ADJUST( + FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); + return TRUE; +} + +FX_BOOL CFPF_SkiaFont::GetBBox(FX_RECT& rtBBox) { + if (!m_Face) { + return FALSE; + } + rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_xMin(m_Face)); + rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_yMin(m_Face)); + rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_xMax(m_Face)); + rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_yMax(m_Face)); + return TRUE; +} + +int32_t CFPF_SkiaFont::GetHeight() const { + if (!m_Face) + return 0; + return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), + FXFT_Get_Face_Height(m_Face)); +} + +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; +} + +uint32_t CFPF_SkiaFont::GetFontData(uint32_t dwTable, + uint8_t* pBuffer, + uint32_t dwSize) { + if (!m_Face) + return 0; + + FT_ULong ulSize = pdfium::base::checked_cast(dwSize); + if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, &ulSize)) + return 0; + return pdfium::base::checked_cast(ulSize); +} + +FX_BOOL CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr* pFontMgr, + CFPF_SkiaFontDescriptor* pFontDes, + const CFX_ByteStringC& bsFamily, + uint32_t dwStyle, + uint8_t uCharset) { + if (!pFontMgr || !pFontDes) + return FALSE; + + switch (pFontDes->GetType()) { + case FPF_SKIAFONTTYPE_Path: { + CFPF_SkiaPathFont* pFont = (CFPF_SkiaPathFont*)pFontDes; + m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceIndex); + break; + } + case FPF_SKIAFONTTYPE_File: { + CFPF_SkiaFileFont* pFont = (CFPF_SkiaFileFont*)pFontDes; + m_Face = pFontMgr->GetFontFace(pFont->m_pFile, pFont->m_iFaceIndex); + break; + } + case FPF_SKIAFONTTYPE_Buffer: { + CFPF_SkiaBufferFont* pFont = (CFPF_SkiaBufferFont*)pFontDes; + m_Face = pFontMgr->GetFontFace((const uint8_t*)pFont->m_pBuffer, + pFont->m_szBuffer, pFont->m_iFaceIndex); + break; + } + default: + return FALSE; + } + if (!m_Face) + return FALSE; + + m_dwStyle = dwStyle; + m_uCharset = uCharset; + m_pFontMgr = pFontMgr; + m_pFontDes = pFontDes; + m_dwRefCount = 1; + return TRUE; +} diff --git a/core/fxge/android/cfpf_skiafont.h b/core/fxge/android/cfpf_skiafont.h new file mode 100644 index 0000000000..ad0245d5d6 --- /dev/null +++ b/core/fxge/android/cfpf_skiafont.h @@ -0,0 +1,53 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_ + +#include "core/fxcrt/fx_system.h" +#include "core/fxge/fx_font.h" + +class CFPF_SkiaFontDescriptor; +class CFPF_SkiaFontMgr; + +class CFPF_SkiaFont { + public: + CFPF_SkiaFont(); + ~CFPF_SkiaFont(); + + void Release(); + CFPF_SkiaFont* Retain(); + + CFX_ByteString GetFamilyName(); + CFX_ByteString GetPsName(); + uint32_t GetFontStyle() const { return m_dwStyle; } + uint8_t GetCharset() const { return m_uCharset; } + int32_t GetGlyphIndex(FX_WCHAR wUnicode); + int32_t GetGlyphWidth(int32_t iGlyphIndex); + int32_t GetAscent() const; + int32_t GetDescent() const; + FX_BOOL GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox); + FX_BOOL GetBBox(FX_RECT& rtBBox); + int32_t GetHeight() const; + int32_t GetItalicAngle() const; + uint32_t GetFontData(uint32_t dwTable, uint8_t* pBuffer, uint32_t dwSize); + + FX_BOOL InitFont(CFPF_SkiaFontMgr* pFontMgr, + CFPF_SkiaFontDescriptor* pFontDes, + const CFX_ByteStringC& bsFamily, + uint32_t dwStyle, + uint8_t uCharset); + + private: + CFPF_SkiaFontMgr* m_pFontMgr; + CFPF_SkiaFontDescriptor* m_pFontDes; + FXFT_Face m_Face; + uint32_t m_dwStyle; + uint8_t m_uCharset; + uint32_t m_dwRefCount; +}; + +#endif // CORE_FXGE_ANDROID_CFPF_SKIAFONT_H_ diff --git a/core/fxge/android/cfpf_skiafontdescriptor.h b/core/fxge/android/cfpf_skiafontdescriptor.h new file mode 100644 index 0000000000..57b85404ad --- /dev/null +++ b/core/fxge/android/cfpf_skiafontdescriptor.h @@ -0,0 +1,40 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFONTDESCRIPTOR_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIAFONTDESCRIPTOR_H_ + +#include "core/fxcrt/fx_system.h" + +#define FPF_SKIAFONTTYPE_Unknown 0 + +class CFPF_SkiaFontDescriptor { + public: + CFPF_SkiaFontDescriptor() + : m_pFamily(nullptr), + m_dwStyle(0), + m_iFaceIndex(0), + m_dwCharsets(0), + m_iGlyphNum(0) {} + virtual ~CFPF_SkiaFontDescriptor() { FX_Free(m_pFamily); } + + virtual int32_t GetType() const { return FPF_SKIAFONTTYPE_Unknown; } + + void SetFamily(const FX_CHAR* pFamily) { + FX_Free(m_pFamily); + int32_t iSize = FXSYS_strlen(pFamily); + m_pFamily = FX_Alloc(FX_CHAR, iSize + 1); + FXSYS_memcpy(m_pFamily, pFamily, iSize * sizeof(FX_CHAR)); + m_pFamily[iSize] = 0; + } + FX_CHAR* m_pFamily; + uint32_t m_dwStyle; + int32_t m_iFaceIndex; + uint32_t m_dwCharsets; + int32_t m_iGlyphNum; +}; + +#endif // CORE_FXGE_ANDROID_CFPF_SKIAFONTDESCRIPTOR_H_ diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp index 2deb327392..6463e8b531 100644 --- a/core/fxge/android/cfpf_skiafontmgr.cpp +++ b/core/fxge/android/cfpf_skiafontmgr.cpp @@ -1,10 +1,10 @@ -// Copyright 2014 PDFium Authors. All rights reserved. +// Copyright 2016 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fxcrt/fx_system.h" +#include "core/fxge/android/cfpf_skiafontmgr.h" #define FPF_SKIAMATCHWEIGHT_NAME1 62 #define FPF_SKIAMATCHWEIGHT_NAME2 60 @@ -15,8 +15,10 @@ #include "core/fxcrt/fx_ext.h" #include "core/fxcrt/fx_memory.h" -#include "core/fxge/android/fpf_skiafont.h" -#include "core/fxge/android/fpf_skiafontmgr.h" +#include "core/fxcrt/fx_system.h" +#include "core/fxge/android/cfpf_skiafont.h" +#include "core/fxge/android/cfpf_skiafontdescriptor.h" +#include "core/fxge/android/cfpf_skiapathfont.h" #include "core/fxge/fx_freetype.h" #ifdef __cplusplus diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h new file mode 100644 index 0000000000..7d89c6edb8 --- /dev/null +++ b/core/fxge/android/cfpf_skiafontmgr.h @@ -0,0 +1,52 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFONTMGR_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIAFONTMGR_H_ + +#include +#include + +#include "core/fxcrt/fx_stream.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxge/fx_font.h" + +#define FPF_MATCHFONT_REPLACEANSI 1 + +class CFPF_SkiaFont; +class CFPF_SkiaFontDescriptor; + +class CFPF_SkiaFontMgr { + public: + CFPF_SkiaFontMgr(); + ~CFPF_SkiaFontMgr(); + + void LoadSystemFonts(); + CFPF_SkiaFont* CreateFont(const CFX_ByteStringC& bsFamilyname, + uint8_t uCharset, + uint32_t dwStyle, + uint32_t dwMatch = 0); + + bool InitFTLibrary(); + FXFT_Face GetFontFace(IFX_SeekableReadStream* pFileRead, + int32_t iFaceIndex = 0); + FXFT_Face GetFontFace(const CFX_ByteStringC& bsFile, int32_t iFaceIndex = 0); + FXFT_Face GetFontFace(const uint8_t* pBuffer, + size_t szBuffer, + int32_t iFaceIndex = 0); + + private: + void ScanPath(const CFX_ByteString& path); + void ScanFile(const CFX_ByteString& file); + void ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor* pFontDesc); + + bool m_bLoaded; + FXFT_Library m_FTLibrary; + std::vector m_FontFaces; + std::map m_FamilyFonts; +}; + +#endif // CORE_FXGE_ANDROID_CFPF_SKIAFONTMGR_H_ diff --git a/core/fxge/android/cfpf_skiapathfont.h b/core/fxge/android/cfpf_skiapathfont.h new file mode 100644 index 0000000000..f1cff2574b --- /dev/null +++ b/core/fxge/android/cfpf_skiapathfont.h @@ -0,0 +1,33 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_ +#define CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_ + +#include "core/fxcrt/fx_system.h" +#include "core/fxge/android/cfpf_skiafontdescriptor.h" + +#define FPF_SKIAFONTTYPE_Path 1 + +class CFPF_SkiaPathFont : public CFPF_SkiaFontDescriptor { + public: + CFPF_SkiaPathFont() : m_pPath(nullptr) {} + ~CFPF_SkiaPathFont() override { FX_Free(m_pPath); } + + // CFPF_SkiaFontDescriptor + int32_t GetType() const override { return FPF_SKIAFONTTYPE_Path; } + + void SetPath(const FX_CHAR* pPath) { + FX_Free(m_pPath); + int32_t iSize = FXSYS_strlen(pPath); + m_pPath = FX_Alloc(FX_CHAR, iSize + 1); + FXSYS_memcpy(m_pPath, pPath, iSize * sizeof(FX_CHAR)); + m_pPath[iSize] = 0; + } + FX_CHAR* m_pPath; +}; + +#endif // CORE_FXGE_ANDROID_CFPF_SKIAPATHFONT_H_ diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp new file mode 100644 index 0000000000..6db46e2775 --- /dev/null +++ b/core/fxge/android/cfx_androidfontinfo.cpp @@ -0,0 +1,87 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fxge/android/cfx_androidfontinfo.h" + +#include "core/fxcrt/fx_system.h" +#include "core/fxge/android/cfpf_skiafont.h" +#include "core/fxge/android/cfpf_skiafontmgr.h" +#include "core/fxge/cfx_fontmapper.h" + +CFX_AndroidFontInfo::CFX_AndroidFontInfo() : m_pFontMgr(nullptr) {} +CFX_AndroidFontInfo::~CFX_AndroidFontInfo() {} +FX_BOOL CFX_AndroidFontInfo::Init(CFPF_SkiaFontMgr* pFontMgr) { + if (!pFontMgr) + return FALSE; + + pFontMgr->LoadSystemFonts(); + m_pFontMgr = pFontMgr; + return TRUE; +} + +FX_BOOL CFX_AndroidFontInfo::EnumFontList(CFX_FontMapper* pMapper) { + return FALSE; +} + +void* CFX_AndroidFontInfo::MapFont(int weight, + FX_BOOL bItalic, + int charset, + int pitch_family, + const FX_CHAR* face, + int& iExact) { + if (!m_pFontMgr) + return nullptr; + + uint32_t dwStyle = 0; + if (weight >= 700) + dwStyle |= FXFONT_BOLD; + if (bItalic) + dwStyle |= FXFONT_ITALIC; + if (pitch_family & FXFONT_FF_FIXEDPITCH) + dwStyle |= FXFONT_FIXED_PITCH; + if (pitch_family & FXFONT_FF_SCRIPT) + dwStyle |= FXFONT_SCRIPT; + if (pitch_family & FXFONT_FF_ROMAN) + dwStyle |= FXFONT_SERIF; + return m_pFontMgr->CreateFont(face, charset, dwStyle, + FPF_MATCHFONT_REPLACEANSI); +} + +void* CFX_AndroidFontInfo::GetFont(const FX_CHAR* face) { + return nullptr; +} + +uint32_t CFX_AndroidFontInfo::GetFontData(void* hFont, + uint32_t table, + uint8_t* buffer, + uint32_t size) { + if (!hFont) + return 0; + return static_cast(hFont)->GetFontData(table, buffer, size); +} + +FX_BOOL CFX_AndroidFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) { + if (!hFont) + return FALSE; + + name = static_cast(hFont)->GetFamilyName(); + return TRUE; +} + +FX_BOOL CFX_AndroidFontInfo::GetFontCharset(void* hFont, int& charset) { + if (!hFont) + return FALSE; + + charset = static_cast(hFont)->GetCharset(); + return FALSE; +} + +void CFX_AndroidFontInfo::DeleteFont(void* hFont) { + if (!hFont) + return; + + static_cast(hFont)->Release(); +} diff --git a/core/fxge/android/cfx_androidfontinfo.h b/core/fxge/android/cfx_androidfontinfo.h new file mode 100644 index 0000000000..135a2cdae7 --- /dev/null +++ b/core/fxge/android/cfx_androidfontinfo.h @@ -0,0 +1,45 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_ +#define CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_ + +#include "core/fxcrt/fx_system.h" +#include "core/fxge/cfx_fontmapper.h" +#include "core/fxge/fx_font.h" +#include "core/fxge/ifx_systemfontinfo.h" + +class CFPF_SkiaFontMgr; + +class CFX_AndroidFontInfo : public IFX_SystemFontInfo { + public: + CFX_AndroidFontInfo(); + ~CFX_AndroidFontInfo() override; + + FX_BOOL Init(CFPF_SkiaFontMgr* pFontMgr); + + // IFX_SystemFontInfo: + FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override; + void* MapFont(int weight, + FX_BOOL bItalic, + int charset, + int pitch_family, + const FX_CHAR* face, + int& bExact) override; + void* GetFont(const FX_CHAR* face) override; + uint32_t GetFontData(void* hFont, + uint32_t table, + uint8_t* buffer, + uint32_t size) override; + FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override; + FX_BOOL GetFontCharset(void* hFont, int& charset) override; + void DeleteFont(void* hFont) override; + + protected: + CFPF_SkiaFontMgr* m_pFontMgr; +}; + +#endif // CORE_FXGE_ANDROID_CFX_ANDROIDFONTINFO_H_ diff --git a/core/fxge/android/fpf_skiafont.cpp b/core/fxge/android/fpf_skiafont.cpp deleted file mode 100644 index 9c19697387..0000000000 --- a/core/fxge/android/fpf_skiafont.cpp +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxge/android/fpf_skiafont.h" - -#include - -#include "core/fxcrt/fx_system.h" -#include "core/fxge/android/fpf_skiafontmgr.h" -#include "core/fxge/fx_freetype.h" - -#define FPF_EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) - -CFPF_SkiaFont::CFPF_SkiaFont() - : m_pFontMgr(nullptr), - m_pFontDes(nullptr), - m_Face(nullptr), - m_dwStyle(0), - m_uCharset(0), - m_dwRefCount(0) {} - -CFPF_SkiaFont::~CFPF_SkiaFont() { - if (m_Face) - FXFT_Done_Face(m_Face); -} - -void CFPF_SkiaFont::Release() { - if (--m_dwRefCount == 0) - delete this; -} - -CFPF_SkiaFont* CFPF_SkiaFont::Retain() { - m_dwRefCount++; - return this; -} - -CFX_ByteString CFPF_SkiaFont::GetFamilyName() { - if (!m_Face) - return CFX_ByteString(); - return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); -} - -CFX_ByteString CFPF_SkiaFont::GetPsName() { - if (!m_Face) - return CFX_ByteString(); - return FXFT_Get_Postscript_Name(m_Face); -} - -int32_t CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) { - if (!m_Face) - return wUnicode; - if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE)) - return 0; - return FXFT_Get_Char_Index(m_Face, wUnicode); -} - -int32_t CFPF_SkiaFont::GetGlyphWidth(int32_t iGlyphIndex) { - if (!m_Face) - return 0; - if (FXFT_Load_Glyph( - m_Face, iGlyphIndex, - FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { - return 0; - } - return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Glyph_HoriAdvance(m_Face)); -} - -int32_t CFPF_SkiaFont::GetAscent() const { - if (!m_Face) - return 0; - return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_Ascender(m_Face)); -} - -int32_t CFPF_SkiaFont::GetDescent() const { - if (!m_Face) - return 0; - return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_Descender(m_Face)); -} - -FX_BOOL CFPF_SkiaFont::GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox) { - if (!m_Face) - return FALSE; - if (FXFT_Is_Face_Tricky(m_Face)) { - if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) - return FALSE; - if (FXFT_Load_Glyph(m_Face, iGlyphIndex, - FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { - FXFT_Set_Pixel_Sizes(m_Face, 0, 64); - return FALSE; - } - FXFT_Glyph glyph; - if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { - FXFT_Set_Pixel_Sizes(m_Face, 0, 64); - return FALSE; - } - FXFT_BBox cbox; - FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); - int32_t x_ppem = m_Face->size->metrics.x_ppem; - int32_t y_ppem = m_Face->size->metrics.y_ppem; - rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); - rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); - rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); - rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); - rtBBox.top = std::min(rtBBox.top, GetAscent()); - rtBBox.bottom = std::max(rtBBox.bottom, GetDescent()); - FXFT_Done_Glyph(glyph); - return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; - } - if (FXFT_Load_Glyph( - m_Face, iGlyphIndex, - FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { - return FALSE; - } - rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Glyph_HoriBearingX(m_Face)); - rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Glyph_HoriBearingY(m_Face)); - rtBBox.right = FPF_EM_ADJUST( - FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); - rtBBox.top = FPF_EM_ADJUST( - FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); - return TRUE; -} - -FX_BOOL CFPF_SkiaFont::GetBBox(FX_RECT& rtBBox) { - if (!m_Face) { - return FALSE; - } - rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_xMin(m_Face)); - rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_yMin(m_Face)); - rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_xMax(m_Face)); - rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_yMax(m_Face)); - return TRUE; -} - -int32_t CFPF_SkiaFont::GetHeight() const { - if (!m_Face) - return 0; - return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), - FXFT_Get_Face_Height(m_Face)); -} - -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; -} - -uint32_t CFPF_SkiaFont::GetFontData(uint32_t dwTable, - uint8_t* pBuffer, - uint32_t dwSize) { - if (!m_Face) - return 0; - - FT_ULong ulSize = pdfium::base::checked_cast(dwSize); - if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, &ulSize)) - return 0; - return pdfium::base::checked_cast(ulSize); -} - -FX_BOOL CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr* pFontMgr, - CFPF_SkiaFontDescriptor* pFontDes, - const CFX_ByteStringC& bsFamily, - uint32_t dwStyle, - uint8_t uCharset) { - if (!pFontMgr || !pFontDes) - return FALSE; - - switch (pFontDes->GetType()) { - case FPF_SKIAFONTTYPE_Path: { - CFPF_SkiaPathFont* pFont = (CFPF_SkiaPathFont*)pFontDes; - m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceIndex); - break; - } - case FPF_SKIAFONTTYPE_File: { - CFPF_SkiaFileFont* pFont = (CFPF_SkiaFileFont*)pFontDes; - m_Face = pFontMgr->GetFontFace(pFont->m_pFile, pFont->m_iFaceIndex); - break; - } - case FPF_SKIAFONTTYPE_Buffer: { - CFPF_SkiaBufferFont* pFont = (CFPF_SkiaBufferFont*)pFontDes; - m_Face = pFontMgr->GetFontFace((const uint8_t*)pFont->m_pBuffer, - pFont->m_szBuffer, pFont->m_iFaceIndex); - break; - } - default: - return FALSE; - } - if (!m_Face) - return FALSE; - - m_dwStyle = dwStyle; - m_uCharset = uCharset; - m_pFontMgr = pFontMgr; - m_pFontDes = pFontDes; - m_dwRefCount = 1; - return TRUE; -} diff --git a/core/fxge/android/fpf_skiafont.h b/core/fxge/android/fpf_skiafont.h deleted file mode 100644 index 3adf0c36cf..0000000000 --- a/core/fxge/android/fpf_skiafont.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXGE_ANDROID_FPF_SKIAFONT_H_ -#define CORE_FXGE_ANDROID_FPF_SKIAFONT_H_ - -#include "core/fxcrt/fx_system.h" -#include "core/fxge/fx_font.h" - -class CFPF_SkiaFontDescriptor; -class CFPF_SkiaFontMgr; - -class CFPF_SkiaFont { - public: - CFPF_SkiaFont(); - ~CFPF_SkiaFont(); - - void Release(); - CFPF_SkiaFont* Retain(); - - CFX_ByteString GetFamilyName(); - CFX_ByteString GetPsName(); - uint32_t GetFontStyle() const { return m_dwStyle; } - uint8_t GetCharset() const { return m_uCharset; } - int32_t GetGlyphIndex(FX_WCHAR wUnicode); - int32_t GetGlyphWidth(int32_t iGlyphIndex); - int32_t GetAscent() const; - int32_t GetDescent() const; - FX_BOOL GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox); - FX_BOOL GetBBox(FX_RECT& rtBBox); - int32_t GetHeight() const; - int32_t GetItalicAngle() const; - uint32_t GetFontData(uint32_t dwTable, uint8_t* pBuffer, uint32_t dwSize); - - FX_BOOL InitFont(CFPF_SkiaFontMgr* pFontMgr, - CFPF_SkiaFontDescriptor* pFontDes, - const CFX_ByteStringC& bsFamily, - uint32_t dwStyle, - uint8_t uCharset); - - private: - CFPF_SkiaFontMgr* m_pFontMgr; - CFPF_SkiaFontDescriptor* m_pFontDes; - FXFT_Face m_Face; - uint32_t m_dwStyle; - uint8_t m_uCharset; - uint32_t m_dwRefCount; -}; - -#endif // CORE_FXGE_ANDROID_FPF_SKIAFONT_H_ diff --git a/core/fxge/android/fpf_skiafontmgr.h b/core/fxge/android/fpf_skiafontmgr.h deleted file mode 100644 index 74e7adeb5a..0000000000 --- a/core/fxge/android/fpf_skiafontmgr.h +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXGE_ANDROID_FPF_SKIAFONTMGR_H_ -#define CORE_FXGE_ANDROID_FPF_SKIAFONTMGR_H_ - -#include "core/fxcrt/fx_system.h" - -#if _FX_OS_ == _FX_ANDROID_ - -#include -#include - -#include "core/fxge/fx_font.h" - -#define FPF_SKIAFONTTYPE_Unknown 0 -#define FPF_SKIAFONTTYPE_Path 1 -#define FPF_SKIAFONTTYPE_File 2 -#define FPF_SKIAFONTTYPE_Buffer 3 - -#define FPF_MATCHFONT_REPLACEANSI 1 - -class CFPF_SkiaFont; - -class CFPF_SkiaFontDescriptor { - public: - CFPF_SkiaFontDescriptor() - : m_pFamily(nullptr), - m_dwStyle(0), - m_iFaceIndex(0), - m_dwCharsets(0), - m_iGlyphNum(0) {} - virtual ~CFPF_SkiaFontDescriptor() { FX_Free(m_pFamily); } - - virtual int32_t GetType() const { return FPF_SKIAFONTTYPE_Unknown; } - - void SetFamily(const FX_CHAR* pFamily) { - FX_Free(m_pFamily); - int32_t iSize = FXSYS_strlen(pFamily); - m_pFamily = FX_Alloc(FX_CHAR, iSize + 1); - FXSYS_memcpy(m_pFamily, pFamily, iSize * sizeof(FX_CHAR)); - m_pFamily[iSize] = 0; - } - FX_CHAR* m_pFamily; - uint32_t m_dwStyle; - int32_t m_iFaceIndex; - uint32_t m_dwCharsets; - int32_t m_iGlyphNum; -}; - -class CFPF_SkiaPathFont : public CFPF_SkiaFontDescriptor { - public: - CFPF_SkiaPathFont() : m_pPath(nullptr) {} - ~CFPF_SkiaPathFont() override { FX_Free(m_pPath); } - - // CFPF_SkiaFontDescriptor - int32_t GetType() const override { return FPF_SKIAFONTTYPE_Path; } - - void SetPath(const FX_CHAR* pPath) { - FX_Free(m_pPath); - int32_t iSize = FXSYS_strlen(pPath); - m_pPath = FX_Alloc(FX_CHAR, iSize + 1); - FXSYS_memcpy(m_pPath, pPath, iSize * sizeof(FX_CHAR)); - m_pPath[iSize] = 0; - } - FX_CHAR* m_pPath; -}; - -class CFPF_SkiaFileFont : public CFPF_SkiaFontDescriptor { - public: - CFPF_SkiaFileFont() : m_pFile(nullptr) {} - - // CFPF_SkiaFontDescriptor - int32_t GetType() const override { return FPF_SKIAFONTTYPE_File; } - IFX_SeekableReadStream* m_pFile; -}; - -class CFPF_SkiaBufferFont : public CFPF_SkiaFontDescriptor { - public: - CFPF_SkiaBufferFont() : m_pBuffer(nullptr), m_szBuffer(0) {} - - // CFPF_SkiaFontDescriptor - int32_t GetType() const override { return FPF_SKIAFONTTYPE_Buffer; } - - void* m_pBuffer; - size_t m_szBuffer; -}; - -class CFPF_SkiaFontMgr { - public: - CFPF_SkiaFontMgr(); - ~CFPF_SkiaFontMgr(); - - void LoadSystemFonts(); - CFPF_SkiaFont* CreateFont(const CFX_ByteStringC& bsFamilyname, - uint8_t uCharset, - uint32_t dwStyle, - uint32_t dwMatch = 0); - - bool InitFTLibrary(); - FXFT_Face GetFontFace(IFX_SeekableReadStream* pFileRead, - int32_t iFaceIndex = 0); - FXFT_Face GetFontFace(const CFX_ByteStringC& bsFile, int32_t iFaceIndex = 0); - FXFT_Face GetFontFace(const uint8_t* pBuffer, - size_t szBuffer, - int32_t iFaceIndex = 0); - - private: - void ScanPath(const CFX_ByteString& path); - void ScanFile(const CFX_ByteString& file); - void ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor* pFontDesc); - - bool m_bLoaded; - FXFT_Library m_FTLibrary; - std::vector m_FontFaces; - std::map m_FamilyFonts; -}; - -#endif // _FX_OS_ == _FX_ANDROID_ - -#endif // CORE_FXGE_ANDROID_FPF_SKIAFONTMGR_H_ diff --git a/core/fxge/android/fpf_skiamodule.cpp b/core/fxge/android/fpf_skiamodule.cpp deleted file mode 100644 index e541b2414f..0000000000 --- a/core/fxge/android/fpf_skiamodule.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcrt/fx_system.h" - -#if _FX_OS_ == _FX_ANDROID_ - -#include "core/fxge/android/fpf_skiafontmgr.h" -#include "core/fxge/android/fpf_skiamodule.h" - -namespace { - -CFPF_SkiaDeviceModule* gs_pPFModule = nullptr; - -} // namespace - -CFPF_SkiaDeviceModule* CFPF_GetSkiaDeviceModule() { - if (!gs_pPFModule) - gs_pPFModule = new CFPF_SkiaDeviceModule; - return gs_pPFModule; -} - -CFPF_SkiaDeviceModule::~CFPF_SkiaDeviceModule() { - delete m_pFontMgr; -} - -void CFPF_SkiaDeviceModule::Destroy() { - delete gs_pPFModule; - gs_pPFModule = nullptr; -} - -CFPF_SkiaFontMgr* CFPF_SkiaDeviceModule::GetFontMgr() { - if (!m_pFontMgr) { - m_pFontMgr = new CFPF_SkiaFontMgr; - if (!m_pFontMgr->InitFTLibrary()) { - delete m_pFontMgr; - return nullptr; - } - } - return m_pFontMgr; -} - -#endif // _FX_OS_ == _FX_ANDROID_ diff --git a/core/fxge/android/fpf_skiamodule.h b/core/fxge/android/fpf_skiamodule.h deleted file mode 100644 index a0fb5e0826..0000000000 --- a/core/fxge/android/fpf_skiamodule.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXGE_ANDROID_FPF_SKIAMODULE_H_ -#define CORE_FXGE_ANDROID_FPF_SKIAMODULE_H_ - -#include "core/fxcrt/fx_system.h" - -#if _FX_OS_ == _FX_ANDROID_ - -#include "core/fxge/android/fpf_skiafontmgr.h" - -class CFPF_SkiaFontMgr; - -class CFPF_SkiaDeviceModule { - public: - CFPF_SkiaDeviceModule() : m_pFontMgr(nullptr) {} - ~CFPF_SkiaDeviceModule(); - - void Destroy(); - CFPF_SkiaFontMgr* GetFontMgr(); - - protected: - CFPF_SkiaFontMgr* m_pFontMgr; -}; - -CFPF_SkiaDeviceModule* CFPF_GetSkiaDeviceModule(); - -#endif // _FX_OS_ == _FX_ANDROID_ - -#endif // CORE_FXGE_ANDROID_FPF_SKIAMODULE_H_ diff --git a/core/fxge/android/fx_android_font.cpp b/core/fxge/android/fx_android_font.cpp deleted file mode 100644 index 2ffc897332..0000000000 --- a/core/fxge/android/fx_android_font.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcrt/fx_system.h" - -#if _FX_OS_ == _FX_ANDROID_ - -#include "core/fxge/android/fpf_skiafont.h" -#include "core/fxge/android/fpf_skiafontmgr.h" -#include "core/fxge/android/fx_android_font.h" -#include "core/fxge/cfx_fontmapper.h" - -CFX_AndroidFontInfo::CFX_AndroidFontInfo() : m_pFontMgr(nullptr) {} -CFX_AndroidFontInfo::~CFX_AndroidFontInfo() {} -FX_BOOL CFX_AndroidFontInfo::Init(CFPF_SkiaFontMgr* pFontMgr) { - if (!pFontMgr) - return FALSE; - - pFontMgr->LoadSystemFonts(); - m_pFontMgr = pFontMgr; - return TRUE; -} - -FX_BOOL CFX_AndroidFontInfo::EnumFontList(CFX_FontMapper* pMapper) { - return FALSE; -} - -void* CFX_AndroidFontInfo::MapFont(int weight, - FX_BOOL bItalic, - int charset, - int pitch_family, - const FX_CHAR* face, - int& iExact) { - if (!m_pFontMgr) - return nullptr; - - uint32_t dwStyle = 0; - if (weight >= 700) - dwStyle |= FXFONT_BOLD; - if (bItalic) - dwStyle |= FXFONT_ITALIC; - if (pitch_family & FXFONT_FF_FIXEDPITCH) - dwStyle |= FXFONT_FIXED_PITCH; - if (pitch_family & FXFONT_FF_SCRIPT) - dwStyle |= FXFONT_SCRIPT; - if (pitch_family & FXFONT_FF_ROMAN) - dwStyle |= FXFONT_SERIF; - return m_pFontMgr->CreateFont(face, charset, dwStyle, - FPF_MATCHFONT_REPLACEANSI); -} - -void* CFX_AndroidFontInfo::GetFont(const FX_CHAR* face) { - return nullptr; -} - -uint32_t CFX_AndroidFontInfo::GetFontData(void* hFont, - uint32_t table, - uint8_t* buffer, - uint32_t size) { - if (!hFont) - return 0; - return static_cast(hFont)->GetFontData(table, buffer, size); -} - -FX_BOOL CFX_AndroidFontInfo::GetFaceName(void* hFont, CFX_ByteString& name) { - if (!hFont) - return FALSE; - - name = static_cast(hFont)->GetFamilyName(); - return TRUE; -} - -FX_BOOL CFX_AndroidFontInfo::GetFontCharset(void* hFont, int& charset) { - if (!hFont) - return FALSE; - - charset = static_cast(hFont)->GetCharset(); - return FALSE; -} - -void CFX_AndroidFontInfo::DeleteFont(void* hFont) { - if (!hFont) - return; - - static_cast(hFont)->Release(); -} - -#endif // _FX_OS_ == _FX_ANDROID_ diff --git a/core/fxge/android/fx_android_font.h b/core/fxge/android/fx_android_font.h deleted file mode 100644 index 5b75d9d06e..0000000000 --- a/core/fxge/android/fx_android_font.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXGE_ANDROID_FX_ANDROID_FONT_H_ -#define CORE_FXGE_ANDROID_FX_ANDROID_FONT_H_ - -#include "core/fxcrt/fx_system.h" - -#if _FX_OS_ == _FX_ANDROID_ - -#include "core/fxge/cfx_fontmapper.h" -#include "core/fxge/fx_font.h" -#include "core/fxge/ifx_systemfontinfo.h" - -class CFPF_SkiaFontMgr; - -class CFX_AndroidFontInfo : public IFX_SystemFontInfo { - public: - CFX_AndroidFontInfo(); - ~CFX_AndroidFontInfo() override; - - FX_BOOL Init(CFPF_SkiaFontMgr* pFontMgr); - - // IFX_SystemFontInfo: - FX_BOOL EnumFontList(CFX_FontMapper* pMapper) override; - void* MapFont(int weight, - FX_BOOL bItalic, - int charset, - int pitch_family, - const FX_CHAR* face, - int& bExact) override; - void* GetFont(const FX_CHAR* face) override; - uint32_t GetFontData(void* hFont, - uint32_t table, - uint8_t* buffer, - uint32_t size) override; - FX_BOOL GetFaceName(void* hFont, CFX_ByteString& name) override; - FX_BOOL GetFontCharset(void* hFont, int& charset) override; - void DeleteFont(void* hFont) override; - - protected: - CFPF_SkiaFontMgr* m_pFontMgr; -}; - -#endif // _FX_OS_ == _FX_ANDROID_ - -#endif // CORE_FXGE_ANDROID_FX_ANDROID_FONT_H_ diff --git a/core/fxge/android/fx_android_imp.cpp b/core/fxge/android/fx_android_imp.cpp index 6e9dafc0e4..b8e7c5b218 100644 --- a/core/fxge/android/fx_android_imp.cpp +++ b/core/fxge/android/fx_android_imp.cpp @@ -4,16 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fxcrt/fx_system.h" - -#if _FX_OS_ == _FX_ANDROID_ +#include "core/fxge/cfx_gemodule.h" #include #include -#include "core/fxge/android/fpf_skiamodule.h" -#include "core/fxge/android/fx_android_font.h" -#include "core/fxge/cfx_gemodule.h" +#include "core/fxge/android/cfpf_skiadevicemodule.h" +#include "core/fxge/android/cfx_androidfontinfo.h" void CFX_GEModule::InitPlatform() { CFPF_SkiaDeviceModule* pDeviceModule = CFPF_GetSkiaDeviceModule(); @@ -33,5 +30,3 @@ void CFX_GEModule::DestroyPlatform() { if (m_pPlatformData) static_cast(m_pPlatformData)->Destroy(); } - -#endif // _FX_OS_ == _FX_ANDROID_ -- cgit v1.2.3