Class: HarfBuzz::UnicodeFuncs
- Inherits:
-
Object
- Object
- HarfBuzz::UnicodeFuncs
- Defined in:
- lib/harfbuzz/unicode_funcs.rb
Overview
Wraps hb_unicode_funcs_t — Unicode property callbacks
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Class Method Summary collapse
-
.default ⇒ UnicodeFuncs
Returns the default Unicode functions.
- .define_finalizer(obj, ptr) ⇒ Object
-
.empty ⇒ UnicodeFuncs
Returns the empty Unicode functions.
- .wrap_borrowed(ptr) ⇒ Object
- .wrap_owned(ptr) ⇒ Object
Instance Method Summary collapse
-
#combining_class(cp) ⇒ Integer
Queries the combining class of a codepoint.
-
#compose(a, b) ⇒ Integer?
Composes two codepoints into one.
-
#decompose(cp) ⇒ Array<Integer>?
Decomposes a codepoint into two.
-
#general_category(cp) ⇒ Symbol
Queries the general category of a codepoint.
-
#immutable? ⇒ Boolean
True if immutable.
-
#initialize(parent = nil) ⇒ UnicodeFuncs
constructor
Creates a new UnicodeFuncs, optionally inheriting from a parent.
- #inspect ⇒ Object
-
#make_immutable! ⇒ self
Makes immutable.
-
#mirroring(cp) ⇒ Integer
Queries the mirror codepoint.
-
#on_combining_class {|codepoint| ... } ⇒ Object
Sets a custom combining_class function.
-
#on_compose {|a, b| ... } ⇒ Object
Sets a custom compose function.
-
#on_decompose {|ab| ... } ⇒ Object
Sets a custom decompose function.
-
#on_general_category {|codepoint| ... } ⇒ Object
Sets a custom general_category function.
-
#on_mirroring {|codepoint| ... } ⇒ Object
Sets a custom mirroring function.
-
#on_script {|codepoint| ... } ⇒ Object
Sets a custom script function.
-
#parent ⇒ UnicodeFuncs
Returns the parent functions.
-
#script(cp) ⇒ Integer
Queries the script of a codepoint.
Constructor Details
#initialize(parent = nil) ⇒ UnicodeFuncs
Creates a new UnicodeFuncs, optionally inheriting from a parent
10 11 12 13 14 15 16 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 10 def initialize(parent = nil) parent_ptr = parent ? parent.ptr : C.hb_unicode_funcs_get_default @ptr = C.hb_unicode_funcs_create(parent_ptr) raise AllocationError, "Failed to create unicode_funcs" if @ptr.null? HarfBuzz::UnicodeFuncs.define_finalizer(self, @ptr) end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
6 7 8 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 6 def ptr @ptr end |
Class Method Details
.default ⇒ UnicodeFuncs
Returns the default Unicode functions
20 21 22 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 20 def self.default wrap_borrowed(C.hb_unicode_funcs_get_default) end |
.define_finalizer(obj, ptr) ⇒ Object
196 197 198 199 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 196 def self.define_finalizer(obj, ptr) destroy = C.method(:hb_unicode_funcs_destroy) ObjectSpace.define_finalizer(obj, proc { destroy.call(ptr) }) end |
.empty ⇒ UnicodeFuncs
Returns the empty Unicode functions
26 27 28 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 26 def self.empty wrap_borrowed(C.hb_unicode_funcs_get_empty) end |
.wrap_borrowed(ptr) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 189 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
182 183 184 185 186 187 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 182 def self.wrap_owned(ptr) obj = allocate obj.instance_variable_set(:@ptr, ptr) define_finalizer(obj, ptr) obj end |
Instance Method Details
#combining_class(cp) ⇒ Integer
Queries the combining class of a codepoint
140 141 142 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 140 def combining_class(cp) C.hb_unicode_combining_class(@ptr, cp) end |
#compose(a, b) ⇒ Integer?
Composes two codepoints into one
162 163 164 165 166 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 162 def compose(a, b) ab_ptr = FFI::MemoryPointer.new(:uint32) ok = C.hb_unicode_compose(@ptr, a, b, ab_ptr) ok.zero? ? nil : ab_ptr.read_uint32 end |
#decompose(cp) ⇒ Array<Integer>?
Decomposes a codepoint into two
171 172 173 174 175 176 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 171 def decompose(cp) a_ptr = FFI::MemoryPointer.new(:uint32) b_ptr = FFI::MemoryPointer.new(:uint32) ok = C.hb_unicode_decompose(@ptr, cp, a_ptr, b_ptr) ok.zero? ? nil : [a_ptr.read_uint32, b_ptr.read_uint32] end |
#general_category(cp) ⇒ Symbol
Queries the general category of a codepoint
133 134 135 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 133 def general_category(cp) C.hb_unicode_general_category(@ptr, cp) end |
#immutable? ⇒ Boolean
Returns true if immutable.
37 38 39 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 37 def immutable? C.from_hb_bool(C.hb_unicode_funcs_is_immutable(@ptr)) end |
#inspect ⇒ Object
178 179 180 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 178 def inspect "#<HarfBuzz::UnicodeFuncs immutable=#{immutable?}>" end |
#make_immutable! ⇒ self
Makes immutable
43 44 45 46 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 43 def make_immutable! C.hb_unicode_funcs_make_immutable(@ptr) self end |
#mirroring(cp) ⇒ Integer
Queries the mirror codepoint
147 148 149 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 147 def mirroring(cp) C.hb_unicode_mirroring(@ptr, cp) end |
#on_combining_class {|codepoint| ... } ⇒ Object
Sets a custom combining_class function
62 63 64 65 66 67 68 69 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 62 def on_combining_class(&block) @combining_class_callback = block cb = FFI::Function.new(:uint, [:pointer, :uint32, :pointer]) do |_ufuncs, cp, _user_data| block.call(cp) end @combining_class_ffi = cb C.hb_unicode_funcs_set_combining_class_func(@ptr, cb, nil, nil) end |
#on_compose {|a, b| ... } ⇒ Object
Sets a custom compose function
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 95 def on_compose(&block) @compose_callback = block cb = FFI::Function.new(:int, [:pointer, :uint32, :uint32, :pointer, :pointer]) do |_ufuncs, a, b, ab_ptr, _user_data| result = block.call(a, b) if result ab_ptr.write_uint32(result) 1 else 0 end end @compose_ffi = cb C.hb_unicode_funcs_set_compose_func(@ptr, cb, nil, nil) end |
#on_decompose {|ab| ... } ⇒ Object
Sets a custom decompose function
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 113 def on_decompose(&block) @decompose_callback = block cb = FFI::Function.new(:int, [:pointer, :uint32, :pointer, :pointer, :pointer]) do |_ufuncs, ab, a_ptr, b_ptr, _user_data| result = block.call(ab) if result a_ptr.write_uint32(result[0]) b_ptr.write_uint32(result[1]) 1 else 0 end end @decompose_ffi = cb C.hb_unicode_funcs_set_decompose_func(@ptr, cb, nil, nil) end |
#on_general_category {|codepoint| ... } ⇒ Object
Sets a custom general_category function
50 51 52 53 54 55 56 57 58 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 50 def on_general_category(&block) @general_category_callback = block cb = FFI::Function.new(:int, [:pointer, :uint32, :pointer]) do |_ufuncs, cp, _user_data| result = block.call(cp) C::UnicodeGeneralCategory[result] || result end @general_category_ffi = cb C.hb_unicode_funcs_set_general_category_func(@ptr, cb, nil, nil) end |
#on_mirroring {|codepoint| ... } ⇒ Object
Sets a custom mirroring function
73 74 75 76 77 78 79 80 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 73 def on_mirroring(&block) @mirroring_callback = block cb = FFI::Function.new(:uint32, [:pointer, :uint32, :pointer]) do |_ufuncs, cp, _user_data| block.call(cp) end @mirroring_ffi = cb C.hb_unicode_funcs_set_mirroring_func(@ptr, cb, nil, nil) end |
#on_script {|codepoint| ... } ⇒ Object
Sets a custom script function
84 85 86 87 88 89 90 91 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 84 def on_script(&block) @script_callback = block cb = FFI::Function.new(:uint32, [:pointer, :uint32, :pointer]) do |_ufuncs, cp, _user_data| block.call(cp) end @script_ffi = cb C.hb_unicode_funcs_set_script_func(@ptr, cb, nil, nil) end |
#parent ⇒ UnicodeFuncs
Returns the parent functions
32 33 34 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 32 def parent self.class.wrap_borrowed(C.hb_unicode_funcs_get_parent(@ptr)) end |
#script(cp) ⇒ Integer
Queries the script of a codepoint
154 155 156 |
# File 'lib/harfbuzz/unicode_funcs.rb', line 154 def script(cp) C.hb_unicode_script(@ptr, cp) end |