cairo-render-context.h revision 3c286c39653509ce12cd7221cc471934b1f2f475
3853N/A#ifndef EXTENSION_INTERNAL_CAIRO_RENDER_CONTEXT_H_SEEN
3853N/A#define EXTENSION_INTERNAL_CAIRO_RENDER_CONTEXT_H_SEEN
3853N/A
3853N/A/** \file
3853N/A * Declaration of CairoRenderContext, a class used for rendering with Cairo.
3853N/A */
3853N/A/*
3853N/A * Authors:
3853N/A * Miklos Erdelyi <erdelyim@gmail.com>
3853N/A *
3853N/A * Copyright (C) 2006 Miklos Erdelyi
3853N/A *
3853N/A * Licensed under GNU GPL
3853N/A */
3853N/A
3853N/A#ifdef HAVE_CONFIG_H
3853N/A# include "config.h"
3853N/A#endif
3853N/A
3853N/A#include "extension/extension.h"
3853N/A#include <set>
3853N/A#include <string>
3853N/A
3853N/A#include <2geom/forward.h>
5035N/A
3853N/A#include "style.h"
3853N/A
3853N/A#include <cairo.h>
3853N/A
3853N/Aclass SPClipPath;
4803N/Aclass SPMask;
3853N/A
3853N/Anamespace Inkscape {
3853N/Anamespace Extension {
4141N/Anamespace Internal {
3853N/A
3853N/Aclass CairoRenderer;
3853N/Aclass CairoRenderContext;
3853N/Aclass CairoRenderState;
3853N/Aclass CairoGlyphInfo;
4141N/A
3898N/A// Holds info for rendering a glyph
3898N/Astruct CairoGlyphInfo {
4920N/A unsigned long index;
4518N/A double x;
3853N/A double y;
3853N/A};
3853N/A
3853N/Astruct CairoRenderState {
4803N/A unsigned int merge_opacity : 1; // whether fill/stroke opacity can be mul'd with item opacity
3853N/A unsigned int need_layer : 1;
3853N/A unsigned int has_overflow : 1;
3853N/A unsigned int parent_has_userspace : 1; // whether the parent's ctm should be applied
3853N/A float opacity;
3853N/A bool has_filtereffect;
3853N/A Geom::Matrix item_transform; // this item's item->transform, for correct clipping
3853N/A
3853N/A SPClipPath *clip_path;
3853N/A SPMask* mask;
3853N/A
3853N/A Geom::Matrix transform; // the CTM
3853N/A};
3853N/A
3853N/Aclass CairoRenderContext {
3853N/A friend class CairoRenderer;
4803N/Apublic:
4803N/A CairoRenderContext *cloneMe(void) const;
3853N/A CairoRenderContext *cloneMe(double width, double height) const;
3853N/A bool finish(void);
3853N/A
3853N/A CairoRenderer *getRenderer(void) const;
3853N/A cairo_t *getCairoContext(void) const;
3853N/A
3853N/A typedef enum CairoRenderMode {
3853N/A RENDER_MODE_NORMAL,
4141N/A RENDER_MODE_CLIP
4141N/A };
4141N/A
4141N/A typedef enum CairoClipMode {
4141N/A CLIP_MODE_PATH,
4141N/A CLIP_MODE_MASK
4141N/A };
4141N/A
4141N/A bool setImageTarget(cairo_format_t format);
4141N/A bool setPdfTarget(gchar const *utf8_fn);
4518N/A bool setPsTarget(gchar const *utf8_fn);
4518N/A /** Set the cairo_surface_t from an external source */
4141N/A bool setSurfaceTarget(cairo_surface_t *surface, bool is_vector);
4141N/A
3853N/A void setPSLevel(unsigned int level);
3853N/A void setEPS(bool eps);
4920N/A unsigned int getPSLevel(void);
3853N/A void setPDFLevel(unsigned int level);
4500N/A void setTextToPath(bool texttopath);
4500N/A bool getTextToPath(void);
4500N/A void setFilterToBitmap(bool filtertobitmap);
4500N/A bool getFilterToBitmap(void);
3853N/A void setBitmapResolution(int resolution);
3853N/A int getBitmapResolution(void);
3853N/A
3853N/A /** Creates the cairo_surface_t for the context with the
3853N/A given width, height and with the currently set target
3853N/A surface type. */
3853N/A bool setupSurface(double width, double height);
3853N/A
3853N/A cairo_surface_t *getSurface(void);
3853N/A
3853N/A /** Saves the contents of the context to a PNG file. */
3853N/A bool saveAsPng(const char *file_name);
3853N/A
3853N/A /* Render/clip mode setting/query */
3853N/A void setRenderMode(CairoRenderMode mode);
3853N/A CairoRenderMode getRenderMode(void) const;
3853N/A void setClipMode(CairoClipMode mode);
3853N/A CairoClipMode getClipMode(void) const;
3853N/A
3853N/A void addPathVector(Geom::PathVector const &pv);
3853N/A void setPathVector(Geom::PathVector const &pv);
3853N/A
3853N/A void pushLayer(void);
4500N/A void popLayer(void);
4500N/A
4500N/A /* Graphics state manipulation */
4500N/A void pushState(void);
3853N/A void popState(void);
3853N/A CairoRenderState *getCurrentState(void) const;
3853N/A CairoRenderState *getParentState(void) const;
3853N/A void setStateForStyle(SPStyle const *style);
3853N/A
3853N/A void transform(Geom::Matrix const *transform);
3853N/A void setTransform(Geom::Matrix const *transform);
3853N/A void getTransform(Geom::Matrix *copy) const;
3853N/A void getParentTransform(Geom::Matrix *copy) const;
3853N/A
3853N/A /* Clipping methods */
3853N/A void addClipPath(Geom::PathVector const &pv, SPIEnum const *fill_rule);
3853N/A void addClippingRect(double x, double y, double width, double height);
3853N/A
3853N/A /* Rendering methods */
3853N/A bool renderPathVector(Geom::PathVector const & pathv, SPStyle const *style, NRRect const *pbox);
3853N/A bool renderPath(const_NRBPath const *bpath, SPStyle const *style, NRRect const *pbox);
3853N/A bool renderImage(unsigned char *px, unsigned int w, unsigned int h, unsigned int rs,
3858N/A Geom::Matrix const *image_transform, SPStyle const *style);
3853N/A bool renderGlyphtext(PangoFont *font, Geom::Matrix const *font_matrix,
3853N/A std::vector<CairoGlyphInfo> const &glyphtext, SPStyle const *style);
3853N/A
3853N/A /* More general rendering methods will have to be added (like fill, stroke) */
3853N/A
3853N/Aprotected:
3853N/A CairoRenderContext(CairoRenderer *renderer);
3853N/A virtual ~CairoRenderContext(void);
3858N/A
3853N/A float _width;
3853N/A float _height;
3853N/A unsigned short _dpi;
3853N/A unsigned int _pdf_level;
3853N/A unsigned int _ps_level;
3853N/A bool _eps;
3853N/A bool _is_texttopath;
3853N/A bool _is_filtertobitmap;
3853N/A int _bitmapresolution;
3853N/A
3853N/A FILE *_stream;
3853N/A
3853N/A unsigned int _is_valid : 1;
3853N/A unsigned int _vector_based_target : 1;
3853N/A
3853N/A cairo_t *_cr;
3853N/A cairo_surface_t *_surface;
3853N/A cairo_surface_type_t _target;
3853N/A cairo_format_t _target_format;
3853N/A PangoLayout *_layout;
3853N/A
3853N/A unsigned int _clip_rule : 8;
3853N/A unsigned int _clip_winding_failed : 1;
4060N/A
4060N/A GSList *_state_stack;
4060N/A CairoRenderState *_state; // the current state
4060N/A
4060N/A CairoRenderer *_renderer;
4803N/A
4060N/A CairoRenderMode _render_mode;
4060N/A CairoClipMode _clip_mode;
4060N/A
4060N/A cairo_pattern_t *_createPatternForPaintServer(SPPaintServer const *const paintserver,
4060N/A NRRect const *pbox, float alpha);
4060N/A cairo_pattern_t *_createPatternPainter(SPPaintServer const *const paintserver, NRRect const *pbox);
4060N/A
4060N/A unsigned int _showGlyphs(cairo_t *cr, PangoFont *font, std::vector<CairoGlyphInfo> const &glyphtext, bool is_stroke);
4060N/A
4060N/A bool _finishSurfaceSetup(cairo_surface_t *surface);
4803N/A void _setFillStyle(SPStyle const *style, NRRect const *pbox);
4060N/A void _setStrokeStyle(SPStyle const *style, NRRect const *pbox);
4060N/A
4060N/A void _initCairoMatrix(cairo_matrix_t *matrix, Geom::Matrix const *transform);
4060N/A void _concatTransform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0);
4060N/A void _concatTransform(cairo_t *cr, Geom::Matrix const *transform);
3853N/A
3853N/A CairoRenderState *_createState(void);
3853N/A};
4803N/A
3853N/A} /* namespace Internal */
3853N/A} /* namespace Extension */
3853N/A} /* namespace Inkscape */
3853N/A
3853N/A#endif /* !EXTENSION_INTERNAL_CAIRO_RENDER_CONTEXT_H_SEEN */
3853N/A
3853N/A/*
3853N/A Local Variables:
4803N/A mode:c++
3853N/A c-file-style:"stroustrup"
3853N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
3853N/A indent-tabs-mode:nil
3853N/A fill-column:99
3853N/A End:
4803N/A*/
4803N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
4803N/A