diff options
| author | David Mathog <> | 2013-06-19 17:20:33 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2013-06-19 17:20:33 +0000 |
| commit | d19db89e2e22d4e09c539bd42823d511aebb669f (patch) | |
| tree | f5322f76b16b0e4c97895ce2b805ea7375e44142 /src/text-editing.cpp | |
| parent | merge from trunk (r12337) (diff) | |
| download | inkscape-d19db89e2e22d4e09c539bd42823d511aebb669f.tar.gz inkscape-d19db89e2e22d4e09c539bd42823d511aebb669f.zip | |
changes_2013_05_22a.patch:
1. Resolves issue of bug #988601 message 170 (Support of 'Unset' styles in EMF export).
2. Implements CSS 3 (and CSS 2) text-decoration support.
Note that it does not yet provide any method of adding these features - at present it just shows whatever is in the SVG. This new code is also used to display EMF/WMF strike-through and underline text decorations when these files are read in. Those decorations may also be written out to EMF/WMF. Other text decoration features, like overline, or dotted lines, are dropped. For SVG text-decoration -line, -style, -color are all implemented. CSS3 provides two ways to represent the same state, this code uses the compound text-decoration method rather than the 3 fields method. Also it leaves out keywords that are not needed and would break backwards compatibility. For instance:
text-decoration: underline solid
is valid, but would break CSS2. Solid is the default, so that sort of case is written as:
text-decoration: underline
If the state is CSS3 specific all of the needed fields are of course include, like
text-decoration: underline wavy red
3. It incorporates the fix for bug 1181326 (Text edit mishandles span of just colored spaces)
4. It incorporates further changes to text editing so that style can be changed on spans consisting of only spaces when text decorations are present in the span.
5. It incorporates code to disable text decorations when text so marked is mapped onto a path.
6. Fixed more bugs in Hebrew language support than I can remember. Hebrew language export/import to EMF now works quite well. (See the examples in libTERE v 0.7.) WMF does not support unicode and for all intents and purposes Inkscape has no way to read or write Hebrew to it. Some of more important things that now work that didn't (or didn't always): Hebrew diacritical marks, R/L/center justification, and bidirectional text. The Hebrew fonts "Ezra SIL" and "EZRA SIL SR" should be installed before viewing the libTERE examples, otherwise font substitutions will cause some text shifts.
7. Implemented font failover in Text Reassemble, which makes the process more robust. (Again, see the examples in libTERE. )
(bzr r11668.1.71)
Diffstat (limited to '')
| -rw-r--r-- | src/text-editing.cpp | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 401f56bb2..050917e03 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -43,7 +43,7 @@ static const gchar *tref_edit_message = _("You cannot edit <b>cloned character data</b>."); -static bool tidy_xml_tree_recursively(SPObject *root); +static bool tidy_xml_tree_recursively(SPObject *root, bool has_text_decoration); Inkscape::Text::Layout const * te_get_layout (SPItem const *item) { @@ -774,6 +774,10 @@ sp_te_delete (SPItem *item, Inkscape::Text::Layout::iterator const &start, SPObject *common_ancestor = get_common_ancestor(item, start_item, end_item); + bool has_text_decoration = false; + gchar const *root_style = (item)->getRepr()->attribute("style"); + if(strstr(root_style,"text-decoration"))has_text_decoration = true; + if (start_item == end_item) { // the quick case where we're deleting stuff all from the same string if (SP_IS_STRING(start_item)) { // always true (if it_start != it_end anyway) @@ -835,7 +839,7 @@ sp_te_delete (SPItem *item, Inkscape::Text::Layout::iterator const &start, } } - while (tidy_xml_tree_recursively(common_ancestor)){}; + while (tidy_xml_tree_recursively(common_ancestor, has_text_decoration)){}; te_update_layout_now(item); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); layout->validateIterator(&iter_pair.first); @@ -1554,7 +1558,7 @@ static SPObject* ascend_while_first(SPObject *item, Glib::ustring::iterator text /** empty spans: abc<span></span>def -> abcdef */ -static bool tidy_operator_empty_spans(SPObject **item) +static bool tidy_operator_empty_spans(SPObject **item, bool has_text_decoration) { bool result = false; if ( !(*item)->hasChildren() @@ -1572,7 +1576,7 @@ static bool tidy_operator_empty_spans(SPObject **item) /** inexplicable spans: abc<span style="">def</span>ghi -> "abc""def""ghi" the repeated strings will be merged by another operator. */ -static bool tidy_operator_inexplicable_spans(SPObject **item) +static bool tidy_operator_inexplicable_spans(SPObject **item, bool has_text_decoration) { //XML Tree being directly used here while it shouldn't be. if (*item && sp_repr_is_meta_element((*item)->getRepr())) { @@ -1607,7 +1611,7 @@ static bool tidy_operator_inexplicable_spans(SPObject **item) /** repeated spans: <font a>abc</font><font a>def</font> -> <font a>abcdef</font> */ -static bool tidy_operator_repeated_spans(SPObject **item) +static bool tidy_operator_repeated_spans(SPObject **item, bool has_text_decoration) { SPObject *first = *item; SPObject *second = first->getNext(); @@ -1653,7 +1657,7 @@ static bool tidy_operator_repeated_spans(SPObject **item) -> <font b>abc</font> excessive nesting: <font a><size 1>abc</size></font> -> <font a,size 1>abc</font> */ -static bool tidy_operator_excessive_nesting(SPObject **item) +static bool tidy_operator_excessive_nesting(SPObject **item, bool has_text_decoration) { if (!(*item)->hasChildren()) { return false; @@ -1731,7 +1735,7 @@ example. You may note that this only does its work when the doubly-nested child is the first or last. The other cases are called 'style inversion' below, and I'm not yet convinced that the result of that operation will be tidier in all cases. */ -static bool tidy_operator_redundant_double_nesting(SPObject **item) +static bool tidy_operator_redundant_double_nesting(SPObject **item, bool has_text_decoration) { if (!(*item)->hasChildren()) return false; if ((*item)->firstChild() == (*item)->lastChild()) return false; // this is excessive nesting, done above @@ -1792,7 +1796,7 @@ static bool redundant_semi_nesting_processor(SPObject **item, SPObject *child, b -> <font b>abc</font><font>def</font> test this by applying a colour to a region, then a different colour to a partially-overlapping region. */ -static bool tidy_operator_redundant_semi_nesting(SPObject **item) +static bool tidy_operator_redundant_semi_nesting(SPObject **item, bool has_text_decoration) { if (!(*item)->hasChildren()) return false; if ((*item)->firstChild() == (*item)->lastChild()) return false; // this is redundant nesting, done above @@ -1819,13 +1823,21 @@ static SPString* find_last_string_child_not_equal_to(SPObject *root, SPObject *n return NULL; } -/** whitespace-only spans: abc<font> </font>def - -> abc<font></font> def - abc<b><i>def</i> </b>ghi - -> abc<b><i>def</i></b> ghi */ -static bool tidy_operator_styled_whitespace(SPObject **item) +/** whitespace-only spans: + abc<font> </font>def + -> abc<font></font> def + abc<b><i>def</i> </b>ghi + -> abc<b><i>def</i></b> ghi + + visible text-decoration changes on white spaces should not be subject + to this sort of processing. So + abc<text-decoration-color> </text-decoration-color>def + is unchanged. +*/ +static bool tidy_operator_styled_whitespace(SPObject **item, bool has_text_decoration) { - if (!SP_IS_STRING(*item)) { + // any type of visible text decoration is OK as pure spaces, so do nothing here in that case. + if (!SP_IS_STRING(*item) || has_text_decoration ) { return false; } Glib::ustring const &str = SP_STRING(*item)->string; @@ -1835,6 +1847,7 @@ static bool tidy_operator_styled_whitespace(SPObject **item) } } + SPObject *test_item = *item; SPString *next_string; for ( ; ; ) { // find the next string @@ -1862,7 +1875,7 @@ static bool tidy_operator_styled_whitespace(SPObject **item) if (next_string == NULL) { return false; // an empty paragraph } - next_string->string += str; + next_string->string = str + next_string->string; break; } } @@ -1896,9 +1909,11 @@ It may be that some of the later tidy operators that I wrote are actually general cases of the earlier operators, and hence the special-case-only versions can be removed. I haven't analysed my work in detail to figure out if this is so. */ -static bool tidy_xml_tree_recursively(SPObject *root) +static bool tidy_xml_tree_recursively(SPObject *root, bool has_text_decoration) { - static bool (* const tidy_operators[])(SPObject**) = { + gchar const *root_style = (root)->getRepr()->attribute("style"); + if(root_style && strstr(root_style,"text-decoration"))has_text_decoration = true; + static bool (* const tidy_operators[])(SPObject**, bool) = { tidy_operator_empty_spans, tidy_operator_inexplicable_spans, tidy_operator_repeated_spans, @@ -1915,12 +1930,12 @@ static bool tidy_xml_tree_recursively(SPObject *root) continue; } if (child->hasChildren()) { - changes |= tidy_xml_tree_recursively(child); + changes |= tidy_xml_tree_recursively(child, has_text_decoration); } unsigned i; for (i = 0 ; i < sizeof(tidy_operators) / sizeof(tidy_operators[0]) ; i++) { - if (tidy_operators[i](&child)) { + if (tidy_operators[i](&child, has_text_decoration)) { changes = true; break; } @@ -2018,7 +2033,10 @@ void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &sta and neither option can be made to work, a fallback could be to reduce everything to a single level of nesting and drop all pretence of roundtrippability. */ - while (tidy_xml_tree_recursively(common_ancestor)){}; + bool has_text_decoration = false; + gchar const *root_style = (text)->getRepr()->attribute("style"); + if(strstr(root_style,"text-decoration"))has_text_decoration = true; + while (tidy_xml_tree_recursively(common_ancestor, has_text_decoration)){}; // if we only modified subobjects this won't have been automatically sent text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); |
