[paint] Return bool from paint_image()

Fixes https://github.com/harfbuzz/harfbuzz/issues/3974
This commit is contained in:
Behdad Esfahbod 2022-12-24 10:44:25 -07:00
parent 346331d375
commit 6ccbfabd4f
7 changed files with 38 additions and 28 deletions

View File

@ -438,7 +438,7 @@ hb_paint_extents_pop_group (hb_paint_funcs_t *funcs HB_UNUSED,
c->pop_group (mode); c->pop_group (mode);
} }
static void static hb_bool_t
hb_paint_extents_paint_image (hb_paint_funcs_t *funcs HB_UNUSED, hb_paint_extents_paint_image (hb_paint_funcs_t *funcs HB_UNUSED,
void *paint_data, void *paint_data,
hb_blob_t *blob HB_UNUSED, hb_blob_t *blob HB_UNUSED,
@ -458,6 +458,8 @@ hb_paint_extents_paint_image (hb_paint_funcs_t *funcs HB_UNUSED,
c->push_clip (extents); c->push_clip (extents);
c->paint (); c->paint ();
c->pop_clip (); c->pop_clip ();
return true;
} }
static void static void

View File

@ -75,7 +75,7 @@ hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_color_t color, hb_color_t color,
void *user_data) {} void *user_data) {}
static void static hb_bool_t
hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_blob_t *image, hb_blob_t *image,
unsigned int width, unsigned int width,
@ -83,7 +83,7 @@ hb_paint_image_nil (hb_paint_funcs_t *funcs, void *paint_data,
hb_tag_t format, hb_tag_t format,
float slant_xy, float slant_xy,
hb_glyph_extents_t *extents, hb_glyph_extents_t *extents,
void *user_data) {} void *user_data) { return false; }
static void static void
hb_paint_linear_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_linear_gradient_nil (hb_paint_funcs_t *funcs, void *paint_data,

View File

@ -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, * The image dimensions and glyph extents are provided if available,
* and should be used to size and position the image. * and should be used to size and position the image.
* *
* Return value: Whether the operation was successful.
*
* Since: REPLACEME * Since: REPLACEME
*/ */
typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs, typedef hb_bool_t (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_blob_t *image, hb_blob_t *image,
unsigned int width, unsigned int width,
unsigned int height, unsigned int height,
hb_tag_t format, hb_tag_t format,
float slant, float slant,
hb_glyph_extents_t *extents, hb_glyph_extents_t *extents,
void *user_data); void *user_data);
/** /**
* hb_color_stop_t: * hb_color_stop_t:

View File

@ -40,7 +40,9 @@ typedef struct {
GString *string; GString *string;
} paint_data_t; } 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, print (paint_data_t *data,
const char *format, const char *format,
...) ...)
@ -133,7 +135,7 @@ paint_color (hb_paint_funcs_t *funcs,
hb_color_get_alpha (color)); hb_color_get_alpha (color));
} }
static void static hb_bool_t
paint_image (hb_paint_funcs_t *funcs, paint_image (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_blob_t *blob, hb_blob_t *blob,
@ -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", print (data, "image type %s size %u %u slant %f extents %d %d %d %d\n",
buf, width, height, slant, buf, width, height, slant,
extents->x_bearing, extents->y_bearing, extents->width, extents->height); extents->x_bearing, extents->y_bearing, extents->width, extents->height);
return TRUE;
} }
static void static void

View File

@ -106,7 +106,7 @@ _hb_cairo_destroy_blob (void *p)
hb_blob_destroy ((hb_blob_t *) p); hb_blob_destroy ((hb_blob_t *) p);
} }
void hb_bool_t
hb_cairo_paint_glyph_image (cairo_t *cr, hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob, hb_blob_t *blob,
unsigned width, unsigned width,
@ -116,7 +116,7 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
hb_glyph_extents_t *extents) hb_glyph_extents_t *extents)
{ {
if (!extents) /* SVG currently. */ if (!extents) /* SVG currently. */
return; return FALSE;
cairo_surface_t *surface = NULL; cairo_surface_t *surface = NULL;
@ -140,7 +140,7 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
/* Byte-endian conversion. */ /* Byte-endian conversion. */
unsigned data_size = hb_blob_get_length (blob); unsigned data_size = hb_blob_get_length (blob);
if (data_size < width * height * 4) if (data_size < width * height * 4)
return; return FALSE;
unsigned char *data; unsigned char *data;
#ifdef __BYTE_ORDER #ifdef __BYTE_ORDER
@ -148,7 +148,7 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
{ {
data = (unsigned char *) hb_blob_get_data_writable (blob, NULL); data = (unsigned char *) hb_blob_get_data_writable (blob, NULL);
if (!data) if (!data)
return; return FALSE;
unsigned count = width * height * 4; unsigned count = width * height * 4;
for (unsigned i = 0; i < count; i += 4) for (unsigned i = 0; i < count; i += 4)
@ -178,7 +178,7 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
} }
if (!surface) if (!surface)
return; return FALSE;
cairo_save (cr); cairo_save (cr);
/* this clip is here to work around recording surface limitations */ /* this clip is here to work around recording surface limitations */
@ -211,6 +211,8 @@ hb_cairo_paint_glyph_image (cairo_t *cr,
cairo_surface_destroy (surface); cairo_surface_destroy (surface);
cairo_restore (cr); cairo_restore (cr);
return TRUE;
} }
static void static void

View File

@ -70,13 +70,13 @@ hb_paint_composite_mode_to_cairo (hb_paint_composite_mode_t mode)
return CAIRO_OPERATOR_SOURCE; return CAIRO_OPERATOR_SOURCE;
} }
void hb_cairo_paint_glyph_image (cairo_t *cr, hb_bool_t hb_cairo_paint_glyph_image (cairo_t *cr,
hb_blob_t *blob, hb_blob_t *blob,
unsigned width, unsigned width,
unsigned height, unsigned height,
hb_tag_t format, hb_tag_t format,
float slant, float slant,
hb_glyph_extents_t *extents); hb_glyph_extents_t *extents);
void hb_cairo_paint_linear_gradient (cairo_t *cr, void hb_cairo_paint_linear_gradient (cairo_t *cr,
hb_color_line_t *color_line, hb_color_line_t *color_line,

View File

@ -282,7 +282,7 @@ paint_color (hb_paint_funcs_t *funcs,
cairo_paint (cr); cairo_paint (cr);
} }
static void static hb_bool_t
paint_image (hb_paint_funcs_t *funcs, paint_image (hb_paint_funcs_t *funcs,
void *paint_data, void *paint_data,
hb_blob_t *blob, hb_blob_t *blob,
@ -302,7 +302,7 @@ paint_image (hb_paint_funcs_t *funcs,
buf, width, height, (double) slant, buf, width, height, (double) slant,
extents->x_bearing, extents->y_bearing, extents->width, extents->height); 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 static void