[Libreoffice-commits] core.git: include/oox oox/source sd/qa
Katarina Behrens
Katarina.Behrens at cib.de
Mon Sep 14 09:53:12 PDT 2015
include/oox/export/drawingml.hxx | 2 -
oox/source/export/drawingml.cxx | 40 ++++++++++++++-------------
sd/qa/unit/data/pptx/hyperlinktest.pptx |binary
sd/qa/unit/export-tests.cxx | 47 ++++++++++++++++++++++++++++++++
4 files changed, 70 insertions(+), 19 deletions(-)
New commits:
commit 2b2a812b89d0d1df08c5d771bfe9bc5eaa3a040c
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date: Wed Aug 26 18:05:08 2015 +0200
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
6a043e9c0acff20e1618ca8ec15c21d5d0fd0d37 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/18031
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index f1e6ddc..378ae5e 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -109,7 +109,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
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 83fd6f0..4cb8530 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1439,7 +1439,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
@@ -1462,11 +1462,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 ) )
{
@@ -1480,7 +1479,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() )
{
@@ -1488,17 +1486,19 @@ const char* DrawingML::GetFieldType( ::com::sun::star::uno::Reference< ::com::su
SAL_INFO("oox.shape", "field kind: " << 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;
}
OString DrawingML::GetUUID()
@@ -1523,14 +1523,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 );
@@ -1548,13 +1553,12 @@ void DrawingML::WriteRun( Reference< XTextRange > rRun )
}
}
- sFieldType = GetFieldType( rRun, bIsField );
- if( ( sFieldType != NULL ) )
+ if( ( bWriteField ) )
{
OString sUUID(GetUUID());
mpFS->startElementNS( XML_a, XML_fld,
XML_id, sUUID.getStr(),
- XML_type, sFieldType,
+ XML_type, OUStringToOString( sFieldValue, RTL_TEXTENCODING_UTF8 ).getStr(),
FSEND );
}
else
@@ -1563,13 +1567,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 );
diff --git a/sd/qa/unit/data/pptx/hyperlinktest.pptx b/sd/qa/unit/data/pptx/hyperlinktest.pptx
new file mode 100644
index 0000000..dac61c0
Binary files /dev/null and b/sd/qa/unit/data/pptx/hyperlinktest.pptx differ
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index 375ed3e..ee6a416 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -60,6 +60,7 @@
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/frame/XStorable.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/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
@@ -118,6 +119,7 @@ public:
void testLineStyle();
void testCellLeftAndRightMargin();
void testRightToLeftParaghraph();
+ void testTextboxWithHyperlink();
void testTableCellBorder();
void testBulletColor();
void testTdf62176();
@@ -158,6 +160,7 @@ public:
CPPUNIT_TEST(testLineStyle);
CPPUNIT_TEST(testCellLeftAndRightMargin);
CPPUNIT_TEST(testRightToLeftParaghraph);
+ CPPUNIT_TEST(testTextboxWithHyperlink);
CPPUNIT_TEST(testTableCellBorder);
CPPUNIT_TEST(testBulletColor);
CPPUNIT_TEST(testTdf62176);
@@ -955,6 +958,50 @@ 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
+ // 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()
{
::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc("/sd/qa/unit/data/pptx/bulletColor.pptx"), PPTX );
More information about the Libreoffice-commits
mailing list