diff --git a/src/marker.cpp b/src/marker.cpp
index d3927fd59e8e4ee069a11175bc6be033603c4c18..0ec92a1ff2147b00573ad9703e86d10a7628083c 100644 (file)
--- a/src/marker.cpp
+++ b/src/marker.cpp
-#define __MARKER_C__
-
/*
* SVG <marker> implementation
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Bryce Harrington <bryce@bryceharrington.org>
+ * Abhishek Sharma
*
* Copyright (C) 1999-2003 Lauris Kaplinski
* 2004-2006 Bryce Harrington
static void
sp_marker_init (SPMarker *marker)
{
- marker->viewBox_set = FALSE;
-
- marker->c2p.setIdentity();
-
+ marker->viewBox = Geom::OptRect();
+ marker->c2p.setIdentity();
marker->views = NULL;
}
@@ -143,14 +140,14 @@ sp_marker_build (SPObject *object, SPDocument *document, Inkscape::XML::Node *re
group = (SPGroup *) object;
marker = (SPMarker *) object;
- sp_object_read_attr (object, "markerUnits");
- sp_object_read_attr (object, "refX");
- sp_object_read_attr (object, "refY");
- sp_object_read_attr (object, "markerWidth");
- sp_object_read_attr (object, "markerHeight");
- sp_object_read_attr (object, "orient");
- sp_object_read_attr (object, "viewBox");
- sp_object_read_attr (object, "preserveAspectRatio");
+ object->readAttr( "markerUnits" );
+ object->readAttr( "refX" );
+ object->readAttr( "refY" );
+ object->readAttr( "markerWidth" );
+ object->readAttr( "markerHeight" );
+ object->readAttr( "orient" );
+ object->readAttr( "viewBox" );
+ object->readAttr( "preserveAspectRatio" );
if (((SPObjectClass *) parent_class)->build)
((SPObjectClass *) parent_class)->build (object, document, repr);
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;
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);
SPItem *item;
SPMarker *marker;
SPItemCtx rctx;
- NRRect *vb;
+ Geom::Rect vb;
double x, y, width, height;
SPMarkerView *v;
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 */
} 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:
}
}
- {
- 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;
- /* Append viewbox transformation */
- marker->c2p = q * marker->c2p;
- }
-
- /* Append reference translation */
- /* fixme: lala (Lauris) */
- marker->c2p = Geom::Translate(-marker->refX.computed, -marker->refY.computed) * marker->c2p;
+ // viewbox transformation and reference translation
+ marker->c2p = Geom::Translate(-marker->refX.computed, -marker->refY.computed) *
+ Geom::Scale(width / vb.width(), height / vb.height());
rctx.i2doc = marker->c2p * rctx.i2doc;
/* 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();
}
@@ -542,8 +523,10 @@ sp_marker_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::X
repr->setAttribute("orient", NULL);
}
/* fixme: */
- repr->setAttribute("viewBox", object->repr->attribute("viewBox"));
- repr->setAttribute("preserveAspectRatio", object->repr->attribute("preserveAspectRatio"));
+ //XML Tree being used directly here while it shouldn't be....
+ repr->setAttribute("viewBox", object->getRepr()->attribute("viewBox"));
+ //XML Tree being used directly here while it shouldn't be....
+ repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio"));
if (((SPObjectClass *) (parent_class))->write)
((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
@@ -727,11 +710,10 @@ sp_marker_view_remove (SPMarker *marker, SPMarkerView *view, unsigned int destro
delete view;
}
-const gchar *
-generate_marker (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Matrix /*transform*/, Geom::Matrix move)
+const gchar *generate_marker(GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::Matrix /*transform*/, Geom::Matrix move)
{
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
- Inkscape::XML::Node *defsrepr = SP_OBJECT_REPR (SP_DOCUMENT_DEFS (document));
+ Inkscape::XML::Document *xml_doc = document->getReprDoc();
+ Inkscape::XML::Node *defsrepr = SP_DOCUMENT_DEFS(document)->getRepr();
Inkscape::XML::Node *repr = xml_doc->createElement("svg:marker");
@@ -758,7 +740,7 @@ generate_marker (GSList *reprs, Geom::Rect bounds, SPDocument *document, Geom::M
dup_transform = Geom::identity();
dup_transform *= move;
- sp_item_write_transform(copy, SP_OBJECT_REPR(copy), dup_transform);
+ copy->doWriteTransform(SP_OBJECT_REPR(copy), dup_transform);
}
Inkscape::GC::release(repr);