Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion lib/impl/cairo/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <cairo.h>
#include <stack>

#include "font_impl.h"

namespace cycfi::artist
{
class canvas::canvas_state
Expand All @@ -25,6 +27,7 @@ namespace cycfi::artist

void apply_fill_style();
void apply_stroke_style();
float pre_scale = 1.0f;

using state_stack = std::stack<info>;

Expand Down Expand Up @@ -60,8 +63,10 @@ namespace cycfi::artist
{
}

void canvas::pre_scale(float scale)
void canvas::pre_scale(float sc)
{
scale({sc,sc});
_state->pre_scale = sc;
}

void canvas::translate(point p)
Expand All @@ -79,6 +84,20 @@ namespace cycfi::artist
cairo_scale(_context, p.x, p.y);
}

point canvas::device_to_user(point p) {
double x = p.x * _state->pre_scale;
double y = p.y * _state->pre_scale;
cairo_device_to_user_distance(_context, &x, &y);
return {float(x),float(y)};
}

point canvas::user_to_device(point p) {
double x = p.x;
double y = p.y;
cairo_user_to_device_distance(_context, &x, &y);
return {float(x / _state->pre_scale),float(y / _state->pre_scale)};
}

void canvas::save()
{
cairo_save(_context);
Expand All @@ -102,6 +121,10 @@ namespace cycfi::artist
cairo_close_path(_context);
}

void canvas::fill_rule(path::fill_rule_enum rule) {
//TODO
}

void canvas::fill()
{
_state->apply_fill_style();
Expand Down Expand Up @@ -131,6 +154,11 @@ namespace cycfi::artist
cairo_clip(_context);
}

bool canvas::point_in_path(point p) const {
// not sure how to implement this on cairo
return false;
}

void canvas::move_to(point p)
{
cairo_move_to(_context, p.x, p.y);
Expand Down Expand Up @@ -399,6 +427,10 @@ namespace cycfi::artist

void canvas::font(class font const& font_)
{
if( font_.impl() ) {
cairo_set_font_face(_context,font_.impl()->font_face);
cairo_set_font_size(_context,font_.impl()->size);
}
}

namespace
Expand Down
Loading