rsyntaxtree 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rsyntaxtree +5 -5
- data/lib/rsyntaxtree/graph.rb +3 -2
- data/lib/rsyntaxtree/svg_graph.rb +17 -4
- data/lib/rsyntaxtree/tree_graph.rb +4 -8
- data/lib/rsyntaxtree/version.rb +1 -1
- data/lib/rsyntaxtree.rb +16 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dbad02f72d4b84bdaaf1db6ed5506ed4bb3c447b9b15651dc4878a8e276f3e5
|
4
|
+
data.tar.gz: 3b3c54cc2f174a4be46b827cb42f7f871e6334a28cb2df6099bf4d9521a4fbf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b36dab4e18a88cf7db1874512236e8d049ddec1f06157b92215e329f323587d6055daf7e8011ada31c5533f0e71a901359db872cd367bf86a1d1065c4ab878c
|
7
|
+
data.tar.gz: e68eb7afa8b4714ab1e48861fdf5ce2237669afc0350f28f642626f9f40274fd15d4169a9cf44f418afdcbe42abaea121329503b714625a38d436a375f801f60
|
data/bin/rsyntaxtree
CHANGED
@@ -27,9 +27,9 @@ EOS
|
|
27
27
|
opt :font, "Path to a ttf font used to generate tree (optional)", :type => String
|
28
28
|
opt :fontsize, "Size: 8-26",
|
29
29
|
:default => 16
|
30
|
-
opt :margin, "Margin:
|
31
|
-
:default =>
|
32
|
-
opt :vheight, "Connector Height: 0.5-
|
30
|
+
opt :margin, "Margin: 1-5",
|
31
|
+
:default => 1
|
32
|
+
opt :vheight, "Connector Height: 0.5-5.0",
|
33
33
|
:default => 1.0
|
34
34
|
opt :color, "Color text and bars: on or off",
|
35
35
|
:default => "on"
|
@@ -48,8 +48,8 @@ Optimist::die :fontsize, "must be in the range of 8-26" unless opts[:fontsize] >
|
|
48
48
|
Optimist::die :color, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:color]
|
49
49
|
Optimist::die :symmetrize, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:symmetrize]
|
50
50
|
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
|
52
|
-
Optimist::die :vheight, "must be in the range of 0.5-
|
51
|
+
Optimist::die :margin, "must be in the range of 1-5" if opts[:margin] < 1 || opts[:margin] > 5
|
52
|
+
Optimist::die :vheight, "must be in the range of 0.5-5.0" if opts[:vheight] < 0.5 || opts[:vheight] > 5.0
|
53
53
|
|
54
54
|
string_opts = {}
|
55
55
|
opts.each do |key, value|
|
data/lib/rsyntaxtree/graph.rb
CHANGED
@@ -58,7 +58,8 @@ class Graph
|
|
58
58
|
|
59
59
|
def img_get_txt_metrics(text, font, font_size, multiline)
|
60
60
|
|
61
|
-
background = Image.new(500, 250)
|
61
|
+
# background = Image.new(500, 250)
|
62
|
+
background = Image.new(1, 1)
|
62
63
|
|
63
64
|
gc = Draw.new
|
64
65
|
gc.annotate(background, 0, 0, 0, 0, text) do |gc|
|
@@ -286,7 +287,7 @@ class Graph
|
|
286
287
|
|
287
288
|
def get_txt_only(text)
|
288
289
|
text = text.strip
|
289
|
-
if /\A([
|
290
|
+
if /\A([\+\-\=\*\#]+).+/ =~ text
|
290
291
|
prefix = $1
|
291
292
|
prefix_l = Regexp.escape(prefix)
|
292
293
|
prefix_r = Regexp.escape(prefix.reverse)
|
@@ -21,15 +21,20 @@ class SVGGraph < Graph
|
|
21
21
|
def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font, font_size)
|
22
22
|
|
23
23
|
# Store class-specific parameters
|
24
|
-
@fontstyle = fontstyle
|
25
24
|
@font = multibyte ? font_cjk : font
|
26
25
|
@font_size = font_size
|
26
|
+
case fontstyle
|
27
|
+
when /(?:sans|cjk)/
|
28
|
+
@fontstyle = "sans-serif"
|
29
|
+
when /(?:serif|math)/
|
30
|
+
@fontstyle = "serif"
|
31
|
+
end
|
27
32
|
|
28
33
|
super(e_list, metrics, symmetrize, color, leafstyle, multibyte, @font, @font_size)
|
29
34
|
|
30
|
-
@line_styles = "<line style='stroke:black; stroke-width
|
31
|
-
@polygon_styles = "<polygon style='fill: none; stroke: black; stroke-width
|
32
|
-
@text_styles = "<text style='fill: COLOR; font-size: FONT_SIZEpx; ST; WA;' x='X_VALUE' y='Y_VALUE' TD font-family='#{@
|
35
|
+
@line_styles = "<line style='stroke:black; stroke-width:#{FONT_SCALING};' x1='X1' y1='Y1' x2='X2' y2='Y2' />\n"
|
36
|
+
@polygon_styles = "<polygon style='fill: none; stroke: black; stroke-width:#{FONT_SCALING};' points='X1 Y1 X2 Y2 X3 Y3' />\n"
|
37
|
+
@text_styles = "<text style='fill: COLOR; font-size: FONT_SIZEpx; ST; WA;' x='X_VALUE' y='Y_VALUE' TD font-family='#{@fontstyle}'>CONTENT</text>\n"
|
33
38
|
@tree_data = String.new
|
34
39
|
end
|
35
40
|
|
@@ -115,6 +120,10 @@ EOD
|
|
115
120
|
main_weight = ""
|
116
121
|
end
|
117
122
|
|
123
|
+
if /\A#(.+)#\z/ =~ main
|
124
|
+
main = $1
|
125
|
+
end
|
126
|
+
|
118
127
|
# Calculate text size for the main and the
|
119
128
|
# subscript part of the element
|
120
129
|
# symbols for underline/overline removed temporarily
|
@@ -153,6 +162,10 @@ EOD
|
|
153
162
|
sub_width = 0
|
154
163
|
end
|
155
164
|
|
165
|
+
if /\A#(.+)#\z/ =~ sub
|
166
|
+
sub = $1
|
167
|
+
end
|
168
|
+
|
156
169
|
# Center text in the element
|
157
170
|
txt_width = main_width + sub_width
|
158
171
|
txt_pos = left + (right - left) / 2 - txt_width / 2
|
@@ -63,10 +63,6 @@ class TreeGraph < Graph
|
|
63
63
|
def to_blob(fileformat='PNG')
|
64
64
|
draw
|
65
65
|
@im.border!(@margin, @margin, "white")
|
66
|
-
# return @im.to_blob do
|
67
|
-
# self.format = fileformat
|
68
|
-
# self.interlace = PlaneInterlace
|
69
|
-
# end
|
70
66
|
@im.format = fileformat
|
71
67
|
@im.interlace = PlaneInterlace
|
72
68
|
return @im.to_blob
|
@@ -127,7 +123,7 @@ class TreeGraph < Graph
|
|
127
123
|
end
|
128
124
|
end
|
129
125
|
|
130
|
-
if /\A
|
126
|
+
if /\A#(.+)#\z/ =~ main
|
131
127
|
main = $1
|
132
128
|
main_font = @font_math
|
133
129
|
end
|
@@ -166,7 +162,7 @@ class TreeGraph < Graph
|
|
166
162
|
end
|
167
163
|
end
|
168
164
|
|
169
|
-
if /\A
|
165
|
+
if /\A#(.+)#\z/ =~ sub
|
170
166
|
sub = $1
|
171
167
|
sub_font = @font_math
|
172
168
|
end
|
@@ -231,7 +227,7 @@ class TreeGraph < Graph
|
|
231
227
|
|
232
228
|
@gc.fill("none")
|
233
229
|
@gc.stroke @col_line
|
234
|
-
@gc.stroke_width 1
|
230
|
+
@gc.stroke_width 1 * FONT_SCALING
|
235
231
|
@gc.line(fromLeft.ceil, fromTop.ceil, toLeft.ceil, toBot.ceil)
|
236
232
|
end
|
237
233
|
|
@@ -256,7 +252,7 @@ class TreeGraph < Graph
|
|
256
252
|
|
257
253
|
@gc.fill("none")
|
258
254
|
@gc.stroke @col_line
|
259
|
-
@gc.stroke_width 1
|
255
|
+
@gc.stroke_width 1 * 2
|
260
256
|
@gc.line(fromLeft1, fromTop, toLeft, toBot)
|
261
257
|
@gc.line(fromLeft2, fromTop, toLeft, toBot)
|
262
258
|
@gc.line(fromLeft1, fromTop, fromLeft2, fromTop)
|
data/lib/rsyntaxtree/version.rb
CHANGED
data/lib/rsyntaxtree.rb
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
# Facade of rsyntaxtree library. When loaded by a driver script, it does all
|
9
9
|
# the necessary 'require' to use the library.
|
10
10
|
#
|
11
|
-
# This file is part of RSyntaxTree, which is a ruby port of Andre Eisenbach's
|
11
|
+
# This file is part of RSyntaxTree, which is originally a ruby port of Andre Eisenbach's
|
12
12
|
# excellent program phpSyntaxTree.
|
13
|
-
# Copyright (c) 2007-
|
13
|
+
# Copyright (c) 2007-2021 Yoichiro Hasebe <yohasebe@gmail.com>
|
14
14
|
# Copyright (c) 2003-2004 Andre Eisenbach <andre@ironcreek.net>
|
15
15
|
|
16
16
|
$LOAD_PATH << File.join( File.dirname(__FILE__), 'rsyntaxtree')
|
@@ -31,8 +31,9 @@ ETYPE_UNDEFINED = 0
|
|
31
31
|
ETYPE_NODE = 1
|
32
32
|
ETYPE_LEAF = 2
|
33
33
|
SUBSCRIPT_CONST = 0.7
|
34
|
+
FONT_SCALING = 2
|
34
35
|
|
35
|
-
class RSGenerator
|
36
|
+
class RSGenerator
|
36
37
|
def initialize(params = {})
|
37
38
|
new_params = {}
|
38
39
|
params.each do |keystr, value|
|
@@ -51,9 +52,9 @@ class RSGenerator
|
|
51
52
|
when :symmetrize, :color, :autosub
|
52
53
|
new_params[key] = value && value != "off" ? true : false
|
53
54
|
when :fontsize
|
54
|
-
new_params[key] = value.to_i
|
55
|
+
new_params[key] = value.to_i * FONT_SCALING
|
55
56
|
when :margin
|
56
|
-
new_params[key] = value.to_i
|
57
|
+
new_params[key] = value.to_i * FONT_SCALING * 4
|
57
58
|
when :vheight
|
58
59
|
new_params[key] = value.to_f
|
59
60
|
when :fontstyle
|
@@ -82,11 +83,11 @@ class RSGenerator
|
|
82
83
|
new_params[:font_cjk] = FONT_DIR + "/wqy-zenhei.ttf"
|
83
84
|
new_params[:fontstyle] = "sans"
|
84
85
|
elsif value == "modern-math" || value == "math"
|
85
|
-
new_params[:font] = FONT_DIR + "/latinmodern-math.otf"
|
86
|
-
new_params[:font_it] = FONT_DIR + "/lmroman10-italic.otf"
|
87
|
-
new_params[:font_bd] = FONT_DIR + "/lmroman10-bold.otf"
|
88
|
-
new_params[:font_bdit] = FONT_DIR + "/lmroman10-bolditalic.otf"
|
89
|
-
new_params[:font_math] = FONT_DIR + "/latinmodern-math.otf"
|
86
|
+
new_params[:font] = FONT_DIR + "/latinmodern-math.otf"
|
87
|
+
new_params[:font_it] = FONT_DIR + "/lmroman10-italic.otf"
|
88
|
+
new_params[:font_bd] = FONT_DIR + "/lmroman10-bold.otf"
|
89
|
+
new_params[:font_bdit] = FONT_DIR + "/lmroman10-bolditalic.otf"
|
90
|
+
new_params[:font_math] = FONT_DIR + "/latinmodern-math.otf"
|
90
91
|
new_params[:font_cjk] = FONT_DIR + "/NotoSerifCJKjp-Regular.otf"
|
91
92
|
new_params[:fontstyle] = "math"
|
92
93
|
end
|
@@ -112,7 +113,7 @@ class RSGenerator
|
|
112
113
|
:font_it => "/NotoSans-Italic.ttf",
|
113
114
|
:font_bd => "/NotoSans-Bold.ttf",
|
114
115
|
:font_bdit => "/NotoSans-BoldItalic.ttf",
|
115
|
-
:font_math => "/NotoSansMath-Regular.ttf"
|
116
|
+
:font_math => "/NotoSansMath-Regular.ttf"
|
116
117
|
}
|
117
118
|
@metrics = {
|
118
119
|
:e_width => 120,
|
@@ -124,8 +125,8 @@ class RSGenerator
|
|
124
125
|
}
|
125
126
|
|
126
127
|
@params.merge! new_params
|
127
|
-
@params[:fontsize] = @params[:fontsize] *
|
128
|
-
@params[:margin] = @params[:margin] *
|
128
|
+
@params[:fontsize] = @params[:fontsize] * FONT_SCALING
|
129
|
+
@params[:margin] = @params[:margin] * FONT_SCALING
|
129
130
|
@metrics[:v_space] = @metrics[:v_space] * @params[:vheight]
|
130
131
|
end
|
131
132
|
|
@@ -161,7 +162,7 @@ class RSGenerator
|
|
161
162
|
sp.auto_subscript if @params[:autosub]
|
162
163
|
elist = sp.get_elementlist
|
163
164
|
graph = SVGGraph.new(elist, @metrics,
|
164
|
-
@params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
|
165
|
+
@params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
|
165
166
|
@params[:fontstyle], @params[:font], @params[:fontsize],
|
166
167
|
)
|
167
168
|
graph.svg_data
|
@@ -175,7 +176,7 @@ class RSGenerator
|
|
175
176
|
graph = TreeGraph.new(elist, @metrics,
|
176
177
|
@params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
|
177
178
|
@params[:fontstyle], @params[:font], @params[:font_it], @params[:font_bd], @params[:font_bdit], @params[:font_math],
|
178
|
-
@params[:font_cjk], @params[:fontsize], @params[:margin],
|
179
|
+
@params[:font_cjk], @params[:fontsize], @params[:margin],
|
179
180
|
)
|
180
181
|
graph.to_blob(@params[:format])
|
181
182
|
end
|