Module: FreeTypeApiTest
- Includes:
- FreeType::API
- Defined in:
- lib/freetype/api_test.rb
Instance Method Summary collapse
- #font_open ⇒ Object
- #test_Font(t) ⇒ Object
- #test_glyph(t) ⇒ Object
- #test_library_version(t) ⇒ Object
- #test_outline(t) ⇒ Object
Methods included from FreeType::API
Instance Method Details
#font_open ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/freetype/api_test.rb', line 6 def font_open ['data/Prida01.otf', 'data/Starjedi.ttf'].each do |font| Font.open(font) do |f| yield f, font end end end |
#test_Font(t) ⇒ Object
24 25 26 27 28 29 30 31 32 33 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 74 75 76 77 |
# File 'lib/freetype/api_test.rb', line 24 def test_Font(t) font = nil ret = Font.open('data/Prida01.otf') do |f| font = f :abc end if font.nil? t.error('cannot get FT_Library in `open` with block') end if ret != :abc t.error 'want to return last value in block' end font_open do |f, _font| if f.char_index('a') == 0 t.error('ascii char not defined this font') end if f.char_index('㍿') != 0 t.error("I don't know why set character was defined in font") end v = f.kerning('A', 'W') unless v t.error('#kerning return object was changed') end unless Fixnum === v.x && Fixnum === v.y t.error('Not vector object. Check spec for FT_Get_Kerning()') end f.set_char_size(0, 0, 300, 300) bbox = f.bbox unless BBox === bbox t.error('FreeType::API::Face#bbox return value was break') end unless 0 < f.line_height t.error('Not expected behavior') end unless Glyph === f.glyph('a') t.error 'return value was break' end unless 0 < f.line_height t.error('Not expected behavior') end unless Glyph === f.notdef t.error 'return value was break' end end end |
#test_glyph(t) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/freetype/api_test.rb', line 79 def test_glyph(t) font_open do |f| f.set_char_size(0, 0, 300, 300) table = { 'a' => nil, 'b' => nil, 'c' => nil, 'd' => nil } table.each do |char, _| glyph = f.glyph(char) metrics = glyph.metrics unless FreeType::C::FT_Glyph_Metrics === metrics t.error 'return value was break' end char_width = glyph.char_width unless Fixnum === char_width t.error 'return value was break' end outline = glyph.outline unless Outline === outline t.error('FreeType::API::Face#outline return value was break') end ret = glyph.bold unless ret.nil? t.error SystemCallError.new(FFI.errno). end ret = glyph.italic unless ret.nil? t.error SystemCallError.new(FFI.errno). end end end end |
#test_library_version(t) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/freetype/api_test.rb', line 14 def test_library_version(t) v = FreeType::API.library_version unless String === v t.error 'return value was break' end unless /\A\d+.\d+.\d+\z/ =~ v t.error "version format was break got #{v}" end end |
#test_outline(t) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/freetype/api_test.rb', line 114 def test_outline(t) font_open do |f| f.set_char_size(0, 0, 300, 300) table = { 'a' => nil, 'b' => nil, 'c' => nil, 'd' => nil } table.each do |char, _| outline = f.glyph(char).outline unless 0 < outline.points.length t.error('FT_Outline.points get failed from ffi') end unless outline.points.all? { |i| Point === i } t.error('Miss array of FreeType::API::Outline#points objects assignment') end unless outline..all? { |i| Fixnum === i } t.error('Got values miss assigned from ffi') end unless outline.contours.all? { |i| Fixnum === i } t.error('Got values miss assigned from ffi') end unless outline.svg_path_data.empty?.! t.error('Could not get svg path data form outline') end table[char] = outline.points.map(&:x) end if table.values.uniq.length != table.length t.error 'char reference miss' end end end |