summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2014-08-20 11:51:41 +0000
committertavmjong-free <tavmjong@free.fr>2014-08-20 11:51:41 +0000
commit8c009ccdce90c5198260e12ffac837bfdf9b26b7 (patch)
tree15d06a894e294814d86521f10d164b77390d62c5 /src
parentFix gtk3 build (diff)
downloadinkscape-8c009ccdce90c5198260e12ffac837bfdf9b26b7.tar.gz
inkscape-8c009ccdce90c5198260e12ffac837bfdf9b26b7.zip
Implement SVG2 marker 'orient' attribute value 'auto-start-reverse' (rendering only).
(bzr r13341.1.148)
Diffstat (limited to 'src')
-rw-r--r--src/extension/internal/cairo-renderer.cpp12
-rw-r--r--src/marker.cpp41
-rw-r--r--src/marker.h8
-rw-r--r--src/sp-shape.cpp20
4 files changed, 53 insertions, 28 deletions
diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp
index 6fbc85c05..0fec68c06 100644
--- a/src/extension/internal/cairo-renderer.cpp
+++ b/src/extension/internal/cairo-renderer.cpp
@@ -202,8 +202,10 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
if ( shape->_marker[i] ) {
SPMarker* marker = SP_MARKER (shape->_marker[i]);
Geom::Affine tr;
- if (marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_AUTO) {
tr = sp_shape_marker_get_transform_at_start(pathv.begin()->front());
+ } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) {
+ tr = Geom::Rotate::from_degrees( 180.0 ) * sp_shape_marker_get_transform_at_start(pathv.begin()->front());
} else {
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(pathv.begin()->front().pointAt(0));
}
@@ -220,7 +222,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
&& ! ((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
{
Geom::Affine tr;
- if (marker->orient_auto) {
+ if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
tr = sp_shape_marker_get_transform_at_start(path_it->front());
} else {
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(path_it->front().pointAt(0));
@@ -237,7 +239,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
* 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 */
Geom::Affine tr;
- if (marker->orient_auto) {
+ if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
tr = sp_shape_marker_get_transform(*curve_it1, *curve_it2);
} else {
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(curve_it1->pointAt(1));
@@ -253,7 +255,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
if ( path_it != (pathv.end()-1) && !path_it->empty()) {
Geom::Curve const &lastcurve = path_it->back_default();
Geom::Affine tr;
- if (marker->orient_auto) {
+ if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
tr = sp_shape_marker_get_transform_at_end(lastcurve);
} else {
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
@@ -277,7 +279,7 @@ static void sp_shape_render (SPItem *item, CairoRenderContext *ctx)
Geom::Curve const &lastcurve = path_last[index];
Geom::Affine tr;
- if (marker->orient_auto) {
+ if (marker->orient_mode != MARKER_ORIENT_ANGLE) {
tr = sp_shape_marker_get_transform_at_end(lastcurve);
} else {
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(lastcurve.pointAt(1));
diff --git a/src/marker.cpp b/src/marker.cpp
index 7fee16ead..a4cbc30ca 100644
--- a/src/marker.cpp
+++ b/src/marker.cpp
@@ -52,7 +52,7 @@ SPMarker::SPMarker() : SPGroup(), SPViewBox() {
this->markerUnits = 0;
this->markerUnits_set = 0;
- this->orient_auto = 0;
+ this->orient_mode = MARKER_ORIENT_ANGLE;
this->orient_set = 0;
this->orient = 0;
@@ -158,16 +158,20 @@ void SPMarker::set(unsigned int key, const gchar* value) {
case SP_ATTR_ORIENT:
this->orient_set = FALSE;
- this->orient_auto = FALSE;
+ this->orient_mode = MARKER_ORIENT_ANGLE;
this->orient = 0.0;
if (value) {
- if (!strcmp (value, "auto")) {
- this->orient_auto = TRUE;
- this->orient_set = TRUE;
- } else if (sp_svg_number_read_f (value, &this->orient)) {
- this->orient_set = TRUE;
- }
+ if (!strcmp (value, "auto")) {
+ this->orient_mode = MARKER_ORIENT_AUTO;
+ this->orient_set = TRUE;
+ } else if (!strcmp (value, "auto-start-reverse")) {
+ this->orient_mode = MARKER_ORIENT_AUTO_START_REVERSE;
+ this->orient_set = TRUE;
+ } else if (sp_svg_number_read_f (value, &this->orient)) {
+ this->orient_mode = MARKER_ORIENT_ANGLE;
+ this->orient_set = TRUE;
+ }
}
this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
@@ -264,15 +268,17 @@ Inkscape::XML::Node* SPMarker::write(Inkscape::XML::Document *xml_doc, Inkscape:
}
if (this->orient_set) {
- if (this->orient_auto) {
- repr->setAttribute("orient", "auto");
- } else {
- sp_repr_set_css_double(repr, "orient", this->orient);
- }
+ if (this->orient_mode == MARKER_ORIENT_AUTO) {
+ repr->setAttribute("orient", "auto");
+ } else if (this->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) {
+ repr->setAttribute("orient", "auto-start-reverse");
+ } else {
+ sp_repr_set_css_double(repr, "orient", this->orient);
+ }
} else {
- repr->setAttribute("orient", NULL);
+ repr->setAttribute("orient", NULL);
}
-
+
/* fixme: */
//XML Tree being used directly here while it shouldn't be....
repr->setAttribute("viewBox", this->getRepr()->attribute("viewBox"));
@@ -381,7 +387,10 @@ sp_marker_show_instance ( SPMarker *marker, Inkscape::DrawingItem *parent,
}
if (v->items[pos]) {
Geom::Affine m;
- if (marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_AUTO) {
+ m = base;
+ } else if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) {
+ m = Geom::Rotate::from_degrees( 180.0 ) * base;
m = base;
} else {
/* fixme: Orient units (Lauris) */
diff --git a/src/marker.h b/src/marker.h
index 585615476..9eefcdf16 100644
--- a/src/marker.h
+++ b/src/marker.h
@@ -32,6 +32,12 @@ struct SPMarkerView;
#include "uri-references.h"
#include "viewbox.h"
+enum markerOrient {
+ MARKER_ORIENT_ANGLE,
+ MARKER_ORIENT_AUTO,
+ MARKER_ORIENT_AUTO_START_REVERSE
+};
+
class SPMarker : public SPGroup, public SPViewBox {
public:
SPMarker();
@@ -51,7 +57,7 @@ public:
/* orient */
unsigned int orient_set : 1;
- unsigned int orient_auto : 1;
+ markerOrient orient_mode : 2;
float orient;
/* Private views */
diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp
index de9103dee..d76bd9780 100644
--- a/src/sp-shape.cpp
+++ b/src/sp-shape.cpp
@@ -288,8 +288,13 @@ sp_shape_update_marker_view(SPShape *shape, Inkscape::DrawingItem *ai)
Geom::Affine const m (sp_shape_marker_get_transform_at_start(pathv.begin()->front()));
for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
if ( shape->_marker[i] ) {
+ Geom::Affine m_auto = m;
+ // Reverse start marker if necessary.
+ if (SP_MARKER(shape->_marker[i])->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) {
+ m_auto = Geom::Rotate::from_degrees( 180.0 ) * m;
+ }
sp_marker_show_instance ((SPMarker* ) shape->_marker[i], ai,
- ai->key() + i, counter[i], m,
+ ai->key() + i, counter[i], m_auto,
shape->style->stroke_width.computed);
counter[i]++;
}
@@ -425,7 +430,10 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox
if (marker_item) {
Geom::Affine tr(sp_shape_marker_get_transform_at_start(pathv.begin()->front()));
- if (!marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_AUTO_START_REVERSE) {
+ // Reverse start marker if necessary
+ tr = Geom::Rotate::from_degrees( 180.0 ) * tr;
+ } else if (marker->orient_mode == MARKER_ORIENT_ANGLE) {
Geom::Point transl = tr.translation();
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
}
@@ -463,7 +471,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox
{
Geom::Affine tr(sp_shape_marker_get_transform_at_start(path_it->front()));
- if (!marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_ANGLE) {
Geom::Point transl = tr.translation();
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
}
@@ -493,7 +501,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox
if (marker_item) {
Geom::Affine tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2));
- if (!marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_ANGLE) {
Geom::Point transl = tr.translation();
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
}
@@ -516,7 +524,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox
Geom::Curve const &lastcurve = path_it->back_default();
Geom::Affine tr = sp_shape_marker_get_transform_at_end(lastcurve);
- if (!marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_ANGLE) {
Geom::Point transl = tr.translation();
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
}
@@ -551,7 +559,7 @@ Geom::OptRect SPShape::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox
Geom::Affine tr = sp_shape_marker_get_transform_at_end(lastcurve);
- if (!marker->orient_auto) {
+ if (marker->orient_mode == MARKER_ORIENT_ANGLE) {
Geom::Point transl = tr.translation();
tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
}