Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update test font to Vera San and start workaround for Mac 10.9 font-l…
…oading bugs

- Test font loading should be moved to QgsFontUtils
  • Loading branch information
dakcarto committed Feb 19, 2014
1 parent 570e24b commit 34be93b
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 2,353 deletions.
2 changes: 1 addition & 1 deletion src/app/main.cpp
Expand Up @@ -737,7 +737,7 @@ int main( int argc, char *argv[] )
}

// load standard test font from testdata.qrc (for unit tests)
QFile testFont( ":/testdata/font/FreeSansQGIS.ttf" );
QFile testFont( ":/testdata/font/QGIS-Vera/QGIS-Vera.ttf" );
if ( testFont.open( QIODevice::ReadOnly ) )
{
int fontID = QFontDatabase::addApplicationFontFromData( testFont.readAll() );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -91,6 +91,7 @@ void QgsApplication::init( QString customConfigPath )
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );

QString prefixPath( getenv( "QGIS_PREFIX_PATH" ) ? getenv( "QGIS_PREFIX_PATH" ) : applicationDirPath() );
// QgsDebugMsg( QString( "prefixPath(): %1" ).arg( prefixPath ) );

// check if QGIS is run from build directory (not the install directory)
QFile f;
Expand Down
40 changes: 33 additions & 7 deletions src/mapserver/qgis_map_serv.cpp
Expand Up @@ -248,21 +248,47 @@ int main( int argc, char * argv[] )
theMapRenderer->setLabelingEngine( new QgsPalLabeling() );

#ifdef QGSMSDEBUG
// load standard test font from testdata.qrc (for unit tests)
// load standard test font from filesystem or testdata.qrc (for unit tests)
bool testFontLoaded = false;
QFile testFont( ":/testdata/font/FreeSansQGIS.ttf" );
if ( testFont.open( QIODevice::ReadOnly ) )
QFontDatabase fontDB;
QFont testFont = fontDB.font( "QGIS Vera Sans", "Roman", 12 );
if ( testFont.family().startsWith( "QGIS", Qt::CaseInsensitive ) )
{
int fontID = QFontDatabase::addApplicationFontFromData( testFont.readAll() );
testFontLoaded = ( fontID != -1 );
} // else app wasn't built with ENABLE_TESTS or not GUI app
testFontLoaded = true;
QgsDebugMsg( "Test font already available" );
}
else
{
QString fontFromWhere( "" );
if ( QgsApplication::isRunningFromBuildDir() )
{
// [LS] workaround for serious bugs on Mac 10.9, where fonts from qrc resources fail:
// https://bugreports.qt-project.org/browse/QTBUG-30917
// https://bugreports.qt-project.org/browse/QTBUG-32789
QString testFont( QgsApplication::buildSourcePath() + "/tests/testdata/font/QGIS-Vera/QGIS-Vera.ttf" );
int fontID = QFontDatabase::addApplicationFont( testFont );
testFontLoaded = ( fontID != -1 );
fontFromWhere = testFontLoaded ? "filesystem" : "";
}
else
{
QFile testFont( ":/testdata/font/QGIS-Vera/QGIS-Vera.ttf" );
if ( testFont.open( QIODevice::ReadOnly ) )
{
int fontID = QFontDatabase::addApplicationFontFromData( testFont.readAll() );
testFontLoaded = ( fontID != -1 );
} // else app wasn't built with ENABLE_TESTS or not GUI app
fontFromWhere = testFontLoaded ? "testdata.qrc" : "";
}
QgsDebugMsg( QString( "Test font %1loaded from %2 on startup" ).arg( testFontLoaded ? "" : "NOT " ).arg( fontFromWhere ) );
}
#endif

while ( fcgi_accept() >= 0 )
{
printRequestInfos(); //print request infos if in debug mode
#ifdef QGSMSDEBUG
QgsDebugMsg( QString( "Test font %1 loaded from testdata.qrc" ).arg( testFontLoaded ? "" : "NOT " ) );
QgsDebugMsg( QString( "Test font %1loaded" ).arg( testFontLoaded ? "" : "NOT " ) );
#endif

//use QgsGetRequestHandler in case of HTTP GET and QgsSOAPRequestHandler in case of HTTP POST
Expand Down
4 changes: 3 additions & 1 deletion tests/src/python/test_qgspallabeling_tests.py
Expand Up @@ -23,13 +23,15 @@
QgsPalLayerSettings,
)

from utilities import loadTestFont


class TestPointBase(object):

def __init__(self):
"""Dummy assignments, intended to be overriden in subclasses"""
self.lyr = QgsPalLayerSettings()
self._TestFont = QApplication.font()
self._TestFont = loadTestFont()

def checkTest(self, **kwargs):
"""Intended to be overriden in subclasses"""
Expand Down
14 changes: 8 additions & 6 deletions tests/src/python/utilities.py
Expand Up @@ -50,6 +50,7 @@

TESTFONT = None


def assertHashesForFile(theHashes, theFilename):
"""Assert that a files has matches one of a list of expected hashes"""
myHash = hashForFile(theFilename)
Expand Down Expand Up @@ -220,10 +221,11 @@ def loadTestFont():
global TESTFONT # pylint: disable=W0603

if TESTFONT is None:
fontid = QtGui.QFontDatabase.addApplicationFont(
os.path.join(unitTestDataPath('font'), 'FreeSansQGIS.ttf'))
fontid = QtGui.QFontDatabase().addApplicationFont(
os.path.join(unitTestDataPath('font'),
'QGIS-Vera', 'QGIS-Vera.ttf'))
if fontid != -1:
TESTFONT = QtGui.QFont('FreeSansQGIS')
TESTFONT = QtGui.QFont('QGIS Vera Sans')

return TESTFONT

Expand All @@ -235,6 +237,6 @@ def openInBrowserTab(url):
# some Linux OS pause execution on webbrowser open, so background it
cmd = 'import webbrowser;' \
'webbrowser.open_new_tab({0})'.format(url)
p = subprocess.Popen([sys.executable, "-c", cmd],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT).pid
subprocess.Popen([sys.executable, "-c", cmd],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
159 changes: 0 additions & 159 deletions tests/testdata/font/AUTHORS

This file was deleted.

0 comments on commit 34be93b

Please sign in to comment.