-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcairoRenderer.h
More file actions
102 lines (98 loc) · 3.57 KB
/
cairoRenderer.h
File metadata and controls
102 lines (98 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Ravel C API. © Ravelation Pty Ltd 2018
*/
#ifndef CAIRORENDERER_H
#define CAIRORENDERER_H
#include "capiRenderer.h"
#include <cairo/cairo.h>
#include <assert.h>
#include <math.h>
namespace ravel
{
struct CairoRenderer: public CAPIRenderer
{
cairo_t* cr;
static cairo_t* cairo(CAPIRenderer* r)
{return static_cast<CairoRenderer*>(r)->cr;}
cairo_text_extents_t ext{0,0,0,0,0,0};
static cairo_text_extents_t& extents(CAPIRenderer* r)
{return static_cast<CairoRenderer*>(r)->ext;}
CairoRenderer(cairo_t* cairo): cr(cairo)
{
moveTo=s_moveTo;
lineTo=s_lineTo;
relMoveTo=s_relMoveTo;
relLineTo=s_relLineTo;
arc=s_arc;
setLineWidth=s_setLineWidth;
newPath=s_newPath;
closePath=s_closePath;
fill=s_fill;
clip=s_clip;
stroke=s_stroke;
strokePreserve=s_strokePreserve;
setSourceRGB=s_setSourceRGB;
setSourceRGBA=s_setSourceRGBA;
showText=s_showText;
setTextExtents=s_setTextExtents;
textWidth=s_textWidth;
textHeight=s_textHeight;
identityMatrix=s_identityMatrix;
translate=s_translate;
scale=s_scale;
rotate=s_rotate;
save=s_save;
restore=s_restore;
}
static void s_moveTo(CAPIRenderer* c, double x, double y)
{cairo_move_to(cairo(c),x,y);}
static void s_lineTo(CAPIRenderer* c, double x, double y)
{cairo_line_to(cairo(c),x,y);}
static void s_relMoveTo(CAPIRenderer* c, double x, double y)
{cairo_rel_move_to(cairo(c),x,y);}
static void s_relLineTo(CAPIRenderer* c, double x, double y)
{cairo_rel_line_to(cairo(c),x,y);}
static void s_arc(CAPIRenderer* c, double x, double y, double radius, double start, double end)
{cairo_arc(cairo(c),x,y,radius,start,end);}
static void s_setLineWidth(CAPIRenderer* c, double w)
{cairo_set_line_width(cairo(c), w);}
static void s_newPath(CAPIRenderer* c) {cairo_new_path(cairo(c));}
static void s_closePath(CAPIRenderer* c) {cairo_close_path(cairo(c));}
static void s_fill(CAPIRenderer* c) {cairo_fill(cairo(c));}
static void s_clip(CAPIRenderer* c) {cairo_clip(cairo(c));}
static void s_stroke(CAPIRenderer* c) {cairo_stroke(cairo(c));}
static void s_strokePreserve(CAPIRenderer* c) {cairo_stroke_preserve(cairo(c));}
static void s_setSourceRGBA(CAPIRenderer* c, double r, double g, double b,double a)
{cairo_set_source_rgba(cairo(c),r,g,b,a);}
static void s_setSourceRGB(CAPIRenderer* c, double r, double g, double b)
{cairo_set_source_rgb(cairo(c),r,g,b);}
static void s_showText(CAPIRenderer* c, const char* s)
{cairo_show_text(cairo(c),s);}
static void s_setTextExtents(CAPIRenderer* c, const char* s)
{cairo_text_extents(cairo(c),s,&extents(c));}
static double s_textWidth(CAPIRenderer* c) {return extents(c).width;}
static double s_textHeight(CAPIRenderer* c) {return extents(c).height;}
static void s_identityMatrix(CAPIRenderer* c)
{cairo_identity_matrix(cairo(c));}
static void s_translate(CAPIRenderer* c, double x, double y)
{
assert(std::isfinite(x) && std::isfinite(y));
cairo_translate(cairo(c),x,y);
}
static void s_scale(CAPIRenderer* c, double sx, double sy)
{
assert(std::isfinite(sx) && std::isfinite(sy));
cairo_scale(cairo(c),sx,sy);
}
static void s_rotate(CAPIRenderer* c, double angle)
{
assert(std::isfinite(angle));
cairo_rotate(cairo(c),angle);
}
static void s_save(CAPIRenderer* c)
{cairo_save(cairo(c));}
static void s_restore(CAPIRenderer* c)
{cairo_restore(cairo(c));}
};
}
#endif