Class: Harfbuzz::Buffer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#define_finalizer, finalize

Constructor Details

#initializeBuffer

Returns a new instance of Buffer.



88
89
90
91
# File 'lib/harfbuzz/buffer.rb', line 88

def initialize
  @hb_buffer = Harfbuzz.hb_buffer_create
  define_finalizer(:hb_buffer_destroy, @hb_buffer)
end

Instance Attribute Details

#hb_bufferObject (readonly)

Returns the value of attribute hb_buffer.



86
87
88
# File 'lib/harfbuzz/buffer.rb', line 86

def hb_buffer
  @hb_buffer
end

Instance Method Details

#add_utf8(text, offset = 0, length = -1)) ⇒ Object



93
94
95
96
97
98
# File 'lib/harfbuzz/buffer.rb', line 93

def add_utf8(text, offset=0, length=-1)
  raise "expected text in UTF-8 encoding, but received #{text.encoding}" unless text.encoding == Encoding::UTF_8
  text_ptr = FFI::MemoryPointer.new(:char, text.bytesize)
  text_ptr.put_bytes(0, text)
  Harfbuzz.hb_buffer_add_utf8(@hb_buffer, text_ptr, text.bytesize, offset, length)
end

#get_glyph_infosObject



112
113
114
115
116
117
118
119
# File 'lib/harfbuzz/buffer.rb', line 112

def get_glyph_infos
  length_ptr = FFI::MemoryPointer.new(:uint, 1)
  info_ptr = Harfbuzz.hb_buffer_get_glyph_infos(@hb_buffer, length_ptr)
  length = length_ptr.read_uint
  length.times.map do |i|
    GlyphInfo.new(info_ptr + (i * GlyphInfo.size))
  end
end

#get_glyph_positionsObject



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

def get_glyph_positions
  length_ptr = FFI::MemoryPointer.new(:uint, 1)
  positions_ptr = Harfbuzz.hb_buffer_get_glyph_positions(@hb_buffer, length_ptr)
  length = length_ptr.read_uint
  length.times.map do |i|
    GlyphPosition.new(positions_ptr + (i * GlyphPosition.size))
  end
end

#guess_segment_propertiesObject



100
101
102
# File 'lib/harfbuzz/buffer.rb', line 100

def guess_segment_properties
  Harfbuzz.hb_buffer_guess_segment_properties(@hb_buffer)
end

#lengthObject



108
109
110
# File 'lib/harfbuzz/buffer.rb', line 108

def length
  Harfbuzz.hb_buffer_get_length(@hb_buffer)
end

#normalize_glyphsObject



104
105
106
# File 'lib/harfbuzz/buffer.rb', line 104

def normalize_glyphs
  Harfbuzz.hb_buffer_normalize_glyphs(@hb_buffer)
end