Class: HarfBuzz::Buffer
- Inherits:
-
Object
- Object
- HarfBuzz::Buffer
- Defined in:
- lib/harfbuzz/buffer.rb
Overview
Wraps hb_buffer_t — text buffer for shaping
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Class Method Summary collapse
- .define_finalizer(obj, ptr) ⇒ Object
-
.empty ⇒ Buffer
Returns the singleton empty buffer.
-
.serialize_format(str) ⇒ Symbol
Converts a format string to a serialize format symbol.
-
.serialize_format_name(fmt) ⇒ String
Converts a serialize format symbol to a string.
-
.serialize_formats ⇒ Array<String>
Returns a list of available serialize format names.
- .wrap_borrowed(ptr) ⇒ Object
- .wrap_owned(ptr) ⇒ Object
Instance Method Summary collapse
-
#add(codepoint, cluster) ⇒ self
Adds a single codepoint with cluster index.
-
#add_codepoints(codepoints, item_offset: 0, item_length: -1)) ⇒ self
Adds an array of Unicode codepoints to the buffer.
-
#add_latin1(text, item_offset: 0, item_length: -1)) ⇒ self
Adds Latin-1 (ISO-8859-1) text to the buffer.
-
#add_utf16(text, item_offset: 0, item_length: -1)) ⇒ self
Adds UTF-16 text to the buffer.
-
#add_utf32(text, item_offset: 0, item_length: -1)) ⇒ self
Adds UTF-32 text to the buffer.
-
#add_utf8(text, item_offset: 0, item_length: -1)) ⇒ self
Adds UTF-8 text to the buffer.
-
#allocation_successful? ⇒ Boolean
True if last allocation was successful.
-
#append(other, start, end_) ⇒ self
Appends part of another buffer.
-
#clear ⇒ self
Clears text content but keeps properties.
-
#cluster_level ⇒ Symbol
Cluster level.
- #cluster_level=(level) ⇒ Object
-
#content_type ⇒ Symbol
Content type (:invalid, :unicode, :glyphs).
- #content_type=(type) ⇒ Object
-
#create_similar ⇒ Buffer
Creates a buffer similar to this one (same properties, empty content).
-
#deserialize_glyphs(str, font: nil, format: :text) ⇒ Boolean
Deserializes glyph data from a string into this buffer.
-
#deserialize_unicode(str, format: :text) ⇒ Boolean
Deserializes Unicode codepoints from a string into this buffer.
-
#diff(other, dottedcircle_glyph, position_fuzz) ⇒ Integer
Computes difference flags between this buffer and another.
-
#direction ⇒ Symbol
Buffer direction (:ltr, :rtl, :ttb, :btt, :invalid).
- #direction=(dir) ⇒ Object
-
#each_glyph {|glyph_id, cluster, x_advance, y_advance, x_offset, y_offset| ... } ⇒ Enumerator, self
Iterates over shaped glyph data without allocating GlyphInfo/GlyphPosition objects.
-
#each_glyph_with_clusters {|glyph_id, cluster, next_cluster, x_advance, y_advance, x_offset, y_offset| ... } ⇒ Enumerator, self
Iterates over shaped glyph data and yields the next distinct cluster without allocating GlyphInfo/GlyphPosition objects.
-
#flags ⇒ Integer
Buffer flags bitmask.
- #flags=(flags) ⇒ Object
-
#glyph_infos ⇒ Array<GlyphInfo>
Array of glyph info structs.
-
#glyph_positions ⇒ Array<GlyphPosition>
Array of glyph position structs.
-
#guess_segment_properties ⇒ self
Guesses direction/script/language from buffer contents.
-
#has_positions? ⇒ Boolean
True if the buffer has glyph position data.
-
#initialize ⇒ Buffer
constructor
Creates a new empty buffer.
- #inspect ⇒ Object
-
#invisible_glyph ⇒ Integer
Invisible glyph ID.
- #invisible_glyph=(glyph) ⇒ Object
-
#language ⇒ FFI::Pointer
Language pointer.
- #language=(lang) ⇒ Object
-
#length ⇒ Integer
(also: #size)
Number of items in buffer.
- #length=(len) ⇒ Object
-
#normalize_glyphs ⇒ self
Normalizes glyph clusters.
-
#not_found_glyph ⇒ Integer
Not-found glyph ID.
- #not_found_glyph=(glyph) ⇒ Object
-
#on_message {|message| ... } ⇒ self
Sets a message callback for debugging/tracing shaping.
-
#pre_allocate(size) ⇒ Boolean
Pre-allocates buffer capacity.
-
#random_state ⇒ Integer
Random state.
- #random_state=(state) ⇒ Object
-
#replacement_codepoint ⇒ Integer
Replacement codepoint for invalid input.
- #replacement_codepoint=(cp) ⇒ Object
-
#reset ⇒ self
Resets all buffer state.
-
#reverse ⇒ self
Reverses buffer contents.
-
#reverse_clusters ⇒ self
Reverses clusters.
-
#reverse_range(start, end_) ⇒ self
Reverses a range of buffer contents.
-
#script ⇒ Integer
Script (hb_script_t value).
- #script=(script) ⇒ Object
-
#segment_properties ⇒ C::HbSegmentPropertiesT
Segment properties struct.
- #segment_properties=(props) ⇒ Object
-
#serialize(font: nil, format: :text, flags: 0) ⇒ String
Serializes buffer contents (glyphs or unicode) to a string representation.
-
#serialize_glyphs(font: nil, format: :text, flags: 0) ⇒ String
Serializes shaped glyphs to a string representation.
-
#serialize_unicode(format: :text, flags: 0) ⇒ String
Serializes Unicode codepoints to a string representation.
-
#unicode_funcs ⇒ UnicodeFuncs
Unicode functions associated with this buffer.
- #unicode_funcs=(ufuncs) ⇒ Object
Constructor Details
#initialize ⇒ Buffer
Creates a new empty buffer
26 27 28 29 30 31 |
# File 'lib/harfbuzz/buffer.rb', line 26 def initialize @ptr = C.hb_buffer_create raise AllocationError, "Failed to create buffer" if @ptr.null? register_finalizer end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
23 24 25 |
# File 'lib/harfbuzz/buffer.rb', line 23 def ptr @ptr end |
Class Method Details
.define_finalizer(obj, ptr) ⇒ Object
595 596 597 598 |
# File 'lib/harfbuzz/buffer.rb', line 595 def self.define_finalizer(obj, ptr) destroy = C.method(:hb_buffer_destroy) ObjectSpace.define_finalizer(obj, proc { destroy.call(ptr) }) end |
.empty ⇒ Buffer
Returns the singleton empty buffer
42 43 44 |
# File 'lib/harfbuzz/buffer.rb', line 42 def self.empty wrap_borrowed(C.hb_buffer_get_empty) end |
.serialize_format(str) ⇒ Symbol
Converts a format string to a serialize format symbol
532 533 534 |
# File 'lib/harfbuzz/buffer.rb', line 532 def self.serialize_format(str) C.hb_buffer_serialize_format_from_string(str, str.bytesize) end |
.serialize_format_name(fmt) ⇒ String
Converts a serialize format symbol to a string
539 540 541 |
# File 'lib/harfbuzz/buffer.rb', line 539 def self.serialize_format_name(fmt) C.hb_buffer_serialize_format_to_string(fmt) end |
.serialize_formats ⇒ Array<String>
Returns a list of available serialize format names
545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/harfbuzz/buffer.rb', line 545 def self.serialize_formats ptr = C.hb_buffer_serialize_list_formats result = [] i = 0 loop do p = ptr.get_pointer(i * FFI::Pointer.size) break if p.null? result << p.read_string i += 1 end result end |
.wrap_borrowed(ptr) ⇒ Object
566 567 568 569 570 571 |
# File 'lib/harfbuzz/buffer.rb', line 566 def self.wrap_borrowed(ptr) obj = allocate obj.instance_variable_set(:@ptr, ptr) obj.instance_variable_set(:@borrowed, true) obj end |
.wrap_owned(ptr) ⇒ Object
559 560 561 562 563 564 |
# File 'lib/harfbuzz/buffer.rb', line 559 def self.wrap_owned(ptr) obj = allocate obj.instance_variable_set(:@ptr, ptr) obj.send(:register_finalizer) obj end |
Instance Method Details
#add(codepoint, cluster) ⇒ self
Adds a single codepoint with cluster index
76 77 78 79 |
# File 'lib/harfbuzz/buffer.rb', line 76 def add(codepoint, cluster) C.hb_buffer_add(@ptr, codepoint, cluster) self end |
#add_codepoints(codepoints, item_offset: 0, item_length: -1)) ⇒ self
Adds an array of Unicode codepoints to the buffer
137 138 139 140 141 142 |
# File 'lib/harfbuzz/buffer.rb', line 137 def add_codepoints(codepoints, item_offset: 0, item_length: -1) mem = FFI::MemoryPointer.new(:uint32, codepoints.size) mem.put_array_of_uint32(0, codepoints) C.hb_buffer_add_codepoints(@ptr, mem, codepoints.size, item_offset, item_length) self end |
#add_latin1(text, item_offset: 0, item_length: -1)) ⇒ self
Adds Latin-1 (ISO-8859-1) text to the buffer
124 125 126 127 128 129 130 |
# File 'lib/harfbuzz/buffer.rb', line 124 def add_latin1(text, item_offset: 0, item_length: -1) encoded = text.encode("ISO-8859-1") mem = FFI::MemoryPointer.new(:uint8, encoded.bytesize) mem.put_bytes(0, encoded) C.hb_buffer_add_latin1(@ptr, mem, encoded.bytesize, item_offset, item_length) self end |
#add_utf16(text, item_offset: 0, item_length: -1)) ⇒ self
Adds UTF-16 text to the buffer
98 99 100 101 102 103 104 |
# File 'lib/harfbuzz/buffer.rb', line 98 def add_utf16(text, item_offset: 0, item_length: -1) encoded = text.encode("UTF-16LE") mem = FFI::MemoryPointer.new(:uint16, encoded.bytesize / 2 + 1) mem.put_bytes(0, encoded) C.hb_buffer_add_utf16(@ptr, mem, encoded.bytesize / 2, item_offset, item_length) self end |
#add_utf32(text, item_offset: 0, item_length: -1)) ⇒ self
Adds UTF-32 text to the buffer
111 112 113 114 115 116 117 |
# File 'lib/harfbuzz/buffer.rb', line 111 def add_utf32(text, item_offset: 0, item_length: -1) encoded = text.encode("UTF-32LE") mem = FFI::MemoryPointer.new(:uint32, encoded.bytesize / 4 + 1) mem.put_bytes(0, encoded) C.hb_buffer_add_utf32(@ptr, mem, encoded.bytesize / 4, item_offset, item_length) self end |
#add_utf8(text, item_offset: 0, item_length: -1)) ⇒ self
Adds UTF-8 text to the buffer
86 87 88 89 90 91 |
# File 'lib/harfbuzz/buffer.rb', line 86 def add_utf8(text, item_offset: 0, item_length: -1) encoded = text.encode("UTF-8") mem = FFI::MemoryPointer.from_string(encoded) C.hb_buffer_add_utf8(@ptr, mem, encoded.bytesize, item_offset, item_length) self end |
#allocation_successful? ⇒ Boolean
Returns true if last allocation was successful.
68 69 70 |
# File 'lib/harfbuzz/buffer.rb', line 68 def allocation_successful? C.from_hb_bool(C.hb_buffer_allocation_successful(@ptr)) end |
#append(other, start, end_) ⇒ self
Appends part of another buffer
149 150 151 152 |
# File 'lib/harfbuzz/buffer.rb', line 149 def append(other, start, end_) C.hb_buffer_append(@ptr, other.ptr, start, end_) self end |
#clear ⇒ self
Clears text content but keeps properties
55 56 57 58 |
# File 'lib/harfbuzz/buffer.rb', line 55 def clear C.hb_buffer_clear_contents(@ptr) self end |
#cluster_level ⇒ Symbol
Returns Cluster level.
235 236 237 |
# File 'lib/harfbuzz/buffer.rb', line 235 def cluster_level C.hb_buffer_get_cluster_level(@ptr) end |
#cluster_level=(level) ⇒ Object
240 241 242 |
# File 'lib/harfbuzz/buffer.rb', line 240 def cluster_level=(level) C.hb_buffer_set_cluster_level(@ptr, level) end |
#content_type ⇒ Symbol
Returns Content type (:invalid, :unicode, :glyphs).
155 156 157 |
# File 'lib/harfbuzz/buffer.rb', line 155 def content_type C.hb_buffer_get_content_type(@ptr) end |
#content_type=(type) ⇒ Object
160 161 162 |
# File 'lib/harfbuzz/buffer.rb', line 160 def content_type=(type) C.hb_buffer_set_content_type(@ptr, type) end |
#create_similar ⇒ Buffer
Creates a buffer similar to this one (same properties, empty content)
35 36 37 38 |
# File 'lib/harfbuzz/buffer.rb', line 35 def create_similar ptr = C.hb_buffer_create_similar(@ptr) self.class.wrap_owned(ptr) end |
#deserialize_glyphs(str, font: nil, format: :text) ⇒ Boolean
Deserializes glyph data from a string into this buffer
506 507 508 509 510 511 512 |
# File 'lib/harfbuzz/buffer.rb', line 506 def deserialize_glyphs(str, font: nil, format: :text) font_ptr = font ? font.ptr : FFI::Pointer::NULL end_ptr = FFI::MemoryPointer.new(:pointer) C.from_hb_bool( C.hb_buffer_deserialize_glyphs(@ptr, str, str.bytesize, end_ptr, font_ptr, format) ) end |
#deserialize_unicode(str, format: :text) ⇒ Boolean
Deserializes Unicode codepoints from a string into this buffer
518 519 520 521 522 523 |
# File 'lib/harfbuzz/buffer.rb', line 518 def deserialize_unicode(str, format: :text) end_ptr = FFI::MemoryPointer.new(:pointer) C.from_hb_bool( C.hb_buffer_deserialize_unicode(@ptr, str, str.bytesize, end_ptr, format) ) end |
#diff(other, dottedcircle_glyph, position_fuzz) ⇒ Integer
Computes difference flags between this buffer and another
457 458 459 |
# File 'lib/harfbuzz/buffer.rb', line 457 def diff(other, dottedcircle_glyph, position_fuzz) C.hb_buffer_diff(@ptr, other.ptr, dottedcircle_glyph, position_fuzz) end |
#direction ⇒ Symbol
Returns Buffer direction (:ltr, :rtl, :ttb, :btt, :invalid).
165 166 167 |
# File 'lib/harfbuzz/buffer.rb', line 165 def direction C.hb_buffer_get_direction(@ptr) end |
#direction=(dir) ⇒ Object
170 171 172 |
# File 'lib/harfbuzz/buffer.rb', line 170 def direction=(dir) C.hb_buffer_set_direction(@ptr, dir) end |
#each_glyph {|glyph_id, cluster, x_advance, y_advance, x_offset, y_offset| ... } ⇒ Enumerator, self
Iterates over shaped glyph data without allocating GlyphInfo/GlyphPosition objects
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/harfbuzz/buffer.rb', line 333 def each_glyph return enum_for(__method__) { length } unless block_given? with_glyph_data do |infos_ptr, positions_ptr, count| i = 0 while i < count info_offset = i * GLYPH_INFO_SIZE position_offset = i * GLYPH_POSITION_SIZE yield infos_ptr.get_uint32(info_offset + GLYPH_INFO_CODEPOINT_OFFSET), infos_ptr.get_uint32(info_offset + GLYPH_INFO_CLUSTER_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_X_ADVANCE_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_Y_ADVANCE_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_X_OFFSET_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_Y_OFFSET_OFFSET) i += 1 end end self end |
#each_glyph_with_clusters {|glyph_id, cluster, next_cluster, x_advance, y_advance, x_offset, y_offset| ... } ⇒ Enumerator, self
Iterates over shaped glyph data and yields the next distinct cluster without allocating GlyphInfo/GlyphPosition objects.
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/harfbuzz/buffer.rb', line 360 def each_glyph_with_clusters return enum_for(__method__) { length } unless block_given? with_glyph_data do |infos_ptr, positions_ptr, count| i = 0 while i < count info_offset = i * GLYPH_INFO_SIZE cluster = infos_ptr.get_uint32(info_offset + GLYPH_INFO_CLUSTER_OFFSET) next_cluster = nil next_run_index = i + 1 while next_run_index < count next_cluster_offset = (next_run_index * GLYPH_INFO_SIZE) + GLYPH_INFO_CLUSTER_OFFSET candidate_cluster = infos_ptr.get_uint32(next_cluster_offset) if candidate_cluster != cluster next_cluster = candidate_cluster break end next_run_index += 1 end while i < next_run_index info_offset = i * GLYPH_INFO_SIZE position_offset = i * GLYPH_POSITION_SIZE yield infos_ptr.get_uint32(info_offset + GLYPH_INFO_CODEPOINT_OFFSET), cluster, next_cluster, positions_ptr.get_int32(position_offset + GLYPH_POSITION_X_ADVANCE_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_Y_ADVANCE_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_X_OFFSET_OFFSET), positions_ptr.get_int32(position_offset + GLYPH_POSITION_Y_OFFSET_OFFSET) i += 1 end end end self end |
#flags ⇒ Integer
Returns Buffer flags bitmask.
225 226 227 |
# File 'lib/harfbuzz/buffer.rb', line 225 def flags C.hb_buffer_get_flags(@ptr) end |
#flags=(flags) ⇒ Object
230 231 232 |
# File 'lib/harfbuzz/buffer.rb', line 230 def flags=(flags) C.hb_buffer_set_flags(@ptr, flags) end |
#glyph_infos ⇒ Array<GlyphInfo>
Returns Array of glyph info structs.
307 308 309 310 311 312 313 314 315 316 |
# File 'lib/harfbuzz/buffer.rb', line 307 def glyph_infos length_ptr = FFI::MemoryPointer.new(:uint) infos_ptr = C.hb_buffer_get_glyph_infos(@ptr, length_ptr) count = length_ptr.read_uint return [] if infos_ptr.null? || count.zero? count.times.map do |i| GlyphInfo.new(infos_ptr + (i * C::HbGlyphInfoT.size)) end end |
#glyph_positions ⇒ Array<GlyphPosition>
Returns Array of glyph position structs.
319 320 321 322 323 324 325 326 327 328 |
# File 'lib/harfbuzz/buffer.rb', line 319 def glyph_positions length_ptr = FFI::MemoryPointer.new(:uint) positions_ptr = C.hb_buffer_get_glyph_positions(@ptr, length_ptr) count = length_ptr.read_uint return [] if positions_ptr.null? || count.zero? count.times.map do |i| GlyphPosition.new(positions_ptr + (i * C::HbGlyphPositionT.size)) end end |
#guess_segment_properties ⇒ self
Guesses direction/script/language from buffer contents
219 220 221 222 |
# File 'lib/harfbuzz/buffer.rb', line 219 def guess_segment_properties C.hb_buffer_guess_segment_properties(@ptr) self end |
#has_positions? ⇒ Boolean
Returns true if the buffer has glyph position data.
403 404 405 |
# File 'lib/harfbuzz/buffer.rb', line 403 def has_positions? C.from_hb_bool(C.hb_buffer_has_positions(@ptr)) end |
#inspect ⇒ Object
525 526 527 |
# File 'lib/harfbuzz/buffer.rb', line 525 def inspect "#<HarfBuzz::Buffer length=#{length} direction=#{direction} content_type=#{content_type}>" end |
#invisible_glyph ⇒ Integer
Returns Invisible glyph ID.
255 256 257 |
# File 'lib/harfbuzz/buffer.rb', line 255 def invisible_glyph C.hb_buffer_get_invisible_glyph(@ptr) end |
#invisible_glyph=(glyph) ⇒ Object
260 261 262 |
# File 'lib/harfbuzz/buffer.rb', line 260 def invisible_glyph=(glyph) C.hb_buffer_set_invisible_glyph(@ptr, glyph) end |
#language ⇒ FFI::Pointer
Returns Language pointer.
185 186 187 |
# File 'lib/harfbuzz/buffer.rb', line 185 def language C.hb_buffer_get_language(@ptr) end |
#language=(lang) ⇒ Object
190 191 192 |
# File 'lib/harfbuzz/buffer.rb', line 190 def language=(lang) C.hb_buffer_set_language(@ptr, lang) end |
#length ⇒ Integer Also known as: size
Returns Number of items in buffer.
295 296 297 |
# File 'lib/harfbuzz/buffer.rb', line 295 def length C.hb_buffer_get_length(@ptr) end |
#length=(len) ⇒ Object
302 303 304 |
# File 'lib/harfbuzz/buffer.rb', line 302 def length=(len) C.hb_buffer_set_length(@ptr, len) end |
#normalize_glyphs ⇒ self
Normalizes glyph clusters
409 410 411 412 |
# File 'lib/harfbuzz/buffer.rb', line 409 def normalize_glyphs C.hb_buffer_normalize_glyphs(@ptr) self end |
#not_found_glyph ⇒ Integer
Returns Not-found glyph ID.
265 266 267 |
# File 'lib/harfbuzz/buffer.rb', line 265 def not_found_glyph C.hb_buffer_get_not_found_glyph(@ptr) end |
#not_found_glyph=(glyph) ⇒ Object
270 271 272 |
# File 'lib/harfbuzz/buffer.rb', line 270 def not_found_glyph=(glyph) C.hb_buffer_set_not_found_glyph(@ptr, glyph) end |
#on_message {|message| ... } ⇒ self
Sets a message callback for debugging/tracing shaping
440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/harfbuzz/buffer.rb', line 440 def (&block) @message_callback = block cb = FFI::Function.new(:int, [:pointer, :pointer, :string, :pointer]) do |_buf_ptr, _font_ptr, , _user_data| block.call() 1 end @message_ffi = cb C.(@ptr, cb, nil, nil) self end |
#pre_allocate(size) ⇒ Boolean
Pre-allocates buffer capacity
63 64 65 |
# File 'lib/harfbuzz/buffer.rb', line 63 def pre_allocate(size) C.from_hb_bool(C.hb_buffer_pre_allocate(@ptr, size)) end |
#random_state ⇒ Integer
Returns Random state.
276 277 278 279 280 281 282 |
# File 'lib/harfbuzz/buffer.rb', line 276 def random_state unless C.respond_to?(:hb_buffer_get_random_state) raise NotImplementedError, "random_state requires HarfBuzz >= 7.2.0" end C.hb_buffer_get_random_state(@ptr) end |
#random_state=(state) ⇒ Object
286 287 288 289 290 291 292 |
# File 'lib/harfbuzz/buffer.rb', line 286 def random_state=(state) unless C.respond_to?(:hb_buffer_set_random_state) raise NotImplementedError, "random_state= requires HarfBuzz >= 7.2.0" end C.hb_buffer_set_random_state(@ptr, state) end |
#replacement_codepoint ⇒ Integer
Returns Replacement codepoint for invalid input.
245 246 247 |
# File 'lib/harfbuzz/buffer.rb', line 245 def replacement_codepoint C.hb_buffer_get_replacement_codepoint(@ptr) end |
#replacement_codepoint=(cp) ⇒ Object
250 251 252 |
# File 'lib/harfbuzz/buffer.rb', line 250 def replacement_codepoint=(cp) C.hb_buffer_set_replacement_codepoint(@ptr, cp) end |
#reset ⇒ self
Resets all buffer state
48 49 50 51 |
# File 'lib/harfbuzz/buffer.rb', line 48 def reset C.hb_buffer_reset(@ptr) self end |
#reverse ⇒ self
Reverses buffer contents
416 417 418 419 |
# File 'lib/harfbuzz/buffer.rb', line 416 def reverse C.hb_buffer_reverse(@ptr) self end |
#reverse_clusters ⇒ self
Reverses clusters
432 433 434 435 |
# File 'lib/harfbuzz/buffer.rb', line 432 def reverse_clusters C.hb_buffer_reverse_clusters(@ptr) self end |
#reverse_range(start, end_) ⇒ self
Reverses a range of buffer contents
425 426 427 428 |
# File 'lib/harfbuzz/buffer.rb', line 425 def reverse_range(start, end_) C.hb_buffer_reverse_range(@ptr, start, end_) self end |
#script ⇒ Integer
Returns Script (hb_script_t value).
175 176 177 |
# File 'lib/harfbuzz/buffer.rb', line 175 def script C.hb_buffer_get_script(@ptr) end |
#script=(script) ⇒ Object
180 181 182 |
# File 'lib/harfbuzz/buffer.rb', line 180 def script=(script) C.hb_buffer_set_script(@ptr, script) end |
#segment_properties ⇒ C::HbSegmentPropertiesT
Returns Segment properties struct.
206 207 208 209 210 |
# File 'lib/harfbuzz/buffer.rb', line 206 def segment_properties props = C::HbSegmentPropertiesT.new C.hb_buffer_get_segment_properties(@ptr, props.to_ptr) props end |
#segment_properties=(props) ⇒ Object
213 214 215 |
# File 'lib/harfbuzz/buffer.rb', line 213 def segment_properties=(props) C.hb_buffer_set_segment_properties(@ptr, props.to_ptr) end |
#serialize(font: nil, format: :text, flags: 0) ⇒ String
Serializes buffer contents (glyphs or unicode) to a string representation
466 467 468 469 470 471 472 473 |
# File 'lib/harfbuzz/buffer.rb', line 466 def serialize(font: nil, format: :text, flags: 0) buf_size = 4096 buf = FFI::MemoryPointer.new(:char, buf_size) written_ptr = FFI::MemoryPointer.new(:uint) font_ptr = font ? font.ptr : FFI::Pointer::NULL C.hb_buffer_serialize(@ptr, 0, length, buf, buf_size, written_ptr, font_ptr, format, flags) buf.read_string(written_ptr.read_uint) end |
#serialize_glyphs(font: nil, format: :text, flags: 0) ⇒ String
Serializes shaped glyphs to a string representation
480 481 482 483 484 485 486 487 |
# File 'lib/harfbuzz/buffer.rb', line 480 def serialize_glyphs(font: nil, format: :text, flags: 0) buf_size = 4096 buf = FFI::MemoryPointer.new(:char, buf_size) written_ptr = FFI::MemoryPointer.new(:uint) font_ptr = font ? font.ptr : FFI::Pointer::NULL C.hb_buffer_serialize_glyphs(@ptr, 0, length, buf, buf_size, written_ptr, font_ptr, format, flags) buf.read_string(written_ptr.read_uint) end |
#serialize_unicode(format: :text, flags: 0) ⇒ String
Serializes Unicode codepoints to a string representation
493 494 495 496 497 498 499 |
# File 'lib/harfbuzz/buffer.rb', line 493 def serialize_unicode(format: :text, flags: 0) buf_size = 4096 buf = FFI::MemoryPointer.new(:char, buf_size) written_ptr = FFI::MemoryPointer.new(:uint) C.hb_buffer_serialize_unicode(@ptr, 0, length, buf, buf_size, written_ptr, format, flags) buf.read_string(written_ptr.read_uint) end |
#unicode_funcs ⇒ UnicodeFuncs
Returns Unicode functions associated with this buffer.
195 196 197 198 |
# File 'lib/harfbuzz/buffer.rb', line 195 def unicode_funcs ptr = C.hb_buffer_get_unicode_funcs(@ptr) UnicodeFuncs.wrap_borrowed(ptr) end |
#unicode_funcs=(ufuncs) ⇒ Object
201 202 203 |
# File 'lib/harfbuzz/buffer.rb', line 201 def unicode_funcs=(ufuncs) C.hb_buffer_set_unicode_funcs(@ptr, ufuncs.ptr) end |