Class: Harfbuzz::Font

Inherits:
Base
  • Object
show all
Defined in:
lib/harfbuzz/font.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#define_finalizer, finalize

Constructor Details

#initialize(face) ⇒ Font

Returns a new instance of Font.



123
124
125
126
127
128
# File 'lib/harfbuzz/font.rb', line 123

def initialize(face)
  @hb_font = Harfbuzz.hb_font_create(face.hb_face)
  Harfbuzz.hb_font_set_scale(@hb_font, face.upem, face.upem)
  Harfbuzz.hb_ft_font_set_funcs(@hb_font)
  define_finalizer(:hb_font_destroy, @hb_font)
end

Instance Attribute Details

#hb_fontObject (readonly)

Returns the value of attribute hb_font.



121
122
123
# File 'lib/harfbuzz/font.rb', line 121

def hb_font
  @hb_font
end

Instance Method Details

#extentsObject



192
193
194
# File 'lib/harfbuzz/font.rb', line 192

def extents
  [h_extents, v_extents]
end

#extents_for_direction(direction) ⇒ Object



196
197
198
199
200
201
# File 'lib/harfbuzz/font.rb', line 196

def extents_for_direction(direction)
  extents = FontExtents.new
  func = "hb_font_get_#{direction}_extents".to_sym
  Harfbuzz.send(func, @hb_font, extents)
  extents
end

#glyph_extents(codepoint) ⇒ Object



176
177
178
179
180
# File 'lib/harfbuzz/font.rb', line 176

def glyph_extents(codepoint)
  glyph_extents = GlyphExtents.new
  Harfbuzz.hb_font_get_glyph_extents(@hb_font, codepoint, glyph_extents)
  glyph_extents
end

#glyph_from_name(name) ⇒ Object



165
166
167
168
169
170
171
172
173
174
# File 'lib/harfbuzz/font.rb', line 165

def glyph_from_name(name)
  name_ptr = FFI::MemoryPointer.new(:char, name.bytesize)
  name_ptr.put_bytes(0, name)
  glyph_ptr = FFI::MemoryPointer.new(:uint, 1)
  if Harfbuzz.hb_font_get_glyph_from_name(@hb_font, name_ptr, name.length, glyph_ptr)
    glyph_ptr.read_uint
  else
    nil
  end
end

#glyph_name(glyph) ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/harfbuzz/font.rb', line 156

def glyph_name(glyph)
  string_ptr = FFI::MemoryPointer.new(:char, 20)
  if Harfbuzz.hb_font_get_glyph_name(@hb_font, glyph, string_ptr, 20)
    string_ptr.get_string(0, 20)
  else
    nil
  end
end

#glyph_to_string(glyph) ⇒ Object



150
151
152
153
154
# File 'lib/harfbuzz/font.rb', line 150

def glyph_to_string(glyph)
  string_ptr = FFI::MemoryPointer.new(:char, 20)
  Harfbuzz.hb_font_glyph_to_string(@hb_font, glyph, string_ptr, 20)
  string_ptr.get_string(0, 20)
end

#h_extentsObject



184
185
186
# File 'lib/harfbuzz/font.rb', line 184

def h_extents
  extents_for_direction(:h)
end

#ppemObject



140
141
142
143
144
145
146
147
148
# File 'lib/harfbuzz/font.rb', line 140

def ppem
  ppem_x_ptr = FFI::MemoryPointer.new(:uint, 1)
  ppem_y_ptr = FFI::MemoryPointer.new(:uint, 1)
  Harfbuzz.hb_font_get_ppem(@hb_font, ppem_x_ptr, ppem_y_ptr)
  [
    ppem_x_ptr.read_uint,
    ppem_y_ptr.read_uint,
  ]
end

#scaleObject



130
131
132
133
134
135
136
137
138
# File 'lib/harfbuzz/font.rb', line 130

def scale
  x_scale_ptr = FFI::MemoryPointer.new(:int, 1)
  y_scale_ptr = FFI::MemoryPointer.new(:int, 1)
  Harfbuzz.hb_font_get_scale(@hb_font, x_scale_ptr, y_scale_ptr)
  [
    x_scale_ptr.read_int,
    y_scale_ptr.read_int,
  ]
end

#v_extentsObject



188
189
190
# File 'lib/harfbuzz/font.rb', line 188

def v_extents
  extents_for_direction(:v)
end