Skip to content

SVG Text Path is mirrored in output #319

@ss32

Description

@ss32

I am rendering a font to an SVG path and was very happy to find this package, but when I render the image the words are mirrored about the x axis. Is there an option I have missed?

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/tdewolff/canvas"
	"github.com/tdewolff/canvas/text"
)

func main() {
	fontFamily := canvas.NewFontFamily("Tangerine")
	if err := fontFamily.LoadFontFile("Tangerine-Regular.ttf", canvas.FontRegular); err != nil {
		panic(err)
	}

	face := fontFamily.Face(300.0, canvas.Black, canvas.FontRegular, canvas.FontNormal)
	//face.Direction = text.LeftToRight  // I tried all of these but nothing corrected it.
	path, _, err := face.ToPath("Verb")
	if err != nil {
		panic(err)
	}
	//newPath, _, err := face.ToPath("me to svg path") // Trying to add a new line
	//if err != nil {
	//	panic(err)
	//}
	//path = path.Append(newPath)

	tpl := `<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" height="400" width="800">
    <path d="%s" />
</svg>`
	//fmt.Printf(tpl, path.ToSVG())
	file, err := os.Create("output.svg")
	if err != nil {
		log.Fatalf("failed creating file: %s", err)
	}
	defer file.Close()
	_, err = file.WriteString(fmt.Sprintf(tpl, path.ToSVG()))
	if err != nil {
		log.Fatalf("failed writing to file: %s", err)
	}
}

output

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