Class: FreeType::API::Font

Inherits:
Object
  • Object
show all
Extended by:
IOInterface
Includes:
C
Defined in:
lib/freetype/api.rb

Constant Summary

Constants included from C

C::FT_ENC_TAG, C::FT_Encoding, C::FT_Glyph_Format, C::FT_IMAGE_TAG, C::FT_Kerning_Mode, C::FT_LOAD_COLOR, C::FT_LOAD_COMPUTE_METRICS, C::FT_LOAD_CROP_BITMAP, C::FT_LOAD_DEFAULT, C::FT_LOAD_FORCE_AUTOHINT, C::FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH, C::FT_LOAD_IGNORE_TRANSFORM, C::FT_LOAD_LINEAR_DESIGN, C::FT_LOAD_MONOCHROME, C::FT_LOAD_NO_AUTOHINT, C::FT_LOAD_NO_BITMAP, C::FT_LOAD_NO_HINTING, C::FT_LOAD_NO_RECURSE, C::FT_LOAD_NO_SCALE, C::FT_LOAD_PEDANTIC, C::FT_LOAD_RENDER, C::FT_LOAD_VERTICAL_LAYOUT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IOInterface

open

Methods included from C::LazyAttach

#attach_function

Constructor Details

#initialize(font_path) ⇒ Font

Returns a new instance of Font.



43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Attribute Details

#faceObject (readonly)

Returns the value of attribute face.



42
43
44
# File 'lib/freetype/api.rb', line 42

def face
  @face
end

Instance Method Details

#bboxObject



95
96
97
98
# 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) ⇒ Object



87
88
89
# File 'lib/freetype/api.rb', line 87

def char_index(char)
  FT_Get_Char_Index(@face, char.ord)
end

#closeObject



56
57
58
59
60
61
62
# 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) ⇒ Object

TODO Should be use FT_Get_Glyph and FT_Done_Glyph Because return value will be change after call FT_Load_Char



82
83
84
85
# File 'lib/freetype/api.rb', line 82

def glyph(char)
  load_char(char)
  Glyph.new(@face[:glyph])
end

#kerning(before_char, after_char) ⇒ Object Also known as: kerning_default



100
101
102
# File 'lib/freetype/api.rb', line 100

def kerning(before_char, after_char)
  get_kerning(before_char, after_char, :FT_KERNING_DEFAULT)
end

#kerning_unfitted(before_char, after_char) ⇒ Object



105
106
107
# 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) ⇒ Object



109
110
111
# 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_heightObject



91
92
93
# File 'lib/freetype/api.rb', line 91

def line_height
  @face[:size][:metrics][:height]
end

#notdefObject

TODO: Should be use FT_Get_Glyph



75
76
77
# File 'lib/freetype/api.rb', line 75

def notdef
  glyph("\x00".freeze)
end

#select_charmap(enc_code) ⇒ Object



64
65
66
67
# 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) ⇒ Object



69
70
71
72
# 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