Incorrect handling of <text> without <tspan>

Bug #167904 reported by Norbert Nemec
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
Invalid
Low
Unassigned

Bug Description

The attached file contains three text objects:

"breakable text"
is a usual piece of text, created in inkscape that
behaves fine

"broken text"
is a two-line text object that works fine as well

"unbreakable text" is a piece of text that was created
by matplotlib. It looks identical to the breakable text
but behaves very strangely on editing:
* when the cursor is at the end of the text, one cannot
insert spaces
* pressing newline within the text breaks the text in
two lines that are placed *on top of each other*

Internally, the "unbreakable text" is correct SVG, that
does not use the <tspan> tag. Inkscape never produces
such text objects itself, but when importing, it seems
to preserve the internal structure and then has
problems with it.

Revision history for this message
Norbert Nemec (nnemec) wrote :
Revision history for this message
Norbert Nemec (nnemec) wrote :

Further explanation:
Inkscape obviously expects all text object to be wrapped by
<tspan>. SVG does not require this for single-line,
single-format text elements.

In other words: Objects like
   <text x="0" y="0">Hello world!</text>
can never occur in Inkscape-created documents, but they may
be imported as legal SVG and are then incorrectly handled by
Inkscape.

Revision history for this message
Hystrix (hystrix-) wrote :

Confirmed with Inkscape 0.46dev+devel, built Dec 18 2007

Changed in inkscape:
importance: Undecided → Low
status: New → Confirmed
Changed in inkscape:
assignee: nobody → Jimmy Varvaro (supershospy)
Changed in inkscape:
status: Confirmed → In Progress
Revision history for this message
Jimmy Varvaro (supershospy) wrote :

Patch in progress:
// Lets say that move_child_nodes is declared before sp_te_insert_line so it is available
// This was changed from a const
Inkscape::Text::Layout *layout = (Inkscape::Text::Layout*)te_get_layout(item);
//...

if(strcmp(SP_OBJECT_REPR(SP_OBJECT_PARENT(split_obj))->name(), "svg:text") == 0) {

    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(split_obj));
    Inkscape::XML::Node *rtspan;

    Inkscape::XML::Node *repr = SP_OBJECT_REPR(split_obj);
    Inkscape::XML::Node *parent = sp_repr_parent(repr);

    Glib::ustring *string = &SP_STRING(split_obj)->string;

    rtspan = xml_doc->createElement("svg:tspan");
    rtspan->setAttribute("sodipodi:role", "line");
    rtspan->setAttribute("x", SP_OBJECT_REPR(SP_OBJECT_PARENT(split_obj))->attribute("x"));
    rtspan->setAttribute("y", SP_OBJECT_REPR(SP_OBJECT_PARENT(split_obj))->attribute("y"));

    move_child_nodes(parent, rtspan);
    parent->addChild(rtspan, NULL);
    Inkscape::GC::release(rtspan);

    item->updateRepr();
    te_update_layout_now(item);
    item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
    layout = (Inkscape::Text::Layout*)te_get_layout(item);
       if (position != layout->end()) {
           void *rawptr = 0;
           layout->getSourceOfCharacter(position, &rawptr, &split_text_iter);
    split_obj = SP_OBJECT(rawptr);
       }
    string = &SP_STRING(split_obj)->string;
}
//-------------- End of modifications---------------------
// Iterators in question (Crash occurs here in infinity loop when they occur)
unsigned char_index = 0;
        for (Glib::ustring::iterator it = string->begin() ; it != split_text_iter ; it++) {
   std::cout << "your problem on a stick IT: " << *it << std::endl;
   std::cout << "your problem on a stick: SPLIT" << *split_text_iter << std::endl;
            char_index++;
  }

//... To rest of function

The patch works, with some issues.
(Note I didn't handle the space at end problem or line break at end problem yet, but I will after this is taken care of)
Any input on why the Iterator decided to freak out after certain actions such as: line break - undo - line break (in succession), and the selection of the text box followed by the movement of the cursor with the keyboard before a line break. I would be grateful for comments and tips on this patch.

su_v (suv-lp)
tags: added: text
Changed in inkscape:
assignee: Jimmy Varvaro (supershospy) → nobody
Revision history for this message
su_v (suv-lp) wrote :

@Jimmy Varvaro - are you still working on the patch? Could you attach it as diff file against current trunk to allow testing and reviewing of the proposed changes?

If you have questions about the current code, please do consider asking on the 'inkscape-devel' mailing list:
<https://lists.sourceforge.net/lists/listinfo/inkscape-devel>

Changed in inkscape:
status: In Progress → Incomplete
Revision history for this message
su_v (suv-lp) wrote :

No more feedback, reverting to 'Triaged'.

Changed in inkscape:
status: Incomplete → Triaged
Revision history for this message
su_v (suv-lp) wrote :

Related newer reports wrt to editing <text> objects without <tspan> or with <tspan> but missing 'sodipodi:role' attribute:
Bug #276456 “Extension bug at creating text elements”
Bug #446952 "problem when selecting whole text and start typing”

Revision history for this message
su_v (suv-lp) wrote :

Both issues
* when the cursor is at the end of the text, one cannot insert spaces
* pressing newline within the text breaks the text in two lines that are placed *on top of each other
also reported in bug #167647.

Revision history for this message
quazgar (quazgar) wrote :

Still confirmed with 0.92 on Debian testing.

Revision history for this message
Patrick Storz (ede123) wrote :
Changed in inkscape:
status: Triaged → Invalid
tags: added: bug-migration
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.