Kaydet (Commit) ffb1053b authored tarafından Vinaya Mandke's avatar Vinaya Mandke Kaydeden (comit) Markus Mohrhard

fdo#74115 Fix for DOCX BitmapFill for Chart Wall

Fixed import and export for chart wall Bitmap Fill in DOCX
Added UT for the same.

Conflicts:
	oox/source/export/chartexport.cxx

Change-Id: Id066b0e4c2007fcdfdbbfa67b40307463bf0cfe7
üst f38a223d
...@@ -44,6 +44,7 @@ public: ...@@ -44,6 +44,7 @@ public:
void testDoughnutChart(); void testDoughnutChart();
void testDisplayUnits(); void testDisplayUnits();
void testFdo74115WallGradientFill(); void testFdo74115WallGradientFill();
void testFdo74115WallBitmapFill();
CPPUNIT_TEST_SUITE(Chart2ExportTest); CPPUNIT_TEST_SUITE(Chart2ExportTest);
CPPUNIT_TEST(test); CPPUNIT_TEST(test);
...@@ -60,6 +61,7 @@ public: ...@@ -60,6 +61,7 @@ public:
CPPUNIT_TEST(testDoughnutChart); CPPUNIT_TEST(testDoughnutChart);
CPPUNIT_TEST(testDisplayUnits); CPPUNIT_TEST(testDisplayUnits);
CPPUNIT_TEST(testFdo74115WallGradientFill); CPPUNIT_TEST(testFdo74115WallGradientFill);
CPPUNIT_TEST(testFdo74115WallBitmapFill);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
protected: protected:
...@@ -556,6 +558,14 @@ void Chart2ExportTest::testFdo74115WallGradientFill() ...@@ -556,6 +558,14 @@ void Chart2ExportTest::testFdo74115WallGradientFill()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill"); assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill");
} }
void Chart2ExportTest::testFdo74115WallBitmapFill()
{
load("/chart2/qa/extras/data/docx/", "fdo74115_WallBitmapFill.docx");
xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:blipFill");
}
CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest); CPPUNIT_TEST_SUITE_REGISTRATION(Chart2ExportTest);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -123,6 +123,7 @@ private: ...@@ -123,6 +123,7 @@ private:
void exportPlotAreaShapeProps( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet ); void exportPlotAreaShapeProps( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet );
void exportFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet ); void exportFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet );
void exportGradientFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet ); void exportGradientFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet );
void exportBitmapFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet );
void exportDataTable( ); void exportDataTable( );
void exportAreaChart( com::sun::star::uno::Reference< com::sun::star::chart2::XChartType > xChartType ); void exportAreaChart( com::sun::star::uno::Reference< com::sun::star::chart2::XChartType > xChartType );
......
...@@ -101,7 +101,9 @@ protected: ...@@ -101,7 +101,9 @@ protected:
OUString aName, ::com::sun::star::beans::PropertyState& eState ); OUString aName, ::com::sun::star::beans::PropertyState& eState );
const char* GetFieldType( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > rRun, sal_Bool& bIsField ); const char* GetFieldType( ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > rRun, sal_Bool& bIsField );
OUString WriteImage( const OUString& rURL );
/// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
OUString WriteImage( const OUString& rURL, bool bRelPathToMedia = false);
void WriteStyleProperties( sal_Int32 nTokenId, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aProperties ); void WriteStyleProperties( sal_Int32 nTokenId, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aProperties );
const char* GetComponentDir(); const char* GetComponentDir();
...@@ -117,7 +119,8 @@ public: ...@@ -117,7 +119,8 @@ public:
::oox::core::XmlFilterBase* GetFB() { return mpFB; } ::oox::core::XmlFilterBase* GetFB() { return mpFB; }
DocumentType GetDocumentType() { return meDocumentType; } DocumentType GetDocumentType() { return meDocumentType; }
OUString WriteImage( const Graphic &rGraphic ); /// If bRelPathToMedia is true add "../" to image folder path while adding the image relationship
OUString WriteImage( const Graphic &rGraphic , bool bRelPathToMedia = false);
void WriteColor( sal_uInt32 nColor, sal_Int32 nAlpha = MAX_PERCENT ); void WriteColor( sal_uInt32 nColor, sal_Int32 nAlpha = MAX_PERCENT );
void WriteColor( OUString sColorSchemeName, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aTransformations ); void WriteColor( OUString sColorSchemeName, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aTransformations );
...@@ -132,14 +135,19 @@ public: ...@@ -132,14 +135,19 @@ public:
void WriteGradientFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); void WriteGradientFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
void WriteGradientFill( ::com::sun::star::awt::Gradient rGradient ); void WriteGradientFill( ::com::sun::star::awt::Gradient rGradient );
void WriteGrabBagGradientFill( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aGradientStops, ::com::sun::star::awt::Gradient rGradient); void WriteGrabBagGradientFill( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aGradientStops, ::com::sun::star::awt::Gradient rGradient);
void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, OUString sURLPropName, sal_Int32 nXmlNamespace ); void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
OUString sBitmapURL, sal_Int32 nXmlNamespace,
bool bWriteMode, bool bRelPathToMedia = false );
void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, OUString sURLPropName ); void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, OUString sURLPropName );
void WriteBlipFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
OUString sURLPropName, sal_Int32 nXmlNamespace );
void WriteSrcRect( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, const OUString& ); void WriteSrcRect( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >, const OUString& );
void WriteOutline( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); void WriteOutline( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
void WriteStretch(); void WriteStretch();
void WriteLinespacing( ::com::sun::star::style::LineSpacing& rLineSpacing ); void WriteLinespacing( ::com::sun::star::style::LineSpacing& rLineSpacing );
OUString WriteBlip( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet, OUString& rURL, const Graphic *pGraphic=NULL ); OUString WriteBlip( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet,
OUString& rURL, bool bRelPathToMedia = false , const Graphic *pGraphic=NULL );
void WriteBlipMode( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); void WriteBlipMode( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
void WriteShapeTransformation( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > rXShape, void WriteShapeTransformation( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > rXShape,
......
...@@ -1166,11 +1166,40 @@ void ChartExport::exportFill( Reference< XPropertySet > xPropSet ) ...@@ -1166,11 +1166,40 @@ void ChartExport::exportFill( Reference< XPropertySet > xPropSet )
case FillStyle_GRADIENT : case FillStyle_GRADIENT :
exportGradientFill( xPropSet ); exportGradientFill( xPropSet );
break; break;
case FillStyle_BITMAP :
exportBitmapFill( xPropSet );
break;
default: default:
WriteFill( xPropSet ); WriteFill( xPropSet );
} }
} }
void ChartExport::exportBitmapFill( Reference< XPropertySet > xPropSet )
{
if( xPropSet.is() )
{
OUString sFillGradientName;
xPropSet->getPropertyValue("FillBitmapName") >>= sFillGradientName;
uno::Reference< lang::XMultiServiceFactory > xFact( getModel(), uno::UNO_QUERY );
try
{
uno::Reference< container::XNameAccess > xGradient( xFact->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
uno::Any rValue = xGradient->getByName( sFillGradientName );
OUString sBitmapURL;
if( (rValue >>= sBitmapURL) )
{
WriteBlipFill( xPropSet, sBitmapURL, XML_a, true, true );
}
}
catch( const uno::Exception & rEx )
{
DBG_WARNING( "Bitmap Property not Found; ChartExport::exportBitmapFill" );
}
}
}
void ChartExport::exportGradientFill( Reference< XPropertySet > xPropSet ) void ChartExport::exportGradientFill( Reference< XPropertySet > xPropSet )
{ {
if( xPropSet.is() ) if( xPropSet.is() )
...@@ -1191,7 +1220,7 @@ void ChartExport::exportGradientFill( Reference< XPropertySet > xPropSet ) ...@@ -1191,7 +1220,7 @@ void ChartExport::exportGradientFill( Reference< XPropertySet > xPropSet )
} }
catch( const uno::Exception & rEx ) catch( const uno::Exception & rEx )
{ {
DBG_WARNING( "Gradient Property not Found; ChartExport::exportPlotAreaGradientFill" ); DBG_WARNING( "Gradient Property not Found; ChartExport::exportGradientFill" );
} }
} }
......
...@@ -661,7 +661,7 @@ void DrawingML::WriteOutline( Reference< XPropertySet > rXPropSet ) ...@@ -661,7 +661,7 @@ void DrawingML::WriteOutline( Reference< XPropertySet > rXPropSet )
mpFS->endElementNS( XML_a, XML_ln ); mpFS->endElementNS( XML_a, XML_ln );
} }
OUString DrawingML::WriteImage( const OUString& rURL ) OUString DrawingML::WriteImage( const OUString& rURL, bool bRelPathToMedia )
{ {
OString aURLBS(OUStringToOString(rURL, RTL_TEXTENCODING_UTF8)); OString aURLBS(OUStringToOString(rURL, RTL_TEXTENCODING_UTF8));
...@@ -673,7 +673,7 @@ OUString DrawingML::WriteImage( const OUString& rURL ) ...@@ -673,7 +673,7 @@ OUString DrawingML::WriteImage( const OUString& rURL )
DBG(fprintf (stderr, "begin: %ld %s\n", long( sizeof( aURLBegin ) ), USS( rURL ) + RTL_CONSTASCII_LENGTH( aURLBegin ) )); DBG(fprintf (stderr, "begin: %ld %s\n", long( sizeof( aURLBegin ) ), USS( rURL ) + RTL_CONSTASCII_LENGTH( aURLBegin ) ));
Graphic aGraphic = GraphicObject( aURLBS.copy(RTL_CONSTASCII_LENGTH(aURLBegin)) ).GetTransformedGraphic (); Graphic aGraphic = GraphicObject( aURLBS.copy(RTL_CONSTASCII_LENGTH(aURLBegin)) ).GetTransformedGraphic ();
return WriteImage( aGraphic ); return WriteImage( aGraphic , bRelPathToMedia );
} else { } else {
// add link to relations // add link to relations
} }
...@@ -705,7 +705,7 @@ const char* DrawingML::GetRelationCompPrefix() ...@@ -705,7 +705,7 @@ const char* DrawingML::GetRelationCompPrefix()
return "unknown"; return "unknown";
} }
OUString DrawingML::WriteImage( const Graphic& rGraphic ) OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia )
{ {
GfxLink aLink = rGraphic.GetLink (); GfxLink aLink = rGraphic.GetLink ();
OUString sMediaType; OUString sMediaType;
...@@ -780,11 +780,14 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic ) ...@@ -780,11 +780,14 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic )
xOutStream->writeBytes( Sequence< sal_Int8 >( (const sal_Int8*) aData, nDataSize ) ); xOutStream->writeBytes( Sequence< sal_Int8 >( (const sal_Int8*) aData, nDataSize ) );
xOutStream->closeOutput(); xOutStream->closeOutput();
OString sRelPathToMedia = "media/image";
if ( bRelPathToMedia )
sRelPathToMedia = "../" + sRelPathToMedia;
sRelId = mpFB->addRelation( mpFS->getOutputStream(), sRelId = mpFB->addRelation( mpFS->getOutputStream(),
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
OUStringBuffer() OUStringBuffer()
.appendAscii( GetRelationCompPrefix() ) .appendAscii( GetRelationCompPrefix() )
.appendAscii( "media/image" ) .appendAscii( sRelPathToMedia.getStr() )
.append( (sal_Int32) mnImageCounter ++ ) .append( (sal_Int32) mnImageCounter ++ )
.appendAscii( pExtension ) .appendAscii( pExtension )
.makeStringAndClear() ); .makeStringAndClear() );
...@@ -792,9 +795,9 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic ) ...@@ -792,9 +795,9 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic )
return sRelId; return sRelId;
} }
OUString DrawingML::WriteBlip( Reference< XPropertySet > rXPropSet, OUString& rURL, const Graphic *pGraphic ) OUString DrawingML::WriteBlip( Reference< XPropertySet > rXPropSet, OUString& rURL, bool bRelPathToMedia, const Graphic *pGraphic )
{ {
OUString sRelId = pGraphic ? WriteImage( *pGraphic ) : WriteImage( rURL ); OUString sRelId = pGraphic ? WriteImage( *pGraphic, bRelPathToMedia ) : WriteImage( rURL, bRelPathToMedia );
sal_Int16 nBright = 0; sal_Int16 nBright = 0;
sal_Int32 nContrast = 0; sal_Int32 nContrast = 0;
...@@ -845,17 +848,27 @@ void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sUR ...@@ -845,17 +848,27 @@ void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sUR
if ( GetProperty( rXPropSet, sURLPropName ) ) { if ( GetProperty( rXPropSet, sURLPropName ) ) {
OUString aURL; OUString aURL;
mAny >>= aURL; mAny >>= aURL;
bool bWriteMode = false;
if( sURLPropName == "FillBitmapURL" || sURLPropName == "BackGraphicURL")
bWriteMode = true;
WriteBlipFill( rXPropSet, aURL, nXmlNamespace, bWriteMode );
}
}
DBG(fprintf (stderr, "URL: %s\n", OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() )); void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sBitmapURL, sal_Int32 nXmlNamespace, bool bWriteMode, bool bRelPathToMedia )
{
if ( !sBitmapURL.isEmpty() ) {
DBG(fprintf (stderr, "URL: %s\n", OUStringToOString( sBitmapURL, RTL_TEXTENCODING_UTF8 ).getStr() ));
if( aURL.isEmpty() )
if( sBitmapURL.isEmpty() )
return; return;
mpFS->startElementNS( nXmlNamespace , XML_blipFill, FSEND ); mpFS->startElementNS( nXmlNamespace , XML_blipFill, FSEND );
WriteBlip( rXPropSet, aURL ); WriteBlip( rXPropSet, sBitmapURL, bRelPathToMedia );
if( sURLPropName == "FillBitmapURL" || sURLPropName == "BackGraphicURL") if( bWriteMode )
WriteBlipMode( rXPropSet ); WriteBlipMode( rXPropSet );
else if( GetProperty( rXPropSet, "FillBitmapStretch" ) ) { else if( GetProperty( rXPropSet, "FillBitmapStretch" ) ) {
bool bStretch = false; bool bStretch = false;
...@@ -864,7 +877,6 @@ void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sUR ...@@ -864,7 +877,6 @@ void DrawingML::WriteBlipFill( Reference< XPropertySet > rXPropSet, OUString sUR
if( bStretch ) if( bStretch )
WriteStretch(); WriteStretch();
} }
mpFS->endElementNS( nXmlNamespace, XML_blipFill ); mpFS->endElementNS( nXmlNamespace, XML_blipFill );
} }
} }
......
...@@ -507,7 +507,7 @@ void ShapeExport::WriteGraphicObjectShapePart( Reference< XShape > xShape, const ...@@ -507,7 +507,7 @@ void ShapeExport::WriteGraphicObjectShapePart( Reference< XShape > xShape, const
pFS->startElementNS( mnXmlNamespace, XML_blipFill, FSEND ); pFS->startElementNS( mnXmlNamespace, XML_blipFill, FSEND );
WriteBlip( xShapeProps, sGraphicURL, pGraphic ); WriteBlip( xShapeProps, sGraphicURL, false, pGraphic );
WriteSrcRect( xShapeProps, sGraphicURL ); WriteSrcRect( xShapeProps, sGraphicURL );
......
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