summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-09-03 02:44:57 +0200
committerخالد حسني <khaled@aliftype.com>2022-09-04 02:09:46 +0200
commitb87f4dfd33b48bb2f6cec9732ace51f2a272308d (patch)
tree0ffc91718ff071991b42d42555d19f5c71fa1a51
parentdd5f021e08b0f6da1b5330c37db4c759e35941c6 (diff)
vcl: Align GenPspGraphics and FreeTypeTextRenderImpl more
They share lots of code with few small differences, reduce these differences and de-duplicate more of the shared code. The main motivation is to make sure FreetypeFontFace is always created with a non-NULL FreetypeFontInfo. Change-Id: I6f36f5975908d52033fe959cfe2b265c79ebe190 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139280 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r--vcl/inc/unx/genpspgraphics.h29
-rw-r--r--vcl/unx/generic/gdi/freetypetextrender.cxx48
-rw-r--r--vcl/unx/generic/glyphs/freetype_glyphcache.cxx1
-rw-r--r--vcl/unx/generic/print/genpspgraphics.cxx132
4 files changed, 73 insertions, 137 deletions
diff --git a/vcl/inc/unx/genpspgraphics.h b/vcl/inc/unx/genpspgraphics.h
index c55947c8bdb2..0588e8354032 100644
--- a/vcl/inc/unx/genpspgraphics.h
+++ b/vcl/inc/unx/genpspgraphics.h
@@ -52,6 +52,7 @@ class VCL_DLLPUBLIC GenPspGraphics final : public SalGraphicsAutoDelegateToImpl
rtl::Reference<FreetypeFontInstance>
m_pFreetypeFont[ MAX_FALLBACK ];
+
public:
GenPspGraphics();
virtual ~GenPspGraphics() override;
@@ -59,18 +60,19 @@ public:
void Init( psp::JobData* pJob, psp::PrinterGfx* pGfx );
// helper methods
- static const void * DoGetEmbedFontData(psp::fontID aFont, tools::Long* pDataLen);
- static void DoFreeEmbedFontData( const void* pData, tools::Long nLen );
-
- // helper methods for sharing with X11SalGraphics
- static void DoGetGlyphWidths( psp::fontID aFont,
- bool bVertical,
- std::vector< sal_Int32 >& rWidths,
- Ucs2UIntMap& rUnicodeEnc );
-
- static FontAttributes Info2FontAttributes( const psp::FastPrintFontInfo& );
- static void AnnounceFonts( vcl::font::PhysicalFontCollection*,
- const psp::FastPrintFontInfo& );
+ static FontAttributes Info2FontAttributes(const psp::FastPrintFontInfo&);
+
+ // helper methods for sharing with FreeTypeTextRenderImpl
+ static void GetDevFontListHelper(vcl::font::PhysicalFontCollection*);
+ static bool AddTempDevFontHelper(vcl::font::PhysicalFontCollection* pFontCollection,
+ std::u16string_view rFileURL,
+ const OUString& rFontName);
+ static void GetGlyphWidthsHelper(const vcl::font::PhysicalFontFace*,
+ bool bVertical,
+ std::vector<sal_Int32>& rWidths,
+ Ucs2UIntMap& rUnicodeEnc);
+ 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
@@ -91,9 +93,6 @@ public:
virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*,
const OUString& rFileURL,
const OUString& rFontName ) override;
- static bool AddTempDevFontHelper( vcl::font::PhysicalFontCollection* pFontCollection,
- std::u16string_view rFileURL,
- const OUString& rFontName);
virtual bool CreateFontSubset( const OUString& rToFile,
const vcl::font::PhysicalFontFace*,
diff --git a/vcl/unx/generic/gdi/freetypetextrender.cxx b/vcl/unx/generic/gdi/freetypetextrender.cxx
index ea8474e69fee..1ec3a1522b8e 100644
--- a/vcl/unx/generic/gdi/freetypetextrender.cxx
+++ b/vcl/unx/generic/gdi/freetypetextrender.cxx
@@ -107,35 +107,7 @@ void FreeTypeTextRenderImpl::ClearDevFontCache()
void FreeTypeTextRenderImpl::GetDevFontList( vcl::font::PhysicalFontCollection* pFontCollection )
{
- // prepare the FreetypeManager using psprint's font infos
- FreetypeManager& rFreetypeManager = FreetypeManager::get();
-
- psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
- ::std::vector< psp::fontID > aList;
- psp::FastPrintFontInfo aInfo;
- rMgr.getFontList( aList );
- for (auto const& elem : aList)
- {
- if( !rMgr.getFontFastInfo( elem, aInfo ) )
- continue;
-
- // normalize face number to the FreetypeManager
- int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
- int nVariantNum = rMgr.getFontFaceVariation( aInfo.m_nID );
-
- // inform FreetypeManager about this font provided by the PsPrint subsystem
- FontAttributes aDFA = GenPspGraphics::Info2FontAttributes( aInfo );
- aDFA.IncreaseQualityBy( 4096 );
- const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
- rFreetypeManager.AddFontFile(rFileName, nFaceNum, nVariantNum, aInfo.m_nID, aDFA);
- }
-
- // announce glyphcache fonts
- rFreetypeManager.AnnounceFonts(pFontCollection);
-
- // register platform specific font substitutions if available
- if (!utl::ConfigManager::IsFuzzing())
- SalGenericInstance::RegisterFontSubstitutors( pFontCollection );
+ GenPspGraphics::GetDevFontListHelper(pFontCollection);
}
void FreeTypeTextRenderImpl::GetFontMetric( ImplFontMetricDataRef& rxFontMetric, int nFallbackLevel )
@@ -185,18 +157,12 @@ bool FreeTypeTextRenderImpl::CreateFontSubset(
const void* FreeTypeTextRenderImpl::GetEmbedFontData(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();
- return GenPspGraphics::DoGetEmbedFontData(aFont, pDataLen);
+ return GenPspGraphics::GetEmbedFontDataHelper(pFont, pDataLen);
}
void FreeTypeTextRenderImpl::FreeEmbedFontData( const void* pData, tools::Long nLen )
{
- GenPspGraphics::DoFreeEmbedFontData( pData, nLen );
+ GenPspGraphics::FreeEmbedFontDataHelper(pData, nLen);
}
void FreeTypeTextRenderImpl::GetGlyphWidths( const vcl::font::PhysicalFontFace* pFont,
@@ -204,13 +170,7 @@ void FreeTypeTextRenderImpl::GetGlyphWidths( const vcl::font::PhysicalFontFace*
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 FreetypeManager search for the PhysicalFontFace pFont
- psp::fontID aFont = pFont->GetFontId();
- GenPspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
+ GenPspGraphics::GetGlyphWidthsHelper(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 693d7a646436..3b45eadd9658 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -366,6 +366,7 @@ FreetypeFontFace::FreetypeFontFace( FreetypeFontInfo* pFI, const FontAttributes&
: vcl::font::PhysicalFontFace( rDFA ),
mpFreetypeFontInfo( pFI )
{
+ assert(mpFreetypeFontInfo);
}
rtl::Reference<LogicalFontInstance> FreetypeFontFace::CreateFontInstance(const vcl::font::FontSelectPattern& rFSD) const
diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx
index 7c4e14b27d52..ce29ecfeb51b 100644
--- a/vcl/unx/generic/print/genpspgraphics.cxx
+++ b/vcl/unx/generic/print/genpspgraphics.cxx
@@ -90,25 +90,6 @@ void GenPspGraphics::GetResolution( sal_Int32 &rDPIX, sal_Int32 &rDPIY )
namespace {
-class ImplPspFontData : public FreetypeFontFace
-{
-private:
- sal_IntPtr mnFontId;
-
-public:
- explicit ImplPspFontData( const psp::FastPrintFontInfo& );
- virtual sal_IntPtr GetFontId() const override { return mnFontId; }
-};
-
-}
-
-ImplPspFontData::ImplPspFontData(const psp::FastPrintFontInfo& rInfo)
-: FreetypeFontFace(nullptr, GenPspGraphics::Info2FontAttributes(rInfo)),
- mnFontId( rInfo.m_nID )
-{}
-
-namespace {
-
class PspSalLayout : public GenericSalLayout
{
public:
@@ -233,11 +214,6 @@ void GenPspGraphics::SetTextColor( Color nColor )
m_pPrinterGfx->SetTextColor (aColor);
}
-bool GenPspGraphics::AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString&,const OUString& )
-{
- return false;
-}
-
bool GenPspGraphics::AddTempDevFontHelper( vcl::font::PhysicalFontCollection* pFontCollection,
std::u16string_view rFileURL,
const OUString& rFontName)
@@ -258,7 +234,7 @@ bool GenPspGraphics::AddTempDevFontHelper( vcl::font::PhysicalFontCollection* pF
aInfo.m_aFamilyName = rFontName;
// inform glyph cache of new font
- FontAttributes aDFA = GenPspGraphics::Info2FontAttributes( aInfo );
+ FontAttributes aDFA = Info2FontAttributes( aInfo );
aDFA.IncreaseQualityBy( 5800 );
int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
@@ -273,21 +249,50 @@ bool GenPspGraphics::AddTempDevFontHelper( vcl::font::PhysicalFontCollection* pF
return true;
}
-void GenPspGraphics::GetDevFontList( vcl::font::PhysicalFontCollection *pFontCollection )
+bool GenPspGraphics::AddTempDevFont( vcl::font::PhysicalFontCollection* pFontCollection,
+ const OUString& rFileURL,
+ const OUString& rFontName )
{
- ::std::vector< psp::fontID > aList;
- psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
- rMgr.getFontList( aList );
+ return AddTempDevFontHelper(pFontCollection, rFileURL, rFontName);
+}
+
+void GenPspGraphics::GetDevFontListHelper( vcl::font::PhysicalFontCollection *pFontCollection )
+{
+ // prepare the FreetypeManager using psprint's font infos
+ FreetypeManager& rFreetypeManager = FreetypeManager::get();
+ psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
+ ::std::vector< psp::fontID > aList;
psp::FastPrintFontInfo aInfo;
+ rMgr.getFontList( aList );
for (auto const& elem : aList)
- if (rMgr.getFontFastInfo (elem, aInfo))
- AnnounceFonts( pFontCollection, aInfo );
+ {
+ if( !rMgr.getFontFastInfo( elem, aInfo ) )
+ continue;
+
+ // normalize face number to the FreetypeManager
+ int nFaceNum = rMgr.getFontFaceNumber( aInfo.m_nID );
+ int nVariantNum = rMgr.getFontFaceVariation( aInfo.m_nID );
+
+ // inform FreetypeManager about this font provided by the PsPrint subsystem
+ FontAttributes aDFA = Info2FontAttributes( aInfo );
+ aDFA.IncreaseQualityBy( 4096 );
+ const OString& rFileName = rMgr.getFontFileSysPath( aInfo.m_nID );
+ rFreetypeManager.AddFontFile(rFileName, nFaceNum, nVariantNum, aInfo.m_nID, aDFA);
+ }
+
+ // announce glyphcache fonts
+ rFreetypeManager.AnnounceFonts(pFontCollection);
// register platform specific font substitutions if available
SalGenericInstance::RegisterFontSubstitutors( pFontCollection );
}
+void GenPspGraphics::GetDevFontList( vcl::font::PhysicalFontCollection *pFontCollection )
+{
+ GetDevFontListHelper(pFontCollection);
+}
+
void GenPspGraphics::ClearDevFontCache()
{
FreetypeManager::get().ClearFontCache();
@@ -343,20 +348,20 @@ void GenPspGraphics::GetGlyphWidths( const vcl::font::PhysicalFontFace* pFont,
std::vector< sal_Int32 >& rWidths,
Ucs2UIntMap& rUnicodeEnc )
{
+ GenPspGraphics::GetGlyphWidthsHelper(pFont, bVertical, rWidths, rUnicodeEnc);
+}
+
+void GenPspGraphics::GetGlyphWidthsHelper(const vcl::font::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 FreetypeManager search for the PhysicalFontFace pFont
psp::fontID aFont = pFont->GetFontId();
- GenPspGraphics::DoGetGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
-}
-
-void GenPspGraphics::DoGetGlyphWidths( psp::fontID aFont,
- bool bVertical,
- std::vector< sal_Int32 >& rWidths,
- Ucs2UIntMap& rUnicodeEnc )
-{
psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
rMgr.getGlyphWidths( aFont, bVertical, rWidths, rUnicodeEnc );
}
@@ -408,35 +413,6 @@ namespace vcl
}
}
-void GenPspGraphics::AnnounceFonts( vcl::font::PhysicalFontCollection* pFontCollection, const psp::FastPrintFontInfo& aInfo )
-{
- int nQuality = 0;
-
- psp::PrintFontManager& rMgr = psp::PrintFontManager::get();
- OString aFileName( rMgr.getFontFileSysPath( aInfo.m_nID ) );
- int nPos = aFileName.lastIndexOf( '_' );
- if( nPos == -1 || aFileName[nPos+1] == '.' )
- nQuality += 5;
- else
- {
- static const char* pLangBoost = nullptr;
- static bool bOnce = true;
- if( bOnce )
- {
- bOnce = false;
- pLangBoost = vcl::getLangBoost();
- }
-
- if( pLangBoost )
- if( o3tl::equalsIgnoreAsciiCase(aFileName.subView( nPos+1, 3 ), pLangBoost ) )
- nQuality += 10;
- }
-
- rtl::Reference<ImplPspFontData> pFD(new ImplPspFontData( aInfo ));
- pFD->IncreaseQualityBy( nQuality );
- pFontCollection->Add( pFD.get() );
-}
-
SystemGraphicsData GenPspGraphics::GetGraphicsData() const
{
return SystemGraphicsData();
@@ -471,14 +447,20 @@ css::uno::Any GenPspGraphics::GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& /*
#endif // ENABLE_CAIRO_CANVAS
-void GenPspGraphics::DoFreeEmbedFontData( const void* pData, tools::Long nLen )
+void GenPspGraphics::FreeEmbedFontDataHelper( const void* pData, tools::Long nLen )
{
if( pData )
munmap( const_cast<void *>(pData), nLen );
}
-const void* GenPspGraphics::DoGetEmbedFontData(psp::fontID aFont, tools::Long* pDataLen)
+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();
@@ -504,18 +486,12 @@ const void* GenPspGraphics::DoGetEmbedFontData(psp::fontID aFont, tools::Long* p
void GenPspGraphics::FreeEmbedFontData( const void* pData, tools::Long nLen )
{
- DoFreeEmbedFontData( pData, nLen );
+ FreeEmbedFontDataHelper(pData, nLen);
}
const void* GenPspGraphics::GetEmbedFontData(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();
- return DoGetEmbedFontData(aFont, pDataLen);
+ return GetEmbedFontDataHelper(pFont, pDataLen);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */