Code

Fix ef spam when adjusting pattern on text - patch from Adonis Papaderos
[inkscape.git] / src / sp-text.cpp
index 423922b80c991a11207973b3ab800b1185a18ee3..4b896db9cd980ad8d90d8f6a4408bb1e2165b618 100644 (file)
@@ -74,7 +74,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, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
+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);
 
@@ -421,14 +421,20 @@ 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, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const */*snapprefs*/)
+static void sp_text_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const */*snapprefs*/)
 {
     // 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)
@@ -436,8 +442,7 @@ static void sp_text_snappoints(SPItem const *item, bool const target, SnapPoints
     if (layout != NULL && layout->outputExists()) {
         boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
         if (pt) {
-            int type = target ? int(Inkscape::SNAPTARGET_TEXT_BASELINE) : int(Inkscape::SNAPSOURCE_TEXT_BASELINE);
-            p.push_back(std::make_pair((*pt) * sp_item_i2d_affine(item), type));
+            p.push_back(Inkscape::SnapCandidatePoint((*pt) * sp_item_i2d_affine(item), Inkscape::SNAPSOURCE_TEXT_BASELINE, Inkscape::SNAPTARGET_TEXT_BASELINE));
         }
     }
 }
@@ -523,6 +528,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);
     }
@@ -921,6 +928,50 @@ void TextTagAttributes::transform(Geom::Matrix const &matrix, double scale_x, do
         *it = it->computed * scale_y;
 }
 
+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 (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;
@@ -936,6 +987,19 @@ void TextTagAttributes::addToDxDy(unsigned index, Geom::Point const &adjust)
     }
 }
 
+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;
@@ -951,6 +1015,21 @@ void TextTagAttributes::addToRotate(unsigned index, double 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++
@@ -960,4 +1039,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 :