cairo-renderer.cpp revision ccf9b93e83dfde6c33afe97636f5c3ce77ee5ca8
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/** \file
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Rendering with Cairo.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Author:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Miklos Erdelyi <erdelyim@gmail.com>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Jon A. Cruz <jon@joncruz.org>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Abhishek Sharma
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#include <boost/scoped_ptr.hpp>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "libnrtype/Layout-TNG.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <2geom/transforms.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include <2geom/pathvector.h>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include <glib.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include <glibmm/i18n.h>
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "display/curve.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "display/canvas-bpath.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "display/cairo-utils.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#include "sp-item.h"
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#include "sp-item-group.h"
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#include "style.h"
54e660c4de9d37185e3953165d053526632ef4f0johanengelen#include "sp-marker.h"
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#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-hatch-path.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-image.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-symbol.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-pattern.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "sp-mask.h"
dd69425007680aafc47fdd994e1985625571d252bryce#include "sp-clippath.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "util/units.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "helper/png-write.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#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#include "document.h"
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib// include support for only the compiled-in surface types
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib#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
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define TRACE(_args)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh//#define TEST(_args) _args
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#define TEST(_args)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// FIXME: expose these from sp-clippath/mask.cpp
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstruct SPClipPathView {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPClipPathView *next;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unsigned int key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Inkscape::DrawingItem *arenaitem;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::OptRect bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh};
d444ed610362dab3c3e727d1b110312318b84cb8miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstruct SPMaskView {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPMaskView *next;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unsigned int key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Inkscape::DrawingItem *arenaitem;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::OptRect 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();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh 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)
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh delete ctx;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshHere comes the rendering part which could be put into the 'render' methods of SPItems'
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh*/
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib/* 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);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render_invoke_marker_rendering(SPMarker* marker, Geom::Affine tr, SPStyle* style, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bool render = true;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (style->stroke_width.computed > 1e-9) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Scale(style->stroke_width.computed) * tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib render = false; // stroke width zero and marker is thus scaled down to zero, skip
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (render) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPItem* marker_item = sp_item_first_item_child(marker);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker_item) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = (Geom::Affine)marker_item->transform * (Geom::Affine)marker->c2p * tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine old_tr = marker_item->transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh marker_item->transform = tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->getRenderer()->renderItem (ctx, marker_item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh marker_item->transform = old_tr;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPShape *shape = SP_SHAPE(item);
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!shape->_curve) {
c87a66337fedd13cf951d99e604362432220deb5johanengelen return;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Geom::OptRect pbox = item->geometricBounds();
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPStyle* style = item->style;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::PathVector const & pathv = shape->_curve->get_pathvector();
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (pathv.empty()) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen return;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen ctx->renderPathVector(pathv, style, pbox);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen // START marker
54e660c4de9d37185e3953165d053526632ef4f0johanengelen for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if ( shape->_marker[i] ) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPMarker* marker = SP_MARKER (shape->_marker[i]);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Geom::Affine tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->orient_mode == MARKER_ORIENT_AUTO) {
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen tr = sp_shape_marker_get_transform_at_start(pathv.begin()->front());
54e660c4de9d37185e3953165d053526632ef4f0johanengelen } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen tr = Geom::Rotate::from_degrees( 180.0 ) * sp_shape_marker_get_transform_at_start(pathv.begin()->front());
54e660c4de9d37185e3953165d053526632ef4f0johanengelen } else {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(pathv.begin()->front().pointAt(0));
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen // MID marker
54e660c4de9d37185e3953165d053526632ef4f0johanengelen for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if ( !shape->_marker[i] ) continue;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen SPMarker* marker = SP_MARKER (shape->_marker[i]);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // START position
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen if ( path_it != pathv.begin()
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh && ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Affine tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = sp_shape_marker_get_transform_at_start(path_it->front());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(path_it->front().pointAt(0));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen // MID position
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (path_it->size_default() > 1) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh 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,
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen * there should be a midpoint marker between last segment and closing straight line segment */
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen Geom::Affine tr;
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen tr = sp_shape_marker_get_transform(*curve_it1, *curve_it2);
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen } else {
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(curve_it1->pointAt(1));
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen }
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen
54e660c4de9d37185e3953165d053526632ef4f0johanengelen ++curve_it1;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen ++curve_it2;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
54e660c4de9d37185e3953165d053526632ef4f0johanengelen }
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen // END position
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if ( path_it != (pathv.end()-1) && !path_it->empty()) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Curve const &lastcurve = path_it->back_default();
54e660c4de9d37185e3953165d053526632ef4f0johanengelen Geom::Affine tr;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen tr = sp_shape_marker_get_transform_at_end(lastcurve);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // END marker
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (int i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib if ( shape->_marker[i] ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPMarker* marker = SP_MARKER (shape->_marker[i]);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Get reference to last curve in the path.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * For moveto-only path, this returns the "closing line segment". */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Path const &path_last = pathv.back();
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib unsigned int index = path_last.size_default();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (index > 0) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh index--;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Curve const &lastcurve = path_last[index];
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = sp_shape_marker_get_transform_at_end(lastcurve);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
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(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value)));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
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));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
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)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine 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{
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib SPFlowtext *group = SP_FLOWTEXT(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh group->layout.showGlyphs(ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_image_render(SPItem *item, CairoRenderContext *ctx)
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen{
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen SPImage *image;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen int w, h;
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 w = image->pixbuf->width();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh h = image->pixbuf->height();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib double x = image->x.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double y = image->y.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double width = image->width.computed;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double height = image->height.computed;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (image->aspect_align != SP_ASPECT_NONE) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh calculatePreserveAspectRatio (image->aspect_align, image->aspect_clip, (double)w, (double)h,
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen &x, &y, &width, &height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
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
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib Geom::Translate tp(x, y);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Scale s(width / (double)w, height / (double)h);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine t(s * tp);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->renderImage (image->pixbuf, t, item->style);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_symbol_render(SPItem *item, CairoRenderContext *ctx)
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPSymbol *symbol = SP_SYMBOL(item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!symbol->cloned) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Cloned <symbol> is actually renderable */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib ctx->transform(symbol->c2p);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // apply viewbox if set
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (0 /*symbol->viewBox_set*/) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine 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;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh view_width = symbol->viewBox.width();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh view_height = symbol->viewBox.height();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen calculatePreserveAspectRatio(symbol->aspect_align, symbol->aspect_clip, view_width, view_height,
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen &x, &y,&width, &height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // [itemTransform *] translate(x, y) * scale(w/vw, h/vh) * translate(-vx, -vy);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh vb2user = Geom::identity();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh vb2user[0] = width / view_width;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib vb2user[3] = height / view_height;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib vb2user[4] = x - symbol->viewBox.left() * vb2user[0];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib vb2user[5] = y - symbol->viewBox.top() * vb2user[3];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->transform(vb2user);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sp_group_render(item, ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->popState();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_root_render(SPRoot *root, CairoRenderContext *ctx)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib{
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen CairoRenderer *renderer = ctx->getRenderer();
26b62dfb088a00b6debad350538a64c2af145f50johanengelen
26b62dfb088a00b6debad350538a64c2af145f50johanengelen if (!ctx->getCurrentState()->has_overflow && root->parent)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->addClippingRect(root->x.computed, root->y.computed, root->width.computed, root->height.computed);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->pushState();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib renderer->setStateForItem(ctx, root);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->transform(root->c2p);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib sp_group_render(root, ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->popState();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib/**
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib This function converts the item to a raster image and includes the image into the cairo renderer.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib It is only used for filters and then only when rendering filters as bitmaps is requested.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib*/
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib{
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib // The code was adapted from sp_selection_create_bitmap_copy in selection-chemistry.cpp
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib // Calculate resolution
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib double res;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /** @TODO reimplement the resolution stuff (WHY?)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib */
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib res = ctx->getBitmapResolution();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if(res == 0) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib res = Inkscape::Util::Quantity::convert(1, "in", "px");
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib TRACE(("sp_asbitmap_render: resolution: %f\n", res ));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Get the bounding box of the selection in desktop coordinates.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Geom::OptRect bbox = item->desktopVisualBounds();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // no bbox, e.g. empty group
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (!bbox) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Geom::Rect docrect(Geom::Rect(Geom::Point(0, 0), item->document->getDimensions()));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib bbox &= docrect;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // no bbox, e.g. empty group
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (!bbox) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // The width and height of the bitmap in pixels
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib unsigned width = ceil(bbox->width() * Inkscape::Util::Quantity::convert(res, "px", "in"));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib unsigned height = ceil(bbox->height() * Inkscape::Util::Quantity::convert(res, "px", "in"));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (width == 0 || height == 0) return;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Scale to exactly fit integer bitmap inside bounding box
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib double scale_x = bbox->width() / width;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen double scale_y = bbox->height() / height;
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Location of bounding box in document coordinates.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib double shift_x = bbox->min()[Geom::X];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib double shift_y = bbox->max()[Geom::Y];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // For default 96 dpi, snap bitmap to pixel grid
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib shift_x = round (shift_x);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion.
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib // Remove the negations when the inversion is gone.
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Matix to put bitmap in correct place on document
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Geom::Affine t_on_document = (Geom::Affine)(Geom::Scale (scale_x, -scale_y)) *
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib (Geom::Affine)(Geom::Translate (shift_x, shift_y));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // ctx matrix already includes item transformation. We must substract.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Geom::Affine t_item = item->i2dt_affine ();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Geom::Affine t = t_on_document * t_item.inverse();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Do the export
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib SPDocument *document = item->document;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib GSList *items = NULL;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib items = g_slist_append(items, item);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib boost::scoped_ptr<Inkscape::Pixbuf> pb(
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen sp_generate_internal_bitmap(document, NULL,
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib bbox->min()[Geom::X], bbox->min()[Geom::Y], bbox->max()[Geom::X], bbox->max()[Geom::Y],
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen width, height, res, res, (guint32) 0xffffff00, items ));
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (pb) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib //TEST(gdk_pixbuf_save( pb, "bitmap.png", "png", NULL, NULL ));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->renderImage(pb.get(), t, item->style);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib g_slist_free (items);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib}
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib{
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Check item's visibility
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (item->isHidden()) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib SPStyle* style = item->style;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if((ctx->getFilterToBitmap() == TRUE) && (style->filter.set != 0)) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return sp_asbitmap_render(item, ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib }
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (SP_IS_ROOT(item)) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib TRACE(("root\n"));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return sp_root_render(SP_ROOT(item), ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else if (SP_IS_SYMBOL(item)) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib TRACE(("symbol\n"));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return sp_symbol_render(item, ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else if (SP_IS_GROUP(item)) {
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib TRACE(("group\n"));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib return sp_group_render(item, ctx);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib } else if (SP_IS_SHAPE(item)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("shape\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return sp_shape_render(item, ctx);
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak } else if (SP_IS_USE(item)) {
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak TRACE(("use begin---\n"));
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak sp_use_render(item, ctx);
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak TRACE(("---use end\n"));
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak } else if (SP_IS_TEXT(item)) {
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib TRACE(("text\n"));
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib return sp_text_render(item, ctx);
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib } else if (SP_IS_FLOWTEXT(item)) {
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib TRACE(("flowtext\n"));
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib 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 = item->style;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setStateForStyle(style);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderState *state = ctx->getCurrentState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->clip_path = item->clip_ref->getObject();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->mask = item->mask_ref->getObject();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->item_transform = Geom::Affine (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(("setStateForItem opacity: %f\n", state->opacity));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// TODO change this to accept a const SPItem:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid CairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setStateForItem(ctx, item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib CairoRenderState *state = ctx->getCurrentState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->need_layer = ( state->mask || state->clip_path || state->opacity != 1.0 );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Draw item on a temporary surface so a mask, clip-path, or opacity can be applied to it.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (state->need_layer) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->merge_opacity = FALSE;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushLayer();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(item->transform);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_item_invoke_render(item, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (state->need_layer)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popLayer(); // This applies clipping/masking
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid CairoRenderer::renderHatchPath(CairoRenderContext *ctx, SPHatchPath const &hatchPath, unsigned key) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setStateForStyle(hatchPath.style);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib ctx->transform(Geom::Translate(hatchPath.offset.computed, 0));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPCurve *curve = hatchPath.calculateRenderCurve(key);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::PathVector const & pathv =curve->get_pathvector();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!pathv.empty()) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->renderPathVector(pathv, hatchPath.style, Geom::OptRect());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen curve->unref();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshbool
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, float bleedmargin_px, SPItem *base)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// PLEASE note when making changes to the boundingbox and transform calculation, corresponding changes should be made to PDFLaTeXRenderer::setupDocument !!!
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_assert( ctx != NULL );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!base) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh base = doc->getRoot();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Rect d;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (pageBoundingBox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d = Geom::Rect::from_xywh(Geom::Point(0,0), doc->getDimensions());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::OptRect bbox = base->desktopVisualBounds();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (!bbox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_message("CairoRenderer: empty bounding box.");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return false;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d = *bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d.expandBy(bleedmargin_px);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (ctx->_vector_based_target) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // convert from px to pt
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
26b62dfb088a00b6debad350538a64c2af145f50johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->_width = d.width();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->_height = d.height();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("setupDocument: %f x %f\n", ctx->_width, ctx->_height));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bool ret = ctx->setupSurface(ctx->_width, ctx->_height);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (ret) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (pageBoundingBox) {
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib // translate to set bleed/margin
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine tp( Geom::Translate( bleedmargin_px, bleedmargin_px ) );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(tp);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh } else {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh double high = doc->getHeight().value("px");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (ctx->_vector_based_target)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh high = Inkscape::Util::Quantity::convert(high, "px", "pt");
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // this transform translates the export drawing to a virtual page (0,0)-(width,height)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0),
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib (d.bottom() - high) * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0)));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(tp);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return ret;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh}
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh#include "macros.h" // SP_PRINT_*
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// Apply an SVG clip path
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelenvoid
3955580a5a68a873b098921626f5b9d841b964ecjaspervdgCairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp)
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg{
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg g_assert( ctx != NULL && ctx->_is_valid );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp == NULL)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // FIXME: the access to the first clippath view to obtain the bbox is completely bogus
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine saved_ctm;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX && cp->display->bbox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("clipd", cp->display->bbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Rect clip_bbox = *cp->display->bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine t(Geom::Scale(clip_bbox.dimensions()));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t[4] = clip_bbox.left();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t[5] = clip_bbox.top();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t *= ctx->getCurrentState()->transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh saved_ctm = ctx->getTransform();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setTransform(t);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("BEGIN clip\n"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPObject const *co = cp;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for ( SPObject const *child = co->firstChild() ; child; child = child->getNext() ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_ITEM(child)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPItem const *item = SP_ITEM(child);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // combine transform of the item in clippath and the item using clippath:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine tempmat = item->transform * ctx->getCurrentState()->item_transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib // render this item in clippath
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->pushState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->transform(tempmat);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh setStateForItem(ctx, item);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // TODO fix this call to accept const items
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_item_invoke_render(const_cast<SPItem *>(item), ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->popState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen }
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg TRACE(("END clip\n"));
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg
3955580a5a68a873b098921626f5b9d841b964ecjaspervdg // 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
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// Apply an SVG mask
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh{
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh g_assert( ctx != NULL && ctx->_is_valid );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (mask == NULL)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // FIXME: the access to the first mask view to obtain the bbox is completely bogus
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // TODO: should the bbox be transformed if maskUnits != userSpaceOnUse ?
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX && mask->display->bbox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("maskd", &mask->display->bbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Rect mask_bbox = *mask->display->bbox;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine t(Geom::Scale(mask_bbox.dimensions()));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t[4] = mask_bbox.left();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh t[5] = mask_bbox.top();
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib t *= ctx->getCurrentState()->transform;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setTransform(t);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh }
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Clip mask contents... but...
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // The mask's bounding box is the "geometric bounding box" which doesn't allow for
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // filters which extend outside the bounding box. So don't clip.
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 const *co = mask;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for ( SPObject const *child = co->firstChild() ; child; child = child->getNext() ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (SP_IS_ITEM(child)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPItem const *item = SP_ITEM(child);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // TODO fix const correctness:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh renderItem(ctx, const_cast<SPItem*>(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;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh
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;
case SP_ASPECT_XMAX_YMAX:
*x -= 1.0 * (new_width - *width);
*y -= 1.0 * (new_height - *height);
break;
default:
break;
}
*width = new_width;
*height = new_height;
}
#include "clear-n_.h"
} /* namespace Internal */
} /* namespace Extension */
} /* namespace Inkscape */
#undef TRACE
/* End of GNU GPL code */
/*
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:fileencoding=utf-8:textwidth=99 :