Kaydet (Commit) 61a1beb0 authored tarafından Mark Hung's avatar Mark Hung Kaydeden (comit) Andras Timar

Fix tdf#80224 Custom text color changed to black on .PPTX export

1) Write endParaRPr so that PowerPoint display them properly.
2) Original design forbid properites with default value to be exprted, now fixed.
3) Automatic colors are written as white or black based on
   whether background is dark.

Note that tdf#77881,tdf#80520,tdf#89525 depend on this.

Change-Id: I255c16f35149b738be2daf2800b1c90389f2c7cf
Reviewed-on: https://gerrit.libreoffice.org/17472Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNorbert Thiebaud <nthiebaud@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/19862Reviewed-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
Tested-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
(cherry picked from commit 0b5e3885)
üst f7d9f59b
......@@ -103,6 +103,7 @@ protected:
::oox::core::XmlFilterBase* mpFB;
/// If set, this is the parent of the currently handled shape.
com::sun::star::uno::Reference<com::sun::star::drawing::XShape> m_xParent;
bool mbIsBackgroundDark;
bool GetProperty( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, const OUString& aName );
bool GetPropertyAndState( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
......@@ -122,7 +123,7 @@ protected:
public:
DrawingML( ::sax_fastparser::FSHelperPtr pFS, ::oox::core::XmlFilterBase* pFB = NULL, DocumentType eDocumentType = DOCUMENT_PPTX, DMLTextExport* pTextExport = 0 )
: meDocumentType( eDocumentType ), mpTextExport(pTextExport), mpFS( pFS ), mpFB( pFB ) {}
: meDocumentType( eDocumentType ), mpTextExport(pTextExport), mpFS( pFS ), mpFB( pFB ), mbIsBackgroundDark( false ) {}
void SetFS( ::sax_fastparser::FSHelperPtr pFS ) { mpFS = pFS; }
::sax_fastparser::FSHelperPtr GetFS() { return mpFS; }
::oox::core::XmlFilterBase* GetFB() { return mpFB; }
......@@ -130,6 +131,7 @@ public:
/// The application-specific text exporter callback, if there is one.
DMLTextExport* GetTextExport() { return mpTextExport; }
void SetBackgroundDark(bool bIsDark) { mbIsBackgroundDark = bIsDark; }
/// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
OUString WriteImage( const Graphic &rGraphic , bool bRelPathToMedia = false);
......
......@@ -113,6 +113,9 @@ namespace drawingml {
if ( GETA(propName) ) \
mAny >>= variable;
#define CGETAD(propName) \
(( bCheckDirect && GetPropertyAndState( rXPropSet, rXPropState, OUString( #propName ), eState ) && eState == beans::PropertyState_DIRECT_VALUE )||GetProperty( rXPropSet, OUString( #propName ) ))
// not thread safe
int DrawingML::mnImageCounter = 1;
int DrawingML::mnWdpImageCounter = 1;
......@@ -1214,7 +1217,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
sal_Int32 nSize = 1800;
sal_Int32 nCharEscapement = 0;
sal_Int32 nCharKerning = 0;
bool bCheckDirect = XML_endParaRPr != nElement ;
if( GETA( CharHeight ) )
nSize = (sal_Int32) (100*(*static_cast<float const *>(mAny.getValue())));
......@@ -1245,7 +1248,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
break;
}
if ( GETAD( CharUnderline ) )
if ( CGETAD( CharUnderline ) )
{
switch ( *static_cast<sal_Int16 const *>(mAny.getValue()) )
{
......@@ -1300,7 +1303,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
}
}
if ( GETAD( CharStrikeout ) )
if ( CGETAD( CharStrikeout ) )
{
switch ( *static_cast<sal_Int16 const *>(mAny.getValue()) )
{
......@@ -1374,16 +1377,14 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
FSEND );
// mso doesn't like text color to be placed after typeface
if( GETAD( CharColor ) )
if( CGETAD( CharColor ) )
{
sal_uInt32 color = *static_cast<sal_uInt32 const *>(mAny.getValue());
DBG(fprintf(stderr, "run color: %x auto: %x\n", static_cast<unsigned int>( color ), static_cast<unsigned int>( COL_AUTO )));
if( color == COL_AUTO ) // nCharColor depends to the background color
{
bool bIsDark = false;
GET( bIsDark, IsBackgroundDark );
color = bIsDark ? 0xffffff : 0x000000;
color = mbIsBackgroundDark ? COL_WHITE : COL_BLACK ;
}
color &= 0xffffff;
......@@ -1392,7 +1393,7 @@ void DrawingML::WriteRunProperties( Reference< XPropertySet > rRun, bool bIsFiel
WriteSolidFill( color );
}
if( GETAD( CharUnderlineColor ) )
if( CGETAD( CharUnderlineColor ) )
{
sal_uInt32 color = *static_cast<sal_uInt32 const *>(mAny.getValue());
......@@ -1677,7 +1678,8 @@ void DrawingML::WriteParagraphNumbering( Reference< XPropertySet > rXPropSet, sa
OUString aGraphicURL;
sal_Int16 nBulletRelSize = 0;
sal_Int16 nStartWith = 1;
sal_Int32 nBulletColor = 0;
sal_uInt32 nBulletColor = 0;
bool bHasBulletColor = false;
for ( sal_Int32 i = 0; i < nPropertyCount; i++ )
{
......@@ -1704,7 +1706,8 @@ void DrawingML::WriteParagraphNumbering( Reference< XPropertySet > rXPropSet, sa
}
else if(aPropName == "BulletColor")
{
nBulletColor = *static_cast<sal_Int32 const *>(pValue);
nBulletColor = *static_cast<sal_uInt32 const *>(pValue);
bHasBulletColor = true;
}
else if ( aPropName == "BulletChar" )
{
......@@ -1764,8 +1767,12 @@ void DrawingML::WriteParagraphNumbering( Reference< XPropertySet > rXPropSet, sa
}
else
{
if(nBulletColor)
if(bHasBulletColor)
{
if (nBulletColor == COL_AUTO )
{
nBulletColor = mbIsBackgroundDark ? COL_WHITE : COL_BLACK ;
}
mpFS->startElementNS( XML_a, XML_buClr, FSEND );
WriteColor( nBulletColor );
mpFS->endElementNS( XML_a, XML_buClr );
......@@ -1962,6 +1969,7 @@ void DrawingML::WriteParagraph( Reference< XTextContent > rParagraph )
mpFS->startElementNS( XML_a, XML_p, FSEND );
bool bPropertiesWritten = false;
while( enumeration->hasMoreElements() )
{
......@@ -1978,7 +1986,8 @@ void DrawingML::WriteParagraph( Reference< XTextContent > rParagraph )
WriteRun( run );
}
}
mpFS->singleElementNS( XML_a, XML_endParaRPr, FSEND );
Reference< XPropertySet > rXPropSet( rParagraph, UNO_QUERY );
WriteRunProperties( rXPropSet , false, XML_endParaRPr );
mpFS->endElementNS( XML_a, XML_p );
}
......
......@@ -111,6 +111,7 @@ public:
#if !defined WNT
void testBnc822341();
#endif
void testTdf80224();
CPPUNIT_TEST_SUITE(SdExportTest);
CPPUNIT_TEST(testFdo90607);
......@@ -146,6 +147,7 @@ public:
#if !defined WNT
CPPUNIT_TEST(testBnc822341);
#endif
CPPUNIT_TEST(testTdf80224);
CPPUNIT_TEST_SUITE_END();
};
......@@ -1217,6 +1219,25 @@ void SdExportTest::testTableCellBorder()
xDocShRef->DoClose();
}
void SdExportTest::testTdf80224()
{
::sd::DrawDocShellRef xDocShRef = loadURL( getURLFromSrc("/sd/qa/unit/data/odp/tdf80224.odp"), ODP);
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< drawing::XShape > xShape(xPage->getByIndex(0), uno::UNO_QUERY);
uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText();
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);
uno::Reference< beans::XPropertySet > xPropSet( xParagraph->getStart(), uno::UNO_QUERY_THROW );
sal_Int32 nCharColor;
xPropSet->getPropertyValue("CharColor") >>= nCharColor;
CPPUNIT_ASSERT_EQUAL(sal_Int32(6644396), nCharColor);
xDocShRef->DoClose();
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -347,6 +347,7 @@ protected:
OString mType;
bool mbPresObj;
bool mbEmptyPresObj;
bool mbIsBackgroundDark;
sal_Int32 mnAngle;
sal_uInt32 mnPages; ///< number of Slides ( w/o master pages & notes & handout )
......
......@@ -133,6 +133,7 @@ PPTWriterBase::PPTWriterBase()
, mbStatusIndicator(false)
, mbPresObj(false)
, mbEmptyPresObj(false)
, mbIsBackgroundDark(false)
, mnAngle(0)
, mnPages(0)
, mnMasterPages(0)
......@@ -325,6 +326,9 @@ bool PPTWriterBase::GetPageByIndex( sal_uInt32 nIndex, PageType ePageType )
if ( !mXPagePropSet.is() )
break;
if (GetPropertyValue( aAny, mXPagePropSet, OUString("IsBackgroundDark") ) )
aAny >>= mbIsBackgroundDark;
mXShapes = Reference< XShapes >( mXDrawPage, UNO_QUERY );
if ( !mXShapes.is() )
break;
......
......@@ -412,7 +412,9 @@ void PowerPointExport::ImplWriteBackground( FSHelperPtr pFS, Reference< XPropert
pFS->startElementNS( XML_p, XML_bg, FSEND );
pFS->startElementNS( XML_p, XML_bgPr, FSEND );
PowerPointShapeExport( pFS, &maShapeMap, this ).WriteFill( rXPropSet );
PowerPointShapeExport aDML( pFS, &maShapeMap, this );
aDML.SetBackgroundDark(mbIsBackgroundDark);
aDML.WriteFill( rXPropSet );
pFS->endElementNS( XML_p, XML_bgPr );
pFS->endElementNS( XML_p, XML_bg );
......@@ -1706,6 +1708,7 @@ void PowerPointExport::WriteShapeTree( FSHelperPtr pFS, PageType ePageType, bool
PowerPointShapeExport aDML( pFS, &maShapeMap, this );
aDML.SetMaster( bMaster );
aDML.SetPageType( ePageType );
aDML.SetBackgroundDark(mbIsBackgroundDark);
sal_uInt32 nShapes;
pFS->startElementNS( XML_p, XML_spTree, FSEND );
......
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