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

Support multi-byte fonts #25

Closed
k1LoW opened this issue Jun 22, 2020 · 5 comments
Closed

Support multi-byte fonts #25

k1LoW opened this issue Jun 22, 2020 · 5 comments

Comments

@k1LoW
Copy link
Contributor

k1LoW commented Jun 22, 2020

Hi @goccy !

This is feature request.

I want to use go-graphviz with multi-byte fonts.

Example DOT and current render results

Example DOT
digraph "blog" {
  // Config
  graph [rankdir=TB, layout=dot, fontname="Arial"];
  node [shape=record, fontsize=14, margin=0.6, fontname="Arial"];
  edge [fontsize=10, labelfloat=false, splines=none, fontname="Arial"];

  // Tables
  "users" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
                 <tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">users</font> <font color="#666666">[BASE TABLE]</font><br /><font color="#333333">ユーザテーブル</font></td></tr>
                 <tr><td port="id" align="left">id <font color="#666666">[int(11)]</font></td></tr>
                 <tr><td port="username" align="left">username <font color="#666666">[varchar(50)]</font></td></tr>
                 <tr><td port="password" align="left">password <font color="#666666">[varchar(50)]</font></td></tr>
                 <tr><td port="email" align="left">email <font color="#666666">[varchar(355)]</font> ex. user@example.com</td></tr>
                 <tr><td port="created" align="left">created <font color="#666666">[timestamp]</font></td></tr>
                 <tr><td port="updated" align="left">updated <font color="#666666">[timestamp]</font></td></tr>
              </table>>];
  "posts" [shape=none, label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="6">
                 <tr><td bgcolor="#EFEFEF"><font face="Arial Bold" point-size="18">posts</font> <font color="#666666">[BASE TABLE]</font><br /><font color="#333333">投稿テーブル</font></td></tr>
                 <tr><td port="id" align="left">id <font color="#666666">[bigint(20)]</font></td></tr>
                 <tr><td port="user_id" align="left">user_id <font color="#666666">[int(11)]</font></td></tr>
                 <tr><td port="title" align="left">title <font color="#666666">[varchar(255)]</font></td></tr>
                 <tr><td port="body" align="left">body <font color="#666666">[text]</font> post body</td></tr>
                 <tr><td port="post_type" align="left">post_type <font color="#666666">[enum(&#39;public&#39;,&#39;private&#39;,&#39;draft&#39;)]</font> public/private/draft</td></tr>
                 <tr><td port="created" align="left">created <font color="#666666">[datetime]</font></td></tr>
                 <tr><td port="updated" align="left">updated <font color="#666666">[datetime]</font></td></tr>
              </table>>];

  // Relations
  "posts":"user_id" -> "users":"id" [dir=back, arrowtail=crow, style ="dashed", taillabel=<<table cellpadding="5" border="0" cellborder="0"><tr><td>ユーザと投稿の関連</td></tr></table>>];
}

Render results

Graphviz 2.44.0 via Homebrew goccy/go-graphviz/cmd/dot
logs dot logs dot2

Best Regards.

@goccy
Copy link
Owner

goccy commented Jun 23, 2020

Thank you for the reporting !!
I will fix it as soon as possible !

@k1LoW
Copy link
Contributor Author

k1LoW commented Jun 23, 2020

THANK YOU!!!! 🤩

@goccy
Copy link
Owner

goccy commented Jun 29, 2020

Currently, multibyte characters can already be used in the following way .

import (
    "github.com/golang/freetype/truetype"
    "golang.org/x/image/font"
)
	ftBinary, _ := ioutil.ReadFile("/path/to/Japanese-Font.ttf")
	ft, _ := truetype.Parse(ftBinary)

	g := graphviz.New()
	g.SetFontFace(func(size float64) (font.Face, error) {
		opt := &truetype.Options{
			Size:              size,
			DPI:               0,
			Hinting:           0,
			GlyphCacheEntries: 0,
			SubPixelsX:        0,
			SubPixelsY:        0,
		}
		return truetype.NewFace(ft, opt), nil
	})

@goccy
Copy link
Owner

goccy commented Jun 29, 2020

On the other hand, I try to set a font.Face from the font name automatically .

@k1LoW
Copy link
Contributor Author

k1LoW commented Jun 29, 2020

Currently, multibyte characters can already be used in the following way .

@goccy Thank you for your support !

On the other hand, I try to set a font.Face from the font name automatically .

I'm looking forward to the automatic font settings !

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

2 participants