class FreeType::API::Font
Attributes
face[R]
Public Class Methods
new(font_path)
click to toggle source
# File lib/freetype/api.rb, line 43 def initialize(font_path) @library = ::FFI::MemoryPointer.new(:pointer) err = FT_Init_FreeType(@library) raise FreeType::Error.find(err) unless err == 0 @font_path = font_path f = ::FFI::MemoryPointer.new(:pointer) err = FT_New_Face(@library.get_pointer(0), @font_path, 0, f) raise FreeType::Error.find(err) unless err == 0 @face = FT_FaceRec.new(f.get_pointer(0)) end
Public Instance Methods
bbox()
click to toggle source
# File lib/freetype/api.rb, line 95 def bbox bbox = @face[:bbox] BBox.new(bbox[:xMin], bbox[:xMax], bbox[:yMin], bbox[:yMax]) end
char_index(char)
click to toggle source
# File lib/freetype/api.rb, line 87 def char_index(char) FT_Get_Char_Index(@face, char.ord) end
close()
click to toggle source
# File lib/freetype/api.rb, line 56 def close err = FT_Done_Face(@face) raise FreeType::Error.find(err) unless err == 0 err = FT_Done_Library(@library.get_pointer(0)) raise FreeType::Error.find(err) unless err == 0 end
glyph(char)
click to toggle source
TODO Should be use FT_Get_Glyph and FT_Done_Glyph Because return value will be change after call FT_Load_Char
# File lib/freetype/api.rb, line 82 def glyph(char) load_char(char) Glyph.new(@face[:glyph]) end
kerning(before_char, after_char)
click to toggle source
# File lib/freetype/api.rb, line 100 def kerning(before_char, after_char) get_kerning(before_char, after_char, :FT_KERNING_DEFAULT) end
Also aliased as: kerning_default
kerning_unfitted(before_char, after_char)
click to toggle source
# File lib/freetype/api.rb, line 105 def kerning_unfitted(before_char, after_char) get_kerning(before_char, after_char, :FT_KERNING_UNFITTED) end
kerning_unscaled(before_char, after_char)
click to toggle source
# File lib/freetype/api.rb, line 109 def kerning_unscaled(before_char, after_char) get_kerning(before_char, after_char, :FT_KERNING_UNSCALED) end
line_height()
click to toggle source
# File lib/freetype/api.rb, line 91 def line_height @face[:size][:metrics][:height] end
notdef()
click to toggle source
TODO: Should be use FT_Get_Glyph
# File lib/freetype/api.rb, line 75 def notdef glyph("\x00".freeze) end
select_charmap(enc_code)
click to toggle source
# File lib/freetype/api.rb, line 64 def select_charmap(enc_code) err = FT_Select_Charmap(@face, enc_code) raise FreeType::Error.find(err) unless err == 0 end
set_char_size(char_width, char_height, horz_resolution, vert_resolution)
click to toggle source
# File lib/freetype/api.rb, line 69 def set_char_size(char_width, char_height, horz_resolution, vert_resolution) err = FT_Set_Char_Size(@face, char_width, char_height, horz_resolution, vert_resolution) raise FreeType::Error.find(err) unless err == 0 end
Private Instance Methods
get_kerning(before_char, after_char, kerning_mode)
click to toggle source
# File lib/freetype/api.rb, line 115 def get_kerning(before_char, after_char, kerning_mode) if before_char.nil? || before_char == ''.freeze || after_char.nil? || after_char == ''.freeze return Vector.new(0, 0) end v = FT_Vector.new err = FT_Get_Kerning( @face, char_index(before_char), char_index(after_char), kerning_mode, v, ) raise FreeType::Error.find(err) unless err == 0 Vector.new(v[:x], v[:y]) end
load_char(char)
click to toggle source
# File lib/freetype/api.rb, line 133 def load_char(char) err = FT_Load_Char(@face, char.ord, FreeType::C::FT_LOAD_DEFAULT) unless err == 0 e = FreeType::Error.find(err) if FreeType::Error::Invalid_Size_Handle === e warn 'should be call FT_Set_Char_Size before FT_Load_Char' end raise e end end