Skip to content

Commit 34be93b

Browse files
committedFeb 19, 2014
Update test font to Vera San and start workaround for Mac 10.9 font-loading bugs
- Test font loading should be moved to QgsFontUtils
1 parent 570e24b commit 34be93b

24 files changed

+354
-2353
lines changed
 

‎src/app/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ int main( int argc, char *argv[] )
737737
}
738738

739739
// load standard test font from testdata.qrc (for unit tests)
740-
QFile testFont( ":/testdata/font/FreeSansQGIS.ttf" );
740+
QFile testFont( ":/testdata/font/QGIS-Vera/QGIS-Vera.ttf" );
741741
if ( testFont.open( QIODevice::ReadOnly ) )
742742
{
743743
int fontID = QFontDatabase::addApplicationFontFromData( testFont.readAll() );

‎src/core/qgsapplication.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void QgsApplication::init( QString customConfigPath )
9191
qRegisterMetaType<QgsGeometry::Error>( "QgsGeometry::Error" );
9292

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

9596
// check if QGIS is run from build directory (not the install directory)
9697
QFile f;

‎src/mapserver/qgis_map_serv.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,47 @@ int main( int argc, char * argv[] )
248248
theMapRenderer->setLabelingEngine( new QgsPalLabeling() );
249249

250250
#ifdef QGSMSDEBUG
251-
// load standard test font from testdata.qrc (for unit tests)
251+
// load standard test font from filesystem or testdata.qrc (for unit tests)
252252
bool testFontLoaded = false;
253-
QFile testFont( ":/testdata/font/FreeSansQGIS.ttf" );
254-
if ( testFont.open( QIODevice::ReadOnly ) )
253+
QFontDatabase fontDB;
254+
QFont testFont = fontDB.font( "QGIS Vera Sans", "Roman", 12 );
255+
if ( testFont.family().startsWith( "QGIS", Qt::CaseInsensitive ) )
255256
{
256-
int fontID = QFontDatabase::addApplicationFontFromData( testFont.readAll() );
257-
testFontLoaded = ( fontID != -1 );
258-
} // else app wasn't built with ENABLE_TESTS or not GUI app
257+
testFontLoaded = true;
258+
QgsDebugMsg( "Test font already available" );
259+
}
260+
else
261+
{
262+
QString fontFromWhere( "" );
263+
if ( QgsApplication::isRunningFromBuildDir() )
264+
{
265+
// [LS] workaround for serious bugs on Mac 10.9, where fonts from qrc resources fail:
266+
// https://bugreports.qt-project.org/browse/QTBUG-30917
267+
// https://bugreports.qt-project.org/browse/QTBUG-32789
268+
QString testFont( QgsApplication::buildSourcePath() + "/tests/testdata/font/QGIS-Vera/QGIS-Vera.ttf" );
269+
int fontID = QFontDatabase::addApplicationFont( testFont );
270+
testFontLoaded = ( fontID != -1 );
271+
fontFromWhere = testFontLoaded ? "filesystem" : "";
272+
}
273+
else
274+
{
275+
QFile testFont( ":/testdata/font/QGIS-Vera/QGIS-Vera.ttf" );
276+
if ( testFont.open( QIODevice::ReadOnly ) )
277+
{
278+
int fontID = QFontDatabase::addApplicationFontFromData( testFont.readAll() );
279+
testFontLoaded = ( fontID != -1 );
280+
} // else app wasn't built with ENABLE_TESTS or not GUI app
281+
fontFromWhere = testFontLoaded ? "testdata.qrc" : "";
282+
}
283+
QgsDebugMsg( QString( "Test font %1loaded from %2 on startup" ).arg( testFontLoaded ? "" : "NOT " ).arg( fontFromWhere ) );
284+
}
259285
#endif
260286

261287
while ( fcgi_accept() >= 0 )
262288
{
263289
printRequestInfos(); //print request infos if in debug mode
264290
#ifdef QGSMSDEBUG
265-
QgsDebugMsg( QString( "Test font %1 loaded from testdata.qrc" ).arg( testFontLoaded ? "" : "NOT " ) );
291+
QgsDebugMsg( QString( "Test font %1loaded" ).arg( testFontLoaded ? "" : "NOT " ) );
266292
#endif
267293

268294
//use QgsGetRequestHandler in case of HTTP GET and QgsSOAPRequestHandler in case of HTTP POST

‎tests/src/python/test_qgspallabeling_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
QgsPalLayerSettings,
2424
)
2525

26+
from utilities import loadTestFont
27+
2628

2729
class TestPointBase(object):
2830

2931
def __init__(self):
3032
"""Dummy assignments, intended to be overriden in subclasses"""
3133
self.lyr = QgsPalLayerSettings()
32-
self._TestFont = QApplication.font()
34+
self._TestFont = loadTestFont()
3335

3436
def checkTest(self, **kwargs):
3537
"""Intended to be overriden in subclasses"""

‎tests/src/python/utilities.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
TESTFONT = None
5252

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

222223
if TESTFONT is None:
223-
fontid = QtGui.QFontDatabase.addApplicationFont(
224-
os.path.join(unitTestDataPath('font'), 'FreeSansQGIS.ttf'))
224+
fontid = QtGui.QFontDatabase().addApplicationFont(
225+
os.path.join(unitTestDataPath('font'),
226+
'QGIS-Vera', 'QGIS-Vera.ttf'))
225227
if fontid != -1:
226-
TESTFONT = QtGui.QFont('FreeSansQGIS')
228+
TESTFONT = QtGui.QFont('QGIS Vera Sans')
227229

228230
return TESTFONT
229231

@@ -235,6 +237,6 @@ def openInBrowserTab(url):
235237
# some Linux OS pause execution on webbrowser open, so background it
236238
cmd = 'import webbrowser;' \
237239
'webbrowser.open_new_tab({0})'.format(url)
238-
p = subprocess.Popen([sys.executable, "-c", cmd],
239-
stdout=subprocess.PIPE,
240-
stderr=subprocess.STDOUT).pid
240+
subprocess.Popen([sys.executable, "-c", cmd],
241+
stdout=subprocess.PIPE,
242+
stderr=subprocess.STDOUT)

‎tests/testdata/font/AUTHORS

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.