Code

Line-end fix
[inkscape.git] / src / sp-text.cpp
index 3bbb3b89263d55e0fcc91c14c4d3eccda0bb7c39..810df25307da1ddc6ba06cb249e62ab7cee6baa6 100644 (file)
@@ -46,6 +46,7 @@
 #include "mod360.h"
 
 #include "sp-textpath.h"
+#include "sp-tref.h"
 #include "sp-tspan.h"
 
 #include "text-editing.h"
@@ -193,7 +194,7 @@ sp_text_child_added (SPObject *object, Inkscape::XML::Node *rch, Inkscape::XML::
     if (((SPObjectClass *) text_parent_class)->child_added)
         ((SPObjectClass *) text_parent_class)->child_added (object, rch, ref);
 
-    text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG);
+    text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
 }
 
 static void
@@ -248,6 +249,7 @@ sp_text_update (SPObject *object, SPCtx *ctx, guint flags)
         sp_item_invoke_bbox(text, &paintbox, NR::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));
             // pass the bbox of the text object as paintbox (used for paintserver fills)
             text->layout.show(NR_ARENA_GROUP(v->arenaitem), &paintbox);
         }
@@ -263,6 +265,21 @@ sp_text_modified (SPObject *object, guint flags)
     guint cflags = (flags & SP_OBJECT_MODIFIED_CASCADE);
     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
+    // text object. Therefore we do here the same as in _update, that is, destroy all arena items
+    // and create new ones. This is probably quite wasteful.
+    if (flags & ( SP_OBJECT_STYLE_MODIFIED_FLAG )) {
+        SPText *text = SP_TEXT (object);
+        NRRect paintbox;
+        sp_item_invoke_bbox(text, &paintbox, NR::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));
+            text->layout.show(NR_ARENA_GROUP(v->arenaitem), &paintbox);
+        }
+    }
+
     /* Create temporary list of children */
     GSList *l = NULL;
     SPObject *child;
@@ -287,13 +304,14 @@ sp_text_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
     SPText *text = SP_TEXT (object);
 
     if (flags & SP_OBJECT_WRITE_BUILD) {
+        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
         if (!repr)
-            repr = sp_repr_new ("svg:text");
+            repr = xml_doc->createElement("svg:text");
         GSList *l = NULL;
         for (SPObject *child = sp_object_first_child(object) ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
             Inkscape::XML::Node *crepr = NULL;
             if (SP_IS_STRING(child)) {
-                crepr = sp_repr_new_text(SP_STRING(child)->string.c_str());
+                crepr = xml_doc->createTextNode(SP_STRING(child)->string.c_str());
             } else {
                 crepr = child->updateRepr(NULL, flags);
             }
@@ -338,7 +356,7 @@ sp_text_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsi
 
     // Add stroke width
     SPStyle* style=SP_OBJECT_STYLE (item);
-    if (style->stroke.type != SP_PAINT_TYPE_NONE) {
+    if (!style->stroke.isNone()) {
         double const scale = expansion(transform);
         if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
             double const width = MAX(0.125, style->stroke_width.computed * scale);
@@ -361,6 +379,8 @@ sp_text_show(SPItem *item, NRArena *arena, unsigned /* key*/, unsigned /*flags*/
     NRArenaGroup *flowed = NRArenaGroup::create(arena);
     nr_arena_group_set_transparent (flowed, FALSE);
 
+    nr_arena_group_set_style(flowed, group->style);
+
     // pass the bbox of the text object as paintbox (used for paintserver fills)
     NRRect paintbox;
     sp_item_invoke_bbox(item, &paintbox, NR::identity(), TRUE);
@@ -382,8 +402,8 @@ sp_text_description(SPItem *item)
     SPText *text = (SPText *) item;
     SPStyle *style = SP_OBJECT_STYLE(text);
 
-    font_instance *tf = (font_factory::Default())->Face(style->text->font_family.value,
-                                                        font_style_to_pos(*style));
+    font_instance *tf = font_factory::Default()->FaceFromStyle(style);
+    
     char name_buf[256];
     char *n;
     if (tf) {
@@ -395,7 +415,7 @@ sp_text_description(SPItem *item)
         n = g_strdup(_("<no name found>"));
     }
 
-    GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP)->getDefaultMetric());
+    GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric());
 
     char *ret = ( SP_IS_TEXT_TEXTPATH(item)
                   ? g_strdup_printf(_("<b>Text on path</b> (%s, %s)"), n, xs->str)
@@ -497,6 +517,9 @@ unsigned SPText::_buildLayoutInput(SPObject *root, Inkscape::Text::Layout::Optio
         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);
     }
+    else if (SP_IS_TREF(root)) {
+        SP_TREF(root)->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, true, true);
+    }
     else if (SP_IS_TEXTPATH(root)) {
         in_textpath = true;
         SP_TEXTPATH(root)->attributes.mergeInto(&optional_attrs, parent_optional_attrs, parent_attrs_offset, false, true);
@@ -564,8 +587,7 @@ void SPText::rebuildLayout()
         if (!tspan->attributes.singleXYCoordinates()) continue;
         Inkscape::Text::Layout::iterator iter = layout.sourceToIterator(tspan);
         NR::Point anchor_point = layout.chunkAnchorPoint(iter);
-        sp_repr_set_svg_double(SP_OBJECT_REPR(tspan), "x", anchor_point[NR::X]);
-        sp_repr_set_svg_double(SP_OBJECT_REPR(tspan), "y", anchor_point[NR::Y]);
+        tspan->attributes.setFirstXY(anchor_point);
     }
 }
 
@@ -600,6 +622,9 @@ void SPText::_adjustCoordsRecursive(SPItem *item, NR::Matrix const &m, double ex
         SP_TEXT(item)->attributes.transform(m, ex, ex, is_root);
     else if (SP_IS_TEXTPATH(item))
         SP_TEXTPATH(item)->attributes.transform(m, ex, ex, is_root);
+    else if (SP_IS_TREF(item)) {
+        SP_TREF(item)->attributes.transform(m, ex, ex, is_root);
+    }
 
     for (SPObject *o = item->children; o != NULL; o = o->next) {
         if (SP_IS_ITEM(o))
@@ -699,6 +724,19 @@ NR::Point TextTagAttributes::firstXY() const
     return point;
 }
 
+void TextTagAttributes::setFirstXY(NR::Point &point)
+{
+    SVGLength zero_length;
+    zero_length = 0.0;
+
+    if (attributes.x.empty())
+        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];
+}
+
 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
 {
     mergeSingleAttribute(&output->x,      parent_attrs.x,      parent_attrs_offset, copy_xy ? &attributes.x : NULL);
@@ -710,11 +748,14 @@ void TextTagAttributes::mergeInto(Inkscape::Text::Layout::OptionalTextTagAttrs *
 
 void TextTagAttributes::mergeSingleAttribute(std::vector<SVGLength> *output_list, std::vector<SVGLength> const &parent_list, unsigned parent_offset, std::vector<SVGLength> const *overlay_list)
 {
+    output_list->clear();
     if (overlay_list == NULL) {
-        output_list->resize(std::max(0, (int)parent_list.size() - (int)parent_offset));
-        std::copy(parent_list.begin() + parent_offset, parent_list.end(), output_list->begin());
+        if (parent_list.size() > parent_offset)
+        {
+            output_list->reserve(parent_list.size() - parent_offset);
+            std::copy(parent_list.begin() + parent_offset, parent_list.end(), std::back_inserter(*output_list));
+        }
     } else {
-        output_list->clear();
         output_list->reserve(std::max((int)parent_list.size() - (int)parent_offset, (int)overlay_list->size()));
         unsigned overlay_offset = 0;
         while (parent_offset < parent_list.size() || overlay_offset < overlay_list->size()) {