text2svg 0.4.3 → 0.5.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
  SHA1:
3
- metadata.gz: e29c2ffc44a242de91e2876aef21d394daa5daa0
4
- data.tar.gz: f860b743cecb07c3678290131ecaeeafdaf10bf7
3
+ metadata.gz: 50a6d18c07bd996b35d694f9316685611ae3680f
4
+ data.tar.gz: 11ad00087eb6292b4805610df01b4c8e165fc23f
5
5
  SHA512:
6
- metadata.gz: 07bfe6642e0e844de542503f5611fc04eae4f82b91e09a7fd0ae47ddaa4904f9da02c1581f3b41fe2ed4dd01246d23222b5d76bb82278f19d8598a8c69d39b15
7
- data.tar.gz: 6b868b446bc1ffd78b9df88080eaf347a8503b6d27d984fe9f9d5c88b58b95ae8d611113fa81c340ee7bfa0313aa6d19079f5af2ed135c3d6622c587c7091bf4
6
+ metadata.gz: 999e7ce52316d2550e98b1b611b35c52c5c3868b4a3fd6f91dd3c9116723576437c4f678070a4566e9b2549658be53af4113b3e842d1eabc128e30381a99eae5
7
+ data.tar.gz: 11e8ec2c883b133aa8e66bfabc6243b3b557e00c3a796fcc7297c4e8a86a29a06342adde92d5d85df59d7dbb50c5528fb1e5297a13d52789c4d542e2ccb47fc2
data/lib/text2svg/cli.rb CHANGED
@@ -30,6 +30,9 @@ module Text2svg
30
30
  opt.on('--char-size WCHAR,HCHAR,HDPI,VDPI', 'char size set (default "0,0,3000,3000")') do |arg|
31
31
  o.char_size = arg
32
32
  end
33
+ opt.on('--scale NUM', 'scale (default 1)', Numeric) do |arg|
34
+ o.scale = arg
35
+ end
33
36
  }.parse!(ARGV)
34
37
  unless o.font
35
38
  raise ArgumentError, 'require `--font` cli option. see --help'
@@ -7,6 +7,7 @@ module Text2svg
7
7
  :italic,
8
8
  :attribute,
9
9
  :char_size,
10
+ :scale,
10
11
  )
11
12
  DEFAULTS = [
12
13
  nil, # font
@@ -16,6 +17,7 @@ module Text2svg
16
17
  false, # italic
17
18
  nil, # attribute
18
19
  "0,0,3000,3000", # char_size
20
+ 1,
19
21
  ]
20
22
 
21
23
  class << self
@@ -141,33 +141,34 @@ module Text2svg
141
141
  lines.zip(width_by_line).each_with_index do |(line, line_width), index|
142
142
  x = 0r
143
143
  y += if index == 0
144
- f.face[:size][:metrics][:ascender]
144
+ f.face[:size][:metrics][:ascender] * option.scale
145
145
  else
146
- f.line_height
146
+ f.line_height * option.scale
147
147
  end
148
148
  before_char = nil
149
149
 
150
150
  case option.text_align.to_sym
151
151
  when :center
152
- x += (max_width - line_width) / 2r
152
+ x += (max_width - line_width) / 2r * option.scale
153
153
  when :right
154
- x += max_width - line_width
154
+ x += (max_width - line_width) * option.scale
155
155
  when :left
156
156
  # nothing
157
157
  else
158
158
  warn 'text_align must be left,right or center'
159
159
  end
160
160
 
161
- output << %!<g transform="matrix(1,0,0,1,0,#{y.to_i})">\n!
161
+ output << %!<g transform="matrix(1,0,0,1,0,#{y.round})">\n!
162
162
 
163
- x -= min_hori_bearing_x_all
163
+ x -= min_hori_bearing_x_all * option.scale
164
164
  line.each do |cs|
165
- x += f.kerning_unfitted(before_char, cs.char).x.to_i
165
+ x += f.kerning_unfitted(before_char, cs.char).x * option.scale
166
166
  if cs.draw?
167
- output << %! <path transform="matrix(1,0,0,1,#{x.to_i},0)" d="#{cs.outline2d.join(' '.freeze)}"/>\n!
167
+ d = cs.outline2d.map { |cmd, *points| [cmd, *(points.map { |i| i * option.scale })] }
168
+ output << %! <path transform="matrix(1,0,0,1,#{x.round},0)" d="#{d.join(' '.freeze)}"/>\n!
168
169
  end
169
- x += cs.metrics[:horiAdvance]
170
- x += inter_char_space if cs != line.last
170
+ x += cs.metrics[:horiAdvance] * option.scale
171
+ x += inter_char_space * option.scale if cs != line.last
171
172
  before_char = cs.char
172
173
  end
173
174
  output << "</g>\n".freeze
@@ -175,11 +176,11 @@ module Text2svg
175
176
  output << "</g>\n".freeze if option.attribute
176
177
 
177
178
  option_width = 0
178
- option_width += space_width / 1.5 if option.italic
179
+ option_width += (space_width / 1.5 * option.scale) if option.italic
179
180
  Content.new(
180
181
  output,
181
- (max_width + option_width).to_i,
182
- (y.to_i - f.face[:size][:metrics][:descender] * 1.2).ceil,
182
+ ((max_width + option_width) * option.scale).ceil,
183
+ (y - f.face[:size][:metrics][:descender] * 1.2 * option.scale).ceil,
183
184
  notdef_indexes,
184
185
  )
185
186
  end
@@ -1,6 +1,36 @@
1
1
  require 'text2svg/typography'
2
2
 
3
3
  module Text2svgTypographyTest
4
+ def check(t, opt)
5
+ ['ABC', "\n", "\n\nA", "", "A\nB\n\n", "A\n \n\nC", "<", ">", "&", "=", "@", "%", "#", "("].each do |text|
6
+ begin
7
+ c = Text2svg::Typography.build(text, opt)
8
+ rescue => e
9
+ t.log("raise error #{e.class}: #{e.message} with text=\"#{text}\",opt=#{opt}")
10
+ raise
11
+ end
12
+
13
+ unless Text2svg::Content === c
14
+ t.error('return value was break')
15
+ end
16
+
17
+ unless Integer === c.width
18
+ t.error('return value was break')
19
+ end
20
+
21
+ unless Integer === c.height
22
+ t.error('return value was break')
23
+ end
24
+ unless Array === c.notdef_indexes
25
+ t.error('return value was break')
26
+ end
27
+
28
+ unless c.data.encoding == Encoding::UTF_8
29
+ t.error('encoding was changed')
30
+ end
31
+ end
32
+ end
33
+
4
34
  def test_build(t)
5
35
  c = Text2svg::Typography.build(nil, Text2svg::Option.new)
6
36
  unless Text2svg::Content === c
@@ -21,41 +51,17 @@ module Text2svgTypographyTest
21
51
  [false, true].each do |bold|
22
52
  [false, true].each do |italic|
23
53
  ["0,0,0,0", "128,128,100,100"].each do |char_size|
24
- opt = Text2svg::Option.default
25
- opt.font = font
26
- opt.text_align = text_align
27
- opt.encoding = encoding
28
- opt.attribute = attribute
29
- opt.bold = bold
30
- opt.italic = italic
31
- opt.char_size = char_size
32
-
33
- ['ABC', "\n", "\n\nA", "", "A\nB\n\n", "A\n \n\nC", "<", ">", "&", "=", "@", "%", "#", "("].each do |text|
34
- begin
35
- c = Text2svg::Typography.build(text, opt)
36
- rescue => e
37
- t.log("raise error #{e.class}: #{e.message} with text=\"#{text}\",opt=#{opt}")
38
- raise
39
- end
40
-
41
- unless Text2svg::Content === c
42
- t.error('return value was break')
43
- end
44
-
45
- unless Integer === c.width
46
- t.error('return value was break')
47
- end
48
-
49
- unless Integer === c.height
50
- t.error('return value was break')
51
- end
52
- unless Array === c.notdef_indexes
53
- t.error('return value was break')
54
- end
55
-
56
- unless c.data.encoding == Encoding::UTF_8
57
- t.error('encoding was changed')
58
- end
54
+ [1, 0.02].each do |scale|
55
+ opt = Text2svg::Option.default
56
+ opt.font = font
57
+ opt.text_align = text_align
58
+ opt.encoding = encoding
59
+ opt.attribute = attribute
60
+ opt.bold = bold
61
+ opt.italic = italic
62
+ opt.char_size = char_size
63
+ opt.scale = scale
64
+ check(t, opt)
59
65
  end
60
66
  end
61
67
  end
@@ -1,3 +1,3 @@
1
1
  module Text2svg
2
- VERSION = '0.4.3'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text2svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-12 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: freetype
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.6.2
117
+ rubygems_version: 2.5.1
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Build svg path data from font file