Skip to content

Commit 83cb4ef

Browse files
committed
Initial test for PAL engine
- Includes small custom test font based of off Gnu Free Sans - Test if font can be stored and loaded - Test if layer can have PAL engine set - Test render comparison for output of vector line layer
1 parent ac3f33d commit 83cb4ef

File tree

11 files changed

+2545
-0
lines changed

11 files changed

+2545
-0
lines changed

tests/src/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ ADD_PYTHON_TEST(PyQgsSymbolLayerV2 test_qgssymbollayerv2.py)
1717
ADD_PYTHON_TEST(PyQgsPoint test_qgspoint.py)
1818
ADD_PYTHON_TEST(PyQgsAtlasComposition test_qgsatlascomposition.py)
1919
ADD_PYTHON_TEST(PyQgsComposerLabel test_qgscomposerlabel.py)
20+
ADD_PYTHON_TEST(PyQgsPalLabeling test_qgspallabeling.py)
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# -*- coding: utf-8 -*-
2+
"""QGIS Unit tests for QgsPalLabeling
3+
4+
.. note:: This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 2 of the License, or
7+
(at your option) any later version.
8+
"""
9+
__author__ = 'Larry Shaffer'
10+
__date__ = '12/10/2012'
11+
__copyright__ = 'Copyright 2012, The Quantum GIS Project'
12+
# This will get replaced with a git SHA1 when you do a git archive
13+
__revision__ = '$Format:%H$'
14+
15+
import os
16+
from PyQt4.QtCore import *
17+
from PyQt4.QtGui import *
18+
19+
from qgis.core import (QgsPalLabeling,
20+
QgsPalLayerSettings,
21+
QgsVectorLayer,
22+
QgsMapLayerRegistry,
23+
QgsMapRenderer,
24+
QgsCoordinateReferenceSystem,
25+
QgsRenderChecker,
26+
QGis)
27+
28+
from utilities import (getQgisTestApp,
29+
TestCase,
30+
unittest,
31+
expectedFailure,
32+
unitTestDataPath)
33+
34+
# Convenience instances in case you may need them
35+
QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
36+
TEST_DATA_DIR = unitTestDataPath()
37+
38+
39+
class TestQgsPalLabeling(TestCase):
40+
41+
@classmethod
42+
def setUpClass(cls):
43+
"""Run before all tests"""
44+
45+
# Store/load the FreeSansQGIS labeling test font
46+
myFontDB = QFontDatabase()
47+
cls._testFontID = myFontDB.addApplicationFont(
48+
os.path.join(TEST_DATA_DIR, 'font', 'FreeSansQGIS.ttf'))
49+
myMessage = ('\nCould not store test font in font database, '
50+
'skipping test suite')
51+
assert cls._testFontID != -1, myMessage
52+
53+
cls._testFont = myFontDB.font('FreeSansQGIS', 'Medium', 12)
54+
myAppFont = QApplication.font()
55+
myMessage = ('\nCould not load test font from font database, '
56+
'skipping test suite')
57+
assert cls._testFont.toString() != myAppFont.toString(), myMessage
58+
59+
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
60+
cls._MapRegistry = QgsMapLayerRegistry.instance()
61+
cls._Canvas = CANVAS
62+
# to match render test comparisons background
63+
cls._Canvas.setCanvasColor(QColor(152, 219, 249))
64+
cls._Map = cls._Canvas.map()
65+
cls._Map.resize(QSize(600, 400))
66+
cls._MapRenderer = cls._Canvas.mapRenderer()
67+
cls._MapRenderer.setOutputSize(QSize(600, 400), 72)
68+
69+
cls._Pal = QgsPalLabeling();
70+
cls._MapRenderer.setLabelingEngine(cls._Pal)
71+
cls._PalEngine = cls._MapRenderer.labelingEngine()
72+
myMessage = ('\nCould initialize PAL labeling engine, '
73+
'skipping test suite')
74+
assert cls._PalEngine, myMessage
75+
76+
@classmethod
77+
def tearDownClass(cls):
78+
"""Run after all tests"""
79+
# remove test font
80+
myFontDB = QFontDatabase()
81+
myResult = myFontDB.removeApplicationFont(cls._testFontID)
82+
myMessage = ('\nFailed to remove test font from font database')
83+
assert myResult, myMessage
84+
85+
def setUp(self):
86+
"""Run before each test."""
87+
pass
88+
89+
def tearDown(self):
90+
"""Run after each test."""
91+
pass
92+
93+
def test_AddPALToVectorLayer(self):
94+
"""Check if we can set a label field, verify that PAL is assigned
95+
and that output is rendered correctly"""
96+
# TODO: add UTM PAL-specific shps, with 4326 as on-the-fly cross-check
97+
# setCanvasCrs(26913)
98+
99+
myShpFile = os.path.join(TEST_DATA_DIR, 'lines.shp')
100+
myVectorLayer = QgsVectorLayer(myShpFile, 'Lines', 'ogr')
101+
102+
self._MapRegistry.addMapLayer(myVectorLayer)
103+
104+
myLayers = QStringList()
105+
myLayers.append(myVectorLayer.id())
106+
self._MapRenderer.setLayerSet(myLayers)
107+
self._MapRenderer.setExtent(myVectorLayer.extent())
108+
self._Canvas.zoomToFullExtent()
109+
110+
# check layer labeling is PAL with customProperty access
111+
# should not be activated on layer load
112+
myPalSet = myVectorLayer.customProperty( "labeling" ).toString()
113+
myMessage = '\nExpected: Empty QString\nGot: %s' % (str(myPalSet))
114+
assert str(myPalSet) == '', myMessage
115+
116+
# simulate clicking checkbox, setting label field and clicking apply
117+
self._testFont.setPointSize(20)
118+
myPalLyr = QgsPalLayerSettings()
119+
120+
myPalLyr.enabled = True
121+
myPalLyr.fieldName = 'Name'
122+
myPalLyr.placement = QgsPalLayerSettings.Line
123+
myPalLyr.placementFlags = QgsPalLayerSettings.AboveLine
124+
myPalLyr.xQuadOffset = 0
125+
myPalLyr.yQuadOffset = 0
126+
myPalLyr.xOffset = 0
127+
myPalLyr.yOffset = 0
128+
myPalLyr.angleOffset = 0
129+
myPalLyr.centroidWhole = False
130+
myPalLyr.textFont = self._testFont
131+
myPalLyr.textNamedStyle = QString("Medium")
132+
myPalLyr.textColor = Qt.black
133+
myPalLyr.textTransp = 0
134+
myPalLyr.previewBkgrdColor = Qt.white
135+
myPalLyr.priority = 5
136+
myPalLyr.obstacle = True
137+
myPalLyr.dist = 0
138+
myPalLyr.scaleMin = 0
139+
myPalLyr.scaleMax = 0
140+
myPalLyr.bufferSize = 1
141+
myPalLyr.bufferColor = Qt.white
142+
myPalLyr.bufferTransp = 0
143+
myPalLyr.bufferNoFill = False
144+
myPalLyr.bufferJoinStyle = Qt.RoundJoin
145+
myPalLyr.formatNumbers = False
146+
myPalLyr.decimals = 3
147+
myPalLyr.plusSign = False
148+
myPalLyr.labelPerPart = False
149+
myPalLyr.displayAll = True
150+
myPalLyr.mergeLines = False
151+
myPalLyr.minFeatureSize = 0.0
152+
myPalLyr.vectorScaleFactor = 1.0
153+
myPalLyr.rasterCompressFactor = 1.0
154+
myPalLyr.addDirectionSymbol = False
155+
myPalLyr.upsidedownLabels = QgsPalLayerSettings.Upright
156+
myPalLyr.fontSizeInMapUnits = False
157+
myPalLyr.bufferSizeInMapUnits = False
158+
myPalLyr.labelOffsetInMapUnits = True
159+
myPalLyr.distInMapUnits = False
160+
myPalLyr.wrapChar = ""
161+
myPalLyr.preserveRotation = True
162+
163+
myPalLyr.writeToLayer(myVectorLayer)
164+
165+
# check layer labeling is PAL with customProperty access
166+
myPalSet = myVectorLayer.customProperty( "labeling" ).toString()
167+
myMessage = '\nExpected: pal\nGot: %s' % (str(myPalSet))
168+
assert str(myPalSet) == 'pal', myMessage
169+
170+
# check layer labeling is PAL via engine interface
171+
myMessage = '\nCould not get whether PAL enabled from labelingEngine'
172+
assert self._PalEngine.willUseLayer(myVectorLayer), myMessage
173+
174+
#
175+
myChecker = QgsRenderChecker()
176+
myChecker.setControlName("expected_pal_aboveLineLabeling")
177+
myChecker.setMapRenderer(self._MapRenderer)
178+
179+
myResult = myChecker.runTest("pal_aboveLineLabeling_python");
180+
myMessage = ('\nVector layer \'above line\' label engine '
181+
'rendering test failed')
182+
assert myResult, myMessage
183+
184+
# compare against a straight rendering/save as from QgsMapCanvasMap
185+
# unnecessary? works a bit different than QgsRenderChecker, though
186+
# myImage = os.path.join(unicode(QDir.tempPath()),
187+
# 'render_pal_aboveLineLabeling.png')
188+
# self._Map.render()
189+
# self._Canvas.saveAsImage(myImage)
190+
# myChecker.setRenderedImage(myImage)
191+
# myResult = myChecker.compareImages("pal_aboveLineLabeling_python")
192+
# myMessage = ('\nVector layer \'above line\' label engine '
193+
# 'comparison to QgsMapCanvasMap.render() test failed')
194+
# assert myResult, myMessage
195+
196+
self._MapRegistry.removeMapLayer(myVectorLayer.id())
197+
198+
# @expectedFailure
199+
# def testIssue####(self):
200+
# """Test we can .
201+
# """
202+
# pass
203+
204+
if __name__ == '__main__':
205+
unittest.main()
206+
207+

tests/testdata/font/AUTHORS

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
-*- mode:text; coding:utf-8; -*-
2+
$Id: AUTHORS,v 1.9 2005/12/03 10:56:08 peterlin Exp $
3+
4+
The free UCS scalable font collection is being maintained by Primo�
5+
Peterlin <primoz.peterlin AT biofiz.mf.uni-lj.si>. The folowing list
6+
cites the other contributors that contributed to particular ISO 10646
7+
blocks.
8+
9+
* URW++ Design & Development GmbH <http://www.urwpp.de/>
10+
11+
Basic Latin (U+0041-U+007A)
12+
Latin-1 Supplement (U+00C0-U+00FF) (most)
13+
Latin Extended-A (U+0100-U+017F)
14+
Spacing Modifier Letters (U+02B0-U+02FF)
15+
Mathematical Operators (U+2200-U+22FF) (parts)
16+
Block Elements (U+2580-U+259F)
17+
Dingbats (U+2700-U+27BF)
18+
19+
* Yannis Haralambous <yannis.haralambous AT enst-bretagne.fr> and John
20+
Plaice <plaice AT omega.cse.unsw.edu.au>
21+
22+
Latin Extended-B (U+0180-U+024F)
23+
IPA Extensions (U+0250-U+02AF)
24+
Greek (U+0370-U+03FF)
25+
Armenian (U+0530-U+058F)
26+
Hebrew (U+0590-U+05FF)
27+
Arabic (U+0600-U+06FF)
28+
Currency Symbols (U+20A0-U+20CF)
29+
Arabic Presentation Forms-A (U+FB50-U+FDFF)
30+
Arabic Presentation Forms-B (U+FE70-U+FEFF)
31+
32+
* Young U. Ryu <ryoung AT utdallas.edu>
33+
34+
Arrows (U+2190-U+21FF)
35+
Mathematical Symbols (U+2200-U+22FF)
36+
37+
* Valek Filippov <frob AT df.ru>
38+
39+
Cyrillic (U+0400-U+04FF)
40+
41+
* Wadalab Kanji Comittee
42+
43+
Hiragana (U+3040-U+309F)
44+
Katakana (U+30A0-U+30FF)
45+
46+
* Angelo Haritsis <ah AT computer.org>
47+
48+
Greek (U+0370-U+03FF)
49+
50+
* Yannis Haralambous and Virach Sornlertlamvanich
51+
52+
Thai (U+0E00-U+0E7F)
53+
54+
* Shaheed R. Haque <srhaque AT iee.org>
55+
56+
Bengali (U+0980-U+09FF)
57+
58+
* Sam Stepanyan <sam AT arminco.com>
59+
60+
Armenian (U+0530-U+058F)
61+
62+
* Mohamed Ishan <ishan AT mitf.f2s.com>
63+
64+
Thaana (U+0780-U+07BF)
65+
66+
* Sushant Kumar Dash <sushant AT writeme.com>
67+
68+
Oriya (U+0B00-U+0B7F)
69+
70+
* Harsh Kumar <harshkumar AT vsnl.com>
71+
72+
Devanagari (U+0900-U+097F)
73+
Bengali (U+0980-U+09FF)
74+
Gurmukhi (U+0A00-U+0A7F)
75+
Gujarati (U+0A80-U+0AFF)
76+
77+
* Prasad A. Chodavarapu <chprasad AT hotmail.com>
78+
79+
Telugu (U+0C00-U+0C7F)
80+
81+
* Frans Velthuis <velthuis AT rc.rug.nl> and Anshuman Pandey
82+
<apandey AT u.washington.edu>
83+
84+
Devanagari (U+0900-U+097F)
85+
86+
* Hardip Singh Pannu <HSPannu AT aol.com>
87+
88+
Gurmukhi (U+0A00-U+0A7F)
89+
90+
* Jeroen Hellingman <jehe AT kabelfoon.nl>
91+
92+
Oriya (U+0B00-U+0B7F)
93+
Malayalam (U+0D00-U+0D7F)
94+
95+
* Thomas Ridgeway <email needed>
96+
97+
Tamil (U+0B80-U+0BFF)
98+
99+
* Berhanu Beyene <1beyene AT informatik.uni-hamburg.de>,
100+
Prof. Dr. Manfred Kudlek <kudlek AT informatik.uni-hamburg.de>, Olaf
101+
Kummer <kummer AT informatik.uni-hamburg.de>, and Jochen Metzinger <?>
102+
103+
Ethiopic (U+1200-U+137F)
104+
105+
* Maxim Iorsh <iorsh AT users.sourceforge.net>
106+
107+
Hebrew (U+0590-U+05FF)
108+
109+
* Vyacheslav Dikonov <sdiconov AT mail.ru>
110+
111+
Syriac (U+0700-U+074A)
112+
Braille (U+2800-U+28FF)
113+
114+
* Panayotis Katsaloulis <panayotis AT panayotis.com>
115+
116+
Greek Extended (U+1F00-U+1FFF)
117+
118+
* M.S. Sridhar <mssridhar AT vsnl.com>
119+
120+
Devanagari (U+0900-U+097F)
121+
Bengali (U+0980-U+09FF)
122+
Gurmukhi (U+0A00-U+0A7F)
123+
Gujarati (U+0A80-U+0AFF)
124+
Oriya (U+0B00-U+0B7F)
125+
Tamil (U+0B80-U+0BFF)
126+
Telugu (U+0C00-U+0C7F)
127+
Kannada (U+0C80-U+0CFF)
128+
Malayalam (U+0D00-U+0D7F)
129+
130+
* DMS Electronics, The Sri Lanka Tipitaka Project, and Noah Levitt
131+
<nlevitt AT columbia.edu>
132+
133+
Sinhala (U+0D80-U+0DFF)
134+
135+
* Dan Shurovich Chirkov <dansh AT chirkov.com>
136+
137+
Cyrillic (U+0400-U+04FF)
138+
139+
* Abbas Izad <abbasizad AT hotmail.com>
140+
141+
Arabic (U+0600-U+06FF)
142+
Arabic Presentation Forms-A (U+FB50-U+FDFF)
143+
Arabic Presentation Forms-B (U+FE70-U+FEFF)
144+
145+
* Denis Jacquerye <moyogo AT gmail.com>
146+
147+
Latin Extended-B (U+0180-U+024F)
148+
IPA Extensions (U+0250-U+02AF)
149+
150+
* K.H. Hussain <hussain AT kfri.org> and R. Chitrajan
151+
152+
Malayalam (U+0D00-U+0D7F)
153+
154+
* Solaiman Karim <solaiman AT ekushey.org>
155+
156+
Bengali (U+0980-U+09FF)
157+
158+
Please see the CREDITS file for details on who contributed particular
159+
subsets of the glyphs in font files.

0 commit comments

Comments
 (0)