# HG changeset patch
# User Laman
# Date 2017-02-05 22:02:28
# Node ID c705c709565bd185e9f257e1ba9e4356a7263bc4
# Parent  2a5d1585e74897ebea95dd0d663ab7a25f2d972a

enhanced SVG, added pleb.svg circumventing a rendering bug in librsvg

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -2,3 +2,4 @@
 __pycache__/
 ^in/
 ^out/
+\.pyc$
diff --git a/src/diana.py b/src/diana.py
--- a/src/diana.py
+++ b/src/diana.py
@@ -2,6 +2,8 @@
 import re
 import sys
 
+from jinja2 import Environment,FileSystemLoader
+
 import go
 from go import BLACK,WHITE,EMPTY
 from sgfParser.collection import Collection
@@ -11,8 +13,7 @@ from drawer.tikz import Tikz
 
 
 templateDir=os.path.join(os.path.dirname(__file__),"templ")
-with open(os.path.join(templateDir,"templ.svg")) as f:
-	template=f.read()
+env=Environment(loader=FileSystemLoader(templateDir))
 
 
 if len(sys.argv)>1:
@@ -99,7 +100,7 @@ def processFile(fileName):
 			
 		# finish and save the diagram
 		t=open(os.path.join("out","{0}-{1}.{2}".format(shortName,i+1,diagram.extension)),'w') # a new file
-		t.write(diagram.render(template))
+		t.write(diagram.render(env.get_template("templ.svg")))
 		t.close()
 			
 	notes=open(os.path.join("out","{0}.txt".format(shortName)),'w')
diff --git a/src/drawer/svg.py b/src/drawer/svg.py
--- a/src/drawer/svg.py
+++ b/src/drawer/svg.py
@@ -48,10 +48,9 @@ class Svg:
 		moves = [p for p in points if p.color and p.label]
 		labels = [p for p in points if not p.color and p.label]
 
-		svg = Template(template)
 		params = {"boardSize":self.boardSize, "padding":self.padding, "stones":stones, "moves":moves, "labels":labels}
 
-		return svg.render(params)
+		return template.render(params)
 
 	# def getFontSize(self,text):
 	# 	if len(text)<2: return round(0.7*c)
diff --git a/src/templ/templ-pleb.svg b/src/templ/templ-pleb.svg
new file mode 100644
--- /dev/null
+++ b/src/templ/templ-pleb.svg
@@ -0,0 +1,18 @@
+{% extends "templ.svg" %}
+
+{% block style %}
+rect{fill:white;stroke:black;stroke-width:1px}
+text{font-family:"DejaVu Sans";text-anchor:middle;}
+line{stroke:black;stroke-width:0.7px}
+circle{stroke:black}
+circle.b, text.w, text.e{fill:black}
+circle.w, text.b{fill:white}
+circle.e {stroke:none;fill:white}
+{% endblock %}
+
+{% macro labeledPoint(p) %}
+<g transform="translate({{(p.x*cellSize) | round(2)}},{{(p.y*cellSize) | round(2)}})">
+	<circle class="{{p.color or 'e'}}" cx="0" cy="0" r="{{stoneRadius|round(2)}}"/>
+	<text class="{{p.color or 'e'}}" y="0.4em">{{p.label}}</text>
+</g>
+{% endmacro %}
diff --git a/src/templ/templ.svg b/src/templ/templ.svg
--- a/src/templ/templ.svg
+++ b/src/templ/templ.svg
@@ -1,20 +1,31 @@
-<?xml version="1.0" standalone="no"?>
+<?xml version="1.0" encoding="utf-8"?>
 {% set cellSize=boardSize/18 %}
 {% set stoneRadius=cellSize/2-1 %}
 
-<svg width="{{boardSize+padding*2}}" height="{{boardSize+padding*2}}" version="1.1" xmlns="http://www.w3.org/2000/svg" alignment-baseline="center">
+{% if not labeledPoint %}
+	{% macro labeledPoint(p) %}
+	<g class="{{p.color or 'e'}}" transform="translate({{(p.x*cellSize) | round(2)}},{{(p.y*cellSize) | round(2)}})">
+		<circle cx="0" cy="0" r="{{stoneRadius|round(2)}}"/>
+		<text y="0.4em">{{p.label}}</text>
+	</g>
+	{% endmacro %}
+{% endif %}
+
+<svg width="{{boardSize+padding*2}}" height="{{boardSize+padding*2}}" version="1.1" xmlns="http://www.w3.org/2000/svg">
 	<defs>
 		<style type="text/css"><![CDATA[
-			rect{fill:white;stroke:black;stroke-width:1}
+		{% block style %}
+			rect{fill:white;stroke:black;stroke-width:1px}
 			text{font-family:"DejaVu Sans";text-anchor:middle;}
-			line{stroke:black;stroke-width:0.7}
+			line{stroke:black;stroke-width:0.7px}
 			circle{stroke:black}
 			circle.b, .b circle, .w text, .e text{fill:black}
 			circle.w, .w circle, .b text{fill:white}
 			.e circle {stroke:none;fill:white}
+		{% endblock %}
 		]]></style>
 	</defs>
-	<g width="{{boardSize}}" height="{{boardSize}}" transform="translate({{padding}},{{padding}})">
+	<g transform="translate({{padding}},{{padding}})">
 		<rect x="0" y="0" width="{{boardSize}}" height="{{boardSize}}"/>
 		{# grid #}
 		{% for i in range(1,18) %}
@@ -36,18 +47,12 @@
 
 		{# moves #}
 		{% for p in moves %}
-			<g width="{{cellSize|round(2)}}" height="{{cellSize|round(2)}}" class="{{p.color}}" transform="translate({{(p.x*cellSize) | round(2)}},{{(p.y*cellSize) | round(2)}})">
-				<circle cx="0" cy="0" r="{{stoneRadius|round(2)}}"/>
-				<text y="0.4em">{{p.label}}</text>
-			</g>
+			{{labeledPoint(p)}}
 		{% endfor %}
 
 		{# labels #}
 		{% for p in labels %}
-			<g width="{{cellSize|round(2)}}" height="{{cellSize|round(2)}}" class="e" transform="translate({{(p.x*cellSize) | round(2)}},{{(p.y*cellSize) | round(2)}})">
-				<circle cx="0" cy="0" r="{{stoneRadius|round(2)}}"/>
-				<text y="0.4em">{{p.label}}</text>
-			</g>
+			{{labeledPoint(p)}}
 		{% endfor %}
 	</g>
 </svg>