rsyntaxtree 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2b0490e0b866d5e82213a7e131af2eb12f4561b5d2132298324e2309303ad65
4
- data.tar.gz: aa27a23a4c922af2c2d3f701ca6cc571fab074eecc3cd327c2296fd79b1d42ff
3
+ metadata.gz: a93fb86aba069b61d5095d8cd565153b36ea9cdc0bd9903b2ffc656bae5986cb
4
+ data.tar.gz: a11db6cdb80b0ccdc118761a4f2131915bffd3dc1a13343be4df662e13bb88b3
5
5
  SHA512:
6
- metadata.gz: c2885be41a0cda5efb42ee408f2ec24fc6da741a9460c50a4bb3376a7f70463748960de0be1c7a5f7822592d04c4b79b50f4e90ebe4b1c0964e2d4acffd28be8
7
- data.tar.gz: b861f941a2082d9c02119bb404e96dd121b739315df0188d31382adccf6810f85b57289c3675fcb1e07bc287387720a33df8892c1e02a13f6f524f76e0b41d97
6
+ metadata.gz: 8ce0bbb49b1c7207aa5d65958e9185dd2e28c762bf39304077b37d03c8e7a2e32b79f2b490d110a6223d1b1ca7df591f43ec82bbc7532f5f4a6c406107e55d72
7
+ data.tar.gz: 66849abf7520966907cece66a1f12fc3eb29384911ddda5f518ad23ecdf7249d589edebfec98c42f35f468c1dea7204e285a38ddb37e510610bec08807d6d154
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ### Web Interface
6
6
 
7
- Working web interface of is available at <https://yohasebe.com/rsyntaxtree>.
7
+ See updates and a working web interface available at <https://yohasebe.com/rsyntaxtree>.
8
8
 
9
9
  ### Installation
10
10
 
@@ -25,7 +25,7 @@ where [options] are:
25
25
  -o, --outdir=<s> Output directory (default: ./)
26
26
  -f, --format=<s> Output format: png, pdf, or svg (default: png)
27
27
  -l, --leafstyle=<s> visual style of tree leaves: auto, triangle, bar, or nothing (default: auto)
28
- -n, --fontstyle=<s> Font style: sans, serif, cjk (default: sans)
28
+ -n, --fontstyle=<s> Font style: sans, serif, cjk, math (default: sans)
29
29
  -t, --font=<s> Path to a ttf font used to generate tree (optional)
30
30
  -s, --fontsize=<i> Size: 8-26 (default: 16)
31
31
  -c, --color=<s> Color text and bars: on or off (default: on)
data/bin/rsyntaxtree CHANGED
@@ -20,9 +20,9 @@ EOS
20
20
  :default => "./"
21
21
  opt :format, "Output format: png, gif, jpg, pdf, or svg",
22
22
  :default => "png"
23
- opt :leafstyle, "visual style of tree leaves: auto, triangle, bar, or nothing",
23
+ opt :leafstyle, "visual style of tree leaves: auto, triangle, bar, or nothing",
24
24
  :default => "auto"
25
- opt :fontstyle, "Font style (available when ttf font is specified): sans, serif, cjk",
25
+ opt :fontstyle, "Font style (available when ttf font is specified): sans, serif, cjk, math",
26
26
  :default => "sans"
27
27
  opt :font, "Path to a ttf font used to generate tree (optional)", :type => String
28
28
  opt :fontsize, "Size: 8-26",
@@ -32,17 +32,17 @@ EOS
32
32
  opt :vheight, "Connector Height: 0.5-2.0",
33
33
  :default => 1.0
34
34
  opt :color, "Color text and bars: on or off",
35
- :default => "on"
35
+ :default => "on"
36
36
  opt :symmetrize, "Generate symmetrical, balanced tree: on or off",
37
- :default => "on"
37
+ :default => "on"
38
38
  opt :autosub, "Put subscript numbers to nodes: on or off",
39
- :default => "off"
39
+ :default => "off"
40
40
  end
41
41
 
42
42
  Optimist::die :outdir, "must be an exsting directory path" unless FileTest::directory?(opts[:outdir])
43
43
  Optimist::die :format, "must be png, jpg, gif, or svg" unless /\A(png|jpg|gif|pdf|svg)\z/ =~ opts[:format]
44
44
  Optimist::die :leafstyle, "must be auto, triangle, bar, or nothing" unless /\A(auto|triangle|bar|nothing)\z/ =~ opts[:leafstyle]
45
- Optimist::die :fontstyle, "must be sans, serif, cjk" unless /\A(sans|serif|cjk)\z/ =~ opts[:fontstyle]
45
+ Optimist::die :fontstyle, "must be sans, serif, cjk, math" unless /\A(sans|serif|cjk|math)\z/ =~ opts[:fontstyle]
46
46
  Optimist::die :font, "must be path to an existing ttf font" if opts[:font] && !File::exists?(opts[:font])
47
47
  Optimist::die :fontsize, "must be in the range of 8-26" unless opts[:fontsize] >= 8 && opts[:fontsize] <= 26
48
48
  Optimist::die :color, "must be either on or off" unless /\A(on|off)\z/ =~ opts[:color]
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -62,7 +62,7 @@ class Graph
62
62
 
63
63
  gc = Draw.new
64
64
  gc.annotate(background, 0, 0, 0, 0, text) do |gc|
65
- gc.font = font
65
+ gc.font = font
66
66
  gc.pointsize = font_size
67
67
  gc.gravity = CenterGravity
68
68
  gc.stroke = 'none'
@@ -286,7 +286,7 @@ class Graph
286
286
 
287
287
  def get_txt_only(text)
288
288
  text = text.strip
289
- if /\A([\+\-\=\*]+).+/ =~ text
289
+ if /\A([\+\-\=\*\~]+).+/ =~ text
290
290
  prefix = $1
291
291
  prefix_l = Regexp.escape(prefix)
292
292
  prefix_r = Regexp.escape(prefix.reverse)
@@ -17,18 +17,18 @@
17
17
  require 'elementlist'
18
18
  require 'element'
19
19
 
20
- def escape_high_ascii(string)
21
- html = ""
22
- string.length.times do |i|
23
- ch = string[i]
24
- if(ch < 127)
25
- html += ch.chr
26
- else
27
- html += sprintf("&#%d;", ch)
28
- end
29
- end
30
- html
31
- end
20
+ # def escape_high_ascii(string)
21
+ # html = ""
22
+ # string.length.times do |i|
23
+ # ch = string[i]
24
+ # if(ch < 127)
25
+ # html += ch.chr
26
+ # else
27
+ # html += sprintf("&#%d;", ch)
28
+ # end
29
+ # end
30
+ # html
31
+ # end
32
32
 
33
33
  class StringParser
34
34
 
@@ -18,10 +18,11 @@ require 'graph'
18
18
 
19
19
  class SVGGraph < Graph
20
20
 
21
- def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font_size)
21
+ def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font, font_size)
22
22
 
23
23
  # Store class-specific parameters
24
- @font = fontstyle == "sans" ? "sans-serif" : fontstyle
24
+ @fontstyle = fontstyle
25
+ @font = multibyte ? font_cjk : font
25
26
  @font_size = font_size
26
27
 
27
28
  super(e_list, metrics, symmetrize, color, leafstyle, multibyte, @font, @font_size)
@@ -87,15 +88,12 @@ EOD
87
88
  sub = ""
88
89
  end
89
90
 
90
- if /\A\+(.+)\+\z/ =~ main
91
+ if /\A\=(.+)\=\z/ =~ main
91
92
  main = $1
92
93
  main_decoration= "overline"
93
94
  elsif /\A\-(.+)\-\z/ =~ main
94
95
  main = $1
95
96
  main_decoration= "underline"
96
- elsif /\A\=(.+)\=\z/ =~ main
97
- main = $1
98
- main_decoration= "line-through"
99
97
  else
100
98
  main_decoration= ""
101
99
  end
@@ -124,15 +122,12 @@ EOD
124
122
  main_width = img_get_txt_width(main, @font, @font_size)
125
123
 
126
124
  if sub != ""
127
- if /\A\+(.+)\+\z/ =~ sub
125
+ if /\A\=(.+)\=\z/ =~ sub
128
126
  sub = $1
129
127
  sub_decoration= "overline"
130
128
  elsif /\A\-(.+)\-\z/ =~ sub
131
129
  sub = $1
132
130
  sub_decoration= "underline"
133
- elsif /\A\=(.+)\=\z/ =~ sub
134
- sub = $1
135
- sub_decoration= "line-through"
136
131
  else
137
132
  sub_decoration= ""
138
133
  end
@@ -20,7 +20,7 @@ include Magick
20
20
  class TreeGraph < Graph
21
21
 
22
22
  def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte,
23
- fontstyle, font, font_it, font_bd, font_itbd, font_cjk, font_size,
23
+ fontstyle, font, font_it, font_bd, font_itbd, font_math, font_cjk, font_size,
24
24
  margin)
25
25
 
26
26
  # Store class-specific parameters
@@ -30,6 +30,7 @@ class TreeGraph < Graph
30
30
  @font_it = font_it
31
31
  @font_bd = font_bd
32
32
  @font_itbd = font_itbd
33
+ @font_math = font_math
33
34
  @font_cjk = font_cjk
34
35
  @margin = margin
35
36
 
@@ -62,10 +63,13 @@ class TreeGraph < Graph
62
63
  def to_blob(fileformat='PNG')
63
64
  draw
64
65
  @im.border!(@margin, @margin, "white")
65
- return @im.to_blob do
66
- self.format = fileformat
67
- self.interlace = PlaneInterlace
68
- end
66
+ # return @im.to_blob do
67
+ # self.format = fileformat
68
+ # self.interlace = PlaneInterlace
69
+ # end
70
+ @im.format = fileformat
71
+ @im.interlace = PlaneInterlace
72
+ return @im.to_blob
69
73
  end
70
74
 
71
75
  :private
@@ -94,19 +98,18 @@ class TreeGraph < Graph
94
98
  sub = ""
95
99
  end
96
100
 
97
- if /\A\+(.+)\+\z/ =~ main
101
+ if /\A\=(.+)\=\z/ =~ main
98
102
  main = $1
99
103
  main_decoration = OverlineDecoration
100
104
  elsif /\A\-(.+)\-\z/ =~ main
101
105
  main = $1
102
106
  main_decoration = UnderlineDecoration
103
- elsif /\A\=(.+)\=\z/ =~ main
104
- main = $1
105
- main_decoration = LineThroughDecoration
106
107
  else
107
108
  main_decoration = NoDecoration
108
109
  end
109
110
 
111
+ main_font = @font
112
+
110
113
  if /\A\*\*\*(.+)\*\*\*\z/ =~ main
111
114
  main = $1
112
115
  if !@multibyte
@@ -122,32 +125,30 @@ class TreeGraph < Graph
122
125
  if !@multibyte
123
126
  main_font = @font_it
124
127
  end
125
- else
126
- main_font = @font
128
+ end
129
+
130
+ if /\A\~(.+)\~\z/ =~ main
131
+ main = $1
132
+ main_font = @font_math
127
133
  end
128
134
 
129
135
  # Calculate text size for the main and the
130
136
  # subscript part of the element
131
- # symbols for underline/overline removed temporarily
132
137
 
133
138
  main_width = img_get_txt_width(main, main_font, @font_size)
134
139
 
135
- if /\A\+(.+)\+\z/ =~ sub
140
+ if /\A\=(.+)\=\z/ =~ sub
136
141
  sub = $1
137
142
  sub_decoration = OverlineDecoration
138
143
  elsif /\A\-(.+)\-\z/ =~ sub
139
144
  sub = $1
140
145
  @gc.decorate(UnderlineDecoration)
141
146
  sub_decoration = UnderlineDecoration
142
- elsif /\A\=(.+)\=\z/ =~ sub
143
- sub = $1
144
- sub_decoration = LineThroughDecoration
145
147
  else
146
148
  sub_decoration = NoDecoration
147
149
  end
148
150
 
149
151
  sub_font = @font
150
-
151
152
  if /\A\*\*\*(.+)\*\*\*\z/ =~ sub
152
153
  sub = $1
153
154
  if !@multibyte
@@ -163,8 +164,11 @@ class TreeGraph < Graph
163
164
  if !@multibyte
164
165
  sub_font = @font_it
165
166
  end
166
- else
167
- sub_font = @font
167
+ end
168
+
169
+ if /\A~(.+)~\z/ =~ sub
170
+ sub = $1
171
+ sub_font = @font_math
168
172
  end
169
173
 
170
174
  if sub != ""
@@ -1,4 +1,4 @@
1
1
  module RSyntaxTree
2
- VERSION = "0.7.7"
2
+ VERSION = "0.8.0"
3
3
  end
4
4
 
data/lib/rsyntaxtree.rb CHANGED
@@ -62,6 +62,7 @@ class RSGenerator
62
62
  new_params[:font_it] = FONT_DIR + "/NotoSans-Italic.ttf"
63
63
  new_params[:font_bd] = FONT_DIR + "/NotoSans-Bold.ttf"
64
64
  new_params[:font_bdit] = FONT_DIR + "/NotoSans-BoldItalic.ttf"
65
+ new_params[:font_math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
65
66
  new_params[:font_cjk] = FONT_DIR + "/NotoSansCJKjp-Regular.otf"
66
67
  new_params[:fontstyle] = "sans"
67
68
  elsif value == "noto-serif" || value == "serif"
@@ -69,6 +70,7 @@ class RSGenerator
69
70
  new_params[:font_it] = FONT_DIR + "/NotoSerif-Italic.ttf"
70
71
  new_params[:font_bd] = FONT_DIR + "/NotoSerif-Bold.ttf"
71
72
  new_params[:font_bdit] = FONT_DIR + "/NotoSerif-BoldItalic.ttf"
73
+ new_params[:font_math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
72
74
  new_params[:font_cjk] = FONT_DIR + "/NotoSerifCJKjp-Regular.otf"
73
75
  new_params[:fontstyle] = "serif"
74
76
  elsif value == "cjk zenhei" || value == "cjk"
@@ -76,14 +78,24 @@ class RSGenerator
76
78
  new_params[:font_it] = FONT_DIR + "/NotoSans-Italic.ttf"
77
79
  new_params[:font_bd] = FONT_DIR + "/NotoSans-Bold.ttf"
78
80
  new_params[:font_bdit] = FONT_DIR + "/NotoSans-BoldItalic.ttf"
81
+ new_params[:font_math] = FONT_DIR + "/NotoSansMath-Regular.ttf"
79
82
  new_params[:font_cjk] = FONT_DIR + "/wqy-zenhei.ttf"
80
83
  new_params[:fontstyle] = "sans"
84
+ 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"
90
+ new_params[:font_cjk] = FONT_DIR + "/NotoSerifCJKjp-Regular.otf"
91
+ new_params[:fontstyle] = "math"
81
92
  end
82
93
  else
83
94
  new_params[key] = value
84
95
  end
85
96
  end
86
97
 
98
+ # defaults to the following
87
99
  @params = {
88
100
  :symmetrize => true,
89
101
  :color => true,
@@ -100,6 +112,7 @@ class RSGenerator
100
112
  :font_it => "/NotoSans-Italic.ttf",
101
113
  :font_bd => "/NotoSans-Bold.ttf",
102
114
  :font_bdit => "/NotoSans-BoldItalic.ttf",
115
+ :font_math => "/NotoSansMath-Regular.ttf"
103
116
  }
104
117
  @metrics = {
105
118
  :e_width => 120,
@@ -149,7 +162,7 @@ class RSGenerator
149
162
  elist = sp.get_elementlist
150
163
  graph = SVGGraph.new(elist, @metrics,
151
164
  @params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
152
- @params[:fontstyle], @params[:fontsize],
165
+ @params[:fontstyle], @params[:font], @params[:fontsize],
153
166
  )
154
167
  graph.svg_data
155
168
  end
@@ -161,7 +174,7 @@ class RSGenerator
161
174
  elist = sp.get_elementlist
162
175
  graph = TreeGraph.new(elist, @metrics,
163
176
  @params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
164
- @params[:fontstyle], @params[:font], @params[:font_it], @params[:font_bd], @params[:font_bdit],
177
+ @params[:fontstyle], @params[:font], @params[:font_it], @params[:font_bd], @params[:font_bdit], @params[:font_math],
165
178
  @params[:font_cjk], @params[:fontsize], @params[:margin],
166
179
  )
167
180
  graph.to_blob(@params[:format])
data/rsyntaxtree.gemspec CHANGED
@@ -12,14 +12,11 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{RSyntaxTree is a graphical syntax tree generator written in Ruby}
13
13
  s.description = %q{Yet another syntax tree generator made with Ruby and RMagick}
14
14
  s.licenses = ["MIT"]
15
-
16
- s.rubyforge_project = "rsyntaxtree"
17
-
18
15
  s.files = `git ls-files`.split("\n")
19
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
17
  s.require_paths = ["lib"]
21
18
 
22
19
  # specify any dependencies here; for example:
23
- s.add_runtime_dependency("rmagick", '>= 2.16.0')
24
- s.add_runtime_dependency("optimist")
20
+ s.add_runtime_dependency 'rmagick', '~> 4.2', '>= 4.2.3'
21
+ s.add_runtime_dependency 'optimist', '~> 3.0', '>= 3.0.1'
25
22
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsyntaxtree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.8.0
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-02-17 00:00:00.000000000 Z
11
+ date: 2021-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: 2.16.0
22
+ version: 4.2.3
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: 2.16.0
32
+ version: 4.2.3
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: optimist
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 3.0.1
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
- version: '0'
52
+ version: 3.0.1
41
53
  description: Yet another syntax tree generator made with Ruby and RMagick
42
54
  email:
43
55
  - yohasebe@gmail.com
@@ -56,11 +68,17 @@ files:
56
68
  - fonts/NotoSans-Italic.ttf
57
69
  - fonts/NotoSans-Regular.ttf
58
70
  - fonts/NotoSansCJKjp-Regular.otf
71
+ - fonts/NotoSansMath-Regular.ttf
59
72
  - fonts/NotoSerif-Bold.ttf
60
73
  - fonts/NotoSerif-BoldItalic.ttf
61
74
  - fonts/NotoSerif-Italic.ttf
62
75
  - fonts/NotoSerif-Regular.ttf
63
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
64
82
  - fonts/wqy-zenhei.ttf
65
83
  - lib/rsyntaxtree.rb
66
84
  - lib/rsyntaxtree/element.rb
@@ -92,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
110
  - !ruby/object:Gem::Version
93
111
  version: '0'
94
112
  requirements: []
95
- rubygems_version: 3.2.3
113
+ rubygems_version: 3.2.11
96
114
  signing_key:
97
115
  specification_version: 4
98
116
  summary: RSyntaxTree is a graphical syntax tree generator written in Ruby