rsyntaxtree 0.8.3 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/rsyntaxtree +4 -1
- data/lib/rsyntaxtree/element.rb +3 -3
- data/lib/rsyntaxtree/graph.rb +71 -82
- data/lib/rsyntaxtree/svg_graph.rb +30 -13
- data/lib/rsyntaxtree/tree_graph.rb +25 -15
- data/lib/rsyntaxtree/version.rb +1 -1
- data/lib/rsyntaxtree.rb +20 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1d573e0201c4374f3fc497b12eb34856fcedeb3513b7d17e403c3d85dbb4d1c
|
4
|
+
data.tar.gz: 60b26c37bd71b6f89f6a048a8e594945783d2486def18e4b9b170e89a68bf91c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9bc21b39ead52c96d917d799354b84b1c99c1f9d0a7078611e2213086d31d16c3bbb416ce856c874a0563a018b2df8452da1bdaad056348c86905d7a914a40f
|
7
|
+
data.tar.gz: e44c03daee5602becb706539f4035d8272d6096d1a26a7e79b0b0c0e439e579a24b85d04717bc1794704c19df24f47d0f95b6f2f05c66abe955f568ac52b189c
|
data/bin/rsyntaxtree
CHANGED
@@ -37,6 +37,8 @@ EOS
|
|
37
37
|
:default => "on"
|
38
38
|
opt :autosub, "Put subscript numbers to nodes: on or off",
|
39
39
|
:default => "off"
|
40
|
+
opt :transparent, "Make background transparent: on or off",
|
41
|
+
:default => "off"
|
40
42
|
end
|
41
43
|
|
42
44
|
Optimist::die :outdir, "must be an exsting directory path" unless FileTest::directory?(opts[:outdir])
|
@@ -48,8 +50,9 @@ Optimist::die :fontsize, "must be in the range of 8-26" unless opts[:fontsize] >
|
|
48
50
|
Optimist::die :color, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:color]
|
49
51
|
Optimist::die :symmetrize, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:symmetrize]
|
50
52
|
Optimist::die :autosub, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:autosub]
|
51
|
-
Optimist::die :margin, "must be in the range of
|
53
|
+
Optimist::die :margin, "must be in the range of 0-5" if opts[:margin] < 1 || opts[:margin] > 5
|
52
54
|
Optimist::die :vheight, "must be in the range of 0.5-5.0" if opts[:vheight] < 0.5 || opts[:vheight] > 5.0
|
55
|
+
Optimist::die :transparent, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:transparent]
|
53
56
|
|
54
57
|
string_opts = {}
|
55
58
|
opts.each do |key, value|
|
data/lib/rsyntaxtree/element.rb
CHANGED
@@ -23,12 +23,12 @@ class Element
|
|
23
23
|
@level = level # Element level in the tree (0=top etc...)
|
24
24
|
@width = 0 # Width of the element in pixels
|
25
25
|
@indent = 0 # Drawing offset
|
26
|
-
|
27
|
-
if /\A.+\^\z/ =~ content
|
26
|
+
content = content.strip
|
27
|
+
if /\A.+\^\z/ =~ content
|
28
28
|
@content = content.gsub("^"){""} # The actual element content
|
29
29
|
@triangle = true # draw triangle instead of stright bar when in auto mode
|
30
30
|
else
|
31
|
-
@content = content.gsub("^"){""} # The actual element content
|
31
|
+
@content = content.gsub("^"){""}.strip # The actual element content
|
32
32
|
@triangle = false # draw triangle instead of stright bar when in auto mode
|
33
33
|
end
|
34
34
|
# workaround to save "[A [B [C] [D] ] [E [F] [G [H] [J] ] ] ]"
|
data/lib/rsyntaxtree/graph.rb
CHANGED
@@ -32,8 +32,8 @@ class Graph
|
|
32
32
|
# Calculate image dimensions
|
33
33
|
@e_height = font_size + @m[:e_padd] * 2
|
34
34
|
h = @e_list.get_level_height
|
35
|
-
w
|
36
|
-
@width
|
35
|
+
w = calc_level_width(0)
|
36
|
+
@width = w
|
37
37
|
@height = h * @e_height + (h-1) * (@m[:v_space] + font_size) + @m[:b_topbot] * 2
|
38
38
|
|
39
39
|
# Initialize the image and colors
|
@@ -50,7 +50,7 @@ class Graph
|
|
50
50
|
@col_leaf = "black"
|
51
51
|
@col_trace = "black"
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
@main_height = img_get_txt_height("l", font, font_size)
|
55
55
|
@sub_size = (font_size * SUBSCRIPT_CONST)
|
56
56
|
@sub_space_width = img_get_txt_width("l", font, @sub_size)
|
@@ -58,12 +58,11 @@ class Graph
|
|
58
58
|
|
59
59
|
def img_get_txt_metrics(text, font, font_size, multiline)
|
60
60
|
|
61
|
-
# background = Image.new(500, 250)
|
62
61
|
background = Image.new(1, 1)
|
63
62
|
|
64
63
|
gc = Draw.new
|
65
64
|
gc.annotate(background, 0, 0, 0, 0, text) do |gc|
|
66
|
-
gc.font = font
|
65
|
+
gc.font = font
|
67
66
|
gc.pointsize = font_size
|
68
67
|
gc.gravity = CenterGravity
|
69
68
|
gc.stroke = 'none'
|
@@ -110,9 +109,10 @@ class Graph
|
|
110
109
|
e = @e_list.get_first
|
111
110
|
while e
|
112
111
|
if(e.level == level)
|
113
|
-
|
112
|
+
x = calc_element_width(e)
|
113
|
+
w += x
|
114
114
|
end
|
115
|
-
|
115
|
+
e = @e_list.get_next
|
116
116
|
end
|
117
117
|
return w
|
118
118
|
end
|
@@ -168,127 +168,116 @@ class Graph
|
|
168
168
|
if(j.parent != 0 )
|
169
169
|
words = j.content.split(" ")
|
170
170
|
unless @leafstyle == "nothing" && ETYPE_LEAF == j.type
|
171
|
-
if (@leafstyle == "
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
else
|
179
|
-
line_to_parent(x, i, cw, @e_list.get_indent(j.parent), @e_list.get_element_width(j.parent))
|
180
|
-
end
|
171
|
+
if (@leafstyle == "auto" && ETYPE_LEAF == j.type && x == parent_indent)
|
172
|
+
if words.length > 1 || j.triangle
|
173
|
+
txt_width = img_get_txt_width(j.content, @font, @font_size)
|
174
|
+
triangle_to_parent(x, i, cw, txt_width, @symmetrize)
|
175
|
+
else
|
176
|
+
line_to_parent(x, i, cw, @e_list.get_indent(j.parent), @e_list.get_element_width(j.parent))
|
177
|
+
end
|
181
178
|
else
|
182
179
|
line_to_parent(x, i, cw, @e_list.get_indent(j.parent), @e_list.get_element_width(j.parent))
|
183
180
|
end
|
184
181
|
end
|
185
182
|
end
|
186
183
|
end
|
187
|
-
|
188
184
|
x += cw
|
189
185
|
end
|
190
186
|
end
|
191
187
|
end
|
192
188
|
return true if !@symmetrize
|
189
|
+
|
190
|
+
elements_to_draw = {}
|
191
|
+
triangles_to_draw = []
|
192
|
+
lines_to_draw = []
|
193
193
|
|
194
|
+
lmost = {:level => nil, :value => nil, :type => nil}
|
195
|
+
rmost = nil
|
194
196
|
h.times do |i|
|
195
197
|
curlevel = h - i - 1
|
196
|
-
indent = 0
|
197
198
|
e_arr.each_with_index do |j, idx|
|
198
199
|
if (j.level == curlevel)
|
199
200
|
# Draw a line to the parent element
|
200
201
|
children = @e_list.get_children(j.id)
|
201
202
|
|
202
203
|
tw = img_get_txt_width(j.content, @font, @font_size)
|
203
|
-
if children.length >
|
204
|
+
if children.length > 0
|
204
205
|
left, right = -1, -1
|
205
|
-
children.each do |child|
|
206
|
+
children.each do |child|
|
206
207
|
k = @e_list.get_id(child)
|
207
|
-
kw = img_get_txt_width(k.content, @font, @font_size)
|
208
|
+
kw = img_get_txt_width(k.content, @font, @font_size)
|
208
209
|
left = k.indent + kw / 2 if k.indent + kw / 2 < left or left == -1
|
209
210
|
right = k.indent + kw / 2 if k.indent + kw / 2 > right
|
210
211
|
end
|
211
|
-
|
212
|
+
|
213
|
+
elements_to_draw[j.id] = {:left => left, :curlevel => curlevel, :width => right - left, :content => j.content, :type => j.type}
|
212
214
|
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
213
215
|
|
214
216
|
children.each do |child|
|
215
217
|
k = @e_list.get_id(child)
|
216
218
|
words = k.content.split(" ")
|
217
219
|
dw = img_get_txt_width(k.content, @font, @font_size)
|
220
|
+
|
221
|
+
children2 = @e_list.get_children(k.id)
|
222
|
+
|
218
223
|
unless @leafstyle == "nothing" && ETYPE_LEAF == k.type
|
219
|
-
if (@leafstyle == "
|
220
|
-
txt_width = img_get_txt_width(k.content, @font, @font_size)
|
221
|
-
triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
|
222
|
-
elsif (@leafstyle == "auto" && ETYPE_LEAF == k.type && k.indent == j.indent)
|
224
|
+
if (@leafstyle == "auto" && ETYPE_LEAF == k.type)
|
223
225
|
if words.length > 1 || k.triangle
|
224
226
|
txt_width = img_get_txt_width(k.content, @font, @font_size)
|
225
|
-
|
227
|
+
triangles_to_draw << {:indent => k.indent, :curlevel => curlevel + 1, :width1 => dw, :width2 => txt_width}
|
226
228
|
else
|
227
|
-
|
229
|
+
lines_to_draw << {:indent1 => k.indent, :curlevel => curlevel + 1, :width1 => dw, :indent2 => j.indent, :width2 => tw}
|
228
230
|
end
|
229
231
|
else
|
230
|
-
|
232
|
+
lines_to_draw << {:indent1 => k.indent, :curlevel => curlevel + 1, :width1 => dw, :indent2 => j.indent, :width2 => tw}
|
231
233
|
end
|
232
234
|
end
|
233
235
|
end
|
234
236
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
left = k.indent
|
240
|
-
right = k.indent + kw
|
241
|
-
draw_element(left, curlevel, right - left, j.content, j.type)
|
242
|
-
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
243
|
-
|
244
|
-
k = @e_list.get_id(children[0])
|
245
|
-
words = k.content.split(" ")
|
246
|
-
dw = img_get_txt_width(k.content, @font, @font_size)
|
247
|
-
unless (@leafstyle == "nothing" && ETYPE_LEAF == k.type)
|
248
|
-
if (@leafstyle == "triangle" && ETYPE_LEAF == k.type && words.length > 0)
|
249
|
-
txt_width = img_get_txt_width(k.content, @font, @font_size)
|
250
|
-
triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
|
251
|
-
elsif (@leafstyle == "auto" && ETYPE_LEAF == k.type)
|
252
|
-
if words.length > 1 || k.triangle
|
253
|
-
txt_width = img_get_txt_width(k.content, @font, @font_size)
|
254
|
-
triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
|
255
|
-
else
|
256
|
-
line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
|
257
|
-
end
|
258
|
-
else
|
259
|
-
line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
|
260
|
-
end
|
261
|
-
end
|
237
|
+
end
|
238
|
+
elements = e_arr.select do |l|
|
239
|
+
l.level == curlevel && @e_list.get_children(l.id).empty?
|
240
|
+
end
|
262
241
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
e_arr.select{|l|l.level == curlevel}.each do |l|
|
270
|
-
lw = img_get_txt_width(l.content, @font, @font_size)
|
271
|
-
left = l.indent
|
272
|
-
right = left + lw
|
273
|
-
@e_list.set_indent(l.id, left + (right - left) / 2 - tw / 2)
|
274
|
-
draw_element(left, curlevel, right - left, l.content, l.type)
|
275
|
-
end
|
276
|
-
break
|
277
|
-
else
|
278
|
-
left = j.indent
|
279
|
-
right = left + tw
|
280
|
-
if pw > tw
|
281
|
-
left = pleft
|
282
|
-
right = pright
|
283
|
-
end
|
284
|
-
draw_element(left, curlevel, right - left, j.content, j.type)
|
285
|
-
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
286
|
-
end
|
242
|
+
elements.each.with_index do |l, idx|
|
243
|
+
lw = img_get_txt_width(l.content, @font, @font_size)
|
244
|
+
left = l.indent
|
245
|
+
right = left + lw
|
246
|
+
unless elements_to_draw.include? l.id
|
247
|
+
elements_to_draw[l.id] = {:left => left, :curlevel => curlevel, :width => right - left, :content => l.content, :type => l.type}
|
287
248
|
end
|
288
|
-
|
289
249
|
end
|
290
250
|
end
|
291
251
|
end
|
252
|
+
|
253
|
+
e_arr.each do |e|
|
254
|
+
lpos = e.indent - img_get_txt_width(e.content, @font, @font_size) / 2
|
255
|
+
next if lpos > 0
|
256
|
+
if !lmost[:value] || lmost[:value] > lpos
|
257
|
+
lmost[:level] = e.level
|
258
|
+
lmost[:value] = lpos
|
259
|
+
lmost[:type] = e
|
260
|
+
end
|
261
|
+
rpos = e.indent + e.width
|
262
|
+
rmost = rpos if !rmost || rmost < rpos
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
offset = 0
|
267
|
+
if lmost[:level] != h - 1
|
268
|
+
offset = lmost[:value] / -2
|
269
|
+
new_width = rmost
|
270
|
+
@width = new_width + offset
|
271
|
+
end
|
272
|
+
|
273
|
+
elements_to_draw.each do |k, v|
|
274
|
+
draw_element(v[:left] + offset, v[:curlevel], v[:width], v[:content], v[:type])
|
275
|
+
end
|
276
|
+
triangles_to_draw.each do |v|
|
277
|
+
triangle_to_parent(v[:indent] + offset, v[:curlevel], v[:width1], v[:width2])
|
278
|
+
end
|
279
|
+
lines_to_draw.each do |v|
|
280
|
+
line_to_parent(v[:indent1] + offset, v[:curlevel], v[:width1], v[:indent2] + offset, v[:width2])
|
292
281
|
end
|
293
282
|
end
|
294
283
|
|
@@ -18,17 +18,20 @@ require 'graph'
|
|
18
18
|
|
19
19
|
class SVGGraph < Graph
|
20
20
|
|
21
|
-
def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font, font_cjk, font_size)
|
21
|
+
def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font, font_cjk, font_size, margin, transparent)
|
22
22
|
|
23
23
|
# Store class-specific parameters
|
24
24
|
@font = multibyte ? font_cjk : font
|
25
25
|
@font_size = font_size
|
26
|
+
@transparent = transparent
|
27
|
+
|
26
28
|
case fontstyle
|
27
29
|
when /(?:sans|cjk)/
|
28
30
|
@fontstyle = "sans-serif"
|
29
31
|
when /(?:serif|math)/
|
30
32
|
@fontstyle = "serif"
|
31
33
|
end
|
34
|
+
@margin = margin.to_i
|
32
35
|
|
33
36
|
super(e_list, metrics, symmetrize, color, leafstyle, multibyte, @font, @font_size)
|
34
37
|
|
@@ -38,17 +41,35 @@ class SVGGraph < Graph
|
|
38
41
|
@tree_data = String.new
|
39
42
|
end
|
40
43
|
|
44
|
+
def get_left_most(tree_data)
|
45
|
+
xs = @tree_data.scan(/x1?=['"]([^'"]+)['"]/).map{|m| m.first.to_i}
|
46
|
+
xs.min
|
47
|
+
end
|
48
|
+
|
41
49
|
def svg_data
|
42
50
|
parse_list
|
51
|
+
lm = get_left_most(@tree_data)
|
52
|
+
width = @width - lm + @margin * 2
|
53
|
+
height = @height + @margin * 2
|
54
|
+
|
43
55
|
header =<<EOD
|
44
56
|
<?xml version="1.0" standalone="no"?>
|
45
57
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
46
58
|
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
47
|
-
<svg width="#{
|
59
|
+
<svg width="#{width}" height="#{height}" viewBox="#{-@margin + lm}, -#{@margin}, #{@width - lm + @margin * 2}, #{@height + @margin * 2}" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
60
|
+
EOD
|
61
|
+
|
62
|
+
rect =<<EOD
|
63
|
+
<rect x="#{-@margin + lm}" y="-#{@margin}" width="#{@width - lm + @margin * 2}" height="#{@height + @margin * 2}" stroke="none" fill="white" />"
|
48
64
|
EOD
|
49
65
|
|
50
66
|
footer = "</svg>"
|
51
|
-
|
67
|
+
|
68
|
+
if @transparent
|
69
|
+
header + @tree_data + footer
|
70
|
+
else
|
71
|
+
header + rect + @tree_data + footer
|
72
|
+
end
|
52
73
|
end
|
53
74
|
|
54
75
|
# Create a temporary file and returns only its filename
|
@@ -99,6 +120,9 @@ EOD
|
|
99
120
|
elsif /\A\-(.+)\-\z/ =~ main
|
100
121
|
main = $1
|
101
122
|
main_decoration= "underline"
|
123
|
+
elsif /\A\~(.+)\~\z/ =~ main
|
124
|
+
main = $1
|
125
|
+
main_decoration= "line-through"
|
102
126
|
else
|
103
127
|
main_decoration= ""
|
104
128
|
end
|
@@ -137,6 +161,9 @@ EOD
|
|
137
161
|
elsif /\A\-(.+)\-\z/ =~ sub
|
138
162
|
sub = $1
|
139
163
|
sub_decoration= "underline"
|
164
|
+
elsif /\A\~(.+)\~\z/ =~ sub
|
165
|
+
sub = $1
|
166
|
+
sub_decoration= "line-through"
|
140
167
|
else
|
141
168
|
sub_decoration= ""
|
142
169
|
end
|
@@ -281,19 +308,9 @@ EOD
|
|
281
308
|
main_before = parts[0].strip
|
282
309
|
sub = parts[1]
|
283
310
|
main = get_txt_only(main_before)
|
284
|
-
if(main.contains_cjk?)
|
285
|
-
main = 'n' * main.strip.size * 2
|
286
|
-
else
|
287
|
-
main
|
288
|
-
end
|
289
311
|
main_metrics = img_get_txt_metrics(main, font, font_size, multiline)
|
290
312
|
width = main_metrics.width
|
291
313
|
if sub
|
292
|
-
if(sub.contains_cjk?)
|
293
|
-
sub = 'n' * sub.strip.size * 2
|
294
|
-
else
|
295
|
-
sub
|
296
|
-
end
|
297
314
|
sub_metrics = img_get_txt_metrics(sub, font, font_size * SUBSCRIPT_CONST, multiline)
|
298
315
|
width += sub_metrics.width
|
299
316
|
end
|
@@ -21,24 +21,23 @@ class TreeGraph < Graph
|
|
21
21
|
|
22
22
|
def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte,
|
23
23
|
fontstyle, font, font_it, font_bd, font_itbd, font_math, font_cjk, font_size,
|
24
|
-
margin)
|
24
|
+
margin, transparent)
|
25
25
|
|
26
26
|
# Store class-specific parameters
|
27
|
-
@fontstyle
|
28
|
-
@font
|
29
|
-
@font_size
|
30
|
-
@font_it
|
31
|
-
@font_bd
|
32
|
-
@font_itbd
|
33
|
-
@font_math
|
34
|
-
@font_cjk
|
35
|
-
@margin
|
27
|
+
@fontstyle = fontstyle
|
28
|
+
@font = multibyte ? font_cjk : font
|
29
|
+
@font_size = font_size
|
30
|
+
@font_it = font_it
|
31
|
+
@font_bd = font_bd
|
32
|
+
@font_itbd = font_itbd
|
33
|
+
@font_math = font_math
|
34
|
+
@font_cjk = font_cjk
|
35
|
+
@margin = margin
|
36
|
+
@transparent = transparent
|
36
37
|
|
37
38
|
super(e_list, metrics, symmetrize, color, leafstyle, multibyte, @font, @font_size)
|
38
39
|
|
39
40
|
# Initialize the image and colors
|
40
|
-
@im = Image.new(@width, @height)
|
41
|
-
@im.interlace = PlaneInterlace
|
42
41
|
@gc = Draw.new
|
43
42
|
@gc.font = @font
|
44
43
|
@gc.pointsize(@font_size)
|
@@ -50,6 +49,11 @@ class TreeGraph < Graph
|
|
50
49
|
|
51
50
|
def draw
|
52
51
|
parse_list
|
52
|
+
@im = Image.new(@width, @height)
|
53
|
+
if @transparent
|
54
|
+
@im.matte_reset!
|
55
|
+
end
|
56
|
+
@im.interlace = PlaneInterlace
|
53
57
|
@gc.draw(@im)
|
54
58
|
end
|
55
59
|
|
@@ -62,7 +66,12 @@ class TreeGraph < Graph
|
|
62
66
|
# by Geoffrey Grosenbach
|
63
67
|
def to_blob(fileformat='PNG')
|
64
68
|
draw
|
65
|
-
@im.
|
69
|
+
@im.trim!
|
70
|
+
if @transparent
|
71
|
+
@im.border!(@margin, @margin, "transparent")
|
72
|
+
else
|
73
|
+
@im.border!(@margin, @margin, "white")
|
74
|
+
end
|
66
75
|
@im.format = fileformat
|
67
76
|
@im.interlace = PlaneInterlace
|
68
77
|
return @im.to_blob
|
@@ -72,6 +81,7 @@ class TreeGraph < Graph
|
|
72
81
|
|
73
82
|
# Add the element into the tree (draw it)
|
74
83
|
def draw_element(x, y, w, string, type)
|
84
|
+
numlines = string.count("\n")
|
75
85
|
string = string.sub(/\^\z/){""}
|
76
86
|
# Calculate element dimensions and position
|
77
87
|
if (type == ETYPE_LEAF) and @leafstyle == "nothing"
|
@@ -80,7 +90,7 @@ class TreeGraph < Graph
|
|
80
90
|
top = row2px(y)
|
81
91
|
end
|
82
92
|
left = x + @m[:b_side]
|
83
|
-
bottom = top + @e_height
|
93
|
+
bottom = top + @e_height * numlines
|
84
94
|
right = left + w
|
85
95
|
|
86
96
|
# Split the string into the main part and the
|
@@ -283,7 +293,7 @@ class TreeGraph < Graph
|
|
283
293
|
end
|
284
294
|
end
|
285
295
|
|
286
|
-
def img_get_txt_width(text, font, font_size, multiline =
|
296
|
+
def img_get_txt_width(text, font, font_size, multiline = true)
|
287
297
|
parts = text.split("_", 2)
|
288
298
|
main_before = parts[0].strip
|
289
299
|
sub = parts[1]
|
data/lib/rsyntaxtree/version.rb
CHANGED
data/lib/rsyntaxtree.rb
CHANGED
@@ -49,7 +49,7 @@ class RSGenerator
|
|
49
49
|
.gsub('-CABRACKET-', '>')
|
50
50
|
new_params[key] = data
|
51
51
|
new_params[:multibyte] = data.contains_cjk?
|
52
|
-
when :symmetrize, :color, :autosub
|
52
|
+
when :symmetrize, :color, :autosub, :transparent
|
53
53
|
new_params[key] = value && value != "off" ? true : false
|
54
54
|
when :fontsize
|
55
55
|
new_params[key] = value.to_i * FONT_SCALING
|
@@ -98,22 +98,23 @@ class RSGenerator
|
|
98
98
|
|
99
99
|
# defaults to the following
|
100
100
|
@params = {
|
101
|
-
:symmetrize
|
102
|
-
:color
|
103
|
-
:autosub
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
112
|
-
:
|
113
|
-
:
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
101
|
+
:symmetrize => true,
|
102
|
+
:color => true,
|
103
|
+
:autosub => false,
|
104
|
+
:transparent => false,
|
105
|
+
:fontsize => 18,
|
106
|
+
:format => "png",
|
107
|
+
:leafstyle => "auto",
|
108
|
+
:filename => "syntree",
|
109
|
+
:data => "",
|
110
|
+
:margin => 0,
|
111
|
+
:vheight => 1.0,
|
112
|
+
:fontstyle => "sans",
|
113
|
+
:font => "/NotoSansCJKjp-Regular.otf",
|
114
|
+
:font_it => "/NotoSans-Italic.ttf",
|
115
|
+
:font_bd => "/NotoSans-Bold.ttf",
|
116
|
+
:font_bdit => "/NotoSans-BoldItalic.ttf",
|
117
|
+
:font_math => "/NotoSansMath-Regular.ttf"
|
117
118
|
}
|
118
119
|
@metrics = {
|
119
120
|
:e_width => 120,
|
@@ -163,7 +164,7 @@ class RSGenerator
|
|
163
164
|
elist = sp.get_elementlist
|
164
165
|
graph = SVGGraph.new(elist, @metrics,
|
165
166
|
@params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
|
166
|
-
@params[:fontstyle], @params[:font], @params[:font_cjk], @params[:fontsize],
|
167
|
+
@params[:fontstyle], @params[:font], @params[:font_cjk], @params[:fontsize], @params[:margin], @params[:transparent]
|
167
168
|
)
|
168
169
|
graph.svg_data
|
169
170
|
end
|
@@ -176,7 +177,7 @@ class RSGenerator
|
|
176
177
|
graph = TreeGraph.new(elist, @metrics,
|
177
178
|
@params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
|
178
179
|
@params[:fontstyle], @params[:font], @params[:font_it], @params[:font_bd], @params[:font_bdit], @params[:font_math],
|
179
|
-
@params[:font_cjk], @params[:fontsize], @params[:margin],
|
180
|
+
@params[:font_cjk], @params[:fontsize], @params[:margin], @params[:transparent]
|
180
181
|
)
|
181
182
|
graph.to_blob(@params[:format])
|
182
183
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsyntaxtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoichiro Hasebe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|