Bug 114854 - FILEOPEN: DOCX: URL in comment imported as plain text
Summary: FILEOPEN: DOCX: URL in comment imported as plain text
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Justin L
URL:
Whiteboard: target:6.4.0
Keywords: filter:docx
Depends on:
Blocks: DOCX-Comments DOCX-Hyperlink
  Show dependency treegraph
 
Reported: 2018-01-05 17:24 UTC by Justin L
Modified: 2019-08-13 04:43 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
tdf104707_urlComment.odt: ODT master for creating .doc and .docx copies. (9.71 KB, application/vnd.oasis.opendocument.text)
2018-01-05 17:24 UTC, Justin L
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin L 2018-01-05 17:24:25 UTC
Created attachment 138904 [details]
tdf104707_urlComment.odt: ODT master for creating .doc and .docx copies.

URLs in comments in .docx format are imported as plain text, losing the URL formatting/clickability.

See attachment 138876 [details] from related bug 104707
URLinComment2003.docx: MS Word 2003 created test with URL in comment

.odt and .doc files don't have this problem. Look at ww8par5.cxx:Read_F_Hyperlink for the function that creates the SwFormatINetFormat attribute.

The problem code for docx is in DomainMapper_Impl:PopFieldContext() which throws an exception when setting the "HyperLinkURL" property in the annotation. The same code is used for setting the URL property in regular text and works fine there. I'm stumped, but it should be an easy bug to solve for someone with good understanding of how .docx importing works.
Comment 1 raal 2018-01-05 21:52:59 UTC
I can confirm with Version: 6.1.0.0.alpha0+
Build ID: 88f6ffeb9e0c0b942c2b0bc9d60af7bb7a6caaf8
CPU threads: 4; OS: Linux 4.4; UI render: default; VCL: gtk3;
Comment 2 Timur 2018-12-31 15:33:41 UTC
Repro 6.3+ with ODT attachment 138904 [details]. MSO 2016 opens DOCX fine.
Comment 3 Justin L 2019-08-06 15:51:22 UTC
(In reply to Justin L from comment #0)
> The same code is used for setting the URL property in regular
> text and works fine there.
Normal text uses SwTextCursor, while the draw-based cursor uses SvxUnoTextRangeBase. 

Since .doc format worked, I found that it uses Draw to ImportAsOutliner
m_pDrawEditEngine->QuickInsertField(SvxFieldItem(aURL, EE_FEATURE_FIELD), aSel);

That suggests doing something like this
#include <editeng/flditem.hxx>
#include <editeng/unotext.hxx>
SvxUnoTextRangeBase* pDrawText = dynamic_cast<SvxUnoTextRangeBase*>(xCrsr.get());
if ( pDrawText )
    pDrawText->attachField( std::make_unique<SvxURLField>(pContext->GetHyperlinkURL(), "the displayed text", SvxURLFormat::AppDefault) );
Comment 4 Justin L 2019-08-07 12:57:09 UTC
proposed fix at https://gerrit.libreoffice.org/77108
Comment 5 Commit Notification 2019-08-13 04:35:40 UTC
Justin Luth committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/+/75b10a6c36267c30ae01c850b2a2f9ee99b74e43%5E%21

tdf#114854 writerfilter: EditEng URLs import different from SW URLs

It will be available in 6.4.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.