rsyntaxtree 0.8.5 → 0.8.6
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/lib/rsyntaxtree/element.rb +2 -2
- data/lib/rsyntaxtree/graph.rb +57 -42
- data/lib/rsyntaxtree/svg_graph.rb +10 -10
- data/lib/rsyntaxtree/tree_graph.rb +3 -2
- data/lib/rsyntaxtree/version.rb +1 -1
- 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: b25b4f9bf189bb33a19980c2cd6247a93ae2dd14df820eaa9e991425fa56b0dd
|
4
|
+
data.tar.gz: '0646683a124670135b38f5d93667cac8140a96d74c352d6bb28483cec93e3ee8'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dc8fdc7c0b9c4181ed50372eeebc41d75bccaf4c81db63a79da218918c0c71d70fd0fa9e6df9e8f6e46d52c4153b0934577a76fbdc03d90e23d28bda6a37811
|
7
|
+
data.tar.gz: c65b56bef0deb983be7cd81e914834de1536c07633c3709a642eedf2d3b461344d4a2ddfc0beae0f85ac0a954cf895472459919b2cf317ea2f26b633309a1f1a
|
data/lib/rsyntaxtree/element.rb
CHANGED
@@ -25,10 +25,10 @@ class Element
|
|
25
25
|
@indent = 0 # Drawing offset
|
26
26
|
# content = content.strip
|
27
27
|
if /\A.+\^\z/ =~ content.strip
|
28
|
-
@content = content.gsub("^"){""} # The actual element content
|
28
|
+
@content = content.gsub("^"){""}.strip # 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
|
@@ -58,7 +58,6 @@ 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
|
@@ -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,30 +168,31 @@ 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
|
-
|
194
|
+
lmost = {:level => nil, :value => nil, :type => nil}
|
195
|
+
rmost = nil
|
195
196
|
h.times do |i|
|
196
197
|
curlevel = h - i - 1
|
197
198
|
e_arr.each_with_index do |j, idx|
|
@@ -209,7 +210,7 @@ class Graph
|
|
209
210
|
right = k.indent + kw / 2 if k.indent + kw / 2 > right
|
210
211
|
end
|
211
212
|
|
212
|
-
|
213
|
+
elements_to_draw[j.id] = {:left => left, :curlevel => curlevel, :width => right - left, :content => j.content, :type => j.type}
|
213
214
|
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
214
215
|
|
215
216
|
children.each do |child|
|
@@ -223,12 +224,12 @@ class Graph
|
|
223
224
|
if (@leafstyle == "auto" && ETYPE_LEAF == k.type)
|
224
225
|
if words.length > 1 || k.triangle
|
225
226
|
txt_width = img_get_txt_width(k.content, @font, @font_size)
|
226
|
-
|
227
|
+
triangles_to_draw << {:indent => k.indent, :curlevel => curlevel + 1, :width1 => dw, :width2 => txt_width}
|
227
228
|
else
|
228
|
-
|
229
|
+
lines_to_draw << {:indent1 => k.indent, :curlevel => curlevel + 1, :width1 => dw, :indent2 => j.indent, :width2 => tw}
|
229
230
|
end
|
230
231
|
else
|
231
|
-
|
232
|
+
lines_to_draw << {:indent1 => k.indent, :curlevel => curlevel + 1, :width1 => dw, :indent2 => j.indent, :width2 => tw}
|
232
233
|
end
|
233
234
|
end
|
234
235
|
end
|
@@ -237,32 +238,46 @@ class Graph
|
|
237
238
|
elements = e_arr.select do |l|
|
238
239
|
l.level == curlevel && @e_list.get_children(l.id).empty?
|
239
240
|
end
|
240
|
-
|
241
|
+
|
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}
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
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
|
241
260
|
end
|
261
|
+
rpos = e.indent + e.width
|
262
|
+
rmost = rpos if !rmost || rmost < rpos
|
242
263
|
end
|
243
264
|
end
|
244
|
-
end
|
245
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
|
246
272
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
lw = img_get_txt_width(l.content, @font, @font_size)
|
256
|
-
left = l.indent
|
257
|
-
right = left + lw
|
258
|
-
# if pw > tw
|
259
|
-
# left = pleft
|
260
|
-
# right = pright
|
261
|
-
# end
|
262
|
-
unless @check.include? l.id
|
263
|
-
draw_element(left, curlevel, right - left, l.content, l.type)
|
264
|
-
@check << l.id
|
265
|
-
end
|
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])
|
266
281
|
end
|
267
282
|
end
|
268
283
|
|
@@ -287,19 +287,19 @@ EOD
|
|
287
287
|
main_before = parts[0].strip
|
288
288
|
sub = parts[1]
|
289
289
|
main = get_txt_only(main_before)
|
290
|
-
if(main.contains_cjk?)
|
291
|
-
|
292
|
-
else
|
293
|
-
main
|
294
|
-
end
|
290
|
+
# if(main.contains_cjk?)
|
291
|
+
# main = 'n' * main.strip.size * 2
|
292
|
+
# else
|
293
|
+
# main
|
294
|
+
# end
|
295
295
|
main_metrics = img_get_txt_metrics(main, font, font_size, multiline)
|
296
296
|
width = main_metrics.width
|
297
297
|
if sub
|
298
|
-
if(sub.contains_cjk?)
|
299
|
-
|
300
|
-
else
|
301
|
-
|
302
|
-
end
|
298
|
+
# if(sub.contains_cjk?)
|
299
|
+
# sub = 'n' * sub.strip.size * 2
|
300
|
+
# else
|
301
|
+
# sub
|
302
|
+
# end
|
303
303
|
sub_metrics = img_get_txt_metrics(sub, font, font_size * SUBSCRIPT_CONST, multiline)
|
304
304
|
width += sub_metrics.width
|
305
305
|
end
|
@@ -37,8 +37,6 @@ class TreeGraph < Graph
|
|
37
37
|
super(e_list, metrics, symmetrize, color, leafstyle, multibyte, @font, @font_size)
|
38
38
|
|
39
39
|
# Initialize the image and colors
|
40
|
-
@im = Image.new(@width, @height)
|
41
|
-
@im.interlace = PlaneInterlace
|
42
40
|
@gc = Draw.new
|
43
41
|
@gc.font = @font
|
44
42
|
@gc.pointsize(@font_size)
|
@@ -50,6 +48,8 @@ class TreeGraph < Graph
|
|
50
48
|
|
51
49
|
def draw
|
52
50
|
parse_list
|
51
|
+
@im = Image.new(@width, @height)
|
52
|
+
@im.interlace = PlaneInterlace
|
53
53
|
@gc.draw(@im)
|
54
54
|
end
|
55
55
|
|
@@ -62,6 +62,7 @@ class TreeGraph < Graph
|
|
62
62
|
# by Geoffrey Grosenbach
|
63
63
|
def to_blob(fileformat='PNG')
|
64
64
|
draw
|
65
|
+
@im.trim!
|
65
66
|
@im.border!(@margin, @margin, "white")
|
66
67
|
@im.format = fileformat
|
67
68
|
@im.interlace = PlaneInterlace
|
data/lib/rsyntaxtree/version.rb
CHANGED
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.6
|
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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|