OOXML/ODF Support for Shadow blur radius

Adding export support for OOXML. Adding import/export support for ODF
Changing some values in test cases as convertEMUtoHmm round the fraction.
Add two test functions for OOXML and ODF export.

Change-Id: Ie5d862b46b5264ead4954f407fee2837b5151cd7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96907
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
A_GAN 2020-06-22 23:39:16 +02:00 committed by Tomaž Vajngerl
parent cb0c7e26e5
commit 2803b09ec0
10 changed files with 66 additions and 4 deletions

View File

@ -1655,6 +1655,7 @@ namespace xmloff::token {
XML_SHADOW_OFFSET_Y,
XML_SHADOW_SLANT,
XML_SHADOW_TRANSPARENCY,
XML_SHADOW_BLUR,
XML_SHAPE,
XML_SHAPE_ID,
XML_SHAPES,

View File

@ -3618,7 +3618,7 @@ void DrawingML::WriteShapeEffect( const OUString& sName, const Sequence< Propert
}
else if( rOuterShdwProp.Name == "blurRad" )
{
sal_Int32 nVal = 0;
sal_Int64 nVal = 0;
rOuterShdwProp.Value >>= nVal;
aOuterShdwAttrList->add( XML_blurRad, OString::number( nVal ).getStr() );
}
@ -3802,16 +3802,20 @@ void DrawingML::WriteShapeEffects( const Reference< XPropertySet >& rXPropSet )
if( bHasShadow )
{
Sequence< PropertyValue > aShadowGrabBag( 3 );
Sequence< PropertyValue > aShadowAttribsGrabBag( 2 );
Sequence< PropertyValue > aShadowAttribsGrabBag( 3 );
double dX = +0.0, dY = +0.0;
sal_Int32 nBlur =0;
rXPropSet->getPropertyValue( "ShadowXDistance" ) >>= dX;
rXPropSet->getPropertyValue( "ShadowYDistance" ) >>= dY;
rXPropSet->getPropertyValue( "ShadowBlur" ) >>= nBlur;
aShadowAttribsGrabBag[0].Name = "dist";
aShadowAttribsGrabBag[0].Value <<= lcl_CalculateDist(dX, dY);
aShadowAttribsGrabBag[1].Name = "dir";
aShadowAttribsGrabBag[1].Value <<= lcl_CalculateDir(dX, dY);
aShadowAttribsGrabBag[2].Name = "blurRad";
aShadowAttribsGrabBag[2].Value <<= oox::drawingml::convertHmmToEmu(nBlur);
aShadowGrabBag[0].Name = "Attribs";
aShadowGrabBag[0].Value <<= aShadowAttribsGrabBag;
@ -3836,8 +3840,11 @@ void DrawingML::WriteShapeEffects( const Reference< XPropertySet >& rXPropSet )
rOuterShdwProp.Value >>= aAttribsProps;
double dX = +0.0, dY = +0.0;
sal_Int32 nBlur =0;
rXPropSet->getPropertyValue( "ShadowXDistance" ) >>= dX;
rXPropSet->getPropertyValue( "ShadowYDistance" ) >>= dY;
rXPropSet->getPropertyValue( "ShadowBlur" ) >>= nBlur;
for( auto& rAttribsProp : aAttribsProps )
{
@ -3849,6 +3856,10 @@ void DrawingML::WriteShapeEffects( const Reference< XPropertySet >& rXPropSet )
{
rAttribsProp.Value <<= lcl_CalculateDir(dX, dY);
}
else if( rAttribsProp.Name == "blurRad" )
{
rAttribsProp.Value <<= oox::drawingml::convertHmmToEmu(nBlur);
}
}
rOuterShdwProp.Value <<= aAttribsProps;

View File

@ -344,6 +344,12 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.
<rng:ref name="zeroToHundredPercent"/>
</rng:attribute>
</rng:optional>
<!-- TODO: no proposal for loext:shadow-blur -->
<rng:optional>
<rng:attribute name="loext:shadow-blur">
<rng:ref name="length"/>
</rng:attribute>
</rng:optional>
<rng:optional>
<rng:attribute name="draw:start-line-spacing-horizontal">
<rng:ref name="distance"/>

Binary file not shown.

View File

@ -197,6 +197,7 @@ public:
void testTdf132282();
void testTdf132201EffectOrder();
void testShapeSoftEdgeEffect();
void testShapeShadowBlurEffect();
CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
@ -311,6 +312,7 @@ public:
CPPUNIT_TEST(testTdf132282);
CPPUNIT_TEST(testTdf132201EffectOrder);
CPPUNIT_TEST(testShapeSoftEdgeEffect);
CPPUNIT_TEST(testShapeShadowBlurEffect);
CPPUNIT_TEST_SUITE_END();
@ -2911,6 +2913,20 @@ void SdOOXMLExportTest2::testShapeSoftEdgeEffect()
CPPUNIT_ASSERT_EQUAL(sal_Int32(635), nRadius); // 18 pt
}
void SdOOXMLExportTest2::testShapeShadowBlurEffect()
{
auto xDocShRef
= loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/shape-blur-effect.pptx"), PPTX);
xDocShRef = saveAndReload(xDocShRef.get(), PPTX);
uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(0, 0, xDocShRef));
bool bHasShadow = false;
xShape->getPropertyValue("Shadow") >>= bHasShadow;
CPPUNIT_ASSERT(bHasShadow);
sal_Int32 nRadius = -1;
xShape->getPropertyValue("ShadowBlur") >>= nRadius;
CPPUNIT_ASSERT_EQUAL(sal_Int32(388), nRadius); // 11 pt
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest2);
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@ -76,6 +76,7 @@ public:
void testTdf126761();
void testGlow();
void testSoftEdges();
void testShadowBlur();
CPPUNIT_TEST_SUITE(SdExportTest);
@ -112,6 +113,7 @@ public:
CPPUNIT_TEST(testTdf126761);
CPPUNIT_TEST(testGlow);
CPPUNIT_TEST(testSoftEdges);
CPPUNIT_TEST(testShadowBlur);
CPPUNIT_TEST_SUITE_END();
@ -1307,6 +1309,29 @@ void SdExportTest::testSoftEdges()
xDocShRef->DoClose();
}
void SdExportTest::testShadowBlur()
{
auto xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/odg/shadow-blur.odg"), ODG);
utl::TempFile tempFile;
xDocShRef = saveAndReload(xDocShRef.get(), ODG, &tempFile);
uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(0, 0, xDocShRef));
sal_Int32 nRad = 0;
CPPUNIT_ASSERT(xShape->getPropertyValue("ShadowBlur") >>= nRad);
CPPUNIT_ASSERT_EQUAL(sal_Int32(388), nRad); // 11 pt = 388 Hmm
xmlDocUniquePtr pXmlDoc = parseExport(tempFile, "content.xml");
assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[2]",
"family", "graphic");
assertXPath(
pXmlDoc,
"/office:document-content/office:automatic-styles/style:style[2]/style:graphic-properties",
"shadow-blur", "0.388cm");
xDocShRef->DoClose();
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@ -173,7 +173,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testShapeEffectPreservation, "shape-effect-p
"algn", "tl");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"blurRad", "50800");
"blurRad", "50760"); // because convertEMUtoHmm rounds fractions into nearest integer 50800 will be 50760
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"dir", "2700000");
@ -196,7 +196,7 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testShapeEffectPreservation, "shape-effect-p
"algn", "tl");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"blurRad", "114300");
"blurRad", "114480"); // because convertEMUtoHmm rounds fractions into nearest integer 114300 will be 114480
assertXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"dir", "2700000");

View File

@ -1661,6 +1661,7 @@ namespace xmloff::token {
TOKEN( "shadow-offset-y", XML_SHADOW_OFFSET_Y ),
TOKEN( "shadow-slant", XML_SHADOW_SLANT ),
TOKEN( "shadow-transparency", XML_SHADOW_TRANSPARENCY ),
TOKEN( "shadow-blur", XML_SHADOW_BLUR ),
TOKEN( "shape", XML_SHAPE ),
TOKEN( "shape-id", XML_SHAPE_ID ),
TOKEN( "shapes", XML_SHAPES ),

View File

@ -151,6 +151,7 @@ const XMLPropertyMapEntry aXMLSDProperties[] =
GMAP( "ShadowYDistance", XML_NAMESPACE_DRAW, XML_SHADOW_OFFSET_Y, XML_TYPE_MEASURE, 0 ),
GMAP( "ShadowColor", XML_NAMESPACE_DRAW, XML_SHADOW_COLOR, XML_TYPE_COLOR, 0 ),
GMAP( "ShadowTransparence", XML_NAMESPACE_DRAW, XML_SHADOW_OPACITY, XML_TYPE_NEG_PERCENT, 0 ),
GMAPV( "ShadowBlur", XML_NAMESPACE_LO_EXT, XML_SHADOW_BLUR, XML_TYPE_MEASURE, 0, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED),
// glow attributes
GMAPV( "GlowEffectRadius", XML_NAMESPACE_LO_EXT, XML_GLOW_RADIUS, XML_TYPE_MEASURE , 0, SvtSaveOptions::ODFSVER_FUTURE_EXTENDED),

View File

@ -1571,6 +1571,7 @@ shadow-offset-x
shadow-offset-y
shadow-slant
shadow-transparency
shadow-blur
shape
shape-id
shapes