rsyntaxtree 0.8.8 → 1.0.1

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.
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.8
4
+ version: 1.0.1
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-04 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -50,6 +50,34 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 3.0.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: parslet
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rsvg2
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
53
81
  description: Yet another syntax tree generator made with Ruby and RMagick
54
82
  email:
55
83
  - yohasebe@gmail.com
@@ -59,6 +87,7 @@ extensions: []
59
87
  extra_rdoc_files: []
60
88
  files:
61
89
  - ".gitignore"
90
+ - ".tags"
62
91
  - Gemfile
63
92
  - README.md
64
93
  - Rakefile
@@ -67,30 +96,29 @@ files:
67
96
  - fonts/NotoSans-BoldItalic.ttf
68
97
  - fonts/NotoSans-Italic.ttf
69
98
  - fonts/NotoSans-Regular.ttf
70
- - fonts/NotoSansCJKjp-Regular.otf
99
+ - fonts/NotoSansJP-Bold.otf
100
+ - fonts/NotoSansJP-Regular.otf
71
101
  - fonts/NotoSansMath-Regular.ttf
72
102
  - fonts/NotoSerif-Bold.ttf
73
103
  - fonts/NotoSerif-BoldItalic.ttf
74
104
  - fonts/NotoSerif-Italic.ttf
75
105
  - fonts/NotoSerif-Regular.ttf
76
- - fonts/NotoSerifCJKjp-Regular.otf
77
- - fonts/latinmodern-math.otf
78
- - fonts/lmroman10-bold.otf
79
- - fonts/lmroman10-bolditalic.otf
80
- - fonts/lmroman10-italic.otf
81
- - fonts/lmroman10-regular.otf
106
+ - fonts/NotoSerifJP-Bold.otf
107
+ - fonts/NotoSerifJP-Regular.otf
108
+ - fonts/OpenMoji-Black.ttf
109
+ - fonts/OpenMoji-Color.ttf
82
110
  - fonts/wqy-zenhei.ttf
83
111
  - lib/rsyntaxtree.rb
112
+ - lib/rsyntaxtree/base_graph.rb
84
113
  - lib/rsyntaxtree/element.rb
85
114
  - lib/rsyntaxtree/elementlist.rb
86
- - lib/rsyntaxtree/error_message.rb
87
- - lib/rsyntaxtree/graph.rb
115
+ - lib/rsyntaxtree/markup_parser.rb
88
116
  - lib/rsyntaxtree/string_parser.rb
89
117
  - lib/rsyntaxtree/svg_graph.rb
90
- - lib/rsyntaxtree/tree_graph.rb
91
118
  - lib/rsyntaxtree/utils.rb
92
119
  - lib/rsyntaxtree/version.rb
93
120
  - rsyntaxtree.gemspec
121
+ - test/markup_parser_test.rb
94
122
  homepage: http://github.com/yohasebe/rsyntaxtree
95
123
  licenses:
96
124
  - MIT
@@ -110,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
138
  - !ruby/object:Gem::Version
111
139
  version: '0'
112
140
  requirements: []
113
- rubygems_version: 3.2.32
141
+ rubygems_version: 3.3.3
114
142
  signing_key:
115
143
  specification_version: 4
116
144
  summary: RSyntaxTree is a graphical syntax tree generator written in Ruby
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
-
4
- #==========================
5
- # error_message.rb
6
- #==========================
7
- #
8
- # Takes an error message and drow an image file of the very message
9
- #
10
- # This file is part of RSyntaxTree, which is a ruby port of Andre Eisenbach's
11
- # excellent program phpSyntaxTree.
12
- #
13
- # Copyright (c) 2007-2021 Yoichiro Hasebe <yohasebe@gmail.com>
14
- # Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
15
-
16
- class ErrorMessage
17
-
18
- def initialize(text, font, font_size, filename, format)
19
-
20
- @text = text
21
- @font = font
22
- @font_size = font_size
23
- @filename = filename
24
- @format = format
25
-
26
- metrics = img_get_txt_metrics(text, font, font_size, true)
27
-
28
- @im = Image.new(metrics.width, metrics.height)
29
- @gc = Draw.new
30
- @gc.font = font
31
- @gc.pointsize = font_size
32
- @gc.stroke("transparent")
33
- @gc.fill("black")
34
- @gc.gravity(CenterGravity)
35
- @gc.text(0, 0, text)
36
- end
37
-
38
- def img_get_txt_metrics(text, font, font_size, multiline)
39
-
40
- background = Image.new(500, 250)
41
-
42
- gc = Draw.new
43
- gc.annotate(background, 0, 0, 0, 0, text) do |gc|
44
- gc.font = font
45
- gc.pointsize = font_size
46
- gc.gravity = CenterGravity
47
- gc.stroke = 'none'
48
- end
49
-
50
- if multiline
51
- metrics = gc.get_multiline_type_metrics(background, text)
52
- else
53
- metrics = gc.get_type_metrics(background, text)
54
- end
55
-
56
- return metrics
57
- end
58
-
59
- def draw
60
- @gc.draw(@im)
61
- end
62
-
63
- def save
64
- @gc.draw(@im)
65
- @im.write(@filename + "." + @format)
66
- end
67
-
68
- end
@@ -1,307 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
-
4
- #==========================
5
- # graph.rb
6
- #==========================
7
- #
8
- # Image utility functions to inspect text font metrics
9
- #
10
- # This file is part of RSyntaxTree, which is a ruby port of Andre Eisenbach's
11
- # excellent program phpSyntaxTree.
12
- #
13
- # Copyright (c) 2007-2021 Yoichiro Hasebe <yohasebe@gmail.com>
14
- # Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
15
-
16
- require 'rmagick'
17
- include Magick
18
-
19
- class Graph
20
-
21
- def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, font, font_size)
22
-
23
- # Set class-specific parameters beforehand in subclass
24
-
25
- # Store parameters
26
- @e_list = e_list
27
- @m = metrics
28
- @multibyte = multibyte
29
- @leafstyle = leafstyle
30
- @symmetrize = symmetrize
31
-
32
- # Calculate image dimensions
33
- @e_height = font_size + @m[:e_padd] * 2
34
- h = @e_list.get_level_height
35
- w = calc_level_width(0)
36
- @width = w
37
- @height = h * @e_height + (h-1) * (@m[:v_space] + font_size) + @m[:b_topbot] * 2
38
-
39
- # Initialize the image and colors
40
- @col_bg = "none"
41
- @col_fg = "black"
42
- @col_line = "black"
43
-
44
- if color
45
- @col_node = "blue"
46
- @col_leaf = "green"
47
- @col_trace = "red"
48
- else
49
- @col_node = "black"
50
- @col_leaf = "black"
51
- @col_trace = "black"
52
- end
53
-
54
- @main_height = img_get_txt_height("l", font, font_size)
55
- @sub_size = (font_size * SUBSCRIPT_CONST)
56
- @sub_space_width = img_get_txt_width("l", font, @sub_size)
57
- end
58
-
59
- def img_get_txt_metrics(text, font, font_size, multiline)
60
-
61
- background = Image.new(1, 1)
62
-
63
- gc = Draw.new
64
- gc.annotate(background, 0, 0, 0, 0, text) do |gc|
65
- gc.font = font
66
- gc.pointsize = font_size
67
- gc.gravity = CenterGravity
68
- gc.stroke = 'none'
69
- end
70
-
71
- if multiline
72
- metrics = gc.get_multiline_type_metrics(background, text)
73
- else
74
- metrics = gc.get_type_metrics(background, text)
75
- end
76
- return metrics
77
- end
78
-
79
- # Calculate the width of the element. If the element is
80
- # a node, the calculation will be performed recursively
81
- # for all child elements.
82
- def calc_element_width(e)
83
- w = 0
84
-
85
- children = @e_list.get_children(e.id)
86
-
87
- if(children.length == 0)
88
- w = img_get_txt_width(e.content, @font, @font_size) + @font_size
89
- else
90
- children.each do |child|
91
- child_e = @e_list.get_id(child)
92
- w += calc_element_width(child_e)
93
- end
94
-
95
- tw = img_get_txt_width(e.content, @font, @font_size) + @font_size
96
- if(tw > w)
97
- fix_child_size(e.id, w, tw)
98
- w = tw
99
- end
100
- end
101
-
102
- @e_list.set_element_width(e.id, w)
103
- return w
104
- end
105
-
106
- # Calculate the width of all elements in a certain level
107
- def calc_level_width(level)
108
- w = 0
109
- e = @e_list.get_first
110
- while e
111
- if(e.level == level)
112
- x = calc_element_width(e)
113
- w += x
114
- end
115
- e = @e_list.get_next
116
- end
117
- return w
118
- end
119
-
120
- def calc_children_width(id)
121
- left = 0
122
- right = 0
123
- c_list = @e_list.get_children(id)
124
- return nil if c_list.empty?
125
-
126
- c_list.each do |c|
127
- left = c.indent if indent == 0 or left > c.indent
128
- end
129
- c_list.each do |c|
130
- right = c.indent + e.width if c.indent + c.width > right
131
- end
132
- return [left, right]
133
- end
134
-
135
- def get_children_indent(id)
136
- calc_children_width(id)[0]
137
- end
138
-
139
- def get_children_width(id)
140
- calc_children_width(id)[1] - get_children_indent(id)
141
- end
142
-
143
- # Parse the elements in the list top to bottom and
144
- # draw the elements into the image.
145
- # As we it iterate through the levels, the element
146
- # indentation is calculated.
147
- def parse_list
148
-
149
- # Calc element list recursively....
150
- e_arr = @e_list.get_elements
151
-
152
- h = @e_list.get_level_height
153
-
154
- h.times do |i|
155
- x = 0
156
- e_arr.each do |j|
157
-
158
- if (j.level == i)
159
- cw = @e_list.get_element_width(j.id)
160
- parent_indent = @e_list.get_indent(j.parent)
161
- if (x < parent_indent)
162
- x = parent_indent
163
- end
164
- @e_list.set_indent(j.id, x)
165
-
166
- if !@symmetrize
167
- draw_element(x, i, cw, j.content, j.type)
168
- if(j.parent != 0 )
169
- words = j.content.split(" ")
170
- unless @leafstyle == "nothing" && ETYPE_LEAF == j.type
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
178
- else
179
- line_to_parent(x, i, cw, @e_list.get_indent(j.parent), @e_list.get_element_width(j.parent))
180
- end
181
- end
182
- end
183
- end
184
- x += cw
185
- end
186
- end
187
- end
188
- return true if !@symmetrize
189
-
190
- elements_to_draw = {}
191
- triangles_to_draw = []
192
- lines_to_draw = []
193
-
194
- lmost = {:level => nil, :value => nil, :type => nil}
195
- rmost = nil
196
- h.times do |i|
197
- curlevel = h - i - 1
198
- e_arr.each_with_index do |j, idx|
199
- if (j.level == curlevel)
200
- # Draw a line to the parent element
201
- children = @e_list.get_children(j.id)
202
-
203
- tw = img_get_txt_width(j.content, @font, @font_size)
204
- if children.length > 0
205
- left, right = -1, -1
206
- children.each do |child|
207
- k = @e_list.get_id(child)
208
- kw = img_get_txt_width(k.content, @font, @font_size)
209
- left = k.indent + kw / 2 if k.indent + kw / 2 < left or left == -1
210
- right = k.indent + kw / 2 if k.indent + kw / 2 > right
211
- end
212
-
213
- elements_to_draw[j.id] = {:left => left, :curlevel => curlevel, :width => right - left, :content => j.content, :type => j.type}
214
- @e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
215
-
216
- children.each do |child|
217
- k = @e_list.get_id(child)
218
- words = k.content.split(" ")
219
- dw = img_get_txt_width(k.content, @font, @font_size)
220
-
221
- children2 = @e_list.get_children(k.id)
222
-
223
- unless @leafstyle == "nothing" && ETYPE_LEAF == k.type
224
- if (@leafstyle == "auto" && ETYPE_LEAF == k.type)
225
- if words.length > 1 || k.triangle
226
- txt_width = img_get_txt_width(k.content, @font, @font_size)
227
- triangles_to_draw << {:indent => k.indent, :curlevel => curlevel + 1, :width1 => dw, :width2 => txt_width}
228
- else
229
- lines_to_draw << {:indent1 => k.indent, :curlevel => curlevel + 1, :width1 => dw, :indent2 => j.indent, :width2 => tw}
230
- end
231
- else
232
- lines_to_draw << {:indent1 => k.indent, :curlevel => curlevel + 1, :width1 => dw, :indent2 => j.indent, :width2 => tw}
233
- end
234
- end
235
- end
236
-
237
- end
238
- elements = e_arr.select do |l|
239
- l.level == curlevel && @e_list.get_children(l.id).empty?
240
- end
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
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])
281
- end
282
- end
283
-
284
- # Calculate top position from row (level)
285
- def row2px(row)
286
- @m[:b_topbot] + @e_height * row + (@m[:v_space] + @font_size) * row
287
- end
288
-
289
- def get_txt_only(text)
290
- text = text.strip
291
- if /\A([\+\-\=\*\#\~]+).+/ =~ text
292
- prefix = $1
293
- prefix_l = Regexp.escape(prefix)
294
- prefix_r = Regexp.escape(prefix.reverse)
295
- if /\A#{prefix_l}(.+)#{prefix_r}\z/ =~ text
296
- return $1
297
- end
298
- end
299
- return text
300
- end
301
-
302
- def img_get_txt_height(text, font, font_size, multiline = false)
303
- metrics = img_get_txt_metrics(text, font, font_size, multiline)
304
- y = metrics.height
305
- return y
306
- end
307
- end