Kaydet (Commit) 2b2a812b authored tarafından Katarina Behrens's avatar Katarina Behrens Kaydeden (comit) Markus Mohrhard

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

Change-Id: I4317e4a2f6f2e6f15c30932adc80f1227e010af0
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>
üst 97ad6393
...@@ -109,7 +109,7 @@ protected: ...@@ -109,7 +109,7 @@ protected:
bool GetPropertyAndState( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, bool GetPropertyAndState( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState > rXPropState, ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState > rXPropState,
const OUString& aName, ::com::sun::star::beans::PropertyState& eState ); 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 /// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
......
...@@ -1439,7 +1439,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel ...@@ -1439,7 +1439,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
Reference< XTextField > rXTextField; Reference< XTextField > rXTextField;
GET( rXTextField, TextField ); GET( rXTextField, TextField );
if( rXTextField.is() ) if( rXTextField.is() )
rRun.set( rXTextField, UNO_QUERY ); rXPropSet.set( rXTextField, UNO_QUERY );
} }
// field properties starts here // field properties starts here
...@@ -1462,11 +1462,10 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel ...@@ -1462,11 +1462,10 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
mpFS->endElementNS( XML_a, nElement ); 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 ); Reference< XPropertySet > rXPropSet( rRun, UNO_QUERY );
OUString aFieldType; OUString aFieldType, aFieldValue;
if( GETA( TextPortionType ) ) if( GETA( TextPortionType ) )
{ {
...@@ -1480,7 +1479,6 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su ...@@ -1480,7 +1479,6 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su
GET( rXTextField, TextField ); GET( rXTextField, TextField );
if( rXTextField.is() ) if( rXTextField.is() )
{ {
bIsField = true;
rXPropSet.set( rXTextField, UNO_QUERY ); rXPropSet.set( rXTextField, UNO_QUERY );
if( rXPropSet.is() ) if( rXPropSet.is() )
{ {
...@@ -1488,17 +1486,19 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su ...@@ -1488,17 +1486,19 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su
SAL_INFO("oox.shape", "field kind: " << aFieldKind); SAL_INFO("oox.shape", "field kind: " << aFieldKind);
if( aFieldKind == "Page" ) 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;
} }
OString DrawingML::GetUUID() OString DrawingML::GetUUID()
...@@ -1523,14 +1523,19 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun ) ...@@ -1523,14 +1523,19 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
sal_Int16 nLevel = -1; sal_Int16 nLevel = -1;
GET( nLevel, NumberingLevel ); GET( nLevel, NumberingLevel );
const char* sFieldType; bool bIsURLField = false;
bool bIsField = false; OUString sFieldValue = GetFieldValue( rRun, bIsURLField );
bool bWriteField = !( sFieldValue.isEmpty() || bIsURLField );
OUString sText = rRun->getString(); OUString sText = rRun->getString();
//if there is no text following the bullet, add a space after the bullet //if there is no text following the bullet, add a space after the bullet
if (nLevel !=-1 && sText.isEmpty() ) if (nLevel !=-1 && sText.isEmpty() )
sText=" "; sText=" ";
if ( bIsURLField )
sText = sFieldValue;
if( sText.isEmpty()) if( sText.isEmpty())
{ {
Reference< XPropertySet > xPropSet( rRun, UNO_QUERY ); Reference< XPropertySet > xPropSet( rRun, UNO_QUERY );
...@@ -1548,13 +1553,12 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun ) ...@@ -1548,13 +1553,12 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
} }
} }
sFieldType = GetFieldType( rRun, bIsField ); if( ( bWriteField ) )
if( ( sFieldType != NULL ) )
{ {
OString sUUID(GetUUID()); OString sUUID(GetUUID());
mpFS->startElementNS( XML_a, XML_fld, mpFS->startElementNS( XML_a, XML_fld,
XML_id, sUUID.getStr(), XML_id, sUUID.getStr(),
XML_type, sFieldType, XML_type, OUStringToOString( sFieldValue, RTL_TEXTENCODING_UTF8 ).getStr(),
FSEND ); FSEND );
} }
else else
...@@ -1563,13 +1567,13 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun ) ...@@ -1563,13 +1567,13 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
} }
Reference< XPropertySet > xPropSet( rRun, uno::UNO_QUERY ); Reference< XPropertySet > xPropSet( rRun, uno::UNO_QUERY );
WriteRunProperties( xPropSet, bIsField ); WriteRunProperties( xPropSet, bIsURLField );
mpFS->startElementNS( XML_a, XML_t, FSEND ); mpFS->startElementNS( XML_a, XML_t, FSEND );
mpFS->writeEscaped( sText ); mpFS->writeEscaped( sText );
mpFS->endElementNS( XML_a, XML_t ); mpFS->endElementNS( XML_a, XML_t );
if( sFieldType ) if( bWriteField )
mpFS->endElementNS( XML_a, XML_fld ); mpFS->endElementNS( XML_a, XML_fld );
else else
mpFS->endElementNS( XML_a, XML_r ); mpFS->endElementNS( XML_a, XML_r );
......
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include <com/sun/star/graphic/XGraphic.hpp> #include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/frame/XStorable.hpp> #include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/text/XTextField.hpp>
#include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/text/WritingMode2.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/table/BorderLine2.hpp> #include <com/sun/star/table/BorderLine2.hpp>
...@@ -118,6 +119,7 @@ public: ...@@ -118,6 +119,7 @@ public:
void testLineStyle(); void testLineStyle();
void testCellLeftAndRightMargin(); void testCellLeftAndRightMargin();
void testRightToLeftParaghraph(); void testRightToLeftParaghraph();
void testTextboxWithHyperlink();
void testTableCellBorder(); void testTableCellBorder();
void testBulletColor(); void testBulletColor();
void testTdf62176(); void testTdf62176();
...@@ -158,6 +160,7 @@ public: ...@@ -158,6 +160,7 @@ public:
CPPUNIT_TEST(testLineStyle); CPPUNIT_TEST(testLineStyle);
CPPUNIT_TEST(testCellLeftAndRightMargin); CPPUNIT_TEST(testCellLeftAndRightMargin);
CPPUNIT_TEST(testRightToLeftParaghraph); CPPUNIT_TEST(testRightToLeftParaghraph);
CPPUNIT_TEST(testTextboxWithHyperlink);
CPPUNIT_TEST(testTableCellBorder); CPPUNIT_TEST(testTableCellBorder);
CPPUNIT_TEST(testBulletColor); CPPUNIT_TEST(testBulletColor);
CPPUNIT_TEST(testTdf62176); CPPUNIT_TEST(testTdf62176);
...@@ -955,6 +958,50 @@ void SdExportTest::testRightToLeftParaghraph() ...@@ -955,6 +958,50 @@ void SdExportTest::testRightToLeftParaghraph()
xDocShRef->DoClose(); 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
// FIXME: those should really be some convenience function (getShape, getParagraph, getRun etc.)
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() void SdExportTest::testBulletColor()
{ {
::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc("/sd/qa/unit/data/pptx/bulletColor.pptx"), PPTX ); ::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