Commit 1b25a9ea authored by Derek Schaab's avatar Derek Schaab

Draw one background region instead of individual squares to avoid gaps when scaling

parent 978fa4f4
......@@ -19,8 +19,9 @@ func WriteSVG(w io.Writer, g chess.Game, o Options) (err error) {
}
rowSize := boardSize >> 3
var (
rowSizeStr = []byte(strconv.Itoa(rowSize))
coordStrs = [8][]byte{
boardSizeStr = []byte(strconv.Itoa(boardSize))
rowSizeStr = []byte(strconv.Itoa(rowSize))
coordStrs = [8][]byte{
[]byte(strconv.Itoa(0 * rowSize)),
[]byte(strconv.Itoa(1 * rowSize)),
[]byte(strconv.Itoa(2 * rowSize)),
......@@ -56,8 +57,9 @@ func WriteSVG(w io.Writer, g chess.Game, o Options) (err error) {
)
dst := &svgWriter{w: w}
dst.writeOpenTag(boardSize)
dst.writeDefs(g, rowSize, rowSizeStr, lightRGBAStr, darkRGBAStr, o.Style)
dst.writeDefs(g, rowSize, boardSizeStr, rowSizeStr, lightRGBAStr, darkRGBAStr, o.Style)
dst.writeGroupOpenTag(rowSize)
dst.writeSquareBackground(coordStrs[0], coordStrs[0], dark)
var x, y int
var tx, ty []byte
var p chess.Piece
......@@ -65,8 +67,6 @@ func WriteSVG(w io.Writer, g chess.Game, o Options) (err error) {
x, y = rotate(s, o.Rotate, 1)
if s.Light() {
dst.writeSquareBackground(coordStrs[x], coordStrs[y], light)
} else {
dst.writeSquareBackground(coordStrs[x], coordStrs[y], dark)
}
lbl := label(s, o.Rotate)
if lbl != "" {
......@@ -155,7 +155,7 @@ func (w *svgWriter) writeOpenTag(boardSize int) {
w.write(bracket)
}
func (w *svgWriter) writeDefs(g chess.Game, rowSize int, rowSizeStr, lightRGBAStr, darkRGBAStr []byte, s PieceStyle) {
func (w *svgWriter) writeDefs(g chess.Game, rowSize int, boardSizeStr, rowSizeStr, lightRGBAStr, darkRGBAStr []byte, s PieceStyle) {
w.write(tagDefs)
w.write(tagRect)
w.write(attID)
......@@ -177,10 +177,10 @@ func (w *svgWriter) writeDefs(g chess.Game, rowSize int, rowSizeStr, lightRGBASt
w.write(dark)
w.write(quote)
w.write(attWidth)
w.write(rowSizeStr)
w.write(boardSizeStr)
w.write(quote)
w.write(attHeight)
w.write(rowSizeStr)
w.write(boardSizeStr)
w.write(quote)
w.write(attFill)
w.write(darkRGBAStr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment