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 +4 -4
- data/.travis.yml +1 -1
- data/Rakefile +1 -1
- data/lib/text2svg/cli.rb +6 -8
- data/lib/text2svg/option.rb +15 -1
- data/lib/text2svg/typography.rb +5 -1
- data/lib/text2svg/typography_test.rb +24 -20
- data/lib/text2svg/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bfacdff9cb34a8770ff99e984013f4ff9a4f837
|
4
|
+
data.tar.gz: 0909e9114da286c14ec1bb577c7ac2c858902ddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa3d335335590c1c9a76cdd12a2bdd758e14651c76eb5b42c5f8fe064789a3ad5a3daee73e76ae7ff00ee507b496be9639cf9b08ae53e5954b36fb1af02d0879
|
7
|
+
data.tar.gz: 137eb22ad7a9be9a9f742d3158d69f78dda6f7bf844bdb38add81e32aff7a4037be6d25ce2e3de7d52d26b696f6057398127d1031dd67d7c3429b323939bfeb2
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
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
|
-
|
9
|
-
|
10
|
-
|
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'
|
data/lib/text2svg/option.rb
CHANGED
@@ -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
|
data/lib/text2svg/typography.rb
CHANGED
@@ -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(
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
41
|
+
unless Text2svg::Content === c
|
42
|
+
t.error('return value was break')
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
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.
|
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
|
data/lib/text2svg/version.rb
CHANGED
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
|
+
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-
|
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.
|
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
|