Code

Node tool: fix handle retraction with non-cusp nodes
[inkscape.git] / src / sp-text.cpp
index dd57428ef914877edc58da707e64634a3a420f9e..80eb786f28754cbfed3928c5b7cc6d5c62de92af 100644 (file)
@@ -4,6 +4,8 @@
  * Author:
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   bulia byak <buliabyak@users.sf.net>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 1999-2002 Lauris Kaplinski
  * Copyright (C) 2000-2001 Ximian, Inc.
@@ -74,7 +76,7 @@ static void sp_text_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &t
 static NRArenaItem *sp_text_show (SPItem *item, NRArena *arena, unsigned key, unsigned flags);
 static void sp_text_hide (SPItem *item, unsigned key);
 static char *sp_text_description (SPItem *item);
-static void sp_text_snappoints(SPItem const *item, SnapPointsIter p);
+static void sp_text_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
 static Geom::Matrix sp_text_set_transform(SPItem *item, Geom::Matrix const &xform);
 static void sp_text_print (SPItem *item, SPPrintContext *gpc);
 
@@ -149,16 +151,16 @@ sp_text_release (SPObject *object)
 static void
 sp_text_build (SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr)
 {
-    sp_object_read_attr(object, "x");
-    sp_object_read_attr(object, "y");
-    sp_object_read_attr(object, "dx");
-    sp_object_read_attr(object, "dy");
-    sp_object_read_attr(object, "rotate");
+    object->readAttr( "x" );
+    object->readAttr( "y" );
+    object->readAttr( "dx" );
+    object->readAttr( "dy" );
+    object->readAttr( "rotate" );
 
     if (((SPObjectClass *) text_parent_class)->build)
         ((SPObjectClass *) text_parent_class)->build(object, doc, repr);
 
-    sp_object_read_attr(object, "sodipodi:linespacing");    // has to happen after the styles are read
+    object->readAttr( "sodipodi:linespacing" );    // has to happen after the styles are read
 }
 
 static void
@@ -211,8 +213,7 @@ sp_text_remove_child (SPObject *object, Inkscape::XML::Node *rch)
     text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
 }
 
-static void
-sp_text_update (SPObject *object, SPCtx *ctx, guint flags)
+static void sp_text_update(SPObject *object, SPCtx *ctx, guint flags)
 {
     SPText *text = SP_TEXT (object);
 
@@ -223,9 +224,9 @@ sp_text_update (SPObject *object, SPCtx *ctx, guint flags)
     if (flags & SP_OBJECT_MODIFIED_FLAG) cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
 
 
-    /* Create temporary list of children */
+    // Create temporary list of children
     GSList *l = NULL;
-    for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+    for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
         sp_object_ref (SP_OBJECT (child), object);
         l = g_slist_prepend (l, child);
     }
@@ -249,7 +250,7 @@ sp_text_update (SPObject *object, SPCtx *ctx, guint flags)
         text->rebuildLayout();
 
         NRRect paintbox;
-        sp_item_invoke_bbox(text, &paintbox, NR::identity(), TRUE);
+        text->invoke_bbox( &paintbox, Geom::identity(), TRUE);
         for (SPItemView* v = text->display; v != NULL; v = v->next) {
             text->_clearFlow(NR_ARENA_GROUP(v->arenaitem));
             nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
@@ -259,14 +260,16 @@ sp_text_update (SPObject *object, SPCtx *ctx, guint flags)
     }
 }
 
-static void
-sp_text_modified (SPObject *object, guint flags)
+static void sp_text_modified(SPObject *object, guint flags)
 {
-    if (((SPObjectClass *) text_parent_class)->modified)
+    if (((SPObjectClass *) text_parent_class)->modified) {
         ((SPObjectClass *) text_parent_class)->modified (object, flags);
+    }
 
     guint cflags = (flags & SP_OBJECT_MODIFIED_CASCADE);
-    if (flags & SP_OBJECT_MODIFIED_FLAG) cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+    if (flags & SP_OBJECT_MODIFIED_FLAG) {
+        cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG;
+    }
 
     // FIXME: all that we need to do here is nr_arena_glyphs_[group_]set_style, to set the changed
     // style, but there's no easy way to access the arena glyphs or glyph groups corresponding to a
@@ -275,7 +278,7 @@ sp_text_modified (SPObject *object, guint flags)
     if (flags & ( SP_OBJECT_STYLE_MODIFIED_FLAG )) {
         SPText *text = SP_TEXT (object);
         NRRect paintbox;
-        sp_item_invoke_bbox(text, &paintbox, NR::identity(), TRUE);
+        text->invoke_bbox( &paintbox, Geom::identity(), TRUE);
         for (SPItemView* v = text->display; v != NULL; v = v->next) {
             text->_clearFlow(NR_ARENA_GROUP(v->arenaitem));
             nr_arena_group_set_style(NR_ARENA_GROUP(v->arenaitem), SP_OBJECT_STYLE(object));
@@ -283,16 +286,15 @@ sp_text_modified (SPObject *object, guint flags)
         }
     }
 
-    /* Create temporary list of children */
+    // Create temporary list of children
     GSList *l = NULL;
-    SPObject *child;
-    for (child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+    for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
         sp_object_ref (SP_OBJECT (child), object);
         l = g_slist_prepend (l, child);
     }
     l = g_slist_reverse (l);
     while (l) {
-        child = SP_OBJECT (l->data);
+        SPObject *child = SP_OBJECT (l->data);
         l = g_slist_remove (l, child);
         if (cflags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) {
             child->emitModified(cflags);
@@ -301,24 +303,28 @@ sp_text_modified (SPObject *object, guint flags)
     }
 }
 
-static Inkscape::XML::Node *
-sp_text_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
+static Inkscape::XML::Node *sp_text_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
     SPText *text = SP_TEXT (object);
 
     if (flags & SP_OBJECT_WRITE_BUILD) {
-        if (!repr)
+        if (!repr) {
             repr = xml_doc->createElement("svg:text");
+        }
         GSList *l = NULL;
-        for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
-            if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
+        for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
+            if (SP_IS_TITLE(child) || SP_IS_DESC(child)) {
+                continue;
+            }
             Inkscape::XML::Node *crepr = NULL;
             if (SP_IS_STRING(child)) {
                 crepr = xml_doc->createTextNode(SP_STRING(child)->string.c_str());
             } else {
                 crepr = child->updateRepr(xml_doc, NULL, flags);
             }
-            if (crepr) l = g_slist_prepend (l, crepr);
+            if (crepr) {
+                l = g_slist_prepend (l, crepr);
+            }
         }
         while (l) {
             repr->addChild((Inkscape::XML::Node *) l->data, NULL);
@@ -326,8 +332,10 @@ sp_text_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML
             l = g_slist_remove (l, l->data);
         }
     } else {
-        for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
-            if (SP_IS_TITLE(child) || SP_IS_DESC(child)) continue;
+        for (SPObject *child = object->firstChild() ; child ; child = child->getNext() ) {
+            if (SP_IS_TITLE(child) || SP_IS_DESC(child)) {
+                continue;
+            }
             if (SP_IS_STRING(child)) {
                 SP_OBJECT_REPR(child)->setContent(SP_STRING(child)->string.c_str());
             } else {
@@ -343,12 +351,13 @@ sp_text_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML
         Inkscape::SVGOStringStream os;
         os << (text->style->line_height.value * 100.0) << "%";
         SP_OBJECT_REPR(text)->setAttribute("sodipodi:linespacing", os.str().c_str());
-    }
-    else
+    } else {
         SP_OBJECT_REPR(text)->setAttribute("sodipodi:linespacing", NULL);
+    }
 
-    if (((SPObjectClass *) (text_parent_class))->write)
+    if (((SPObjectClass *) (text_parent_class))->write) {
         ((SPObjectClass *) (text_parent_class))->write (object, xml_doc, repr, flags);
+    }
 
     return repr;
 }
@@ -387,7 +396,7 @@ sp_text_show(SPItem *item, NRArena *arena, unsigned /* key*/, unsigned /*flags*/
 
     // pass the bbox of the text object as paintbox (used for paintserver fills)
     NRRect paintbox;
-    sp_item_invoke_bbox(item, &paintbox, NR::identity(), TRUE);
+    item->invoke_bbox( &paintbox, Geom::identity(), TRUE);
     group->layout.show(flowed, &paintbox);
 
     return flowed;
@@ -407,7 +416,7 @@ sp_text_description(SPItem *item)
     SPStyle *style = SP_OBJECT_STYLE(text);
 
     font_instance *tf = font_factory::Default()->FaceFromStyle(style);
-    
+
     char name_buf[256];
     char *n;
     if (tf) {
@@ -421,19 +430,29 @@ sp_text_description(SPItem *item)
 
     GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric());
 
+    char const *trunc = "";
+    Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
+    if (layout && layout->inputTruncated()) {
+        trunc = _(" [truncated]");
+    }
+
     char *ret = ( SP_IS_TEXT_TEXTPATH(item)
-                  ? g_strdup_printf(_("<b>Text on path</b> (%s, %s)"), n, xs->str)
-                  : g_strdup_printf(_("<b>Text</b> (%s, %s)"), n, xs->str) );
+                  ? g_strdup_printf(_("<b>Text on path</b>%s (%s, %s)"), trunc, n, xs->str)
+                  : g_strdup_printf(_("<b>Text</b>%s (%s, %s)"), trunc, n, xs->str) );
     g_free(n);
     return ret;
 }
 
-static void sp_text_snappoints(SPItem const *item, SnapPointsIter p)
+static void sp_text_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const */*snapprefs*/)
 {
-    // the baseline anchor of the first char
+    // Choose a point on the baseline for snapping from or to, with the horizontal position
+    // of this point depending on the text alignment (left vs. right)
     Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
-    if(layout != NULL) {
-        *p = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item);
+    if (layout != NULL && layout->outputExists()) {
+        boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+        if (pt) {
+            p.push_back(Inkscape::SnapCandidatePoint((*pt) * item->i2d_affine(), Inkscape::SNAPSOURCE_TEXT_BASELINE, Inkscape::SNAPTARGET_TEXT_BASELINE));
+        }
     }
 }
 
@@ -473,13 +492,13 @@ sp_text_set_transform (SPItem *item, Geom::Matrix const &xform)
     text->_adjustFontsizeRecursive (item, ex);
 
     // Adjust stroke width
-    sp_item_adjust_stroke_width_recursive (item, ex);
+    item->adjust_stroke_width_recursive (ex);
 
     // Adjust pattern fill
-    sp_item_adjust_pattern(item, xform * ret.inverse());
+    item->adjust_pattern(xform * ret.inverse());
 
     // Adjust gradient fill
-    sp_item_adjust_gradient(item, xform * ret.inverse());
+    item->adjust_gradient(xform * ret.inverse());
 
     item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
 
@@ -492,13 +511,13 @@ sp_text_print (SPItem *item, SPPrintContext *ctx)
     NRRect     pbox, dbox, bbox;
     SPText *group = SP_TEXT (item);
 
-    sp_item_invoke_bbox(item, &pbox, NR::identity(), TRUE);
-    sp_item_bbox_desktop (item, &bbox);
+    item->invoke_bbox( &pbox, Geom::identity(), TRUE);
+    item->getBboxDesktop (&bbox);
     dbox.x0 = 0.0;
     dbox.y0 = 0.0;
-    dbox.x1 = sp_document_width (SP_OBJECT_DOCUMENT (item));
-    dbox.y1 = sp_document_height (SP_OBJECT_DOCUMENT (item));
-    NR::Matrix const ctm (sp_item_i2d_affine(item));
+    dbox.x1 = SP_OBJECT_DOCUMENT (item)->getWidth ();
+    dbox.y1 = SP_OBJECT_DOCUMENT (item)->getHeight ();
+    Geom::Matrix const ctm (item->i2d_affine());
 
     group->layout.print(ctx,&pbox,&dbox,&bbox,ctm);
 }
@@ -518,6 +537,8 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio
     }
     else if (SP_IS_TSPAN(root)) {
         SPTSpan *tspan = SP_TSPAN(root);
+        // x, y attributes are stripped from some tspans marked with role="line" as we do our own line layout.
+        // This should be checked carefully, as it can undo line layout in imported SVG files.
         bool use_xy = !in_textpath && (tspan->role == SP_TSPAN_ROLE_UNSPECIFIED || !tspan->attributes.singleXYCoordinates());
         tspan->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, use_xy, true);
     }
@@ -538,14 +559,16 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio
     if (SP_IS_TSPAN(root))
         if (SP_TSPAN(root)->role != SP_TSPAN_ROLE_UNSPECIFIED) {
             // we need to allow the first line not to have role=line, but still set the source_cookie to the right value
-            SPObject *prev_object = SP_OBJECT_PREV(root);
+            SPObject *prev_object = root->getPrev();
             if (prev_object && SP_IS_TSPAN(prev_object)) {
-                if (!layout.inputExists())
+                if (!layout.inputExists()) {
                     layout.appendText("", prev_object->style, prev_object, &optional_attrs);
+                }
                 layout.appendControlCode(Inkscape::Text::Layout::PARAGRAPH_BREAK, prev_object);
             }
-            if (!root->hasChildren())
+            if (!root->hasChildren()) {
                 layout.appendText("", root->style, root, &optional_attrs);
+            }
             length++;     // interpreting line breaks as a character for the purposes of x/y/etc attributes
                           // is a liberal interpretation of the svg spec, but a strict reading would mean
                           // that if the first line is empty the second line would take its place at the
@@ -553,12 +576,12 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio
             child_attrs_offset--;
         }
 
-    for (SPObject *child = sp_object_first_child(root) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+    for (SPObject *child = root->firstChild() ; child ; child = child->getNext() ) {
         if (SP_IS_STRING(child)) {
             Glib::ustring const &string = SP_STRING(child)->string;
             layout.appendText(string, root->style, child, &optional_attrs, child_attrs_offset + length);
             length += string.length();
-        } else if (!sp_repr_is_meta_element(child->repr)) {
+        } /*XML Tree being directly used here while it shouldn't be.*/ else if (!sp_repr_is_meta_element(child->getRepr())) {
             length += _buildLayoutInput(child, optional_attrs, child_attrs_offset + length, in_textpath);
         }
     }
@@ -572,7 +595,7 @@ void SPText::rebuildLayout()
     Inkscape::Text::Layout::OptionalTextTagAttrs optional_attrs;
     _buildLayoutInput(this, optional_attrs, 0, false);
     layout.calculateFlow();
-    for (SPObject *child = firstChild() ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+    for (SPObject *child = firstChild() ; child ; child = child->getNext() ) {
         if (SP_IS_TEXTPATH(child)) {
             SPTextPath const *textpath = SP_TEXTPATH(child);
             if (textpath->originalPath != NULL) {
@@ -584,14 +607,16 @@ void SPText::rebuildLayout()
     //g_print(layout.dumpAsText().c_str());
 
     // set the x,y attributes on role:line spans
-    for (SPObject *child = firstChild() ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
-        if (!SP_IS_TSPAN(child)) continue;
-        SPTSpan *tspan = SP_TSPAN(child);
-        if (tspan->role == SP_TSPAN_ROLE_UNSPECIFIED) continue;
-        if (!tspan->attributes.singleXYCoordinates()) continue;
-        Inkscape::Text::Layout::iterator iter = layout.sourceToIterator(tspan);
-        NR::Point anchor_point = layout.chunkAnchorPoint(iter);
-        tspan->attributes.setFirstXY(anchor_point);
+    for (SPObject *child = firstChild() ; child ; child = child->getNext() ) {
+        if (SP_IS_TSPAN(child)) {
+            SPTSpan *tspan = SP_TSPAN(child);
+            if ( (tspan->role != SP_TSPAN_ROLE_UNSPECIFIED)
+                 && tspan->attributes.singleXYCoordinates() ) {
+                Inkscape::Text::Layout::iterator iter = layout.sourceToIterator(tspan);
+                Geom::Point anchor_point = layout.chunkAnchorPoint(iter);
+                tspan->attributes.setFirstXY(anchor_point);
+            }
+        }
     }
 }
 
@@ -603,8 +628,8 @@ void SPText::_adjustFontsizeRecursive(SPItem *item, double ex, bool is_root)
     if (style && !NR_DF_TEST_CLOSE (ex, 1.0, NR_EPSILON)) {
         if (!style->font_size.set && is_root) {
             style->font_size.set = 1;
-            style->font_size.type = SP_FONT_SIZE_LENGTH;
         }
+        style->font_size.type = SP_FONT_SIZE_LENGTH;
         style->font_size.computed *= ex;
         style->letter_spacing.computed *= ex;
         style->word_spacing.computed *= ex;
@@ -617,7 +642,7 @@ void SPText::_adjustFontsizeRecursive(SPItem *item, double ex, bool is_root)
     }
 }
 
-void SPText::_adjustCoordsRecursive(SPItem *item, NR::Matrix const &m, double ex, bool is_root)
+void SPText::_adjustCoordsRecursive(SPItem *item, Geom::Matrix const &m, double ex, bool is_root)
 {
     if (SP_IS_TSPAN(item))
         SP_TSPAN(item)->attributes.transform(m, ex, ex, is_root);
@@ -718,17 +743,17 @@ bool TextTagAttributes::anyAttributesSet() const
     return !attributes.x.empty() || !attributes.y.empty() || !attributes.dx.empty() || !attributes.dy.empty() || !attributes.rotate.empty();
 }
 
-NR::Point TextTagAttributes::firstXY() const
+Geom::Point TextTagAttributes::firstXY() const
 {
-    NR::Point point;
-    if (attributes.x.empty()) point[NR::X] = 0.0;
-    else point[NR::X] = attributes.x[0].computed;
-    if (attributes.y.empty()) point[NR::Y] = 0.0;
-    else point[NR::Y] = attributes.y[0].computed;
+    Geom::Point point;
+    if (attributes.x.empty()) point[Geom::X] = 0.0;
+    else point[Geom::X] = attributes.x[0].computed;
+    if (attributes.y.empty()) point[Geom::Y] = 0.0;
+    else point[Geom::Y] = attributes.y[0].computed;
     return point;
 }
 
-void TextTagAttributes::setFirstXY(NR::Point &point)
+void TextTagAttributes::setFirstXY(Geom::Point &point)
 {
     SVGLength zero_length;
     zero_length = 0.0;
@@ -737,8 +762,8 @@ void TextTagAttributes::setFirstXY(NR::Point &point)
         attributes.x.resize(1, zero_length);
     if (attributes.y.empty())
         attributes.y.resize(1, zero_length);
-    attributes.x[0].computed = point[NR::X];
-    attributes.y[0].computed = point[NR::Y];
+    attributes.x[0].computed = point[Geom::X];
+    attributes.y[0].computed = point[Geom::Y];
 }
 
 void TextTagAttributes::mergeInto(Inkscape::Text::Layout::OptionalTextTagAttrs *output, Inkscape::Text::Layout::OptionalTextTagAttrs const &parent_attrs, unsigned parent_attrs_offset, bool copy_xy, bool copy_dxdyrotate) const
@@ -878,7 +903,7 @@ void TextTagAttributes::joinSingleAttribute(std::vector<SVGLength> *dest_vector,
     }
 }
 
-void TextTagAttributes::transform(NR::Matrix const &matrix, double scale_x, double scale_y, bool extend_zero_length)
+void TextTagAttributes::transform(Geom::Matrix const &matrix, double scale_x, double scale_y, bool extend_zero_length)
 {
     SVGLength zero_length;
     zero_length = 0.0;
@@ -891,23 +916,23 @@ void TextTagAttributes::transform(NR::Matrix const &matrix, double scale_x, doub
     if (extend_zero_length && points_count < 1)
         points_count = 1;
     for (unsigned i = 0 ; i < points_count ; i++) {
-        NR::Point point;
-        if (i < attributes.x.size()) point[NR::X] = attributes.x[i].computed;
-        else point[NR::X] = 0.0;
-        if (i < attributes.y.size()) point[NR::Y] = attributes.y[i].computed;
-        else point[NR::Y] = 0.0;
+        Geom::Point point;
+        if (i < attributes.x.size()) point[Geom::X] = attributes.x[i].computed;
+        else point[Geom::X] = 0.0;
+        if (i < attributes.y.size()) point[Geom::Y] = attributes.y[i].computed;
+        else point[Geom::Y] = 0.0;
         point *= matrix;
         if (i < attributes.x.size())
-            attributes.x[i] = point[NR::X];
-        else if (point[NR::X] != 0.0 && extend_zero_length) {
+            attributes.x[i] = point[Geom::X];
+        else if (point[Geom::X] != 0.0 && extend_zero_length) {
             attributes.x.resize(i + 1, zero_length);
-            attributes.x[i] = point[NR::X];
+            attributes.x[i] = point[Geom::X];
         }
         if (i < attributes.y.size())
-            attributes.y[i] = point[NR::Y];
-        else if (point[NR::Y] != 0.0 && extend_zero_length) {
+            attributes.y[i] = point[Geom::Y];
+        else if (point[Geom::Y] != 0.0 && extend_zero_length) {
             attributes.y.resize(i + 1, zero_length);
-            attributes.y[i] = point[NR::Y];
+            attributes.y[i] = point[Geom::Y];
         }
     }
     for (std::vector<SVGLength>::iterator it = attributes.dx.begin() ; it != attributes.dx.end() ; it++)
@@ -916,36 +941,108 @@ void TextTagAttributes::transform(NR::Matrix const &matrix, double scale_x, doub
         *it = it->computed * scale_y;
 }
 
-void TextTagAttributes::addToDxDy(unsigned index, NR::Point const &adjust)
+double TextTagAttributes::getDx(unsigned index)
+{
+    if( attributes.dx.size() == 0 ) {
+        return 0.0;
+    }
+    if( index < attributes.dx.size() ) {
+        return attributes.dx[index].computed;
+    } else {
+        return 0.0; // attributes.dx.back().computed;
+    }
+}
+
+
+double TextTagAttributes::getDy(unsigned index)
+{
+    if( attributes.dy.size() == 0 ) {
+        return 0.0;
+    }
+    if( index < attributes.dy.size() ) {
+        return attributes.dy[index].computed;
+    } else {
+        return 0.0; // attributes.dy.back().computed;
+    }
+}
+
+
+void TextTagAttributes::addToDx(unsigned index, double delta)
 {
     SVGLength zero_length;
     zero_length = 0.0;
 
-    if (adjust[NR::X] != 0.0) {
+    if (attributes.dx.size() < index + 1) attributes.dx.resize(index + 1, zero_length);
+    attributes.dx[index] = attributes.dx[index].computed + delta;
+}
+
+void TextTagAttributes::addToDy(unsigned index, double delta)
+{
+    SVGLength zero_length;
+    zero_length = 0.0;
+
+    if (attributes.dy.size() < index + 1) attributes.dy.resize(index + 1, zero_length);
+    attributes.dy[index] = attributes.dy[index].computed + delta;
+}
+
+void TextTagAttributes::addToDxDy(unsigned index, Geom::Point const &adjust)
+{
+    SVGLength zero_length;
+    zero_length = 0.0;
+
+    if (adjust[Geom::X] != 0.0) {
         if (attributes.dx.size() < index + 1) attributes.dx.resize(index + 1, zero_length);
-        attributes.dx[index] = attributes.dx[index].computed + adjust[NR::X];
+        attributes.dx[index] = attributes.dx[index].computed + adjust[Geom::X];
     }
-    if (adjust[NR::Y] != 0.0) {
+    if (adjust[Geom::Y] != 0.0) {
         if (attributes.dy.size() < index + 1) attributes.dy.resize(index + 1, zero_length);
-        attributes.dy[index] = attributes.dy[index].computed + adjust[NR::Y];
+        attributes.dy[index] = attributes.dy[index].computed + adjust[Geom::Y];
     }
 }
 
+double TextTagAttributes::getRotate(unsigned index)
+{
+    if( attributes.rotate.size() == 0 ) {
+        return 0.0;
+    }
+    if( index < attributes.rotate.size() ) {
+        return attributes.rotate[index].computed;
+    } else {
+        return attributes.rotate.back().computed;
+    }
+}
+
+
 void TextTagAttributes::addToRotate(unsigned index, double delta)
 {
     SVGLength zero_length;
     zero_length = 0.0;
 
-    if (attributes.rotate.size() < index + 1) {
+    if (attributes.rotate.size() < index + 2) {
         if (attributes.rotate.empty())
-            attributes.rotate.resize(index + 1, zero_length);
+            attributes.rotate.resize(index + 2, zero_length);
         else
-            attributes.rotate.resize(index + 1, attributes.rotate.back());
+            attributes.rotate.resize(index + 2, attributes.rotate.back());
     }
     attributes.rotate[index] = mod360(attributes.rotate[index].computed + delta);
 }
 
 
+void TextTagAttributes::setRotate(unsigned index, double angle)
+{
+    SVGLength zero_length;
+    zero_length = 0.0;
+
+    if (attributes.rotate.size() < index + 2) {
+        if (attributes.rotate.empty())
+            attributes.rotate.resize(index + 2, zero_length);
+        else
+            attributes.rotate.resize(index + 2, attributes.rotate.back());
+    }
+    attributes.rotate[index] = mod360(angle);
+}
+
+
 /*
   Local Variables:
   mode:c++
@@ -955,4 +1052,4 @@ void TextTagAttributes::addToRotate(unsigned index, double delta)
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :