Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
drawing-context.cpp
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
15#include "display/cairo-utils.h"
16
17namespace Inkscape {
18
19using Geom::X;
20using Geom::Y;
21
28 : _dc(nullptr)
29{}
31 : _dc(&dc)
32{
33 _dc->save();
34}
36{
37 if (_dc) {
38 _dc->restore();
39 }
40}
42{
43 if (_dc) {
44 // TODO: it might be better to treat this occurrence as a bug
45 _dc->restore();
46 }
47 _dc = &dc;
48 _dc->save();
49}
50
61// Uses existing Cairo surface
63 : _ct(ct)
64 , _surface(new DrawingSurface(cairo_get_group_target(ct), origin))
65 , _delete_surface(true)
66 , _restore_context(true)
67{
68 _surface->_has_context = true;
69 cairo_reference(_ct);
70 cairo_save(_ct);
71 cairo_translate(_ct, -origin[Geom::X], -origin[Geom::Y]);
72}
73
74// Uses existing Cairo surface
76 : _ct(nullptr)
77 , _surface(new DrawingSurface(surface, origin))
78 , _delete_surface(true)
79 , _restore_context(false)
80{
81 _surface->_has_context = true;
83}
84
86 : _ct(s.createRawContext())
87 , _surface(&s)
88 , _delete_surface(false)
89 , _restore_context(false)
90{}
91
93{
94 if (_restore_context) {
95 cairo_restore(_ct);
96 }
97 cairo_destroy(_ct);
98 _surface->_has_context = false;
99 if (_delete_surface) {
100 delete _surface;
101 }
102}
103
104void DrawingContext::arc(Geom::Point const &center, double radius, Geom::AngleInterval const &angle)
105{
106 double from = angle.initialAngle();
107 double to = angle.finalAngle();
108 if (to > from) {
109 cairo_arc(_ct, center[X], center[Y], radius, from, to);
110 } else {
111 cairo_arc_negative(_ct, center[X], center[Y], radius, to, from);
112 }
113}
114
115// Applies transform to Cairo surface
117 ink_cairo_transform(_ct, trans);
118}
119
123
124void DrawingContext::paint(double alpha) {
125 if (alpha == 1.0) cairo_paint(_ct);
126 else cairo_paint_with_alpha(_ct, alpha);
127}
128
132
138 cairo_set_source_surface(_ct, s->raw(), origin[X], origin[Y]);
139}
140
142{
143 Geom::Rect ret(_surface->area());
144 return ret;
145}
146
147} // end namespace Inkscape
148
149/*
150 Local Variables:
151 mode:c++
152 c-file-style:"stroustrup"
153 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
154 indent-tabs-mode:nil
155 fill-column:99
156 End:
157*/
158// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Point origin
Definition aa.cpp:227
void ink_cairo_transform(cairo_t *ct, Geom::Affine const &m)
void feed_pathvector_to_cairo(cairo_t *ct, Geom::PathVector const &pathv, Geom::Affine trans, Geom::OptRect area, bool optimize_stroke, double stroke_width)
Feeds path-creating calls to the cairo context translating them from the PathVector,...
void ink_cairo_set_hairline(cairo_t *ct)
void ink_cairo_set_source_rgba32(cairo_t *ct, guint32 rgba)
Cairo integration helpers.
Cairo::RefPtr< Cairo::ImageSurface > surface
Definition canvas.cpp:137
3x3 matrix representing an affine transformation.
Definition affine.h:70
Directed angular interval.
Definition angle.h:188
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
void save(DrawingContext &dc)
Minimal wrapper over Cairo.
void arc(Geom::Point const &center, double radius, Geom::AngleInterval const &angle)
void path(Geom::PathVector const &pv)
Geom::Rect targetLogicalBounds() const
void setSource(cairo_pattern_t *source)
void transform(Geom::Affine const &trans)
void paint(double alpha=1.0)
DrawingContext(cairo_t *ct, Geom::Point const &origin)
Drawing surface that remembers its origin.
cairo_t * createRawContext()
Create a drawing context for this surface.
Geom::Point origin() const
Geom::Rect area() const
Get the logical extents of the surface.
cairo_surface_t * raw()
Cairo drawing context with Inkscape extensions.
unsigned int guint32
Cairo surface that remembers its origin.
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.
struct _cairo cairo_t
Definition path-cairo.h:16