[paint] Change the image callback
Instead of passing the glyph ID, give it the image blob, a mimetype, and glyph extents (if available). Update all callers.
This commit is contained in:
parent
ea48d6c292
commit
37f3f0fcc2
|
@ -939,11 +939,15 @@ struct CBDT
|
||||||
|
|
||||||
bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const
|
bool paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const
|
||||||
{
|
{
|
||||||
|
hb_glyph_extents_t extents;
|
||||||
hb_blob_t *blob = reference_png (font, glyph);
|
hb_blob_t *blob = reference_png (font, glyph);
|
||||||
if (unlikely (blob == hb_blob_get_empty ()))
|
if (unlikely (blob == hb_blob_get_empty ()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
funcs->image (data, glyph);
|
if (unlikely (!get_extents (font, glyph, &extents)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
funcs->image (data, blob, "image/png", &extents);
|
||||||
|
|
||||||
hb_blob_destroy (blob);
|
hb_blob_destroy (blob);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -240,11 +240,15 @@ struct sbix
|
||||||
int x_offset = 0, y_offset = 0;
|
int x_offset = 0, y_offset = 0;
|
||||||
unsigned int strike_ppem = 0;
|
unsigned int strike_ppem = 0;
|
||||||
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset, &strike_ppem);
|
hb_blob_t *blob = reference_png (font, glyph, &x_offset, &y_offset, &strike_ppem);
|
||||||
|
hb_glyph_extents_t extents;
|
||||||
|
|
||||||
if (blob == hb_blob_get_empty ())
|
if (blob == hb_blob_get_empty ())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
funcs->image (data, glyph);
|
if (!get_extents (font, glyph, &extents))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
funcs->image (data, blob, "image/png", &extents);
|
||||||
|
|
||||||
hb_blob_destroy (blob);
|
hb_blob_destroy (blob);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -103,7 +103,7 @@ struct SVG
|
||||||
if (blob == hb_blob_get_empty ())
|
if (blob == hb_blob_get_empty ())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
funcs->image (data, glyph);
|
funcs->image (data, blob, "image/svg+xml", nullptr);
|
||||||
|
|
||||||
hb_blob_destroy (blob);
|
hb_blob_destroy (blob);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -70,7 +70,9 @@ hb_paint_color_nil (hb_paint_funcs_t *funcs, void *paint_data,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
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_codepoint_t glyph,
|
hb_blob_t *image,
|
||||||
|
const char *mimetype,
|
||||||
|
hb_glyph_extents_t *extents,
|
||||||
void *user_data) {}
|
void *user_data) {}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -344,9 +346,11 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
|
||||||
|
|
||||||
void
|
void
|
||||||
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
|
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
|
||||||
hb_codepoint_t glyph)
|
hb_blob_t *image,
|
||||||
|
const char *mimetype,
|
||||||
|
hb_glyph_extents_t *extents)
|
||||||
{
|
{
|
||||||
funcs->image (paint_data, glyph);
|
funcs->image (paint_data, image, mimetype, extents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#define HB_PAINT_H
|
#define HB_PAINT_H
|
||||||
|
|
||||||
#include "hb.h"
|
#include "hb.h"
|
||||||
|
#include "hb-font.h"
|
||||||
|
|
||||||
HB_BEGIN_DECLS
|
HB_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -225,20 +226,27 @@ typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
|
||||||
* hb_paint_image_func_t:
|
* hb_paint_image_func_t:
|
||||||
* @funcs: paint functions object
|
* @funcs: paint functions object
|
||||||
* @paint_data: The data accompanying the paint functions
|
* @paint_data: The data accompanying the paint functions
|
||||||
* @glyph: the glyph ID
|
* @image: the image data
|
||||||
|
* @mimetype: the mime type for the image data
|
||||||
|
* @extents: (nullable): glyph extents
|
||||||
* @user_data: user data passed to the hb_font_paint_glyph() call
|
* @user_data: user data passed to the hb_font_paint_glyph() call
|
||||||
*
|
*
|
||||||
* A virtual method for the #hb_paint_funcs_t to paint the
|
* A virtual method for the #hb_paint_funcs_t to paint the
|
||||||
* glyph image.
|
* glyph image.
|
||||||
*
|
*
|
||||||
* This method is intended for glyphs with image blobs in the CBDT,
|
* This method is intended for glyphs with image blobs in the CBDT,
|
||||||
* sbix or SVG tables.
|
* sbix or SVG tables. The @mimetype identifies the kind of data
|
||||||
|
* that is contained in @image. Possible values include "image/png"
|
||||||
|
* and "image/svg+xml". The glyph extents are provided if available,
|
||||||
|
* and should be used to position the image.
|
||||||
*
|
*
|
||||||
* Since: REPLACEME
|
* Since: REPLACEME
|
||||||
*/
|
*/
|
||||||
typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
|
typedef void (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
|
||||||
void *paint_data,
|
void *paint_data,
|
||||||
hb_codepoint_t glyph,
|
hb_blob_t *image,
|
||||||
|
const char *mimetype,
|
||||||
|
hb_glyph_extents_t *extents,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -684,7 +692,9 @@ hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
|
||||||
|
|
||||||
HB_EXTERN void
|
HB_EXTERN void
|
||||||
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
|
hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
|
||||||
hb_codepoint_t glyph);
|
hb_blob_t *image,
|
||||||
|
const char *mimetype,
|
||||||
|
hb_glyph_extents_t *extents);
|
||||||
|
|
||||||
HB_EXTERN void
|
HB_EXTERN void
|
||||||
hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data,
|
hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data,
|
||||||
|
|
|
@ -94,9 +94,11 @@ struct hb_paint_funcs_t
|
||||||
color_index, alpha,
|
color_index, alpha,
|
||||||
!user_data ? nullptr : user_data->color); }
|
!user_data ? nullptr : user_data->color); }
|
||||||
void image (void *paint_data,
|
void image (void *paint_data,
|
||||||
hb_codepoint_t glyph)
|
hb_blob_t *image,
|
||||||
|
const char *mimetype,
|
||||||
|
hb_glyph_extents_t *extents)
|
||||||
{ func.image (this, paint_data,
|
{ func.image (this, paint_data,
|
||||||
glyph,
|
image, mimetype, extents,
|
||||||
!user_data ? nullptr : user_data->image); }
|
!user_data ? nullptr : user_data->image); }
|
||||||
void linear_gradient (void *paint_data,
|
void linear_gradient (void *paint_data,
|
||||||
hb_color_line_t *color_line,
|
hb_color_line_t *color_line,
|
||||||
|
|
|
@ -324,7 +324,9 @@ read_blob (void *closure,
|
||||||
static void
|
static void
|
||||||
paint_image (hb_paint_funcs_t *funcs,
|
paint_image (hb_paint_funcs_t *funcs,
|
||||||
void *paint_data,
|
void *paint_data,
|
||||||
hb_codepoint_t glyph,
|
hb_blob_t *blob,
|
||||||
|
const char *mimetype,
|
||||||
|
hb_glyph_extents_t *extents,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
paint_data_t *data = user_data;
|
paint_data_t *data = user_data;
|
||||||
|
@ -332,17 +334,19 @@ paint_image (hb_paint_funcs_t *funcs,
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
cairo_pattern_t *pattern;
|
cairo_pattern_t *pattern;
|
||||||
cairo_matrix_t m;
|
cairo_matrix_t m;
|
||||||
hb_glyph_extents_t extents;
|
|
||||||
|
|
||||||
hb_font_get_glyph_extents (data->font, glyph, &extents);
|
if (strcmp (mimetype, "image/png") != 0)
|
||||||
r.blob = hb_ot_color_glyph_reference_png (data->font, glyph);
|
return;
|
||||||
|
|
||||||
|
r.blob = blob;
|
||||||
r.offset = 0;
|
r.offset = 0;
|
||||||
surface = cairo_image_surface_create_from_png_stream (read_blob, &r);
|
surface = cairo_image_surface_create_from_png_stream (read_blob, &r);
|
||||||
hb_blob_destroy (r.blob);
|
|
||||||
|
|
||||||
pattern = cairo_pattern_create_for_surface (surface);
|
pattern = cairo_pattern_create_for_surface (surface);
|
||||||
cairo_matrix_init_scale (&m, 1, -1);
|
cairo_matrix_init_scale (&m, 1, -1);
|
||||||
cairo_matrix_translate (&m, extents.x_bearing, - extents.y_bearing);
|
cairo_matrix_translate (&m,
|
||||||
|
extents ? extents->x_bearing : 0,
|
||||||
|
extents ? - extents->y_bearing : 0);
|
||||||
cairo_pattern_set_matrix (pattern, &m);
|
cairo_pattern_set_matrix (pattern, &m);
|
||||||
cairo_set_source (data->cr, pattern);
|
cairo_set_source (data->cr, pattern);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue