Skip to content

Commit

Permalink
Backport test related font utils from master
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 17, 2015
1 parent c19d692 commit a6f5203
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/core/qgsfontutils.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,25 @@ bool QgsFontUtils::fontFamilyOnSystem( const QString& family )
bool QgsFontUtils::fontFamilyHasStyle( const QString& family, const QString& style )
{
QFontDatabase fontDB;
return ( fontFamilyOnSystem( family ) && fontDB.styles( family ).contains( style ) );
if ( !fontFamilyOnSystem( family ) )
return false;

if ( fontDB.styles( family ).contains( style ) )
return true;

#ifdef Q_OS_WIN
QString modified( style );
if ( style == "Roman" )
modified = "Normal";
if ( style == "Oblique" )
modified = "Italic";
if ( style == "Bold Oblique" )
modified = "Bold Italic";
if ( fontDB.styles( family ).contains( modified ) )
return true;
#endif

return false;
}

bool QgsFontUtils::fontFamilyMatchOnSystem( const QString& family, QString* chosen, bool* match )
Expand Down Expand Up @@ -243,6 +261,8 @@ bool QgsFontUtils::loadStandardTestFonts( QStringList loadstyles )
fontsLoaded = ( fontsLoaded || loaded );
QgsDebugMsg( QString( "Test font '%1' %2 from filesystem [%3]" )
.arg( familyStyle ).arg( loaded ? "loaded" : "FAILED to load" ).arg( fontPath ) );
QFontDatabase db;
QgsDebugMsg( QString( "font families in %1: %2" ).arg( fontID ).arg( db.applicationFontFamilies( fontID ).join( "," ) ) );
}
else
{
Expand All @@ -264,16 +284,37 @@ bool QgsFontUtils::loadStandardTestFonts( QStringList loadstyles )

QFont QgsFontUtils::getStandardTestFont( const QString& style, int pointsize )
{
QFontDatabase fontDB;
if ( ! fontFamilyHasStyle( standardTestFontFamily(), style ) )
{
loadStandardTestFonts( QStringList() << style );
}

QFontDatabase fontDB;
QFont f = fontDB.font( standardTestFontFamily(), style, pointsize );
#ifdef Q_OS_WIN
if ( !f.exactMatch() )
{
QString modified;
if ( style == "Roman" )
modified = "Normal";
else if ( style == "Oblique" )
modified = "Italic";
else if ( style == "Bold Oblique" )
modified = "Bold Italic";
if ( !modified.isEmpty() )
f = fontDB.font( standardTestFontFamily(), modified, pointsize );
}
if ( !f.exactMatch() )
{
QgsDebugMsg( QString( "Inexact font match - consider installing the %1 font." ).arg( standardTestFontFamily() ) );
QgsDebugMsg( QString( "Requested: %1" ).arg( f.toString() ) );
QFontInfo fi( f );
QgsDebugMsg( QString( "Replaced: %1,%2,%3,%4,%5,%6,%7,%8,%9,%10" ).arg( fi.family() ).arg( fi.pointSizeF() ).arg( fi.pixelSize() ).arg( fi.styleHint() ).arg( fi.weight() ).arg( fi.style() ).arg( fi.underline() ).arg( fi.strikeOut() ).arg( fi.fixedPitch() ).arg( fi.rawMode() ) );
}
#endif
// in case above statement fails to set style
f.setBold( style.contains( "Bold" ) );
f.setItalic( style.contains( "Oblique" ) );
f.setItalic( style.contains( "Oblique" ) || style.contains( "Italic" ) );

return f;
}
Expand Down

0 comments on commit a6f5203

Please sign in to comment.