summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabiertxof <jabier.arraiza@marker.es>2019-09-13 20:09:42 +0000
committerJabiertxof <jabier.arraiza@marker.es>2019-09-13 20:09:42 +0000
commitbf052b6e7cb79317c4f38ff144a77b6f9e49421e (patch)
tree8b5235b21eeac68e495ad60a51065aaeed4aff33 /src
parentRefactor of prepare inner and some comments (diff)
downloadinkscape-bf052b6e7cb79317c4f38ff144a77b6f9e49421e.tar.gz
inkscape-bf052b6e7cb79317c4f38ff144a77b6f9e49421e.zip
Allow to paste paragraphs in SVG2 Flow then paste overflow the shape
Diffstat (limited to 'src')
-rw-r--r--src/object/sp-text.cpp32
-rw-r--r--src/object/sp-text.h9
-rw-r--r--src/ui/clipboard.cpp8
-rw-r--r--src/ui/toolbar/text-toolbar.cpp19
-rw-r--r--src/ui/tools/text-tool.cpp7
5 files changed, 55 insertions, 20 deletions
diff --git a/src/object/sp-text.cpp b/src/object/sp-text.cpp
index 91ca65170..4dd5a9ff1 100644
--- a/src/object/sp-text.cpp
+++ b/src/object/sp-text.cpp
@@ -63,7 +63,12 @@
SPText::SPText() : SPItem() {
}
-SPText::~SPText() = default;
+SPText::~SPText()
+{
+ if (css) {
+ sp_repr_css_attr_unref(css);
+ }
+};
void SPText::build(SPDocument *doc, Inkscape::XML::Node *repr) {
this->readAttr( "x" );
@@ -76,7 +81,7 @@ void SPText::build(SPDocument *doc, Inkscape::XML::Node *repr) {
this->readAttr( "textLength" );
this->readAttr( "lengthAdjust" );
SPItem::build(doc, repr);
-
+ css = nullptr;
this->readAttr( "sodipodi:linespacing" ); // has to happen after the styles are read
}
@@ -383,6 +388,29 @@ void SPText::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::
}
}
+void SPText::hide_shape_inside()
+{
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ SPStyle *item_style = this->style;
+ if (item_style && prefs->getBool("/tools/text/use_svg2") && item_style->shape_inside.set) {
+ SPCSSAttr *css_unset = sp_css_attr_from_style(item_style, SP_STYLE_FLAG_IFSET);
+ css = sp_css_attr_from_style(item_style, SP_STYLE_FLAG_IFSET);
+ sp_repr_css_unset_property(css_unset, "shape-inside");
+ sp_repr_css_attr_unref(css_unset);
+ this->changeCSS(css_unset, "style");
+ } else {
+ css = nullptr;
+ }
+}
+
+void SPText::show_shape_inside()
+{
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ if (prefs->getBool("/tools/text/use_svg2") && css) {
+ this->changeCSS(css, "style");
+ }
+}
+
Geom::Affine SPText::set_transform(Geom::Affine const &xform) {
// See if 'shape-inside' has rectangle
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
diff --git a/src/object/sp-text.h b/src/object/sp-text.h
index 3b7880a88..e058bd6e7 100644
--- a/src/object/sp-text.h
+++ b/src/object/sp-text.h
@@ -59,6 +59,12 @@ public:
completely specified by transformations. */
static void _adjustCoordsRecursive(SPItem *item, Geom::Affine const &m, double ex, bool is_root = true);
static void _adjustFontsizeRecursive(SPItem *item, double ex, bool is_root = true);
+ /**
+ This two functions are useful because layout calculations need text visible for example
+ Calculating a invisible char position object or pasting text with paragraps that overflow
+ shape defined. I have doubts abot trransform into a toggle function*/
+ void show_shape_inside();
+ void hide_shape_inside();
/** discards the drawing objects representing this text. */
void _clearFlow(Inkscape::DrawingGroup *in_arena);
@@ -83,8 +89,9 @@ private:
/** Find first x/y values which may be in a descendent element. */
SVGLength* _getFirstXLength();
SVGLength* _getFirstYLength();
+ SPCSSAttr *css;
-public:
+ public:
/** Optimize textpath text on next set_transform. */
void optimizeTextpathText() {_optimizeTextpathText = true;}
diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp
index b9e7dc2b5..078dfc125 100644
--- a/src/ui/clipboard.cpp
+++ b/src/ui/clipboard.cpp
@@ -1089,7 +1089,10 @@ bool ClipboardManagerImpl::_pasteText(SPDesktop *desktop)
Inkscape::Text::Layout const *layout = te_get_layout(tc->text);
Inkscape::Text::Layout::iterator it_next;
Inkscape::Text::Layout::iterator it = tc->text_sel_end;
-
+ SPText *textitem = dynamic_cast<SPText *>(tc->text);
+ if (textitem) {
+ textitem->hide_shape_inside();
+ }
SPCSSAttr *css = take_style_from_item(tc->text);
for (int i = 0; i < nr_blocks; ++i)
{
@@ -1116,6 +1119,9 @@ bool ClipboardManagerImpl::_pasteText(SPDesktop *desktop)
for (unsigned int j = te_selected_style_positions[i]; j < te_selected_style_positions[i+1]; ++j)
it.nextCharacter();
}
+ if (textitem) {
+ textitem->show_shape_inside();
+ }
}
return true;
}
diff --git a/src/ui/toolbar/text-toolbar.cpp b/src/ui/toolbar/text-toolbar.cpp
index 839fb997b..b0af522d3 100644
--- a/src/ui/toolbar/text-toolbar.cpp
+++ b/src/ui/toolbar/text-toolbar.cpp
@@ -2293,28 +2293,15 @@ void TextToolbar::prepare_inner()
}
// Here we remove temporary the shape to allow layout calculate where are the warp_end and warpo_start
// position if one of this are hiden because the previous line height changed
- SPCSSAttr *css = nullptr;
if (text) {
- SPStyle *item_style = spitem->style;
- if (item_style->shape_inside.set) {
- SPCSSAttr *css_unset = sp_css_attr_from_style(item_style, SP_STYLE_FLAG_IFSET);
- css = sp_css_attr_from_style(item_style, SP_STYLE_FLAG_IFSET);
- sp_repr_css_unset_property(css_unset, "shape-inside");
- spitem->changeCSS(css_unset, "style");
- spitem->updateRepr();
- }
+ text->hide_shape_inside();
}
- /* if (text) {
- text->rebuildLayout();
- } else if (flowtext) {
- flowtext->rebuildLayout();
- } */
void *rawptr_start = nullptr;
void *rawptr_end = nullptr;
layout->getSourceOfCharacter(wrap_start, &rawptr_start);
layout->getSourceOfCharacter(wrap_end, &rawptr_end);
- if (css) {
- spitem->changeCSS(css, "style");
+ if (text) {
+ text->show_shape_inside();
}
if (!rawptr_start || !rawptr_end || !SP_IS_OBJECT(rawptr_start)|| !SP_IS_OBJECT(rawptr_end)) {
return;
diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp
index 20b4c2c65..a9a66d64f 100644
--- a/src/ui/tools/text-tool.cpp
+++ b/src/ui/tools/text-tool.cpp
@@ -1315,6 +1315,10 @@ bool sp_text_paste_inline(ToolBase *ec)
Glib::ustring const clip_text = refClipboard->wait_for_text();
if (!clip_text.empty()) {
+ SPText *textitem = dynamic_cast<SPText *>(tc->text);
+ if (textitem) {
+ textitem->hide_shape_inside();
+ }
// Fix for 244940
// The XML standard defines the following as valid characters
// (Extensible Markup Language (XML) 1.0 (Fourth Edition) paragraph 2.2)
@@ -1360,6 +1364,9 @@ bool sp_text_paste_inline(ToolBase *ec)
tc->text_sel_start = tc->text_sel_end = sp_te_insert_line(tc->text, tc->text_sel_start);
begin = end + 1;
}
+ if (textitem) {
+ textitem->show_shape_inside();
+ }
DocumentUndo::done(ec->desktop->getDocument(), SP_VERB_CONTEXT_TEXT,
_("Paste text"));