diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp
index 0a655fdcb5e3620daeee1e69ff04dba10bc86871..f574b69fb14a6628f693373dac3927d2c9fc27e1 100644 (file)
--- a/src/text-chemistry.cpp
+++ b/src/text-chemistry.cpp
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
+
+#include <cstring>
+#include <string>
+#include <glibmm/i18n.h>
+
#include "libnr/nr-matrix-fns.h"
#include "xml/repr.h"
-#include <glibmm/i18n.h>
#include "sp-rect.h"
#include "sp-textpath.h"
#include "inkscape.h"
#include "sp-flowtext.h"
#include "sp-flowregion.h"
#include "sp-flowdiv.h"
+#include "sp-tspan.h"
SPItem *
SP_OBJECT_REPR(text)->addChild(textpath, NULL);
for ( GSList *i = text_reprs ; i ; i = i->next ) {
- // make a copy of each text child
- Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate();
+ // Make a copy of each text child
+ Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) i->data)->duplicate(xml_doc);
// We cannot have multiline in textpath, so remove line attrs from tspans
if (!strcmp(copy->name(), "svg:tspan")) {
copy->setAttribute("sodipodi:role", NULL);
if (!did) {
sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No texts-on-paths</b> in the selection."));
} else {
- 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"));
+ selection->setList(g_slist_copy((GSList *) selection->itemList())); // reselect to update statusbar description
}
}
SP_OBJECT_REPR(o)->setAttribute("dy", NULL);
SP_OBJECT_REPR(o)->setAttribute("rotate", NULL);
+ // 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 = sp_object_first_child(o); i != NULL; i = SP_OBJECT_NEXT(i)) {
text_remove_all_kerns_recursively(i);
}
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;
}
} else { // reflow an already flowed text, preserving paras
for (SPObject *o = SP_OBJECT(text)->children; o != NULL; o = o->next) {
if (SP_IS_FLOWPARA(o)) {
- Inkscape::XML::Node *para_repr = SP_OBJECT_REPR(o)->duplicate();
+ Inkscape::XML::Node *para_repr = SP_OBJECT_REPR(o)->duplicate(xml_doc);
root_repr->appendChild(para_repr);
object = doc->getObjectByRepr(para_repr);
g_return_if_fail(SP_IS_FLOWPARA(object));
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;
+ }
+
/* Create <text> */
Inkscape::XML::Node *rtext = xml_doc->createElement("svg:text");
rtext->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create
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]);
+ 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 <tspan> */
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);
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);