Changeset - b104a0ddefed
[Not reviewed]
default
0 3 0
Laman - 8 years ago 2017-02-09 21:00:26

SVG rendering: set font size
3 files changed with 11 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/drawer/svg.py
Show inline comments
 
from jinja2 import Template
 

	
 

	
 
c=28
 
padding=15
 
highNumbers=True
 

	
 

	
 
def adjustFont(base,text):
 
	text=str(text)
 
	if len(text)<2: return round(0.7*base)
 
	elif len(text)<3: return round(0.55*base)
 
	else: return round(0.4*base)
 

	
 

	
 
class DiagramPoint:
 
	def __init__(self,x,y,color="",label=""):
 
		self.x=x
 
@@ -48,16 +52,6 @@ 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]
 

	
 
		params = {"boardSize":self.boardSize, "padding":self.padding, "stones":stones, "moves":moves, "labels":labels}
 
		params = {"boardSize":self.boardSize, "padding":self.padding, "stones":stones, "moves":moves, "labels":labels, "adjustFont":adjustFont}
 

	
 
		return template.render(params)
 

	
 
	# def getFontSize(self,text):
 
	# 	if len(text)<2: return round(0.7*c)
 
	# 	elif len(text)<3: return round(0.55*c)
 
	# 	else: return round(0.4*c)
 
	#
 
	# def writeLabel(self,x,y,label,color):
 
	# 	label=str(label)
 
	# 	fontSize=self.getFontSize(label)
 
	# 	self.content+='  <text x="{0}" y="{1}" class="{2}" font-size="{3}">{4}</text>\n'.format(padding+x*c, padding+y*c+0.35*fontSize, color, fontSize, label)
src/templ/templ-pleb.svg
Show inline comments
 
@@ -13,6 +13,6 @@ circle.e {stroke:none;fill:white}
 
{% 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>
 
	<text class="{{p.color or 'e'}}" y="0.35em" font-size="{{adjustFont(cellSize,p.label)}}">{{p.label}}</text>
 
</g>
 
{% endmacro %}
src/templ/templ.svg
Show inline comments
 
@@ -6,7 +6,7 @@
 
	{% 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>
 
		<text y="0.35em" font-size="{{adjustFont(cellSize,p.label)}}">{{p.label}}</text>
 
	</g>
 
	{% endmacro %}
 
{% endif %}
 
@@ -16,7 +16,7 @@
 
		<style type="text/css"><![CDATA[
 
		{% block style %}
 
			rect{fill:white;stroke:black;stroke-width:1px}
 
			text{font-family:"DejaVu Sans";text-anchor:middle;}
 
			text{font-family:"DejaVu Sans";text-anchor:middle}
 
			line{stroke:black;stroke-width:0.7px}
 
			circle{stroke:black}
 
			circle.b, .b circle, .w text, .e text{fill:black}
0 comments (0 inline, 0 general)