Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
drawing-context.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
6 * Authors:
7 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
8 *
9 * Copyright (C) 2011 Authors
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef SEEN_INKSCAPE_DISPLAY_DRAWING_CONTEXT_H
14#define SEEN_INKSCAPE_DISPLAY_DRAWING_CONTEXT_H
15
16#include <2geom/rect.h>
17#include <2geom/transforms.h>
18#include <boost/noncopyable.hpp>
19#include <cairo.h>
20
21typedef unsigned int guint32;
22
23namespace Inkscape {
24
25class DrawingSurface;
26
28 : boost::noncopyable
29{
30public:
31 class Save {
32 public:
33 Save();
35 ~Save();
36 void save(DrawingContext &dc);
37 private:
39 };
40
45
46 void save() { cairo_save(_ct); }
47 void restore() { cairo_restore(_ct); }
48 void pushGroup() { cairo_push_group(_ct); }
49 void pushAlphaGroup() { cairo_push_group_with_content(_ct, CAIRO_CONTENT_ALPHA); }
50 void popGroupToSource() { cairo_pop_group_to_source(_ct); }
51
52 void transform(Geom::Affine const &trans);
53 void translate(Geom::Point const &t) { cairo_translate(_ct, t[Geom::X], t[Geom::Y]); } // todo: take Translate
54 void translate(double dx, double dy) { cairo_translate(_ct, dx, dy); }
55 void scale(Geom::Scale const &s) { cairo_scale(_ct, s[Geom::X], s[Geom::Y]); }
56 void scale(double sx, double sy) { cairo_scale(_ct, sx, sy); }
57 void device_to_user_distance(double &dx, double &dy) { cairo_device_to_user_distance(_ct, &dx, &dy); }
58 void user_to_device_distance(double &dx, double &dy) { cairo_user_to_device_distance(_ct, &dx, &dy); }
59
60 void moveTo(Geom::Point const &p) { cairo_move_to(_ct, p[Geom::X], p[Geom::Y]); }
61 void lineTo(Geom::Point const &p) { cairo_line_to(_ct, p[Geom::X], p[Geom::Y]); }
62 void curveTo(Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3) {
63 cairo_curve_to(_ct, p1[Geom::X], p1[Geom::Y], p2[Geom::X], p2[Geom::Y], p3[Geom::X], p3[Geom::Y]);
64 }
65 void arc(Geom::Point const &center, double radius, Geom::AngleInterval const &angle);
66 void closePath() { cairo_close_path(_ct); }
67 void rectangle(Geom::Rect const &r) {
68 cairo_rectangle(_ct, r.left(), r.top(), r.width(), r.height());
69 }
70 void rectangle(Geom::IntRect const &r) {
71 cairo_rectangle(_ct, r.left(), r.top(), r.width(), r.height());
72 }
73 // Used in drawing-text.cpp to overwrite glyphs, which have the opposite path rotation as a regular rect
74 void revrectangle(Geom::Rect const &r) {
75 cairo_move_to ( _ct, r.left(), r.top() );
76 cairo_rel_line_to (_ct, 0, r.height() );
77 cairo_rel_line_to (_ct, r.width(), 0 );
78 cairo_rel_line_to (_ct, 0, -r.height() );
79 cairo_close_path ( _ct);
80 }
81 void revrectangle(Geom::IntRect const &r) {
82 cairo_move_to ( _ct, r.left(), r.top() );
83 cairo_rel_line_to (_ct, 0, r.height() );
84 cairo_rel_line_to (_ct, r.width(), 0 );
85 cairo_rel_line_to (_ct, 0, -r.height() );
86 cairo_close_path ( _ct);
87 }
88 void newPath() { cairo_new_path(_ct); }
89 void newSubpath() { cairo_new_sub_path(_ct); }
90 void path(Geom::PathVector const &pv);
91
92 void paint(double alpha = 1.0);
93 void fill() { cairo_fill(_ct); }
94 void fillPreserve() { cairo_fill_preserve(_ct); }
95 void stroke() { cairo_stroke(_ct); }
96 void strokePreserve() { cairo_stroke_preserve(_ct); }
97 void clip() { cairo_clip(_ct); }
98
99 void setLineWidth(double w) { cairo_set_line_width(_ct, w); }
100 void setHairline();
101 void setLineCap(cairo_line_cap_t cap) { cairo_set_line_cap(_ct, cap); }
102 void setLineJoin(cairo_line_join_t join) { cairo_set_line_join(_ct, join); }
103 void setMiterLimit(double miter) { cairo_set_miter_limit(_ct, miter); }
104 void setFillRule(cairo_fill_rule_t rule) { cairo_set_fill_rule(_ct, rule); }
105 void setOperator(cairo_operator_t op) { cairo_set_operator(_ct, op); }
106 cairo_operator_t getOperator() { return cairo_get_operator(_ct); }
107 void setTolerance(double tol) { cairo_set_tolerance(_ct, tol); }
108 void setSource(cairo_pattern_t *source) { cairo_set_source(_ct, source); }
109 void setSource(cairo_surface_t *surface, double x, double y) {
110 cairo_set_source_surface(_ct, surface, x, y);
111 }
112 void setSource(double r, double g, double b, double a = 1.0) {
113 cairo_set_source_rgba(_ct, r, g, b, a);
114 }
115 void setSource(guint32 rgba);
116 void setSource(DrawingSurface *s);
117
118 void patternSetFilter(cairo_filter_t filter) {
119 cairo_pattern_set_filter(cairo_get_source(_ct), filter);
120 }
121 void patternSetExtend(cairo_extend_t extend) { cairo_pattern_set_extend(cairo_get_source(_ct), extend); }
122
124
125 cairo_t *raw() { return _ct; }
126 cairo_surface_t *rawTarget() { return cairo_get_group_target(_ct); }
127
128 DrawingSurface *surface() { return _surface; } // Needed to find scale in drawing-item.cpp
129
130private:
132
137
138 friend class DrawingSurface;
139};
140
141} // end namespace Inkscape
142
143#endif // !SEEN_INKSCAPE_DISPLAY_DRAWING_ITEM_H
144
145/*
146 Local Variables:
147 mode:c++
148 c-file-style:"stroustrup"
149 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150 indent-tabs-mode:nil
151 fill-column:99
152 End:
153*/
154// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Point origin
Definition aa.cpp:227
3x3 matrix representing an affine transformation.
Definition affine.h:70
Directed angular interval.
Definition angle.h:188
Axis aligned, non-empty, generic rectangle.
C top() const
Return top coordinate of the rectangle (+Y is downwards).
C left() const
Return leftmost coordinate of the rectangle (+X is to the right).
C height() const
Get the vertical extent of the rectangle.
C width() const
Get the horizontal extent of the rectangle.
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Scaling from the origin.
Definition transforms.h:150
RAII idiom for saving the state of DrawingContext.
Minimal wrapper over Cairo.
void arc(Geom::Point const &center, double radius, Geom::AngleInterval const &angle)
DrawingContext(cairo_t *ct, DrawingSurface *surface, bool destroy)
void setLineCap(cairo_line_cap_t cap)
void path(Geom::PathVector const &pv)
Geom::Rect targetLogicalBounds() const
void setSource(cairo_pattern_t *source)
cairo_surface_t * rawTarget()
void scale(Geom::Scale const &s)
void transform(Geom::Affine const &trans)
void setTolerance(double tol)
void device_to_user_distance(double &dx, double &dy)
DrawingSurface * surface()
void scale(double sx, double sy)
void paint(double alpha=1.0)
void revrectangle(Geom::Rect const &r)
void rectangle(Geom::Rect const &r)
void curveTo(Geom::Point const &p1, Geom::Point const &p2, Geom::Point const &p3)
void setOperator(cairo_operator_t op)
void patternSetExtend(cairo_extend_t extend)
void translate(double dx, double dy)
void setSource(cairo_surface_t *surface, double x, double y)
void setFillRule(cairo_fill_rule_t rule)
void lineTo(Geom::Point const &p)
void moveTo(Geom::Point const &p)
void translate(Geom::Point const &t)
void revrectangle(Geom::IntRect const &r)
void setMiterLimit(double miter)
void rectangle(Geom::IntRect const &r)
cairo_operator_t getOperator()
void setSource(double r, double g, double b, double a=1.0)
void patternSetFilter(cairo_filter_t filter)
void user_to_device_distance(double &dx, double &dy)
void setLineJoin(cairo_line_join_t join)
Drawing surface that remembers its origin.
const double w
Definition conic-4.cpp:19
unsigned int guint32
_cairo_pattern cairo_pattern_t
struct _cairo_surface cairo_surface_t
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
Helper class to stream background task notifications as a series of messages.
static Glib::ustring join(std::vector< Glib::ustring > const &accels, char const separator)
void cairo_rectangle(cairo_t *cr, Geom::Rect const &r)
void cairo_line_to(cairo_t *cr, Geom::Point p1)
struct _cairo cairo_t
Definition path-cairo.h:16
void cairo_move_to(cairo_t *cr, Geom::Point p1)
void cairo_curve_to(cairo_t *cr, Geom::Point p1, Geom::Point p2, Geom::Point p3)
Axis-aligned rectangle.
void cairo_set_source_rgba(cairo_t *cr, colour c)
Affine transformation classes.