cairo-renderer.cpp revision 479ed85bac2b7467a6678bae572404e33465a5d9
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define __SP_CAIRO_RENDERER_C__
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/** \file
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Rendering with Cairo.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Author:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Miklos Erdelyi <erdelyim@gmail.com>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Copyright (C) 2006 Miklos Erdelyi
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib *
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Licensed under GNU GPL
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifdef HAVE_CONFIG_H
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh# include "config.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifndef PANGO_ENABLE_BACKEND
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define PANGO_ENABLE_BACKEND
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifndef PANGO_ENABLE_ENGINE
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define PANGO_ENABLE_ENGINE
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <signal.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <errno.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <libnr/nr-matrix-ops.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <libnr/nr-matrix-fns.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <libnr/nr-matrix-translate-ops.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <libnr/nr-scale-matrix-ops.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-matrix-rotate-ops.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-matrix-translate-ops.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-rotate-fns.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-scale-ops.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-scale-translate-ops.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-translate-matrix-ops.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "libnr/nr-translate-scale-ops.h"
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#include "libnr/nr-convert2geom.h"
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#include <2geom/transforms.h>
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#include <2geom/pathvector.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <glib/gmem.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <glibmm/i18n.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "display/nr-arena.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "display/nr-arena-item.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "display/nr-arena-group.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "display/curve.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "display/canvas-bpath.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-item.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-item-group.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "style.h"
dd69425007680aafc47fdd994e1985625571d252bryce#include "marker.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-linear-gradient.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-radial-gradient.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-root.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-shape.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-use.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-text.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-flowtext.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-image.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-symbol.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-pattern.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-mask.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-clippath.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <unit-constants.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "helper/png-write.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "helper/pixbuf-ops.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "cairo-renderer.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "cairo-render-context.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "extension/system.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "io/sys.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <cairo.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// include support for only the compiled-in surface types
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifdef CAIRO_HAS_PDF_SURFACE
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <cairo-pdf.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#ifdef CAIRO_HAS_PS_SURFACE
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <cairo-ps.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh//#define TRACE(_args) g_printf _args
d444ed610362dab3c3e727d1b110312318b84cb8miklosh#define TRACE(_args)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// FIXME: expose these from sp-clippath/mask.cpp
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstruct SPClipPathView {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPClipPathView *next;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unsigned int key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRArenaItem *arenaitem;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRRect bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh};
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstruct SPMaskView {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPMaskView *next;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unsigned int key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRArenaItem *arenaitem;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRRect bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh};
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace Inkscape {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace Extension {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshnamespace Internal {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::CairoRenderer(void)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::~CairoRenderer(void)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* restore default signal handling for SIGPIPE */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#if !defined(_WIN32) && !defined(__WIN32__)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh (void) signal(SIGPIPE, SIG_DFL);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#endif
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderContext*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::createContext(void)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderContext *new_context = new CairoRenderContext(this);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_assert( new_context != NULL );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_context->_state_stack = NULL;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_context->_state = NULL;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // create initial render state
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderState *state = new_context->_createState();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen state->transform = Geom::identity();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_context->_state_stack = g_slist_prepend(new_context->_state_stack, state);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_context->_state = state;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return new_context;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::destroyContext(CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib delete ctx;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshHere comes the rendering part which could be put into the 'render' methods of SPItems'
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh*/
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/* The below functions are copy&pasted plus slightly modified from *_invoke_print functions. */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_group_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_use_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_text_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_flowtext_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_image_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_symbol_render(SPItem *item, CairoRenderContext *ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
54e660c4de9d37185e3953165d053526632ef4f0johanengelen/* TODO FIXME: this does not render painting-marker-01-f.svg of SVG1.1 Test suite correctly. (orientation of one of the markers middle left ) */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRRect pbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPShape *shape = SP_SHAPE(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!shape->curve) return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* fixme: Think (Lauris) */
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen sp_item_invoke_bbox(item, &pbox, Geom::identity(), TRUE);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPStyle* style = SP_OBJECT_STYLE (item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderer *renderer = ctx->getRenderer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen Geom::PathVector const & pathv = shape->curve->get_pathvector();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen ctx->renderPathVector(pathv, style, &pbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
c87a66337fedd13cf951d99e604362432220deb5johanengelen /* TODO: make code prettier: lots of variables can be taken out of the loop! */
54e660c4de9d37185e3953165d053526632ef4f0johanengelen for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if ( shape->marker[SP_MARKER_LOC_START] ) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPMarker* marker = SP_MARKER (shape->marker[SP_MARKER_LOC_START]);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[SP_MARKER_LOC_START]));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix tr(sp_shape_marker_get_transform_at_start(path_it->front()));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = Geom::Scale(style->stroke_width.computed) * tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix old_tr = marker_item->transform;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen marker_item->transform = tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen renderer->renderItem (ctx, marker_item);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen marker_item->transform = old_tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen if ( shape->marker[SP_MARKER_LOC_MID] && (path_it->size_default() > 1) ) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve
54e660c4de9d37185e3953165d053526632ef4f0johanengelen while (curve_it2 != path_it->end_default())
54e660c4de9d37185e3953165d053526632ef4f0johanengelen {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen /* Put marker between curve_it1 and curve_it2.
54e660c4de9d37185e3953165d053526632ef4f0johanengelen * Loop to end_default (so including closing segment), because when a path is closed,
54e660c4de9d37185e3953165d053526632ef4f0johanengelen * there should be a midpoint marker between last segment and closing straight line segment */
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPMarker* marker = SP_MARKER (shape->marker[SP_MARKER_LOC_MID]);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[SP_MARKER_LOC_MID]));
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = Geom::Scale(style->stroke_width.computed) * tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix old_tr = marker_item->transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh marker_item->transform = tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh renderer->renderItem (ctx, marker_item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh marker_item->transform = old_tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen ++curve_it1;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen ++curve_it2;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if ( shape->marker[SP_MARKER_LOC_END] ) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPMarker* marker = SP_MARKER (shape->marker[SP_MARKER_LOC_END]);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[SP_MARKER_LOC_END]));
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen /* Get reference to last curve in the path.
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen * For moveto-only path, this returns the "closing line segment". */
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen unsigned int index = path_it->size_default();
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen if (index > 0) {
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen index--;
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen }
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen Geom::Curve const &lastcurve = (*path_it)[index];
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix tr = sp_shape_marker_get_transform_at_end(lastcurve);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = Geom::Scale(style->stroke_width.computed) * tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix old_tr = marker_item->transform;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen marker_item->transform = tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen renderer->renderItem (ctx, marker_item);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen marker_item->transform = old_tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_group_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPGroup *group = SP_GROUP(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderer *renderer = ctx->getRenderer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("group op: %f\n", SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(item)->opacity.value)));
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh GSList *l = g_slist_reverse(group->childList(false));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh while (l) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPObject *o = SP_OBJECT (l->data);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_ITEM(o)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh renderer->renderItem (ctx, SP_ITEM (o));
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh l = g_slist_remove (l, o);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_use_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bool translated = false;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPUse *use = SP_USE(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderer *renderer = ctx->getRenderer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix tp(Geom::Translate(use->x.computed, use->y.computed));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(&tp);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh translated = true;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (use->child && SP_IS_ITEM(use->child)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh renderer->renderItem(ctx, SP_ITEM(use->child));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (translated) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_text_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPText *group = SP_TEXT (item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh group->layout.showGlyphs(ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_flowtext_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPFlowtext *group = SP_FLOWTEXT(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh group->layout.showGlyphs(ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_image_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPImage *image;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh guchar *px;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh int w, h, rs;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh image = SP_IMAGE (item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!image->pixbuf) return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ((image->width.computed <= 0.0) || (image->height.computed <= 0.0)) return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh px = gdk_pixbuf_get_pixels (image->pixbuf);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh w = gdk_pixbuf_get_width (image->pixbuf);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh h = gdk_pixbuf_get_height (image->pixbuf);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh rs = gdk_pixbuf_get_rowstride (image->pixbuf);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double x = image->x.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double y = image->y.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double width = image->width.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double height = image->height.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (image->aspect_align != SP_ASPECT_NONE) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh calculatePreserveAspectRatio (image->aspect_align, image->aspect_clip, (double)w, (double)h,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh &x, &y, &width, &height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (image->aspect_clip == SP_ASPECT_SLICE && !ctx->getCurrentState()->has_overflow) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->addClippingRect(image->x.computed, image->y.computed, image->width.computed, image->height.computed);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Translate tp(x, y);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Scale s(width / (double)w, height / (double)h);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix t(s * tp);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->renderImage (px, w, h, rs, &t, SP_OBJECT_STYLE (item));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_symbol_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPSymbol *symbol = SP_SYMBOL(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!SP_OBJECT_IS_CLONED (symbol))
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Cloned <symbol> is actually renderable */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(&symbol->c2p);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // apply viewbox if set
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (0 /*symbol->viewBox_set*/) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix vb2user;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double x, y, width, height;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double view_width, view_height;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh x = 0.0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh y = 0.0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh width = 1.0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh height = 1.0;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh view_width = symbol->viewBox.x1 - symbol->viewBox.x0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh view_height = symbol->viewBox.y1 - symbol->viewBox.y0;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh calculatePreserveAspectRatio(symbol->aspect_align, symbol->aspect_clip, view_width, view_height,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh &x, &y,&width, &height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // [itemTransform *] translate(x, y) * scale(w/vw, h/vh) * translate(-vx, -vy);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen vb2user = Geom::identity();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh vb2user[0] = width / view_width;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh vb2user[3] = height / view_height;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh vb2user[4] = x - symbol->viewBox.x0 * vb2user[0];
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh vb2user[5] = y - symbol->viewBox.y0 * vb2user[3];
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(&vb2user);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_group_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_root_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPRoot *root = SP_ROOT(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderer *renderer = ctx->getRenderer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!ctx->getCurrentState()->has_overflow && SP_OBJECT(item)->parent)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->addClippingRect(root->x.computed, root->y.computed, root->width.computed, root->height.computed);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh renderer->setStateForItem(ctx, item);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix tempmat (root->c2p);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen ctx->transform(&tempmat);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_group_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib/**
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib this function convert the item to a raster image and include the raster into the cairo renderer
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib*/
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib{
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib //the code now was copied from sp_selection_create_bitmap_copy
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib SPDocument *document = SP_OBJECT(item)->document;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Get the bounding box of the selection
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen //boost::optional<Geom::Rect> _bbox = item->getBounds(sp_item_i2d_affine(item));
26b62dfb088a00b6debad350538a64c2af145f50johanengelen // NRRect bbox = item->getBounds(sp_item_i2d_affine(item));
26b62dfb088a00b6debad350538a64c2af145f50johanengelen NRRect bbox(item->getBounds(sp_item_i2d_affine(item)));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // List of the items to show; all others will be hidden
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib GSList *items = NULL; //g_slist_copy ((GSList *) selection->itemList());
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib items = g_slist_append(items, item);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Remember parent and z-order of the topmost one
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gint pos = SP_OBJECT_REPR(g_slist_last(items)->data)->position();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib SPObject *parent_object = SP_OBJECT_PARENT(g_slist_last(items)->data);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Inkscape::XML::Node *parent = SP_OBJECT_REPR(parent_object);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Calculate resolution
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib double res;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /** @TODO reimplement the resolution stuff
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib */
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib res = ctx->getBitmapResolution();
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib if(res == 0) {
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib res = PX_PER_IN;
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib }
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // The width and height of the bitmap in pixels
479ed85bac2b7467a6678bae572404e33465a5d9acspike unsigned width = (unsigned) floor ((bbox.x1 - bbox.x0) * (res / PX_PER_IN));
479ed85bac2b7467a6678bae572404e33465a5d9acspike unsigned height =(unsigned) floor ((bbox.y1 - bbox.y0) * (res / PX_PER_IN));
479ed85bac2b7467a6678bae572404e33465a5d9acspike
479ed85bac2b7467a6678bae572404e33465a5d9acspike double scale_x = (bbox.x1 - bbox.x0) / width;
479ed85bac2b7467a6678bae572404e33465a5d9acspike double scale_y = (bbox.y1 - bbox.y0) / height;
479ed85bac2b7467a6678bae572404e33465a5d9acspike
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Find out if we have to run a filter
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar const *run = NULL;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar const *filter = NULL;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /** @TODO reimplement the filter stuff
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib //gchar const *filter = prefs_get_string_attribute ("options.createbitmap", "filter");
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (filter) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // filter command is given;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // see if we have a parameter to pass to it
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar const *param1 = prefs_get_string_attribute ("options.createbitmap", "filter_param1");
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (param1) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (param1[strlen(param1) - 1] == '%') {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // if the param string ends with %, interpret it as a percentage of the image's max dimension
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar p1[256];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_ascii_dtostr (p1, 256, ceil (g_ascii_strtod (param1, NULL) * MAX(width, height) / 100));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // the first param is always the image filename, the second is param1
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib run = g_strdup_printf ("%s \"%s\" %s", filter, filepath, p1);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // otherwise pass the param1 unchanged
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib run = g_strdup_printf ("%s \"%s\" %s", filter, filepath, param1);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // run without extra parameter
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib run = g_strdup_printf ("%s \"%s\"", filter, filepath);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib */
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix eek = sp_item_i2d_affine (SP_ITEM(parent_object));
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix t;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib double shift_x = bbox.x0;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib double shift_y = bbox.y1;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib shift_x = round (shift_x);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib shift_y = -round (-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
479ed85bac2b7467a6678bae572404e33465a5d9acspike t = (Geom::Matrix)(Geom::Scale(scale_x, -scale_y) * (Geom::Matrix)(Geom::Translate (shift_x, shift_y)* eek.inverse()));
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen //t = t * ((Geom::Matrix)ctx->getCurrentState()->transform).inverse();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Do the export
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib GdkPixbuf *pb = sp_generate_internal_bitmap(document, NULL,
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib bbox.x0, bbox.y0, bbox.x1, bbox.y1, width, height, res, res, (guint32) 0xffffff00, items );
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Run filter, if any
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /*
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (run) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_print ("Running external filter: %s\n", run);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib system (run);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib */
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (pb) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib unsigned char *px = gdk_pixbuf_get_pixels (pb);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib unsigned int w = gdk_pixbuf_get_width(pb);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib unsigned int h = gdk_pixbuf_get_height(pb);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib unsigned int rs = gdk_pixbuf_get_rowstride(pb);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix matrix;
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib matrix = t;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen //matrix = ((Geom::Matrix)ctx->getCurrentState()->transform).inverse();
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg //matrix.set_identity();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->renderImage (px, w, h, rs, &matrix, SP_OBJECT_STYLE (item));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /*
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Create the repr for the image
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Inkscape::XML::Node * repr = xml_doc->createElement("svg:image");
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib repr->setAttribute("xlink:href", filename);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib repr->setAttribute("sodipodi:absref", filepath);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sp_repr_set_svg_double(repr, "width", width);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sp_repr_set_svg_double(repr, "height", height);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sp_repr_set_svg_double(repr, "width", (bbox.x1 - bbox.x0));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sp_repr_set_svg_double(repr, "height", (bbox.y1 - bbox.y0));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Write transform
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gchar *c=sp_svg_transform_write(t);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib repr->setAttribute("transform", c);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_free(c);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // add the new repr to the parent
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib parent->appendChild(repr);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // move to the saved position
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib repr->setPosition(pos > 0 ? pos + 1 : 1);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib */
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib gdk_pixbuf_unref (pb);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_slist_free (items);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak // Check item's visibility
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak if (item->isHidden()) {
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak return;
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak }
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib SPStyle* style = SP_OBJECT_STYLE (item);
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib if((ctx->getFilterToBitmap() == TRUE) && (style->filter.set != 0)) {
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib return sp_asbitmap_render(item, ctx);
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib }
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_ROOT(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("root\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_root_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_GROUP(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("group\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_group_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_SHAPE(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("shape\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_shape_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_USE(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("use begin---\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_use_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("---use end\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_SYMBOL(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("symbol\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_symbol_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_TEXT(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("text\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_text_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_FLOWTEXT(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("flowtext\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_flowtext_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else if (SP_IS_IMAGE(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("image\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_image_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::setStateForItem(CairoRenderContext *ctx, SPItem const *item)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPStyle const *style = SP_OBJECT_STYLE(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setStateForStyle(style);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderState *state = ctx->getCurrentState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->clip_path = item->clip_ref->getObject();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->mask = item->mask_ref->getObject();
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak state->item_transform = Geom::Matrix (item->transform);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // If parent_has_userspace is true the parent state's transform
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // has to be used for the mask's/clippath's context.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // This is so because we use the image's/(flow)text's transform for positioning
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // instead of explicitly specifying it and letting the renderer do the
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // transformation before rendering the item.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item) || SP_IS_IMAGE(item))
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->parent_has_userspace = TRUE;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("set op: %f\n", state->opacity));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setStateForItem(ctx, item);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderState *state = ctx->getCurrentState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->need_layer = ( state->mask || state->clip_path || state->opacity != 1.0 );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (state->need_layer) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->merge_opacity = FALSE;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushLayer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix tempmat (item->transform);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen ctx->transform(&tempmat);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_item_invoke_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (state->need_layer)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popLayer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshbool
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyakCairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, SPItem *base)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_assert( ctx != NULL );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (ctx->_vector_based_target) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // width and height in pt
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->_width = sp_document_width(doc) * PT_PER_PX;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->_height = sp_document_height(doc) * PT_PER_PX;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->_width = sp_document_width(doc);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->_height = sp_document_height(doc);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRRect d;
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak if (pageBoundingBox || !base) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.x0 = d.y0 = 0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.x1 = ceil(ctx->_width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.y1 = ceil(ctx->_height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak sp_item_invoke_bbox(base, &d, sp_item_i2r_affine(base), TRUE);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (ctx->_vector_based_target) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // convert from px to pt
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.x0 *= PT_PER_PX;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.x1 *= PT_PER_PX;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.y0 *= PT_PER_PX;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.y1 *= PT_PER_PX;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("%f x %f\n", ctx->_width, ctx->_height));
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak bool ret = ctx->setupSurface(d.x1-d.x0, d.y1-d.y0);
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak if (ret && !pageBoundingBox && base)
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak {
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak Geom::Matrix tp(Geom::Translate(-d.x0 * (ctx->_vector_based_target ? PX_PER_PT : 1.0),
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak (d.y1 - ctx->_height) * (ctx->_vector_based_target ? PX_PER_PT : 1.0)));
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak ctx->transform(&tp);
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak ctx->_width = d.x1 - d.x0;
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak ctx->_height = d.y1 - d.y0;
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak }
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak return ret;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "macros.h" // SP_PRINT_*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_assert( ctx != NULL && ctx->_is_valid );
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp == NULL)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix saved_ctm;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("clipd", cp->display->bbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRRect clip_bbox(cp->display->bbox);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix t(Geom::Scale(clip_bbox.x1 - clip_bbox.x0, clip_bbox.y1 - clip_bbox.y0));
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg t[4] = clip_bbox.x0;
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg t[5] = clip_bbox.y0;
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg t *= ctx->getCurrentState()->transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->getTransform(&saved_ctm);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setTransform(&t);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("BEGIN clip\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPObject *co = SP_OBJECT(cp);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (SPObject *child = sp_object_first_child(co) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_ITEM(child)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPItem *item = SP_ITEM(child);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak // combine transform of the item in clippath and the item using clippath:
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak Geom::Matrix tempmat (item->transform);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak tempmat = tempmat * (ctx->getCurrentState()->item_transform);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak // render this item in clippath
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak ctx->pushState();
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak ctx->transform(&tempmat);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak setStateForItem(ctx, item);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak sp_item_invoke_render(item, ctx);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("END clip\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // do clipping only if this was the first call to applyClipPath
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (ctx->getClipMode() == CairoRenderContext::CLIP_MODE_PATH
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh && saved_mode == CairoRenderContext::RENDER_MODE_NORMAL)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh cairo_clip(ctx->_cr);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setTransform(&saved_ctm);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setRenderMode(saved_mode);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_assert( ctx != NULL && ctx->_is_valid );
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (mask == NULL)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("maskd", &mask->display->bbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh NRRect mask_bbox(mask->display->bbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // TODO: should the bbox be transformed if maskUnits != userSpaceOnUse ?
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix t(Geom::Scale(mask_bbox.x1 - mask_bbox.x0, mask_bbox.y1 - mask_bbox.y0));
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg t[4] = mask_bbox.x0;
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg t[5] = mask_bbox.y0;
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg t *= ctx->getCurrentState()->transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setTransform(&t);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // clip mask contents
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->addClippingRect(mask_bbox.x0, mask_bbox.y0, mask_bbox.x1 - mask_bbox.x0, mask_bbox.y1 - mask_bbox.y0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("BEGIN mask\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPObject *co = SP_OBJECT(mask);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (SPObject *child = sp_object_first_child(co) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_ITEM(child)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPItem *item = SP_ITEM(child);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh renderItem(ctx, item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("END mask\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshcalculatePreserveAspectRatio(unsigned int aspect_align, unsigned int aspect_clip, double vp_width, double vp_height,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double *x, double *y, double *width, double *height)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (aspect_align == SP_ASPECT_NONE)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double scalex, scaley, scale;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double new_width, new_height;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh scalex = *width / vp_width;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh scaley = *height / vp_height;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh scale = (aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_width = vp_width * scale;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_height = vp_height * scale;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Now place viewbox to requested position */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh switch (aspect_align) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMIN_YMIN:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMID_YMIN:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *x -= 0.5 * (new_width - *width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMAX_YMIN:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *x -= 1.0 * (new_width - *width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMIN_YMID:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *y -= 0.5 * (new_height - *height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMID_YMID:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *x -= 0.5 * (new_width - *width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *y -= 0.5 * (new_height - *height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMAX_YMID:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *x -= 1.0 * (new_width - *width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *y -= 0.5 * (new_height - *height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMIN_YMAX:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *y -= 1.0 * (new_height - *height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMID_YMAX:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *x -= 0.5 * (new_width - *width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *y -= 1.0 * (new_height - *height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh case SP_ASPECT_XMAX_YMAX:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *x -= 1.0 * (new_width - *width);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *y -= 1.0 * (new_height - *height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh default:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh break;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *width = new_width;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh *height = new_height;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "clear-n_.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} /* namespace Internal */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} /* namespace Extension */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} /* namespace Inkscape */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#undef TRACE
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/* End of GNU GPL code */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Local Variables:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh mode:c++
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh c-file-style:"stroustrup"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh indent-tabs-mode:nil
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh fill-column:99
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh End:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh*/
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :