diff options
| author | Alexandru-Daniel Roman <alexroman5g@gmail.com> | 2017-02-28 11:48:29 +0000 |
|---|---|---|
| committer | Alexandru-Daniel Roman <alexroman5g@gmail.com> | 2017-02-28 11:48:29 +0000 |
| commit | 0fad68e35604556b9a3af81b90d8cc6b89e817b8 (patch) | |
| tree | 9de21c8ce185f3f5c2e7fda2538417d077f20e93 /src/ui/tools | |
| parent | More consistent naming scheme. (diff) | |
| download | inkscape-0fad68e35604556b9a3af81b90d8cc6b89e817b8.tar.gz inkscape-0fad68e35604556b9a3af81b90d8cc6b89e817b8.zip | |
This patch adds the copy-paste formated text functionality to the text tool.
It doesn't retain the font-size and font-style properties.
(bzr r15553)
Diffstat (limited to 'src/ui/tools')
| -rw-r--r-- | src/ui/tools/text-tool.cpp | 56 | ||||
| -rw-r--r-- | src/ui/tools/text-tool.h | 1 |
2 files changed, 56 insertions, 1 deletions
diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index 559187764..649bbb045 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -48,6 +48,8 @@ #include "ui/control-manager.h" #include "verbs.h" #include "xml/node-event-vector.h" +#include "xml/attribute-record.h" +#include "xml/sp-css-attr.h" using Inkscape::ControlManager; using Inkscape::DocumentUndo; @@ -1357,6 +1359,59 @@ SPCSSAttr *sp_text_get_style_at_cursor(ToolBase const *ec) return NULL; } +static bool css_attrs_are_equal(SPCSSAttr const *first, SPCSSAttr const *second) +{ + Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attrs = first->attributeList(); + for ( ; attrs ; attrs++) { + gchar const *other_attr = second->attribute(g_quark_to_string(attrs->key)); + if (other_attr == NULL || strcmp(attrs->value, other_attr)) + return false; + } + attrs = second->attributeList(); + for ( ; attrs ; attrs++) { + gchar const *other_attr = first->attribute(g_quark_to_string(attrs->key)); + if (other_attr == NULL || strcmp(attrs->value, other_attr)) + return false; + } + return true; +} + +std::vector<SPCSSAttr*> sp_text_get_selected_style(ToolBase const *ec, unsigned *k, int *b, std::vector<unsigned> *positions) +{ + std::vector<SPCSSAttr*> vec; + SPCSSAttr *css, *css_new; + TextTool *tc = SP_TEXT_CONTEXT(ec); + Inkscape::Text::Layout::iterator i = std::min(tc->text_sel_start, tc->text_sel_end); + SPObject const *obj = sp_te_object_at_position(tc->text, i); + if (obj) { + css = take_style_from_item(const_cast<SPObject*>(obj)); + } + vec.push_back(css); + positions->push_back(0); + i.nextCharacter(); + *k = 1; + *b = 1; + while (i != std::max(tc->text_sel_start, tc->text_sel_end)) + { + obj = sp_te_object_at_position(tc->text, i); + if (obj) { + css_new = take_style_from_item(const_cast<SPObject*>(obj)); + } + if(!css_attrs_are_equal(css, css_new)) + { + vec.push_back(css_new); + css = sp_repr_css_attr_new(); + sp_repr_css_merge(css, css_new); + positions->push_back(*k); + (*b)++; + } + i.nextCharacter(); + (*k)++; + } + positions->push_back(*k); + return vec; +} + /** Deletes the currently selected characters. Returns false if there is no text selection currently. @@ -1442,7 +1497,6 @@ bool TextTool::_styleSet(SPCSSAttr const *css) _("Set text style")); sp_text_context_update_cursor(this); sp_text_context_update_text_selection(this); - return true; } diff --git a/src/ui/tools/text-tool.h b/src/ui/tools/text-tool.h index 289ee180d..f2e6fea1a 100644 --- a/src/ui/tools/text-tool.h +++ b/src/ui/tools/text-tool.h @@ -94,6 +94,7 @@ private: bool sp_text_paste_inline(ToolBase *ec); Glib::ustring sp_text_get_selected_text(ToolBase const *ec); SPCSSAttr *sp_text_get_style_at_cursor(ToolBase const *ec); +std::vector<SPCSSAttr*> sp_text_get_selected_style(ToolBase const *ec, unsigned *k, int *b, std::vector<unsigned> *positions); bool sp_text_delete_selection(ToolBase *ec); void sp_text_context_place_cursor (TextTool *tc, SPObject *text, Inkscape::Text::Layout::iterator where); void sp_text_context_place_cursor_at (TextTool *tc, SPObject *text, Geom::Point const p); |
