Skip to content

Commit

Permalink
Fix paint_color_glyph_func
Browse files Browse the repository at this point in the history
For whatever reason, passing the individual functions as user_data
results in a mixup between paint_color_glyph_func and
push_clip_glyph_func. Passing the while PainFuncs instance instead seems
to workaround this.
  • Loading branch information
khaledhosny committed Jan 27, 2024
1 parent fd21b67 commit e965531
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1593,16 +1593,16 @@ cdef void _paint_push_transform_func(
float dx,
float dy,
void *user_data) noexcept:
f = <object>user_data
f(xx, yx, xy, yy, dx, dy, <object>paint_data)
py_funcs = <PaintFuncs>user_data
py_funcs._push_transform_func(xx, yx, xy, yy, dx, dy, <object>paint_data)


cdef void _paint_pop_transform_func(
hb_paint_funcs_t *funcs,
void *paint_data,
void *user_data) noexcept:
f = <object>user_data
f(<object>paint_data)
py_funcs = <PaintFuncs>user_data
py_funcs._pop_transform_func(<object>paint_data)


cdef hb_bool_t _paint_color_glyph_func(
Expand All @@ -1611,9 +1611,9 @@ cdef hb_bool_t _paint_color_glyph_func(
hb_codepoint_t glyph,
hb_font_t *font,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_font = Font.from_ptr(hb_font_reference(font))
if f(py_font, glyph, <object>paint_data):
if py_funcs._color_glyph_func(py_font, glyph, <object>paint_data):
return 1
return 0

Expand All @@ -1624,9 +1624,9 @@ cdef void _paint_push_clip_glyph_func(
hb_codepoint_t glyph,
hb_font_t *font,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_font = Font.from_ptr(hb_font_reference(font))
f(py_font, glyph, <object>paint_data)
py_funcs._push_clip_glyph_func(py_font, glyph, <object>paint_data)


cdef void _paint_push_clip_rectangle_func(
Expand All @@ -1637,16 +1637,16 @@ cdef void _paint_push_clip_rectangle_func(
float xmax,
float ymax,
void *user_data) noexcept:
f = <object>user_data
f(xmin, ymin, xmax, ymax, <object>paint_data)
py_funcs = <PaintFuncs>user_data
py_funcs._push_clip_rectangle_func(xmin, ymin, xmax, ymax, <object>paint_data)


cdef void _paint_pop_clip_func(
hb_paint_funcs_t *funcs,
void *paint_data,
void *user_data) noexcept:
f = <object>user_data
f(<object>paint_data)
py_funcs = <PaintFuncs>user_data
py_funcs._pop_clip_func(<object>paint_data)


cdef void _paint_color_func(
Expand All @@ -1655,8 +1655,8 @@ cdef void _paint_color_func(
hb_bool_t is_foreground,
hb_color_t color,
void *user_data) noexcept:
f = <object>user_data
f(color, is_foreground, <object>paint_data)
py_funcs = <PaintFuncs>user_data
py_funcs._color_func(color, is_foreground, <object>paint_data)


cdef hb_bool_t _paint_image_func(
Expand All @@ -1669,11 +1669,11 @@ cdef hb_bool_t _paint_image_func(
float slant,
hb_glyph_extents_t *extents,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_image = Blob.from_ptr(hb_blob_reference(image))
py_format = hb_tag_to_string(format, NULL)
py_extents = GlyphExtents(extents.x_bearing, extents.y_bearing, extents.width, extents.height)
if f(py_image, width, height, py_format, slant, py_extents, <object>paint_data):
if py_funcs._image_func(py_image, width, height, py_format, slant, py_extents, <object>paint_data):
return 1
return 0

Expand All @@ -1689,9 +1689,9 @@ cdef void _paint_linear_gradient_func(
float x2,
float y2,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_color_line = ColorLine.from_ptr(color_line)
f(py_color_line, x0, y0, x1, y1, x2, y2, <object>paint_data)
py_funcs._linear_gradient_func(py_color_line, x0, y0, x1, y1, x2, y2, <object>paint_data)


cdef void _paint_radial_gradient_func(
Expand All @@ -1705,9 +1705,9 @@ cdef void _paint_radial_gradient_func(
float y1,
float r1,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_color_line = ColorLine.from_ptr(color_line)
f(py_color_line, x0, y0, r0, x1, y1, r1, <object>paint_data)
py_funcs._radial_gradient_func(py_color_line, x0, y0, r0, x1, y1, r1, <object>paint_data)


cdef void _paint_sweep_gradient_func(
Expand All @@ -1719,27 +1719,27 @@ cdef void _paint_sweep_gradient_func(
float start_angle,
float end_angle,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_color_line = ColorLine.from_ptr(color_line)
f(py_color_line, x0, y0, start_angle, end_angle, <object>paint_data)
py_funcs._sweep_gradient_func(py_color_line, x0, y0, start_angle, end_angle, <object>paint_data)


cdef void _paint_push_group_func(
hb_paint_funcs_t *funcs,
void *paint_data,
void *user_data) noexcept:
f = <object>user_data
f(<object>paint_data)
py_funcs = <PaintFuncs>user_data
py_funcs._push_group_func(<object>paint_data)


cdef void _paint_pop_group_func(
hb_paint_funcs_t *funcs,
void *paint_data,
hb_paint_composite_mode_t mode,
void *user_data) noexcept:
f = <object>user_data
py_funcs = <PaintFuncs>user_data
py_mode = PaintCompositeMode(mode)
f(py_mode, <object>paint_data)
py_funcs._pop_group_func(py_mode, <object>paint_data)


cdef hb_bool_t _paint_custom_palette_color_func(
Expand All @@ -1748,8 +1748,8 @@ cdef hb_bool_t _paint_custom_palette_color_func(
unsigned int color_index,
hb_color_t *color,
void *user_data) noexcept:
f = <object>user_data
py_color = f(color_index, <object>paint_data)
py_funcs = <PaintFuncs>user_data
py_color = py_funcs._custom_palette_color_func(color_index, <object>paint_data)
if py_color is not None:
color[0] = py_color
return 1
Expand Down Expand Up @@ -1791,15 +1791,15 @@ cdef class PaintFuncs:
], None]) -> None:
self._push_transform_func = func
hb_paint_funcs_set_push_transform_func(
self._hb_paintfuncs, _paint_push_transform_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_push_transform_func, <void*>self, NULL)

def set_pop_transform_func(self,
func: Callable[[
object, # paint_data
], None]) -> None:
self._pop_transform_func = func
hb_paint_funcs_set_pop_transform_func(
self._hb_paintfuncs, _paint_pop_transform_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_pop_transform_func, <void*>self, NULL)

def set_color_glyph_func(self,
func: Callable[[
Expand All @@ -1809,7 +1809,7 @@ cdef class PaintFuncs:
], bool]) -> None:
self._color_glyph_func = func
hb_paint_funcs_set_color_glyph_func(
self._hb_paintfuncs, _paint_color_glyph_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_color_glyph_func, <void*>self, NULL)

def set_push_clip_glyph_func(self,
func: Callable[[
Expand All @@ -1819,7 +1819,7 @@ cdef class PaintFuncs:
], None]) -> None:
self._push_clip_glyph_func = func
hb_paint_funcs_set_push_clip_glyph_func(
self._hb_paintfuncs, _paint_push_clip_glyph_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_push_clip_glyph_func, <void*>self, NULL)

def set_push_clip_rectangle_func(self,
func: Callable[[
Expand All @@ -1831,15 +1831,15 @@ cdef class PaintFuncs:
], None]) -> None:
self._push_clip_rectangle_func = func
hb_paint_funcs_set_push_clip_rectangle_func(
self._hb_paintfuncs, _paint_push_clip_rectangle_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_push_clip_rectangle_func, <void*>self, NULL)

def set_pop_clip_func(self,
func: Callable[[
object, # paint_data
], None]) -> None:
self._pop_clip_func = func
hb_paint_funcs_set_pop_clip_func(
self._hb_paintfuncs, _paint_pop_clip_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_pop_clip_func, <void*>self, NULL)

def set_color_func(self,
func: Callable[[
Expand All @@ -1849,7 +1849,7 @@ cdef class PaintFuncs:
], None]) -> None:
self._color_func = func
hb_paint_funcs_set_color_func(
self._hb_paintfuncs, _paint_color_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_color_func, <void*>self, NULL)

def set_image_func(self,
func: Callable[[
Expand All @@ -1863,7 +1863,7 @@ cdef class PaintFuncs:
], bool]) -> None:
self._image_func = func
hb_paint_funcs_set_image_func(
self._hb_paintfuncs, _paint_image_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_image_func, <void*>self, NULL)

def set_linear_gradient_func(self,
func: Callable[[
Expand All @@ -1878,7 +1878,7 @@ cdef class PaintFuncs:
], None]) -> None:
self._linear_gradient_func = func
hb_paint_funcs_set_linear_gradient_func(
self._hb_paintfuncs, _paint_linear_gradient_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_linear_gradient_func, <void*>self, NULL)

def set_radial_gradient_func(self,
func: Callable[[
Expand All @@ -1893,7 +1893,7 @@ cdef class PaintFuncs:
], None]) -> None:
self._radial_gradient_func = func
hb_paint_funcs_set_radial_gradient_func(
self._hb_paintfuncs, _paint_radial_gradient_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_radial_gradient_func, <void*>self, NULL)

def set_sweep_gradient_func(self,
func: Callable[[
Expand All @@ -1906,15 +1906,15 @@ cdef class PaintFuncs:
], None]) -> None:
self._sweep_gradient_func = func
hb_paint_funcs_set_sweep_gradient_func(
self._hb_paintfuncs, _paint_sweep_gradient_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_sweep_gradient_func, <void*>self, NULL)

def set_push_group_func(self,
func: Callable[[
object, # paint_data
], None]) -> None:
self._push_group_func = func
hb_paint_funcs_set_push_group_func(
self._hb_paintfuncs, _paint_push_group_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_push_group_func, <void*>self, NULL)

def set_pop_group_func(self,
func: Callable[[
Expand All @@ -1923,7 +1923,7 @@ cdef class PaintFuncs:
], None]) -> None:
self._pop_group_func = func
hb_paint_funcs_set_pop_group_func(
self._hb_paintfuncs, _paint_pop_group_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_pop_group_func, <void*>self, NULL)

def set_custom_palette_color_func(self,
func: Callable[[
Expand All @@ -1932,7 +1932,7 @@ cdef class PaintFuncs:
], bool]) -> None:
self._custom_palette_color_func = func
hb_paint_funcs_set_custom_palette_color_func(
self._hb_paintfuncs, _paint_custom_palette_color_func, <void*>func, NULL)
self._hb_paintfuncs, _paint_custom_palette_color_func, <void*>self, NULL)


cdef void _move_to_func(hb_draw_funcs_t *dfuncs,
Expand Down

0 comments on commit e965531

Please sign in to comment.