Skip to content

Commit

Permalink
[paint] Return bool from paint_image()
Browse files Browse the repository at this point in the history
Fixes #3974
  • Loading branch information
behdad committed Dec 24, 2022
1 parent 346331d commit 6ccbfab
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/hb-paint-extents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ hb_paint_extents_pop_group (hb_paint_funcs_t *funcs HB_UNUSED,
c->pop_group (mode);
}

static void
static hb_bool_t
hb_paint_extents_paint_image (hb_paint_funcs_t *funcs HB_UNUSED,
void *paint_data,
hb_blob_t *blob HB_UNUSED,
Expand All @@ -458,6 +458,8 @@ hb_paint_extents_paint_image (hb_paint_funcs_t *funcs HB_UNUSED,
c->push_clip (extents);
c->paint ();
c->pop_clip ();

return true;
}

static void
Expand Down
4 changes: 2 additions & 2 deletions src/hb-paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_color_t color,
void *user_data) {}

static void
static hb_bool_t
hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_blob_t *image,
unsigned int width,
unsigned int height,
hb_tag_t format,
float slant_xy,
hb_glyph_extents_t *extents,
void *user_data) {}
void *user_data) { return false; }

static void
hb_paint_linear_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data,
Expand Down
20 changes: 11 additions & 9 deletions src/hb-paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,19 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
* The image dimensions and glyph extents are provided if available,
* and should be used to size and position the image.
*
* Return value: Whether the operation was successful.
*
* Since: REPLACEME
*/
typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *image,
unsigned int width,
unsigned int height,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents,
void *user_data);
typedef hb_bool_t (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *image,
unsigned int width,
unsigned int height,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents,
void *user_data);

/**
* hb_color_stop_t:
Expand Down
8 changes: 6 additions & 2 deletions test/api/test-paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ typedef struct {
GString *string;
} paint_data_t;

static void
static void print (paint_data_t *data, const char *format, ...) __attribute__((format (printf, 2, 3)));

void
print (paint_data_t *data,
const char *format,
...)
Expand Down Expand Up @@ -133,7 +135,7 @@ paint_color (hb_paint_funcs_t *funcs,
hb_color_get_alpha (color));
}

static void
static hb_bool_t
paint_image (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *blob,
Expand All @@ -151,6 +153,8 @@ paint_image (hb_paint_funcs_t *funcs,
print (data, "image type %s size %u %u slant %f extents %d %d %d %d\n",
buf, width, height, slant,
extents->x_bearing, extents->y_bearing, extents->width, extents->height);

return TRUE;
}

static void
Expand Down
12 changes: 7 additions & 5 deletions util/hb-cairo-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ _hb_cairo_destroy_blob (void *p)
hb_blob_destroy ((hb_blob_t *) p);
}

void
hb_bool_t
hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob,
unsigned width,
Expand All @@ -116,7 +116,7 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
hb_glyph_extents_t *extents)
{
if (!extents) /* SVG currently. */
return;
return FALSE;

cairo_surface_t *surface = NULL;

Expand All @@ -140,15 +140,15 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
/* Byte-endian conversion. */
unsigned data_size = hb_blob_get_length (blob);
if (data_size < width * height * 4)
return;
return FALSE;

unsigned char *data;
#ifdef __BYTE_ORDER
if (__BYTE_ORDER == __BIG_ENDIAN)
{
data = (unsigned char *) hb_blob_get_data_writable (blob, NULL);
if (!data)
return;
return FALSE;

unsigned count = width * height * 4;
for (unsigned i = 0; i < count; i += 4)
Expand Down Expand Up @@ -178,7 +178,7 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
}

if (!surface)
return;
return FALSE;

cairo_save (cr);
/* this clip is here to work around recording surface limitations */
Expand Down Expand Up @@ -211,6 +211,8 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
cairo_surface_destroy (surface);

cairo_restore (cr);

return TRUE;
}

static void
Expand Down
14 changes: 7 additions & 7 deletions util/hb-cairo-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode)
return CAIRO_OPERATOR_SOURCE;
}

void hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob,
unsigned width,
unsigned height,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents);
hb_bool_t hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob,
unsigned width,
unsigned height,
hb_tag_t format,
float slant,
hb_glyph_extents_t *extents);

void hb_cairo_paint_linear_gradient (cairo_t *cr,
hb_color_line_t *color_line,
Expand Down
4 changes: 2 additions & 2 deletions util/helper-cairo-user.hh
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ paint_color (hb_paint_funcs_t *funcs,
cairo_paint (cr);
}

static void
static hb_bool_t
paint_image (hb_paint_funcs_t *funcs,
void *paint_data,
hb_blob_t *blob,
Expand All @@ -302,7 +302,7 @@ paint_image (hb_paint_funcs_t *funcs,
buf, width, height, (double) slant,
extents->x_bearing, extents->y_bearing, extents->width, extents->height);

hb_cairo_paint_glyph_image (cr, blob, width, height, format, slant, extents);
return hb_cairo_paint_glyph_image (cr, blob, width, height, format, slant, extents);
}

static void
Expand Down

2 comments on commit 6ccbfab

@khaledhosny
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t the callers of the callback functions checks their return value for the fallabck to happen?

@behdad
Copy link
Member Author

@behdad behdad commented on 6ccbfab Dec 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Doing.

Please sign in to comment.