Skip to content

Scaled transform breaks dashing #18

@Qendolin

Description

@Qendolin

When rasterizing an SVG with a scaled transformation matrix dashing does not behave correctly.
My goal is to create a high resolution png render of the svg.

At scale 1.0 (correct):
Not Scaled SVG

At scale 2.0:
image

Code used:

package main

import (
	"image"
	"image/png"
	"os"

	"github.com/srwiley/oksvg"
	"github.com/srwiley/rasterx"
)

func main() {
	scale := 2.0

	in, err := os.Open("in.svg")
	check(err)
	defer in.Close()

	icon, err := oksvg.ReadIconStream(in)
	check(err)

	w, h := int(icon.ViewBox.W*scale), int(icon.ViewBox.H*scale)

	icon.SetTarget(0, 0, float64(w), float64(h))
	rgba := image.NewRGBA(image.Rect(0, 0, w, h))
	dasher := rasterx.NewDasher(w, h, rasterx.NewScannerGV(w, h, rgba, rgba.Bounds()))
	icon.Draw(dasher, 1)

	out, err := os.Create("out.png")
	check(err)
	defer out.Close()

	err = png.Encode(out, rgba)
	check(err)
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}

SVG used:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="-5 -5 110 110">
    <path d="
      M 50, 50
	  l 0 -50
    " stroke="teal" fill="none" />
    <path d="
      M 0, 50
      a 50,50 0 1,0 100,0
      a 50,50 0 1,0 -100,0
    " stroke="teal" fill="none" stroke-dasharray="314" stroke-dashoffset="157" />
</svg>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions