Code

Committed double code because of the hurry to let you use the axonom-snapping stuff.
[inkscape.git] / src / sp-flowtext.cpp
index 4c46a699c9df9937e2e0b22d5a146ef2047401f7..614e0b45092eb7b3236e5156a76ce3e2769550ce 100644 (file)
@@ -311,6 +311,21 @@ sp_flowtext_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform,
 {
     SPFlowtext *group = SP_FLOWTEXT(item);
     group->layout.getBoundingBox(bbox, transform);
+
+    // Add stroke width
+    SPStyle* style=SP_OBJECT_STYLE (item);
+    if (style->stroke.type != SP_PAINT_TYPE_NONE) {
+        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);
+            if ( fabs(bbox->x1 - bbox->x0) > -0.00001 && fabs(bbox->y1 - bbox->y0) > -0.00001 ) {
+                bbox->x0-=0.5*width;
+                bbox->x1+=0.5*width;
+                bbox->y0-=0.5*width;
+                bbox->y1+=0.5*width;
+            }
+        }
+    }
 }
 
 static void
@@ -338,9 +353,9 @@ 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(_("<b>Flowed text</b> (%d characters)"), nChars);
+        return g_strdup_printf(ngettext("<b>Flowed text</b> (%d character)", "<b>Flowed text</b> (%d characters)", nChars), nChars);
     else
-        return g_strdup_printf(_("<b>Linked flowed text</b> (%d characters)"), nChars);
+        return g_strdup_printf(ngettext("<b>Linked flowed text</b> (%d character)", "<b>Linked flowed text</b> (%d characters)", nChars), nChars);
 }
 
 static NRArenaItem *
@@ -487,7 +502,7 @@ void SPFlowtext::_clearFlow(NRArenaGroup *in_arena)
 void SPFlowtext::convert_to_text()
 {
     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
-    Inkscape::Selection *selection = SP_DT_SELECTION(desktop);
+    Inkscape::Selection *selection = sp_desktop_selection(desktop);
     SPItem *item = selection->singleItem();
     if (!SP_IS_FLOWTEXT(item)) return;
 
@@ -543,9 +558,11 @@ void SPFlowtext::convert_to_text()
             if (set_y)
                 sp_repr_set_svg_double(span_tspan, "y", anchor_point[NR::Y]);
 
-            SPObject *source_obj;
+            SPObject *source_obj = 0;
+            void *rawptr = 0;
             Glib::ustring::iterator span_text_start_iter;
-            group->layout.getSourceOfCharacter(it, (void**)&source_obj, &span_text_start_iter);
+            group->layout.getSourceOfCharacter(it, &rawptr, &span_text_start_iter);
+            source_obj = SP_OBJECT (rawptr);
             gchar *style_text = sp_style_write_difference((SP_IS_STRING(source_obj) ? source_obj->parent : source_obj)->style, group->style);
             if (style_text && *style_text) {
                 span_tspan->setAttribute("style", style_text);
@@ -554,9 +571,11 @@ void SPFlowtext::convert_to_text()
 
             if (SP_IS_STRING(source_obj)) {
                 Glib::ustring *string = &SP_STRING(source_obj)->string;
-                SPObject *span_end_obj;
+                SPObject *span_end_obj = 0;
+                void *rawptr = 0;
                 Glib::ustring::iterator span_text_end_iter;
-                group->layout.getSourceOfCharacter(it_span_end, (void**)&span_end_obj, &span_text_end_iter);
+                group->layout.getSourceOfCharacter(it_span_end, &rawptr, &span_text_end_iter);
+                span_end_obj = SP_OBJECT(rawptr);
                 if (span_end_obj != source_obj) {
                     if (it_span_end == group->layout.end()) {
                         span_text_end_iter = span_text_start_iter;
@@ -586,7 +605,7 @@ void SPFlowtext::convert_to_text()
 
     Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
     parent->appendChild(repr);
-    SPItem *new_item = (SPItem *) SP_DT_DOCUMENT(desktop)->getObjectByRepr(repr);
+    SPItem *new_item = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr);
     sp_item_write_transform(new_item, repr, item->transform);
     SP_OBJECT(new_item)->updateRepr();
 
@@ -594,7 +613,8 @@ void SPFlowtext::convert_to_text()
     selection->set(new_item);
     item->deleteObject();
 
-    sp_document_done(SP_DT_DOCUMENT(desktop));
+    sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, 
+                     _("Convert flowed text to text"));
 }
 
 SPItem *SPFlowtext::get_frame(SPItem *after)
@@ -645,7 +665,7 @@ bool SPFlowtext::has_internal_frame()
 
 SPItem *create_flowtext_with_internal_frame (SPDesktop *desktop, NR::Point p0, NR::Point p1)
 {
-    SPDocument *doc = SP_DT_DOCUMENT (desktop);
+    SPDocument *doc = sp_desktop_document (desktop);
 
     Inkscape::XML::Node *root_repr = sp_repr_new("svg:flowRoot");
     root_repr->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create