cairo-renderer.cpp revision ccf9b93e83dfde6c33afe97636f5c3ce77ee5ca8
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Rendering with Cairo.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Miklos Erdelyi <erdelyim@gmail.com>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Jon A. Cruz <jon@joncruz.org>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Abhishek Sharma
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Copyright (C) 2006 Miklos Erdelyi
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Licensed under GNU GPL
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib// include support for only the compiled-in surface types
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh//#define TRACE(_args) g_printf _args
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh//#define TEST(_args) _args
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// FIXME: expose these from sp-clippath/mask.cpp
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unsigned int key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh unsigned int key;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* restore default signal handling for SIGPIPE */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderContext *new_context = new CairoRenderContext(this);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // create initial render state
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderState *state = new_context->_createState();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh new_context->_state_stack = g_slist_prepend(new_context->_state_stack, state);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::destroyContext(CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshHere comes the rendering part which could be put into the 'render' methods of SPItems'
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);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render_invoke_marker_rendering(SPMarker* marker, Geom::Affine tr, SPStyle* style, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bool render = true;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Scale(style->stroke_width.computed) * tr;
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib render = false; // stroke width zero and marker is thus scaled down to zero, skip
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPItem* marker_item = sp_item_first_item_child(marker);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = (Geom::Affine)marker_item->transform * (Geom::Affine)marker->c2p * tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::PathVector const & pathv = shape->_curve->get_pathvector();
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen // START marker
54e660c4de9d37185e3953165d053526632ef4f0johanengelen for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
54e660c4de9d37185e3953165d053526632ef4f0johanengelen SPMarker* marker = SP_MARKER (shape->_marker[i]);
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 tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(pathv.begin()->front().pointAt(0));
54e660c4de9d37185e3953165d053526632ef4f0johanengelen sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen // MID marker
54e660c4de9d37185e3953165d053526632ef4f0johanengelen for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
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
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
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen tr = sp_shape_marker_get_transform_at_start(path_it->front());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(path_it->front().pointAt(0));
54e660c4de9d37185e3953165d053526632ef4f0johanengelen sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
54e660c4de9d37185e3953165d053526632ef4f0johanengelen // MID position
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 /* 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 if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen tr = sp_shape_marker_get_transform(*curve_it1, *curve_it2);
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(curve_it1->pointAt(1));
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen // END position
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if ( path_it != (pathv.end()-1) && !path_it->empty()) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Curve const &lastcurve = path_it->back_default();
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
54e660c4de9d37185e3953165d053526632ef4f0johanengelen tr = sp_shape_marker_get_transform_at_end(lastcurve);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // END marker
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (int i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Get reference to last curve in the path.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * For moveto-only path, this returns the "closing line segment". */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = sp_shape_marker_get_transform_at_end(lastcurve);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_shape_render_invoke_marker_rendering(marker, tr, style, ctx);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_group_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value)));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh GSList *l = g_slist_reverse(group->childList(false));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh while (l) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_use_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bool translated = false;
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));
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)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if ((image->width.computed <= 0.0) || (image->height.computed <= 0.0)) return;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh calculatePreserveAspectRatio (image->aspect_align, image->aspect_clip, (double)w, (double)h,
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 Geom::Scale s(width / (double)w, height / (double)h);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_symbol_render(SPItem *item, CairoRenderContext *ctx)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Cloned <symbol> is actually renderable */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // apply viewbox if set
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (0 /*symbol->viewBox_set*/) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen calculatePreserveAspectRatio(symbol->aspect_align, symbol->aspect_clip, view_width, view_height,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // [itemTransform *] translate(x, y) * scale(w/vw, h/vh) * translate(-vx, -vy);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib vb2user[4] = x - symbol->viewBox.left() * vb2user[0];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib vb2user[5] = y - symbol->viewBox.top() * vb2user[3];
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_root_render(SPRoot *root, CairoRenderContext *ctx)
26b62dfb088a00b6debad350538a64c2af145f50johanengelen if (!ctx->getCurrentState()->has_overflow && root->parent)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib ctx->addClippingRect(root->x.computed, root->y.computed, root->width.computed, root->height.computed);
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.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx)
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib // The code was adapted from sp_selection_create_bitmap_copy in selection-chemistry.cpp
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib // Calculate resolution
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib /** @TODO reimplement the resolution stuff (WHY?)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib res = Inkscape::Util::Quantity::convert(1, "in", "px");
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib TRACE(("sp_asbitmap_render: resolution: %f\n", res ));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Get the bounding box of the selection in desktop coordinates.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // no bbox, e.g. empty group
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib Geom::Rect docrect(Geom::Rect(Geom::Point(0, 0), item->document->getDimensions()));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // no bbox, e.g. empty group
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 // Scale to exactly fit integer bitmap inside bounding box
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Location of bounding box in document coordinates.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // For default 96 dpi, snap bitmap to pixel grid
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion.
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib // Remove the negations when the inversion is gone.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
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 // ctx matrix already includes item transformation. We must substract.
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Do the export
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 ));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib //TEST(gdk_pixbuf_save( pb, "bitmap.png", "png", NULL, NULL ));
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadibstatic void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx)
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Check item's visibility
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib if((ctx->getFilterToBitmap() == TRUE) && (style->filter.set != 0)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::setStateForItem(CairoRenderContext *ctx, SPItem const *item)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->item_transform = Geom::Affine (item->transform);
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 TRACE(("setStateForItem opacity: %f\n", state->opacity));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// TODO change this to accept a const SPItem:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid CairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->need_layer = ( state->mask || state->clip_path || state->opacity != 1.0 );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // Draw item on a temporary surface so a mask, clip-path, or opacity can be applied to it.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshvoid CairoRenderer::renderHatchPath(CairoRenderContext *ctx, SPHatchPath const &hatchPath, unsigned key) {
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib ctx->transform(Geom::Translate(hatchPath.offset.computed, 0));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh SPCurve *curve = hatchPath.calculateRenderCurve(key);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::PathVector const & pathv =curve->get_pathvector();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->renderPathVector(pathv, hatchPath.style, Geom::OptRect());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, float bleedmargin_px, SPItem *base)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// PLEASE note when making changes to the boundingbox and transform calculation, corresponding changes should be made to PDFLaTeXRenderer::setupDocument !!!
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d = Geom::Rect::from_xywh(Geom::Point(0,0), doc->getDimensions());
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh return false;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // convert from px to pt
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt"));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh TRACE(("setupDocument: %f x %f\n", ctx->_width, ctx->_height));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh bool ret = ctx->setupSurface(ctx->_width, ctx->_height);
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib // translate to set bleed/margin
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine tp( Geom::Translate( bleedmargin_px, bleedmargin_px ) );
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh high = Inkscape::Util::Quantity::convert(high, "px", "pt");
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// Apply an SVG clip path
3955580a5a68a873b098921626f5b9d841b964ecjaspervdgCairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // FIXME: the access to the first clippath view to obtain the bbox is completely bogus
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX && cp->display->bbox) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("clipd", cp->display->bbox);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine t(Geom::Scale(clip_bbox.dimensions()));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for ( SPObject const *child = co->firstChild() ; child; child = child->getNext() ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // combine transform of the item in clippath and the item using clippath:
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Geom::Affine tempmat = item->transform * ctx->getCurrentState()->item_transform;
4b1c2be41ce8c1a88502c1b1885ad1468646fbfftheadib // render this item in clippath
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // TODO fix this call to accept const items
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh sp_item_invoke_render(const_cast<SPItem *>(item), ctx);
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 if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// Apply an SVG mask
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask)
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::Affine t(Geom::Scale(mask_bbox.dimensions()));
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 for ( SPObject const *child = co->firstChild() ; child; child = child->getNext() ) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // TODO fix const correctness:
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 scale = (aspect_clip == SP_ASPECT_MEET) ? MIN(scalex, scaley) : MAX(scalex, scaley);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh /* Now place viewbox to requested position */
case SP_ASPECT_XMAX_YMAX:
#include "clear-n_.h"