| Top |
| enum | hb_raster_format_t |
| hb_raster_extents_t | |
| typedef | hb_raster_image_t |
| typedef | hb_raster_draw_t |
| typedef | hb_raster_paint_t |
Functions for rasterizing glyph outlines into pixel buffers.
hb_raster_draw_t rasterizes outline geometry and always outputs
HB_RASTER_FORMAT_A8
. Typical flow:
hb_raster_draw_t *draw = hb_raster_draw_create_or_fail (); hb_raster_draw_set_scale_factor (draw, 64.f, 64.f); hb_raster_draw_set_transform (draw, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); hb_raster_draw_set_glyph_extents (draw, &glyph_extents); hb_raster_draw_glyph (draw, font, gid, pen_x, pen_y); hb_raster_image_t *mask = hb_raster_draw_render (draw);
hb_raster_paint_t renders color paint graphs and always outputs
HB_RASTER_FORMAT_BGRA32
. Typical flow:
hb_raster_paint_t *paint = hb_raster_paint_create_or_fail (); hb_raster_paint_set_scale_factor (paint, 64.f, 64.f); hb_raster_paint_set_transform (paint, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); hb_raster_paint_set_foreground (paint, foreground); hb_glyph_extents_t glyph_extents; hb_font_get_glyph_extents (font, gid, &glyph_extents); hb_raster_paint_set_glyph_extents (paint, &glyph_extents); hb_raster_paint_glyph (paint, font, gid, pen_x, pen_y); hb_raster_image_t *img = hb_raster_paint_render (paint);
In both modes, set extents explicitly (or via glyph extents) before rendering to avoid implicit allocations and to get deterministic bounds.
hb_raster_image_t *
hb_raster_image_create_or_fail (void);
Creates a new raster image object.
A newly allocated hb_raster_image_t with a reference count of 1,
or NULL on allocation failure.
The returned image can be released with hb_raster_image_destroy(), or
transferred for reuse with hb_raster_draw_recycle_image() or
hb_raster_paint_recycle_image().
[transfer full]
Since: 13.0.0
hb_raster_image_t *
hb_raster_image_reference (hb_raster_image_t *image);
Increases the reference count on image
by one.
This prevents image
from being destroyed until a matching
call to hb_raster_image_destroy() is made.
[skip]
Since: 13.0.0
void
hb_raster_image_destroy (hb_raster_image_t *image);
Decreases the reference count on image
by one. When the
reference count reaches zero, the image and its pixel buffer
are freed.
[skip]
Since: 13.0.0
hb_bool_t hb_raster_image_set_user_data (hb_raster_image_t *image,hb_user_data_key_t *key,void *data,hb_destroy_func_t destroy,hb_bool_t replace);
Attaches a user-data key/data pair to the specified raster image.
[skip]
image |
a raster image |
|
key |
the user-data key |
|
data |
a pointer to the user data |
|
destroy |
a callback to call when |
[nullable] |
replace |
whether to replace an existing data with the same key |
Since: 13.0.0
void * hb_raster_image_get_user_data (const hb_raster_image_t *image,hb_user_data_key_t *key);
Fetches the user-data associated with the specified key, attached to the specified raster image.
[skip]
Since: 13.0.0
hb_bool_t hb_raster_image_configure (hb_raster_image_t *image,hb_raster_format_t format,const hb_raster_extents_t *extents);
Configures image
format and extents together, resizing backing storage
at most once. This function does not clear pixel contents.
Passing NULL for extents
clears extents and releases the backing
allocation.
Since: 13.0.0
void
hb_raster_image_clear (hb_raster_image_t *image);
Clears image
pixels to zero while keeping current extents and format.
Since: 13.0.0
const uint8_t *
hb_raster_image_get_buffer (const hb_raster_image_t *image);
Fetches the raw pixel buffer of image
. The buffer layout is
described by the extents obtained from hb_raster_image_get_extents()
and the format from hb_raster_image_get_format(). Rows are stored
bottom-to-top.
Since: 13.0.0
void hb_raster_image_get_extents (const hb_raster_image_t *image,hb_raster_extents_t *extents);
Fetches the pixel-buffer extents of image
.
Since: 13.0.0
hb_raster_format_t
hb_raster_image_get_format (const hb_raster_image_t *image);
Fetches the pixel format of image
.
Since: 13.0.0
hb_bool_t hb_raster_image_deserialize_from_png_or_fail (hb_raster_image_t *image,hb_blob_t *png);
Replaces image
contents by deserializing a PNG blob into a
HB_RASTER_FORMAT_BGRA32 raster image.
On success, image
extents are reset to pixel extents with origin
(0, 0). Rows in the resulting image buffer are stored bottom-to-top.
On failure, image
is left unchanged.
Since: 13.1.0
hb_blob_t *
hb_raster_image_serialize_to_png_or_fail
(const hb_raster_image_t *image);
Serializes image
to a PNG blob.
Currently only HB_RASTER_FORMAT_BGRA32 images are supported.
Since: 13.1.0
hb_raster_draw_t *
hb_raster_draw_create_or_fail (void);
Creates a new rasterizer object.
A newly allocated hb_raster_draw_t with a reference count of 1. The
initial reference count should be released with hb_raster_draw_destroy()
when you are done using the hb_raster_draw_t, or NULL on
allocation failure.
[transfer full]
Since: 13.0.0
hb_raster_draw_t *
hb_raster_draw_reference (hb_raster_draw_t *draw);
Increases the reference count on draw
by one.
This prevents draw
from being destroyed until a matching
call to hb_raster_draw_destroy() is made.
[skip]
Since: 13.0.0
void
hb_raster_draw_destroy (hb_raster_draw_t *draw);
Decreases the reference count on draw
by one. When the
reference count reaches zero, the rasterizer is freed.
[skip]
Since: 13.0.0
hb_bool_t hb_raster_draw_set_user_data (hb_raster_draw_t *draw,hb_user_data_key_t *key,void *data,hb_destroy_func_t destroy,hb_bool_t replace);
Attaches a user-data key/data pair to the specified rasterizer.
[skip]
draw |
a rasterizer |
|
key |
the user-data key |
|
data |
a pointer to the user data |
|
destroy |
a callback to call when |
[nullable] |
replace |
whether to replace an existing data with the same key |
Since: 13.0.0
void * hb_raster_draw_get_user_data (const hb_raster_draw_t *draw,hb_user_data_key_t *key);
Fetches the user-data associated with the specified key, attached to the specified rasterizer.
[skip]
Since: 13.0.0
void hb_raster_draw_set_transform (hb_raster_draw_t *draw,float xx,float yx,float xy,float yy,float dx,float dy);
Sets a 2×3 affine transform applied to all incoming draw coordinates before rasterization. The default is the identity.
draw |
a rasterizer |
|
xx |
xx component of the transform matrix |
|
yx |
yx component of the transform matrix |
|
xy |
xy component of the transform matrix |
|
yy |
yy component of the transform matrix |
|
dx |
x translation |
|
dy |
y translation |
Since: 13.0.0
void hb_raster_draw_set_scale_factor (hb_raster_draw_t *draw,float x_scale_factor,float y_scale_factor);
Sets post-transform minification factors applied during rasterization. Factors larger than 1 shrink the output in pixels. The default is 1.
draw |
a rasterizer |
|
x_scale_factor |
x-axis minification factor |
|
y_scale_factor |
y-axis minification factor |
Since: 13.0.0
void hb_raster_draw_get_scale_factor (const hb_raster_draw_t *draw,float *x_scale_factor,float *y_scale_factor);
Fetches the current post-transform minification factors.
draw |
a rasterizer |
|
x_scale_factor |
x-axis minification factor. |
[out][nullable] |
y_scale_factor |
y-axis minification factor. |
[out][nullable] |
Since: 13.0.0
void hb_raster_draw_get_transform (const hb_raster_draw_t *draw,float *xx,float *yx,float *xy,float *yy,float *dx,float *dy);
Fetches the current affine transform of the rasterizer.
draw |
a rasterizer |
|
xx |
xx component of the transform matrix. |
[out][nullable] |
yx |
yx component of the transform matrix. |
[out][nullable] |
xy |
xy component of the transform matrix. |
[out][nullable] |
yy |
yy component of the transform matrix. |
[out][nullable] |
dx |
x translation. |
[out][nullable] |
dy |
y translation. |
[out][nullable] |
Since: 13.0.0
void hb_raster_draw_set_extents (hb_raster_draw_t *draw,const hb_raster_extents_t *extents);
Overrides the output image extents for the next render. When set,
hb_raster_draw_render() uses the given extents instead of
auto-computing them from the accumulated geometry.
Since: 13.0.0
hb_bool_t hb_raster_draw_get_extents (const hb_raster_draw_t *draw,hb_raster_extents_t *extents);
Gets currently configured output extents.
Since: 13.0.0
hb_bool_t hb_raster_draw_set_glyph_extents (hb_raster_draw_t *draw,const hb_glyph_extents_t *glyph_extents);
Transforms glyph_extents
with the rasterizer's current transform and
sets the resulting pixel extents for the next render.
This is equivalent to computing a transformed bounding box in pixel
space and calling hb_raster_draw_set_extents().
Since: 13.0.0
void
hb_raster_draw_clear (hb_raster_draw_t *draw);
Discards accumulated geometry and extents so draw
can be reused
for another render. User configuration (transform, scale factors)
is preserved. Call hb_raster_draw_reset() to also reset user
configuration to defaults.
Since: 14.2.0
void
hb_raster_draw_reset (hb_raster_draw_t *draw);
Resets the rasterizer to its initial state, clearing all accumulated geometry, the transform, and fixed extents. The object can then be reused for a new glyph.
Since: 13.0.0
hb_draw_funcs_t *
hb_raster_draw_get_funcs (const hb_raster_draw_t *draw);
Fetches the hb_draw_funcs_t that feeds outline data into
draw
. Pass draw
as the draw_data
argument when calling
the draw functions.
Since: 14.2.0
void hb_raster_draw_glyph (hb_raster_draw_t *draw,hb_font_t *font,hb_codepoint_t glyph);
Draws one glyph into draw
using the rasterizer's current
transform. Equivalent to hb_raster_draw_glyph_or_fail() with the
return value ignored.
Since: 14.2.0
hb_bool_t hb_raster_draw_glyph_or_fail (hb_raster_draw_t *draw,hb_font_t *font,hb_codepoint_t glyph);
Convenience to draw one glyph. Equivalent to:
hb_font_draw_glyph_or_fail (font, glyph, hb_raster_draw_get_funcs (draw), draw);
Since: 14.2.0
hb_raster_image_t *
hb_raster_draw_render (hb_raster_draw_t *draw);
Rasterizes the accumulated outline geometry into a new
hb_raster_image_t. After rendering, the accumulated edges are
cleared so the rasterizer can be reused. Output format is always
HB_RASTER_FORMAT_A8
.
A rendered hb_raster_image_t. Returns NULL on allocation/configuration
failure. If no geometry was accumulated, returns an empty image.
[transfer full]
Since: 13.0.0
void hb_raster_draw_recycle_image (hb_raster_draw_t *draw,hb_raster_image_t *image);
Recycles image
for reuse by a subsequent hb_raster_draw_render()
call, avoiding per-render memory allocation. The caller transfers
ownership of image
to draw
and must not use it afterwards.
If draw
already holds a recycled image, the previously recycled
image is destroyed.
Since: 13.0.0
hb_raster_paint_t *
hb_raster_paint_create_or_fail (void);
Creates a new color-glyph paint context.
Since: 13.0.0
hb_raster_paint_t *
hb_raster_paint_reference (hb_raster_paint_t *paint);
Increases the reference count on paint
by one.
[skip]
Since: 13.0.0
void
hb_raster_paint_destroy (hb_raster_paint_t *paint);
Decreases the reference count on paint
by one. When the
reference count reaches zero, the paint context is freed.
[skip]
Since: 13.0.0
hb_bool_t hb_raster_paint_set_user_data (hb_raster_paint_t *paint,hb_user_data_key_t *key,void *data,hb_destroy_func_t destroy,hb_bool_t replace);
Attaches a user-data key/data pair to the specified paint context.
[skip]
paint |
a paint context |
|
key |
the user-data key |
|
data |
a pointer to the user data |
|
destroy |
a callback to call when |
[nullable] |
replace |
whether to replace an existing data with the same key |
Since: 13.0.0
void * hb_raster_paint_get_user_data (const hb_raster_paint_t *paint,hb_user_data_key_t *key);
Fetches the user-data associated with the specified key, attached to the specified paint context.
[skip]
Since: 13.0.0
void hb_raster_paint_set_transform (hb_raster_paint_t *paint,float xx,float yx,float xy,float yy,float dx,float dy);
Sets the base 2×3 affine transform that maps from glyph-space coordinates to pixel-space coordinates.
paint |
a paint context |
|
xx |
xx component of the transform matrix |
|
yx |
yx component of the transform matrix |
|
xy |
xy component of the transform matrix |
|
yy |
yy component of the transform matrix |
|
dx |
x translation |
|
dy |
y translation |
Since: 13.0.0
void hb_raster_paint_get_transform (const hb_raster_paint_t *paint,float *xx,float *yx,float *xy,float *yy,float *dx,float *dy);
Gets the current base 2x3 affine transform.
paint |
a paint context |
|
xx |
xx component of the transform matrix. |
[out][nullable] |
yx |
yx component of the transform matrix. |
[out][nullable] |
xy |
xy component of the transform matrix. |
[out][nullable] |
yy |
yy component of the transform matrix. |
[out][nullable] |
dx |
x translation. |
[out][nullable] |
dy |
y translation. |
[out][nullable] |
Since: 13.0.0
void hb_raster_paint_set_scale_factor (hb_raster_paint_t *paint,float x_scale_factor,float y_scale_factor);
Sets post-transform minification factors applied during painting. Factors larger than 1 shrink the output in pixels. The default is 1.
paint |
a paint context |
|
x_scale_factor |
x-axis minification factor |
|
y_scale_factor |
y-axis minification factor |
Since: 13.0.0
void hb_raster_paint_get_scale_factor (const hb_raster_paint_t *paint,float *x_scale_factor,float *y_scale_factor);
Fetches the current post-transform minification factors.
paint |
a paint context |
|
x_scale_factor |
x-axis minification factor. |
[out][nullable] |
y_scale_factor |
y-axis minification factor. |
[out][nullable] |
Since: 13.0.0
void hb_raster_paint_set_extents (hb_raster_paint_t *paint,const hb_raster_extents_t *extents);
Sets the output image extents (pixel rectangle).
Call this before hb_font_paint_glyph() for each render.
A common pattern is:
hb_glyph_extents_t gext; if (hb_font_get_glyph_extents (font, gid, &gext)) hb_raster_paint_set_glyph_extents (paint, &gext);
Since: 13.0.0
hb_bool_t hb_raster_paint_get_extents (const hb_raster_paint_t *paint,hb_raster_extents_t *extents);
Gets currently configured output extents.
Since: 13.0.0
hb_bool_t hb_raster_paint_set_glyph_extents (hb_raster_paint_t *paint,const hb_glyph_extents_t *glyph_extents);
Transforms glyph_extents
with the paint context's base transform and
sets the resulting output image extents.
This is equivalent to computing a transformed bounding box in pixel
space and calling hb_raster_paint_set_extents().
Since: 13.0.0
void hb_raster_paint_set_foreground (hb_raster_paint_t *paint,hb_color_t foreground);
Sets the foreground color used when paint callbacks request it
(e.g. is_foreground in color stops or solid fills).
Since: 13.0.0
hb_color_t
hb_raster_paint_get_foreground (const hb_raster_paint_t *paint);
Returns the foreground color previously set on paint
, or the
default opaque black if none was set.
Since: 14.2.0
void hb_raster_paint_set_background (hb_raster_paint_t *paint,hb_color_t background);
Sets the background color for paint
. If set to a non-transparent
value, the rendered image is pre-filled with this color before
glyph content is composited on top. Default is transparent.
Since: 14.2.0
hb_color_t
hb_raster_paint_get_background (const hb_raster_paint_t *paint);
Returns the background color previously set on paint
, or
transparent if none was set.
Since: 14.2.0
void hb_raster_paint_set_palette (hb_raster_paint_t *paint,unsigned palette);
Selects which font palette is used when paint callbacks look up indexed colors. Default is palette 0.
Since: 14.2.0
unsigned
hb_raster_paint_get_palette (const hb_raster_paint_t *paint);
Returns the palette index previously set on paint
, or 0 if none
was set.
Since: 14.2.0
void
hb_raster_paint_clear_custom_palette_colors
(hb_raster_paint_t *paint);
Clears all custom palette color overrides previously set on paint
.
After this call, palette lookups use the selected font palette without custom override entries.
Since: 13.0.0
hb_bool_t hb_raster_paint_set_custom_palette_color (hb_raster_paint_t *paint,unsigned int color_index,hb_color_t color);
Overrides one font palette color entry for subsequent paint operations.
Overrides are keyed by color_index
and persist on paint
until cleared
(or replaced for the same index).
These overrides are consulted by paint operations that resolve CPAL entries.
Since: 13.0.0
hb_paint_funcs_t *
hb_raster_paint_get_funcs (const hb_raster_paint_t *paint);
Fetches the hb_paint_funcs_t that renders color glyphs into
paint
. Pass paint
as the paint_data
argument when calling
hb_font_paint_glyph().
Since: 14.2.0
void hb_raster_paint_glyph (hb_raster_paint_t *paint,hb_font_t *font,hb_codepoint_t glyph);
Paints one glyph into paint
. Unlike
hb_raster_paint_glyph_or_fail(), glyphs with no color paint data
fall back to a synthesized foreground-colored outline, so any
glyph with an outline or bitmap image produces output.
Since: 14.2.0
hb_bool_t hb_raster_paint_glyph_or_fail (hb_raster_paint_t *paint,hb_font_t *font,hb_codepoint_t glyph);
Convenience to paint one color glyph. Equivalent to:
hb_font_paint_glyph_or_fail (font, glyph, hb_raster_paint_get_funcs (paint), paint, palette, foreground);
Since: 14.2.0
hb_raster_image_t *
hb_raster_paint_render (hb_raster_paint_t *paint);
Extracts the rendered image after hb_font_paint_glyph() has
completed. The paint context's surface stack is consumed and
the result returned as a new hb_raster_image_t. Output format is
always HB_RASTER_FORMAT_BGRA32
.
Call hb_font_paint_glyph() before calling this function.
hb_raster_paint_set_extents() or hb_raster_paint_set_glyph_extents()
must be called before painting; otherwise this function returns NULL.
Internal drawing state is cleared here so the same object can
be reused without client-side clearing.
A rendered hb_raster_image_t. Returns NULL if extents were not set
or if allocation/configuration fails. If extents were set but nothing
was painted, returns an empty image.
[transfer full]
Since: 13.0.0
void
hb_raster_paint_clear (hb_raster_paint_t *paint);
Discards accumulated paint output so paint
can be reused for
another render. User configuration (base transform, scale
factors, foreground, custom palette colors) is preserved. Call
hb_raster_paint_reset() to also reset user configuration to
defaults.
Since: 14.2.0
void
hb_raster_paint_reset (hb_raster_paint_t *paint);
Resets the paint context to its initial state, clearing all configuration while preserving internal image caches.
Since: 13.0.0
void hb_raster_paint_recycle_image (hb_raster_paint_t *paint,hb_raster_image_t *image);
Recycles image
for reuse by subsequent render calls.
The caller transfers ownership of image
to paint
.
Since: 13.0.0
typedef struct {
int x_origin, y_origin;
unsigned int width, height;
unsigned int stride;
} hb_raster_extents_t;
Pixel-buffer extents for raster operations.
X coordinate of the left edge of the image in glyph space |
||
Y coordinate of the bottom edge of the image in glyph space |
||
Width in pixels |
||
Height in pixels |
||
Bytes per row; 0 means auto-calculate on input, filled on output |
Since: 13.0.0
typedef struct hb_raster_image_t hb_raster_image_t;
An opaque raster image object holding a pixel buffer produced by
hb_raster_draw_render(). Use hb_raster_image_get_buffer() and
hb_raster_image_get_extents() to access the pixels.
Since: 13.0.0
typedef struct hb_raster_draw_t hb_raster_draw_t;
An opaque outline rasterizer object. Accumulates glyph outlines
via hb_draw_funcs_t callbacks obtained from hb_raster_draw_get_funcs(),
then produces an hb_raster_image_t with hb_raster_draw_render().
Since: 13.0.0
typedef struct hb_raster_paint_t hb_raster_paint_t;
An opaque color-glyph paint context. Implements hb_paint_funcs_t callbacks that render COLRv0/v1 color glyphs into a BGRA32 hb_raster_image_t.
Since: 13.0.0