Bug 152305 - FILEOPEN DOCX: comment range spans outside to inside table
Summary: FILEOPEN DOCX: comment range spans outside to inside table
Status: RESOLVED WONTFIX
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: low trivial
Assignee: Not Assigned
URL:
Whiteboard: target:7.5.0
Keywords: filter:docx
Depends on:
Blocks: DOCX-Comments
  Show dependency treegraph
 
Reported: 2022-11-30 00:55 UTC by Justin L
Modified: 2022-11-30 18:15 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
tableComment.docx: two comments spanning table border / cell borders (13.00 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2022-11-30 00:55 UTC, Justin L
Details
tableComment_mso2010.pdf: how it looks in Word (12.73 KB, application/pdf)
2022-11-30 00:59 UTC, Justin L
Details
tableComment.docx: two comments spanning table border / cell borders (13.00 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2022-11-30 16:32 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin L 2022-11-30 00:55:07 UTC
Created attachment 183902 [details]
tableComment.docx: two comments spanning table border / cell borders

MS Word allows a comment span to start and end pretty much anywhere. LibreOffice doesn't let it span across a table boundary. Perhaps a bit of intelligence can figure out whether it is better to span the comment outside or inside the table. At the moment the comment is just an anchor without any span.

Steps to reproduce:
1.) open the file.
The first comment should cover the text before the table and the contents A1.
The second comment should cover 2, C2, D.

Also note that the rest of the text in D2 is missing, and lost on a round-trip.
Comment 1 Justin L 2022-11-30 00:59:27 UTC
Created attachment 183903 [details]
tableComment_mso2010.pdf: how it looks in Word
Comment 2 Justin L 2022-11-30 01:01:46 UTC
P.S. DOC format doesn't lose any text. It drops both spans and just has the anchor.
Comment 3 Justin L 2022-11-30 02:36:59 UTC
xCur = xTextRange->getText( )->createTextCursor( );
xCur->gotoEnd(false);
xCur->goLeft(1, false);
uno::Reference<text::XTextCursor> xCur2 =
    xTextRange->getText()->createTextCursorByRange(xCur);

SAL_DEBUG("next line is our exception");
uno::Reference<text::XParagraphCursor> xParaCursor(xCur2, uno::UNO_QUERY_THROW);
xParaCursor->gotoStartOfParagraph(false);

The exception happens for both A1 and D2. This UNO mumbo-jumbo won't be easy to figure out. Low priority - this was a hand-modified example. Not so easy to create in the wild, but inspired by a client's example.
Comment 4 Justin L 2022-11-30 16:32:20 UTC
Created attachment 183917 [details]
tableComment.docx: two comments spanning table border / cell borders

The part about losing text is somewhat bogus. I accidentally crafted an invalid document. This one doesn't lose the cell text...
Comment 5 Justin L 2022-11-30 17:07:02 UTC
I don't see any way to resolve this (short of completely changing the LO model to accept comments that span table borders). Oh, sure, for a specific document with a comment at the very beginning of the table you could edge-case that as ending before the table, but that is a whole lot of complication for very little benefit. WONTFIX.
Comment 6 Commit Notification 2022-11-30 18:15:35 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/61b5835fc81f1dec9c9e334a9f886f35997d1b56

related tdf#152305 writerfilter: avoid comment-related exceptions

It will be available in 7.5.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.