| Top |
| enum | hb_vector_format_t |
| hb_vector_extents_t | |
| enum | hb_vector_extents_mode_t |
| typedef | hb_vector_draw_t |
| typedef | hb_vector_paint_t |
Functions for converting glyph outlines and color paint trees into SVG or PDF vector output.
hb_vector_draw_t converts monochrome glyph outlines into vector paths. Typical flow:
hb_vector_draw_t *draw = hb_vector_draw_create_or_fail (HB_VECTOR_FORMAT_SVG); hb_vector_draw_set_scale_factor (draw, 64.f, 64.f); hb_vector_draw_set_foreground (draw, foreground); hb_vector_draw_glyph (draw, font, gid, pen_x, pen_y); hb_blob_t *svg = hb_vector_draw_render (draw);
hb_vector_paint_t renders color paint graphs (COLRv0/v1) and embedded PNG images into vector output with gradients, layers, and compositing. Typical flow:
hb_vector_paint_t *paint = hb_vector_paint_create_or_fail (HB_VECTOR_FORMAT_SVG);
hb_vector_paint_set_scale_factor (paint, 64.f, 64.f);
hb_vector_paint_set_foreground (paint, foreground);
hb_vector_paint_glyph (paint, font, gid, pen_x, pen_y,
HB_VECTOR_EXTENTS_MODE_EXPAND);
hb_blob_t *svg = hb_vector_paint_render (paint);
Both contexts accumulate multiple glyphs into a single document.
Call hb_vector_draw_render() / hb_vector_paint_render() to
retrieve the final blob. Rendering clears all accumulated
content (including extents), so retrieve any needed extents
via hb_vector_draw_get_extents() / hb_vector_paint_get_extents()
before rendering.
Each glyph is emitted as an independent element. If glyphs overlap and the foreground color is semi-transparent, the overlapping regions will be composited separately rather than painted as a single uniform layer.
hb_vector_draw_t *
hb_vector_draw_create_or_fail (hb_vector_format_t format);
Creates a new draw context for vector output.
Since: 13.0.0
hb_vector_draw_t *
hb_vector_draw_reference (hb_vector_draw_t *draw);
Increases the reference count of draw
.
Since: 13.0.0
void
hb_vector_draw_destroy (hb_vector_draw_t *draw);
Decreases the reference count of draw
and destroys it when it reaches zero.
Since: 13.0.0
hb_bool_t hb_vector_draw_set_user_data (hb_vector_draw_t *draw,hb_user_data_key_t *key,void *data,hb_destroy_func_t destroy,hb_bool_t replace);
Attaches user data to draw
.
draw |
a draw context. |
|
key |
user-data key. |
|
data |
user-data value. |
|
destroy |
destroy callback for |
[nullable] |
replace |
whether to replace an existing value for |
Since: 13.0.0
void * hb_vector_draw_get_user_data (const hb_vector_draw_t *draw,hb_user_data_key_t *key);
Gets previously attached user data from draw
.
Since: 13.0.0
void hb_vector_draw_set_transform (hb_vector_draw_t *draw,float xx,float yx,float xy,float yy,float dx,float dy);
Sets the affine transform used when drawing glyphs.
draw |
a draw context. |
|
xx |
transform xx component. |
|
yx |
transform yx component. |
|
xy |
transform xy component. |
|
yy |
transform yy component. |
|
dx |
transform x translation. |
|
dy |
transform y translation. |
Since: 13.0.0
void hb_vector_draw_get_transform (const hb_vector_draw_t *draw,float *xx,float *yx,float *xy,float *yy,float *dx,float *dy);
Gets the affine transform used when drawing glyphs.
draw |
a draw context. |
|
xx |
transform xx component. |
[out][nullable] |
yx |
transform yx component. |
[out][nullable] |
xy |
transform xy component. |
[out][nullable] |
yy |
transform yy component. |
[out][nullable] |
dx |
transform x translation. |
[out][nullable] |
dy |
transform y translation. |
[out][nullable] |
Since: 13.0.0
void hb_vector_draw_set_scale_factor (hb_vector_draw_t *draw,float x_scale_factor,float y_scale_factor);
Sets additional output scaling factors.
Since: 13.0.0
void hb_vector_draw_get_scale_factor (const hb_vector_draw_t *draw,float *x_scale_factor,float *y_scale_factor);
Gets additional output scaling factors.
draw |
a draw context. |
|
x_scale_factor |
x scale factor. |
[out][nullable] |
y_scale_factor |
y scale factor. |
[out][nullable] |
Since: 13.0.0
void hb_vector_draw_set_extents (hb_vector_draw_t *draw,const hb_vector_extents_t *extents);
Sets or expands output extents on draw
. Passing NULL clears extents.
Since: 13.0.0
hb_bool_t hb_vector_draw_get_extents (const hb_vector_draw_t *draw,hb_vector_extents_t *extents);
Gets current output extents from draw
.
Since: 13.0.0
hb_bool_t hb_vector_draw_set_glyph_extents (hb_vector_draw_t *draw,const hb_glyph_extents_t *glyph_extents);
Expands draw
extents using glyph_extents
under the current transform.
Since: 13.0.0
hb_vector_format_t
hb_vector_draw_get_format (const hb_vector_draw_t *draw);
Gets the output format draw
was created with.
Since: 14.2.0
hb_draw_funcs_t *
hb_vector_draw_get_funcs (const hb_vector_draw_t *draw);
Gets draw callbacks for feeding outline data into draw
.
Pass draw
as the draw_data
argument when calling them.
Since: 14.2.0
void hb_vector_draw_glyph (hb_vector_draw_t *draw,hb_font_t *font,hb_codepoint_t glyph,hb_vector_extents_mode_t extents_mode);
Draws one glyph into draw
. Equivalent to
hb_vector_draw_glyph_or_fail() with the return value ignored.
Since: 14.2.0
hb_bool_t hb_vector_draw_glyph_or_fail (hb_vector_draw_t *draw,hb_font_t *font,hb_codepoint_t glyph,hb_vector_extents_mode_t extents_mode);
Convenience to draw one glyph into draw
. Equivalent to:
// extend extents if requested hb_vector_draw_new_path (draw); hb_font_draw_glyph_or_fail (font, glyph, hb_vector_draw_get_funcs (draw), draw);
Since: 14.2.0
void hb_vector_draw_set_precision (hb_vector_draw_t *draw,unsigned precision);
Sets numeric output precision for draw output.
Since: 14.2.0
unsigned
hb_vector_draw_get_precision (const hb_vector_draw_t *draw);
Returns the numeric output precision previously set on draw
,
or the default if none was set.
Since: 14.2.0
void hb_vector_draw_set_foreground (hb_vector_draw_t *draw,hb_color_t foreground);
Sets the fill color for drawn glyph outlines. Default is opaque black.
Since: 14.2.0
hb_color_t
hb_vector_draw_get_foreground (const hb_vector_draw_t *draw);
Returns the foreground fill color.
Since: 14.2.0
void hb_vector_draw_set_background (hb_vector_draw_t *draw,hb_color_t background);
Sets the background color. If non-transparent, a filled rectangle covering the extents is emitted behind all content. Default is transparent (no background).
Since: 14.2.0
hb_color_t
hb_vector_draw_get_background (const hb_vector_draw_t *draw);
Returns the background color.
Since: 14.2.0
void
hb_vector_draw_new_path (hb_vector_draw_t *draw);
Flushes any pending path and starts a new one. Call this between glyphs to separate their outlines so fill rules don't interact across glyphs.
Since: 14.2.0
hb_blob_t *
hb_vector_draw_render (hb_vector_draw_t *draw);
Renders accumulated draw content to an output blob.
Since: 13.0.0
void
hb_vector_draw_clear (hb_vector_draw_t *draw);
Discards accumulated draw output so draw
can be reused for
another render. User configuration (transform, scale factors,
precision) is preserved. Call hb_vector_draw_reset() to
also reset user configuration to defaults.
Since: 14.2.0
void
hb_vector_draw_reset (hb_vector_draw_t *draw);
Resets draw
state and clears accumulated content.
Since: 13.0.0
void hb_vector_draw_recycle_blob (hb_vector_draw_t *draw,hb_blob_t *blob);
Provides a blob for internal buffer reuse by later render calls.
Since: 13.0.0
hb_vector_paint_t *
hb_vector_paint_create_or_fail (hb_vector_format_t format);
Creates a new paint context for vector output.
Since: 13.0.0
hb_vector_paint_t *
hb_vector_paint_reference (hb_vector_paint_t *paint);
Increases the reference count of paint
.
Since: 13.0.0
void
hb_vector_paint_destroy (hb_vector_paint_t *paint);
Decreases the reference count of paint
and destroys it when it reaches zero.
Since: 13.0.0
hb_bool_t hb_vector_paint_set_user_data (hb_vector_paint_t *paint,hb_user_data_key_t *key,void *data,hb_destroy_func_t destroy,hb_bool_t replace);
Attaches user data to paint
.
paint |
a paint context. |
|
key |
user-data key. |
|
data |
user-data value. |
|
destroy |
destroy callback for |
[nullable] |
replace |
whether to replace an existing value for |
Since: 13.0.0
void * hb_vector_paint_get_user_data (const hb_vector_paint_t *paint,hb_user_data_key_t *key);
Gets previously attached user data from paint
.
Since: 13.0.0
void hb_vector_paint_set_transform (hb_vector_paint_t *paint,float xx,float yx,float xy,float yy,float dx,float dy);
Sets the affine transform used when painting glyphs.
paint |
a paint context. |
|
xx |
transform xx component. |
|
yx |
transform yx component. |
|
xy |
transform xy component. |
|
yy |
transform yy component. |
|
dx |
transform x translation. |
|
dy |
transform y translation. |
Since: 13.0.0
void hb_vector_paint_get_transform (const hb_vector_paint_t *paint,float *xx,float *yx,float *xy,float *yy,float *dx,float *dy);
Gets the affine transform used when painting glyphs.
paint |
a paint context. |
|
xx |
transform xx component. |
[out][nullable] |
yx |
transform yx component. |
[out][nullable] |
xy |
transform xy component. |
[out][nullable] |
yy |
transform yy component. |
[out][nullable] |
dx |
transform x translation. |
[out][nullable] |
dy |
transform y translation. |
[out][nullable] |
Since: 13.0.0
void hb_vector_paint_set_scale_factor (hb_vector_paint_t *paint,float x_scale_factor,float y_scale_factor);
Sets additional output scaling factors.
Since: 13.0.0
void hb_vector_paint_get_scale_factor (const hb_vector_paint_t *paint,float *x_scale_factor,float *y_scale_factor);
Gets additional output scaling factors.
paint |
a paint context. |
|
x_scale_factor |
x scale factor. |
[out][nullable] |
y_scale_factor |
y scale factor. |
[out][nullable] |
Since: 13.0.0
void hb_vector_paint_set_extents (hb_vector_paint_t *paint,const hb_vector_extents_t *extents);
Sets or expands output extents on paint
. Passing NULL clears extents.
Since: 13.0.0
hb_bool_t hb_vector_paint_get_extents (const hb_vector_paint_t *paint,hb_vector_extents_t *extents);
Gets current output extents from paint
.
Since: 13.0.0
hb_bool_t hb_vector_paint_set_glyph_extents (hb_vector_paint_t *paint,const hb_glyph_extents_t *glyph_extents);
Expands paint
extents using glyph_extents
under the current transform.
Since: 13.0.0
void hb_vector_paint_set_foreground (hb_vector_paint_t *paint,hb_color_t foreground);
Sets fallback foreground color used by paint operations.
Since: 13.0.0
hb_color_t
hb_vector_paint_get_foreground (const hb_vector_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_vector_paint_set_background (hb_vector_paint_t *paint,hb_color_t background);
Sets the background color for paint
. If set to a non-transparent
value, the renderer emits a filled rectangle covering the extents
behind all glyph content. Default is transparent (no background).
Since: 14.2.0
hb_color_t
hb_vector_paint_get_background (const hb_vector_paint_t *paint);
Returns the background color previously set on paint
, or
transparent if none was set.
Since: 14.2.0
void hb_vector_paint_set_palette (hb_vector_paint_t *paint,int palette);
Sets the color palette index used by paint operations.
Since: 13.0.0
int
hb_vector_paint_get_palette (const hb_vector_paint_t *paint);
Returns the palette index previously set on paint
, or 0 if none
was set.
Since: 14.2.0
void hb_vector_paint_set_custom_palette_color (hb_vector_paint_t *paint,unsigned 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, including SVG glyph content using var(--colorN).
Since: 13.0.0
void
hb_vector_paint_clear_custom_palette_colors
(hb_vector_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_vector_format_t
hb_vector_paint_get_format (const hb_vector_paint_t *paint);
Gets the output format paint
was created with.
Since: 14.2.0
hb_paint_funcs_t *
hb_vector_paint_get_funcs (const hb_vector_paint_t *paint);
Gets paint callbacks for emitting paint operations into paint
.
Pass paint
as the paint_data
argument when calling them.
Since: 14.2.0
void hb_vector_paint_glyph (hb_vector_paint_t *paint,hb_font_t *font,hb_codepoint_t glyph,hb_vector_extents_mode_t extents_mode);
Paints one glyph into paint
. Unlike
hb_vector_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.
paint |
a paint context. |
|
font |
font object. |
|
glyph |
glyph ID. |
|
extents_mode |
extents update mode. |
Since: 14.2.0
hb_bool_t hb_vector_paint_glyph_or_fail (hb_vector_paint_t *paint,hb_font_t *font,hb_codepoint_t glyph,hb_vector_extents_mode_t extents_mode);
Convenience to paint one color glyph into paint
.
Equivalent to:
// extend extents if requested hb_paint_funcs_t *funcs = hb_vector_paint_get_funcs (paint); hb_paint_push_transform (funcs, paint, ...transform...); hb_font_paint_glyph_or_fail (font, glyph, funcs, paint, palette, foreground); hb_paint_pop_transform (funcs, paint);
paint |
a paint context. |
|
font |
font object. |
|
glyph |
glyph ID. |
|
extents_mode |
extents update mode. |
Since: 14.2.0
void hb_vector_paint_set_precision (hb_vector_paint_t *paint,unsigned precision);
Sets numeric output precision for paint output.
Since: 14.2.0
unsigned
hb_vector_paint_get_precision (const hb_vector_paint_t *paint);
Returns the numeric output precision previously set on paint
,
or the default if none was set.
Since: 14.2.0
void hb_vector_paint_set_svg_prefix (hb_vector_paint_t *paint,const char *prefix);
Namespaces the paint's SVG output. Callers that inject multiple hb-vector SVGs into the same document (e.g. several glyph previews on one page) must set a distinct prefix per context so that the short IDs hb-vector uses for clipPaths, gradients, and use-refs don't collide in the DOM.
No effect on PDF output.
paint |
a paint context. |
|
prefix |
a null-terminated ASCII string to prepend to every emitted
SVG |
Since: 14.2.0
const char *
hb_vector_paint_get_svg_prefix (const hb_vector_paint_t *paint);
Returns the SVG id prefix previously set on paint
, or "" if
none was set. The pointer remains valid until the next call to
hb_vector_paint_set_svg_prefix() or hb_vector_paint_reset() on the
same context.
Since: 14.2.0
hb_blob_t *
hb_vector_paint_render (hb_vector_paint_t *paint);
Renders accumulated paint content to an output blob.
Since: 13.0.0
void
hb_vector_paint_clear (hb_vector_paint_t *paint);
Discards accumulated paint output so paint
can be reused for
another render. User configuration (transform, scale factors,
precision, foreground, palette, custom palette colors)
is preserved. Call hb_vector_paint_reset() to also reset
user configuration to defaults.
Since: 14.2.0
void
hb_vector_paint_reset (hb_vector_paint_t *paint);
Resets paint
state and clears accumulated content.
Since: 13.0.0
void hb_vector_paint_recycle_blob (hb_vector_paint_t *paint,hb_blob_t *blob);
Provides a blob for internal buffer reuse by later render calls.
Since: 13.0.0
typedef struct {
float x, y;
float width, height;
} hb_vector_extents_t;
Vector output extents, mapped to SVG viewBox.
Since: 13.0.0
Controls whether convenience glyph APIs update context extents.
Since: 13.0.0
typedef struct hb_vector_draw_t hb_vector_draw_t;
Opaque draw context for vector outline conversion.
Since: 13.0.0
typedef struct hb_vector_paint_t hb_vector_paint_t;
Opaque paint context for vector color-glyph conversion.
Since: 13.0.0