Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PNG renderer default font selection on macOS is worse than dot #63

Open
spacedub opened this issue Oct 14, 2022 · 2 comments
Open

PNG renderer default font selection on macOS is worse than dot #63

spacedub opened this issue Oct 14, 2022 · 2 comments

Comments

@spacedub
Copy link

When rendering with dot -Tpng, you get a result using Times,serif on my system.

When rendering with go-graphviz to SVG, you also get the same font.

But when rendering with go-graphviz to PNG, you end-up with a sans font that does looks quirky - specifically, it does overflow from the shape.

Am I missing something that would allow to get a consistent behavior here?

Though, I would expect by default that go-graphviz PNG renderer behaves the same as the SVG renderer, and the same as the default dot png output.

Might be related to #25

Attaching screenshots.

Thanks!

dot_render
gograph_render

@spacedub spacedub changed the title PNG renderer font selection on macOS is worse than dot PNG renderer default font selection on macOS is worse than dot Oct 14, 2022
@spacedub
Copy link
Author

Thought I would just add that when manually specifying the font to Times New Roman, you do get the expected results with go-graphviz renderer.

@spacedub
Copy link
Author

spacedub commented Oct 14, 2022

Here is a workaround in case others want an escape hatch, in case the default stays the same.
This relies on "github.com/flopp/go-findfont"

func useSystemFont(g *graphviz.Graphviz, name string) {
	fontPath, err := findfont.Find(name)
	if err != nil {
		panic(err)
	}

	fontData, err := os.ReadFile(fontPath)
	if err != nil {
		panic(err)
	}
	ft, err := truetype.Parse(fontData)
	if err != nil {
		panic(err)
	}
	g.SetFontFace(func(size float64) (font.Face, error) {
		opt := &truetype.Options{
			Size:              size,
		}
		return truetype.NewFace(ft, opt), nil
	})
}

func main(){
	g := graphviz.New()
	graph, err := g.Graph()
	if err != nil {
		log.Fatal().Err(err)
	}
	defer func() {
		if err := graph.Close(); err != nil {
			log.Fatal().Err(err)
		}
		_ = g.Close()
	}()

	useSystemFont(g, "Times New Roman.ttf")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant