rsyntaxtree 1.2.7 → 1.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tags +65 -0
- data/README.md +3 -2
- data/bin/rsyntaxtree +7 -5
- data/dev/generate_examples.rb +1 -13
- data/docs/_examples/000.md +1 -1
- data/docs/_examples/001.md +1 -1
- data/docs/_examples/002.md +1 -1
- data/docs/_examples/003.md +1 -1
- data/docs/_examples/004.md +1 -1
- data/docs/_examples/005.md +1 -1
- data/docs/_examples/006.md +1 -1
- data/docs/_examples/007.md +1 -1
- data/docs/_examples/008.md +1 -1
- data/docs/_examples/009.md +1 -1
- data/docs/_examples/010.md +1 -1
- data/docs/_examples/011.md +1 -1
- data/docs/_examples/012.md +1 -1
- data/docs/_examples/014.md +1 -1
- data/docs/_examples/015.md +1 -1
- data/docs/_examples/016.md +1 -1
- data/docs/_examples/019.md +1 -1
- data/docs/_examples/021.md +1 -1
- data/docs/_examples/024.md +1 -1
- data/docs/_examples/025.md +1 -1
- data/docs/_examples/026.md +1 -1
- data/docs/_examples/027.md +1 -1
- data/docs/_examples/030.md +1 -1
- data/docs/_examples/031.md +1 -1
- data/docs/_examples/032.md +1 -1
- data/docs/_examples/034.md +1 -1
- data/docs/_examples/035.md +2 -2
- data/docs/_examples/040.md +1 -1
- data/docs/_examples/042.md +1 -1
- data/docs/_examples/047.md +21 -0
- data/docs/_includes/box_and_circle_table.html +24 -0
- data/docs/assets/css/style.scss +6 -0
- data/docs/assets/img/000.png +0 -0
- data/docs/assets/img/001.png +0 -0
- data/docs/assets/img/002.png +0 -0
- data/docs/assets/img/003.png +0 -0
- data/docs/assets/img/004.png +0 -0
- data/docs/assets/img/005.png +0 -0
- data/docs/assets/img/006.png +0 -0
- data/docs/assets/img/007.png +0 -0
- data/docs/assets/img/008.png +0 -0
- data/docs/assets/img/009.png +0 -0
- data/docs/assets/img/010.png +0 -0
- data/docs/assets/img/011.png +0 -0
- data/docs/assets/img/012.png +0 -0
- data/docs/assets/img/013.png +0 -0
- data/docs/assets/img/014.png +0 -0
- data/docs/assets/img/015.png +0 -0
- data/docs/assets/img/016.png +0 -0
- data/docs/assets/img/017.png +0 -0
- data/docs/assets/img/018.png +0 -0
- data/docs/assets/img/019.png +0 -0
- data/docs/assets/img/020.png +0 -0
- data/docs/assets/img/021.png +0 -0
- data/docs/assets/img/022.png +0 -0
- data/docs/assets/img/023.png +0 -0
- data/docs/assets/img/024.png +0 -0
- data/docs/assets/img/025.png +0 -0
- data/docs/assets/img/026.png +0 -0
- data/docs/assets/img/027.png +0 -0
- data/docs/assets/img/028.png +0 -0
- data/docs/assets/img/029.png +0 -0
- data/docs/assets/img/030.png +0 -0
- data/docs/assets/img/031.png +0 -0
- data/docs/assets/img/032.png +0 -0
- data/docs/assets/img/033.png +0 -0
- data/docs/assets/img/034.png +0 -0
- data/docs/assets/img/035.png +0 -0
- data/docs/assets/img/036.png +0 -0
- data/docs/assets/img/037.png +0 -0
- data/docs/assets/img/038.png +0 -0
- data/docs/assets/img/039.png +0 -0
- data/docs/assets/img/040.png +0 -0
- data/docs/assets/img/041.png +0 -0
- data/docs/assets/img/042.png +0 -0
- data/docs/assets/img/043.png +0 -0
- data/docs/assets/img/044.png +0 -0
- data/docs/assets/img/045.png +0 -0
- data/docs/assets/img/046.png +0 -0
- data/docs/assets/img/047.png +0 -0
- data/docs/assets/img/elements/arrow_both.png +0 -0
- data/docs/assets/img/elements/arrow_both_bold.png +0 -0
- data/docs/assets/img/elements/arrow_left.png +0 -0
- data/docs/assets/img/elements/arrow_left_bold.png +0 -0
- data/docs/assets/img/elements/arrow_right.png +0 -0
- data/docs/assets/img/elements/arrow_right_bold.png +0 -0
- data/docs/assets/svg/000.svg +38 -38
- data/docs/assets/svg/001.svg +19 -19
- data/docs/assets/svg/002.svg +37 -37
- data/docs/assets/svg/003.svg +29 -29
- data/docs/assets/svg/004.svg +41 -41
- data/docs/assets/svg/005.svg +21 -21
- data/docs/assets/svg/006.svg +25 -25
- data/docs/assets/svg/007.svg +31 -31
- data/docs/assets/svg/008.svg +35 -35
- data/docs/assets/svg/009.svg +35 -35
- data/docs/assets/svg/010.svg +52 -52
- data/docs/assets/svg/011.svg +30 -30
- data/docs/assets/svg/012.svg +35 -35
- data/docs/assets/svg/013.svg +142 -142
- data/docs/assets/svg/014.svg +119 -119
- data/docs/assets/svg/015.svg +33 -33
- data/docs/assets/svg/016.svg +523 -523
- data/docs/assets/svg/017.svg +49 -49
- data/docs/assets/svg/018.svg +37 -37
- data/docs/assets/svg/019.svg +172 -172
- data/docs/assets/svg/020.svg +62 -62
- data/docs/assets/svg/021.svg +73 -73
- data/docs/assets/svg/022.svg +109 -109
- data/docs/assets/svg/023.svg +73 -73
- data/docs/assets/svg/024.svg +23 -23
- data/docs/assets/svg/025.svg +147 -147
- data/docs/assets/svg/026.svg +23 -23
- data/docs/assets/svg/027.svg +64 -64
- data/docs/assets/svg/028.svg +21 -21
- data/docs/assets/svg/029.svg +79 -79
- data/docs/assets/svg/030.svg +41 -41
- data/docs/assets/svg/031.svg +15 -15
- data/docs/assets/svg/032.svg +52 -52
- data/docs/assets/svg/033.svg +43 -43
- data/docs/assets/svg/034.svg +49 -49
- data/docs/assets/svg/035.svg +39 -39
- data/docs/assets/svg/036.svg +20 -20
- data/docs/assets/svg/037.svg +33 -33
- data/docs/assets/svg/038.svg +45 -45
- data/docs/assets/svg/039.svg +7 -7
- data/docs/assets/svg/040.svg +98 -98
- data/docs/assets/svg/041.svg +55 -55
- data/docs/assets/svg/042.svg +15 -15
- data/docs/assets/svg/043.svg +187 -187
- data/docs/assets/svg/044.svg +9 -9
- data/docs/assets/svg/045.svg +66 -66
- data/docs/assets/svg/046.svg +647 -647
- data/docs/assets/svg/047.svg +62 -0
- data/docs/documentation.md +1 -1
- data/docs/documentation_ja.md +1 -1
- data/docs/examples.html +5 -4
- data/lib/rsyntaxtree/base_graph.rb +2 -1
- data/lib/rsyntaxtree/svg_graph.rb +10 -10
- data/lib/rsyntaxtree/version.rb +1 -1
- data/lib/rsyntaxtree.rb +38 -24
- data/test/example_verify_test.rb +1 -13
- metadata +12 -3
@@ -0,0 +1,62 @@
|
|
1
|
+
<?xml version="1.0" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg width="95.4" height="317.25" viewBox="-16.8, 0, 112.2, 328.5" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
4
|
+
<defs>
|
5
|
+
<marker id="arrow" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="10" refY="5" markerWidth="16.8" markerHeight="16.8" orient="auto">
|
6
|
+
<path d="M 0 0 L 10 5 L 0 10" fill="black"/>
|
7
|
+
</marker>
|
8
|
+
<marker id="arrowBackward" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="16.8" markerHeight="16.8" orient="auto">
|
9
|
+
<path d="M 0 0 L 10 5 L 0 10 z" fill="black"/>
|
10
|
+
</marker>
|
11
|
+
<marker id="arrowForward" markerUnits="userSpaceOnUse" viewBox="0 0 10 10" refX="5" refY="5" markerWidth="16.8" markerHeight="16.8" orient="auto">
|
12
|
+
<path d="M 10 0 L 0 5 L 10 10 z" fill="black"/>
|
13
|
+
</marker>
|
14
|
+
<marker id="arrowBothways" markerUnits="userSpaceOnUse" viewBox="0 0 30 10" refX="15" refY="5" markerWidth="50.400000000000006" markerHeight="16.8" orient="auto">
|
15
|
+
<path d="M 0 5 L 10 0 L 10 5 L 20 5 L 20 0 L 30 5 L 20 10 L 20 5 L 10 5 L 10 10 z" fill="black"/>
|
16
|
+
</marker>
|
17
|
+
<pattern id="hatchBlack" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
|
18
|
+
<line x1="0" y="0" x2="0" y2="10" stroke="black" stroke-width="4"></line>
|
19
|
+
</pattern>
|
20
|
+
<pattern id="hatchForNode" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
|
21
|
+
<line x1="0" y="0" x2="0" y2="10" stroke="black" stroke-width="4"></line>
|
22
|
+
</pattern>
|
23
|
+
<pattern id="hatchForLeaf" x="10" y="10" width="10" height="10" patternUnits="userSpaceOnUse" patternTransform="rotate(45)">
|
24
|
+
<line x1="0" y="0" x2="0" y2="10" stroke="black" stroke-width="4"></line>
|
25
|
+
</pattern>
|
26
|
+
</defs>
|
27
|
+
<rect x="-16.8" y="0" width="112.2" height="328.5" stroke="none" fill="white" />"
|
28
|
+
<text white-space='pre' alignment-baseline='text-top' style='fill: black; storoke-width: 0; font-size: 32px;' x='16.799999999999997' y='67.5'><tspan x='29.799999999999997' y='67.5' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif"> </tspan>
|
29
|
+
<tspan x='29.799999999999997' y='112.5' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif"> </tspan>
|
30
|
+
<tspan x='29.799999999999997' y='157.5' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif"> </tspan>
|
31
|
+
<tspan x='29.799999999999997' y='202.5' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif"> </tspan>
|
32
|
+
<tspan x='29.799999999999997' y='247.5' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif"> </tspan>
|
33
|
+
<tspan x='29.799999999999997' y='292.5' style="" text-decoration="" font-family="'Noto Serif', 'Noto Serif JP', OpenMoji, 'OpenMoji Color', 'OpenMoji Black', serif"> </tspan>
|
34
|
+
</text>
|
35
|
+
<line style='fill:none; stroke:black; stroke-linejoin:round; stroke-linecap:round; stroke-width:2;' x1='17.799999999999997' y1='54.0' x2='60.8' y2='54.0'></line>
|
36
|
+
|
37
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='2' points='50.55,48.375 60.8,54.0 50.55,59.625' />
|
38
|
+
|
39
|
+
<line style='fill:none; stroke:black; stroke-linejoin:round; stroke-linecap:round; stroke-width:3;' x1='17.799999999999997' y1='99.0' x2='60.8' y2='99.0'></line>
|
40
|
+
|
41
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='3' points='50.55,93.375 60.8,99.0 50.55,104.625' />
|
42
|
+
|
43
|
+
<line style='fill:none; stroke:black; stroke-linejoin:round; stroke-linecap:round; stroke-width:2;' x1='17.799999999999997' y1='144.0' x2='60.8' y2='144.0'></line>
|
44
|
+
|
45
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='2' points='28.049999999999997,149.625 17.799999999999997,144.0 28.049999999999997,138.375' />
|
46
|
+
|
47
|
+
<line style='fill:none; stroke:black; stroke-linejoin:round; stroke-linecap:round; stroke-width:3;' x1='17.799999999999997' y1='189.0' x2='60.8' y2='189.0'></line>
|
48
|
+
|
49
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='3' points='28.049999999999997,194.625 17.799999999999997,189.0 28.049999999999997,183.375' />
|
50
|
+
|
51
|
+
<line style='fill:none; stroke:black; stroke-linejoin:round; stroke-linecap:round; stroke-width:2;' x1='17.799999999999997' y1='234.0' x2='60.8' y2='234.0'></line>
|
52
|
+
|
53
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='2' points='28.049999999999997,239.625 17.799999999999997,234.0 28.049999999999997,228.375' />
|
54
|
+
|
55
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='2' points='50.55,228.375 60.8,234.0 50.55,239.625' />
|
56
|
+
|
57
|
+
<line style='fill:none; stroke:black; stroke-linejoin:round; stroke-linecap:round; stroke-width:3;' x1='17.799999999999997' y1='279.0' x2='60.8' y2='279.0'></line>
|
58
|
+
|
59
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='3' points='28.049999999999997,284.625 17.799999999999997,279.0 28.049999999999997,273.375' />
|
60
|
+
|
61
|
+
<polyline stroke-linejoin='round' stroke-linecap='round' fill='none' stroke='black' stroke-width='3' points='50.55,273.375 60.8,279.0 50.55,284.625' />
|
62
|
+
</svg>
|
data/docs/documentation.md
CHANGED
@@ -80,7 +80,7 @@ Note: Currently, overline is displayed in SVG, but not in PNG.
|
|
80
80
|
|`normal_subscript_` |normal<sub>subscript</sub> |
|
81
81
|
|`normal__superscript__`|normal<sup>superscript</sup>|
|
82
82
|
|
83
|
-
#### Box and
|
83
|
+
#### Box, Circle, Bar, and Arrow
|
84
84
|
|
85
85
|
{% include box_and_circle_table.html %}
|
86
86
|
|
data/docs/documentation_ja.md
CHANGED
data/docs/examples.html
CHANGED
@@ -27,8 +27,8 @@ layout: default
|
|
27
27
|
</button>
|
28
28
|
</div>
|
29
29
|
<div class='grid'>
|
30
|
-
<div style='margin-top: 0; margin-bottom: auto;'>
|
31
|
-
<div id="text-{{example.name}}" style='max-height: 600px; overflow-y: auto; margin-bottom: 20px;'>
|
30
|
+
<div style='margin-top: 0; margin-bottom: auto; '>
|
31
|
+
<div id="text-{{example.name}}" style='max-height: 600px; overflow-x: auto; overflow-y: auto; margin-bottom: 20px;'>
|
32
32
|
{{ example.content | markdownify }}
|
33
33
|
</div>
|
34
34
|
<table style='line-height: 110%; font-size: 0.85em; margin-bottom: 20px;'>
|
@@ -36,6 +36,7 @@ layout: default
|
|
36
36
|
<tbody>
|
37
37
|
<tr><td>Category</td><td>{{ example.category}}</td></tr>
|
38
38
|
<tr><td>Connector</td><td>{{ example.connector }}</td></tr>
|
39
|
+
<tr><td>Connector Height</td><td>{{ example.connector_height }}</td></tr>
|
39
40
|
<tr><td>Line Width</td><td>{{ example.linewidth }}</td></tr>
|
40
41
|
<tr><td>Hide Default Connectors</td><td>{{ example.hide_default_connectors }}</td></tr>
|
41
42
|
<tr><td>Polyline</td><td>{{ example.polyline }}</td></tr>
|
@@ -48,9 +49,9 @@ layout: default
|
|
48
49
|
</tbody>
|
49
50
|
</table>
|
50
51
|
</div>
|
51
|
-
<div style='margin-top: 0; margin-bottom: auto;'>
|
52
|
+
<div style='margin-top: 0; padding: 10px; margin-bottom: auto;'>
|
52
53
|
<a href='assets/img/{{ example.name }}.png' data-lightbox='{{ example.name }}'>
|
53
|
-
<img src='assets/img/{{ example.name}}.png'/>
|
54
|
+
<img src='assets/img/{{ example.name}}.png' />
|
54
55
|
</a>
|
55
56
|
</div>
|
56
57
|
</div>
|
@@ -57,7 +57,8 @@ module RSyntaxTree
|
|
57
57
|
|
58
58
|
def calculate_level
|
59
59
|
@element_list.get_elements.select { |e| e.type == 2 }.each do |e|
|
60
|
-
|
60
|
+
parent = @element_list.get_id(e.parent)
|
61
|
+
e.level = @element_list.get_id(e.parent).level + 1 if parent
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
@@ -27,11 +27,11 @@ module RSyntaxTree
|
|
27
27
|
@color = params[:color]
|
28
28
|
@fontstyle = params[:fontstyle]
|
29
29
|
@polyline = params[:polyline]
|
30
|
-
@line_styles = "<line style='stroke:#{@col_line}; stroke-width:#{@linewidth + LINE_SCALING}; stroke-linejoin:round; stroke-linecap:round;' x1='X1' y1='Y1' x2='X2' y2='Y2' />\n"
|
30
|
+
@line_styles = "<line style='fill: none; stroke:#{@col_line}; stroke-width:#{@linewidth + LINE_SCALING}; stroke-linejoin:round; stroke-linecap:round;' x1='X1' y1='Y1' x2='X2' y2='Y2' />\n"
|
31
31
|
@polyline_styles = "<polyline style='stroke:#{@col_line}; stroke-width:#{@linewidth + LINE_SCALING}; fill:none; stroke-linejoin:round; stroke-linecap:round;'
|
32
32
|
points='CHIX CHIY MIDX1 MIDY1 MIDX2 MIDY2 PARX PARY' />\n"
|
33
33
|
@polygon_styles = "<polygon style='fill: none; stroke: black; stroke-width:#{@linewidth + LINE_SCALING}; stroke-linejoin:round;stroke-linecap:round;' points='X1 Y1 X2 Y2 X3 Y3' />\n"
|
34
|
-
@text_styles = "<text white-space='pre' alignment-baseline='text-top' style='fill: COLOR; font-size: fontsize' x='X_VALUE' y='Y_VALUE'>CONTENT</text>\n"
|
34
|
+
@text_styles = "<text white-space='pre' alignment-baseline='text-top' style='fill: COLOR; storoke-width: 0; font-size: fontsize' x='X_VALUE' y='Y_VALUE'>CONTENT</text>\n"
|
35
35
|
@tree_data = String.new
|
36
36
|
@visited_x = {}
|
37
37
|
@visited_y = {}
|
@@ -41,12 +41,12 @@ module RSyntaxTree
|
|
41
41
|
def svg_data
|
42
42
|
metrics = parse_list
|
43
43
|
|
44
|
+
@width = metrics[:width] + @global[:h_gap_between_nodes] * 2
|
44
45
|
@height = metrics[:height] + @global[:height_connector_to_text] / 2
|
45
|
-
@width = metrics[:width] + @global[:h_gap_between_nodes] / 2
|
46
46
|
|
47
|
-
x1 = 0
|
47
|
+
x1 = 0 - @global[:h_gap_between_nodes]
|
48
48
|
y1 = 0
|
49
|
-
x2 = @width + @global[:h_gap_between_nodes]
|
49
|
+
x2 = @width + @global[:h_gap_between_nodes]
|
50
50
|
y2 = @height + @global[:height_connector_to_text] / 2
|
51
51
|
|
52
52
|
extra_lines = @extra_lines.join("\n")
|
@@ -183,7 +183,7 @@ module RSyntaxTree
|
|
183
183
|
when :bborder
|
184
184
|
stroke_width = @linewidth + BLINE_SCALING
|
185
185
|
end
|
186
|
-
@extra_lines << "<line style=\"stroke:#{col}; stroke-linecap:round; stroke-width:#{stroke_width}; \" x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\"></line>"
|
186
|
+
@extra_lines << "<line style=\"stroke:#{col}; fill:none; stroke-linecap:round; stroke-width:#{stroke_width}; \" x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\"></line>"
|
187
187
|
else
|
188
188
|
if element.enclosure == :brackets
|
189
189
|
this_x = txt_pos - element.content_width / 2
|
@@ -247,7 +247,7 @@ module RSyntaxTree
|
|
247
247
|
|
248
248
|
if e[:decoration].include?(:box) || e[:decoration].include?(:circle) || e[:decoration].include?(:bar)
|
249
249
|
enc_height = e[:height]
|
250
|
-
enc_y = this_y - e[:height] * 0.8
|
250
|
+
enc_y = this_y - e[:height] * 0.8
|
251
251
|
enc_width = e[:width]
|
252
252
|
enc_x = this_x
|
253
253
|
|
@@ -279,12 +279,12 @@ module RSyntaxTree
|
|
279
279
|
end
|
280
280
|
|
281
281
|
if e[:decoration].include?(:box)
|
282
|
-
enc = "<rect style='stroke: #{col}; stroke-linejoin:round; stroke-width:#{stroke_width};'
|
282
|
+
enc = "<rect style='fill: none; stroke: #{col}; stroke-linejoin:round; stroke-width:#{stroke_width};'
|
283
283
|
x='#{enc_x}' y='#{enc_y}'
|
284
284
|
width='#{enc_width}' height='#{enc_height}'
|
285
285
|
fill='#{fill}' />\n"
|
286
286
|
elsif e[:decoration].include?(:circle)
|
287
|
-
enc = "<rect style='stroke: #{col}; stroke-width:#{stroke_width};'
|
287
|
+
enc = "<rect style='fill: none; stroke: #{col}; stroke-width:#{stroke_width};'
|
288
288
|
x='#{enc_x}' y='#{enc_y}' rx='#{enc_height / 2}' ry='#{enc_height / 2}'
|
289
289
|
width='#{enc_width}' height='#{enc_height}'
|
290
290
|
fill='#{fill}' />\n"
|
@@ -294,7 +294,7 @@ module RSyntaxTree
|
|
294
294
|
x2 = enc_x + enc_width
|
295
295
|
y2 = y1
|
296
296
|
ar_hwidth = e[:width] / 4.0
|
297
|
-
bar = "<line style='stroke:#{col}; stroke-linejoin:round; stroke-linecap:round; stroke-width:#{stroke_width};' x1='#{x1}' y1='#{y1}' x2='#{x2 - stroke_width / 2}' y2='#{y2}'></line>\n"
|
297
|
+
bar = "<line style='fill:none; stroke:#{col}; stroke-linejoin:round; stroke-linecap:round; stroke-width:#{stroke_width};' x1='#{x1 + stroke_width / 2}' y1='#{y1}' x2='#{x2 - stroke_width / 2}' y2='#{y2}'></line>\n"
|
298
298
|
@extra_lines << bar
|
299
299
|
|
300
300
|
if e[:decoration].include?(:arrow_to_l)
|
data/lib/rsyntaxtree/version.rb
CHANGED
data/lib/rsyntaxtree.rb
CHANGED
@@ -13,9 +13,22 @@ ETYPE_NODE = 1
|
|
13
13
|
ETYPE_LEAF = 2
|
14
14
|
SUBSCRIPT_CONST = 0.7
|
15
15
|
FONT_SCALING = 2
|
16
|
-
LINE_SCALING =
|
17
|
-
BLINE_SCALING =
|
16
|
+
LINE_SCALING = 1
|
17
|
+
BLINE_SCALING = 2
|
18
18
|
WHITESPACE_BLOCK = "■"
|
19
|
+
DEFAULT_OPTS = {
|
20
|
+
format: "png",
|
21
|
+
leafstyle: "auto",
|
22
|
+
fontstyle: "sans",
|
23
|
+
fontsize: 16,
|
24
|
+
linewidth: 1,
|
25
|
+
vheight: 2.0,
|
26
|
+
color: "modern",
|
27
|
+
symmetrize: "on",
|
28
|
+
transparent: "off",
|
29
|
+
polyline: "off",
|
30
|
+
hide_default_connectors: "off"
|
31
|
+
}.freeze
|
19
32
|
|
20
33
|
class RSTError < StandardError
|
21
34
|
def initialize(msg = "Error: something unexpected occurred")
|
@@ -67,7 +80,7 @@ module RSyntaxTree
|
|
67
80
|
"off"
|
68
81
|
end
|
69
82
|
when :fontsize
|
70
|
-
new_params[key] = value.to_i
|
83
|
+
new_params[key] = value.to_i
|
71
84
|
when :linewidth
|
72
85
|
new_params[key] = value.to_i
|
73
86
|
when :vheight
|
@@ -117,21 +130,7 @@ module RSyntaxTree
|
|
117
130
|
end
|
118
131
|
|
119
132
|
# defaults to the following
|
120
|
-
@params =
|
121
|
-
symmetrize: true,
|
122
|
-
color: "modern",
|
123
|
-
transparent: false,
|
124
|
-
fontsize: 16,
|
125
|
-
linewidth: 2,
|
126
|
-
format: "png",
|
127
|
-
leafstyle: "auto",
|
128
|
-
filename: "syntree",
|
129
|
-
data: "",
|
130
|
-
vheight: 1.0,
|
131
|
-
polyline: false,
|
132
|
-
hide_default_connectors: false
|
133
|
-
}
|
134
|
-
|
133
|
+
@params = DEFAULT_OPTS.dup
|
135
134
|
@params.merge! new_params
|
136
135
|
@params[:fontsize] = @params[:fontsize] * FONT_SCALING
|
137
136
|
@params[:fontset] = fontset
|
@@ -170,6 +169,24 @@ module RSyntaxTree
|
|
170
169
|
raise RSTError, +"Error: the result syntree is too big"
|
171
170
|
end
|
172
171
|
|
172
|
+
def draw_pdf(binary = false)
|
173
|
+
b = StringIO.new
|
174
|
+
svg = draw_svg
|
175
|
+
rsvg = RSVG::Handle.new_from_data(svg)
|
176
|
+
dim = rsvg.dimensions
|
177
|
+
surface = Cairo::PDFSurface.new(b, dim.width, dim.height)
|
178
|
+
context = Cairo::Context.new(surface)
|
179
|
+
context.render_rsvg_handle(rsvg)
|
180
|
+
surface.finish
|
181
|
+
if binary
|
182
|
+
b
|
183
|
+
else
|
184
|
+
b.string
|
185
|
+
end
|
186
|
+
rescue Cairo::InvalidSize
|
187
|
+
raise RSTError, +"Error: the result syntree is too big"
|
188
|
+
end
|
189
|
+
|
173
190
|
def draw_svg
|
174
191
|
sp = StringParser.new(@params[:data].gsub('&', '&'), @params[:fontset], @params[:fontsize], @global)
|
175
192
|
sp.parse
|
@@ -177,17 +194,14 @@ module RSyntaxTree
|
|
177
194
|
graph.svg_data
|
178
195
|
end
|
179
196
|
|
197
|
+
# Currently not used
|
180
198
|
def draw_tree
|
181
199
|
svg = draw_svg
|
182
200
|
image, _data = Magick::Image.from_blob(svg) do |im|
|
183
201
|
im.format = 'svg'
|
184
202
|
end
|
185
|
-
|
186
|
-
|
187
|
-
else
|
188
|
-
image.to_blob do |im|
|
189
|
-
im.format = @params[:format].upcase
|
190
|
-
end
|
203
|
+
image.to_blob do |im|
|
204
|
+
im.format = @params[:format].upcase
|
191
205
|
end
|
192
206
|
image
|
193
207
|
end
|
data/test/example_verify_test.rb
CHANGED
@@ -15,19 +15,7 @@ class ExampleParserTest < Minitest::Test
|
|
15
15
|
config = YAML.load_file(md)
|
16
16
|
rst = File.read(md).scan(/```([^`]+)```/m).last.first
|
17
17
|
|
18
|
-
opts =
|
19
|
-
format: "png",
|
20
|
-
leafstyle: "auto",
|
21
|
-
fontstyle: "sans",
|
22
|
-
fontsize: 16,
|
23
|
-
linewidth: 1,
|
24
|
-
vheight: 2.0,
|
25
|
-
color: "on",
|
26
|
-
symmetrize: "on",
|
27
|
-
transparent: "off",
|
28
|
-
polyline: "off",
|
29
|
-
hide_default_connectors: "off"
|
30
|
-
}
|
18
|
+
opts = DEFAULT_OPTS.dup
|
31
19
|
name = nil
|
32
20
|
config.each do |key, value|
|
33
21
|
next if value.to_s == ""
|
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: 1.2.
|
4
|
+
version: 1.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoichiro Hasebe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: optimist
|
@@ -161,6 +161,7 @@ files:
|
|
161
161
|
- docs/_examples/044.md
|
162
162
|
- docs/_examples/045.md
|
163
163
|
- docs/_examples/046.md
|
164
|
+
- docs/_examples/047.md
|
164
165
|
- docs/_includes/box_and_circle_table.html
|
165
166
|
- docs/_includes/escape_char_table.html
|
166
167
|
- docs/_includes/social_media_links.html
|
@@ -213,6 +214,13 @@ files:
|
|
213
214
|
- docs/assets/img/044.png
|
214
215
|
- docs/assets/img/045.png
|
215
216
|
- docs/assets/img/046.png
|
217
|
+
- docs/assets/img/047.png
|
218
|
+
- docs/assets/img/elements/arrow_both.png
|
219
|
+
- docs/assets/img/elements/arrow_both_bold.png
|
220
|
+
- docs/assets/img/elements/arrow_left.png
|
221
|
+
- docs/assets/img/elements/arrow_left_bold.png
|
222
|
+
- docs/assets/img/elements/arrow_right.png
|
223
|
+
- docs/assets/img/elements/arrow_right_bold.png
|
216
224
|
- docs/assets/img/elements/circle.png
|
217
225
|
- docs/assets/img/elements/circle_abc.png
|
218
226
|
- docs/assets/img/elements/circle_bold.png
|
@@ -276,6 +284,7 @@ files:
|
|
276
284
|
- docs/assets/svg/044.svg
|
277
285
|
- docs/assets/svg/045.svg
|
278
286
|
- docs/assets/svg/046.svg
|
287
|
+
- docs/assets/svg/047.svg
|
279
288
|
- docs/documentation.md
|
280
289
|
- docs/documentation_ja.md
|
281
290
|
- docs/examples.html
|
@@ -332,7 +341,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
332
341
|
- !ruby/object:Gem::Version
|
333
342
|
version: '0'
|
334
343
|
requirements: []
|
335
|
-
rubygems_version: 3.
|
344
|
+
rubygems_version: 3.4.2
|
336
345
|
signing_key:
|
337
346
|
specification_version: 4
|
338
347
|
summary: RSyntaxTree is a graphical syntax tree generator written in Ruby
|