53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/rsyntaxtree.rb', line 53
def initialize(params = {})
new_params = {}
fontset = {}
params.each do |keystr, value|
key = keystr.to_sym
case key
when :data
data = value
data = data.gsub('-AMP-', '&')
.gsub('-PERCENT-', "%")
.gsub('-PRIME-', "'")
.gsub('-SCOLON-', ';')
.gsub('-OABRACKET-', '<')
.gsub('-CABRACKET-', '>')
.gsub('¥¥', '\¥')
.gsub(/(?<!\\)¥/, "\\")
new_params[key] = data
when :symmetrize, :transparent, :polyline, :hide_default_connectors
new_params[key] = value && (value != "off" && value != "false") ? true : false
when :color
new_params[key] = case value
when "modern", "on", "true"
"modern"
when "traditional"
"traditional"
else
"off"
end
when :fontsize
new_params[key] = value.to_i
when :linewidth
new_params[key] = value.to_i
when :vheight
new_params[key] = value.to_f
when :fontstyle
case value
when "noto-sans-mono", "mono"
fontset[:normal] = FONT_DIR + "/NotoSansMono_SemiCondensed-Regular.ttf"
fontset[:italic] = FONT_DIR + "/NotoSansMono_SemiCondensed-Regular.ttf"
fontset[:bold] = FONT_DIR + "/NotoSansMono_SemiCondensed-Bold.ttf"
fontset[:bolditalic] = FONT_DIR + "/NotoSansMono_SemiCondensed-Bold.ttf"
fontset[:math] = FONT_DIR + "/latinmodern-math.otf"
fontset[:cjk] = FONT_DIR + "/NotoSansJP-Regular.otf"
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
new_params[:fontstyle] = "mono"
when "noto-sans", "sans"
fontset[:normal] = FONT_DIR + "/NotoSans-Regular.ttf"
fontset[:italic] = FONT_DIR + "/NotoSans-Italic.ttf"
fontset[:bold] = FONT_DIR + "/NotoSans-Bold.ttf"
fontset[:bolditalic] = FONT_DIR + "/NotoSans-BoldItalic.ttf"
fontset[:math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
fontset[:cjk] = FONT_DIR + "/NotoSansJP-Regular.otf"
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
new_params[:fontstyle] = "sans"
when "noto-serif", "serif"
fontset[:normal] = FONT_DIR + "/NotoSerif-Regular.ttf"
fontset[:italic] = FONT_DIR + "/NotoSerif-Italic.ttf"
fontset[:bold] = FONT_DIR + "/NotoSerif-Bold.ttf"
fontset[:bolditalic] = FONT_DIR + "/NotoSerif-BoldItalic.ttf"
fontset[:math] = FONT_DIR + "/latinmodern-math.otf"
fontset[:cjk] = FONT_DIR + "/NotoSerifJP-Regular.otf"
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
new_params[:fontstyle] = "serif"
when "cjk zenhei", "cjk"
fontset[:normal] = FONT_DIR + "/wqy-zenhei.ttf"
fontset[:italic] = FONT_DIR + "/NotoSans-Italic.ttf"
fontset[:bold] = FONT_DIR + "/NotoSans-Bold.ttf"
fontset[:bolditalic] = FONT_DIR + "/NotoSans-BoldItalic.ttf"
fontset[:math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
fontset[:cjk] = FONT_DIR + "/wqy-zenhei.ttf"
fontset[:emoji] = FONT_DIR + "/OpenMoji-black-glyf.ttf"
new_params[:fontstyle] = "cjk"
end
else
new_params[key] = value
end
end
@params = DEFAULT_OPTS.dup
@params.merge! new_params
@params[:fontsize] = @params[:fontsize] * FONT_SCALING
@params[:fontset] = fontset
single_x_metrics = FontMetrics.get_metrics("X", fontset[:normal], @params[:fontsize], :normal, :normal)
@global = {}
@global[:single_x_metrics] = single_x_metrics
@global[:height_connector_to_text] = single_x_metrics.height / 2.0
@global[:single_line_height] = single_x_metrics.height * 2.0
@global[:width_half_x] = single_x_metrics.width / 2.0
@global[:height_connector] = single_x_metrics.height * @params[:vheight]
@global[:h_gap_between_nodes] = single_x_metrics.width * 0.8
@global[:box_vertical_margin] = single_x_metrics.height * 0.8
end
|