diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp
index 4ea47fd278fd4caf19e1d9616d5e28126be4c798..79d5e3a2dc390d5a62068ea6b80c0db2beaff839 100644 (file)
--- a/src/text-chemistry.cpp
+++ b/src/text-chemistry.cpp
#include "sp-rect.h"
#include "sp-textpath.h"
#include "inkscape.h"
#include "sp-rect.h"
#include "sp-textpath.h"
#include "inkscape.h"
+#include "desktop.h"
#include "document.h"
#include "message-stack.h"
#include "selection.h"
#include "document.h"
#include "message-stack.h"
#include "selection.h"
SPItem *text = text_or_flowtext_in_selection(selection);
SPItem *shape = shape_in_selection(selection);
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());
+
if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) {
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text and a path</b> to put text on path."));
return;
if (!text || !shape || g_slist_length((GSList *) selection->itemList()) != 2) {
sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>a text and a path</b> to put text on path."));
return;
// if a flowed text is selected, convert it to a regular text object
if (SP_IS_FLOWTEXT(text)) {
// if a flowed text is selected, convert it to a regular text object
if (SP_IS_FLOWTEXT(text)) {
+
+ if (!SP_FLOWTEXT(text)->layout.outputExists()) {
+ sp_desktop_message_stack(desktop)->
+ flash(Inkscape::WARNING_MESSAGE,
+ _("The flowed text(s) must be <b>visible</b> in order to be put on a path."));
+ }
+
Inkscape::XML::Node *repr = SP_FLOWTEXT(text)->getAsText();
Inkscape::XML::Node *repr = SP_FLOWTEXT(text)->getAsText();
+
+ if (!repr) return;
+
Inkscape::XML::Node *parent = SP_OBJECT_REPR(text)->parent();
parent->appendChild(repr);
Inkscape::XML::Node *parent = SP_OBJECT_REPR(text)->parent();
parent->appendChild(repr);
}
// create textPath and put it into the text
}
// create textPath and put it into the text
- Inkscape::XML::Node *textpath = sp_repr_new("svg:textPath");
+ Inkscape::XML::Node *textpath = xml_doc->createElement("svg:textPath");
// reference the shape
textpath->setAttribute("xlink:href", g_strdup_printf("#%s", SP_OBJECT_REPR(shape)->attribute("id")));
if (text_alignment == Inkscape::Text::Layout::RIGHT)
// reference the shape
textpath->setAttribute("xlink:href", g_strdup_printf("#%s", SP_OBJECT_REPR(shape)->attribute("id")));
if (text_alignment == Inkscape::Text::Layout::RIGHT)
return;
SPDocument *doc = sp_desktop_document (desktop);
return;
SPDocument *doc = sp_desktop_document (desktop);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
Inkscape::Selection *selection = sp_desktop_selection(desktop);
Inkscape::Selection *selection = sp_desktop_selection(desktop);
SP_OBJECT_REPR(text)->setAttribute("transform", NULL);
}
SP_OBJECT_REPR(text)->setAttribute("transform", NULL);
}
- Inkscape::XML::Node *root_repr = sp_repr_new("svg:flowRoot");
+ Inkscape::XML::Node *root_repr = xml_doc->createElement("svg:flowRoot");
root_repr->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create
root_repr->setAttribute("style", SP_OBJECT_REPR(text)->attribute("style")); // fixme: transfer style attrs too
SP_OBJECT_REPR(SP_OBJECT_PARENT(shape))->appendChild(root_repr);
SPObject *root_object = doc->getObjectByRepr(root_repr);
g_return_if_fail(SP_IS_FLOWTEXT(root_object));
root_repr->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create
root_repr->setAttribute("style", SP_OBJECT_REPR(text)->attribute("style")); // fixme: transfer style attrs too
SP_OBJECT_REPR(SP_OBJECT_PARENT(shape))->appendChild(root_repr);
SPObject *root_object = doc->getObjectByRepr(root_repr);
g_return_if_fail(SP_IS_FLOWTEXT(root_object));
- Inkscape::XML::Node *region_repr = sp_repr_new("svg:flowRegion");
+ Inkscape::XML::Node *region_repr = xml_doc->createElement("svg:flowRegion");
root_repr->appendChild(region_repr);
SPObject *object = doc->getObjectByRepr(region_repr);
g_return_if_fail(SP_IS_FLOWREGION(object));
root_repr->appendChild(region_repr);
SPObject *object = doc->getObjectByRepr(region_repr);
g_return_if_fail(SP_IS_FLOWREGION(object));
items = items->next) {
SPItem *item = SP_ITEM(items->data);
if (SP_IS_SHAPE(item)){
items = items->next) {
SPItem *item = SP_ITEM(items->data);
if (SP_IS_SHAPE(item)){
- Inkscape::XML::Node *clone = sp_repr_new("svg:use");
+ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
clone->setAttribute("x", "0");
clone->setAttribute("y", "0");
clone->setAttribute("xlink:href", g_strdup_printf("#%s", SP_OBJECT_REPR(item)->attribute("id")));
clone->setAttribute("x", "0");
clone->setAttribute("y", "0");
clone->setAttribute("xlink:href", g_strdup_printf("#%s", SP_OBJECT_REPR(item)->attribute("id")));
}
if (SP_IS_TEXT(text)) { // flow from text, as string
}
if (SP_IS_TEXT(text)) { // flow from text, as string
- Inkscape::XML::Node *para_repr = sp_repr_new("svg:flowPara");
+ Inkscape::XML::Node *para_repr = xml_doc->createElement("svg:flowPara");
root_repr->appendChild(para_repr);
object = doc->getObjectByRepr(para_repr);
g_return_if_fail(SP_IS_FLOWPARA(object));
root_repr->appendChild(para_repr);
object = doc->getObjectByRepr(para_repr);
g_return_if_fail(SP_IS_FLOWPARA(object));
Inkscape::Text::Layout const *layout = te_get_layout(text);
Glib::ustring text_ustring = sp_te_get_string_multiline(text, layout->begin(), layout->end());
Inkscape::Text::Layout const *layout = te_get_layout(text);
Glib::ustring text_ustring = sp_te_get_string_multiline(text, layout->begin(), layout->end());
- Inkscape::XML::Node *text_repr = sp_repr_new_text(text_ustring.c_str()); // FIXME: transfer all formatting! and convert newlines into flowParas!
+ Inkscape::XML::Node *text_repr = xml_doc->createTextNode(text_ustring.c_str()); // FIXME: transfer all formatting! and convert newlines into flowParas!
para_repr->appendChild(text_repr);
Inkscape::GC::release(para_repr);
para_repr->appendChild(text_repr);
Inkscape::GC::release(para_repr);
return;
SPDocument *doc = sp_desktop_document (desktop);
return;
SPDocument *doc = sp_desktop_document (desktop);
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
Inkscape::Selection *selection = sp_desktop_selection(desktop);
Inkscape::Selection *selection = sp_desktop_selection(desktop);
SPItem *flowtext = SP_ITEM(items->data);
SPItem *flowtext = SP_ITEM(items->data);
+ if (sp_te_get_string_multiline(flowtext) == NULL) { // flowtext is empty
+ continue;
+ }
+
/* Create <text> */
/* Create <text> */
- Inkscape::XML::Node *rtext = sp_repr_new("svg:text");
+ Inkscape::XML::Node *rtext = xml_doc->createElement("svg:text");
rtext->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create
/* Set style */
rtext->setAttribute("xml:space", "preserve"); // we preserve spaces in the text objects we create
/* Set style */
}
/* Create <tspan> */
}
/* Create <tspan> */
- Inkscape::XML::Node *rtspan = sp_repr_new("svg:tspan");
+ Inkscape::XML::Node *rtspan = xml_doc->createElement("svg:tspan");
rtspan->setAttribute("sodipodi:role", "line"); // otherwise, why bother creating the tspan?
rtext->addChild(rtspan, NULL);
gchar *text_string = sp_te_get_string_multiline(flowtext);
rtspan->setAttribute("sodipodi:role", "line"); // otherwise, why bother creating the tspan?
rtext->addChild(rtspan, NULL);
gchar *text_string = sp_te_get_string_multiline(flowtext);
- Inkscape::XML::Node *text_repr = sp_repr_new_text(text_string); // FIXME: transfer all formatting!!!
+ Inkscape::XML::Node *text_repr = xml_doc->createTextNode(text_string); // FIXME: transfer all formatting!!!
free(text_string);
rtspan->appendChild(text_repr);
free(text_string);
rtspan->appendChild(text_repr);
if (!SP_IS_FLOWTEXT(item))
continue;
if (!SP_IS_FLOWTEXT(item))
continue;
- did = true;
+ if (!SP_FLOWTEXT(item)->layout.outputExists()) {
+ sp_desktop_message_stack(desktop)->
+ flash(Inkscape::WARNING_MESSAGE,
+ _("The flowed text(s) must be <b>visible</b> in order to be converted."));
+ return;
+ }
Inkscape::XML::Node *repr = SP_FLOWTEXT(item)->getAsText();
Inkscape::XML::Node *repr = SP_FLOWTEXT(item)->getAsText();
+
+ if (!repr) break;
+
+ did = true;
+
Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
parent->appendChild(repr);
Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
parent->appendChild(repr);