33 void scale(
float sx,
float sy)
override;
36 float d,
float e,
float f)
override;
38 float d,
float e,
float f)
override;
41 void clip_rect(
float x,
float y,
float w,
float h)
override;
71 const Color* colors,
const float* positions,
74 const Color* colors,
const float* positions,
80 float x0,
float y0,
float r0,
81 float x1,
float y1,
float r1,
82 const Color* colors,
const float* positions,
int count)
override;
85 const Color* colors,
const float* positions,
88 const Color* colors,
const float* positions,
98 const Color* colors,
const float* positions,
101 const Color* colors,
const float* positions,
104 float x0,
float y0,
float r0,
105 float x1,
float y1,
float r1,
106 const Color* colors,
const float* positions,
int count)
override;
108 const Color* colors,
const float* positions,
122 void fill_rect(
float x,
float y,
float w,
float h)
override;
123 void clear_rect(
float x,
float y,
float w,
float h)
override;
130 float start_angle,
float end_angle)
override;
131 void stroke_line(
float x0,
float y0,
float x1,
float y1)
override;
149 float blur,
float spread,
Color color)
override;
167 void quad_to(
float cpx,
float cpy,
float x,
float y)
override;
168 void cubic_to(
float cp1x,
float cp1y,
float cp2x,
float cp2y,
169 float x,
float y)
override;
175 void arc(
float cx,
float cy,
float radius,
176 float start_angle,
float end_angle,
177 bool anticlockwise)
override;
178 void arc_to(
float x1,
float y1,
float x2,
float y2,
179 float radius)
override;
180 void ellipse(
float cx,
float cy,
float rx,
float ry,
182 float start_angle,
float end_angle,
183 bool anticlockwise)
override;
185 float tl_x,
float tl_y,
186 float tr_x,
float tr_y,
187 float br_x,
float br_y,
188 float bl_x,
float bl_y)
override;
192 float opacity,
float blur_radius)
override;
203 void set_font(
const std::string& family,
float size)
override;
204 void set_font_full(
const std::string& family,
float size,
int weight,
int slant,
205 float letter_spacing)
override;
212 float x,
float y,
float max_width)
override;
214 float max_width = 0.0f)
override;
218 std::size_t byte_index)
override;
245 float x,
float y,
float w,
float h)
override;
247 float x,
float y,
float w,
float h)
override;
249 float sx,
float sy,
float sw,
float sh,
250 float dx,
float dy,
float dw,
float dh)
override;
252 float sx,
float sy,
float sw,
float sh,
253 float dx,
float dy,
float dw,
float dh)
override;
255 float& out_height)
override;
257 float& out_width,
float& out_height)
override;
266 float sx,
float sy,
float sw,
float sh,
267 float dx,
float dy,
float dw,
float dh);
270 float width_, height_;
274 std::vector<bool> save_is_layer_;
277 std::string font_family_ =
"Helvetica";
278 float font_size_ = 14.0f;
279 int font_weight_ = 400;
281 std::vector<FontFeature> font_features_;
298 enum class GradientKind { none, linear, radial, radial_two_circles, conic_image };
299 bool has_gradient_ =
false;
300 GradientKind gradient_kind_ = GradientKind::none;
301 bool gradient_is_radial_ =
false;
302 float grad_x0_ = 0, grad_y0_ = 0, grad_x1_ = 0, grad_y1_ = 0;
303 float grad_radius_ = 0;
304 float grad_radius_inner_ = 0;
305 std::vector<Color> grad_colors_;
306 std::vector<float> grad_positions_;
310 bool has_stroke_gradient_ =
false;
311 GradientKind stroke_gradient_kind_ = GradientKind::none;
312 float stroke_grad_x0_ = 0, stroke_grad_y0_ = 0, stroke_grad_x1_ = 0, stroke_grad_y1_ = 0;
313 float stroke_grad_radius_ = 0;
314 float stroke_grad_radius_inner_ = 0;
315 std::vector<Color> stroke_grad_colors_;
316 std::vector<float> stroke_grad_positions_;
325 float conic_image_x_ = 0, conic_image_y_ = 0;
326 float conic_image_w_ = 0, conic_image_h_ = 0;
327 void release_conic_image();
334 bool has_pattern_ =
false;
338 void release_pattern_image();
343 bool has_baseline_ =
false;
347 double baseline_xform_[6] = {1, 0, 0, 1, 0, 0};
361 Color shadow_color_ =
Color::rgba(0.0f, 0.0f, 0.0f, 0.0f);
362 float shadow_blur_ = 0.0f;
363 float shadow_offset_x_ = 0.0f;
364 float shadow_offset_y_ = 0.0f;
365 void apply_shadow_to_context();
373 std::vector<float> line_dash_;
374 float line_dash_phase_ = 0.0f;
375 void apply_line_dash_to_ctx();
376 void reset_line_dash_on_ctx();
378 void apply_fill_color();
379 void apply_stroke_color();
380 void add_rounded_rect_path(
float x,
float y,
float w,
float h,
float radius);
383 void fill_with_active_paint();
389 void stroke_with_active_paint(
bool apply_sticky_dash =
true);
401 float scale_x = 1.0f;
402 float scale_y = 1.0f;
403 bool cacheable =
false;
405 std::vector<std::pair<uint64_t, CgLayer>> layers_;
411 std::vector<CgOpenLayer> open_layers_;
412 uint64_t next_layer_id_ = 1;
414 CgLayer* find_layer(uint64_t
id);
415 const CgLayer* find_layer(uint64_t
id)
const;
417 void release_layer(CgLayer& layer);
struct CGImage * CGImageRef
Definition cg_canvas.hpp:12
struct CGPath * CGMutablePathRef
Definition cg_canvas.hpp:11
struct CGContext * CGContextRef
Definition cg_canvas.hpp:10
struct CGPattern * CGPatternRef
Definition cg_canvas.hpp:13
Definition canvas.hpp:240
pulp::canvas::Point2D Point2D
Stroke a continuous polyline through an array of points.
Definition canvas.hpp:682
BlendMode
Indices 0..15 match the existing W3C "advanced" composite ops and must stay stable — set_blend_mode i...
Definition canvas.hpp:527
@ color
Definition canvas.hpp:531
@ normal
Definition canvas.hpp:529
virtual void stroke_path(const Point2D *points, size_t count)
Stroke a continuous polyline — much smoother than individual stroke_line calls.
Definition canvas.hpp:685
ImageSmoothingQuality
Canvas2D image-smoothing quality enum.
Definition canvas.hpp:382
virtual void fill_path(const Point2D *points, size_t count, FillRule rule=FillRule::nonzero)
Fill a closed polygon defined by points, honoring rule.
Definition canvas.hpp:712
PatternTileMode
Canvas2D ctx.createPattern.
Definition canvas.hpp:497
@ repeat
Definition canvas.hpp:497
void stroke_text(const std::string &text, float x, float y, float max_width=0.0f) override
Canvas2D strokeText(text, x, y, maxWidth) spec form.
void clear_rect(float x, float y, float w, float h) override
Clear a rectangular region to transparent black (rgba 0,0,0,0).
bool draw_image_from_file(const std::string &path, float x, float y, float w, float h) override
Draw an image from a file path at the given rect.
void set_fill_gradient_conic_repeating(float cx, float cy, float start_angle, float sweep_turns, const Color *colors, const float *positions, int count) override
Set a REPEATING conic gradient (CSS repeating-conic-gradient).
bool draw_image_from_data_rect(const uint8_t *data, size_t size, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) override
void round_rect(float x, float y, float w, float h, float tl_x, float tl_y, float tr_x, float tr_y, float br_x, float br_y, float bl_x, float bl_y) override
Native rounded-rectangle subpath with per-corner radii.
void set_shadow_blur(float blur) override
void fill_circle(float cx, float cy, float radius) override
void set_image_smoothing(bool enabled, ImageSmoothingQuality quality) override
Canvas2D ctx.imageSmoothingEnabled + imageSmoothingQuality.
void stroke_rounded_rect(float x, float y, float w, float h, float radius) override
void stroke_rect(float x, float y, float w, float h) override
void stroke_arc(float cx, float cy, float radius, float start_angle, float end_angle) override
void fill_rounded_rect(float x, float y, float w, float h, float radius) override
void set_font_full(const std::string &family, float size, int weight, int slant, float letter_spacing) override
Richer font setter that propagates CSS font-weight (100..900), font-slant (0=upright,...
void clear_font_features() override
float text_x_for_byte(const std::string &text, std::size_t byte_index) override
Caret x (in text-local space, measured from the text's leading edge) for the glyph boundary at byte_i...
float measure_text(const std::string &text) override
void set_shadow_offset_x(float dx) override
void set_line_cap(LineCap cap) override
void invalidate_layer(LayerHandle layer) override
Drop layer's texture.
void capture_paint_baseline_transform() override
Snapshot the current device matrix as the baseline for subsequent set_transform() calls.
void ellipse(float cx, float cy, float rx, float ry, float rotation, float start_angle, float end_angle, bool anticlockwise) override
Native ellipse subpath.
void set_fill_gradient_radial(float cx, float cy, float radius, const Color *colors, const float *positions, int count) override
Set a radial gradient as the fill paint.
void set_line_width(float w) override
void fill_path(const Point2D *points, size_t count, FillRule rule=FillRule::nonzero) override
Fill a closed polygon defined by points, honoring rule.
TextMetrics measure_text_full(const std::string &text) override
Measure text with full font metrics using current font settings.
bool draw_image_from_file_rect(const std::string &path, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) override
bool supports(CanvasCapability cap) const override
Report whether this backend renders cap's verb faithfully.
Definition cg_canvas.hpp:235
void set_stroke_gradient_conic(float cx, float cy, float start_angle, const Color *colors, const float *positions, int count) override
void set_opacity(float alpha) override
Set global alpha for subsequent drawing operations (0.0-1.0).
bool layer_valid(LayerHandle layer) const override
Is layer still backed by a live texture that can be drawn WITHOUT re-recording it?
void fill_text_with_max_width(const std::string &text, float x, float y, float max_width) override
Canvas2D fillText(text, x, y, maxWidth) spec form.
void restore_to_count(int target) override
Pop the save stack down to target (typically captured earlier via save_count()).
float backing_scale() const noexcept override
Effective device pixels per local canvas unit at the current transform.
void stroke_path(const Path &path, const StrokeStyle &style) override
Stroke path with style.
void draw_path_shadow(const Path &path, float dx, float dy, float blur, float spread, Color color) override
Draw ONLY the drop shadow cast by path — not the path itself.
void set_line_dash(const float *intervals, int count, float phase) override
Set the line dash pattern for stroke operations.
void fill_path(const Path &path, FillRule rule=FillRule::nonzero) override
Fill path under rule.
void set_miter_limit(float limit) override
Canvas2D ctx.miterLimit.
void clear_fill_gradient() override
Clear gradient, return to solid fill color.
void set_line_join(LineJoin join) override
void save_layer(float x, float y, float w, float h, float opacity, float blur_radius) override
Save a compositing layer.
bool draw_image_from_data(const uint8_t *data, size_t size, float x, float y, float w, float h) override
Draw an image from encoded data (PNG, JPEG, WebP) at the given rect.
void concat_transform(float a, float b, float c, float d, float e, float f) override
Concat (multiply) the supplied affine matrix onto the current transform — does NOT replace it.
void set_stroke_gradient_linear(float x0, float y0, float x1, float y1, const Color *colors, const float *positions, int count) override
void set_blend_mode(BlendMode mode) override
Set the compositing blend mode for subsequent draw operations.
void draw_layer_fitted(LayerHandle layer, Rect2D dest) override
Composite a sealed layer scaled into dest.
bool measure_image_from_file(const std::string &path, float &out_width, float &out_height) override
Decoded-image intrinsic dimensions in pixels.
void arc(float cx, float cy, float radius, float start_angle, float end_angle, bool anticlockwise) override
Native arc subpath.
void clear_stroke_gradient() override
Clear stroke gradient/pattern shader, restore solid stroke color.
void arc_to(float x1, float y1, float x2, float y2, float radius) override
Native arcTo.
void set_transform(float a, float b, float c, float d, float e, float f) override
Replace the current transform with the affine matrix [ a c e ] [ b d f ] [ 0 0 1 ] Mirrors CanvasRend...
void stroke_line(float x0, float y0, float x1, float y1) override
void fill_text(const std::string &text, float x, float y) override
void stroke_path(const Point2D *points, size_t count) override
Stroke a continuous polyline — much smoother than individual stroke_line calls.
void set_stroke_color(Color c) override
LayerHandle end_layer() override
Seal the layer opened by the last begin_layer() and return its handle.
void set_shadow_color(Color color) override
Sticky drop-shadow state that wraps subsequent draw operations, matching the CanvasRenderingContext2D...
AffineTransform2x3 current_transform() const override
Snapshot the current device matrix (CTM) without mutating canvas state.
void stroke_circle(float cx, float cy, float radius) override
CoreGraphicsCanvas(CGContextRef ctx, float width, float height)
void set_stroke_gradient_radial_two_circles(float x0, float y0, float r0, float x1, float y1, float r1, const Color *colors, const float *positions, int count) override
Two-circle radial gradient on stroke (mirrors fill counterpart).
void draw_layer_rotated(LayerHandle layer, float angle_rad) override
Composite a sealed layer rotated about its own center.
void set_fill_gradient_radial_two_circles(float x0, float y0, float r0, float x1, float y1, float r1, const Color *colors, const float *positions, int count) override
True two-circle radial gradient via CGContextDrawRadialGradient(inner_center, inner_r,...
void set_fill_gradient_linear(float x0, float y0, float x1, float y1, const Color *colors, const float *positions, int count) override
Set a linear gradient as the fill paint.
void set_font(const std::string &family, float size) override
void close_path() override
Close the current path subpath.
void clip(FillRule rule=FillRule::nonzero) override
Intersect the current clip region with the current path.
void set_font_features(std::vector< FontFeature > features) override
void translate(float x, float y) override
RendererBackend renderer_backend() const noexcept override
Identity of the renderer this canvas actually wraps.
Definition cg_canvas.hpp:21
LayerHandle begin_layer(Rect2D bounds, bool cacheable=false) override
Begin recording into an offscreen layer covering bounds (in current user space).
void set_fill_pattern(const std::string &image_src, PatternTileMode tile_x, PatternTileMode tile_y) override
Set an image pattern as the fill paint.
void set_fill_color(Color c) override
void clip_path(const Path &path, FillRule rule=FillRule::nonzero) override
Intersect the current clip with path. Caller owns save()/restore().
void stroke_current_path() override
Stroke the current path.
void line_to(float x, float y) override
Add a line segment to (x, y).
void clip_rect(float x, float y, float w, float h) override
void move_to(float x, float y) override
Move the pen to (x, y) without drawing.
void fill_rect(float x, float y, float w, float h) override
void rotate(float radians) override
void set_stroke_pattern(const std::string &image_src, PatternTileMode tile_x, PatternTileMode tile_y) override
Stroke counterpart.
void set_text_align(TextAlign align) override
void set_font_smoothing(FontSmoothing smoothing) override
antialiased turns CoreText font smoothing off, the switch Chromium flips on macOS.
void begin_path() override
Begin a new path.
void scale(float sx, float sy) override
void cubic_to(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) override
Add a cubic bezier curve.
void set_stroke_gradient_radial(float cx, float cy, float radius, const Color *colors, const float *positions, int count) override
void set_fill_gradient_conic(float cx, float cy, float start_angle, const Color *colors, const float *positions, int count) override
Set a conic (sweep) gradient as the fill paint.
void fill_current_path(FillRule rule=FillRule::nonzero) override
Fill the current path.
void draw_layer(LayerHandle layer, float alpha=1.0f, BlendMode mode=BlendMode::normal) override
Composite a sealed layer at its recorded position.
bool measure_image_from_data(const uint8_t *data, size_t size, float &out_width, float &out_height) override
Intrinsic pixel size of encoded image bytes, read from the image header without decoding pixels: the ...
void quad_to(float cpx, float cpy, float x, float y) override
Add a quadratic bezier curve to (x, y) with control point (cpx, cpy).
void set_shadow_offset_y(float dy) override
int save_count() const override
Return the current save-stack depth.
Definition cg_canvas.hpp:30
Definition affine_transform.hpp:24
TextAlign
Definition canvas.hpp:221
@ left
Definition canvas.hpp:221
FontSmoothing
CSS -webkit-font-smoothing as it affects glyph rasterization on macOS.
Definition text_raster_policy.hpp:40
CanvasCapability
Queryable backend capabilities.
Definition canvas_capability.hpp:19
@ images
draw_image_from_* really decode + draw
Definition canvas_capability.hpp:20
@ count
sentinel: number of real capabilities (keep LAST)
Definition canvas_capability.hpp:38
RendererBackend
Runtime identity of the concrete renderer receiving draw calls.
Definition canvas.hpp:29
@ core_graphics
Definition canvas.hpp:32
FillRule
Winding rule used to decide what counts as "inside" a path.
Definition path.hpp:54
@ nonzero
Definition path.hpp:54
LineJoin
Join applied where two segments meet when stroking.
Definition path.hpp:60
@ text
Definition scene_node.hpp:96
@ path
Definition scene_node.hpp:93
LineCap
Line cap applied to the ends of open subpaths when stroking.
Definition path.hpp:57
An opaque reference to a compositing layer owned by the canvas.
Definition canvas.hpp:849
Full text metrics for layout and intrinsic sizing.
Definition canvas.hpp:1230
static constexpr Color rgba(float r, float g, float b, float a=1.0f)
Construct from float channels [0,1] (>1.0 allowed for HDR).
Definition canvas.hpp:56
Axis-aligned rectangle in canvas coordinates.
Definition rectangle_list.hpp:28
Everything needed to stroke a path, as one value.
Definition path.hpp:67