X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fmarker.cpp;h=c66acc1924f3869b67faad8373c2d36167292941;hb=133dcec309d7cde809079815da13d8640a67e6b3;hp=3961f847376d284e1541419ade12c880905a7a2c;hpb=06aecef405c4cf6f7551ab622c3040562cb62c78;p=inkscape.git diff --git a/src/marker.cpp b/src/marker.cpp index 3961f8473..c66acc192 100644 --- a/src/marker.cpp +++ b/src/marker.cpp @@ -117,9 +117,9 @@ sp_marker_class_init (SPMarkerClass *klass) static void sp_marker_init (SPMarker *marker) { - marker->viewBox_set = FALSE; - - marker->c2p.setIdentity(); + marker->viewBox = Geom::OptRect(); + marker->c2p.setIdentity(); + marker->views = NULL; } /** @@ -251,7 +251,7 @@ sp_marker_set (SPObject *object, unsigned int key, const gchar *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_VIEWBOX: - marker->viewBox_set = FALSE; + marker->viewBox = Geom::OptRect(); if (value) { double x, y, width, height; char *eptr; @@ -268,11 +268,8 @@ sp_marker_set (SPObject *object, unsigned int key, const gchar *value) while (*eptr && ((*eptr == ',') || (*eptr == ' '))) eptr++; if ((width > 0) && (height > 0)) { /* Set viewbox */ - marker->viewBox.x0 = x; - marker->viewBox.y0 = y; - marker->viewBox.x1 = x + width; - marker->viewBox.y1 = y + height; - marker->viewBox_set = TRUE; + marker->viewBox = Geom::Rect( Geom::Point(x,y), + Geom::Point(x + width, y + height) ); } } object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG); @@ -354,7 +351,7 @@ sp_marker_update (SPObject *object, SPCtx *ctx, guint flags) SPItem *item; SPMarker *marker; SPItemCtx rctx; - NRRect *vb; + Geom::Rect vb; double x, y, width, height; SPMarkerView *v; @@ -378,10 +375,10 @@ sp_marker_update (SPObject *object, SPCtx *ctx, guint flags) marker->c2p.setIdentity(); /* Viewbox is always present, either implicitly or explicitly */ - if (marker->viewBox_set) { - vb = &marker->viewBox; + if (marker->viewBox) { + vb = *marker->viewBox; } else { - vb = &rctx.vp; + vb = *(rctx.vp.upgrade_2geom()); } /* Now set up viewbox transformation */ /* Determine actual viewbox in viewport coordinates */ @@ -393,11 +390,11 @@ sp_marker_update (SPObject *object, SPCtx *ctx, guint flags) } else { double scalex, scaley, scale; /* Things are getting interesting */ - scalex = (rctx.vp.x1 - rctx.vp.x0) / (vb->x1 - vb->x0); - scaley = (rctx.vp.y1 - rctx.vp.y0) / (vb->y1 - vb->y0); + scalex = (rctx.vp.x1 - rctx.vp.x0) / (vb.width()); + scaley = (rctx.vp.y1 - rctx.vp.y0) / (vb.height()); scale = (marker->aspect_clip == SP_ASPECT_MEET) ? MIN (scalex, scaley) : MAX (scalex, scaley); - width = (vb->x1 - vb->x0) * scale; - height = (vb->y1 - vb->y0) * scale; + width = (vb.width()) * scale; + height = (vb.height()) * scale; /* Now place viewbox to requested position */ switch (marker->aspect_align) { case SP_ASPECT_XMIN_YMIN: @@ -446,12 +443,12 @@ sp_marker_update (SPObject *object, SPCtx *ctx, guint flags) { Geom::Matrix q; /* Compose additional transformation from scale and position */ - q[0] = width / (vb->x1 - vb->x0); - q[1] = 0.0; - q[2] = 0.0; - q[3] = height / (vb->y1 - vb->y0); - q[4] = -vb->x0 * q[0] + x; - q[5] = -vb->y0 * q[3] + y; + q[0] = width / vb.width(); + q[1] = 0.0; + q[2] = 0.0; + q[3] = height / vb.height(); + q[4] = -vb.min()[Geom::X] * q[0] + x; + q[5] = -vb.min()[Geom::Y] * q[3] + y; /* Append viewbox transformation */ marker->c2p = q * marker->c2p; } @@ -464,11 +461,11 @@ sp_marker_update (SPObject *object, SPCtx *ctx, guint flags) /* If viewBox is set reinitialize child viewport */ /* Otherwise it already correct */ - if (marker->viewBox_set) { - rctx.vp.x0 = marker->viewBox.x0; - rctx.vp.y0 = marker->viewBox.y0; - rctx.vp.x1 = marker->viewBox.x1; - rctx.vp.y1 = marker->viewBox.y1; + if (marker->viewBox) { + rctx.vp.x0 = marker->viewBox->min()[Geom::X]; + rctx.vp.y0 = marker->viewBox->min()[Geom::Y]; + rctx.vp.x1 = marker->viewBox->max()[Geom::X]; + rctx.vp.y1 = marker->viewBox->max()[Geom::Y]; rctx.i2vp = Geom::identity(); } @@ -602,30 +599,29 @@ sp_marker_print (SPItem */*item*/, SPPrintContext */*ctx*/) void sp_marker_show_dimension (SPMarker *marker, unsigned int key, unsigned int size) { - SPMarkerView *view; - unsigned int i; + SPMarkerView *view; + unsigned int i; - for (view = marker->views; view != NULL; view = view->next) { - if (view->key == key) break; - } - if (view && (view->items.size() != size)) { - /* Free old view and allocate new */ - /* Parent class ::hide method */ - ((SPItemClass *) parent_class)->hide ((SPItem *) marker, key); - sp_marker_view_remove (marker, view, TRUE); - view = NULL; - } - if (!view) { - view = (SPMarkerView *) g_new (SPMarkerView, 1); - new (&view->items) std::vector; - view->items.clear(); - for (i = 0; i < size; i++) { - view->items.push_back(NULL); + for (view = marker->views; view != NULL; view = view->next) { + if (view->key == key) break; + } + if (view && (view->items.size() != size)) { + /* Free old view and allocate new */ + /* Parent class ::hide method */ + ((SPItemClass *) parent_class)->hide ((SPItem *) marker, key); + sp_marker_view_remove (marker, view, TRUE); + view = NULL; + } + if (!view) { + view = new SPMarkerView(); + view->items.clear(); + for (i = 0; i < size; i++) { + view->items.push_back(NULL); + } + view->next = marker->views; + marker->views = view; + view->key = key; } - view->next = marker->views; - marker->views = view; - view->key = key; - } } /** @@ -661,8 +657,8 @@ sp_marker_show_instance ( SPMarker *marker, NRArenaItem *parent, m = base; } else { /* fixme: Orient units (Lauris) */ - m = Geom::Matrix(Geom::Rotate::from_degrees(marker->orient)); - m *= Geom::Translate(base[4], base[5]); // TODO: this was NR::get_translation() originally; should it be extracted into a new 2geom function? + m = Geom::Rotate::from_degrees(marker->orient); + m *= Geom::Translate(base.translation()); } if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) { m = Geom::Scale(linewidth) * m; @@ -722,8 +718,8 @@ sp_marker_view_remove (SPMarker *marker, SPMarkerView *view, unsigned int destro if (view->items[i]) nr_arena_item_unref (view->items[i]); } } - view->items.clear(); - g_free (view); + view->items.clear(); + delete view; } const gchar *