RTF import: handle target of hyperlink

lcov pointed out that there is no testcase for the export of this, and
turns out the import part wasn't implemented. As a side effect this
implements the same for DOCX import as well.

Change-Id: I016ebc100ec3856bf3a43aea8ea55af72c2ead1e
This commit is contained in:
Miklos Vajna
2017-02-14 09:32:25 +01:00
parent 3713c17ee4
commit 31de0ac30d
4 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
{\rtf1
\pard\plain
{
{\field
{\*\fldinst HYPERLINK "http://libreoffice.org/" \\t "_blank" }
{\fldrslt
{http://libreoffice.org/}
}
}
}
\par }

View File

@@ -1180,6 +1180,12 @@ DECLARE_RTFEXPORT_TEST(testLeveljcCenter, "leveljc-center.rtf")
CPPUNIT_FAIL("no Adjust property");
}
DECLARE_RTFEXPORT_TEST(testHyperlinkTarget, "hyperlink-target.rtf")
{
// This was empty, hyperlink target was lost on import.
CPPUNIT_ASSERT_EQUAL(OUString("_blank"), getProperty<OUString>(getRun(getParagraph(1), 1), "HyperLinkTarget"));
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -3868,6 +3868,7 @@ void DomainMapper_Impl::CloseFieldCommand()
::std::vector<OUString>::const_iterator aPartIt = aParts.begin();
OUString sURL;
OUString sTarget;
while (aPartIt != aItEnd)
{
@@ -3889,6 +3890,8 @@ void DomainMapper_Impl::CloseFieldCommand()
if (aPartIt == aItEnd)
break;
sTarget = *aPartIt;
}
else
{
@@ -3916,6 +3919,9 @@ void DomainMapper_Impl::CloseFieldCommand()
}
pContext->SetHyperlinkURL(sURL);
}
if (!sTarget.isEmpty())
pContext->SetHyperlinkTarget(sTarget);
}
break;
case FIELD_IF : break;
@@ -4579,6 +4585,9 @@ void DomainMapper_Impl::PopFieldContext()
xCrsrProperties->setPropertyValue(getPropertyName(PROP_HYPER_LINK_U_R_L), uno::
makeAny(pContext->GetHyperlinkURL()));
if (!pContext->GetHyperlinkTarget().isEmpty())
xCrsrProperties->setPropertyValue("HyperLinkTarget", uno::makeAny(pContext->GetHyperlinkTarget()));
if (m_bStartTOC) {
OUString sDisplayName("Index Link");
xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::makeAny(sDisplayName));

View File

@@ -150,6 +150,8 @@ class FieldContext
css::uno::Reference<css::beans::XPropertySet> m_xTC; // TOX entry
css::uno::Reference<css::beans::XPropertySet> m_xCustomField;
OUString m_sHyperlinkURL;
/// A frame for the the hyperlink when one exists.
OUString m_sHyperlinkTarget;
FFDataHandler::Pointer_t m_pFFDataHandler;
FormControlHelper::Pointer_t m_pFormControlHelper;
/// (Character) properties of the field itself.
@@ -188,6 +190,8 @@ public:
void SetHyperlinkURL( const OUString& rURL ) { m_sHyperlinkURL = rURL; }
const OUString& GetHyperlinkURL() { return m_sHyperlinkURL; }
void SetHyperlinkTarget(const OUString& rTarget) { m_sHyperlinkTarget = rTarget; }
const OUString& GetHyperlinkTarget() { return m_sHyperlinkTarget; }
void setFFDataHandler(FFDataHandler::Pointer_t pFFDataHandler) { m_pFFDataHandler = pFFDataHandler; }
const FFDataHandler::Pointer_t& getFFDataHandler() const { return m_pFFDataHandler; }