Class: HarfBuzz::ShapePlan
- Inherits:
-
Object
- Object
- HarfBuzz::ShapePlan
- Defined in:
- lib/harfbuzz/shape_plan.rb
Overview
Wraps hb_shape_plan_t — a cached shaping plan for repeated shaping
Instance Attribute Summary collapse
-
#ptr ⇒ Object
readonly
Returns the value of attribute ptr.
Class Method Summary collapse
-
.cached(face, props, features = [], shapers: nil, coords: nil) ⇒ ShapePlan
Creates (or retrieves from cache) a ShapePlan.
- .define_finalizer(obj, ptr) ⇒ Object
-
.empty ⇒ ShapePlan
Returns the singleton empty shape plan.
-
.new(face, props, features = [], shapers: nil, coords: nil) ⇒ ShapePlan
Creates a new ShapePlan for the given face and properties.
- .wrap_borrowed(ptr) ⇒ Object
- .wrap_owned(ptr) ⇒ Object
Instance Method Summary collapse
-
#execute(font, buffer, features = []) ⇒ Boolean
Executes the shape plan.
- #inspect ⇒ Object
-
#shaper ⇒ String
Name of the shaper used.
Instance Attribute Details
#ptr ⇒ Object (readonly)
Returns the value of attribute ptr.
6 7 8 |
# File 'lib/harfbuzz/shape_plan.rb', line 6 def ptr @ptr end |
Class Method Details
.cached(face, props, features = [], shapers: nil, coords: nil) ⇒ ShapePlan
Creates (or retrieves from cache) a ShapePlan
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/harfbuzz/shape_plan.rb', line 40 def self.cached(face, props, features = [], shapers: nil, coords: nil) features_ptr = HarfBuzz.send(:build_features_ptr, features) shapers_ptr = build_shapers_ptr(shapers) if coords coords_ptr = FFI::MemoryPointer.new(:int32, coords.size) coords_ptr.put_array_of_int32(0, coords) ptr = C.hb_shape_plan_create_cached2( face.ptr, props, features_ptr, features.size, shapers_ptr, coords.size, coords_ptr ) else ptr = C.hb_shape_plan_create_cached( face.ptr, props, features_ptr, features.size, shapers_ptr ) end wrap_owned(ptr) end |
.define_finalizer(obj, ptr) ⇒ Object
99 100 101 102 |
# File 'lib/harfbuzz/shape_plan.rb', line 99 def self.define_finalizer(obj, ptr) destroy = C.method(:hb_shape_plan_destroy) ObjectSpace.define_finalizer(obj, proc { destroy.call(ptr) }) end |
.empty ⇒ ShapePlan
Returns the singleton empty shape plan
60 61 62 |
# File 'lib/harfbuzz/shape_plan.rb', line 60 def self.empty wrap_borrowed(C.hb_shape_plan_get_empty) end |
.new(face, props, features = [], shapers: nil, coords: nil) ⇒ ShapePlan
Creates a new ShapePlan for the given face and properties
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/harfbuzz/shape_plan.rb', line 15 def self.new(face, props, features = [], shapers: nil, coords: nil) features_ptr = HarfBuzz.send(:build_features_ptr, features) shapers_ptr = build_shapers_ptr(shapers) if coords coords_ptr = FFI::MemoryPointer.new(:int32, coords.size) coords_ptr.put_array_of_int32(0, coords) ptr = C.hb_shape_plan_create2( face.ptr, props, features_ptr, features.size, shapers_ptr, coords.size, coords_ptr ) else ptr = C.hb_shape_plan_create( face.ptr, props, features_ptr, features.size, shapers_ptr ) end wrap_owned(ptr) end |
.wrap_borrowed(ptr) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/harfbuzz/shape_plan.rb', line 92 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
85 86 87 88 89 90 |
# File 'lib/harfbuzz/shape_plan.rb', line 85 def self.wrap_owned(ptr) obj = allocate obj.instance_variable_set(:@ptr, ptr) define_finalizer(obj, ptr) obj end |
Instance Method Details
#execute(font, buffer, features = []) ⇒ Boolean
Executes the shape plan
69 70 71 72 73 74 |
# File 'lib/harfbuzz/shape_plan.rb', line 69 def execute(font, buffer, features = []) features_ptr = HarfBuzz.send(:build_features_ptr, features) C.from_hb_bool( C.hb_shape_plan_execute(@ptr, font.ptr, buffer.ptr, features_ptr, features.size) ) end |
#inspect ⇒ Object
81 82 83 |
# File 'lib/harfbuzz/shape_plan.rb', line 81 def inspect "#<HarfBuzz::ShapePlan shaper=#{shaper.inspect}>" end |
#shaper ⇒ String
Returns Name of the shaper used.
77 78 79 |
# File 'lib/harfbuzz/shape_plan.rb', line 77 def shaper C.hb_shape_plan_get_shaper(@ptr) end |