Module: Text2svgTypographyTest
- Defined in:
- lib/text2svg/typography_test.rb
Instance Method Summary collapse
Instance Method Details
#benchmark_build(b) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/text2svg/typography_test.rb', line 82 def benchmark_build(b) str = [*'!'..'z'].join opt = Text2svg::Option.default opt.font = 'data/sporq.ttf' b.reset_timer i = 0 while i < b.n Text2svg::Typography.build(str, opt) i += 1 end end |
#check(t, opt) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/text2svg/typography_test.rb', line 4 def check(t, opt) ['ABC', "\n", "\n\nA", "", "A\nB\n\n", "A\n \n\nC", "<", ">", "&", "=", "@", "%", "#", "("].each do |text| begin c = Text2svg::Typography.build(text, opt) rescue => e t.log("raise error #{e.class}: #{e.message} with text=\"#{text}\",opt=#{opt}") raise end unless Text2svg::Content === c t.error('return value was break') end unless Integer === c.width t.error('return value was break') end unless Integer === c.height t.error('return value was break') end unless Array === c.notdef_indexes t.error('return value was break') end unless c.data.encoding == Encoding::UTF_8 t.error('encoding was changed') end end end |
#test_build(t) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/text2svg/typography_test.rb', line 34 def test_build(t) c = Text2svg::Typography.build(nil, Text2svg::Option.new) unless Text2svg::Content === c t.error('return value was break') end begin Text2svg::Typography.build('a', Text2svg::Option.new) rescue Text2svg::OptionError else t.error('error conditions was changed') end Dir["data/*"].grep(/otf|ttf/).each do |font| [nil, :left, :right, :center].each do |text_align| [Encoding::UTF_8, Encoding::ASCII_8BIT].each do |encoding| [nil, 'fill="red"'].each do |attribute| [false, true].each do |bold| [false, true].each do |italic| ["0,0,0,0", "128,128,100,100"].each do |char_size| [1, 0.02].each do |scale| opt = Text2svg::Option.default opt.font = font opt.text_align = text_align opt.encoding = encoding opt.attribute = attribute opt.bold = bold opt.italic = italic opt.char_size = char_size opt.scale = scale check(t, opt) end end end end end end end end end |
#test_path(t) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/text2svg/typography_test.rb', line 75 def test_path(t) c = Text2svg::Typography.path(nil, Text2svg::Option.new) unless Text2svg::Content === c t.error('return value was break') end end |