[Libreoffice-commits] core.git: include/svx svx/source

Regina Henschel rb.henschel at t-online.de
Mon Jan 23 08:16:52 UTC 2017


 include/svx/svdopath.hxx                          |    2 
 svx/source/customshapes/EnhancedCustomShape2d.cxx |   72 ++++++++++++++--------
 svx/source/svdraw/svdopath.cxx                    |    2 
 3 files changed, 50 insertions(+), 26 deletions(-)

New commits:
commit 852b29b091eeb4d4b9521b082b522c37a2a6ec16
Author: Regina Henschel <rb.henschel at t-online.de>
Date:   Fri Jan 20 09:06:23 2017 +0100

    tdf#105266 Make LIGHTEN and DARKEN follow MS specification
    
    Enhanced geometry of custom shapes has got commands for LIGHTEN and
    DARKEN of subpaths. MS specifies, that LIGHTEN is a blending with
    white and DARKEN is a blending with black. This patch adapts the
    calcuation accordingly.
    
    Change-Id: Ie46f1a1a2210c209c3fac34a7a58758b72eb276c
    Reviewed-on: https://gerrit.libreoffice.org/33337
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: jan iversen <jani at documentfoundation.org>

diff --git a/include/svx/svdopath.hxx b/include/svx/svdopath.hxx
index 08f6179..85eca76 100644
--- a/include/svx/svdopath.hxx
+++ b/include/svx/svdopath.hxx
@@ -69,7 +69,7 @@ public:
     double GetBrightness() { return mdBrightness; }
 
     SdrPathObj(SdrObjKind eNewKind);
-    SdrPathObj(SdrObjKind eNewKind, const basegfx::B2DPolyPolygon& rPathPoly, double dBrightness = 1.0);
+    SdrPathObj(SdrObjKind eNewKind, const basegfx::B2DPolyPolygon& rPathPoly, double dBrightness = 0.0);
     virtual ~SdrPathObj() override;
 
     virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index c5c0601..011a4ac 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -1039,16 +1039,40 @@ sal_Int32 EnhancedCustomShape2d::GetLuminanceChange( sal_uInt32 nIndex ) const
 
 Color EnhancedCustomShape2d::GetColorData( const Color& rFillColor, sal_uInt32 nIndex, double dBrightness ) const
 {
-    const sal_Int32 nLuminance = GetLuminanceChange(nIndex);
-    if( !nLuminance && dBrightness == 1.0 )
-        return rFillColor;
-
-    basegfx::BColor aHSVColor=
-        basegfx::tools::rgb2hsv(
-            basegfx::BColor(rFillColor.GetRed()/255.0,
-                            rFillColor.GetGreen()/255.0,
-                            rFillColor.GetBlue()/255.0));
-    if (nLuminance ) {
+    if ( bOOXMLShape || ( mso_sptMin == eSpType /* ODF "non-primitive" */ ) )
+    { //do LibreOffice way, using dBrightness
+        if ( dBrightness == 0.0)
+        {
+            return rFillColor;
+        }
+        else
+        {
+            if (dBrightness >=0.0)
+            { //lighten, blending with white
+                return Color( (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(rFillColor.GetRed() * (1.0-dBrightness) + dBrightness * 255.0, 0.0, 255.0)  ),
+                              (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(rFillColor.GetGreen() * (1.0-dBrightness) + dBrightness * 255.0, 0.0, 255.0) ),
+                              (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(rFillColor.GetBlue() * (1.0-dBrightness) + dBrightness * 255.0, 0.0, 255.0) )  );
+            }
+            else
+            { //darken (indicated by negative sign), blending with black
+                return Color( (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(rFillColor.GetRed() * (1.0+dBrightness), 0.0, 255.0)  ),
+                              (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(rFillColor.GetGreen() * (1.0+dBrightness), 0.0, 255.0) ),
+                              (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(rFillColor.GetBlue() * (1.0+dBrightness), 0.0, 255.0) )  );
+            }
+        }
+    }
+    else
+    { //do OpenOffice way, using nColorData
+        const sal_Int32 nLuminance = GetLuminanceChange(nIndex);
+        if( !nLuminance )
+            return rFillColor;
+
+        basegfx::BColor aHSVColor=
+                basegfx::tools::rgb2hsv(
+                    basegfx::BColor(rFillColor.GetRed()/255.0,
+                                    rFillColor.GetGreen()/255.0,
+                                    rFillColor.GetBlue()/255.0));
+
         if( nLuminance > 0 )
         {
             aHSVColor.setGreen(
@@ -1062,12 +1086,12 @@ Color EnhancedCustomShape2d::GetColorData( const Color& rFillColor, sal_uInt32 n
             aHSVColor.setBlue(
                 (1.0+nLuminance/100.0)*aHSVColor.getBlue());
         }
-    }
 
-    aHSVColor = basegfx::tools::hsv2rgb(aHSVColor);
-    return Color( (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(dBrightness*aHSVColor.getRed(),0.0,1.0) * 255.0 + 0.5 ),
-                  (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(dBrightness*aHSVColor.getGreen(),0.0,1.0) * 255.0 + 0.5 ),
-                  (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(dBrightness*aHSVColor.getBlue(),0.0,1.0) * 255.0 + 0.5 ) );
+        aHSVColor = basegfx::tools::hsv2rgb(aHSVColor);
+        return Color( (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getRed(),0.0,1.0) * 255.0 + 0.5 ),
+                    (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getGreen(),0.0,1.0) * 255.0 + 0.5 ),
+                    (sal_uInt8)static_cast< sal_Int32 >( basegfx::clamp(aHSVColor.getBlue(),0.0,1.0) * 255.0 + 0.5 ) );
+    }
 }
 
 Rectangle EnhancedCustomShape2d::GetTextRect() const
@@ -1431,7 +1455,7 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
 {
     bool bNoFill = false;
     bool bNoStroke = false;
-    double dBrightness = 1.0;
+    double dBrightness = 0.0; //no blending
 
     basegfx::B2DPolyPolygon aNewB2DPolyPolygon;
     basegfx::B2DPolygon aNewB2DPolygon;
@@ -1468,16 +1492,16 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
                     bNoStroke = true;
                 break;
                 case DARKEN :
-                    dBrightness = 0.66666666;
+                    dBrightness = -0.4; //use sign to distinguish DARKEN from LIGHTEN
                     break;
                 case DARKENLESS :
-                    dBrightness = 0.83333333;
+                    dBrightness = -0.2;
                     break;
                 case LIGHTEN :
-                    dBrightness = 1.16666666;
+                    dBrightness = 0.4;
                     break;
                 case LIGHTENLESS :
-                    dBrightness = 1.33333333;
+                    dBrightness = 0.2;
                     break;
                 case MOVETO :
                 {
@@ -2134,7 +2158,7 @@ void EnhancedCustomShape2d::AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rC
             case drawing::FillStyle_SOLID:
             {
                 Color aFillColor;
-                if ( nColorCount || rObj.GetBrightness() != 1.0 )
+                if ( nColorCount || rObj.GetBrightness() != 0.0 )
                 {
                     aFillColor = GetColorData(
                         static_cast<const XFillColorItem&>(rCustomShapeSet.Get( XATTR_FILLCOLOR )).GetColorValue(),
@@ -2146,7 +2170,7 @@ void EnhancedCustomShape2d::AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rC
             case drawing::FillStyle_GRADIENT:
             {
                 XGradient aXGradient(static_cast<const XFillGradientItem&>(rObj.GetMergedItem(XATTR_FILLGRADIENT)).GetGradientValue());
-                if ( nColorCount || rObj.GetBrightness() != 1.0 )
+                if ( nColorCount || rObj.GetBrightness() != 0.0 )
                 {
                     aXGradient.SetStartColor(
                         GetColorData(
@@ -2164,7 +2188,7 @@ void EnhancedCustomShape2d::AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rC
             case drawing::FillStyle_HATCH:
             {
                 XHatch aXHatch(static_cast<const XFillHatchItem&>(rObj.GetMergedItem(XATTR_FILLHATCH)).GetHatchValue());
-                if ( nColorCount || rObj.GetBrightness() != 1.0 )
+                if ( nColorCount || rObj.GetBrightness() != 0.0 )
                 {
                     aXHatch.SetColor(
                         GetColorData(
@@ -2177,7 +2201,7 @@ void EnhancedCustomShape2d::AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rC
             }
             case drawing::FillStyle_BITMAP:
             {
-                if ( nColorCount || rObj.GetBrightness() != 1.0 )
+                if ( nColorCount || rObj.GetBrightness() != 0.0 )
                 {
                     Bitmap aBitmap(static_cast<const XFillBitmapItem&>(rObj.GetMergedItem(XATTR_FILLBITMAP)).GetGraphicObject().GetGraphic().GetBitmapEx().GetBitmap());
 
diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx
index 0d84293..1d94274 100644
--- a/svx/source/svdraw/svdopath.cxx
+++ b/svx/source/svdraw/svdopath.cxx
@@ -1669,7 +1669,7 @@ sdr::contact::ViewContact* SdrPathObj::CreateObjectSpecificViewContact()
 SdrPathObj::SdrPathObj(SdrObjKind eNewKind)
 :   meKind(eNewKind),
     mpDAC(nullptr),
-    mdBrightness(1.0)
+    mdBrightness(0.0)
 {
     bClosedObj = IsClosed();
 }


More information about the Libreoffice-commits mailing list