Files @ b104a0ddefed
Branch filter:

Location: Diana/src/drawer/svg.py

Laman
SVG rendering: set font size
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
		self.y=y
		self.color=color
		self.label=label

	def __repr__(self):
		return 'DiagramPoint({0},{1},"{2}","{3}")'.format(self.x,self.y,self.color,self.label)


class Svg:
	extension="svg"

	padding=15
	highNumbers=True
	
	def __init__(self):
		self.boardSize=480
		self.padding=30

		self._index=dict()

	def addStone(self,x,y,color):
		self._index[(x,y)]=(len(self._index),DiagramPoint(x,y,color))

	def addMove(self,x,y,color,label):
		if (not self.highNumbers) and isinstance(label,int) and label%100!=0:
			label%=100

		self._index[(x,y)]=(len(self._index),DiagramPoint(x,y,color,label))

	def addLabel(self,x,y,label):
		self._index[(x,y)]=(len(self._index),DiagramPoint(x,y,"",label))

	def render(self, template):
		points = [p for (i,p) in sorted(self._index.values())]

		stones = [p for p in points if p.color and not p.label]
		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, "adjustFont":adjustFont}

		return template.render(params)