X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ftext-chemistry.cpp;h=f2ea4367b9acd5ee27de6f2893d27e34d4dd3b56;hb=941ff7c62ac6b94d08e349025428ca1b2e0b6f3a;hp=4853258596d82d74c539e119585d06b964a0f728;hpb=7333a6d3d0e1b6b738726a859e5875d5d97b27d9;p=inkscape.git diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index 485325859..f2ea4367b 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -1,10 +1,10 @@ -#define __SP_TEXT_CHEMISTRY_C__ - /* * Text commands * * Authors: * bulia byak + * Jon A. Cruz + * Abhishek Sharma * * Copyright (C) 2004 authors * @@ -14,9 +14,13 @@ #ifdef HAVE_CONFIG_H # include #endif + +#include +#include +#include + #include "libnr/nr-matrix-fns.h" #include "xml/repr.h" -#include #include "sp-rect.h" #include "sp-textpath.h" #include "inkscape.h" @@ -31,7 +35,9 @@ #include "sp-flowtext.h" #include "sp-flowregion.h" #include "sp-flowdiv.h" +#include "sp-tspan.h" +using Inkscape::DocumentUndo; SPItem * text_in_selection(Inkscape::Selection *selection) @@ -93,7 +99,7 @@ text_put_on_path() SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc()); + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) { sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select a text and a path to put text on path.")); @@ -128,13 +134,13 @@ text_put_on_path() parent->appendChild(repr); SPItem *new_item = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr); - sp_item_write_transform(new_item, repr, text->transform); + new_item->doWriteTransform(repr, text->transform); SP_OBJECT(new_item)->updateRepr(); Inkscape::GC::release(repr); text->deleteObject(); // delete the orignal flowtext - sp_document_ensure_up_to_date(sp_desktop_document(desktop)); + sp_desktop_document(desktop)->ensureUpToDate(); selection->clear(); @@ -183,8 +189,8 @@ text_put_on_path() SP_OBJECT_REPR(text)->setAttribute("x", NULL); SP_OBJECT_REPR(text)->setAttribute("y", NULL); - sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Put text on path")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + _("Put text on path")); g_slist_free(text_reprs); } @@ -210,7 +216,7 @@ text_remove_from_path() continue; } - SPObject *tp = sp_object_first_child(SP_OBJECT(items->data)); + SPObject *tp = SP_OBJECT(items->data)->firstChild(); did = true; @@ -220,9 +226,9 @@ text_remove_from_path() if (!did) { sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("No texts-on-paths in the selection.")); } else { + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + _("Remove text from path")); selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description - sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Remove text from path")); } } @@ -233,7 +239,21 @@ text_remove_all_kerns_recursively(SPObject *o) SP_OBJECT_REPR(o)->setAttribute("dy", NULL); SP_OBJECT_REPR(o)->setAttribute("rotate", NULL); - for (SPObject *i = sp_object_first_child(o); i != NULL; i = SP_OBJECT_NEXT(i)) { + // if x contains a list, leave only the first value + gchar *x = (gchar *) SP_OBJECT_REPR(o)->attribute("x"); + if (x) { + gchar **xa_space = g_strsplit(x, " ", 0); + gchar **xa_comma = g_strsplit(x, ",", 0); + if (xa_space && *xa_space && *(xa_space + 1)) { + SP_OBJECT_REPR(o)->setAttribute("x", g_strdup(*xa_space)); + } else if (xa_comma && *xa_comma && *(xa_comma + 1)) { + SP_OBJECT_REPR(o)->setAttribute("x", g_strdup(*xa_comma)); + } + g_strfreev(xa_space); + g_strfreev(xa_comma); + } + + for (SPObject *i = o->firstChild(); i != NULL; i = i->getNext()) { text_remove_all_kerns_recursively(i); } } @@ -256,21 +276,22 @@ text_remove_all_kerns() for (GSList *items = g_slist_copy((GSList *) selection->itemList()); items != NULL; items = items->next) { + SPObject *obj = SP_OBJECT(items->data); - if (!SP_IS_TEXT(SP_OBJECT(items->data))) { + if (!SP_IS_TEXT(obj) && !SP_IS_TSPAN(obj) && !SP_IS_FLOWTEXT(obj)) { continue; } - text_remove_all_kerns_recursively(SP_OBJECT(items->data)); - SP_OBJECT(items->data)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG); + text_remove_all_kerns_recursively(obj); + obj->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG); did = true; } if (!did) { sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("Select text(s) to remove kerns from.")); } else { - sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, - _("Remove manual kerns")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT, + _("Remove manual kerns")); } } @@ -282,7 +303,7 @@ text_flow_into_shape() return; SPDocument *doc = sp_desktop_document (desktop); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -357,8 +378,8 @@ text_flow_into_shape() SP_OBJECT(text)->deleteObject (true); - sp_document_done(doc, SP_VERB_CONTEXT_TEXT, - _("Flow text into shape")); + DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT, + _("Flow text into shape")); sp_desktop_selection(desktop)->set(SP_ITEM(root_object)); @@ -374,7 +395,7 @@ text_unflow () return; SPDocument *doc = sp_desktop_document (desktop); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -397,6 +418,10 @@ text_unflow () SPItem *flowtext = SP_ITEM(items->data); + // we discard transform when unflowing, but we must preserve expansion which is visible as + // font size multiplier + double ex = (flowtext->transform).descrim(); + if (sp_te_get_string_multiline(flowtext) == NULL) { // flowtext is empty continue; } @@ -409,11 +434,11 @@ text_unflow () rtext->setAttribute("style", SP_OBJECT_REPR(flowtext)->attribute("style")); // fixme: transfer style attrs too; and from descendants NRRect bbox; - sp_item_invoke_bbox(SP_ITEM(flowtext), &bbox, sp_item_i2doc_affine(SP_ITEM(flowtext)), TRUE); - NR::Point xy(bbox.x0, bbox.y0); - if (xy[NR::X] != 1e18 && xy[NR::Y] != 1e18) { - sp_repr_set_svg_double(rtext, "x", xy[NR::X]); - sp_repr_set_svg_double(rtext, "y", xy[NR::Y]); + SP_ITEM(flowtext)->invoke_bbox( &bbox, SP_ITEM(flowtext)->i2doc_affine(), TRUE); + Geom::Point xy(bbox.x0, bbox.y0); + if (xy[Geom::X] != 1e18 && xy[Geom::Y] != 1e18) { + sp_repr_set_svg_double(rtext, "x", xy[Geom::X]); + sp_repr_set_svg_double(rtext, "y", xy[Geom::Y]); } /* Create */ @@ -429,6 +454,9 @@ text_unflow () SP_OBJECT_REPR(SP_OBJECT_PARENT(flowtext))->appendChild(rtext); SPObject *text_object = doc->getObjectByRepr(rtext); + // restore the font size multiplier from the flowtext's transform + SP_TEXT(text_object)->_adjustFontsizeRecursive(SP_ITEM(text_object), ex); + new_objs = g_slist_prepend (new_objs, text_object); old_objs = g_slist_prepend (old_objs, flowtext); @@ -446,8 +474,8 @@ text_unflow () g_slist_free (old_objs); g_slist_free (new_objs); - sp_document_done(doc, SP_VERB_CONTEXT_TEXT, - _("Unflow flowed text")); + DocumentUndo::done(doc, SP_VERB_CONTEXT_TEXT, + _("Unflow flowed text")); } void @@ -488,10 +516,10 @@ flowtext_to_text() did = true; Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent(); - parent->appendChild(repr); + parent->addChild(repr, SP_OBJECT_REPR(item)); SPItem *new_item = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr); - sp_item_write_transform(new_item, repr, item->transform); + new_item->doWriteTransform(repr, item->transform); SP_OBJECT(new_item)->updateRepr(); Inkscape::GC::release(repr); @@ -503,9 +531,9 @@ flowtext_to_text() g_slist_free(items); if (did) { - sp_document_done(sp_desktop_document(desktop), - SP_VERB_OBJECT_FLOWTEXT_TO_TEXT, - _("Convert flowed text to text")); + DocumentUndo::done(sp_desktop_document(desktop), + SP_VERB_OBJECT_FLOWTEXT_TO_TEXT, + _("Convert flowed text to text")); selection->setReprList(reprs); } else { sp_desktop_message_stack(desktop)-> @@ -526,4 +554,4 @@ flowtext_to_text() 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 :