Code

Remove custom color wheel widget in favor of the (relatively) recent GtkHSV. Fixes...
[inkscape.git] / src / sp-flowtext.cpp
index dcaa59ea02d70585d56966a1bae1869bf6f5bc85..b01146d60a3797408a608e4f7f058e717e0aa9fc 100644 (file)
@@ -16,7 +16,6 @@
 #include "selection.h"
 #include "desktop-handles.h"
 #include "desktop.h"
-#include "desktop-affine.h"
 
 #include "xml/repr.h"
 
@@ -28,7 +27,7 @@
 #include "sp-rect.h"
 #include "text-tag-attributes.h"
 #include "text-chemistry.h"
-
+#include "text-editing.h"
 
 #include "livarot/Shape.h"
 
@@ -50,6 +49,7 @@ 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);
 
@@ -99,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;
 }
@@ -352,7 +353,7 @@ sp_flowtext_print(SPItem *item, SPPrintContext *ctx)
     NRRect pbox;
     sp_item_invoke_bbox(item, &pbox, Geom::identity(), TRUE);
     NRRect bbox;
-    boost::optional<Geom::Rect> bbox_maybe = sp_item_bbox_desktop(item);
+    Geom::OptRect bbox_maybe = sp_item_bbox_desktop(item);
     if (!bbox_maybe) {
         return;
     }
@@ -363,7 +364,7 @@ sp_flowtext_print(SPItem *item, SPPrintContext *ctx)
     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));
+    Geom::Matrix const ctm (sp_item_i2d_affine(item));
 
     group->layout.print(ctx, &pbox, &dbox, &bbox, ctm);
 }
@@ -373,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 *
@@ -416,7 +434,7 @@ void SPFlowtext::_buildLayoutInput(SPObject *root, Shape const *exclusion_shape,
     if (SP_IS_FLOWPARA(root)) {
         // emulate par-indent with the first char's kern
         SPObject *t = root;
-        for ( ; t != NULL && !SP_IS_FLOWTEXT(t); t = SP_OBJECT_PARENT(t));
+        for ( ; t != NULL && !SP_IS_FLOWTEXT(t); t = SP_OBJECT_PARENT(t)){};
         if (SP_IS_FLOWTEXT(t)) {
             double indent = SP_FLOWTEXT(t)->par_indent;
             if (indent != 0) {
@@ -533,9 +551,9 @@ SPFlowtext::getAsText()
     Inkscape::XML::Node *repr = xml_doc->createElement("svg:text");
     repr->setAttribute("xml:space", "preserve");
     repr->setAttribute("style", SP_OBJECT_REPR(this)->attribute("style"));
-    NR::Point anchor_point = this->layout.characterAnchorPoint(this->layout.begin());
-    sp_repr_set_svg_double(repr, "x", anchor_point[NR::X]);
-    sp_repr_set_svg_double(repr, "y", anchor_point[NR::Y]);
+    Geom::Point anchor_point = this->layout.characterAnchorPoint(this->layout.begin());
+    sp_repr_set_svg_double(repr, "x", anchor_point[Geom::X]);
+    sp_repr_set_svg_double(repr, "y", anchor_point[Geom::Y]);
 
     for (Inkscape::Text::Layout::iterator it = this->layout.begin() ; it != this->layout.end() ; ) {
         Inkscape::XML::Node *line_tspan = xml_doc->createElement("svg:tspan");
@@ -547,7 +565,7 @@ SPFlowtext::getAsText()
         while (it != it_line_end) {
 
             Inkscape::XML::Node *span_tspan = xml_doc->createElement("svg:tspan");
-            NR::Point anchor_point = this->layout.characterAnchorPoint(it);
+            Geom::Point anchor_point = this->layout.characterAnchorPoint(it);
             // use kerning to simulate justification and whatnot
             Inkscape::Text::Layout::iterator it_span_end = it;
             it_span_end.nextStartOfSpan();
@@ -574,9 +592,13 @@ SPFlowtext::getAsText()
                 attrs.dx[0] = 0.0;
             TextTagAttributes(attrs).writeTo(span_tspan);
             if (set_x)
-                sp_repr_set_svg_double(span_tspan, "x", anchor_point[NR::X]);  // FIXME: this will pick up the wrong end of counter-directional runs
+                sp_repr_set_svg_double(span_tspan, "x", anchor_point[Geom::X]);  // FIXME: this will pick up the wrong end of counter-directional runs
             if (set_y)
-                sp_repr_set_svg_double(span_tspan, "y", anchor_point[NR::Y]);
+                sp_repr_set_svg_double(span_tspan, "y", anchor_point[Geom::Y]);
+            if (line_tspan->childCount() == 0) {
+                sp_repr_set_svg_double(line_tspan, "x", anchor_point[Geom::X]);  // FIXME: this will pick up the wrong end of counter-directional runs
+                sp_repr_set_svg_double(line_tspan, "y", anchor_point[Geom::Y]);
+            }
 
             SPObject *source_obj = 0;
             void *rawptr = 0;
@@ -672,7 +694,7 @@ bool SPFlowtext::has_internal_frame()
 }
 
 
-SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, NR::Point p0, NR::Point p1)
+SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, Geom::Point p0, Geom::Point p1)
 {
     SPDocument *doc = sp_desktop_document (desktop);
 
@@ -693,16 +715,16 @@ SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, NR::Point p0, N
 
     SPObject *rect = doc->getObjectByRepr(rect_repr);
 
-    p0 = sp_desktop_dt2root_xy_point(desktop, p0);
-    p1 = sp_desktop_dt2root_xy_point(desktop, p1);
-    using NR::X;
-    using NR::Y;
-    NR::Coord const x0 = MIN(p0[X], p1[X]);
-    NR::Coord const y0 = MIN(p0[Y], p1[Y]);
-    NR::Coord const x1 = MAX(p0[X], p1[X]);
-    NR::Coord const y1 = MAX(p0[Y], p1[Y]);
-    NR::Coord const w  = x1 - x0;
-    NR::Coord const h  = y1 - y0;
+    p0 *= desktop->dt2doc();
+    p1 *= desktop->dt2doc();
+    using Geom::X;
+    using Geom::Y;
+    Geom::Coord const x0 = MIN(p0[X], p1[X]);
+    Geom::Coord const y0 = MIN(p0[Y], p1[Y]);
+    Geom::Coord const x1 = MAX(p0[X], p1[X]);
+    Geom::Coord const y1 = MAX(p0[Y], p1[Y]);
+    Geom::Coord const w  = x1 - x0;
+    Geom::Coord const h  = y1 - y0;
 
     sp_rect_position_set(SP_RECT(rect), x0, y0, w, h);
     SP_OBJECT(rect)->updateRepr();
@@ -720,6 +742,8 @@ SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, NR::Point p0, N
     Inkscape::GC::release(para_repr);
     Inkscape::GC::release(rect_repr);
 
+    ft_item->transform = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
+
     return ft_item;
 }