Code

Fix ef spam when adjusting pattern on text - patch from Adonis Papaderos
[inkscape.git] / src / sp-flowtext.cpp
index ff4a2fda54cedeae9a19d952a1db59a13674d1ab..b01146d60a3797408a608e4f7f058e717e0aa9fc 100644 (file)
@@ -27,7 +27,7 @@
 #include "sp-rect.h"
 #include "text-tag-attributes.h"
 #include "text-chemistry.h"
-
+#include "text-editing.h"
 
 #include "livarot/Shape.h"
 
@@ -43,12 +43,13 @@ static void sp_flowtext_remove_child(SPObject *object, Inkscape::XML::Node *chil
 static void sp_flowtext_update(SPObject *object, SPCtx *ctx, guint flags);
 static void sp_flowtext_modified(SPObject *object, guint flags);
 static Inkscape::XML::Node *sp_flowtext_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
-static void sp_flowtext_build(SPObject *object, Document *document, Inkscape::XML::Node *repr);
+static void sp_flowtext_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
 static void sp_flowtext_set(SPObject *object, unsigned key, gchar const *value);
 
 static void sp_flowtext_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &transform, unsigned const flags);
 static void sp_flowtext_print(SPItem *item, SPPrintContext *ctx);
 static gchar *sp_flowtext_description(SPItem *item);
+static void sp_flowtext_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
 static NRArenaItem *sp_flowtext_show(SPItem *item, NRArena *arena, unsigned key, unsigned flags);
 static void sp_flowtext_hide(SPItem *item, unsigned key);
 
@@ -98,6 +99,7 @@ sp_flowtext_class_init(SPFlowtextClass *klass)
     item_class->bbox = sp_flowtext_bbox;
     item_class->print = sp_flowtext_print;
     item_class->description = sp_flowtext_description;
+    item_class->snappoints = sp_flowtext_snappoints;
     item_class->show = sp_flowtext_show;
     item_class->hide = sp_flowtext_hide;
 }
@@ -220,7 +222,7 @@ sp_flowtext_modified(SPObject *object, guint flags)
 }
 
 static void
-sp_flowtext_build(SPObject *object, Document *document, Inkscape::XML::Node *repr)
+sp_flowtext_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
 {
     object->_requireSVGVersion(Inkscape::Version(1, 2));
 
@@ -372,10 +374,27 @@ static gchar *sp_flowtext_description(SPItem *item)
 {
     Inkscape::Text::Layout const &layout = SP_FLOWTEXT(item)->layout;
     int const nChars = layout.iteratorToCharIndex(layout.end());
-    if (SP_FLOWTEXT(item)->has_internal_frame())
-        return g_strdup_printf(ngettext("<b>Flowed text</b> (%d character)", "<b>Flowed text</b> (%d characters)", nChars), nChars);
-    else
-        return g_strdup_printf(ngettext("<b>Linked flowed text</b> (%d character)", "<b>Linked flowed text</b> (%d characters)", nChars), nChars);
+
+    char const *trunc = (layout.inputTruncated()) ? _(" [truncated]") : "";
+
+    if (SP_FLOWTEXT(item)->has_internal_frame()) {
+        return g_strdup_printf(ngettext("<b>Flowed text</b> (%d character%s)", "<b>Flowed text</b> (%d characters%s)", nChars), nChars, trunc);
+    } else {
+        return g_strdup_printf(ngettext("<b>Linked flowed text</b> (%d character%s)", "<b>Linked flowed text</b> (%d characters%s)", nChars), nChars, trunc);
+    }
+}
+
+static void sp_flowtext_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)
+    Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item);
+    if (layout != NULL && layout->outputExists()) {
+        boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+        if (pt) {
+            p.push_back(Inkscape::SnapCandidatePoint((*pt) * sp_item_i2d_affine(item), Inkscape::SNAPSOURCE_TEXT_BASELINE, Inkscape::SNAPTARGET_TEXT_BASELINE));
+        }
+    }
 }
 
 static NRArenaItem *
@@ -677,7 +696,7 @@ bool SPFlowtext::has_internal_frame()
 
 SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, Geom::Point p0, Geom::Point p1)
 {
-    Document *doc = sp_desktop_document (desktop);
+    SPDocument *doc = sp_desktop_document (desktop);
 
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
     Inkscape::XML::Node *root_repr = xml_doc->createElement("svg:flowRoot");