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.

‎tests/testdata/font/COPYING

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

‎tests/testdata/font/CREDITS

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

‎tests/testdata/font/ChangeLog

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

‎tests/testdata/font/FreeSansQGIS-README.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.
-33 KB
Binary file not shown.

‎tests/testdata/font/FreeSansQGIS.ttf

-28.4 KB
Binary file not shown.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
Bitstream Vera Fonts Copyright
2+
3+
The fonts have a generous copyright, allowing derivative works (as
4+
long as "Bitstream" or "Vera" are not in the names), and full
5+
redistribution (so long as they are not *sold* by themselves). They
6+
can be be bundled, redistributed and sold with any software.
7+
8+
The fonts are distributed under the following copyright:
9+
10+
Copyright
11+
=========
12+
13+
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream
14+
Vera is a trademark of Bitstream, Inc.
15+
16+
Permission is hereby granted, free of charge, to any person obtaining
17+
a copy of the fonts accompanying this license ("Fonts") and associated
18+
documentation files (the "Font Software"), to reproduce and distribute
19+
the Font Software, including without limitation the rights to use,
20+
copy, merge, publish, distribute, and/or sell copies of the Font
21+
Software, and to permit persons to whom the Font Software is furnished
22+
to do so, subject to the following conditions:
23+
24+
The above copyright and trademark notices and this permission notice
25+
shall be included in all copies of one or more of the Font Software
26+
typefaces.
27+
28+
The Font Software may be modified, altered, or added to, and in
29+
particular the designs of glyphs or characters in the Fonts may be
30+
modified and additional glyphs or characters may be added to the
31+
Fonts, only if the fonts are renamed to names not containing either
32+
the words "Bitstream" or the word "Vera".
33+
34+
This License becomes null and void to the extent applicable to Fonts
35+
or Font Software that has been modified and is distributed under the
36+
"Bitstream Vera" names.
37+
38+
The Font Software may be sold as part of a larger software package but
39+
no copy of one or more of the Font Software typefaces may be sold by
40+
itself.
41+
42+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
44+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
45+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
46+
BITSTREAM OR THE GNOME FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR
47+
OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL,
48+
OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR
49+
OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT
50+
SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
51+
52+
Except as contained in this notice, the names of Gnome, the Gnome
53+
Foundation, and Bitstream Inc., shall not be used in advertising or
54+
otherwise to promote the sale, use or other dealings in this Font
55+
Software without prior written authorization from the Gnome Foundation
56+
or Bitstream Inc., respectively. For further information, contact:
57+
fonts at gnome dot org.
58+
59+
Copyright FAQ
60+
=============
61+
62+
1. I don't understand the resale restriction... What gives?
63+
64+
Bitstream is giving away these fonts, but wishes to ensure its
65+
competitors can't just drop the fonts as is into a font sale system
66+
and sell them as is. It seems fair that if Bitstream can't make money
67+
from the Bitstream Vera fonts, their competitors should not be able to
68+
do so either. You can sell the fonts as part of any software package,
69+
however.
70+
71+
2. I want to package these fonts separately for distribution and
72+
sale as part of a larger software package or system. Can I do so?
73+
74+
Yes. A RPM or Debian package is a "larger software package" to begin
75+
with, and you aren't selling them independently by themselves.
76+
See 1. above.
77+
78+
3. Are derivative works allowed?
79+
Yes!
80+
81+
4. Can I change or add to the font(s)?
82+
Yes, but you must change the name(s) of the font(s).
83+
84+
5. Under what terms are derivative works allowed?
85+
86+
You must change the name(s) of the fonts. This is to ensure the
87+
quality of the fonts, both to protect Bitstream and Gnome. We want to
88+
ensure that if an application has opened a font specifically of these
89+
names, it gets what it expects (though of course, using fontconfig,
90+
substitutions could still could have occurred during font
91+
opening). You must include the Bitstream copyright. Additional
92+
copyrights can be added, as per copyright law. Happy Font Hacking!
93+
94+
6. If I have improvements for Bitstream Vera, is it possible they might get
95+
adopted in future versions?
96+
97+
Yes. The contract between the Gnome Foundation and Bitstream has
98+
provisions for working with Bitstream to ensure quality additions to
99+
the Bitstream Vera font family. Please contact us if you have such
100+
additions. Note, that in general, we will want such additions for the
101+
entire family, not just a single font, and that you'll have to keep
102+
both Gnome and Jim Lyles, Vera's designer, happy! To make sense to add
103+
glyphs to the font, they must be stylistically in keeping with Vera's
104+
design. Vera cannot become a "ransom note" font. Jim Lyles will be
105+
providing a document describing the design elements used in Vera, as a
106+
guide and aid for people interested in contributing to Vera.
107+
108+
7. I want to sell a software package that uses these fonts: Can I do so?
109+
110+
Sure. Bundle the fonts with your software and sell your software
111+
with the fonts. That is the intent of the copyright.
112+
113+
8. If applications have built the names "Bitstream Vera" into them,
114+
can I override this somehow to use fonts of my choosing?
115+
116+
This depends on exact details of the software. Most open source
117+
systems and software (e.g., Gnome, KDE, etc.) are now converting to
118+
use fontconfig (see www.fontconfig.org) to handle font configuration,
119+
selection and substitution; it has provisions for overriding font
120+
names and subsituting alternatives. An example is provided by the
121+
supplied local.conf file, which chooses the family Bitstream Vera for
122+
"sans", "serif" and "monospace". Other software (e.g., the XFree86
123+
core server) has other mechanisms for font substitution.
124+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Source: Bitstream Vera Sans test font from MapServer project (Feb. 2014)
2+
3+
Family name: QGIS Vera Sans
4+
5+
The family name prefix of Bitstream has been set to QGIS so as to never conflict
6+
with any other installed font on user's system, when loaded into QFontDatabase.
7+
8+
DO NOT INSTALL THIS FONT ON YOUR SYSTEM.
9+
It is intended to be loaded by Qt on-the-fly during tests.
64.6 KB
Binary file not shown.
106 KB
Binary file not shown.
60.2 KB
Binary file not shown.
103 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Contained herin is the Bitstream Vera font family.
2+
3+
The Copyright information is found in the COPYRIGHT.TXT file (along
4+
with being incoporated into the fonts themselves).
5+
6+
The releases notes are found in the file "RELEASENOTES.TXT".
7+
8+
We hope you enjoy Vera!
9+
10+
Bitstream, Inc.
11+
The Gnome Project
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
Bitstream Vera Fonts - April 16, 2003
2+
=====================================
3+
4+
The version number of these fonts is 1.10 to distinguish them from the
5+
beta test fonts.
6+
7+
Note that the Vera copyright is incorporated in the fonts themselves.
8+
The License field in the fonts contains the copyright license as it
9+
appears below. The TrueType copyright field is not large enough to
10+
contain the full license, so the license is incorporated (as you might
11+
think if you thought about it) into the license field, which
12+
unfortunately can be obscure to find. (In pfaedit, see: Element->Font
13+
Info->TTFNames->License).
14+
15+
Our apologies for it taking longer to complete the fonts than planned.
16+
Beta testers requested a tighter line spacing (less leading) and Jim
17+
Lyles redesigned Vera's accents to bring its line spacing to more
18+
typical of other fonts. This took additional time and effort. Our
19+
thanks to Jim for this effort above and beyond the call of duty.
20+
21+
There are four monospace and sans faces (normal, oblique, bold, bold
22+
oblique) and two serif faces (normal and bold). Fontconfig/Xft2 (see
23+
www.fontconfig.org) can artificially oblique the serif faces for you:
24+
this loses hinting and distorts the faces slightly, but is visibly
25+
different than normal and bold, and reasonably pleasing.
26+
27+
On systems with fontconfig 2.0 or 2.1 installed, making your sans,
28+
serif and monospace fonts default to these fonts is very easy. Just
29+
drop the file local.conf into your /etc/fonts directory. This will
30+
make the Bitstream fonts your default fonts for all applications using
31+
fontconfig (if sans, serif, or monospace names are used, as they often
32+
are as default values in many desktops). The XML in local.conf may
33+
need modification to enable subpixel decimation, if appropriate,
34+
however, the commented out phrase does so for XFree86 4.3, in the case
35+
that the server does not have sufficient information to identify the
36+
use of a flat panel. Fontconfig 2.2 adds Vera to the list of font
37+
families and will, by default use it as the default sans, serif and
38+
monospace fonts.
39+
40+
During the testing of the final Vera fonts, we learned that screen
41+
fonts in general are only typically hinted to work correctly at
42+
integer pixel sizes. Vera is coded internally for integer sizes only.
43+
We need to investigate further to see if there are commonly used fonts
44+
that are hinted to be rounded but are not rounded to integer sizes due
45+
to oversights in their coding.
46+
47+
Most fonts work best at 8 pixels and below if anti-aliased only, as
48+
the amount of work required to hint well at smaller and smaller sizes
49+
becomes astronomical. GASP tables are typically used to control
50+
whether hinting is used or not, but Freetype/Xft does not currently
51+
support GASP tables (which are present in Vera).
52+
53+
To mitigate this problem, both for Vera and other fonts, there will be
54+
(very shortly) a new fontconfig 2.2 release that will, by default not
55+
apply hints if the size is below 8 pixels. if you should have a font
56+
that in fact has been hinted more agressively, you can use fontconfig
57+
to note this exception. We believe this should improve many hinted
58+
fonts in addition to Vera, though implemeting GASP support is likely
59+
the right long term solution.
60+
61+
Font rendering in Gnome or KDE is the combination of algorithms in
62+
Xft2 and Freetype, along with hinting in the fonts themselves. It is
63+
vital to have sufficient information to disentangle problems that you
64+
may observe.
65+
66+
Note that having your font rendering system set up correctly is vital
67+
to proper judgement of problems of the fonts:
68+
69+
* Freetype may or may not be configured to in ways that may
70+
implement execution of possibly patented (in some parts of the world)
71+
TrueType hinting algorithms, particularly at small sizes. Best
72+
results are obtained while using these algorithms.
73+
74+
* The freetype autohinter (used when the possibly patented
75+
algorithms are not used) continues to improve with each release. If
76+
you are using the autohinter, please ensure you are using an up to
77+
date version of freetype before reporting problems.
78+
79+
* Please identify what version of freetype you are using in any
80+
bug reports, and how your freetype is configured.
81+
82+
* Make sure you are not using the freetype version included in
83+
XFree86 4.3, as it has bugs that significantly degrade most fonts,
84+
including Vera. if you build XFree86 4.3 from source yourself, you may
85+
have installed this broken version without intending it (as I
86+
did). Vera was verified with the recently released Freetype 2.1.4. On
87+
many systems, 'ldd" can be used to see which freetype shared library
88+
is actually being used.
89+
90+
* Xft/X Render does not (yet) implement gamma correction. This
91+
causes significant problems rendering white text on a black background
92+
(causing partial pixels to be insufficiently shaded) if the gamma of
93+
your monitor has not been compensated for, and minor problems with
94+
black text on a while background. The program "xgamma" can be used to
95+
set a gamma correction value in the X server's color pallette. Most
96+
monitors have a gamma near 2.
97+
98+
* Note that the Vera family uses minimal delta hinting. Your
99+
results on other systems when not used anti-aliased may not be
100+
entirely satisfying. We are primarily interested in reports of
101+
problems on open source systems implementing Xft2/fontconfig/freetype
102+
(which implements antialiasing and hinting adjustements, and
103+
sophisticated subpixel decimation on flatpanels). Also, the
104+
algorithms used by Xft2 adjust the hints to integer widths and the
105+
results are crisper on open source systems than on Windows or
106+
MacIntosh.
107+
108+
* Your fontconfig may (probably does) predate the release of
109+
fontconfig 2.2, and you may see artifacts not present when the font is
110+
used at very small sizes with hinting enabled. "vc-list -V" can be
111+
used to see what version you have installed.
112+
113+
We believe and hope that these fonts will resolve the problems
114+
reported during beta test. The largest change is the reduction of
115+
leading (interline spacing), which had annoyed a number of people, and
116+
reduced Vera's utility for some applcations. The Vera monospace font
117+
should also now make '0' and 'O' and '1' and 'l' more clearly
118+
distinguishable.
119+
120+
The version of these fonts is version 1.10. Fontconfig should be
121+
choosing the new version of the fonts if both the released fonts and
122+
beta test fonts are installed (though please discard them: they have
123+
names of form tt20[1-12]gn.ttf). Note that older versions of
124+
fontconfig sometimes did not rebuild their cache correctly when new
125+
fonts are installed: please upgrade to fontconfig 2.2. "fc-cache -f"
126+
can be used to force rebuilding fontconfig's cache files.
127+
128+
If you note problems, please send them to fonts at gnome dot org, with
129+
exactly which face and size and unicode point you observe the problem
130+
at. The xfd utility from XFree86 CVS may be useful for this (e.g. "xfd
131+
-fa sans"). A possibly more useful program to examine fonts at a
132+
variety of sizes is the "waterfall" program found in Keith Packard's
133+
CVS.
134+
135+
$ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS login
136+
Logging in to :pserver:anoncvs@keithp.com:2401/local/src/CVS
137+
CVS password: <hit return>
138+
$ cvs -d :pserver:anoncvs@keithp.com:/local/src/CVS co waterfall
139+
$ cd waterfall
140+
$ xmkmf -a
141+
$ make
142+
# make install
143+
# make install.man
144+
145+
Again, please make sure you are running an up-to-date freetype, and
146+
that you are only examining integer sizes.
147+
148+
Reporting Problems
149+
==================
150+
151+
Please send problem reports to fonts at gnome org, with the following
152+
information:
153+
154+
1. Version of Freetype, Xft2 and fontconfig
155+
2. Whether TT hinting is being used, or the autohinter
156+
3. Application being used
157+
4. Character/Unicode code point that has problems (if applicable)
158+
5. Version of which operating system
159+
6. Please include a screenshot, when possible.
160+
161+
Please check the fonts list archives before reporting problems to cut
162+
down on duplication.

‎tests/testdata/font/README

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

‎tests/testdata/testdata.qrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<RCC>
22
<qresource prefix="/testdata">
3-
<file>font/FreeSansQGIS.ttf</file>
3+
<file>font/QGIS-Vera/QGIS-Vera.ttf</file>
4+
<file>font/QGIS-Vera/QGIS-VeraBd.ttf</file>
45
</qresource>
56
</RCC>

0 commit comments

Comments
 (0)
Please sign in to comment.