Changeset - c705c709565b
[Not reviewed]
default
0 4 1
Laman - 8 years ago 2017-02-05 22:02:28

enhanced SVG, added pleb.svg circumventing a rendering bug in librsvg
5 files changed with 42 insertions and 18 deletions:
0 comments (0 inline, 0 general)
.hgignore
Show inline comments
 
@@ -2,3 +2,4 @@
 
__pycache__/
 
^in/
 
^out/
 
\.pyc$
src/diana.py
Show inline comments
 
@@ -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')
src/drawer/svg.py
Show inline comments
 
@@ -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)
src/templ/templ-pleb.svg
Show inline comments
 
new file 100644
 
{% 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 %}
src/templ/templ.svg
Show inline comments
 
<?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>
0 comments (0 inline, 0 general)