summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-12-19 09:06:49 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-12-19 09:06:49 +0000
commit851a26beaa5506e5b44106d9ec0dd1a2285c38ff (patch)
treec82352d8e47d2d52f5e19251a193564e653ebb5a /src
parentConvert preferences_skeleton to a C++11 raw string. (diff)
downloadinkscape-851a26beaa5506e5b44106d9ec0dd1a2285c38ff.tar.gz
inkscape-851a26beaa5506e5b44106d9ec0dd1a2285c38ff.zip
Add preference for using SVG 2 text in a shape (GUI to come).
Diffstat (limited to 'src')
-rw-r--r--src/preferences-skeleton.h2
-rw-r--r--src/text-chemistry.cpp115
-rw-r--r--src/ui/tools/text-tool.cpp2
3 files changed, 60 insertions, 59 deletions
diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h
index 008aba431..e5099ea0b 100644
--- a/src/preferences-skeleton.h
+++ b/src/preferences-skeleton.h
@@ -134,7 +134,7 @@ R"=====(
<eventcontext id="text" usecurrent="0" gradientdrag="1"
font_sample="AaBbCcIiPpQq12369$\342\202\254\302\242?.;/()"
- show_sample_in_list="1"
+ show_sample_in_list="1" use_svg2="0"
style="fill:black;fill-opacity:1;stroke:none;font-family:sans-serif;font-style:normal;font-weight:normal;font-size:40px;" selcue="1"/>
<eventcontext id="nodes" selcue="1" gradientdrag="1" highlight_color="4278190335" pathflash_enabled="1" pathflash_unselected="0" pathflash_timeout="500" show_handles="1" show_outline="0"
diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp
index 61e2eff6c..371346442 100644
--- a/src/text-chemistry.cpp
+++ b/src/text-chemistry.cpp
@@ -299,7 +299,8 @@ text_flow_into_shape()
return;
}
- if (false) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if (prefs->getBool("/tools/text/use_svg2")) {
// SVG 2 Text
if (SP_IS_TEXT(text)) {
@@ -333,66 +334,66 @@ text_flow_into_shape()
} else {
// SVG 1.2 Flowed Text
- if (SP_IS_TEXT(text)) {
- // remove transform from text, but recursively scale text's fontsize by the expansion
- SP_TEXT(text)->_adjustFontsizeRecursive(text, text->transform.descrim());
- text->getRepr()->setAttribute("transform", nullptr);
- }
-
- 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", text->getRepr()->attribute("style")); // fixme: transfer style attrs too
- shape->parent->getRepr()->appendChild(root_repr);
- SPObject *root_object = doc->getObjectByRepr(root_repr);
- g_return_if_fail(SP_IS_FLOWTEXT(root_object));
-
- 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));
-
- /* Add clones */
- auto items = selection->items();
- for(auto i=items.begin();i!=items.end();++i){
- SPItem *item = *i;
- if (SP_IS_SHAPE(item)){
- Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
- clone->setAttribute("x", "0");
- clone->setAttribute("y", "0");
- gchar *href_str = g_strdup_printf("#%s", item->getRepr()->attribute("id"));
- clone->setAttribute("xlink:href", href_str);
- g_free(href_str);
-
- // add the new clone to the region
- region_repr->appendChild(clone);
+ if (SP_IS_TEXT(text)) {
+ // remove transform from text, but recursively scale text's fontsize by the expansion
+ SP_TEXT(text)->_adjustFontsizeRecursive(text, text->transform.descrim());
+ text->getRepr()->setAttribute("transform", nullptr);
}
- }
- if (SP_IS_TEXT(text)) { // flow from text, as string
- 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));
-
- 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 = 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);
- Inkscape::GC::release(text_repr);
-
- } else { // reflow an already flowed text, preserving paras
- for(auto& o: text->children) {
- if (SP_IS_FLOWPARA(&o)) {
- Inkscape::XML::Node *para_repr = o.getRepr()->duplicate(xml_doc);
- root_repr->appendChild(para_repr);
- object = doc->getObjectByRepr(para_repr);
- g_return_if_fail(SP_IS_FLOWPARA(object));
- Inkscape::GC::release(para_repr);
+ 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", text->getRepr()->attribute("style")); // fixme: transfer style attrs too
+ shape->parent->getRepr()->appendChild(root_repr);
+ SPObject *root_object = doc->getObjectByRepr(root_repr);
+ g_return_if_fail(SP_IS_FLOWTEXT(root_object));
+
+ 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));
+
+ /* Add clones */
+ auto items = selection->items();
+ for(auto i=items.begin();i!=items.end();++i){
+ SPItem *item = *i;
+ if (SP_IS_SHAPE(item)){
+ Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
+ clone->setAttribute("x", "0");
+ clone->setAttribute("y", "0");
+ gchar *href_str = g_strdup_printf("#%s", item->getRepr()->attribute("id"));
+ clone->setAttribute("xlink:href", href_str);
+ g_free(href_str);
+
+ // add the new clone to the region
+ region_repr->appendChild(clone);
}
}
+
+ if (SP_IS_TEXT(text)) { // flow from text, as string
+ 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));
+
+ 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 = 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);
+ Inkscape::GC::release(text_repr);
+
+ } else { // reflow an already flowed text, preserving paras
+ for(auto& o: text->children) {
+ if (SP_IS_FLOWPARA(&o)) {
+ Inkscape::XML::Node *para_repr = o.getRepr()->duplicate(xml_doc);
+ root_repr->appendChild(para_repr);
+ object = doc->getObjectByRepr(para_repr);
+ g_return_if_fail(SP_IS_FLOWPARA(object));
+ Inkscape::GC::release(para_repr);
+ }
+ }
}
text->deleteObject(true);
diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp
index 4bdf5e5ba..4de0dc81f 100644
--- a/src/ui/tools/text-tool.cpp
+++ b/src/ui/tools/text-tool.cpp
@@ -652,7 +652,7 @@ bool TextTool::root_handler(GdkEvent* event) {
if (fabs(p1[Geom::Y] - this->p0[Geom::Y]) > cursor_height) {
// otherwise even one line won't fit; most probably a slip of hand (even if bigger than tolerance)
- if (false) {
+ if (prefs->getBool("/tools/text/use_svg2")) {
// SVG 2 text
SPItem *text = create_text_with_rectangle (desktop, this->p0, p1);