NovaSVG 0.10.0
A header-only SVG library
Loading...
Searching...
No Matches
canvas.h
Go to the documentation of this file.
1#pragma once
2
3#include "private.h"
4#include "utils.h"
5
6namespace novasvg {
7namespace render {
8
13
18
19#define NOVASVG_DEFAULT_STROKE_STYLE (stroke_style_t{1.f, NOVASVG_LINE_CAP_BUTT, NOVASVG_LINE_JOIN_MITER, 10.f})
20
40
59
61{
62 state->paint = paint_reference(source->paint);
64 state->color = source->color;
65 state->matrix = source->matrix;
66 state->stroke.style = source->stroke.style;
71 state->winding = source->winding;
72 state->op = source->op;
73 state->font_size = source->font_size;
74 state->opacity = source->opacity;
75 state->clipping = source->clipping;
76}
77
86
101
107
131
136
141
143{
144 state_t* new_state = canvas->freed_state;
145 if(new_state == NULL)
146 new_state = state_create();
147 else
148 canvas->freed_state = new_state->next;
149 state_copy(new_state, canvas->state);
150 new_state->next = canvas->state;
151 canvas->state = new_state;
152}
153
155{
156 if(canvas->state->next == NULL)
157 return;
158 state_t* old_state = canvas->state;
159 canvas->state = old_state->next;
160 state_reset(old_state);
161 old_state->next = canvas->freed_state;
162 canvas->freed_state = old_state;
163}
164
165NOVASVG_INLINE void canvas_set_rgb(canvas_t* canvas, float r, float g, float b)
166{
167 canvas_set_rgba(canvas, r, g, b, 1.f);
168}
169
170NOVASVG_INLINE void canvas_set_rgba(canvas_t* canvas, float r, float g, float b, float a)
171{
172 color_init_rgba(&canvas->state->color, r, g, b, a);
174}
175
180
181NOVASVG_INLINE void canvas_set_linear_gradient(canvas_t* canvas, float x1, float y1, float x2, float y2, spread_method_t spread, const gradient_stop_t* stops, int nstops, const matrix_t* matrix)
182{
183 paint_t* paint = paint_create_linear_gradient(x1, y1, x2, y2, spread, stops, nstops, matrix);
186}
187
188NOVASVG_INLINE void canvas_set_radial_gradient(canvas_t* canvas, float cx, float cy, float cr, float fx, float fy, float fr, spread_method_t spread, const gradient_stop_t* stops, int nstops, const matrix_t* matrix)
189{
190 paint_t* paint = paint_create_radial_gradient(cx, cy, cr, fx, fy, fr, spread, stops, nstops, matrix);
193}
194
201
208
215
222
227
228NOVASVG_INLINE void canvas_add_font_face(canvas_t* canvas, const char* family, bool bold, bool italic, font_face_t* face)
229{
230 if(canvas->face_cache == NULL)
232 font_face_cache_add(canvas->face_cache, family, bold, italic, face);
233}
234
235NOVASVG_INLINE bool canvas_add_font_file(canvas_t* canvas, const char* family, bool bold, bool italic, const char* filename, int ttcindex)
236{
237 if(canvas->face_cache == NULL)
239 return font_face_cache_add_file(canvas->face_cache, family, bold, italic, filename, ttcindex);
240}
241
242NOVASVG_INLINE bool canvas_select_font_face(canvas_t* canvas, const char* family, bool bold, bool italic)
243{
244 if(canvas->face_cache == NULL)
245 return false;
246 font_face_t* face = font_face_cache_get(canvas->face_cache, family, bold, italic);
247 if(face == NULL)
248 return false;
250 return true;
251}
252
258
265
270
272{
273 canvas->state->font_size = size;
274}
275
280
285
290
295
300
302{
303 canvas->state->opacity = std::clamp(opacity, 0.f, 1.f);
304}
305
310
312{
313 canvas->state->stroke.style.width = line_width;
314}
315
320
325
330
335
340
342{
343 canvas->state->stroke.style.miter_limit = miter_limit;
344}
345
350
351NOVASVG_INLINE void canvas_set_dash(canvas_t* canvas, float offset, const float* dashes, int ndashes)
352{
354 canvas_set_dash_array(canvas, dashes, ndashes);
355}
356
358{
359 canvas->state->stroke.dash.offset = offset;
360}
361
366
367NOVASVG_INLINE void canvas_set_dash_array(canvas_t* canvas, const float* dashes, int ndashes)
368{
371}
372
373NOVASVG_INLINE int canvas_get_dash_array(const canvas_t* canvas, const float** dashes)
374{
375 if(dashes)
376 *dashes = canvas->state->stroke.dash.array.data;
377 return canvas->state->stroke.dash.array.size;
378}
379
381{
383}
384
385NOVASVG_INLINE void canvas_scale(canvas_t* canvas, float sx, float sy)
386{
387 matrix_scale(&canvas->state->matrix, sx, sy);
388}
389
390NOVASVG_INLINE void canvas_shear(canvas_t* canvas, float shx, float shy)
391{
392 matrix_shear(&canvas->state->matrix, shx, shy);
393}
394
396{
397 matrix_rotate(&canvas->state->matrix, angle);
398}
399
404
409
414
419
420NOVASVG_INLINE void canvas_map(const canvas_t* canvas, float x, float y, float* xx, float* yy)
421{
422 matrix_map(&canvas->state->matrix, x, y, xx, yy);
423}
424
426{
427 matrix_map_point(&canvas->state->matrix, src, dst);
428}
429
431{
432 matrix_map_rect(&canvas->state->matrix, src, dst);
433}
434
436{
437 path_move_to(canvas->path, x, y);
438}
439
441{
442 path_line_to(canvas->path, x, y);
443}
444
445NOVASVG_INLINE void canvas_quad_to(canvas_t* canvas, float x1, float y1, float x2, float y2)
446{
447 path_quad_to(canvas->path, x1, y1, x2, y2);
448}
449
450NOVASVG_INLINE void canvas_cubic_to(canvas_t* canvas, float x1, float y1, float x2, float y2, float x3, float y3)
451{
452 path_cubic_to(canvas->path, x1, y1, x2, y2, x3, y3);
453}
454
455NOVASVG_INLINE void canvas_arc_to(canvas_t* canvas, float rx, float ry, float angle, bool large_arc_flag, bool sweep_flag, float x, float y)
456{
457 path_arc_to(canvas->path, rx, ry, angle, large_arc_flag, sweep_flag, x, y);
458}
459
460NOVASVG_INLINE void canvas_rect(canvas_t* canvas, float x, float y, float w, float h)
461{
462 path_add_rect(canvas->path, x, y, w, h);
463}
464
465NOVASVG_INLINE void canvas_round_rect(canvas_t* canvas, float x, float y, float w, float h, float rx, float ry)
466{
467 path_add_round_rect(canvas->path, x, y, w, h, rx, ry);
468}
469
470NOVASVG_INLINE void canvas_ellipse(canvas_t* canvas, float cx, float cy, float rx, float ry)
471{
472 path_add_ellipse(canvas->path, cx, cy, rx, ry);
473}
474
475NOVASVG_INLINE void canvas_circle(canvas_t* canvas, float cx, float cy, float r)
476{
477 path_add_circle(canvas->path, cx, cy, r);
478}
479
480NOVASVG_INLINE void canvas_arc(canvas_t* canvas, float cx, float cy, float r, float a0, float a1, bool ccw)
481{
482 path_add_arc(canvas->path, cx, cy, r, a0, a1, ccw);
483}
484
489
494
499
501{
503}
504
509
515
521
523{
524 if(canvas->state->clipping) {
526 }
527
528 float l = canvas->clip_rect.x;
529 float t = canvas->clip_rect.y;
530 float r = canvas->clip_rect.x + canvas->clip_rect.w;
531 float b = canvas->clip_rect.y + canvas->clip_rect.h;
532
533 return x >= l && x <= r && y >= t && y <= b;
534}
535
541
547
549{
550 if(canvas->state->clipping) {
552 } else {
553 extents->x = canvas->clip_rect.x;
554 extents->y = canvas->clip_rect.y;
555 extents->w = canvas->clip_rect.w;
556 extents->h = canvas->clip_rect.h;
557 }
558}
559
565
571
577
587
598
609
621
622NOVASVG_INLINE void canvas_fill_rect(canvas_t* canvas, float x, float y, float w, float h)
623{
625 canvas_rect(canvas, x, y, w, h);
627}
628
635
636NOVASVG_INLINE void canvas_stroke_rect(canvas_t* canvas, float x, float y, float w, float h)
637{
639 canvas_rect(canvas, x, y, w, h);
641}
642
649
650NOVASVG_INLINE void canvas_clip_rect(canvas_t* canvas, float x, float y, float w, float h)
651{
653 canvas_rect(canvas, x, y, w, h);
655}
656
663
664NOVASVG_INLINE float canvas_add_glyph(canvas_t* canvas, codepoint_t codepoint, float x, float y)
665{
667 if(state->font_face && state->font_size > 0.f)
668 return font_face_get_glyph_path(state->font_face, state->font_size, x, y, codepoint, canvas->path);
669 return 0.f;
670}
671
672NOVASVG_INLINE float canvas_add_text(canvas_t* canvas, const void* text, int length, text_encoding_t encoding, float x, float y)
673{
675 if(state->font_face == NULL || state->font_size <= 0.f)
676 return 0.f;
678 text_iterator_init(&it, text, length, encoding);
679 float advance_width = 0.f;
680 codepoint_t previous = 0;
681 bool has_previous = false;
682 while(text_iterator_has_next(&it)) {
683 codepoint_t codepoint = text_iterator_next(&it);
684 codepoint = font_face_apply_ligature(state->font_face, &it, codepoint);
685 if(has_previous)
686 advance_width += font_face_get_kern_advance(state->font_face, state->font_size, previous, codepoint);
687 advance_width += font_face_get_glyph_path(state->font_face, state->font_size, x + advance_width, y, codepoint, canvas->path);
688 previous = codepoint;
689 has_previous = true;
690 }
691
692 return advance_width;
693}
694
695NOVASVG_INLINE float canvas_fill_text(canvas_t* canvas, const void* text, int length, text_encoding_t encoding, float x, float y)
696{
698 float advance_width = canvas_add_text(canvas, text, length, encoding, x, y);
700 return advance_width;
701}
702
703NOVASVG_INLINE float canvas_stroke_text(canvas_t* canvas, const void* text, int length, text_encoding_t encoding, float x, float y)
704{
706 float advance_width = canvas_add_text(canvas, text, length, encoding, x, y);
708 return advance_width;
709}
710
711NOVASVG_INLINE float canvas_clip_text(canvas_t* canvas, const void* text, int length, text_encoding_t encoding, float x, float y)
712{
714 float advance_width = canvas_add_text(canvas, text, length, encoding, x, y);
716 return advance_width;
717}
718
719NOVASVG_INLINE void canvas_font_metrics(const canvas_t* canvas, float* ascent, float* descent, float* line_gap, rect_t* extents)
720{
722 if(state->font_face && state->font_size > 0.f) {
723 font_face_get_metrics(state->font_face, state->font_size, ascent, descent, line_gap, extents);
724 return;
725 }
726
727 if(ascent) *ascent = 0.f;
728 if(descent) *descent = 0.f;
729 if(line_gap) *line_gap = 0.f;
730 if(extents) {
731 extents->x = 0.f;
732 extents->y = 0.f;
733 extents->w = 0.f;
734 extents->h = 0.f;
735 }
736}
737
738NOVASVG_INLINE void canvas_glyph_metrics(canvas_t* canvas, codepoint_t codepoint, float* advance_width, float* left_side_bearing, rect_t* extents)
739{
741 if(state->font_face && state->font_size > 0.f) {
742 font_face_get_glyph_metrics(state->font_face, state->font_size, codepoint, advance_width, left_side_bearing, extents);
743 return;
744 }
745
746 if(advance_width) *advance_width = 0.f;
747 if(left_side_bearing) *left_side_bearing = 0.f;
748 if(extents) {
749 extents->x = 0.f;
750 extents->y = 0.f;
751 extents->w = 0.f;
752 extents->h = 0.f;
753 }
754}
755
756NOVASVG_INLINE float canvas_text_extents(canvas_t* canvas, const void* text, int length, text_encoding_t encoding, rect_t* extents)
757{
759 if(state->font_face && state->font_size > 0.f) {
760 return font_face_text_extents(state->font_face, state->font_size, text, length, encoding, extents);
761 }
762
763 if(extents) {
764 extents->x = 0.f;
765 extents->y = 0.f;
766 extents->w = 0.f;
767 extents->h = 0.f;
768 }
769
770 return 0.f;
771}
772
773
774} // namespace render
775} // namespace novasvg
NOVASVG_INLINE float canvas_get_dash_offset(const canvas_t *canvas)
Retrieves the current dash offset.
Definition canvas.h:362
NOVASVG_INLINE void canvas_stroke_rect(canvas_t *canvas, float x, float y, float w, float h)
Strokes a rectangle with the current stroke settings.
Definition canvas.h:636
NOVASVG_INLINE void canvas_clip(canvas_t *canvas)
A drawing operator that intersects the current clipping region with the current path according to the...
Definition canvas.h:572
NOVASVG_INLINE int canvas_get_reference_count(const canvas_t *canvas)
Retrieves the reference count of the canvas.
Definition canvas.h:132
NOVASVG_INLINE codepoint_t font_face_apply_ligature(font_face_t *face, text_iterator_t *it, codepoint_t codepoint)
Definition font.h:5592
NOVASVG_INLINE font_face_t * canvas_get_font_face(const canvas_t *canvas)
Retrieves the current font face used for text rendering on the canvas.
Definition canvas.h:266
NOVASVG_INLINE void matrix_map_point(const matrix_t *matrix, const point_t *src, point_t *dst)
Transforms the src point using matrix and stores the result in dst.
Definition matrix.h:106
NOVASVG_INLINE void canvas_arc(canvas_t *canvas, float cx, float cy, float r, float a0, float a1, bool ccw)
Adds an arc to the current path.
Definition canvas.h:480
NOVASVG_INLINE void paint_destroy(paint_t *paint)
Decrements the reference count and destroys the paint if the count reaches zero.
Definition paint.h:494
NOVASVG_INLINE void canvas_move_to(canvas_t *canvas, float x, float y)
Moves the current point to a new position.
Definition canvas.h:435
void span_buffer_init_rect(span_buffer_t *span_buffer, int x, int y, int width, int height)
Definition rasterize.h:20
NOVASVG_INLINE void matrix_map(const matrix_t *matrix, float x, float y, float *xx, float *yy)
Transforms the point (x, y) using matrix and stores the result in (xx, yy).
Definition matrix.h:100
NOVASVG_INLINE path_t * path_create(void)
Creates a new path object.
Definition path.h:43
void span_buffer_init(span_buffer_t *span_buffer)
Definition rasterize.h:14
NOVASVG_INLINE void font_face_cache_add(font_face_cache_t *cache, const char *family, bool bold, bool italic, font_face_t *face)
Add a font face to the cache with the specified family and style.
Definition font.h:5770
NOVASVG_INLINE bool canvas_clip_contains(canvas_t *canvas, float x, float y)
Tests whether a point lies within the current clipping region.
Definition canvas.h:522
NOVASVG_INLINE void font_face_cache_destroy(font_face_cache_t *cache)
Decrement the reference count of a font‐face cache and destroy it when it reaches zero.
Definition font.h:5708
NOVASVG_INLINE void canvas_map_point(const canvas_t *canvas, const point_t *src, point_t *dst)
Transforms the src point using the current transformation matrix and stores the result in dst.
Definition canvas.h:425
NOVASVG_INLINE float font_face_text_extents(font_face_t *face, float size, const void *text, int length, text_encoding_t encoding, rect_t *extents)
Computes the bounding box of a text string and its advance width.
Definition font.h:5616
NOVASVG_INLINE void canvas_set_rgba(canvas_t *canvas, float r, float g, float b, float a)
Sets the current paint to a solid color.
Definition canvas.h:170
texture_type_t
Defines the type of texture, either plain or tiled.
Definition render.h:1294
NOVASVG_INLINE void canvas_clip_extents(canvas_t *canvas, rect_t *extents)
Gets the bounding box of the current clipping region.
Definition canvas.h:548
NOVASVG_INLINE void canvas_fill_rect(canvas_t *canvas, float x, float y, float w, float h)
Fills a rectangle according to the current fill rule.
Definition canvas.h:622
NOVASVG_INLINE void canvas_add_path(canvas_t *canvas, const path_t *path)
Adds a path to the current path.
Definition canvas.h:485
NOVASVG_INLINE fill_rule_t canvas_get_fill_rule(const canvas_t *canvas)
Retrieves the current fill rule.
Definition canvas.h:286
NOVASVG_INLINE state_t * state_create(void)
Definition canvas.h:21
NOVASVG_INLINE float canvas_get_line_width(const canvas_t *canvas)
Retrieves the current line width.
Definition canvas.h:316
NOVASVG_INLINE void canvas_quad_to(canvas_t *canvas, float x1, float y1, float x2, float y2)
Adds a quadratic Bézier curve to the current path.
Definition canvas.h:445
NOVASVG_INLINE void canvas_font_metrics(const canvas_t *canvas, float *ascent, float *descent, float *line_gap, rect_t *extents)
Retrieves font metrics for the current font.
Definition canvas.h:719
NOVASVG_INLINE paint_t * canvas_get_paint(const canvas_t *canvas, color_t *color)
Retrieves the current paint.
Definition canvas.h:209
NOVASVG_INLINE void canvas_set_matrix(canvas_t *canvas, const matrix_t *matrix)
Resets the current transformation matrix to the specified matrix.
Definition canvas.h:410
NOVASVG_INLINE void font_face_destroy(font_face_t *face)
Decrements the reference count and potentially destroys the font face.
Definition font.h:5340
NOVASVG_INLINE void canvas_destroy(canvas_t *canvas)
Decreases the reference count and destroys the canvas when it reaches zero.
Definition canvas.h:108
NOVASVG_INLINE void path_move_to(path_t *path, float x, float y)
Moves the current point to a new position.
Definition path.h:93
NOVASVG_INLINE void canvas_set_line_join(canvas_t *canvas, line_join_t line_join)
Sets the line join style.
Definition canvas.h:331
NOVASVG_INLINE void path_arc_to(path_t *path, float rx, float ry, float angle, bool large_arc_flag, bool sweep_flag, float x, float y)
Adds an elliptical arc to the path.
Definition path.h:131
NOVASVG_INLINE void path_cubic_to(path_t *path, float x1, float y1, float x2, float y2, float x3, float y3)
Adds a cubic Bézier curve to the path.
Definition path.h:120
NOVASVG_INLINE float canvas_get_font_size(const canvas_t *canvas)
Retrieves the current font size used for text rendering on the canvas.
Definition canvas.h:276
NOVASVG_INLINE void canvas_scale(canvas_t *canvas, float sx, float sy)
Scales the current transformation matrix by factors sx and sy.
Definition canvas.h:385
NOVASVG_INLINE void canvas_stroke_extents(canvas_t *canvas, rect_t *extents)
Computes the bounding box of the area that would be affected by a stroke operation.
Definition canvas.h:542
unsigned int codepoint_t
Represents a Unicode code point.
Definition render.h:768
NOVASVG_INLINE void canvas_stroke(canvas_t *canvas)
A drawing operator that strokes the current path according to the current stroke settings.
Definition canvas.h:566
NOVASVG_INLINE void canvas_circle(canvas_t *canvas, float cx, float cy, float r)
Adds a circle to the current path.
Definition canvas.h:475
NOVASVG_INLINE float canvas_text_extents(canvas_t *canvas, const void *text, int length, text_encoding_t encoding, rect_t *extents)
Retrieves the extents of a text.
Definition canvas.h:756
NOVASVG_INLINE void canvas_stroke_path(canvas_t *canvas, const path_t *path)
Strokes a path with the current stroke settings.
Definition canvas.h:643
NOVASVG_INLINE float canvas_clip_text(canvas_t *canvas, const void *text, int length, text_encoding_t encoding, float x, float y)
Intersects the current clipping region with text at the specified origin.
Definition canvas.h:711
NOVASVG_INLINE void path_add_path(path_t *path, const path_t *source, const matrix_t *matrix)
Adds a sub-path to the path.
Definition path.h:380
NOVASVG_INLINE bool canvas_stroke_contains(canvas_t *canvas, float x, float y)
Tests whether a point lies within the current stroke region.
Definition canvas.h:516
NOVASVG_INLINE float canvas_add_text(canvas_t *canvas, const void *text, int length, text_encoding_t encoding, float x, float y)
Adds text to the current path at the specified origin.
Definition canvas.h:672
NOVASVG_INLINE void color_init_rgba(color_t *color, float r, float g, float b, float a)
Initializes a color using RGBA components in the 0-1 range.
Definition paint.h:16
NOVASVG_INLINE void canvas_new_path(canvas_t *canvas)
Starts a new path on the canvas.
Definition canvas.h:490
NOVASVG_INLINE bool canvas_fill_contains(canvas_t *canvas, float x, float y)
Tests whether a point lies within the current fill region.
Definition canvas.h:510
NOVASVG_INLINE void canvas_shear(canvas_t *canvas, float shx, float shy)
Shears the current transformation matrix by factors shx and shy.
Definition canvas.h:390
NOVASVG_INLINE font_face_cache_t * font_face_cache_reference(font_face_cache_t *cache)
Increments the reference count of a font‐face cache.
Definition font.h:5702
NOVASVG_INLINE float canvas_get_opacity(const canvas_t *canvas)
Retrieves the current global opacity.
Definition canvas.h:306
NOVASVG_INLINE path_t * canvas_get_path(const canvas_t *canvas)
Gets the current path from the canvas.
Definition canvas.h:505
NOVASVG_INLINE void canvas_set_font_size(canvas_t *canvas, float size)
Sets the font size for text rendering on the canvas.
Definition canvas.h:271
NOVASVG_INLINE void canvas_save(canvas_t *canvas)
Saves the current state of the canvas.
Definition canvas.h:142
NOVASVG_INLINE canvas_t * canvas_reference(canvas_t *canvas)
Increases the reference count of the canvas.
Definition canvas.h:102
NOVASVG_INLINE float canvas_stroke_text(canvas_t *canvas, const void *text, int length, text_encoding_t encoding, float x, float y)
Strokes a text at the specified origin.
Definition canvas.h:703
NOVASVG_INLINE void path_get_current_point(const path_t *path, float *x, float *y)
Retrieves the current point of the path.
Definition path.h:225
NOVASVG_INLINE paint_t * paint_reference(paint_t *paint)
Increments the reference count of a paint object.
Definition paint.h:488
NOVASVG_INLINE void canvas_fill(canvas_t *canvas)
A drawing operator that fills the current path according to the current fill rule.
Definition canvas.h:560
NOVASVG_INLINE void path_destroy(path_t *path)
Decreases the reference count of a path object.
Definition path.h:61
NOVASVG_INLINE void path_close(path_t *path)
Closes the current sub-path.
Definition path.h:217
NOVASVG_INLINE void canvas_line_to(canvas_t *canvas, float x, float y)
Adds a straight line segment to the current path.
Definition canvas.h:440
NOVASVG_INLINE void canvas_set_dash_offset(canvas_t *canvas, float offset)
Sets the dash offset.
Definition canvas.h:357
NOVASVG_INLINE void font_face_get_glyph_metrics(font_face_t *face, float size, codepoint_t codepoint, float *advance_width, float *left_side_bearing, rect_t *extents)
Retrieves metrics for a specified glyph at a given size.
Definition font.h:5441
NOVASVG_INLINE float canvas_get_miter_limit(const canvas_t *canvas)
Retrieves the current miter limit.
Definition canvas.h:346
NOVASVG_INLINE void canvas_arc_to(canvas_t *canvas, float rx, float ry, float angle, bool large_arc_flag, bool sweep_flag, float x, float y)
Adds an elliptical arc to the current path.
Definition canvas.h:455
NOVASVG_INLINE void canvas_set_fill_rule(canvas_t *canvas, fill_rule_t winding)
Sets the fill rule.
Definition canvas.h:281
void surface_destroy(surface_t *surface)
Decrements the reference count and destroys the surface if the count reaches zero.
Definition surface.h:7926
NOVASVG_INLINE font_face_t * font_face_cache_get(font_face_cache_t *cache, const char *family, bool bold, bool italic)
Retrieve a font face from the cache by family and style.
Definition font.h:5812
NOVASVG_INLINE void canvas_set_opacity(canvas_t *canvas, float opacity)
Sets the global opacity.
Definition canvas.h:301
NOVASVG_INLINE void state_destroy(state_t *state)
Definition canvas.h:78
NOVASVG_INLINE void matrix_init_identity(matrix_t *matrix)
Initializes a 2D transformation matrix to the identity matrix.
Definition matrix.h:15
NOVASVG_INLINE bool canvas_select_font_face(canvas_t *canvas, const char *family, bool bold, bool italic)
Selects and sets the current font face on the canvas.
Definition canvas.h:242
NOVASVG_INLINE surface_t * canvas_get_surface(const canvas_t *canvas)
Gets the surface associated with the canvas.
Definition canvas.h:137
NOVASVG_INLINE void canvas_ellipse(canvas_t *canvas, float cx, float cy, float rx, float ry)
Adds an ellipse to the current path.
Definition canvas.h:470
NOVASVG_INLINE void state_reset(state_t *state)
Definition canvas.h:41
NOVASVG_INLINE void canvas_set_radial_gradient(canvas_t *canvas, float cx, float cy, float cr, float fx, float fy, float fr, spread_method_t spread, const gradient_stop_t *stops, int nstops, const matrix_t *matrix)
Sets the current paint to a radial gradient.
Definition canvas.h:188
line_join_t
Defines the shape used at the corners of paths.
Definition render.h:1464
NOVASVG_INLINE void matrix_shear(matrix_t *matrix, float shx, float shy)
Shears the matrix by factors shx and shy.
Definition matrix.h:63
fill_rule_t
Defines fill rule types for filling paths.
Definition render.h:1421
@ NOVASVG_FILL_RULE_NON_ZERO
Non-zero winding fill rule.
Definition render.h:1422
NOVASVG_INLINE void canvas_map_rect(const canvas_t *canvas, const rect_t *src, rect_t *dst)
Transforms the src rectangle using the current transformation matrix and stores the result in dst.
Definition canvas.h:430
NOVASVG_INLINE canvas_t * canvas_create(surface_t *surface)
Creates a drawing context on a surface.
Definition canvas.h:87
NOVASVG_INLINE void canvas_set_rgb(canvas_t *canvas, float r, float g, float b)
Sets the current paint to a solid color.
Definition canvas.h:165
NOVASVG_INLINE line_join_t canvas_get_line_join(const canvas_t *canvas)
Retrieves the current line join style.
Definition canvas.h:336
NOVASVG_INLINE float font_face_get_kern_advance(font_face_t *face, float size, codepoint_t ch1, codepoint_t ch2)
Definition font.h:5466
NOVASVG_INLINE void canvas_get_current_point(const canvas_t *canvas, float *x, float *y)
Retrieves the current point of the canvas.
Definition canvas.h:500
NOVASVG_INLINE void path_add_ellipse(path_t *path, float cx, float cy, float rx, float ry)
Adds an ellipse to the path.
Definition path.h:291
NOVASVG_INLINE void canvas_set_paint(canvas_t *canvas, paint_t *paint)
Sets the current paint.
Definition canvas.h:202
NOVASVG_INLINE void canvas_paint(canvas_t *canvas)
A drawing operator that paints the current clipping region using the current paint.
Definition canvas.h:578
NOVASVG_INLINE void path_add_arc(path_t *path, float cx, float cy, float r, float a0, float a1, bool ccw)
Adds an arc to the path.
Definition path.h:315
NOVASVG_INLINE void canvas_fill_path(canvas_t *canvas, const path_t *path)
Fills a path according to the current fill rule.
Definition canvas.h:629
NOVASVG_INLINE line_cap_t canvas_get_line_cap(const canvas_t *canvas)
Retrieves the current line cap style.
Definition canvas.h:326
NOVASVG_INLINE void path_quad_to(path_t *path, float x1, float y1, float x2, float y2)
Adds a quadratic Bézier curve to the path.
Definition path.h:109
NOVASVG_INLINE void canvas_add_font_face(canvas_t *canvas, const char *family, bool bold, bool italic, font_face_t *face)
Add a font face to the canvas using the specified family and style.
Definition canvas.h:228
NOVASVG_INLINE void canvas_translate(canvas_t *canvas, float tx, float ty)
Translates the current transformation matrix by offsets tx and ty.
Definition canvas.h:380
NOVASVG_INLINE void blend(canvas_t *canvas, const span_buffer_t *span_buffer)
Definition blend.h:1215
NOVASVG_INLINE void canvas_set_font_face(canvas_t *canvas, font_face_t *face)
Sets the font face for text rendering on the canvas.
Definition canvas.h:259
enum novasvg::render::text_encoding text_encoding_t
Text encodings used for converting text data to code points.
NOVASVG_INLINE void canvas_get_matrix(const canvas_t *canvas, matrix_t *matrix)
Stores the current transformation matrix in matrix.
Definition canvas.h:415
NOVASVG_INLINE void canvas_reset_matrix(canvas_t *canvas)
Resets the current transformation matrix to the identity matrix.
Definition canvas.h:405
NOVASVG_INLINE font_face_cache_t * canvas_get_font_face_cache(const canvas_t *canvas)
Returns the font-face cache associated with the canvas.
Definition canvas.h:223
line_cap_t
Defines the shape used at the ends of open subpaths.
Definition render.h:1455
NOVASVG_INLINE void canvas_stroke_preserve(canvas_t *canvas)
A drawing operator that strokes the current path according to the current stroke settings.
Definition canvas.h:599
NOVASVG_INLINE paint_t * paint_create_linear_gradient(float x1, float y1, float x2, float y2, spread_method_t spread, const gradient_stop_t *stops, int nstops, const matrix_t *matrix)
Creates a linear gradient paint.
Definition paint.h:453
NOVASVG_INLINE int render_version(void)
Gets the version of the novasvg rendering library.
Definition canvas.h:9
NOVASVG_INLINE void canvas_transform(canvas_t *canvas, const matrix_t *matrix)
Multiplies the current transformation matrix with the specified matrix.
Definition canvas.h:400
NOVASVG_INLINE void path_reset(path_t *path)
Resets the path.
Definition path.h:243
NOVASVG_INLINE void path_add_round_rect(path_t *path, float x, float y, float w, float h, float rx, float ry)
Adds a rounded rectangle to the path.
Definition path.h:263
NOVASVG_INLINE operator_t canvas_get_operator(const canvas_t *canvas)
Retrieves the current compositing operator.
Definition canvas.h:296
NOVASVG_INLINE void canvas_set_texture(canvas_t *canvas, surface_t *surface, texture_type_t type, float opacity, const matrix_t *matrix)
Sets the current paint to a texture.
Definition canvas.h:195
operator_t
Defines compositing operations.
Definition render.h:1429
@ NOVASVG_OPERATOR_SRC_OVER
Source is composited over destination.
Definition render.h:1433
void span_buffer_reset(span_buffer_t *span_buffer)
Definition rasterize.h:39
NOVASVG_INLINE codepoint_t text_iterator_next(text_iterator_t *it)
Retrieves the next code point and advances the iterator.
Definition font.h:5046
NOVASVG_INLINE bool canvas_add_font_file(canvas_t *canvas, const char *family, bool bold, bool italic, const char *filename, int ttcindex)
Load a font face from a file and add it to the canvas using the specified family and style.
Definition canvas.h:235
NOVASVG_INLINE void canvas_set_miter_limit(canvas_t *canvas, float miter_limit)
Sets the miter limit.
Definition canvas.h:341
NOVASVG_INLINE paint_t * paint_create_texture(surface_t *surface, texture_type_t type, float opacity, const matrix_t *matrix)
Creates a texture paint from a surface.
Definition paint.h:475
NOVASVG_INLINE void canvas_set_operator(canvas_t *canvas, operator_t op)
Sets the compositing operator.
Definition canvas.h:291
NOVASVG_INLINE void canvas_set_linear_gradient(canvas_t *canvas, float x1, float y1, float x2, float y2, spread_method_t spread, const gradient_stop_t *stops, int nstops, const matrix_t *matrix)
Sets the current paint to a linear gradient.
Definition canvas.h:181
NOVASVG_INLINE void font_face_get_metrics(const font_face_t *face, float size, float *ascent, float *descent, float *line_gap, rect_t *extents)
Retrieves metrics for a font face at a specified size.
Definition font.h:5422
NOVASVG_INLINE void canvas_fill_preserve(canvas_t *canvas)
A drawing operator that fills the current path according to the current fill rule.
Definition canvas.h:588
void span_buffer_destroy(span_buffer_t *span_buffer)
Definition rasterize.h:48
NOVASVG_INLINE float canvas_add_glyph(canvas_t *canvas, codepoint_t codepoint, float x, float y)
Adds a glyph to the current path at the specified origin.
Definition canvas.h:664
NOVASVG_INLINE bool text_iterator_has_next(const text_iterator_t *it)
Checks if there are more code points to iterate.
Definition font.h:5041
void span_buffer_copy(span_buffer_t *span_buffer, const span_buffer_t *source)
Definition rasterize.h:53
NOVASVG_INLINE void canvas_fill_extents(canvas_t *canvas, rect_t *extents)
Computes the bounding box of the area that would be affected by a fill operation.
Definition canvas.h:536
NOVASVG_INLINE void canvas_set_line_width(canvas_t *canvas, float line_width)
Sets the line width.
Definition canvas.h:311
NOVASVG_INLINE void canvas_set_line_cap(canvas_t *canvas, line_cap_t line_cap)
Sets the line cap style.
Definition canvas.h:321
NOVASVG_INLINE void matrix_scale(matrix_t *matrix, float sx, float sy)
Scales the matrix by factors sx and sy
Definition matrix.h:49
NOVASVG_INLINE bool font_face_cache_add_file(font_face_cache_t *cache, const char *family, bool bold, bool italic, const char *filename, int ttcindex)
Load a font face from a file and add it to the cache with the specified family and style.
Definition font.h:5788
NOVASVG_INLINE void state_copy(state_t *state, const state_t *source)
Definition canvas.h:60
NOVASVG_INLINE void path_line_to(path_t *path, float x, float y)
Adds a straight line segment to the path.
Definition path.h:101
NOVASVG_INLINE void canvas_set_color(canvas_t *canvas, const color_t *color)
Sets the current paint to a solid color.
Definition canvas.h:176
void span_buffer_extents(span_buffer_t *span_buffer, rect_t *extents)
Definition rasterize.h:108
NOVASVG_INLINE float font_face_get_glyph_path(font_face_t *face, float size, float x, float y, codepoint_t codepoint, path_t *path)
Retrieves the path of a glyph and its advance width.
Definition font.h:5490
NOVASVG_INLINE void canvas_cubic_to(canvas_t *canvas, float x1, float y1, float x2, float y2, float x3, float y3)
Adds a cubic Bézier curve to the current path.
Definition canvas.h:450
NOVASVG_INLINE void matrix_multiply(matrix_t *matrix, const matrix_t *left, const matrix_t *right)
Multiplies left and right matrices and stores the result in matrix.
Definition matrix.h:70
NOVASVG_INLINE int canvas_get_dash_array(const canvas_t *canvas, const float **dashes)
Retrieves the current dash pattern.
Definition canvas.h:373
NOVASVG_INLINE void canvas_close_path(canvas_t *canvas)
Closes the current path.
Definition canvas.h:495
NOVASVG_INLINE paint_t * paint_create_radial_gradient(float cx, float cy, float cr, float fx, float fy, float fr, spread_method_t spread, const gradient_stop_t *stops, int nstops, const matrix_t *matrix)
Creates a radial gradient paint.
Definition paint.h:463
void span_buffer_intersect(span_buffer_t *span_buffer, const span_buffer_t *a, const span_buffer_t *b)
Definition rasterize.h:117
spread_method_t
Defines the spread method for gradients.
Definition render.h:1302
NOVASVG_INLINE void canvas_set_font_face_cache(canvas_t *canvas, font_face_cache_t *cache)
Assigns a font-face cache to the canvas for font management.
Definition canvas.h:216
NOVASVG_INLINE void matrix_rotate(matrix_t *matrix, float angle)
Rotates the matrix by the specified angle (in radians).
Definition matrix.h:56
NOVASVG_INLINE void canvas_set_font(canvas_t *canvas, font_face_t *face, float size)
Sets the font face and size for text rendering on the canvas.
Definition canvas.h:253
NOVASVG_INLINE void canvas_map(const canvas_t *canvas, float x, float y, float *xx, float *yy)
Transforms the point (x, y) using the current transformation matrix and stores the result in (xx,...
Definition canvas.h:420
NOVASVG_INLINE void canvas_restore(canvas_t *canvas)
Restores the canvas to the most recently saved state.
Definition canvas.h:154
NOVASVG_INLINE void text_iterator_init(text_iterator_t *it, const void *text, int length, text_encoding_t encoding)
Initializes a text iterator.
Definition font.h:5031
NOVASVG_INLINE void path_add_circle(path_t *path, float cx, float cy, float r)
Adds a circle to the path.
Definition path.h:310
NOVASVG_INLINE void canvas_rotate(canvas_t *canvas, float angle)
Rotates the current transformation matrix by the specified angle (in radians).
Definition canvas.h:395
NOVASVG_INLINE void canvas_rect(canvas_t *canvas, float x, float y, float w, float h)
Adds a rectangle to the current path.
Definition canvas.h:460
NOVASVG_INLINE void canvas_clip_preserve(canvas_t *canvas)
A drawing operator that intersects the current clipping region with the current path according to the...
Definition canvas.h:610
surface_t * surface_reference(surface_t *surface)
Increments the reference count for a surface.
Definition surface.h:7920
NOVASVG_INLINE void canvas_set_dash_array(canvas_t *canvas, const float *dashes, int ndashes)
Sets the dash pattern.
Definition canvas.h:367
NOVASVG_INLINE const char * render_version_string(void)
Gets the version of the novasvg rendering library as a string.
Definition canvas.h:14
NOVASVG_INLINE float canvas_fill_text(canvas_t *canvas, const void *text, int length, text_encoding_t encoding, float x, float y)
Fills a text at the specified origin.
Definition canvas.h:695
bool span_buffer_contains(const span_buffer_t *span_buffer, float x, float y)
Definition rasterize.h:63
NOVASVG_INLINE void matrix_translate(matrix_t *matrix, float tx, float ty)
Adds a translation with offsets tx and ty to the matrix.
Definition matrix.h:42
NOVASVG_INLINE void matrix_map_rect(const matrix_t *matrix, const rect_t *src, rect_t *dst)
Transforms the src rectangle using matrix and stores the result in dst.
Definition matrix.h:118
NOVASVG_INLINE font_face_t * font_face_reference(font_face_t *face)
Increments the reference count of a font face.
Definition font.h:5334
NOVASVG_INLINE void canvas_set_dash(canvas_t *canvas, float offset, const float *dashes, int ndashes)
Sets the dash pattern.
Definition canvas.h:351
NOVASVG_INLINE font_face_cache_t * font_face_cache_create(void)
Create a new, empty font‐face cache.
Definition font.h:5690
NOVASVG_INLINE void canvas_glyph_metrics(canvas_t *canvas, codepoint_t codepoint, float *advance_width, float *left_side_bearing, rect_t *extents)
Retrieves metrics for a specific glyph.
Definition canvas.h:738
void rasterize(span_buffer_t *span_buffer, const path_t *path, const matrix_t *matrix, const rect_t *clip_rect, const stroke_data_t *stroke_data, fill_rule_t winding)
Definition rasterize.h:383
NOVASVG_INLINE void canvas_clip_path(canvas_t *canvas, const path_t *path)
Intersects the current clipping region with a path according to the current fill rule.
Definition canvas.h:657
NOVASVG_INLINE void path_add_rect(path_t *path, float x, float y, float w, float h)
Adds a rectangle to the path.
Definition path.h:252
NOVASVG_INLINE void canvas_clip_rect(canvas_t *canvas, float x, float y, float w, float h)
Intersects the current clipping region with a rectangle according to the current fill rule.
Definition canvas.h:650
NOVASVG_INLINE void canvas_round_rect(canvas_t *canvas, float x, float y, float w, float h, float rx, float ry)
Adds a rounded rectangle to the current path.
Definition canvas.h:465
Main namespace for the NovaSVG library.
Definition bitmap.h:23
#define NOVASVG_INLINE
Definition novasvg.h:42
#define novasvg_get_reference_count(ob)
Definition private.h:48
#define novasvg_destroy_reference(ob)
Definition private.h:47
#define novasvg_init_reference(ob)
Definition private.h:45
#define novasvg_increment_reference(ob)
Definition private.h:46
#define NOVASVG_DEFAULT_STROKE_STYLE
Definition canvas.h:19
#define NOVASVG_BLACK_COLOR
Definition render.h:1028
#define NOVASVG_RENDER_VERSION_STRING
Definition render.h:74
#define NOVASVG_MAKE_RECT(x, y, w, h)
Definition render.h:132
#define NOVASVG_RENDER_VERSION
Definition render.h:70
#define NOVASVG_IDENTITY_MATRIX
Definition render.h:150
span_buffer_t fill_spans
Definition private.h:177
font_face_cache_t * face_cache
Definition private.h:174
span_buffer_t clip_spans
Definition private.h:176
surface_t * surface
Definition private.h:170
Represents a color with red, green, blue, and alpha components.
Definition render.h:1019
float b
Blue component (0 to 1).
Definition render.h:1022
float g
Green component (0 to 1).
Definition render.h:1021
float a
Alpha (opacity) component (0 to 1).
Definition render.h:1023
float r
Red component (0 to 1).
Definition render.h:1020
Represents a gradient stop.
Definition render.h:1311
A structure representing a 2D transformation matrix.
Definition render.h:138
A structure representing a point in 2D space.
Definition render.h:114
A structure representing a rectangle in 2D space.
Definition render.h:125
float x
The x-coordinate of the top-left corner of the rectangle.
Definition render.h:126
float w
The width of the rectangle.
Definition render.h:128
float h
The height of the rectangle.
Definition render.h:129
float y
The y-coordinate of the top-left corner of the rectangle.
Definition render.h:127
span_buffer_t clip_spans
Definition private.h:159
fill_rule_t winding
Definition private.h:160
font_face_t * font_face
Definition private.h:155
stroke_data_t stroke
Definition private.h:158
struct state * next
Definition private.h:165
struct novasvg::render::stroke_dash_t::@13 array
Iterator for traversing code points in text data.
Definition render.h:758
std::string text
UTF-8; ' ' marks a forced line break ( ,.
#define novasvg_array_append_data(array, newdata, count)
Definition utils.h:60
#define novasvg_array_destroy(array)
Definition utils.h:71
#define novasvg_array_append(array, other)
Definition utils.h:69
#define novasvg_array_clear(array)
Definition utils.h:70
#define novasvg_array_init(array)
Definition utils.h:36