Class: HarfBuzz::ShapePlan

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

Overview

Wraps hb_shape_plan_t — a cached shaping plan for repeated shaping

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ptrObject (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

Parameters:

  • face (Face)

    Font face

  • props (C::HbSegmentPropertiesT)

    Segment properties

  • features (Array<Feature>) (defaults to: [])

    Features

  • shapers (Array<String>, nil) (defaults to: nil)

    Shaper list

  • coords (Array<Integer>, nil) (defaults to: nil)

    Normalized variation coordinates (nil = none)

Returns:



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

.emptyShapePlan

Returns the singleton empty shape plan

Returns:



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

Parameters:

  • face (Face)

    Font face

  • props (C::HbSegmentPropertiesT)

    Segment properties

  • features (Array<Feature>) (defaults to: [])

    Features

  • shapers (Array<String>, nil) (defaults to: nil)

    Shaper list

  • coords (Array<Integer>, nil) (defaults to: nil)

    Normalized variation coordinates (nil = none)

Returns:



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

Parameters:

  • font (Font)

    Font to use

  • buffer (Buffer)

    Buffer to shape

  • features (Array<Feature>) (defaults to: [])

    Features

Returns:

  • (Boolean)

    Success



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

#inspectObject



81
82
83
# File 'lib/harfbuzz/shape_plan.rb', line 81

def inspect
  "#<HarfBuzz::ShapePlan shaper=#{shaper.inspect}>"
end

#shaperString

Returns Name of the shaper used.

Returns:

  • (String)

    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