cairo-renderer.cpp revision 025db6f90298127a666cd24bcfc2e22fd35ca84d
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Rendering with Cairo.
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Miklos Erdelyi <erdelyim@gmail.com>
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Copyright (C) 2006 Miklos Erdelyi
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh * Licensed under GNU GPL
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh// include support for only the compiled-in surface types
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh//#define TRACE(_args) g_printf _args
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould//#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'
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);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen sp_item_invoke_bbox(item, &pbox, Geom::identity(), TRUE);
7cc06cc17ffc875601993118f9533dfe36bd2dd5johanengelen Geom::PathVector const & pathv = shape->curve->get_pathvector();
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 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]));
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould tr = sp_shape_marker_get_transform_at_start(path_it->front());
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(path_it->front().pointAt(0));
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould bool render = true;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould tr = Geom::Scale(style->stroke_width.computed) * tr;
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould render = false; // stroke width zero and marker is thus scaled down to zero, skip
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
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 /* 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 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]));
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould tr = sp_shape_marker_get_transform(*curve_it1, *curve_it2);
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(curve_it1->pointAt(1));
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould bool render = true;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould tr = Geom::Scale(style->stroke_width.computed) * tr;
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould render = false; // stroke width zero and marker is thus scaled down to zero, skip
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
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]));
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen /* Get reference to last curve in the path.
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen * For moveto-only path, this returns the "closing line segment". */
e21d4ac16bee82a55fd227660aa14af10ecac9b1johanengelen Geom::Curve const &lastcurve = (*path_it)[index];
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould tr = sp_shape_marker_get_transform_at_end(lastcurve);
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould bool render = true;
54e660c4de9d37185e3953165d053526632ef4f0johanengelen if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould tr = Geom::Scale(style->stroke_width.computed) * tr;
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould render = false; // stroke width zero and marker is thus scaled down to zero, skip
7079a43aa387066c2f67402d77dbe3db981b1054Ted Gould tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_group_render(SPItem *item, CairoRenderContext *ctx)
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(SP_OBJECT_STYLE(item)->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)) {
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix 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);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Scale s(width / (double)w, height / (double)h);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->renderImage (px, w, h, rs, &t, SP_OBJECT_STYLE (item));
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*/) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh view_width = symbol->viewBox.x1 - symbol->viewBox.x0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh view_height = symbol->viewBox.y1 - symbol->viewBox.y0;
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh calculatePreserveAspectRatio(symbol->aspect_align, symbol->aspect_clip, view_width, view_height,
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh // [itemTransform *] translate(x, y) * scale(w/vw, h/vh) * translate(-vx, -vy);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_root_render(SPItem *item, CairoRenderContext *ctx)
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);
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould This function converts the item to a raster image and includes the image into the cairo renderer.
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould 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)
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // The code was adapted from sp_selection_create_bitmap_copy in selection-chemistry.cpp
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Calculate resolution
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould /** @TODO reimplement the resolution stuff (WHY?)
16dc3cff4d07c7f5afdd8c74cf34530b0a6ee93btavmjong TRACE(("sp_asbitmap_render: resolution: %f\n", res ));
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // Get the bounding box of the selection in document coordinates.
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould item->getBounds(sp_item_i2d_affine(item), SPItem::RENDERING_BBOX);
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // The width and height of the bitmap in pixels
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould unsigned width = (unsigned) floor ((bbox->max()[Geom::X] - bbox->min()[Geom::X]) * (res / PX_PER_IN));
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould unsigned height =(unsigned) floor ((bbox->max()[Geom::Y] - bbox->min()[Geom::Y]) * (res / PX_PER_IN));
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // Scale to exactly fit integer bitmap inside bounding box
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould double scale_x = (bbox->max()[Geom::X] - bbox->min()[Geom::X]) / width;
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould double scale_y = (bbox->max()[Geom::Y] - bbox->min()[Geom::Y]) / height;
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // Location of bounding box in document coordinates.
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // For default 90 dpi, snap bitmap to pixel grid
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion.
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // Remove the negations when the inversion is gone.
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // Matix to put bitmap in correct place on document
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould Geom::Matrix t_on_document = (Geom::Matrix)(Geom::Scale (scale_x, -scale_y)) *
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould (Geom::Matrix)(Geom::Translate (shift_x, shift_y));
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould // ctx matrix already includes item transformation. We must substract.
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould Geom::Matrix t = t_on_document * t_item.inverse();
5c45c5153b0415f7573f69f4ee3e946b5872a8d1theadib // Do the export
45d0b0d0dc24df8e321cbe8a085ab9b1f60b4a42theadib GdkPixbuf *pb = sp_generate_internal_bitmap(document, NULL,
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould bbox->min()[Geom::X], bbox->min()[Geom::Y], bbox->max()[Geom::X], bbox->max()[Geom::Y],
3bd80e038b72ad220f218d7053a9089685fab17cTed Gould width, height, res, res, (guint32) 0xffffff00, items );
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould TEST(gdk_pixbuf_save( pb, "bitmap.png", "png", NULL, NULL ));
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould ctx->renderImage (px, w, h, rs, &t, SP_OBJECT_STYLE (item));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshstatic void sp_item_invoke_render(SPItem *item, CairoRenderContext *ctx)
1babefb17e4c8157ca2a0f588625a8ac0258dc53buliabyak // Check item's visibility
861fa436e7a6d6ff3eaa889b2298e0b82a0b238ctheadib if((ctx->getFilterToBitmap() == TRUE) && (style->filter.set != 0)) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::setStateForItem(CairoRenderContext *ctx, SPItem const *item)
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak state->item_transform = Geom::Matrix (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))
16dc3cff4d07c7f5afdd8c74cf34530b0a6ee93btavmjong TRACE(("setStateForItem opacity: %f\n", state->opacity));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::renderItem(CairoRenderContext *ctx, SPItem *item)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh state->need_layer = ( state->mask || state->clip_path || state->opacity != 1.0 );
16dc3cff4d07c7f5afdd8c74cf34530b0a6ee93btavmjong // Draw item on a temporary surface so a mask, clip path, or opacity can be applied to it.
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyakCairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool pageBoundingBox, SPItem *base)
025db6f90298127a666cd24bcfc2e22fd35ca84dspeleo sp_item_invoke_bbox(base, &d, sp_item_i2d_affine(base), TRUE, SPItem::RENDERING_BBOX);
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould // convert from px to pt
16dc3cff4d07c7f5afdd8c74cf34530b0a6ee93btavmjong TRACE(("setupDocument: %f x %f\n", ctx->_width, ctx->_height));
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould bool ret = ctx->setupSurface(ctx->_width, ctx->_height);
ddc1f1d1291eb21b244c7328d260c7d4a43be2fcbuliabyak Geom::Matrix tp(Geom::Translate(-d.x0 * (ctx->_vector_based_target ? PX_PER_PT : 1.0),
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould (d.y1 - high) * (ctx->_vector_based_target ? PX_PER_PT : 1.0)));
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould// Apply an SVG clip path
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::applyClipPath(CairoRenderContext *ctx, SPClipPath const *cp)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode();
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("clipd", cp->display->bbox);
17d87f5698f5c2958d38c6a6207c7b322a7adaf9johanengelen Geom::Matrix t(Geom::Scale(clip_bbox.x1 - clip_bbox.x0, clip_bbox.y1 - clip_bbox.y0));
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (SPObject *child = sp_object_first_child(co) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak // combine transform of the item in clippath and the item using clippath:
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak tempmat = tempmat * (ctx->getCurrentState()->item_transform);
bf7069a487ba218c4542e4adc5497ebd746ab929buliabyak // render this item in clippath
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 if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX)
63d6ddd517060979dd8b8fd41aad3faca7be3c5cTed Gould// Apply an SVG mask
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6mikloshCairoRenderer::applyMask(CairoRenderContext *ctx, SPMask const *mask)
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh //SP_PRINT_DRECT("maskd", &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));
533909ea7bb06d8f0658b7d448fa4283afd3f52ftavmjong // Clip mask contents... but...
533909ea7bb06d8f0658b7d448fa4283afd3f52ftavmjong // The mask's bounding box is the "geometric bounding box" which doesn't allow for
533909ea7bb06d8f0658b7d448fa4283afd3f52ftavmjong // filters which extend outside the bounding box. So don't clip.
533909ea7bb06d8f0658b7d448fa4283afd3f52ftavmjong // ctx->addClippingRect(mask_bbox.x0, mask_bbox.y0, mask_bbox.x1 - mask_bbox.x0, mask_bbox.y1 - mask_bbox.y0);
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh for (SPObject *child = sp_object_first_child(co) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
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 */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} /* namespace Internal */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} /* namespace Extension */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh} /* namespace Inkscape */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh/* End of GNU GPL code */
b7f07692f95074fdcf74c7350fbf5f3099ffc1b6miklosh Local Variables:
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// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :