index 02bbfc8a392d2b30afd85754c1c1eb7b43025baf..8c27632e11a9fb8bcc9a9263a025fb361f8988e8 100644 (file)
#include <signal.h>
#include <errno.h>
-#include <libnr/n-art-bpath.h>
#include <libnr/nr-matrix-ops.h>
#include <libnr/nr-matrix-fns.h>
#include <libnr/nr-matrix-translate-ops.h>
#include "libnr/nr-scale-translate-ops.h"
#include "libnr/nr-translate-matrix-ops.h"
#include "libnr/nr-translate-scale-ops.h"
+#include "libnr/nr-convert2geom.h"
+#include <2geom/transforms.h>
+#include <2geom/pathvector.h>
#include <glib/gmem.h>
// create initial render state
CairoRenderState *state = new_context->_createState();
- state->transform.set_identity();
+ state->transform = Geom::identity();
new_context->_state_stack = g_slist_prepend(new_context->_state_stack, state);
new_context->_state = state;
static void sp_symbol_render(SPItem *item, CairoRenderContext *ctx);
static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx);
+/* TODO FIXME: this does not render painting-marker-01-f.svg of SVG1.1 Test suite correctly. (orientation of one of the markers middle left ) */
static void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
{
NRRect pbox;
if (!shape->curve) return;
/* fixme: Think (Lauris) */
- sp_item_invoke_bbox(item, &pbox, NR::identity(), TRUE);
- NR::Matrix const i2d = from_2geom(sp_item_i2d_affine(item));
+ sp_item_invoke_bbox(item, &pbox, Geom::identity(), TRUE);
SPStyle* style = SP_OBJECT_STYLE (item);
CairoRenderer *renderer = ctx->getRenderer();
- const_NRBPath bp;
- bp.path = SP_CURVE_BPATH(shape->curve);
+ Geom::PathVector const & pathv = shape->curve->get_pathvector();
- ctx->renderPath(&bp, style, &pbox);
+ ctx->renderPathVector(pathv, style, &pbox);
- for (NArtBpath const* bp = SP_CURVE_BPATH(shape->curve); bp->code != NR_END; bp++) {
- for (int m = SP_MARKER_LOC_START; m < SP_MARKER_LOC_QTY; m++) {
- if (sp_shape_marker_required (shape, m, bp)) {
+ /* TODO: make code prettier: lots of variables can be taken out of the loop! */
+ for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) {
+ if ( shape->marker[SP_MARKER_LOC_START] ) {
+ SPMarker* marker = SP_MARKER (shape->marker[SP_MARKER_LOC_START]);
+ SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[SP_MARKER_LOC_START]));
- SPMarker* marker = SP_MARKER (shape->marker[m]);
- SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[m]));
+ Geom::Matrix tr(sp_shape_marker_get_transform_at_start(path_it->front()));
- NR::Matrix tr(sp_shape_marker_get_transform(shape, bp));
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
+ }
+
+ tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
+
+ Geom::Matrix old_tr = marker_item->transform;
+ marker_item->transform = tr;
+ renderer->renderItem (ctx, marker_item);
+ marker_item->transform = old_tr;
+ }
+
+ if ( shape->marker[SP_MARKER_LOC_MID] && (path_it->size_default() > 1) ) {
+ Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve
+ Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve
+ while (curve_it2 != path_it->end_default())
+ {
+ /* Put marker between curve_it1 and curve_it2.
+ * Loop to end_default (so including closing segment), because when a path is closed,
+ * there should be a midpoint marker between last segment and closing straight line segment */
+
+ SPMarker* marker = SP_MARKER (shape->marker[SP_MARKER_LOC_MID]);
+ SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[SP_MARKER_LOC_MID]));
+
+ Geom::Matrix tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2));
if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
- tr = NR::scale(style->stroke_width.computed) * tr;
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
}
- tr = marker_item->transform * marker->c2p * tr;
+ tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
- NR::Matrix old_tr = marker_item->transform;
+ Geom::Matrix old_tr = marker_item->transform;
marker_item->transform = tr;
renderer->renderItem (ctx, marker_item);
marker_item->transform = old_tr;
+
+ ++curve_it1;
+ ++curve_it2;
}
}
+
+ if ( shape->marker[SP_MARKER_LOC_END] ) {
+ SPMarker* marker = SP_MARKER (shape->marker[SP_MARKER_LOC_END]);
+ SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (shape->marker[SP_MARKER_LOC_END]));
+
+ /* Get reference to last curve in the path.
+ * For moveto-only path, this returns the "closing line segment". */
+ unsigned int index = path_it->size_default();
+ if (index > 0) {
+ index--;
+ }
+ Geom::Curve const &lastcurve = (*path_it)[index];
+
+ Geom::Matrix tr = sp_shape_marker_get_transform_at_end(lastcurve);
+
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
+ }
+
+ tr = (Geom::Matrix)marker_item->transform * (Geom::Matrix)marker->c2p * tr;
+
+ Geom::Matrix old_tr = marker_item->transform;
+ marker_item->transform = tr;
+ renderer->renderItem (ctx, marker_item);
+ marker_item->transform = old_tr;
+ }
}
}
CairoRenderer *renderer = ctx->getRenderer();
if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) {
- NR::Matrix tp(NR::translate(use->x.computed, use->y.computed));
+ Geom::Matrix tp(Geom::Translate(use->x.computed, use->y.computed));
ctx->pushState();
ctx->transform(&tp);
translated = true;
ctx->addClippingRect(image->x.computed, image->y.computed, image->width.computed, image->height.computed);
}
- NR::translate tp(x, y);
- NR::scale s(width / (double)w, height / (double)h);
- NR::Matrix t(s * tp);
+ Geom::Translate tp(x, y);
+ Geom::Scale s(width / (double)w, height / (double)h);
+ Geom::Matrix t(s * tp);
ctx->renderImage (px, w, h, rs, &t, SP_OBJECT_STYLE (item));
}
// apply viewbox if set
if (0 /*symbol->viewBox_set*/) {
- NR::Matrix vb2user;
+ Geom::Matrix vb2user;
double x, y, width, height;
double view_width, view_height;
x = 0.0;
&x, &y,&width, &height);
// [itemTransform *] translate(x, y) * scale(w/vw, h/vh) * translate(-vx, -vy);
- vb2user.set_identity();
+ vb2user = Geom::identity();
vb2user[0] = width / view_width;
vb2user[3] = height / view_height;
vb2user[4] = x - symbol->viewBox.x0 * vb2user[0];
ctx->pushState();
renderer->setStateForItem(ctx, item);
- ctx->transform(&root->c2p);
+ Geom::Matrix tempmat (root->c2p);
+ ctx->transform(&tempmat);
sp_group_render(item, ctx);
ctx->popState();
}
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
// Get the bounding box of the selection
- //NR::Maybe<NR::Rect> _bbox = item->getBounds(from_2geom(sp_item_i2d_affine(item)));
- // NRRect bbox = item->getBounds(from_2geom(sp_item_i2d_affine(item)));
- NRRect bbox(item->getBounds(from_2geom(sp_item_i2d_affine(item))));
+ //boost::optional<Geom::Rect> _bbox = item->getBounds(sp_item_i2d_affine(item));
+ // NRRect bbox = item->getBounds(sp_item_i2d_affine(item));
+ NRRect bbox(item->getBounds(sp_item_i2d_affine(item)));
// List of the items to show; all others will be hidden
}
*/
// Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
- NR::Matrix eek = from_2geom(sp_item_i2d_affine (SP_ITEM(parent_object)));
- NR::Matrix t;
+ Geom::Matrix eek = sp_item_i2d_affine (SP_ITEM(parent_object));
+ Geom::Matrix t;
double shift_x = bbox.x0;
double shift_y = bbox.y1;
shift_x = round (shift_x);
shift_y = -round (-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone
}
- t = (NR::Matrix)(NR::scale(1, -1) * (NR::Matrix)(NR::translate (shift_x, shift_y)* eek.inverse()));
+ t = (Geom::Matrix)(Geom::Scale(1, -1) * (Geom::Matrix)(Geom::Translate (shift_x, shift_y)* eek.inverse()));
- //t = t * ((NR::Matrix)ctx->getCurrentState()->transform).inverse();
+ //t = t * ((Geom::Matrix)ctx->getCurrentState()->transform).inverse();
// Do the export
GdkPixbuf *pb = sp_generate_internal_bitmap(document, NULL,
unsigned int w = gdk_pixbuf_get_width(pb);
unsigned int h = gdk_pixbuf_get_height(pb);
unsigned int rs = gdk_pixbuf_get_rowstride(pb);
- NR::Matrix matrix;
+ Geom::Matrix matrix;
matrix = t;
- //matrix = ((NR::Matrix)ctx->getCurrentState()->transform).inverse();
+ //matrix = ((Geom::Matrix)ctx->getCurrentState()->transform).inverse();
//matrix.set_identity();
ctx->renderImage (px, w, h, rs, &matrix, SP_OBJECT_STYLE (item));
state->merge_opacity = FALSE;
ctx->pushLayer();
}
- ctx->transform(&item->transform);
+ Geom::Matrix tempmat (item->transform);
+ ctx->transform(&tempmat);
sp_item_invoke_render(item, ctx);
if (state->need_layer)
d.y1 = ceil(ctx->_height);
} else {
SPItem* doc_item = SP_ITEM(sp_document_root(doc));
- sp_item_invoke_bbox(doc_item, &d, from_2geom(sp_item_i2r_affine(doc_item)), TRUE);
+ sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);
if (ctx->_vector_based_target) {
// convert from px to pt
d.x0 *= PT_PER_PX;
CairoRenderContext::CairoRenderMode saved_mode = ctx->getRenderMode();
ctx->setRenderMode(CairoRenderContext::RENDER_MODE_CLIP);
- NR::Matrix saved_ctm;
+ Geom::Matrix saved_ctm;
if (cp->clipPathUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
//SP_PRINT_DRECT("clipd", cp->display->bbox);
NRRect clip_bbox(cp->display->bbox);
- NR::Matrix t(NR::scale(clip_bbox.x1 - clip_bbox.x0, clip_bbox.y1 - clip_bbox.y0));
+ Geom::Matrix t(Geom::Scale(clip_bbox.x1 - clip_bbox.x0, clip_bbox.y1 - clip_bbox.y0));
t[4] = clip_bbox.x0;
t[5] = clip_bbox.y0;
t *= ctx->getCurrentState()->transform;
NRRect mask_bbox(mask->display->bbox);
// TODO: should the bbox be transformed if maskUnits != userSpaceOnUse ?
if (mask->maskContentUnits == SP_CONTENT_UNITS_OBJECTBOUNDINGBOX) {
- NR::Matrix t(NR::scale(mask_bbox.x1 - mask_bbox.x0, mask_bbox.y1 - mask_bbox.y0));
+ Geom::Matrix t(Geom::Scale(mask_bbox.x1 - mask_bbox.x0, mask_bbox.y1 - mask_bbox.y0));
t[4] = mask_bbox.x0;
t[5] = mask_bbox.y0;
t *= ctx->getCurrentState()->transform;