diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index 7a6f5fd15fdef985346060017ed94ebfac35b087..2bdee4c102a643ff8302d7142fd8c8113a35cadc 100644 (file)
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
# include "config.h"
#endif
+#include <cstring>
+#include <string>
+#include <glibmm/i18n.h>
+
#include "desktop.h"
+#include "inkscape.h"
+#include "message-stack.h"
#include "style.h"
#include "unit-constants.h"
+#include "document.h"
#include "xml/repr.h"
#include "xml/attribute-record.h"
#include "sp-flowtext.h"
#include "sp-flowdiv.h"
#include "sp-flowregion.h"
+#include "sp-tref.h"
#include "sp-tspan.h"
#include "text-editing.h"
+static const gchar *tref_edit_message = _("You cannot edit <b>cloned character data</b>.");
+
static bool tidy_xml_tree_recursively(SPObject *root);
Inkscape::Text::Layout const * te_get_layout (SPItem const *item)
}
Inkscape::Text::Layout::iterator
-sp_te_get_position_by_coords (SPItem const *item, NR::Point &i_p)
+sp_te_get_position_by_coords (SPItem const *item, Geom::Point const &i_p)
{
- NR::Matrix im=sp_item_i2d_affine (item);
+ Geom::Matrix im (sp_item_i2d_affine (item));
im = im.inverse();
- NR::Point p = i_p * im;
+ Geom::Point p = i_p * im;
Inkscape::Text::Layout const *layout = te_get_layout(item);
return layout->getNearestCursorPositionTo(p);
}
-std::vector<NR::Point> sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, NR::Matrix const &transform)
+std::vector<Geom::Point> sp_te_create_selection_quads(SPItem const *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, Geom::Matrix const &transform)
{
if (start == end)
- return std::vector<NR::Point>();
+ return std::vector<Geom::Point>();
Inkscape::Text::Layout const *layout = te_get_layout(item);
if (layout == NULL)
- return std::vector<NR::Point>();
+ return std::vector<Geom::Point>();
return layout->createSelectionShape(start, end, transform);
}
void
-sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, NR::Point &p0, NR::Point &p1)
+sp_te_get_cursor_coords (SPItem const *item, Inkscape::Text::Layout::iterator const &position, Geom::Point &p0, Geom::Point &p1)
{
Inkscape::Text::Layout const *layout = te_get_layout(item);
double height, rotation;
- layout->queryCursorShape(position, &p0, &height, &rotation);
- p1 = NR::Point(p0[NR::X] + height * sin(rotation), p0[NR::Y] - height * cos(rotation));
+ layout->queryCursorShape(position, p0, height, rotation);
+ p1 = Geom::Point(p0[Geom::X] + height * sin(rotation), p0[Geom::Y] - height * cos(rotation));
}
SPStyle const * sp_te_style_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position)
+{
+ SPObject const *pos_obj = sp_te_object_at_position(text, position);
+ if (pos_obj)
+ return SP_OBJECT_STYLE(pos_obj);
+ return NULL;
+}
+
+SPObject const * sp_te_object_at_position(SPItem const *text, Inkscape::Text::Layout::iterator const &position)
{
Inkscape::Text::Layout const *layout = te_get_layout(text);
if (layout == NULL)
return NULL;
- union { SPObject const *op; void *vp; } pos_obj;
- pos_obj.vp = NULL;
- layout->getSourceOfCharacter(position, &pos_obj.vp);
- if (pos_obj.vp == NULL) pos_obj.op = text;
- while (SP_OBJECT_STYLE(pos_obj.op) == NULL)
- pos_obj.op = SP_OBJECT_PARENT(pos_obj.op); // SPStrings don't have style
- return SP_OBJECT_STYLE(pos_obj.op);
+ SPObject const *pos_obj = 0;
+ void *rawptr = 0;
+ layout->getSourceOfCharacter(position, &rawptr);
+ pos_obj = SP_OBJECT(rawptr);
+ if (pos_obj == 0) pos_obj = text;
+ while (SP_OBJECT_STYLE(pos_obj) == NULL)
+ pos_obj = SP_OBJECT_PARENT(pos_obj); // not interested in SPStrings
+ return pos_obj;
}
/*
Inkscape::Text::Layout::iterator sp_te_replace(SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, gchar const *utf8)
{
- Inkscape::Text::Layout::iterator new_start = sp_te_delete(item, start, end);
- return sp_te_insert(item, new_start, utf8);
+ iterator_pair pair;
+ sp_te_delete(item, start, end, pair);
+ return sp_te_insert(item, pair.first, utf8);
}
@@ -139,23 +159,34 @@ Inkscape::Text::Layout::iterator sp_te_replace(SPItem *item, Inkscape::Text::Lay
static bool is_line_break_object(SPObject const *object)
{
- return SP_IS_TEXT(object)
- || (SP_IS_TSPAN(object) && SP_TSPAN(object)->role != SP_TSPAN_ROLE_UNSPECIFIED)
- || SP_IS_TEXTPATH(object)
- || SP_IS_FLOWDIV(object)
- || SP_IS_FLOWPARA(object)
- || SP_IS_FLOWLINE(object)
- || SP_IS_FLOWREGIONBREAK(object);
+ bool is_line_break = false;
+
+ if (object) {
+ if (SP_IS_TEXT(object)
+ || (SP_IS_TSPAN(object) && SP_TSPAN(object)->role != SP_TSPAN_ROLE_UNSPECIFIED)
+ || SP_IS_TEXTPATH(object)
+ || SP_IS_FLOWDIV(object)
+ || SP_IS_FLOWPARA(object)
+ || SP_IS_FLOWLINE(object)
+ || SP_IS_FLOWREGIONBREAK(object)) {
+
+ is_line_break = true;
+ }
+ }
+
+ return is_line_break;
}
/** returns the attributes for an object, or NULL if it isn't a text,
-tspan or textpath. */
+tspan, tref, or textpath. */
static TextTagAttributes* attributes_for_object(SPObject *object)
{
if (SP_IS_TSPAN(object))
return &SP_TSPAN(object)->attributes;
if (SP_IS_TEXT(object))
return &SP_TEXT(object)->attributes;
+ if (SP_IS_TREF(object))
+ return &SP_TREF(object)->attributes;
if (SP_IS_TEXTPATH(object))
return &SP_TEXTPATH(object)->attributes;
return NULL;
unsigned length = 0;
if (SP_IS_STRING(item)) return SP_STRING(item)->string.length();
+
if (is_line_break_object(item)) length++;
+
for (SPObject const *child = item->firstChild() ; child ; child = SP_OBJECT_NEXT(child)) {
if (SP_IS_STRING(child)) length += SP_STRING(child)->string.length();
else length += sp_text_get_length(child);
{
unsigned length = 0;
+ // The string is the lowest level and the length can be counted directly.
if (SP_IS_STRING(item)) {
return SP_STRING(item)->string.length();
}
+
+ // Take care of new lines...
if (is_line_break_object(item) && !SP_IS_TEXT(item)) {
if (item != SP_OBJECT_PARENT(item)->firstChild()) {
// add 1 for each newline
length++;
}
}
+
+ // Count the length of the children
for (SPObject const *child = item->firstChild() ; child ; child = SP_OBJECT_NEXT(child)) {
if (upto && child == upto) {
// hit upto, return immediately
return length;
}
-static Inkscape::XML::Node* duplicate_node_without_children(Inkscape::XML::Node const *old_node)
+static Inkscape::XML::Node* duplicate_node_without_children(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node const *old_node)
{
switch (old_node->type()) {
case Inkscape::XML::ELEMENT_NODE: {
- Inkscape::XML::Node *new_node = sp_repr_new(old_node->name());
+ Inkscape::XML::Node *new_node = xml_doc->createElement(old_node->name());
Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attributes = old_node->attributeList();
GQuark const id_key = g_quark_from_string("id");
for ( ; attributes ; attributes++) {
@@ -235,10 +273,13 @@ static Inkscape::XML::Node* duplicate_node_without_children(Inkscape::XML::Node
}
case Inkscape::XML::TEXT_NODE:
- return sp_repr_new_text(old_node->content());
+ return xml_doc->createTextNode(old_node->content());
case Inkscape::XML::COMMENT_NODE:
- return sp_repr_new_comment(old_node->content());
+ return xml_doc->createComment(old_node->content());
+
+ case Inkscape::XML::PI_NODE:
+ return xml_doc->createPI(old_node->name(), old_node->content());
case Inkscape::XML::DOCUMENT_NODE:
return NULL; // this had better never happen
*/
static SPObject* split_text_object_tree_at(SPObject *split_obj, unsigned char_index)
{
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(split_obj));
if (is_line_break_object(split_obj)) {
- Inkscape::XML::Node *new_node = duplicate_node_without_children(SP_OBJECT_REPR(split_obj));
+ Inkscape::XML::Node *new_node = duplicate_node_without_children(xml_doc, SP_OBJECT_REPR(split_obj));
SP_OBJECT_REPR(SP_OBJECT_PARENT(split_obj))->addChild(new_node, SP_OBJECT_REPR(split_obj));
Inkscape::GC::release(new_node);
split_attributes(split_obj, SP_OBJECT_NEXT(split_obj), char_index);
@@ -285,7 +327,7 @@ static SPObject* split_text_object_tree_at(SPObject *split_obj, unsigned char_in
unsigned char_count_before = sum_sibling_text_lengths_before(split_obj);
SPObject *duplicate_obj = split_text_object_tree_at(SP_OBJECT_PARENT(split_obj), char_index + char_count_before);
// copy the split node
- Inkscape::XML::Node *new_node = duplicate_node_without_children(SP_OBJECT_REPR(split_obj));
+ Inkscape::XML::Node *new_node = duplicate_node_without_children(xml_doc, SP_OBJECT_REPR(split_obj));
SP_OBJECT_REPR(duplicate_obj)->appendChild(new_node);
Inkscape::GC::release(new_node);
@@ -315,40 +357,56 @@ Inkscape::Text::Layout::iterator sp_te_insert_line (SPItem *item, Inkscape::Text
{
// Disable newlines in a textpath; TODO: maybe on Enter in a textpath, separate it into two
// texpaths attached to the same path, with a vertical shift
- if (SP_IS_TEXT_TEXTPATH (item))
+ if (SP_IS_TEXT_TEXTPATH (item) || SP_IS_TREF(item))
return position;
+
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Inkscape::Text::Layout const *layout = te_get_layout(item);
- union { SPObject *op; void *vp; } split_obj;
+ SPObject *split_obj = 0;
Glib::ustring::iterator split_text_iter;
- if (position == layout->end())
- split_obj.vp = NULL;
- else
- layout->getSourceOfCharacter(position, &split_obj.vp, &split_text_iter);
-
- if (split_obj.vp == NULL || is_line_break_object(split_obj.op)) {
- if (split_obj.vp == NULL) split_obj.op = item->lastChild();
- if (split_obj.vp) {
- Inkscape::XML::Node *new_node = duplicate_node_without_children(SP_OBJECT_REPR(split_obj.op));
- SP_OBJECT_REPR(SP_OBJECT_PARENT(split_obj.op))->addChild(new_node, SP_OBJECT_REPR(split_obj.op));
+ if (position != layout->end()) {
+ void *rawptr = 0;
+ layout->getSourceOfCharacter(position, &rawptr, &split_text_iter);
+ split_obj = SP_OBJECT(rawptr);
+ }
+
+ if (split_obj == 0 || is_line_break_object(split_obj)) {
+ if (split_obj == 0) split_obj = item->lastChild();
+
+ if (SP_IS_TREF(split_obj)) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, tref_edit_message);
+ return position;
+ }
+
+ if (split_obj) {
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(split_obj));
+ Inkscape::XML::Node *new_node = duplicate_node_without_children(xml_doc, SP_OBJECT_REPR(split_obj));
+ SP_OBJECT_REPR(SP_OBJECT_PARENT(split_obj))->addChild(new_node, SP_OBJECT_REPR(split_obj));
Inkscape::GC::release(new_node);
}
- } else if (SP_IS_STRING(split_obj.op)) {
- Glib::ustring *string = &SP_STRING(split_obj.op)->string;
+ } else if (SP_IS_STRING(split_obj)) {
+ // If the parent is a tref, editing on this particular string is disallowed.
+ if (SP_IS_TREF(SP_OBJECT_PARENT(split_obj))) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, tref_edit_message);
+ return position;
+ }
+
+ Glib::ustring *string = &SP_STRING(split_obj)->string;
unsigned char_index = 0;
for (Glib::ustring::iterator it = string->begin() ; it != split_text_iter ; it++)
char_index++;
// we need to split the entire text tree into two
- SPString *new_string = SP_STRING(split_text_object_tree_at(split_obj.op, char_index));
+ SPString *new_string = SP_STRING(split_text_object_tree_at(split_obj, char_index));
SP_OBJECT_REPR(new_string)->setContent(&*split_text_iter.base()); // a little ugly
string->erase(split_text_iter, string->end());
- SP_OBJECT_REPR(split_obj.op)->setContent(string->c_str());
+ SP_OBJECT_REPR(split_obj)->setContent(string->c_str());
// TODO: if the split point was at the beginning of a span we have a whole load of empty elements to clean up
} else {
// TODO
// I think the only case to put here is arbitrary gaps, which nobody uses yet
}
- item->updateRepr(SP_OBJECT_REPR(item),SP_OBJECT_WRITE_EXT);
+ item->updateRepr();
unsigned char_index = layout->iteratorToCharIndex(position);
te_update_layout_now(item);
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
@@ -403,57 +461,74 @@ sp_te_insert(SPItem *item, Inkscape::Text::Layout::iterator const &position, gch
g_warning("Trying to insert invalid utf8");
return position;
}
+
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Inkscape::Text::Layout const *layout = te_get_layout(item);
- union { SPObject *op; void *vp; } source_obj;
+ SPObject *source_obj = 0;
+ void *rawptr = 0;
Glib::ustring::iterator iter_text;
// we want to insert after the previous char, not before the current char.
// it makes a difference at span boundaries
Inkscape::Text::Layout::iterator it_prev_char = position;
bool cursor_at_start = !it_prev_char.prevCharacter();
bool cursor_at_end = position == layout->end();
- layout->getSourceOfCharacter(it_prev_char, &source_obj.vp, &iter_text);
- if (SP_IS_STRING(source_obj.op)) {
- // the simple case
+ layout->getSourceOfCharacter(it_prev_char, &rawptr, &iter_text);
+ source_obj = SP_OBJECT(rawptr);
+ if (SP_IS_STRING(source_obj)) {
+ // If the parent is a tref, editing on this particular string is disallowed.
+ if (SP_IS_TREF(SP_OBJECT_PARENT(source_obj))) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, tref_edit_message);
+ return position;
+ }
+
+ // Now the simple case can begin...
if (!cursor_at_start) iter_text++;
- SPString *string_item = SP_STRING(source_obj.op);
+ SPString *string_item = SP_STRING(source_obj);
insert_into_spstring(string_item, cursor_at_end ? string_item->string.end() : iter_text, utf8);
} else {
// the not-so-simple case where we're at a line break or other control char; add to the next child/sibling SPString
+ Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(item)->document();
if (cursor_at_start) {
- source_obj.op = item;
- if (source_obj.op->hasChildren()) {
- source_obj.op = source_obj.op->firstChild();
+ source_obj = item;
+ if (source_obj->hasChildren()) {
+ source_obj = source_obj->firstChild();
if (SP_IS_FLOWTEXT(item)) {
- while (SP_IS_FLOWREGION(source_obj.op) || SP_IS_FLOWREGIONEXCLUDE(source_obj.op))
- source_obj.op = SP_OBJECT_NEXT(source_obj.op);
- if (source_obj.vp == NULL)
- source_obj.op = item;
+ while (SP_IS_FLOWREGION(source_obj) || SP_IS_FLOWREGIONEXCLUDE(source_obj))
+ source_obj = SP_OBJECT_NEXT(source_obj);
+ if (source_obj == NULL)
+ source_obj = item;
}
}
- if (source_obj.op == item && SP_IS_FLOWTEXT(item)) {
- Inkscape::XML::Node *para = sp_repr_new("svg:flowPara");
+ if (source_obj == item && SP_IS_FLOWTEXT(item)) {
+ Inkscape::XML::Node *para = xml_doc->createElement("svg:flowPara");
SP_OBJECT_REPR(item)->appendChild(para);
- source_obj.op = item->lastChild();
+ source_obj = item->lastChild();
}
} else
- source_obj.op = SP_OBJECT_NEXT(source_obj.op);
+ source_obj = SP_OBJECT_NEXT(source_obj);
- if (source_obj.vp) { // never fails
- SPString *string_item = sp_te_seek_next_string_recursive(source_obj.op);
+ if (source_obj) { // never fails
+ SPString *string_item = sp_te_seek_next_string_recursive(source_obj);
if (string_item == NULL) {
// need to add an SPString in this (pathological) case
- Inkscape::XML::Node *rstring = sp_repr_new_text("");
- SP_OBJECT_REPR(source_obj.op)->addChild(rstring, NULL);
+ Inkscape::XML::Node *rstring = xml_doc->createTextNode("");
+ SP_OBJECT_REPR(source_obj)->addChild(rstring, NULL);
Inkscape::GC::release(rstring);
- g_assert(SP_IS_STRING(source_obj.op->firstChild()));
- string_item = SP_STRING(source_obj.op->firstChild());
+ g_assert(SP_IS_STRING(source_obj->firstChild()));
+ string_item = SP_STRING(source_obj->firstChild());
+ }
+ // If the parent is a tref, editing on this particular string is disallowed.
+ if (SP_IS_TREF(SP_OBJECT_PARENT(string_item))) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, tref_edit_message);
+ return position;
}
+
insert_into_spstring(string_item, cursor_at_end ? string_item->string.end() : string_item->string.begin(), utf8);
}
}
- item->updateRepr(SP_OBJECT_REPR(item),SP_OBJECT_WRITE_EXT);
+ item->updateRepr();
unsigned char_index = layout->iteratorToCharIndex(position);
te_update_layout_now(item);
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
@@ -520,7 +595,8 @@ static SPObject* delete_line_break(SPObject *root, SPObject *item, bool *next_is
<p><div></div>*text</p>
<p><div></div></p><p>*text</p>
*/
- Inkscape::XML::Node *new_span_repr = sp_repr_new(span_name_for_text_object(root));
+ Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(item)->document();
+ Inkscape::XML::Node *new_span_repr = xml_doc->createElement(span_name_for_text_object(root));
if (gchar const *a = this_repr->attribute("dx"))
new_span_repr->setAttribute("dx", a);
@@ -610,60 +686,82 @@ static void erase_from_spstring(SPString *string_item, Glib::ustring::iterator i
quite a complicated operation, partly due to the cleanup that is done if all
the text in a subobject has been deleted, and partly due to the difficulty
of figuring out what is a line break and how to delete one. Returns the
-lesser of \a start and \a end, because that is where the cursor should be
-put after the deletion is done. */
-Inkscape::Text::Layout::iterator
-sp_te_delete (SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end)
+real start and ending iterators based on the situation. */
+bool
+sp_te_delete (SPItem *item, Inkscape::Text::Layout::iterator const &start,
+ Inkscape::Text::Layout::iterator const &end, iterator_pair &iter_pair)
{
- if (start == end) return start;
- Inkscape::Text::Layout::iterator first, last;
- if (start < end) {
- first = start;
- last = end;
- } else {
- first = end;
- last = start;
+ bool success = false;
+
+ iter_pair.first = start;
+ iter_pair.second = end;
+
+ if (start == end) return success;
+
+ if (start > end) {
+ iter_pair.first = end;
+ iter_pair.second = start;
}
+
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+
Inkscape::Text::Layout const *layout = te_get_layout(item);
- union { SPObject *op; void *vp; } start_item, end_item;
+ SPObject *start_item = 0, *end_item = 0;
+ void *rawptr = 0;
Glib::ustring::iterator start_text_iter, end_text_iter;
- layout->getSourceOfCharacter(first, &start_item.vp, &start_text_iter);
- layout->getSourceOfCharacter(last, &end_item.vp, &end_text_iter);
- if (start_item.vp == NULL)
- return first; // start is at end of text
- if (is_line_break_object(start_item.op))
- move_to_end_of_paragraph(&start_item.op, &start_text_iter);
- if (end_item.vp == NULL) {
- end_item.op = item->lastChild();
- move_to_end_of_paragraph(&end_item.op, &end_text_iter);
+ layout->getSourceOfCharacter(iter_pair.first, &rawptr, &start_text_iter);
+ start_item = SP_OBJECT(rawptr);
+ layout->getSourceOfCharacter(iter_pair.second, &rawptr, &end_text_iter);
+ end_item = SP_OBJECT(rawptr);
+ if (start_item == 0)
+ return success; // start is at end of text
+ if (is_line_break_object(start_item))
+ move_to_end_of_paragraph(&start_item, &start_text_iter);
+ if (end_item == 0) {
+ end_item = item->lastChild();
+ move_to_end_of_paragraph(&end_item, &end_text_iter);
}
- else if (is_line_break_object(end_item.op))
- move_to_end_of_paragraph(&end_item.op, &end_text_iter);
+ else if (is_line_break_object(end_item))
+ move_to_end_of_paragraph(&end_item, &end_text_iter);
- SPObject *common_ancestor = get_common_ancestor(item, start_item.op, end_item.op);
+ SPObject *common_ancestor = get_common_ancestor(item, start_item, end_item);
- if (start_item.op == end_item.op) {
+ if (start_item == end_item) {
// the quick case where we're deleting stuff all from the same string
- if (SP_IS_STRING(start_item.op)) { // always true (if it_start != it_end anyway)
- erase_from_spstring(SP_STRING(start_item.op), start_text_iter, end_text_iter);
+ if (SP_IS_STRING(start_item)) { // always true (if it_start != it_end anyway)
+ // If the parent is a tref, editing on this particular string is disallowed.
+ if (SP_IS_TREF(SP_OBJECT_PARENT(start_item))) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, tref_edit_message);
+ } else {
+ erase_from_spstring(SP_STRING(start_item), start_text_iter, end_text_iter);
+ success = true;
+ }
}
} else {
- SPObject *sub_item = start_item.op;
+ SPObject *sub_item = start_item;
// walk the tree from start_item to end_item, deleting as we go
while (sub_item != item) {
- if (sub_item == end_item.op) {
+ if (sub_item == end_item) {
if (SP_IS_STRING(sub_item)) {
+ // If the parent is a tref, editing on this particular string is disallowed.
+ if (SP_IS_TREF(SP_OBJECT_PARENT(sub_item))) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, tref_edit_message);
+ break;
+ }
+
Glib::ustring *string = &SP_STRING(sub_item)->string;
erase_from_spstring(SP_STRING(sub_item), string->begin(), end_text_iter);
+ success = true;
}
break;
}
if (SP_IS_STRING(sub_item)) {
SPString *string = SP_STRING(sub_item);
- if (sub_item == start_item.op)
+ if (sub_item == start_item)
erase_from_spstring(string, start_text_iter, string->string.end());
else
erase_from_spstring(string, string->string.begin(), string->string.end());
+ success = true;
}
// walk to the next item in the tree
if (sub_item->hasChildren())
@@ -684,16 +782,17 @@ sp_te_delete (SPItem *item, Inkscape::Text::Layout::iterator const &start, Inksc
sub_item = next_item;
if (is_sibling) break;
// no more siblings, go up a parent
- } while (sub_item != item && sub_item != end_item.op);
+ } while (sub_item != item && sub_item != end_item);
}
}
}
- while (tidy_xml_tree_recursively(common_ancestor));
+ while (tidy_xml_tree_recursively(common_ancestor)){};
te_update_layout_now(item);
item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
- layout->validateIterator(&first);
- return first;
+ layout->validateIterator(&iter_pair.first);
+ layout->validateIterator(&iter_pair.second);
+ return success;
}
@@ -749,10 +848,12 @@ sp_te_get_string_multiline (SPItem const *text, Inkscape::Text::Layout::iterator
Glib::ustring result;
// not a particularly fast piece of code. I'll optimise it if people start to notice.
for ( ; first < last ; first.nextCharacter()) {
- union { SPObject *op; void *vp; } char_item;
+ SPObject *char_item = 0;
+ void *rawptr = 0;
Glib::ustring::iterator text_iter;
- layout->getSourceOfCharacter(first, &char_item.vp, &text_iter);
- if (SP_IS_STRING(char_item.op))
+ layout->getSourceOfCharacter(first, &rawptr, &text_iter);
+ char_item = SP_OBJECT(rawptr);
+ if (SP_IS_STRING(char_item))
result += *text_iter;
else
result += '\n';
g_return_if_fail (text != NULL);
g_return_if_fail (SP_IS_TEXT(text) || SP_IS_FLOWTEXT(text));
+ Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(text)->document();
Inkscape::XML::Node *repr;
SPObject *object;
bool is_textpath = false;
if (e) *e = '\0';
Inkscape::XML::Node *rtspan;
if (SP_IS_TEXT(text)) { // create a tspan for each line
- rtspan = sp_repr_new ("svg:tspan");
+ rtspan = xml_doc->createElement("svg:tspan");
rtspan->setAttribute("sodipodi:role", "line");
} else { // create a flowPara for each line
- rtspan = sp_repr_new ("svg:flowPara");
+ rtspan = xml_doc->createElement("svg:flowPara");
}
- Inkscape::XML::Node *rstr = sp_repr_new_text(p);
+ Inkscape::XML::Node *rstr = xml_doc->createTextNode(p);
rtspan->addChild(rstr, NULL);
Inkscape::GC::release(rstr);
repr->appendChild(rtspan);
p = (e) ? e + 1 : NULL;
}
if (is_textpath) {
- Inkscape::XML::Node *rstr = sp_repr_new_text(content);
+ Inkscape::XML::Node *rstr = xml_doc->createTextNode(content);
repr->addChild(rstr, NULL);
Inkscape::GC::release(rstr);
}
@@ -833,27 +935,29 @@ text_tag_attributes_at_position(SPItem *item, Inkscape::Text::Layout::iterator c
return NULL; // flowtext doesn't support kerning yet
SPText *text = SP_TEXT(item);
- union { SPObject *op; void *vp; } source_item;
+ SPObject *source_item = 0;
+ void *rawptr = 0;
Glib::ustring::iterator source_text_iter;
- text->layout.getSourceOfCharacter(position, &source_item.vp, &source_text_iter);
+ text->layout.getSourceOfCharacter(position, &rawptr, &source_text_iter);
+ source_item = SP_OBJECT(rawptr);
- if (!SP_IS_STRING(source_item.op)) return NULL;
- Glib::ustring *string = &SP_STRING(source_item.op)->string;
- *char_index = sum_sibling_text_lengths_before(source_item.op);
+ if (!SP_IS_STRING(source_item)) return NULL;
+ Glib::ustring *string = &SP_STRING(source_item)->string;
+ *char_index = sum_sibling_text_lengths_before(source_item);
for (Glib::ustring::iterator it = string->begin() ; it != source_text_iter ; it++)
++*char_index;
- return attributes_for_object(SP_OBJECT_PARENT(source_item.op));
+ return attributes_for_object(SP_OBJECT_PARENT(source_item));
}
void
-sp_te_adjust_kerning_screen (SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop *desktop, NR::Point by)
+sp_te_adjust_kerning_screen (SPItem *item, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop *desktop, Geom::Point by)
{
// divide increment by zoom
// divide increment by matrix expansion
gdouble factor = 1 / desktop->current_zoom();
- NR::Matrix t = sp_item_i2doc_affine(item);
- factor = factor / NR::expansion(t);
+ Geom::Matrix t (sp_item_i2doc_affine(item));
+ factor = factor / t.descrim();
by = factor * by;
unsigned char_index;
@@ -874,20 +978,22 @@ sp_te_adjust_rotation_screen(SPItem *text, Inkscape::Text::Layout::iterator cons
// divide increment by zoom
// divide increment by matrix expansion
gdouble factor = 1 / desktop->current_zoom();
- NR::Matrix t = sp_item_i2doc_affine(text);
- factor = factor / NR::expansion(t);
- union { SPObject *op; void *vp; } source_item;
+ Geom::Matrix t (sp_item_i2doc_affine(text));
+ factor = factor / t.descrim();
Inkscape::Text::Layout const *layout = te_get_layout(text);
if (layout == NULL) return;
- layout->getSourceOfCharacter(std::min(start, end), &source_item.vp);
- if (source_item.op == NULL) return;
- gdouble degrees = (180/M_PI) * atan2(pixels, SP_OBJECT_PARENT(source_item.op)->style->font_size.computed / factor);
+ SPObject *source_item = 0;
+ void *rawptr = 0;
+ layout->getSourceOfCharacter(std::min(start, end), &rawptr);
+ source_item = SP_OBJECT(rawptr);
+ if (source_item == 0) return;
+ gdouble degrees = (180/M_PI) * atan2(pixels, SP_OBJECT_PARENT(source_item)->style->font_size.computed / factor);
sp_te_adjust_rotation(text, start, end, desktop, degrees);
}
void
-sp_te_adjust_rotation(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop *desktop, gdouble degrees)
+sp_te_adjust_rotation(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop */*desktop*/, gdouble degrees)
{
unsigned char_index;
TextTagAttributes *attributes = text_tag_attributes_at_position(text, std::min(start, end), &char_index);
@@ -914,18 +1020,20 @@ sp_te_adjust_tspan_letterspacing_screen(SPItem *text, Inkscape::Text::Layout::it
Inkscape::Text::Layout const *layout = te_get_layout(text);
gdouble val;
- union { SPObject *op; void *vp; } source_obj;
+ SPObject *source_obj = 0;
+ void *rawptr = 0;
unsigned nb_let;
- layout->getSourceOfCharacter(std::min(start, end), &source_obj.vp);
+ layout->getSourceOfCharacter(std::min(start, end), &rawptr);
+ source_obj = SP_OBJECT(rawptr);
- if (source_obj.vp == NULL) { // end of text
- source_obj.op = text->lastChild();
+ if (source_obj == 0) { // end of text
+ source_obj = text->lastChild();
}
- if (SP_IS_STRING(source_obj.op)) {
- source_obj.op = source_obj.op->parent;
+ if (SP_IS_STRING(source_obj)) {
+ source_obj = source_obj->parent;
}
- SPStyle *style = SP_OBJECT_STYLE (source_obj.op);
+ SPStyle *style = SP_OBJECT_STYLE (source_obj);
// calculate real value
/* TODO: Consider calculating val unconditionally, i.e. drop the first `if' line, and
@@ -943,9 +1051,9 @@ sp_te_adjust_tspan_letterspacing_screen(SPItem *text, Inkscape::Text::Layout::it
}
if (start == end) {
- while (!is_line_break_object(source_obj.op)) // move up the tree so we apply to the closest paragraph
- source_obj.op = SP_OBJECT_PARENT(source_obj.op);
- nb_let = sp_text_get_length(source_obj.op);
+ while (!is_line_break_object(source_obj)) // move up the tree so we apply to the closest paragraph
+ source_obj = SP_OBJECT_PARENT(source_obj);
+ nb_let = sp_text_get_length(source_obj);
} else {
nb_let = abs(layout->iteratorToCharIndex(end) - layout->iteratorToCharIndex(start));
}
@@ -955,7 +1063,7 @@ sp_te_adjust_tspan_letterspacing_screen(SPItem *text, Inkscape::Text::Layout::it
gdouble const zoom = desktop->current_zoom();
gdouble const zby = (by
/ (zoom * (nb_let > 1 ? nb_let - 1 : 1))
- / NR::expansion(sp_item_i2doc_affine(SP_ITEM(source_obj.op))));
+ / to_2geom(sp_item_i2doc_affine(SP_ITEM(source_obj))).descrim());
val += zby;
if (start == end) {
@@ -986,8 +1094,21 @@ sp_te_adjust_tspan_letterspacing_screen(SPItem *text, Inkscape::Text::Layout::it
text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG);
}
+double
+sp_te_get_average_linespacing (SPItem *text)
+{
+ Inkscape::Text::Layout const *layout = te_get_layout(text);
+ if (!layout)
+ return 0;
+
+ unsigned line_count = layout->lineIndex(layout->end());
+ double all_lines_height = layout->characterAnchorPoint(layout->end())[Geom::Y] - layout->characterAnchorPoint(layout->begin())[Geom::Y];
+ double average_line_height = all_lines_height / (line_count == 0 ? 1 : line_count);
+ return average_line_height;
+}
+
void
-sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPDesktop *desktop, gdouble by)
+sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator const &/*start*/, Inkscape::Text::Layout::iterator const &/*end*/, SPDesktop *desktop, gdouble by)
{
// TODO: use start and end iterators to delineate the area to be affected
g_return_if_fail (text != NULL);
@@ -1005,7 +1126,7 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator
}
unsigned line_count = layout->lineIndex(layout->end());
- double all_lines_height = layout->characterAnchorPoint(layout->end())[NR::Y] - layout->characterAnchorPoint(layout->begin())[NR::Y];
+ double all_lines_height = layout->characterAnchorPoint(layout->end())[Geom::Y] - layout->characterAnchorPoint(layout->begin())[Geom::Y];
double average_line_height = all_lines_height / (line_count == 0 ? 1 : line_count);
if (fabs(average_line_height) < 0.001) average_line_height = 0.001;
@@ -1014,8 +1135,8 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator
gdouble zby = by / (desktop->current_zoom() * (line_count == 0 ? 1 : line_count));
// divide increment by matrix expansion
- NR::Matrix t = sp_item_i2doc_affine (SP_ITEM(text));
- zby = zby / NR::expansion(t);
+ Geom::Matrix t (sp_item_i2doc_affine (SP_ITEM(text)));
+ zby = zby / t.descrim();
switch (style->line_height.unit) {
case SP_CSS_UNIT_NONE:
@@ -1033,27 +1154,27 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator
else style->line_height.value *= (average_line_height + zby) / average_line_height;
break;
// absolute-type units
- case SP_CSS_UNIT_PX:
+ case SP_CSS_UNIT_PX:
style->line_height.computed += zby;
style->line_height.value = style->line_height.computed;
break;
- case SP_CSS_UNIT_PT:
+ case SP_CSS_UNIT_PT:
style->line_height.computed += zby * PT_PER_PX;
style->line_height.value = style->line_height.computed;
break;
- case SP_CSS_UNIT_PC:
+ case SP_CSS_UNIT_PC:
style->line_height.computed += zby * (PT_PER_PX / 12);
style->line_height.value = style->line_height.computed;
break;
- case SP_CSS_UNIT_MM:
+ case SP_CSS_UNIT_MM:
style->line_height.computed += zby * MM_PER_PX;
style->line_height.value = style->line_height.computed;
break;
- case SP_CSS_UNIT_CM:
+ case SP_CSS_UNIT_CM:
style->line_height.computed += zby * CM_PER_PX;
style->line_height.value = style->line_height.computed;
break;
- case SP_CSS_UNIT_IN:
+ case SP_CSS_UNIT_IN:
style->line_height.computed += zby * IN_PER_PX;
style->line_height.value = style->line_height.computed;
break;
underneath the existing styles (ie ignoring already set properties). */
static void overwrite_style_with_string(SPObject *item, gchar const *style_string)
{
- SPStyle *new_style = sp_style_new();
+ SPStyle *new_style = sp_style_new(SP_OBJECT_DOCUMENT(item));
sp_style_merge_from_style_string(new_style, style_string);
gchar const *item_style_string = SP_OBJECT_REPR(item)->attribute("style");
if (item_style_string && *item_style_string)
@@ -1107,7 +1228,7 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi
gchar *parent_style = sp_style_write_string(parent->style, SP_STYLE_FLAG_ALWAYS);
// we have to write parent_style then read it again, because some properties format their values
// differently depending on whether they're set or not (*cough*dash-offset*cough*)
- SPStyle *parent_spstyle = sp_style_new();
+ SPStyle *parent_spstyle = sp_style_new(SP_OBJECT_DOCUMENT(parent));
sp_style_merge_from_style_string(parent_spstyle, parent_style);
g_free(parent_style);
parent_style = sp_style_write_string(parent_spstyle, SP_STYLE_FLAG_ALWAYS);
@@ -1123,7 +1244,7 @@ static bool objects_have_equal_style(SPObject const *parent, SPObject const *chi
}
child = SP_OBJECT_PARENT(child);
}
- SPStyle *child_spstyle = sp_style_new();
+ SPStyle *child_spstyle = sp_style_new(SP_OBJECT_DOCUMENT(parent));
sp_style_merge_from_style_string(child_spstyle, child_style_construction.c_str());
gchar *child_style = sp_style_write_string(child_spstyle, SP_STYLE_FLAG_ALWAYS);
sp_style_unref(child_spstyle);
static void recursively_apply_style(SPObject *common_ancestor, SPCSSAttr const *css, SPObject *start_item, Glib::ustring::iterator start_text_iter, SPObject *end_item, Glib::ustring::iterator end_text_iter, char const *span_object_name)
{
bool passed_start = start_item == NULL ? true : false;
-
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(common_ancestor));
+
for (SPObject *child = common_ancestor->firstChild() ; child != NULL ; child = SP_OBJECT_NEXT(child)) {
if (start_item == child)
passed_start = true;
@@ -1202,7 +1324,7 @@ static void recursively_apply_style(SPObject *common_ancestor, SPCSSAttr const *
SPString *string_item = SP_STRING(child);
bool surround_entire_string = true;
- Inkscape::XML::Node *child_span = sp_repr_new(span_object_name);
+ Inkscape::XML::Node *child_span = xml_doc->createElement(span_object_name);
sp_repr_css_set(child_span, const_cast<SPCSSAttr*>(css), "style"); // better hope that prototype wasn't nonconst for a good reason
SPObject *prev_item = SP_OBJECT_PREV(child);
Inkscape::XML::Node *prev_repr = prev_item ? SP_OBJECT_REPR(prev_item) : NULL;
@@ -1214,11 +1336,11 @@ static void recursively_apply_style(SPObject *common_ancestor, SPCSSAttr const *
unsigned start_char_index = char_index_of_iterator(string_item->string, start_text_iter);
unsigned end_char_index = char_index_of_iterator(string_item->string, end_text_iter);
- Inkscape::XML::Node *text_before = sp_repr_new_text(string_item->string.substr(0, start_char_index).c_str());
+ Inkscape::XML::Node *text_before = xml_doc->createTextNode(string_item->string.substr(0, start_char_index).c_str());
SP_OBJECT_REPR(common_ancestor)->addChild(text_before, prev_repr);
SP_OBJECT_REPR(common_ancestor)->addChild(child_span, text_before);
Inkscape::GC::release(text_before);
- Inkscape::XML::Node *text_in_span = sp_repr_new_text(string_item->string.substr(start_char_index, end_char_index - start_char_index).c_str());
+ Inkscape::XML::Node *text_in_span = xml_doc->createTextNode(string_item->string.substr(start_char_index, end_char_index - start_char_index).c_str());
child_span->appendChild(text_in_span);
Inkscape::GC::release(text_in_span);
SP_OBJECT_REPR(child)->setContent(string_item->string.substr(end_char_index).c_str());
@@ -1230,7 +1352,7 @@ static void recursively_apply_style(SPObject *common_ancestor, SPCSSAttr const *
unsigned end_char_index = char_index_of_iterator(string_item->string, end_text_iter);
SP_OBJECT_REPR(common_ancestor)->addChild(child_span, prev_repr);
- Inkscape::XML::Node *text_in_span = sp_repr_new_text(string_item->string.substr(0, end_char_index).c_str());
+ Inkscape::XML::Node *text_in_span = xml_doc->createTextNode(string_item->string.substr(0, end_char_index).c_str());
child_span->appendChild(text_in_span);
Inkscape::GC::release(text_in_span);
SP_OBJECT_REPR(child)->setContent(string_item->string.substr(end_char_index).c_str());
@@ -1239,11 +1361,11 @@ static void recursively_apply_style(SPObject *common_ancestor, SPCSSAttr const *
// eg "abcDEF" -> "abc"<span>"DEF"</span>
unsigned start_char_index = char_index_of_iterator(string_item->string, start_text_iter);
- Inkscape::XML::Node *text_before = sp_repr_new_text(string_item->string.substr(0, start_char_index).c_str());
+ Inkscape::XML::Node *text_before = xml_doc->createTextNode(string_item->string.substr(0, start_char_index).c_str());
SP_OBJECT_REPR(common_ancestor)->addChild(text_before, prev_repr);
SP_OBJECT_REPR(common_ancestor)->addChild(child_span, text_before);
Inkscape::GC::release(text_before);
- Inkscape::XML::Node *text_in_span = sp_repr_new_text(string_item->string.substr(start_char_index).c_str());
+ Inkscape::XML::Node *text_in_span = xml_doc->createTextNode(string_item->string.substr(start_char_index).c_str());
child_span->appendChild(text_in_span);
Inkscape::GC::release(text_in_span);
child->deleteObject();
the repeated strings will be merged by another operator. */
static bool tidy_operator_inexplicable_spans(SPObject **item)
{
+ if (*item && sp_repr_is_meta_element((*item)->repr)) return false;
if (SP_IS_STRING(*item)) return false;
if (is_line_break_object(*item)) return false;
TextTagAttributes *attrs = attributes_for_object(*item);
@@ -1424,8 +1547,9 @@ static bool redundant_double_nesting_processor(SPObject **item, SPObject *child,
if (!objects_have_equal_style(SP_OBJECT_PARENT(*item), child)) return false;
Inkscape::XML::Node *insert_after_repr;
- if (prepend) insert_after_repr = SP_OBJECT_REPR(SP_OBJECT_PREV(*item));
- else insert_after_repr = SP_OBJECT_REPR(*item);
+ if (!prepend) insert_after_repr = SP_OBJECT_REPR(*item);
+ else if (SP_OBJECT_PREV(*item)) insert_after_repr = SP_OBJECT_REPR(SP_OBJECT_PREV(*item));
+ else insert_after_repr = NULL;
while (SP_OBJECT_REPR(child)->childCount()) {
Inkscape::XML::Node *move_repr = SP_OBJECT_REPR(child)->firstChild();
Inkscape::GC::anchor(move_repr);
@@ -1487,7 +1611,8 @@ static bool redundant_semi_nesting_processor(SPObject **item, SPObject *child, b
sp_repr_css_attr_unref(css_child_only);
if (!equal) return false;
- Inkscape::XML::Node *new_span = sp_repr_new(SP_OBJECT_REPR(*item)->name());
+ Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(*item)->document();
+ Inkscape::XML::Node *new_span = xml_doc->createElement(SP_OBJECT_REPR(*item)->name());
if (prepend) {
SPObject *prev = SP_OBJECT_PREV(*item);
SP_OBJECT_REPR(SP_OBJECT_PARENT(*item))->addChild(new_span, prev ? SP_OBJECT_REPR(prev) : NULL);
for ( ; ; ) { // go up one item in the xml
test_item = SP_OBJECT_PARENT(test_item);
if (is_line_break_object(test_item)) break;
+ if (SP_IS_FLOWTEXT(test_item)) return false;
SPObject *next = SP_OBJECT_NEXT(test_item);
if (next) {
test_item = next;
bool changes = false;
for (SPObject *child = root->firstChild() ; child != NULL ; ) {
- if (SP_IS_FLOWREGION(child) || SP_IS_FLOWREGIONEXCLUDE(child)) {
+ if (SP_IS_FLOWREGION(child) || SP_IS_FLOWREGIONEXCLUDE(child) || SP_IS_TREF(child)) {
child = SP_OBJECT_NEXT(child);
continue;
}
@@ -1646,17 +1772,30 @@ void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &sta
last = start;
}
Inkscape::Text::Layout const *layout = te_get_layout(text);
- union { SPObject *op; void *vp; } start_item, end_item;
+ SPObject *start_item = 0, *end_item = 0;
+ void *rawptr = 0;
Glib::ustring::iterator start_text_iter, end_text_iter;
- layout->getSourceOfCharacter(first, &start_item.vp, &start_text_iter);
- layout->getSourceOfCharacter(last, &end_item.vp, &end_text_iter);
- if (start_item.vp == NULL)
+ layout->getSourceOfCharacter(first, &rawptr, &start_text_iter);
+ start_item = SP_OBJECT(rawptr);
+ layout->getSourceOfCharacter(last, &rawptr, &end_text_iter);
+ end_item = SP_OBJECT(rawptr);
+ if (start_item == 0)
return; // start is at end of text
- if (is_line_break_object(start_item.op))
- start_item.op = SP_OBJECT_NEXT(start_item.op);
- if (is_line_break_object(end_item.op))
- end_item.op = SP_OBJECT_NEXT(end_item.op);
- if (end_item.op == NULL) end_item.op = text;
+ if (is_line_break_object(start_item))
+ start_item = SP_OBJECT_NEXT(start_item);
+ if (is_line_break_object(end_item))
+ end_item = SP_OBJECT_NEXT(end_item);
+ if (end_item == 0) end_item = text;
+
+
+ /* Special case: With a tref, we only want to change its style when the whole
+ * string is selected, in which case the style can be applied directly to the
+ * tref node. If only part of the tref's string child is selected, just return. */
+
+ if (!sp_tref_fully_contained(start_item, start_text_iter, end_item, end_text_iter)) {
+
+ return;
+ }
/* stage 1: applying the style. Go up to the closest common ancestor of
start and end and then semi-recursively apply the style to all the
@@ -1666,10 +1805,25 @@ void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &sta
eg: <span>abcDEF</span><span>GHI</span><span>JKLmno</span>
The recursion may involve creating new spans.
*/
- SPObject *common_ancestor = get_common_ancestor(text, start_item.op, end_item.op);
- start_item.op = ascend_while_first(start_item.op, start_text_iter, common_ancestor);
- end_item.op = ascend_while_first(end_item.op, end_text_iter, common_ancestor);
- recursively_apply_style(common_ancestor, css, start_item.op, start_text_iter, end_item.op, end_text_iter, span_name_for_text_object(text));
+ SPObject *common_ancestor = get_common_ancestor(text, start_item, end_item);
+
+ // bug #168370 (consider parent transform and viewBox)
+ // snipplet copied from desktop-style.cpp sp_desktop_apply_css_recursive(...)
+ SPCSSAttr *css_set = sp_repr_css_attr_new();
+ sp_repr_css_merge(css_set, (SPCSSAttr*) css);
+ {
+ Geom::Matrix const local(sp_item_i2doc_affine(SP_ITEM(common_ancestor)));
+ double const ex(local.descrim());
+ if ( ( ex != 0. )
+ && ( ex != 1. ) ) {
+ sp_css_attr_scale(css_set, 1/ex);
+ }
+ }
+
+ start_item = ascend_while_first(start_item, start_text_iter, common_ancestor);
+ end_item = ascend_while_first(end_item, end_text_iter, common_ancestor);
+ recursively_apply_style(common_ancestor, css_set, start_item, start_text_iter, end_item, end_text_iter, span_name_for_text_object(text));
+ sp_repr_css_attr_unref(css_set);
/* stage 2: cleanup the xml tree (of which there are multiple passes) */
/* discussion: this stage requires a certain level of inventiveness because
@@ -1683,7 +1837,7 @@ 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));
+ while (tidy_xml_tree_recursively(common_ancestor)){};
// if we only modified subobjects this won't have been automatically sent
text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG);