text2svg 0.1.0 → 0.1.1

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: 9bda63aa25ac6727ef210af1f40414c3b7d120b7
4
- data.tar.gz: 19469eeca0f2b0308345d6f60b7b94fdd77b9d64
3
+ metadata.gz: 4ca9a26a917f6eb21d00b9776e25080e1025adbf
4
+ data.tar.gz: 7e83538306525d6b741f978fde59f69911e066e6
5
5
  SHA512:
6
- metadata.gz: 06a6b8ad39765e73045d46fccc6880b337b7f61d0416a7d257a87d50181add2a2529b3567f6539aec822c5b82200ee73497bc8af8a103485d8350e5594bc65e3
7
- data.tar.gz: b93fdce03dfee133362ce6e0fdeda849f7f631f4a01d340a807f1ea1592e348608e96cf6d335ed044fa08bb93a4a8c6e058bd59fa26d4b5ed88247fa78453532
6
+ metadata.gz: 7d8ec9d4ff1857f2718ee3cb3a0d0d29cd1a9b91116a9faf5603922089ec8d35b12fde1b0b24f302250b323758363ed8483451c48717e5850578a1ebcab96dbb
7
+ data.tar.gz: 56a9b1e77140fae8c73e9cfcd9a29183c310948552312495f71e28dc2e6e3ad40c8d7f54d1ff72cc386e975a07a7ba7a6beb3d357bca0ef5b812590a10754bdd
@@ -3,6 +3,9 @@ require 'text2svg/outline2d'
3
3
  require 'text2svg/option'
4
4
 
5
5
  module Text2svg
6
+ class OptionError < StandardError
7
+ end
8
+
6
9
  class Typography
7
10
  WHITESPACE = /[[:space:]]/
8
11
  IDEOGRAPHIC_SPACE = /[\u{3000}]/
@@ -15,7 +18,6 @@ module Text2svg
15
18
  if Hash === option
16
19
  option = Option.from_hash(option)
17
20
  end
18
- option.encoding ||= Encoding::UTF_8
19
21
  content = path(text, option)
20
22
  svg = %(<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 #{content.width} #{content.height}">\n)
21
23
  svg << "<title>#{text}</title>\n"
@@ -28,12 +30,17 @@ module Text2svg
28
30
  if Hash === option
29
31
  option = Option.from_hash(option)
30
32
  end
31
- return Content.new("", 0, 0) if text.empty?
33
+ text = String.try_convert(text)
34
+ return Content.new('', 0, 0) if text.nil? || text.empty?
32
35
 
33
36
  option.encoding ||= Encoding::UTF_8
37
+ option.text_align ||= :left
34
38
  text.force_encoding(option.encoding).encode!(Encoding::UTF_8)
35
39
 
36
40
  notdef_indexes = []
41
+ unless option.font
42
+ raise OptionError, 'should be set `font\' option'
43
+ end
37
44
  FreeType::API::Font.open(File.expand_path(option.font)) do |f|
38
45
  f.set_char_size(0, 0, 3000, 3000)
39
46
 
@@ -0,0 +1,55 @@
1
+ require 'text2svg/typography'
2
+
3
+ module Text2svgTypographyTest
4
+ def test_build(t)
5
+ c = Text2svg::Typography.build(nil, Text2svg::Option.new)
6
+ unless Text2svg::Content === c
7
+ t.error('return value was break')
8
+ end
9
+
10
+ begin
11
+ Text2svg::Typography.build('a', Text2svg::Option.new)
12
+ rescue Text2svg::OptionError
13
+ else
14
+ t.error('error conditions was changed')
15
+ end
16
+
17
+ opt = Text2svg::Option.new(
18
+ '/Library/Fonts/Times New Roman.ttf',
19
+ nil,
20
+ )
21
+ [nil, :left, :right, :center].each do |text_align|
22
+ opt.text_align = text_align
23
+ [Encoding::UTF_8, Encoding::ASCII_8BIT].each do |encoding|
24
+ opt.encoding = encoding
25
+ [false, true].each do |bold|
26
+ opt.bold = bold
27
+ [false, true].each do |italic|
28
+ opt.italic = italic
29
+ begin
30
+ c = Text2svg::Typography.build("\u{0041}", opt)
31
+ rescue
32
+ t.log(opt)
33
+ raise
34
+ end
35
+
36
+ unless Text2svg::Content === c
37
+ t.error('return value was break')
38
+ end
39
+
40
+ unless c.data.encoding == Encoding::UTF_8
41
+ t.error('encoding was changed')
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def test_path(t)
50
+ c = Text2svg::Typography.path(nil, Text2svg::Option.new)
51
+ unless Text2svg::Content === c
52
+ t.error('return value was break')
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Text2svg
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-28 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: freetype
@@ -90,6 +90,7 @@ files:
90
90
  - lib/text2svg/option.rb
91
91
  - lib/text2svg/outline2d.rb
92
92
  - lib/text2svg/typography.rb
93
+ - lib/text2svg/typography_test.rb
93
94
  - lib/text2svg/version.rb
94
95
  - text2svg.gemspec
95
96
  homepage: https://github.com/ksss/text2svg