summaryrefslogtreecommitdiff
path: root/svx/source/toolbars
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2022-01-13 13:26:25 +0100
committerRegina Henschel <rb.henschel@t-online.de>2022-02-17 14:14:01 +0100
commit157b027c4cfca2582b1c1bdb66992560084ac008 (patch)
tree41ae4086069acc86fb36ccbb23a1eb82bfa5117c /svx/source/toolbars
parent424cd919c4234d6e6fd4da89acd90197771f7b9d (diff)
tdf#145700 Improve lighting in extruded custom shapes
The fix tries to make rendering similar to MS Office. The ODF standard follows closely the extrusion in RTF and MS binary format. Rendering uses the 3D scene engine. The main problem was, that the z-component of the direction was interpreted with opposite sign. As result the maximum of a light was at false position. Especially a direction from the observer to the object has produced a light behind the shape and so looks as if light was off. The wrong z-direction has produced lighting, which was less intensive than in MS Office. To compensate that, a third light source was added as workaround. That part is removed. Second problem was wrong use of 3D-scene D3DMaterialSpecularIntensity and D3DMaterialSpecular (= UI Specular color). That was not only wrong in OOo but in my previous patch too. D3DMaterialSpecularIntensity corresponds to MS property 'c3DShininess'. Relationship is Intensity = 2^c3DShininess. D3DMaterialSpecular is calculated from MS property c3DSpecularAmt and and c3DKeyIntensity. The light source was missing, but needs to be included, because c3DSpecularAmt is 'the ratio of incident to specular light that is reflected on a shape'. The old unit tests are adapted to this change. MS gives no information how it softens a light in case of harsh=false. ODF specifies it as 'implementation-defined'. The patch uses four additional lights, which have directions in 60° angle to the original light. The light intensity is distributed. That comes near to rendering in MS Office. Changing our 3D engine to provide 'soft' lights was not doable for me. The way MS Office renders a 'metal' surface is different from ODF specification. To distinguish the kinds, I have introduced a new property MetalType. I have discussed it with the ODF TC (see minutes from 2022-02-07) and got the advise to use namespaced values. Therefore the datatype is not boolean. The 'Surface' drop-down in the extrusion bar is changed to make the two kinds of rendering 'Metal' available to the user. If a user sets surface 'Metal' in the UI of MS Office, it sets not only fc3DMetallic but reduces the value of c3DDiffuseAmt in addition. Our 3D-scene engine has the corresponding ODF attribute dr3d:diffuse-color not implemented. To get a similar rendering I change the material color of the 3D-objects as workaround. Change-Id: Ia986b9c318b4c79688e0c0e2d858215b9d612fdc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128449 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'svx/source/toolbars')
-rw-r--r--svx/source/toolbars/extrusionbar.cxx126
1 files changed, 89 insertions, 37 deletions
diff --git a/svx/source/toolbars/extrusionbar.cxx b/svx/source/toolbars/extrusionbar.cxx
index 659af238d77e..26ac4805cde0 100644
--- a/svx/source/toolbars/extrusionbar.cxx
+++ b/svx/source/toolbars/extrusionbar.cxx
@@ -18,6 +18,7 @@
*/
+#include <com/sun/star/drawing/EnhancedCustomShapeMetalType.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
#include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
#include <com/sun/star/drawing/ShadeMode.hpp>
@@ -126,9 +127,9 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
{
css::uno::Any* pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, sExtrusion );
+ bool bOn(false);
if( pAny )
{
- bool bOn(false);
(*pAny) >>= bOn;
bOn = !bOn;
(*pAny) <<= bOn;
@@ -139,6 +140,23 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
aPropValue.Name = sExtrusion;
aPropValue.Value <<= true;
rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
+ bOn = true;
+ }
+ // draw:extrusion-diffusion has default 0% and c3DDiffuseAmt has default 100%. We set property
+ // "Diffusion" with value 100% here if it does not exist already. This forces, that the
+ // property is written to file in case an extrusion is newly created, and users of old
+ // documents, which usually do not have this property, can force the value to 100% by toggling
+ // the extrusion off and on.
+ if (bOn)
+ {
+ pAny = rGeometryItem.GetPropertyValueByName(sExtrusion, u"Diffusion");
+ if (!pAny)
+ {
+ css::beans::PropertyValue aPropValue;
+ aPropValue.Name = u"Diffusion";
+ aPropValue.Value <<= 100.0;
+ rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
+ }
}
}
break;
@@ -335,52 +353,75 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
break;
case 1: // matte
case 2: // plastic
- case 3: // metal
+ case 3: // metal ODF
+ case 4: // metal MS Office
if (eOldShadeMode == ShadeMode_DRAFT)
eShadeMode = ShadeMode_FLAT; // ODF default
break;
}
- bool bMetal = nSurface == 3;
-
// ODF has no dedicated property for 'surface'. MS Office binary format uses attribute
// c3DSpecularAmt to distinguish between 'matte' (=0) and 'plastic'.
- // From point of ODF, using not harsh light has similar effect.
+ // We do the same.
double fOldSpecularity = 0.0;
pAny = rGeometryItem.GetPropertyValueByName(sExtrusion, u"Specularity");
if (pAny)
*pAny >>= fOldSpecularity;
double fSpecularity = fOldSpecularity;
- bool bOldIsFirstLightHarsh = true;
- pAny = rGeometryItem.GetPropertyValueByName(sExtrusion, u"FirstLightHarsh");
- if (pAny)
- *pAny >>= bOldIsFirstLightHarsh;
- bool bIsFirstLightHarsh = bOldIsFirstLightHarsh;
switch( nSurface )
{
case 0: // wireframe
break;
case 1: // matte
fSpecularity = 0.0;
- bIsFirstLightHarsh = false;
break;
case 2: // plastic
- case 3: // metal
+ case 3: // metal ODF
+ case 4: // metal MS Office
if (basegfx::fTools::equalZero(fOldSpecularity, 0.0001))
- fSpecularity = 80; // estimated value, can be changed if necessary
- if (!bOldIsFirstLightHarsh)
- bIsFirstLightHarsh = true;
+ // MS Office uses 80000/65536. That is currently not allowed in ODF.
+ // But the ODF error will be catched in xmloff.
+ fSpecularity = 80000.0 / 655.36; // interpreted as %
break;
}
+ // MS Office binary format uses attribute c3DDiffuseAmt with value =43712 (Fixed 16.16) in
+ // addition to the 'metal' flag. For other surface kinds default = 65536 is used.
+ // We toggle between 100 and 43712.0 / 655.36 here, to get better ODF -> MSO binary.
+ // We keep other values, those might be set outside regular UI, e.g by macro.
+ double fOldDiffusion = 100.0;
+ pAny = rGeometryItem.GetPropertyValueByName(sExtrusion, u"Diffusion");
+ if (pAny)
+ *pAny >>= fOldDiffusion;
+ double fDiffusion = fOldDiffusion;
+ if (nSurface == 4)
+ {
+ if (fOldDiffusion == 100.0)
+ fDiffusion = 43712.0 / 655.36; // interpreted as %
+ }
+ else
+ {
+ if (basegfx::fTools::equalZero(fOldDiffusion - 43712.0 / 655.36, 0.0001))
+ fDiffusion = 100.0;
+ }
+
css::beans::PropertyValue aPropValue;
aPropValue.Name = "ShadeMode";
aPropValue.Value <<= eShadeMode;
rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
aPropValue.Name = "Metal";
- aPropValue.Value <<= bMetal;
- rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
+ aPropValue.Value <<= nSurface == 3 || nSurface == 4;
+ rGeometryItem.SetPropertyValue(sExtrusion, aPropValue);
+
+ if (nSurface == 3 || nSurface == 4)
+ {
+ aPropValue.Name = "MetalType";
+ aPropValue.Value <<= nSurface == 4
+ ? EnhancedCustomShapeMetalType::MetalMSCompatible
+ : EnhancedCustomShapeMetalType::MetalODF;
+ rGeometryItem.SetPropertyValue(sExtrusion, aPropValue);
+ }
if (!basegfx::fTools::equalZero(fOldSpecularity - fSpecularity, 0.0001))
{
@@ -389,10 +430,10 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
rGeometryItem.SetPropertyValue(sExtrusion, aPropValue);
}
- if (bOldIsFirstLightHarsh != bIsFirstLightHarsh)
+ if (!basegfx::fTools::equalZero(fOldDiffusion - fDiffusion, 0.0001))
{
- aPropValue.Name = "FirstLightHarsh";
- aPropValue.Value <<= bIsFirstLightHarsh;
+ aPropValue.Name = "Diffusion";
+ aPropValue.Value <<= fDiffusion;
rGeometryItem.SetPropertyValue(sExtrusion, aPropValue);
}
}
@@ -404,16 +445,17 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
{
sal_Int32 nLevel = rReq.GetArgs()->GetItem<SfxInt32Item>(SID_EXTRUSION_LIGHTING_INTENSITY)->GetValue();
- double fBrightness;
- double fLevel1;
- double fLevel2;
+ double fBrightness; // c3DAmbientIntensity in MS Office
+ double fLevel1; // c3DKeyIntensity in MS Office
+ double fLevel2; // c3DFillIntensity in MS Office
+ // ToDo: "bright" values are different from MS Office. Should they be kept?
switch( nLevel )
{
case 0: // bright
- fBrightness = 34.0;
- fLevel1 = 66.0;
- fLevel2 = 66.0;
+ fBrightness = 33.0; // ODF default.
+ fLevel1 = 66.0; // ODF default
+ fLevel2 = 66.0; // ODF default
break;
case 1: // normal
fBrightness = 15.0;
@@ -432,10 +474,6 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
aPropValue.Value <<= fBrightness;
rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
- aPropValue.Name = "SecondLightHarsh";
- aPropValue.Value <<= false;
- rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
-
aPropValue.Name = "FirstLightLevel";
aPropValue.Value <<= fLevel1;
rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
@@ -443,6 +481,12 @@ static void impl_execute( SfxRequest const & rReq, SdrCustomShapeGeometryItem& r
aPropValue.Name = "SecondLightLevel";
aPropValue.Value <<= fLevel2;
rGeometryItem.SetPropertyValue( sExtrusion, aPropValue );
+
+ // If a user sets light preset 'Dim' in MS Office, MS Office sets second light to harsh.
+ // In other cases it is soft.
+ aPropValue.Name = "SecondLightHarsh";
+ aPropValue.Value <<= nLevel == 2;
+ rGeometryItem.SetPropertyValue(sExtrusion, aPropValue);
}
}
break;
@@ -665,8 +709,8 @@ static void getExtrusionDirectionState( SdrView const * pSdrView, SfxItemSet& rS
}
bool bParallel = true;
- Position3D aViewPoint( 3472, -3472, 25000 );
- double fSkewAngle = -135;
+ Position3D aViewPoint( 3472, -3472, 25000 ); // MSO default
+ double fSkewAngle = -135; // MSO default
pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, "ProjectionMode" );
sal_Int16 nProjectionMode = sal_Int16();
@@ -869,25 +913,33 @@ static void getExtrusionSurfaceState( SdrView const * pSdrView, SfxItemSet& rSet
sal_Int32 nSurface = 0; // wire frame
ShadeMode eShadeMode( ShadeMode_FLAT );
- pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, "ShadeMode" );
+ pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, u"ShadeMode" );
if( pAny )
*pAny >>= eShadeMode;
if (eShadeMode != ShadeMode_DRAFT)
{
bool bMetal = false;
- pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, "Metal" );
+ pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, u"Metal" );
if( pAny )
*pAny >>= bMetal;
if( bMetal )
{
- nSurface = 3; // metal
+ nSurface = 3; // metal ODF
+ sal_Int16 eMetalType;
+ pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, u"MetalType" );
+ if (pAny)
+ {
+ *pAny >>= eMetalType;
+ if (eMetalType == EnhancedCustomShapeMetalType::MetalMSCompatible)
+ nSurface = 4; // metal MS Office
+ }
}
else
{
double fSpecularity = 0;
- pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, "Specularity" );
+ pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, u"Specularity" );
if( pAny )
*pAny >>= fSpecularity;
@@ -951,7 +1003,7 @@ static void getExtrusionDepthState( SdrView const * pSdrView, SfxItemSet& rSet )
continue;
}
- double fDepth = 1270.0;
+ double fDepth = 1270.0; // =36pt ODF default
pAny = rGeometryItem.GetPropertyValueByName( sExtrusion, "Depth" );
if( pAny )
{