Class: HarfBuzz::PaintFuncs

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

Overview

Wraps hb_paint_funcs_t — callbacks for color glyph rendering (COLRv1)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePaintFuncs

Returns a new instance of PaintFuncs.

Raises:



8
9
10
11
12
13
# File 'lib/harfbuzz/paint_funcs.rb', line 8

def initialize
  @ptr = C.hb_paint_funcs_create
  raise AllocationError, "Failed to create paint_funcs" if @ptr.null?

  HarfBuzz::PaintFuncs.define_finalizer(self, @ptr)
end

Instance Attribute Details

#ptrObject (readonly)

Returns the value of attribute ptr.



6
7
8
# File 'lib/harfbuzz/paint_funcs.rb', line 6

def ptr
  @ptr
end

Class Method Details

.define_finalizer(obj, ptr) ⇒ Object



129
130
131
132
# File 'lib/harfbuzz/paint_funcs.rb', line 129

def self.define_finalizer(obj, ptr)
  destroy = C.method(:hb_paint_funcs_destroy)
  ObjectSpace.define_finalizer(obj, proc { destroy.call(ptr) })
end

Instance Method Details

#immutable?Boolean

Returns true if immutable.

Returns:

  • (Boolean)

    true if immutable



16
17
18
# File 'lib/harfbuzz/paint_funcs.rb', line 16

def immutable?
  C.from_hb_bool(C.hb_paint_funcs_is_immutable(@ptr))
end

#inspectObject



125
126
127
# File 'lib/harfbuzz/paint_funcs.rb', line 125

def inspect
  "#<HarfBuzz::PaintFuncs immutable=#{immutable?}>"
end

#make_immutable!self

Makes immutable

Returns:

  • (self)


22
23
24
25
# File 'lib/harfbuzz/paint_funcs.rb', line 22

def make_immutable!
  C.hb_paint_funcs_make_immutable(@ptr)
  self
end

#on_color {|is_foreground, color| ... } ⇒ Object

Sets color callback

Yields:

  • (is_foreground, color)

    Color fill



91
92
93
94
95
96
97
98
99
# File 'lib/harfbuzz/paint_funcs.rb', line 91

def on_color(&block)
  @color_callback = block
  cb = FFI::Function.new(:void, [:pointer, :pointer, :int, :uint32, :pointer]) do
    |_pfuncs, _paint_data, is_foreground, color, _user_data|
    block.call(C.from_hb_bool(is_foreground), color)
  end
  @color_ffi = cb
  C.hb_paint_funcs_set_color_func(@ptr, cb, nil, nil)
end

#on_pop_clip { ... } ⇒ Object

Sets pop_clip callback

Yields:

  • Called when clip is popped



79
80
81
82
83
84
85
86
87
# File 'lib/harfbuzz/paint_funcs.rb', line 79

def on_pop_clip(&block)
  @pop_clip_callback = block
  cb = FFI::Function.new(:void, [:pointer, :pointer, :pointer]) do
    |_pfuncs, _paint_data, _user_data|
    block.call
  end
  @pop_clip_ffi = cb
  C.hb_paint_funcs_set_pop_clip_func(@ptr, cb, nil, nil)
end

#on_pop_group {|mode| ... } ⇒ Object

Sets pop_group callback

Yields:

  • (mode)

    Composite mode



115
116
117
118
119
120
121
122
123
# File 'lib/harfbuzz/paint_funcs.rb', line 115

def on_pop_group(&block)
  @pop_group_callback = block
  cb = FFI::Function.new(:void, [:pointer, :pointer, :int, :pointer]) do
    |_pfuncs, _paint_data, mode, _user_data|
    block.call(mode)
  end
  @pop_group_ffi = cb
  C.hb_paint_funcs_set_pop_group_func(@ptr, cb, nil, nil)
end

#on_pop_transform { ... } ⇒ Object

Sets pop_transform callback

Yields:

  • Called when a transform is popped



42
43
44
45
46
47
48
49
50
# File 'lib/harfbuzz/paint_funcs.rb', line 42

def on_pop_transform(&block)
  @pop_transform_callback = block
  cb = FFI::Function.new(:void, [:pointer, :pointer, :pointer]) do
    |_pfuncs, _paint_data, _user_data|
    block.call
  end
  @pop_transform_ffi = cb
  C.hb_paint_funcs_set_pop_transform_func(@ptr, cb, nil, nil)
end

#on_push_clip_glyph {|glyph| ... } ⇒ Object

Sets push_clip_glyph callback

Yields:

  • (glyph)

    Glyph ID used as clip mask



54
55
56
57
58
59
60
61
62
# File 'lib/harfbuzz/paint_funcs.rb', line 54

def on_push_clip_glyph(&block)
  @push_clip_glyph_callback = block
  cb = FFI::Function.new(:void, [:pointer, :pointer, :uint32, :pointer, :pointer]) do
    |_pfuncs, _paint_data, glyph, _font, _user_data|
    block.call(glyph)
  end
  @push_clip_glyph_ffi = cb
  C.hb_paint_funcs_set_push_clip_glyph_func(@ptr, cb, nil, nil)
end

#on_push_clip_rectangle {|xmin, ymin, xmax, ymax| ... } ⇒ Object

Sets push_clip_rectangle callback

Yields:

  • (xmin, ymin, xmax, ymax)


66
67
68
69
70
71
72
73
74
75
# File 'lib/harfbuzz/paint_funcs.rb', line 66

def on_push_clip_rectangle(&block)
  @push_clip_rectangle_callback = block
  cb = FFI::Function.new(:void,
    [:pointer, :pointer, :float, :float, :float, :float, :pointer]) do
    |_pfuncs, _paint_data, xmin, ymin, xmax, ymax, _user_data|
    block.call(xmin, ymin, xmax, ymax)
  end
  @push_clip_rectangle_ffi = cb
  C.hb_paint_funcs_set_push_clip_rectangle_func(@ptr, cb, nil, nil)
end

#on_push_group { ... } ⇒ Object

Sets push_group callback

Yields:

  • Called when a compositing group is started



103
104
105
106
107
108
109
110
111
# File 'lib/harfbuzz/paint_funcs.rb', line 103

def on_push_group(&block)
  @push_group_callback = block
  cb = FFI::Function.new(:void, [:pointer, :pointer, :pointer]) do
    |_pfuncs, _paint_data, _user_data|
    block.call
  end
  @push_group_ffi = cb
  C.hb_paint_funcs_set_push_group_func(@ptr, cb, nil, nil)
end

#on_push_transform {|xx, yx, xy, yy, dx, dy| ... } ⇒ Object

Sets push_transform callback

Yields:

  • (xx, yx, xy, yy, dx, dy)

    2D transform matrix components



29
30
31
32
33
34
35
36
37
38
# File 'lib/harfbuzz/paint_funcs.rb', line 29

def on_push_transform(&block)
  @push_transform_callback = block
  cb = FFI::Function.new(:void,
    [:pointer, :pointer, :float, :float, :float, :float, :float, :float, :pointer]) do
    |_pfuncs, _paint_data, xx, yx, xy, yy, dx, dy, _user_data|
    block.call(xx, yx, xy, yy, dx, dy)
  end
  @push_transform_ffi = cb
  C.hb_paint_funcs_set_push_transform_func(@ptr, cb, nil, nil)
end