Kaydet (Commit) 73ad72e8 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

ooxml: Preserve effects on pictures

If a picture contains some 2D (glow, shadow...) or 3D effect
(rotation, extrusion...), we prevent the importer from transforming
it into a XTextContent so the XShape grab bag is not removed and
the effects are preserved using the existing mechanisms. Added a unit
test for this issue, and modified some existing unit tests to match
the new behaviour.

Change-Id: I3b87069ea208604383a592d34d0a4ceb6b0f9fc7
üst be415a0f
......@@ -530,6 +530,10 @@ void ShapeExport::WriteGraphicObjectShapePart( Reference< XShape > xShape, const
WritePresetShape( "rect" );
// graphic object can come with the frame (bnc#654525)
WriteOutline( xShapeProps );
WriteShapeEffects( xShapeProps );
WriteShape3DEffects( xShapeProps );
pFS->endElementNS( mnXmlNamespace, XML_spPr );
pFS->endElementNS( mnXmlNamespace, XML_pic );
......
......@@ -1079,8 +1079,10 @@ DECLARE_OOXMLEXPORT_TEST(testFdo67737, "fdo67737.docx")
DECLARE_OOXMLEXPORT_TEST(testTransparentShadow, "transparent-shadow.docx")
{
uno::Reference<drawing::XShape> xPicture = getShape(1);
table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xPicture, "ShadowFormat");
CPPUNIT_ASSERT_EQUAL(sal_Int32(0x7f808080), aShadow.Color);
sal_Int32 nShadowColor = getProperty<sal_Int32>(xPicture, "ShadowColor");
sal_Int16 nShadowTransparence = getProperty<sal_Int16>(xPicture, "ShadowTransparence");
CPPUNIT_ASSERT_EQUAL(sal_Int32(0x808080), nShadowColor);
CPPUNIT_ASSERT_EQUAL(sal_Int16(50), nShadowTransparence);
}
DECLARE_OOXMLEXPORT_TEST(testBnc834035, "bnc834035.odt")
......
......@@ -1285,6 +1285,59 @@ DECLARE_OOXMLEXPORT_TEST(testShape3DEffectPreservation, "shape-3d-effect-preserv
"prstMaterial", "legacyWireframe");
}
DECLARE_OOXMLEXPORT_TEST(testPictureEffectPreservation, "picture-effects-preservation.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
// first picture: glow effect with theme color and transformations, 3d rotation and extrusion
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:glow",
"rad", "228600");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:glow/a:schemeClr",
"val", "accent1");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:glow/a:schemeClr/*",
2);
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:scene3d/a:camera",
"prst", "isometricRightUp");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:scene3d/a:lightRig",
"rig", "threePt");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:sp3d",
"extrusionH", "76200");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:sp3d/a:extrusionClr/a:srgbClr",
"val", "92d050");
// second picture: shadow and reflection effects
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:outerShdw",
"dir", "8100000");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:outerShdw/a:srgbClr",
"val", "000000");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:outerShdw/a:srgbClr/a:alpha",
"val", "40000");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:reflection",
"dir", "5400000");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:reflection/*",
0 ); // should not be present
// third picture: soft edge effect
assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:softEdge",
"rad", "63500");
}
DECLARE_OOXMLEXPORT_TEST(fdo77719, "fdo77719.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
......
......@@ -828,9 +828,11 @@ DECLARE_OOXMLIMPORT_TEST(testShadow, "imgshadow.docx")
*/
uno::Reference<beans::XPropertySet> xPropertySet(getShape(2), uno::UNO_QUERY);
table::ShadowFormat aShadow;
xPropertySet->getPropertyValue("ShadowFormat") >>= aShadow;
CPPUNIT_ASSERT(sal_Int32(aShadow.ShadowWidth) > 0);
bool bShadow = getProperty<bool>(xPropertySet, "Shadow");
CPPUNIT_ASSERT(bShadow);
sal_Int32 nShadowXDistance = getProperty<sal_Int32>(xPropertySet, "ShadowXDistance");
CPPUNIT_ASSERT(nShadowXDistance != 0);
}
DECLARE_OOXMLIMPORT_TEST(testN782061, "n782061.docx")
......
......@@ -643,6 +643,17 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
sal_Int32 nRotation = 0;
xShapeProps->getPropertyValue("RotateAngle") >>= nRotation;
::css::beans::PropertyValues aGrabBag;
bool bContainsEffects = false;
xShapeProps->getPropertyValue("InteropGrabBag") >>= aGrabBag;
for( sal_Int32 i = 0; i < aGrabBag.getLength(); ++i )
{
// if the shape contains effects in the grab bag, we should not transform it
// in a XTextContent so those effects can be preserved
if( aGrabBag[i].Name == "EffectProperties" || aGrabBag[i].Name == "3DEffectProperties" )
bContainsEffects = true;
}
::com::sun::star::beans::PropertyValues aMediaProperties( 1 );
aMediaProperties[0].Name = "URL";
aMediaProperties[0].Value <<= sUrl;
......@@ -661,7 +672,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
xShapeProps->getPropertyValue("AdjustContrast") >>= m_pImpl->nContrast;
// fdo#70457: transform XShape into a SwXTextGraphicObject only if there's no rotation
if ( nRotation == 0 )
if ( nRotation == 0 && !bContainsEffects )
m_xGraphicObject = createGraphicObject( aMediaProperties );
bUseShape = !m_xGraphicObject.is( );
......
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