diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2019-09-03 13:21:50 +0200 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2019-09-11 12:38:18 +0200 |
commit | befc8853fac9fd1265ebd4898bf63b26e62ac9e7 (patch) | |
tree | 47dd13c2b0c9613f119efb73006549954ba961b1 | |
parent | 1a224b4d24d650ab2e1f11980ec90b299343d7f4 (diff) |
Drop SalGraphics::GetGlyphWidths()
It was used only on two places. One use is replaced with a new
LogicalFontInstance::GetGlyphWidth() (backed by HarfBuzz font) and the
other is replaced by getting glyph widths while subsetting the font.
PDFFontCache is now unused, so dropped as well.
Change-Id: I9741f17c0a5626faa952dd0d417cc786cbc877cd
28 files changed, 35 insertions, 475 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index c8e4aa75dccb..71d3c9d8fe64 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -295,7 +295,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/gdi/oldprintadaptor \ vcl/source/gdi/pdfbuildin_fonts \ vcl/source/gdi/pdfextoutdevdata \ - vcl/source/gdi/pdffontcache \ vcl/source/gdi/pdfwriter \ vcl/source/gdi/pdfwriter_impl2 \ vcl/source/gdi/pdfwriter_impl \ diff --git a/vcl/headless/svptext.cxx b/vcl/headless/svptext.cxx index e4b625b365cb..36e515b18518 100644 --- a/vcl/headless/svptext.cxx +++ b/vcl/headless/svptext.cxx @@ -84,14 +84,6 @@ void SvpSalGraphics::FreeEmbedFontData( const void* pData, long nLen ) m_aTextRenderImpl.FreeEmbedFontData(pData, nLen); } -void SvpSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) -{ - m_aTextRenderImpl.GetGlyphWidths(pFont, bVertical, rWidths, rUnicodeEnc); -} - std::unique_ptr<GenericSalLayout> SvpSalGraphics::GetTextLayout(int nFallbackLevel) { if (utl::ConfigManager::IsFuzzing()) diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx index 5e234df72e0c..423dbe9fb7d0 100644 --- a/vcl/inc/fontinstance.hxx +++ b/vcl/inc/fontinstance.hxx @@ -71,6 +71,7 @@ public: // TODO: make data members private const PhysicalFontFace* GetFontFace() const { return m_pFontFace.get(); } const ImplFontCache* GetFontCache() const { return mpFontCache; } + double GetGlyphWidth(sal_GlyphId, bool, bool); bool GetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool); virtual bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const = 0; diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index b0e4aac4adad..a132c17a26e8 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -188,10 +188,6 @@ public: ) override; virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override; - virtual void GetGlyphWidths( const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) override; virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; virtual void DrawTextLayout( const GenericSalLayout& ) override; diff --git a/vcl/inc/impglyphitem.hxx b/vcl/inc/impglyphitem.hxx index b379674548d5..d84bff77e662 100644 --- a/vcl/inc/impglyphitem.hxx +++ b/vcl/inc/impglyphitem.hxx @@ -90,6 +90,7 @@ public: inline bool GetGlyphBoundRect(tools::Rectangle&) const; inline bool GetGlyphOutline(basegfx::B2DPolyPolygon&) const; inline void dropGlyph(); + inline double nativeWidth(bool bPS) const; // Unshaped width from the font. sal_GlyphId glyphId() const { return m_aGlyphId; } int charCount() const { return m_nCharCount; } @@ -114,6 +115,11 @@ void GlyphItem::dropGlyph() m_nFlags |= GlyphItemFlags::IS_DROPPED; } +double GlyphItem::nativeWidth(bool bPS) const +{ + return m_pFontInstance->GetGlyphWidth(m_aGlyphId, IsVertical(), bPS); +} + class SalLayoutGlyphsImpl : public std::vector<GlyphItem> { friend class GenericSalLayout; diff --git a/vcl/inc/qt5/Qt5Graphics.hxx b/vcl/inc/qt5/Qt5Graphics.hxx index a7c7aaa727ac..7d6cb63a4a77 100644 --- a/vcl/inc/qt5/Qt5Graphics.hxx +++ b/vcl/inc/qt5/Qt5Graphics.hxx @@ -192,9 +192,6 @@ public: virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; virtual void FreeEmbedFontData(const void* pData, long nDataLen) override; - virtual void GetGlyphWidths(const PhysicalFontFace*, bool bVertical, - std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc) 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 68c9aff47757..3be470f0caf6 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -377,11 +377,6 @@ public: // frees the font data again virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override; - virtual void GetGlyphWidths( const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) 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 a504fb9fa071..8e7a3d3c153f 100644 --- a/vcl/inc/salgdi.hxx +++ b/vcl/inc/salgdi.hxx @@ -30,7 +30,6 @@ #include <config_cairo_canvas.h> -#include <map> #include <vector> class PhysicalFontCollection; @@ -58,7 +57,6 @@ namespace basegfx { } typedef sal_Unicode sal_Ucs; // TODO: use sal_UCS4 instead of sal_Unicode -typedef std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap; // note: if you add any new methods to class SalGraphics using coordinates // make sure they have a corresponding protected pure virtual method @@ -179,16 +177,6 @@ public: // free the font data again virtual void FreeEmbedFontData( const void* pData, long nDataLen ) = 0; - // get the same widths as in CreateFontSubset - // in case of an embeddable font also fill the mapping - // between unicode and glyph id - // leave widths vector and mapping untouched in case of failure - virtual void GetGlyphWidths( - const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) = 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 742d8445299b..7484a92c48a8 100644 --- a/vcl/inc/textrender.hxx +++ b/vcl/inc/textrender.hxx @@ -53,11 +53,6 @@ public: virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) = 0; virtual void FreeEmbedFontData( const void* pData, long nDataLen ) = 0; - virtual void GetGlyphWidths( - const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) = 0; virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) = 0; diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx index 33b1a622945e..030f10b65de7 100644 --- a/vcl/inc/unx/cairotextrender.hxx +++ b/vcl/inc/unx/cairotextrender.hxx @@ -65,11 +65,6 @@ public: virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override; - virtual void GetGlyphWidths( - const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) override; virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx index 8d388013144a..c20864d6c954 100644 --- a/vcl/inc/unx/fontmanager.hxx +++ b/vcl/inc/unx/fontmanager.hxx @@ -42,7 +42,6 @@ class FontSubsetInfo; class FontConfigFontOptions; class FontSelectPattern; class GenericUnixSalData; -class PhysicalFontFace; namespace psp { class PPDParser; @@ -272,10 +271,6 @@ public: sal_Int32* pWidths, int nGlyphs ); - void getGlyphWidths( const PhysicalFontFace* pFace, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - std::map< sal_Unicode, sal_uInt32 >& rUnicodeEnc ); // font administration functions diff --git a/vcl/inc/unx/genpspgraphics.h b/vcl/inc/unx/genpspgraphics.h index 44ca12ebc458..8f64eea4e076 100644 --- a/vcl/inc/unx/genpspgraphics.h +++ b/vcl/inc/unx/genpspgraphics.h @@ -55,10 +55,6 @@ public: static void DoFreeEmbedFontData( const void* pData, long nLen ); // helper methods for sharing with X11SalGraphics - static void DoGetGlyphWidths( const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ); static FontAttributes Info2FontAttributes( const psp::FastPrintFontInfo& ); static void AnnounceFonts( PhysicalFontCollection*, @@ -106,10 +102,6 @@ public: FontSubsetInfo& rInfo ) override; virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override; - virtual void GetGlyphWidths( const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) 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 c9a9a5120a82..55bcdb7a8a55 100644 --- a/vcl/inc/unx/salgdi.h +++ b/vcl/inc/unx/salgdi.h @@ -135,12 +135,6 @@ public: virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override; - virtual void GetGlyphWidths( - const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) 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 9ccd62085a47..0cc2fd05ba2d 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -370,10 +370,6 @@ public: virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; // frees the font data again virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override; - virtual void GetGlyphWidths( const PhysicalFontFace*, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) override; virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; diff --git a/vcl/qt5/Qt5Graphics_Text.cxx b/vcl/qt5/Qt5Graphics_Text.cxx index 73dd374493e7..63072b1ed740 100644 --- a/vcl/qt5/Qt5Graphics_Text.cxx +++ b/vcl/qt5/Qt5Graphics_Text.cxx @@ -144,11 +144,6 @@ const void* Qt5Graphics::GetEmbedFontData(const PhysicalFontFace*, long* /*pData void Qt5Graphics::FreeEmbedFontData(const void* /*pData*/, long /*nDataLen*/) {} -void Qt5Graphics::GetGlyphWidths(const PhysicalFontFace* /*pPFF*/, bool /*bVertical*/, - std::vector<sal_Int32>& /*rWidths*/, Ucs2UIntMap& /*rUnicodeEnc*/) -{ -} - class Qt5CommonSalLayout : public GenericSalLayout { public: diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx index fc986eba5806..2bc08551c1cc 100644 --- a/vcl/quartz/salgdi.cxx +++ b/vcl/quartz/salgdi.cxx @@ -701,75 +701,6 @@ bool AquaSalGraphics::GetRawFontData( const PhysicalFontFace* pFontData, return true; } -void AquaSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFontData, bool bVertical, - std::vector< sal_Int32 >& rGlyphWidths, Ucs2UIntMap& rUnicodeEnc ) -{ - rGlyphWidths.clear(); - rUnicodeEnc.clear(); - - std::vector<unsigned char> aBuffer; - if( !GetRawFontData( pFontData, aBuffer, nullptr ) ) - return; - - // TODO: modernize psprint's horrible fontsubset C-API - // this probably only makes sense after the switch to another SCM - // that can preserve change history after file renames - - // use the font subsetter to get the widths - TrueTypeFont* pSftFont = nullptr; - SFErrCodes nRC = ::OpenTTFontBuffer( static_cast<void*>(aBuffer.data()), aBuffer.size(), 0, &pSftFont); - if( nRC != SFErrCodes::Ok ) - return; - - const int nGlyphCount = ::GetTTGlyphCount( pSftFont ); - if( nGlyphCount > 0 ) - { - // get glyph metrics - rGlyphWidths.resize(nGlyphCount); - std::vector<sal_uInt16> aGlyphIds(nGlyphCount); - for( int i = 0; i < nGlyphCount; i++ ) - { - aGlyphIds[i] = static_cast<sal_uInt16>(i); - } - - std::unique_ptr<sal_uInt16[]> pGlyphMetrics = ::GetTTSimpleGlyphMetrics( pSftFont, aGlyphIds.data(), - nGlyphCount, bVertical ); - if( pGlyphMetrics ) - { - for( int i = 0; i < nGlyphCount; ++i ) - { - rGlyphWidths[i] = pGlyphMetrics[i]; - } - pGlyphMetrics.reset(); - } - - rtl::Reference<CoreTextFontFace> rCTFontData(new CoreTextFontFace(*pFontData, pFontData->GetFontId())); - FontCharMapRef xFCMap = rCTFontData->GetFontCharMap(); - SAL_WARN_IF( !xFCMap.is() || !xFCMap->GetCharCount(), "vcl", "no charmap" ); - - // get unicode<->glyph encoding - // TODO? avoid sft mapping by using the xFCMap itself - int nCharCount = xFCMap->GetCharCount(); - sal_uInt32 nChar = xFCMap->GetFirstChar(); - for( ; --nCharCount >= 0; nChar = xFCMap->GetNextChar( nChar ) ) - { - if( nChar > 0xFFFF ) // TODO: allow UTF-32 chars - break; - - sal_Ucs nUcsChar = static_cast<sal_Ucs>(nChar); - sal_uInt32 nGlyph = ::MapChar( pSftFont, nUcsChar ); - if( nGlyph > 0 ) - { - rUnicodeEnc[ nUcsChar ] = nGlyph; - } - } - - xFCMap = nullptr; - } - - ::CloseTTFont( pSftFont ); -} - const void* AquaSalGraphics::GetEmbedFontData(const PhysicalFontFace*, long* /*pDataLen*/) { return nullptr; diff --git a/vcl/source/font/fontinstance.cxx b/vcl/source/font/fontinstance.cxx index 07aab6c38618..2cc239362f2a 100644 --- a/vcl/source/font/fontinstance.cxx +++ b/vcl/source/font/fontinstance.cxx @@ -142,6 +142,22 @@ void LogicalFontInstance::IgnoreFallbackForUnicode( sal_UCS4 cChar, FontWeight e mpUnicodeFallbackList->erase( it ); } +double LogicalFontInstance::GetGlyphWidth(sal_GlyphId nID, bool bVertical, bool bPS) +{ + hb_font_t* pHbFont = GetHbFont(); + double fWidth; + if (bVertical) + fWidth = hb_font_get_glyph_v_advance(pHbFont, nID); + else + fWidth = hb_font_get_glyph_h_advance(pHbFont, nID); + + // Translate to PostScript units (standard 1/1000) + if (bPS) + fWidth = (fWidth * 1000) / hb_face_get_upem(hb_font_get_face(pHbFont)); + + return fWidth; +} + bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, tools::Rectangle &rRect, bool bVertical) { if (mpFontCache && mpFontCache->GetCachedGlyphBoundRect(this, nID, rRect)) diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx index b77eca31a389..fe768cb6dcb7 100644 --- a/vcl/source/gdi/CommonSalLayout.cxx +++ b/vcl/source/gdi/CommonSalLayout.cxx @@ -37,6 +37,8 @@ #include <fontselect.hxx> +#include <map> + #if !HB_VERSION_ATLEAST(1, 1, 0) // Disabled Unicode compatibility decomposition, see fdo#66715 static unsigned int unicodeDecomposeCompatibility(hb_unicode_funcs_t* /*ufuncs*/, diff --git a/vcl/source/gdi/pdffontcache.cxx b/vcl/source/gdi/pdffontcache.cxx deleted file mode 100644 index b79753c0ffb4..000000000000 --- a/vcl/source/gdi/pdffontcache.cxx +++ /dev/null @@ -1,65 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <typeinfo> - -#include <sal/types.h> - -#include <PhysicalFontFace.hxx> -#include <salgdi.hxx> - -#include "pdffontcache.hxx" - -using namespace vcl; - -PDFFontCache::FontIdentifier::FontIdentifier( const PhysicalFontFace* pFont, bool bVertical ) : - m_nFontId( pFont->GetFontId() ), - m_bVertical( bVertical ), - m_typeFontFace( const_cast<std::type_info*>(&typeid(pFont)) ) -{ -} - -PDFFontCache::FontData& PDFFontCache::getFont( const PhysicalFontFace* pFont, bool bVertical ) -{ - FontIdentifier aId( pFont, bVertical ); - FontToIndexMap::iterator it = m_aFontToIndex.find( aId ); - if( it != m_aFontToIndex.end() ) - return m_aFonts[ it->second ]; - m_aFontToIndex[ aId ] = sal_uInt32(m_aFonts.size()); - m_aFonts.emplace_back( ); - return m_aFonts.back(); -} - -sal_Int32 PDFFontCache::getGlyphWidth( const PhysicalFontFace* pFont, sal_GlyphId nGlyph, bool bVertical, SalGraphics* pGraphics ) -{ - sal_Int32 nWidth = 0; - FontData& rFontData( getFont( pFont, bVertical ) ); - if( rFontData.m_nWidths.empty() ) - { - pGraphics->GetGlyphWidths( pFont, bVertical, rFontData.m_nWidths, rFontData.m_aGlyphIdToIndex ); - } - if( ! rFontData.m_nWidths.empty() ) - { - if (nGlyph < rFontData.m_nWidths.size()) - nWidth = rFontData.m_nWidths[nGlyph]; - } - return nWidth; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/pdffontcache.hxx b/vcl/source/gdi/pdffontcache.hxx deleted file mode 100644 index 79d6e96f37d6..000000000000 --- a/vcl/source/gdi/pdffontcache.hxx +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_VCL_SOURCE_GDI_PDFFONTCACHE_HXX -#define INCLUDED_VCL_SOURCE_GDI_PDFFONTCACHE_HXX - -#include <typeinfo> - -#include <sal/types.h> - -#include <salgdi.hxx> - -namespace vcl -{ - class PDFFontCache - { - struct FontIdentifier - { - sal_IntPtr const m_nFontId; - bool const m_bVertical; - std::type_info* const m_typeFontFace; - - FontIdentifier( const PhysicalFontFace*, bool bVertical ); - - // Less than needed for std::set and std::map - bool operator<( const FontIdentifier& rRight ) const - { - std::type_info *pType = rRight.m_typeFontFace; - - return m_nFontId < rRight.m_nFontId || - ( m_nFontId == rRight.m_nFontId && - ( m_typeFontFace->before( *pType ) || - ( *m_typeFontFace == *pType && m_bVertical < rRight.m_bVertical ) ) ); - } - }; - struct FontData - { - std::vector< sal_Int32 > m_nWidths; - Ucs2UIntMap m_aGlyphIdToIndex; - }; - typedef std::map< FontIdentifier, sal_uInt32 > FontToIndexMap; - - std::vector< FontData > m_aFonts; - FontToIndexMap m_aFontToIndex; - - FontData& getFont( const PhysicalFontFace*, bool bVertical ); - public: - PDFFontCache() {} - - sal_Int32 getGlyphWidth( const PhysicalFontFace*, sal_GlyphId, bool bVertical, SalGraphics* ); - }; -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index cb7070c78021..065a564589fd 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -2429,17 +2429,12 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitSystemFont( const PhysicalFo aInfo.m_nCapHeight = 1000; aInfo.m_aFontBBox = tools::Rectangle( Point( -200, -200 ), Size( 1700, 1700 ) ); aInfo.m_aPSName = pFont->GetFamilyName(); - sal_Int32 pWidths[256]; - memset( pWidths, 0, sizeof(pWidths) ); SalGraphics *pGraphics = GetGraphics(); assert(pGraphics); aSubType = OString( "/TrueType" ); - std::vector< sal_Int32 > aGlyphWidths; - Ucs2UIntMap aUnicodeMap; - pGraphics->GetGlyphWidths( pFont, false, aGlyphWidths, aUnicodeMap ); OUString aTmpName; osl_createTempFile( nullptr, nullptr, &aTmpName.pData ); @@ -2451,17 +2446,12 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitSystemFont( const PhysicalFo memset( pEncoding, 0, sizeof( pEncoding ) ); memset( pDuWidths, 0, sizeof( pDuWidths ) ); - for( sal_Ucs c = 32; c < 256; c++ ) + FontCharMapRef xFontCharMap = pFont->GetCharMap(); + for( int c = 32; c < 256; c++ ) { pEncoding[c] = c; - aGlyphIds[c] = 0; - if( aUnicodeMap.find( c ) != aUnicodeMap.end() ) - pWidths[ c ] = aGlyphWidths[ aUnicodeMap[ c ] ]; - } - //TODO: surely this is utterly broken because aGlyphIds is just all zeros, if we - //had the right glyphids here then I imagine we could replace pDuWidths with - //pWidths and remove pWidths assignment above. i.e. start with the glyph ids - //and map those to unicode rather than try and reverse map them ? + aGlyphIds[c] = xFontCharMap->GetGlyphIndex(c); + } pGraphics->CreateFontSubset( aTmpName, pFont, aGlyphIds, pEncoding, pDuWidths, 256, aInfo ); osl_removeFile( aTmpName.pData ); @@ -2487,7 +2477,7 @@ std::map< sal_Int32, sal_Int32 > PDFWriterImpl::emitSystemFont( const PhysicalFo "/Widths[" ); for( int i = 32; i < 256; i++ ) { - aLine.append( pWidths[i] ); + aLine.append( pDuWidths[i] ); aLine.append( ((i&15) == 15) ? "\n" : " " ); } aLine.append( "]\n" @@ -6093,8 +6083,9 @@ void PDFWriterImpl::drawHorizontalGlyphs( const Point aThisPos = aMat.transform( rGlyphs[nPos].m_aPos ); const Point aPrevPos = aMat.transform( rGlyphs[nPos-1].m_aPos ); double fAdvance = aThisPos.X() - aPrevPos.X(); + double fNativeWidth = rGlyphs[nPos-1].m_pGlyph->nativeWidth(true); fAdvance *= 1000.0 / nPixelFontHeight; - const double fAdjustment = rGlyphs[nPos-1].m_nNativeWidth - fAdvance + 0.5; + const double fAdjustment = fNativeWidth - fAdvance + 0.5; SAL_WARN_IF( fAdjustment < SAL_MIN_INT32 || fAdjustment > SAL_MAX_INT32, "vcl.pdfwriter", "adjustment " << fAdjustment << " outside 32-bit int"); @@ -6320,21 +6311,12 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool sal_Int32 nMappedFontObject; registerGlyph(pGlyph, pFont, aCodeUnits, nMappedGlyph, nMappedFontObject); - sal_Int32 nGlyphWidth = 0; - SalGraphics *pGraphics = GetGraphics(); - if (pGraphics) - nGlyphWidth = m_aFontCache.getGlyphWidth(pFont, - pGlyph->glyphId(), - pGlyph->IsVertical(), - pGraphics); - int nCharPos = -1; if (bUseActualText || pGlyph->IsInCluster()) nCharPos = pGlyph->charPos(); aGlyphs.emplace_back(aPos, pGlyph, - nGlyphWidth, nMappedFontObject, nMappedGlyph, nCharPos); diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index 7e07d9e0d472..5ca1efc73129 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -25,6 +25,7 @@ #include <memory> #include <vector> +#include <salgdi.hxx> #include <com/sun/star/lang/Locale.hpp> #include <com/sun/star/util/XURLTransformer.hpp> #include <com/sun/star/uno/Sequence.h> @@ -45,7 +46,6 @@ #include <tools/stream.hxx> #include <outdata.hxx> -#include "pdffontcache.hxx" #include "pdfbuildin_fonts.hxx" class StyleSettings; @@ -564,19 +564,17 @@ public: struct PDFGlyph { Point const m_aPos; - const GlyphItem* m_pGlyph; - sal_Int32 const m_nNativeWidth; + const GlyphItem* m_pGlyph; sal_Int32 const m_nMappedFontId; sal_uInt8 const m_nMappedGlyphId; int const m_nCharPos; PDFGlyph( const Point& rPos, const GlyphItem* pGlyph, - sal_Int32 nNativeWidth, sal_Int32 nFontId, sal_uInt8 nMappedGlyphId, int nCharPos ) - : m_aPos( rPos ), m_pGlyph(pGlyph), m_nNativeWidth( nNativeWidth ), + : m_aPos( rPos ), m_pGlyph(pGlyph), m_nMappedFontId( nFontId ), m_nMappedGlyphId( nMappedGlyphId ), m_nCharPos(nCharPos) {} @@ -674,7 +672,6 @@ private: FontSubsetData m_aSubsets; FontEmbedData m_aSystemFonts; sal_Int32 m_nNextFID; - PDFFontCache m_aFontCache; static constexpr sal_Int32 g_nInheritedPageWidth = 595; // default A4 in inch/72 static constexpr sal_Int32 g_nInheritedPageHeight = 842; // default A4 in inch/72 diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index 87c1f2b84c70..f13705377426 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -52,10 +52,6 @@ #include <i18nlangtag/applelangid.hxx> #include <i18nlangtag/mslangid.hxx> -#include <sft.hxx> - -#include <PhysicalFontFace.hxx> - #if OSL_DEBUG_LEVEL > 1 #include <sys/times.h> #include <stdio.h> @@ -1105,59 +1101,6 @@ bool PrintFontManager::createFontSubset( return bSuccess; } -void PrintFontManager::getGlyphWidths( const PhysicalFontFace* pFace, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - std::map< sal_Unicode, sal_uInt32 >& rUnicodeEnc ) -{ - PrintFont* pFont = getFont(pFace->GetFontId()); - if (!pFont) - return; - TrueTypeFont* pTTFont = nullptr; - OString aFromFile = getFontFile( pFont ); - if( OpenTTFontFile( aFromFile.getStr(), pFont->m_nCollectionEntry, &pTTFont ) != SFErrCodes::Ok ) - return; - int nGlyphs = GetTTGlyphCount(pTTFont); - if (nGlyphs > 0) - { - rWidths.resize(nGlyphs); - std::vector<sal_uInt16> aGlyphIds(nGlyphs); - for (int i = 0; i < nGlyphs; i++) - aGlyphIds[i] = sal_uInt16(i); - std::unique_ptr<sal_uInt16[]> pMetrics = GetTTSimpleGlyphMetrics(pTTFont, - aGlyphIds.data(), - nGlyphs, - bVertical); - if (pMetrics) - { - for (int i = 0; i< nGlyphs; i++) - rWidths[i] = pMetrics[i]; - pMetrics.reset(); - rUnicodeEnc.clear(); - } - - // fill the unicode map - FontCharMapRef xFontCharMap = pFace->GetCharMap(); - for (sal_uInt32 cOld = 0;;) - { - // get next unicode covered by font - const sal_uInt32 c = xFontCharMap->GetNextChar(cOld); - if (c == cOld) - break; - cOld = c; -#if 1 // TODO: remove when sal_Unicode covers all of unicode - if (c > sal_Unicode(~0)) - break; -#endif - // get the matching glyph index - const sal_GlyphId aGlyphId = xFontCharMap->GetGlyphIndex(c); - // update the requested map - rUnicodeEnc[static_cast<sal_Unicode>(c)] = aGlyphId; - } - } - CloseTTFont(pTTFont); -} - /// used by online unit tests via dlopen. extern "C" { SAL_DLLPUBLIC_EXPORT const char * unit_online_get_fonts(void) diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx index 7a6f44be779a..cc63b05ad394 100644 --- a/vcl/unx/generic/gdi/cairotextrender.cxx +++ b/vcl/unx/generic/gdi/cairotextrender.cxx @@ -536,17 +536,4 @@ void CairoTextRender::FreeEmbedFontData( const void* pData, long nLen ) GenPspGraphics::DoFreeEmbedFontData( pData, nLen ); } -void CairoTextRender::GetGlyphWidths( const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) -{ - // 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 GlyphCache search for the PhysicalFontFace pFont - GenPspGraphics::DoGetGlyphWidths(pFont, bVertical, rWidths, rUnicodeEnc); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/gdi/font.cxx b/vcl/unx/generic/gdi/font.cxx index 29b0f4daa715..b1d0be68bc22 100644 --- a/vcl/unx/generic/gdi/font.cxx +++ b/vcl/unx/generic/gdi/font.cxx @@ -143,12 +143,4 @@ void X11SalGraphics::FreeEmbedFontData( const void* pData, long nLen ) mxTextRenderImpl->FreeEmbedFontData(pData, nLen); } -void X11SalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) -{ - mxTextRenderImpl->GetGlyphWidths(pFont, bVertical, rWidths, rUnicodeEnc); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx index e3402014dac5..d52da62da4c0 100644 --- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx +++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx @@ -42,7 +42,6 @@ #include <langboost.hxx> #include <PhysicalFontCollection.hxx> -#include <sft.hxx> #include <ft2build.h> #include FT_FREETYPE_H diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index 768c6933900a..a8a08f263ab3 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -788,23 +788,6 @@ bool GenPspGraphics::CreateFontSubset( return bSuccess; } -void GenPspGraphics::GetGlyphWidths( const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) -{ - GenPspGraphics::DoGetGlyphWidths(pFont, bVertical, rWidths, rUnicodeEnc); -} - -void GenPspGraphics::DoGetGlyphWidths( const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) -{ - psp::PrintFontManager& rMgr = psp::PrintFontManager::get(); - rMgr.getGlyphWidths(pFont, bVertical, rWidths, rUnicodeEnc); -} - FontAttributes GenPspGraphics::Info2FontAttributes( const psp::FastPrintFontInfo& rInfo ) { FontAttributes aDFA; diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index 24432782e951..f9b7646bdd7f 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -1651,75 +1651,4 @@ void WinSalGraphics::FreeEmbedFontData( const void* pData, long /*nLen*/ ) delete[] static_cast<char const *>(pData); } -void WinSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont, - bool bVertical, - std::vector< sal_Int32 >& rWidths, - Ucs2UIntMap& rUnicodeEnc ) -{ - // create matching FontSelectPattern - // we need just enough to get to the font file data - FontSelectPattern aIFSD( *pFont, Size(0,1000), 1000.0, 0, false ); - - // TODO: much better solution: move SetFont and restoration of old font to caller - ScopedFont aOldFont(*this); - - float fScale = 0.0; - HFONT hOldFont = nullptr; - ImplDoSetFont(aIFSD, pFont, fScale, hOldFont); - - // get raw font file data - const RawFontData xRawFontData( getHDC() ); - if( !xRawFontData.get() ) - return; - - // open font file - sal_uInt32 nFaceNum = 0; - if( !*xRawFontData.get() ) // TTC candidate - nFaceNum = ~0U; // indicate "TTC font extracts only" - - ScopedTrueTypeFont aSftTTF; - SFErrCodes nRC = aSftTTF.open( xRawFontData.get(), xRawFontData.size(), nFaceNum ); - if( nRC != SFErrCodes::Ok ) - return; - - int nGlyphs = GetTTGlyphCount( aSftTTF.get() ); - if( nGlyphs > 0 ) - { - rWidths.resize(nGlyphs); - std::vector<sal_uInt16> aGlyphIds(nGlyphs); - for( int i = 0; i < nGlyphs; i++ ) - aGlyphIds[i] = sal_uInt16(i); - std::unique_ptr<sal_uInt16[]> pMetrics = ::GetTTSimpleGlyphMetrics( aSftTTF.get(), - &aGlyphIds[0], - nGlyphs, - bVertical ); - if( pMetrics ) - { - for( int i = 0; i< nGlyphs; i++ ) - rWidths[i] = pMetrics[i]; - pMetrics.reset(); - rUnicodeEnc.clear(); - } - const WinFontFace* pWinFont = static_cast<const WinFontFace*>(pFont); - FontCharMapRef xFCMap = pWinFont->GetCharMap(); - SAL_WARN_IF( !xFCMap.is() || !xFCMap->GetCharCount(), "vcl", "no map" ); - - int nCharCount = xFCMap->GetCharCount(); - sal_uInt32 nChar = xFCMap->GetFirstChar(); - for( int i = 0; i < nCharCount; i++ ) - { - if( nChar < 0x00010000 ) - { - sal_uInt16 nGlyph = ::MapChar( aSftTTF.get(), - static_cast<sal_Ucs>(nChar)); - if( nGlyph ) - rUnicodeEnc[ static_cast<sal_Unicode>(nChar) ] = nGlyph; - } - nChar = xFCMap->GetNextChar( nChar ); - } - - xFCMap = nullptr; - } -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |