diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-06-26 01:02:06 +0000 |
|---|---|---|
| committer | Krzysztof Kosiński <tweenk.pl@gmail.com> | 2010-06-26 01:02:06 +0000 |
| commit | 31f84a59da72b31b932833ce1af7d78f0a67e185 (patch) | |
| tree | f72a45ade3678183b262c7d92455e457373aed6e /src/display/cairo-utils.h | |
| parent | Merge from trunk (diff) | |
| download | inkscape-31f84a59da72b31b932833ce1af7d78f0a67e185.tar.gz inkscape-31f84a59da72b31b932833ce1af7d78f0a67e185.zip | |
Implement clipping (slightly incorrect) and masking
(bzr r9508.1.4)
Diffstat (limited to 'src/display/cairo-utils.h')
| -rw-r--r-- | src/display/cairo-utils.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h new file mode 100644 index 000000000..feed987bd --- /dev/null +++ b/src/display/cairo-utils.h @@ -0,0 +1,88 @@ +/** + * @file + * @brief Cairo integration helpers + *//* + * Authors: + * Krzysztof Kosiński <tweenk.pl@gmail.com> + * + * Copyright (C) 2010 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_DISPLAY_CAIRO_UTILS_H +#define SEEN_INKSCAPE_DISPLAY_CAIRO_UTILS_H + +#include <glib.h> +#include <cairomm/cairomm.h> +#include <2geom/forward.h> + +namespace Inkscape { + +/** @brief RAII idiom for Cairo groups. + * Groups are temporary surfaces used when rendering e.g. masks and opacity. + * Use this class to ensure that each group push is matched with a pop. */ +class CairoGroup { +public: + CairoGroup(cairo_t *_ct); + ~CairoGroup(); + void push(); + void push_with_content(cairo_content_t content); + cairo_pattern_t *pop(); + Cairo::RefPtr<Cairo::Pattern> popmm(); + void pop_to_source(); +private: + cairo_t *ct; + bool pushed; +}; + +/** @brief RAII idiom for Cairo state saving */ +class CairoSave { +public: + CairoSave(cairo_t *_ct, bool save=false) + : ct(_ct) + , saved(save) + { + if (save) { + cairo_save(ct); + } + } + void save() { + if (!saved) { + cairo_save(ct); + saved = true; + } + } + ~CairoSave() { + if (saved) + cairo_restore(ct); + } +private: + cairo_t *ct; + bool saved; +}; + +/** @brief Cairo context with Inkscape-specific operations */ +class CairoContext : public Cairo::Context { +public: + CairoContext(cairo_t *obj, bool ref = false); + + void transform(Geom::Matrix const &m); + void set_source_rgba32(guint32 color); + void append_path(Geom::PathVector const &pv); + + static Cairo::RefPtr<CairoContext> create(Cairo::RefPtr<Cairo::Surface> const &target); +}; + +} // namespace Inkscape + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
