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 · 3 comments
Open

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

spacedub opened this issue Oct 14, 2022 · 3 comments
Labels

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")
}

@goccy
Copy link
Owner

goccy commented Oct 23, 2024

@spacedub There is still room for improvement in font selection, but I have adjusted the font size, so I believe this issue is resolved. Could you please confirm?

@goccy goccy added the reviewed label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants