diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-10-01 08:21:58 +0200 |
---|---|---|
committer | خالد حسني <khaled@aliftype.com> | 2022-10-01 13:09:48 +0200 |
commit | 112d07027c4484dd571519911596d11eae897524 (patch) | |
tree | 0b33c5f4970ad3e2dced137581e3cf6d46931930 | |
parent | c107d08460938270cbc2a32a89d995fc0ae8ebea (diff) |
vcl: Use PhysicalFontFace::GetRawFontData() for font embedding
Change-Id: I6f7c4508f7cef022eaf65a998cb242078d3771c6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140826
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r-- | vcl/headless/svptext.cxx | 10 | ||||
-rw-r--r-- | vcl/inc/headless/svpgdi.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/qt5/QtGraphics.hxx | 4 | ||||
-rw-r--r-- | vcl/inc/quartz/salgdi.h | 9 | ||||
-rw-r--r-- | vcl/inc/salgdi.hxx | 9 | ||||
-rw-r--r-- | vcl/inc/textrender.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/unx/freetypetextrender.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/unx/genpspgraphics.h | 4 | ||||
-rw-r--r-- | vcl/inc/unx/salgdi.h | 3 | ||||
-rw-r--r-- | vcl/inc/win/salgdi.h | 8 | ||||
-rw-r--r-- | vcl/qt5/QtGraphics_Text.cxx | 8 | ||||
-rw-r--r-- | vcl/quartz/salgdi.cxx | 12 | ||||
-rw-r--r-- | vcl/source/font/PhysicalFontFace.cxx | 6 | ||||
-rw-r--r-- | vcl/source/gdi/embeddedfontshelper.cxx | 9 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/font.cxx | 10 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/freetypetextrender.cxx | 10 | ||||
-rw-r--r-- | vcl/unx/generic/print/genpspgraphics.cxx | 47 | ||||
-rw-r--r-- | vcl/win/gdi/salfont.cxx | 53 |
18 files changed, 10 insertions, 200 deletions
diff --git a/vcl/headless/svptext.cxx b/vcl/headless/svptext.cxx index 782caba56971..a41d3df1705a 100644 --- a/vcl/headless/svptext.cxx +++ b/vcl/headless/svptext.cxx @@ -62,16 +62,6 @@ bool SvpSalGraphics::AddTempDevFont( vcl::font::PhysicalFontCollection* pFontCol return m_aTextRenderImpl.AddTempDevFont(pFontCollection, rFileURL, rFontName); } -const void* SvpSalGraphics::GetEmbedFontData(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) -{ - return m_aTextRenderImpl.GetEmbedFontData(pFont, pDataLen); -} - -void SvpSalGraphics::FreeEmbedFontData( const void* pData, tools::Long nLen ) -{ - m_aTextRenderImpl.FreeEmbedFontData(pData, nLen); -} - std::unique_ptr<GenericSalLayout> SvpSalGraphics::GetTextLayout(int nFallbackLevel) { return m_aTextRenderImpl.GetTextLayout(nFallbackLevel); diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index 7158a020eb6b..9197e83c20db 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -77,8 +77,6 @@ public: virtual void GetDevFontList( vcl::font::PhysicalFontCollection* ) override; virtual void ClearDevFontCache() override; virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override; - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) override; - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override; virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; diff --git a/vcl/inc/qt5/QtGraphics.hxx b/vcl/inc/qt5/QtGraphics.hxx index 987ab1601f38..b8a168d1a3cf 100644 --- a/vcl/inc/qt5/QtGraphics.hxx +++ b/vcl/inc/qt5/QtGraphics.hxx @@ -232,10 +232,6 @@ public: virtual bool AddTempDevFont(vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName) override; - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, - tools::Long* pDataLen) override; - virtual void FreeEmbedFontData(const void* pData, tools::Long nDataLen) override; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout(const GenericSalLayout&) override; }; diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h index ec63592431e3..0bf004033c52 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -536,15 +536,6 @@ public: virtual void ClearDevFontCache() override; virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override; - // GetEmbedFontData: gets the font data for a font marked - // embeddable by GetDevFontList or NULL in case of error - // parameters: pFont: describes the font in question - // pDataLen: out parameter, contains the byte length of the returned buffer - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) - override; - // frees the font data again - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx index acbfd1fa73e5..0b8952b74123 100644 --- a/vcl/inc/salgdi.hxx +++ b/vcl/inc/salgdi.hxx @@ -160,15 +160,6 @@ public: const OUString& rFileURL, const OUString& rFontName ) = 0; - // GetEmbedFontData: gets the font data for a font marked - // embeddable by GetDevFontList or NULL in case of error - // parameters: pFont: describes the font in question - // pDataLen: out parameter, contains the byte length of the returned buffer - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) = 0; - - // free the font data again - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) = 0; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) = 0; virtual void DrawTextLayout( const GenericSalLayout& ) = 0; diff --git a/vcl/inc/textrender.hxx b/vcl/inc/textrender.hxx index 6675e6aebb5c..028883f98f17 100644 --- a/vcl/inc/textrender.hxx +++ b/vcl/inc/textrender.hxx @@ -43,9 +43,6 @@ public: virtual void ClearDevFontCache() = 0; virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) = 0; - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) = 0; - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) = 0; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) = 0; virtual void DrawTextLayout(const GenericSalLayout&, const SalGraphics&) = 0; diff --git a/vcl/inc/unx/freetypetextrender.hxx b/vcl/inc/unx/freetypetextrender.hxx index e61faa0c9e49..fa961b33b158 100644 --- a/vcl/inc/unx/freetypetextrender.hxx +++ b/vcl/inc/unx/freetypetextrender.hxx @@ -48,9 +48,6 @@ public: virtual void ClearDevFontCache() override; virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override; - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) override; - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; }; diff --git a/vcl/inc/unx/genpspgraphics.h b/vcl/inc/unx/genpspgraphics.h index 438e03fa39be..47d6ae55f2cd 100644 --- a/vcl/inc/unx/genpspgraphics.h +++ b/vcl/inc/unx/genpspgraphics.h @@ -67,8 +67,6 @@ public: static bool AddTempDevFontHelper(vcl::font::PhysicalFontCollection* pFontCollection, std::u16string_view rFileURL, const OUString& rFontName); - static const void * GetEmbedFontDataHelper(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen); - static void FreeEmbedFontDataHelper(const void* pData, tools::Long nLen); // override all pure virtual methods virtual SalGraphicsImpl* GetImpl() const override @@ -90,8 +88,6 @@ public: const OUString& rFileURL, const OUString& rFontName ) override; - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) override; - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override; virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h index dbb7b98fbfec..1e1a5971a7b6 100644 --- a/vcl/inc/unx/salgdi.h +++ b/vcl/inc/unx/salgdi.h @@ -122,9 +122,6 @@ public: virtual void ClearDevFontCache() override; virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override; - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) override; - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index 247408406e8b..6c163d2f1b39 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -349,14 +349,6 @@ public: virtual void ClearDevFontCache() override; virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override; - // GetEmbedFontData: gets the font data for a font marked - // embeddable by GetDevFontList or NULL in case of error - // parameters: pFont: describes the font in question - // pDataLen: out parameter, contains the byte length of the returned buffer - virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) override; - // frees the font data again - virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override; - virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; diff --git a/vcl/qt5/QtGraphics_Text.cxx b/vcl/qt5/QtGraphics_Text.cxx index 42a1037943dc..18790086bbf3 100644 --- a/vcl/qt5/QtGraphics_Text.cxx +++ b/vcl/qt5/QtGraphics_Text.cxx @@ -136,14 +136,6 @@ bool QtGraphics::AddTempDevFont(vcl::font::PhysicalFontCollection*, const OUStri return false; } -const void* QtGraphics::GetEmbedFontData(const vcl::font::PhysicalFontFace*, - tools::Long* /*pDataLen*/) -{ - return nullptr; -} - -void QtGraphics::FreeEmbedFontData(const void* /*pData*/, tools::Long /*nDataLen*/) {} - namespace { class QtCommonSalLayout : public GenericSalLayout diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx index 7267e1a83cad..54127bc07b22 100644 --- a/vcl/quartz/salgdi.cxx +++ b/vcl/quartz/salgdi.cxx @@ -484,18 +484,6 @@ bool AquaSalGraphics::GetFontCapabilities(vcl::FontCapabilities &rFontCapabiliti return mpTextStyle[0]->GetFontFace()->GetFontCapabilities(rFontCapabilities); } -const void* AquaSalGraphics::GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* /*pDataLen*/) -{ - return nullptr; -} - -void AquaSalGraphics::FreeEmbedFontData( const void* pData, tools::Long /*nDataLen*/ ) -{ - // TODO: implementing this only makes sense when the implementation of - // AquaSalGraphics::GetEmbedFontData() returns non-NULL - SAL_WARN_IF( (pData==nullptr), "vcl", "AquaSalGraphics::FreeEmbedFontData() is not implemented"); -} - void AquaSalGraphics::Flush() { mpBackend->Flush(); diff --git a/vcl/source/font/PhysicalFontFace.cxx b/vcl/source/font/PhysicalFontFace.cxx index fb54daf3da04..d1c02bbcc62d 100644 --- a/vcl/source/font/PhysicalFontFace.cxx +++ b/vcl/source/font/PhysicalFontFace.cxx @@ -222,7 +222,11 @@ bool PhysicalFontFace::IsBetterMatch(const FontSelectPattern& rFSP, FontMatchSta RawFontData PhysicalFontFace::GetRawFontData(uint32_t nTag) const { - return RawFontData(hb_face_reference_table(GetHbFace(), nTag)); + auto pHbFace = GetHbFace(); + // If nTag is 0, reference the whole font. + if (!nTag) + return RawFontData(hb_face_reference_blob(pHbFace)); + return RawFontData(hb_face_reference_table(pHbFace, nTag)); } static hb_blob_t* getTable(hb_face_t*, hb_tag_t nTag, void* pUserData) diff --git a/vcl/source/gdi/embeddedfontshelper.cxx b/vcl/source/gdi/embeddedfontshelper.cxx index f21e73498ebd..c816c6b5108b 100644 --- a/vcl/source/gdi/embeddedfontshelper.cxx +++ b/vcl/source/gdi/embeddedfontshelper.cxx @@ -292,9 +292,11 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF } if( selected != nullptr ) { - tools::Long size; - if (const void* data = graphics->GetEmbedFontData(selected, &size)) + auto aFontData(selected->GetRawFontData(0)); + if (!aFontData.empty()) { + auto data = aFontData.data(); + auto size = aFontData.size(); if( sufficientTTFRights( data, size, rights )) { osl::File file( url ); @@ -306,7 +308,7 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF while( written < totalSize && !error) { sal_uInt64 nowWritten; - switch( file.write( static_cast< const char* >( data ) + written, size - written, nowWritten )) + switch( file.write( data + written, size - written, nowWritten )) { case osl::File::E_None: written += nowWritten; @@ -326,7 +328,6 @@ OUString EmbeddedFontsHelper::fontFileUrl( std::u16string_view familyName, FontF ok = true; } } - graphics->FreeEmbedFontData( data, size ); } } return ok ? url : ""; diff --git a/vcl/unx/generic/gdi/font.cxx b/vcl/unx/generic/gdi/font.cxx index 1246d9b525f8..ab7ceaf8c7e7 100644 --- a/vcl/unx/generic/gdi/font.cxx +++ b/vcl/unx/generic/gdi/font.cxx @@ -81,14 +81,4 @@ std::unique_ptr<GenericSalLayout> X11SalGraphics::GetTextLayout(int nFallbackLev return mxTextRenderImpl->GetTextLayout(nFallbackLevel); } -const void* X11SalGraphics::GetEmbedFontData(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) -{ - return mxTextRenderImpl->GetEmbedFontData(pFont, pDataLen); -} - -void X11SalGraphics::FreeEmbedFontData( const void* pData, tools::Long nLen ) -{ - mxTextRenderImpl->FreeEmbedFontData(pData, nLen); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/gdi/freetypetextrender.cxx b/vcl/unx/generic/gdi/freetypetextrender.cxx index b1416721fea6..dcf53bc40083 100644 --- a/vcl/unx/generic/gdi/freetypetextrender.cxx +++ b/vcl/unx/generic/gdi/freetypetextrender.cxx @@ -127,14 +127,4 @@ std::unique_ptr<GenericSalLayout> FreeTypeTextRenderImpl::GetTextLayout(int nFal return std::make_unique<GenericSalLayout>(*mpFreetypeFont[nFallbackLevel]); } -const void* FreeTypeTextRenderImpl::GetEmbedFontData(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) -{ - return GenPspGraphics::GetEmbedFontDataHelper(pFont, pDataLen); -} - -void FreeTypeTextRenderImpl::FreeEmbedFontData( const void* pData, tools::Long nLen ) -{ - GenPspGraphics::FreeEmbedFontDataHelper(pData, nLen); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index dcfdadc64cda..fe3e37627fd9 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -396,51 +396,4 @@ css::uno::Any GenPspGraphics::GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& /* #endif // ENABLE_CAIRO_CANVAS -void GenPspGraphics::FreeEmbedFontDataHelper( const void* pData, tools::Long nLen ) -{ - if( pData ) - munmap( const_cast<void *>(pData), nLen ); -} - -const void* GenPspGraphics::GetEmbedFontDataHelper(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) -{ - // in this context the pFont->GetFontId() is a valid PSP - // font since they are the only ones left after the PDF - // export has filtered its list of subsettable fonts (for - // which this method was created). The correct way would - // be to have the FreetypeManager search for the PhysicalFontFace pFont - psp::fontID aFont = pFont->GetFontId(); - - psp::PrintFontManager& rMgr = psp::PrintFontManager::get(); - - OString aSysPath = rMgr.getFontFileSysPath( aFont ); - - int fd = open( aSysPath.getStr(), O_RDONLY ); - if( fd < 0 ) - return nullptr; - struct stat aStat; - if( fstat( fd, &aStat ) ) - { - close( fd ); - return nullptr; - } - void* pFile = mmap( nullptr, aStat.st_size, PROT_READ, MAP_SHARED, fd, 0 ); - close( fd ); - if( pFile == MAP_FAILED ) - return nullptr; - *pDataLen = aStat.st_size; - - return pFile; -} - -void GenPspGraphics::FreeEmbedFontData( const void* pData, tools::Long nLen ) -{ - FreeEmbedFontDataHelper(pData, nLen); -} - -const void* GenPspGraphics::GetEmbedFontData(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) -{ - return GetEmbedFontDataHelper(pFont, pDataLen); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 058c24284cc9..9d618c6b9c81 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -1449,57 +1449,4 @@ bool WinFontInstance::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& return true; } -namespace { - -class ScopedFontHDC final -{ -public: - explicit ScopedFontHDC(WinSalGraphics& rGraphics, const vcl::font::PhysicalFontFace& rFontFace) - // use height=1000 for easier debugging (to match psprint's font units) - : m_hDC(nullptr) - , m_hOrigFont(nullptr) - { - m_hDC = CreateCompatibleDC(rGraphics.getHDC()); - if (!m_hDC) - return; - - vcl::font::FontSelectPattern aFSP(rFontFace, Size(0,1000), 1000.0, 0, false); - rGraphics.ImplDoSetFont(m_hDC, aFSP, &rFontFace, m_hOrigFont); - } - - ~ScopedFontHDC() - { - if (m_hOrigFont) - ::DeleteFont(SelectFont(m_hDC, m_hOrigFont)); - if (m_hDC) - DeleteDC(m_hDC); - } - - HDC hdc() const { return m_hDC; } - -private: - HDC m_hDC; - HFONT m_hOrigFont; -}; - -} - -const void* WinSalGraphics::GetEmbedFontData(const vcl::font::PhysicalFontFace* pFont, tools::Long* pDataLen) -{ - ScopedFontHDC aScopedFontHDC(*this, *pFont); - HDC hDC = aScopedFontHDC.hdc(); - if (!hDC) - return nullptr; - - // get the raw font file data - RawFontData aRawFontData(hDC); - *pDataLen = aRawFontData.size(); - return aRawFontData.get() ? aRawFontData.steal() : nullptr; -} - -void WinSalGraphics::FreeEmbedFontData( const void* pData, tools::Long /*nLen*/ ) -{ - delete[] static_cast<char const *>(pData); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |