Kaydet (Commit) ea7102c9 authored tarafından Chris Sherlock's avatar Chris Sherlock

fdo#74702 OutputDevice::ImplInitFontList() fails if no fonts on device

It makes no sense that ImplInitFontList() only fails for Window
instances. I have carefully checked all the functions that use
this function, and there are no good cases when no fonts won't cause
problems. In fact, we have a number of functions that specifically
rely on the fact that ImplInitFontList will populate
OutputDevice::mpFontCollection with at least one font.

Therefore, I'm making this abort if it can't populate the collection,
regardless of whether it is a Window, Printer or VirtualDevice.

I have also refactored GetDefaultDevice - I now check the default
pOutDev parameter to see if it is NULL (the default), in which case
it is referring to the default window, so I call on
Application::GetDefaultDevice() instead of going straight to the
pimpl data structure used by the Application class.

Change-Id: I2861521d876d776d7862fc4a7ec56b7acf818789
Reviewed-on: https://gerrit.libreoffice.org/8741Reviewed-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
Tested-by: 's avatarChris Sherlock <chris.sherlock79@gmail.com>
üst ebf96096
...@@ -451,16 +451,22 @@ void ImplFontSubstitute( OUString& rFontName ) ...@@ -451,16 +451,22 @@ void ImplFontSubstitute( OUString& rFontName )
Font OutputDevice::GetDefaultFont( sal_uInt16 nType, LanguageType eLang, Font OutputDevice::GetDefaultFont( sal_uInt16 nType, LanguageType eLang,
sal_uLong nFlags, const OutputDevice* pOutDev ) sal_uLong nFlags, const OutputDevice* pOutDev )
{ {
if (!pOutDev) // default is NULL
pOutDev = Application::GetDefaultDevice();
LanguageTag aLanguageTag( LanguageTag aLanguageTag(
( eLang == LANGUAGE_NONE || eLang == LANGUAGE_SYSTEM || eLang == LANGUAGE_DONTKNOW ) ? ( eLang == LANGUAGE_NONE || eLang == LANGUAGE_SYSTEM || eLang == LANGUAGE_DONTKNOW ) ?
Application::GetSettings().GetUILanguageTag() : Application::GetSettings().GetUILanguageTag() :
LanguageTag( eLang )); LanguageTag( eLang ));
utl::DefaultFontConfiguration& rDefaults = utl::DefaultFontConfiguration::get(); utl::DefaultFontConfiguration& rDefaults = utl::DefaultFontConfiguration::get();
OUString aSearch = rDefaults.getUserInterfaceFont( aLanguageTag ); // ensure a fallback
OUString aDefault = rDefaults.getDefaultFont( aLanguageTag, nType ); OUString aDefault = rDefaults.getDefaultFont( aLanguageTag, nType );
OUString aSearch;
if( !aDefault.isEmpty() ) if( !aDefault.isEmpty() )
aSearch = aDefault; aSearch = aDefault;
else
aSearch = rDefaults.getUserInterfaceFont( aLanguageTag ); // use the UI font as a fallback
Font aFont; Font aFont;
aFont.SetPitch( PITCH_VARIABLE ); aFont.SetPitch( PITCH_VARIABLE );
...@@ -552,11 +558,9 @@ Font OutputDevice::GetDefaultFont( sal_uInt16 nType, LanguageType eLang, ...@@ -552,11 +558,9 @@ Font OutputDevice::GetDefaultFont( sal_uInt16 nType, LanguageType eLang,
{ {
if ( nFlags & DEFAULTFONT_FLAGS_ONLYONE ) if ( nFlags & DEFAULTFONT_FLAGS_ONLYONE )
{ {
if( !pOutDev )
pOutDev = (const OutputDevice *)ImplGetSVData()->mpDefaultWin;
if( !pOutDev ) if( !pOutDev )
{ {
SAL_WARN ("vcl.gdi", "No default window has been set for the application - we really shouldn't be able to get here");
sal_Int32 nIndex = 0; sal_Int32 nIndex = 0;
aFont.SetName( aSearch.getToken( 0, ';', nIndex ) ); aFont.SetName( aSearch.getToken( 0, ';', nIndex ) );
} }
...@@ -1186,26 +1190,28 @@ bool OutputDevice::ImplIsUnderlineAbove( const Font& rFont ) ...@@ -1186,26 +1190,28 @@ bool OutputDevice::ImplIsUnderlineAbove( const Font& rFont )
void OutputDevice::ImplInitFontList() const void OutputDevice::ImplInitFontList() const
{ {
if( ! mpFontCollection->Count() ) if( !mpFontCollection->Count() )
{ {
if( mpGraphics || ImplGetGraphics() ) if( mpGraphics || ImplGetGraphics() )
{ {
SAL_INFO( "vcl.gdi", "OutputDevice::ImplInitFontList()" ); SAL_INFO( "vcl.gdi", "OutputDevice::ImplInitFontList()" );
mpGraphics->GetDevFontList( mpFontCollection ); mpGraphics->GetDevFontList( mpFontCollection );
// There is absolutely no way there should be no fonts available on the device
if( !mpFontCollection->Count() )
{
OUString aError( "Application error: no fonts and no vcl resource found on your system" );
ResMgr* pMgr = ImplGetResMgr();
if( pMgr )
{
OUString aResStr(ResId(SV_ACCESSERROR_NO_FONTS, *pMgr).toString());
if( !aResStr.isEmpty() )
aError = aResStr;
}
Application::Abort( aError );
}
} }
} }
if( meOutDevType == OUTDEV_WINDOW && ! mpFontCollection->Count() )
{
OUString aError( "Application error: no fonts and no vcl resource found on your system" );
ResMgr* pMgr = ImplGetResMgr();
if( pMgr )
{
OUString aResStr(ResId(SV_ACCESSERROR_NO_FONTS, *pMgr).toString());
if( !aResStr.isEmpty() )
aError = aResStr;
}
Application::Abort( aError );
}
} }
void OutputDevice::ImplInitFont() const void OutputDevice::ImplInitFont() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment