text2svg 0.3.6 → 0.4.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: 1d90eb44a01e353a25dcc368cf992346e1c0a9b8
4
- data.tar.gz: f058dd892c5475f56b20c5431bd13ef6615ab4ad
3
+ metadata.gz: 9bfacdff9cb34a8770ff99e984013f4ff9a4f837
4
+ data.tar.gz: 0909e9114da286c14ec1bb577c7ac2c858902ddd
5
5
  SHA512:
6
- metadata.gz: c8d04e7e2dc712884c642cd46eab49f233753fc7bef1924ebdce188ad64e944b6d4a73886c169af3ecee754e1ef4f8d1f927d42088ca7e9c664234a60126b123
7
- data.tar.gz: 443b8559efd03d7bf7c18d07cc11065d8f0fdc1f0ed1e3803db57b84fa3553623c98901a47bc6db349c20908d1f16e330f844fbbb90dffae596b3100af9dc4da
6
+ metadata.gz: aa3d335335590c1c9a76cdd12a2bdd758e14651c76eb5b42c5f8fe064789a3ad5a3daee73e76ae7ff00ee507b496be9639cf9b08ae53e5954b36fb1af02d0879
7
+ data.tar.gz: 137eb22ad7a9be9a9f742d3158d69f78dda6f7bf844bdb38add81e32aff7a4037be6d25ce2e3de7d52d26b696f6057398127d1031dd67d7c3429b323939bfeb2
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  before_install:
3
3
  - sudo apt-get install -qq libfreetype6-dev
4
4
  rvm:
5
- - 2.1.7 # ffi is not support to 2.1.8
5
+ - 2.1.7 # travis-ci issue
6
6
  - 2.2.4
7
7
  - 2.3.0
8
8
  matrix:
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'bundler/gem_tasks'
2
2
  task :test do
3
- sh 'rgot -v'
3
+ sh 'rgot -v --bench .'
4
4
  end
5
5
  task default: [:test]
data/lib/text2svg/cli.rb CHANGED
@@ -5,14 +5,9 @@ require 'text2svg/option'
5
5
  module Text2svg
6
6
  module CLI
7
7
  def start
8
- o = Option.new(
9
- nil, # font
10
- :left, # text_align
11
- Encoding::UTF_8, # encoding
12
- false, # bold
13
- false, # italic
14
- nil, # attribute
15
- )
8
+ # defaults
9
+ o = Option.default
10
+
16
11
  OptionParser.new.tap { |opt|
17
12
  opt.on('-f', '--font FONT', 'font file path (require)') do |arg|
18
13
  o.font = arg
@@ -32,6 +27,9 @@ module Text2svg
32
27
  opt.on('--attribute STRING', 'decorate options (default nil)(e.g. fill="red" stroke-width="100")') do |arg|
33
28
  o.attribute = arg
34
29
  end
30
+ opt.on('--char-size WCHAR,HCHAR,HDPI,VDPI', 'char size set (default "0,0,3000,3000")') do |arg|
31
+ o.char_size = arg
32
+ end
35
33
  }.parse!(ARGV)
36
34
  unless o.font
37
35
  raise ArgumentError, 'require `--font` cli option. see --help'
@@ -6,16 +6,30 @@ module Text2svg
6
6
  :bold,
7
7
  :italic,
8
8
  :attribute,
9
+ :char_size,
9
10
  )
11
+ DEFAULTS = [
12
+ nil, # font
13
+ :left, # text_align
14
+ Encoding::UTF_8, # encoding
15
+ false, # bold
16
+ false, # italic
17
+ nil, # attribute
18
+ "0,0,3000,3000", # char_size
19
+ ]
10
20
 
11
21
  class << self
12
22
  def from_hash(h)
13
- o = new
23
+ o = new(*DEFAULTS)
14
24
  h.to_h.each do |k, v|
15
25
  o[k.to_sym] = v
16
26
  end
17
27
  o
18
28
  end
29
+
30
+ def default
31
+ new(*DEFAULTS)
32
+ end
19
33
  end
20
34
  end
21
35
  end
@@ -41,8 +41,12 @@ module Text2svg
41
41
  unless option.font
42
42
  raise OptionError, 'should set `font\' option'
43
43
  end
44
+ char_sizes = option.char_size.split(',').map(&:to_i)
45
+ unless char_sizes.length == 4
46
+ raise OptionError, 'char-size option should be four integer values'
47
+ end
44
48
  FreeType::API::Font.open(File.expand_path(option.font)) do |f|
45
- f.set_char_size(0, 0, 3000, 3000)
49
+ f.set_char_size(*char_sizes)
46
50
 
47
51
  lines = []
48
52
  line = []
@@ -20,28 +20,31 @@ module Text2svgTypographyTest
20
20
  [nil, 'fill="red"'].each do |attribute|
21
21
  [false, true].each do |bold|
22
22
  [false, true].each do |italic|
23
- opt = Text2svg::Option.new
24
- opt.font = font
25
- opt.text_align = text_align
26
- opt.encoding = encoding
27
- opt.attribute = attribute
28
- opt.bold = bold
29
- opt.italic = italic
23
+ ["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
30
32
 
31
- ['ABC', "\n", "\n\nA", "", "A\nB\n\n", "A\n\n\nC", "<", ">", "&", "=", "@", "%", "#", "("].each do |text|
32
- begin
33
- c = Text2svg::Typography.build(text, opt)
34
- rescue => e
35
- t.log("raise error #{e.class}: #{e.message} with text=\"#{text}\",opt=#{opt}")
36
- raise
37
- end
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
38
40
 
39
- unless Text2svg::Content === c
40
- t.error('return value was break')
41
- end
41
+ unless Text2svg::Content === c
42
+ t.error('return value was break')
43
+ end
42
44
 
43
- unless c.data.encoding == Encoding::UTF_8
44
- t.error('encoding was changed')
45
+ unless c.data.encoding == Encoding::UTF_8
46
+ t.error('encoding was changed')
47
+ end
45
48
  end
46
49
  end
47
50
  end
@@ -61,7 +64,8 @@ module Text2svgTypographyTest
61
64
 
62
65
  def benchmark_build(b)
63
66
  str = [*'!'..'z'].join
64
- opt = Text2svg::Option.new('data/sporq.ttf')
67
+ opt = Text2svg::Option.default
68
+ opt.font = 'data/sporq.ttf'
65
69
  b.reset_timer
66
70
  i = 0
67
71
  while i < b.n
@@ -1,3 +1,3 @@
1
1
  module Text2svg
2
- VERSION = '0.3.6'
2
+ VERSION = '0.4.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.3.6
4
+ version: 0.4.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-03-15 00:00:00.000000000 Z
11
+ date: 2016-04-11 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.1
117
+ rubygems_version: 2.2.5
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Build svg path data from font file