@@ -60,9 +60,9 @@ def testSimpleMarkerRotation(self):
6060
6161 self .assertStaticRotation (root , '50' )
6262
63- def assertStaticRotation (self , root , expectedValue ):
63+ def assertStaticRotation (self , root , expectedValue , index = 0 ):
6464 # Check the rotation element is a literal, not a
65- rotation = root .elementsByTagName ('se:Rotation' ).item (0 )
65+ rotation = root .elementsByTagName ('se:Rotation' ).item (index )
6666 literal = rotation .firstChild ()
6767 self .assertEqual ("ogc:Literal" , literal .nodeName ())
6868 self .assertEqual (expectedValue , literal .firstChild ().nodeValue ())
@@ -127,11 +127,21 @@ def testSimpleMarkerUnitPixels(self):
127127
128128 def testSvgMarkerUnitDefault (self ):
129129 symbol = QgsSvgMarkerSymbolLayer ('symbols/star.svg' , 10 , 90 )
130+ symbol .setFillColor (QColor ("blue" ))
131+ symbol .setOutlineWidth (1 )
132+ symbol .setOutlineColor (QColor ('red' ))
133+ symbol .setPath ('symbols/star.svg' )
130134 symbol .setOffset (QPointF (5 , 10 ))
131135
132136 dom , root = self .symbolToSld (symbol )
133137 # print("Svg marker mm: " + dom.toString())
134138
139+ self .assertExternalGraphic (root , 0 ,
140+ 'symbols/star.svg?fill=%230000ff&fill-opacity=1&outline=%23ff0000&outline-opacity=1&outline-width=4' , 'image/svg+xml' )
141+ self .assertExternalGraphic (root , 1 ,
142+ 'symbols/star.svg' , 'image/svg+xml' )
143+ self .assertWellKnownMark (root , 0 , 'square' , '#0000ff' , '#ff0000' , 4 )
144+
135145 # Check the size has been rescaled
136146 self .assertStaticSize (root , '36' )
137147
@@ -141,11 +151,21 @@ def testSvgMarkerUnitDefault(self):
141151
142152 def testSvgMarkerUnitPixels (self ):
143153 symbol = QgsSvgMarkerSymbolLayer ('symbols/star.svg' , 10 , 0 )
154+ symbol .setFillColor (QColor ("blue" ))
155+ symbol .setOutlineWidth (1 )
156+ symbol .setOutlineColor (QColor ('red' ))
157+ symbol .setPath ('symbols/star.svg' )
144158 symbol .setOffset (QPointF (5 , 10 ))
145159 symbol .setOutputUnit (QgsUnitTypes .RenderPixels )
146160 dom , root = self .symbolToSld (symbol )
147161 # print("Svg marker unit px: " + dom.toString())
148162
163+ self .assertExternalGraphic (root , 0 ,
164+ 'symbols/star.svg?fill=%230000ff&fill-opacity=1&outline=%23ff0000&outline-opacity=1&outline-width=1' , 'image/svg+xml' )
165+ self .assertExternalGraphic (root , 1 ,
166+ 'symbols/star.svg' , 'image/svg+xml' )
167+ self .assertWellKnownMark (root , 0 , 'square' , '#0000ff' , '#ff0000' , 1 )
168+
149169 # Check the size has not been rescaled
150170 self .assertStaticSize (root , '10' )
151171 self .assertStaticDisplacement (root , 5 , 10 )
@@ -154,7 +174,7 @@ def testFontMarkerUnitDefault(self):
154174 symbol = QgsFontMarkerSymbolLayer ('sans' , ',' , 10 , QColor ('black' ), 45 )
155175 symbol .setOffset (QPointF (5 , 10 ))
156176 dom , root = self .symbolToSld (symbol )
157- # print "Font marker unit mm: " + dom.toString()
177+ # print( "Font marker unit mm: " + dom.toString() )
158178
159179 # Check the size has been rescaled
160180 self .assertStaticSize (root , '36' )
@@ -300,32 +320,47 @@ def testSimpleFillPixels(self):
300320
301321 def testSvgFillDefault (self ):
302322 symbol = QgsSVGFillSymbolLayer ('test/star.svg' , 10 , 45 )
323+ symbol .setSvgFillColor (QColor ('blue' ))
303324 symbol .setSvgOutlineWidth (3 )
325+ symbol .setSvgOutlineColor (QColor ('yellow' ))
326+ symbol .subSymbol ().setWidth (10 )
304327
305328 dom , root = self .symbolToSld (symbol )
306329 # print ("Svg fill mm: \n" + dom.toString())
307330
331+ self .assertExternalGraphic (root , 0 ,
332+ 'test/star.svg?fill=%230000ff&fill-opacity=1&outline=%23ffff00&outline-opacity=1&outline-width=11' , 'image/svg+xml' )
333+ self .assertExternalGraphic (root , 1 ,
334+ 'test/star.svg' , 'image/svg+xml' )
335+ self .assertWellKnownMark (root , 0 , 'square' , '#0000ff' , '#ffff00' , 11 )
336+
308337 self .assertStaticRotation (root , '45' )
309338 self .assertStaticSize (root , '36' )
310- # width of the svg outline
311- self .assertStrokeWidth (root , 1 , 11 )
312339 # width of the polygon outline
313- self .assertStrokeWidth (root , 3 , 1 )
340+ lineSymbolizer = root .elementsByTagName ('se:LineSymbolizer' ).item (0 ).toElement ()
341+ self .assertStrokeWidth (lineSymbolizer , 1 , 36 )
314342
315343 def testSvgFillPixel (self ):
316344 symbol = QgsSVGFillSymbolLayer ('test/star.svg' , 10 , 45 )
345+ symbol .setSvgFillColor (QColor ('blue' ))
317346 symbol .setSvgOutlineWidth (3 )
318347 symbol .setOutputUnit (QgsUnitTypes .RenderPixels )
348+ symbol .subSymbol ().setWidth (10 )
319349
320350 dom , root = self .symbolToSld (symbol )
321351 # print ("Svg fill px: \n" + dom.toString())
322352
353+ self .assertExternalGraphic (root , 0 ,
354+ 'test/star.svg?fill=%230000ff&fill-opacity=1&outline=%23000000&outline-opacity=1&outline-width=3' , 'image/svg+xml' )
355+ self .assertExternalGraphic (root , 1 ,
356+ 'test/star.svg' , 'image/svg+xml' )
357+ self .assertWellKnownMark (root , 0 , 'square' , '#0000ff' , '#000000' , 3 )
358+
323359 self .assertStaticRotation (root , '45' )
324360 self .assertStaticSize (root , '10' )
325- # width of the svg outline
326- self .assertStrokeWidth (root , 1 , 3 )
327361 # width of the polygon outline
328- self .assertStrokeWidth (root , 3 , 0.26 )
362+ lineSymbolizer = root .elementsByTagName ('se:LineSymbolizer' ).item (0 ).toElement ()
363+ self .assertStrokeWidth (lineSymbolizer , 1 , 10 )
329364
330365 def testLineFillDefault (self ):
331366 symbol = QgsLinePatternFillSymbolLayer ()
@@ -497,10 +532,41 @@ def assertStaticSize(self, root, expectedValue):
497532 size = root .elementsByTagName ('se:Size' ).item (0 )
498533 self .assertEqual (expectedValue , size .firstChild ().nodeValue ())
499534
535+ def assertExternalGraphic (self , root , index , expectedLink , expectedFormat ):
536+ graphic = root .elementsByTagName ('se:ExternalGraphic' ).item (index )
537+ onlineResource = graphic .firstChildElement ('se:OnlineResource' )
538+ self .assertEqual (expectedLink , onlineResource .attribute ('xlink:href' ))
539+ format = graphic .firstChildElement ('se:Format' )
540+ self .assertEqual (expectedFormat , format .firstChild ().nodeValue ())
541+
500542 def assertStaticPerpendicularOffset (self , root , expectedValue ):
501543 offset = root .elementsByTagName ('se:PerpendicularOffset' ).item (0 )
502544 self .assertEqual (expectedValue , offset .firstChild ().nodeValue ())
503545
546+ def assertWellKnownMark (self , root , index , expectedName , expectedFill , expectedStroke , expectedStrokeWidth ):
547+ mark = root .elementsByTagName ('se:Mark' ).item (index )
548+ wkn = mark .firstChildElement ('se:WellKnownName' )
549+ self .assertEqual (expectedName , wkn .text ())
550+
551+ fill = mark .firstChildElement ('se:Fill' )
552+ if expectedFill is None :
553+ self .assertTrue (fill .isNull ())
554+ else :
555+ parameter = fill .firstChildElement ('se:SvgParameter' )
556+ self .assertEqual ('fill' , parameter .attribute ('name' ))
557+ self .assertEqual (expectedFill , parameter .text ())
558+
559+ stroke = mark .firstChildElement ('se:Stroke' )
560+ if expectedStroke is None :
561+ self .assertTrue (stroke .isNull ())
562+ else :
563+ parameter = stroke .firstChildElement ('se:SvgParameter' )
564+ self .assertEqual ('stroke' , parameter .attribute ('name' ))
565+ self .assertEqual (expectedStroke , parameter .text ())
566+ parameter = parameter .nextSiblingElement ('se:SvgParameter' )
567+ self .assertEqual ('stroke-width' , parameter .attribute ('name' ))
568+ self .assertEqual (str (expectedStrokeWidth ), parameter .text ())
569+
504570 def symbolToSld (self , symbolLayer ):
505571 dom = QDomDocument ()
506572 root = dom .createElement ("FakeRoot" )
0 commit comments