18
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Graphvizのコマンドで日本語が文字化けして困った(windows10)

Last updated at Posted at 2019-01-16

はじめに

VSCodeのプレビューでは文字化けしてないのに、コマンドラインで画像を作成したら文字化けしてて困ってしまいました
その時のメモです

環境

OS windows10(64ビット)
dot - graphviz version 2.38.0 (20140413.2041)

結論

2つのどちらか

  1. コマンドのオプションをつける
dot -Kdot -Tjpg -Nfontname="MS Gothic" -Efontname="MS Gothic" -Gfontname="MS Gothic" src_filename.dot -o out_filename.jpg

  1. dotファイルに記述する
digraph jennica_chart {
    //一番上のあたりに全体設定
    graph [fontname = "MS Gothic"];
    node [fontname = "MS Gothic"];
    edge [fontname = "MS Gothic"];

    ・・・
}

どちらもnodeとedgeとgraphそれぞれに指定が必要です
どちらを選ぶかは趣味ですね
※私は最終的に「2. dotファイルに記述する」を選びました

過程

とりあえずヘルプを見ます

>dot -h
Error: dot: option -h unrecognized

Usage: dot [-Vv?] [-(GNE)name=val] [-(KTlso)<val>] <dot files>
(additional options for neato)    [-x] [-n<v>]
(additional options for fdp)      [-L(gO)] [-L(nUCT)<val>]
(additional options for memtest)  [-m<v>]
(additional options for config)  [-cv]

 -V          - Print version and exit
 -v          - Enable verbose mode
 -Gname=val  - Set graph attribute 'name' to 'val'
 -Nname=val  - Set node attribute 'name' to 'val'
 -Ename=val  - Set edge attribute 'name' to 'val'
 -Tv         - Set output format to 'v'
 -Kv         - Set layout engine to 'v' (overrides default based on command name)
 -lv         - Use external library 'v'
 -ofile      - Write output to 'file'
 -O          - Automatically generate an output filename based on the input filename with a .'format' appended. (Causes all -ofile options to be ignored.)
 -P          - Internally generate a graph of the current plugins.
 -q[l]       - Set level of message suppression (=1)
 -s[v]       - Scale input by 'v' (=72)
 -y          - Invert y coordinate in output

 -n[v]       - No layout mode 'v' (=1)
 -x          - Reduce graph

 -Lg         - Don't use grid
 -LO         - Use old attractive force
 -Ln<i>      - Set number of iterations to i
 -LU<i>      - Set unscaled factor to i
 -LC<v>      - Set overlap expansion factor to v
 -LT[*]<v>   - Set temperature (temperature factor) to v

 -m          - Memory test (Observe no growth with top. Kill when done.)
 -m[v]       - Memory test - v iterations.

 -c          - Configure plugins (Writes $prefix/lib/graphviz/config
               with available plugin information.  Needs write privilege.)
 -?          - Print usage and exit

-hオプションじゃなくて、-?なんですね

使うのはここ

 -Gname=val  - Set graph attribute 'name' to 'val'
 -Nname=val  - Set node attribute 'name' to 'val'
 -Ename=val  - Set edge attribute 'name' to 'val'

atrributeの頭に-N,-E,-Gをつけてname=valするだけでした

使えたフォントの種類

参考
Windows 10 font list
Japanese Supplemental Fonts
https://docs.microsoft.com/ja-jp/typography/fonts/windows_10_font_list#japanese-supplemental-fonts

BIZ UDGothic
BIZ UDGothic Bold
BIZ UDPGothic
BIZ UDPGothic Bold
BIZ UDMincho Medium
BIZ UDPMincho Medium
Meiryo
Meiryo Italic
Meiryo Bold
Meiryo Bold Italic
Meiryo UI
Meiryo UI Italic
Meiryo UI Bold
Meiryo UI Bold Italic
MS Gothic
MS PGothic
MS UI Gothic
MS Mincho
MS PMincho
Yu Mincho Light
Yu Mincho Regular
Yu Mincho Demibold

フォントによってレイアウトがかわったのは意外でした
(最終的にMeiryo UIにしました)

あとは個人の環境で利用しているフォントによります

おわりに

フォントの名前の指定で困りました

graph [fontname = "MS Pゴシック"];

上記を指定しても、Excel見てフォントコピペしたけどエラーで動かないんですね

18
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?