Kaydet (Commit) e17187c3 authored tarafından Katarina Behrens's avatar Katarina Behrens Kaydeden (comit) Miklos Vajna

tdf#91293: Preserve hyperlink on URL field OOXML export

The fix is twofold:
1.Get URL property from the underlying text field, not from the
text run -- put text field properties into rXPropSet (that's
what GETA macro later queries), not into rRun

6a043e9c does s/rXPropSet/rRun/
afaics for no good reason

2. Retrieve string content from URL field early, so that the test
for empty text content doesn't fire

Reviewed-on: https://gerrit.libreoffice.org/18031Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>

Conflicts:
	sd/qa/unit/export-tests.cxx

Change-Id: I4317e4a2f6f2e6f15c30932adc80f1227e010af0
Reviewed-on: https://gerrit.libreoffice.org/18706Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 31d1004f
......@@ -108,7 +108,7 @@ protected:
bool GetPropertyAndState( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState > rXPropState,
const OUString& aName, ::com::sun::star::beans::PropertyState& eState );
const char* GetFieldType( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > rRun, bool& bIsField );
OUString GetFieldValue( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > rRun, bool& bIsURLField );
/// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
......
......@@ -1438,7 +1438,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
Reference< XTextField > rXTextField;
GET( rXTextField, TextField );
if( rXTextField.is() )
rRun.set( rXTextField, UNO_QUERY );
rXPropSet.set( rXTextField, UNO_QUERY );
}
// field properties starts here
......@@ -1461,11 +1461,10 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
mpFS->endElementNS( XML_a, nElement );
}
const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > rRun, bool& bIsField )
OUString DrawingML::GetFieldValue( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > rRun, bool& bIsURLField )
{
const char* sType = NULL;
Reference< XPropertySet > rXPropSet( rRun, UNO_QUERY );
OUString aFieldType;
OUString aFieldType, aFieldValue;
if( GETA( TextPortionType ) )
{
......@@ -1479,7 +1478,6 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su
GET( rXTextField, TextField );
if( rXTextField.is() )
{
bIsField = true;
rXPropSet.set( rXTextField, UNO_QUERY );
if( rXPropSet.is() )
{
......@@ -1487,17 +1485,19 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su
DBG(fprintf (stderr, "field kind: %s\n", USS(aFieldKind) ));
if( aFieldKind == "Page" )
{
return "slidenum";
aFieldValue = OUString("slidenum");
}
else if( aFieldKind == "URL" )
{
bIsURLField = true;
GET( aFieldValue, Representation)
}
// else if( aFieldKind == "URL" ) {
// do not return here
// and make URL field text run with hyperlink property later
// }
}
}
}
return sType;
return aFieldValue;
}
void DrawingML::GetUUID( OStringBuffer& rBuffer )
......@@ -1546,14 +1546,19 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
sal_Int16 nLevel = -1;
GET( nLevel, NumberingLevel );
const char* sFieldType;
bool bIsField = false;
bool bIsURLField = false;
OUString sFieldValue = GetFieldValue( rRun, bIsURLField );
bool bWriteField = !( sFieldValue.isEmpty() || bIsURLField );
OUString sText = rRun->getString();
//if there is no text following the bullet, add a space after the bullet
if (nLevel !=-1 && sText.isEmpty() )
sText=" ";
if ( bIsURLField )
sText = sFieldValue;
if( sText.isEmpty())
{
Reference< XPropertySet > xPropSet( rRun, UNO_QUERY );
......@@ -1571,15 +1576,14 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
}
}
sFieldType = GetFieldType( rRun, bIsField );
if( ( sFieldType != NULL ) )
if( ( bWriteField ) )
{
OStringBuffer sUUID(39);
GetUUID( sUUID );
mpFS->startElementNS( XML_a, XML_fld,
XML_id, sUUID.getStr(),
XML_type, sFieldType,
XML_type, OUStringToOString( sFieldValue, RTL_TEXTENCODING_UTF8 ).getStr(),
FSEND );
}
else
......@@ -1588,13 +1592,13 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
}
Reference< XPropertySet > xPropSet( rRun, uno::UNO_QUERY );
WriteRunProperties( xPropSet, bIsField );
WriteRunProperties( xPropSet, bIsURLField );
mpFS->startElementNS( XML_a, XML_t, FSEND );
mpFS->writeEscaped( sText );
mpFS->endElementNS( XML_a, XML_t );
if( sFieldType )
if( bWriteField )
mpFS->endElementNS( XML_a, XML_fld );
else
mpFS->endElementNS( XML_a, XML_r );
......
......@@ -61,6 +61,7 @@
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/XTable.hpp>
#include <com/sun/star/table/XMergeableCell.hpp>
......@@ -99,6 +100,7 @@ public:
void testLineStyle();
void testCellLeftAndRightMargin();
void testRightToLeftParaghraph();
void testTextboxWithHyperlink();
void testTableCellBorder();
void testBulletColor();
void testBulletCharAndFont();
......@@ -134,6 +136,7 @@ public:
CPPUNIT_TEST(testLineStyle);
CPPUNIT_TEST(testCellLeftAndRightMargin);
CPPUNIT_TEST(testRightToLeftParaghraph);
CPPUNIT_TEST(testTextboxWithHyperlink);
CPPUNIT_TEST(testTableCellBorder);
CPPUNIT_TEST(testBulletColor);
CPPUNIT_TEST(testBulletCharAndFont);
......@@ -914,6 +917,49 @@ void SdExportTest::testRightToLeftParaghraph()
xDocShRef->DoClose();
}
void SdExportTest::testTextboxWithHyperlink()
{
::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/hyperlinktest.pptx"), PPTX);
xDocShRef = saveAndReload( xDocShRef, PPTX );
uno::Reference< drawing::XDrawPagesSupplier > xDoc(
xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW );
uno::Reference< drawing::XDrawPage > xPage(
xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW );
uno::Reference< beans::XPropertySet > xShape(
xPage->getByIndex(0), uno::UNO_QUERY );
CPPUNIT_ASSERT_MESSAGE( "no shape", xShape.is() );
// Get first paragraph
uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY)->getText();
CPPUNIT_ASSERT_MESSAGE( "not a text shape", xText.is() );
uno::Reference<container::XEnumerationAccess> paraEnumAccess;
paraEnumAccess.set(xText, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> paraEnum = paraEnumAccess->createEnumeration();
uno::Reference<text::XTextRange> const xParagraph(paraEnum->nextElement(),
uno::UNO_QUERY_THROW);
// first chunk of text
uno::Reference<container::XEnumerationAccess> xRunEnumAccess(xParagraph, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xRunEnum = xRunEnumAccess->createEnumeration();
uno::Reference<text::XTextRange> xRun(xRunEnum->nextElement(), uno::UNO_QUERY);
uno::Reference< beans::XPropertySet > xPropSet( xRun, uno::UNO_QUERY_THROW );
uno::Reference<text::XTextField> xField;
xPropSet->getPropertyValue("TextField") >>= xField;
CPPUNIT_ASSERT_MESSAGE("Where is the text field?", xField.is() );
xPropSet.set(xField, uno::UNO_QUERY);
OUString aURL;
xPropSet->getPropertyValue("URL") >>= aURL;
CPPUNIT_ASSERT_EQUAL_MESSAGE("URLs don't match", OUString("http://www.xkcd.com/"), aURL);
xDocShRef->DoClose();
}
void SdExportTest::testBulletColor()
{
::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc("/sd/qa/unit/data/pptx/bulletColor.pptx"), PPTX );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment