[Libreoffice-commits] core.git: 3 commits - include/vcl svtools/source sw/source vcl/source

Caolán McNamara caolanm at redhat.com
Wed Jun 19 04:17:40 PDT 2013


 include/vcl/bitmap.hxx              |   29 -----
 include/vcl/bitmapex.hxx            |   32 +++++
 svtools/source/control/ctrlbox.cxx  |   14 +-
 svtools/source/control/valueset.cxx |   14 +-
 sw/source/core/txtnode/txtedt.cxx   |   13 ++
 sw/source/core/undo/unins.cxx       |   13 ++
 vcl/source/control/ilstbox.cxx      |   32 ++---
 vcl/source/gdi/bitmap4.cxx          |  194 ------------------------------------
 vcl/source/gdi/bitmapex.cxx         |  149 +++++++++++++++++++++++++++
 vcl/source/gdi/outdev2.cxx          |    9 +
 10 files changed, 238 insertions(+), 261 deletions(-)

New commits:
commit 18eba6a69f49c9e8e2902f84e96cb6906ee337f1
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Jun 19 12:14:52 2013 +0100

    bounds can be -1 for not-found
    
    Change-Id: I941ef1dae00167460f2f0de39e472ed047539f27

diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 1716010..691da30 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -595,6 +595,15 @@ void SwTxtNode::RstAttr(const SwIndex &rIdx, xub_StrLen nLen, sal_uInt16 nWhich,
     }
 }
 
+sal_Int32 clipIndexBounds(const OUString &rStr, sal_Int32 nPos)
+{
+    if (nPos < 0)
+        return 0;
+    if (nPos > rStr.getLength())
+        return rStr.getLength();
+    return nPos;
+}
+
 /*************************************************************************
  *                SwTxtNode::GetCurWord()
  *
@@ -640,6 +649,10 @@ XubString SwTxtNode::GetCurWord( xub_StrLen nPos ) const
     if (aBndry.endPos != aBndry.startPos && IsSymbol( (xub_StrLen)aBndry.startPos ))
         aBndry.endPos = aBndry.startPos;
 
+    // can have -1 as start/end of bounds not found
+    aBndry.startPos = clipIndexBounds(m_Text, aBndry.startPos);
+    aBndry.endPos = clipIndexBounds(m_Text, aBndry.endPos);
+
     return m_Text.copy(aBndry.startPos,
                        aBndry.endPos - aBndry.startPos);
 }
commit 967b623031cd115722e2708f1281282ca8dccbe0
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Jun 19 11:10:08 2013 +0100

    unusual negative start point on split node undo
    
    Change-Id: I787371e95d9787616ca713c808098b80e40acab0

diff --git a/sw/source/core/undo/unins.cxx b/sw/source/core/undo/unins.cxx
index 4ac9ecb..eafb7f4 100644
--- a/sw/source/core/undo/unins.cxx
+++ b/sw/source/core/undo/unins.cxx
@@ -74,9 +74,18 @@ String * SwUndoInsert::GetTxtFromDoc() const
 
     if( pCNd->IsTxtNode() )
     {
-        pResult = new String(
-            static_cast<SwTxtNode*>(pCNd)->GetTxt().copy(nCntnt-nLen, nLen));
+        OUString sTxt = static_cast<SwTxtNode*>(pCNd)->GetTxt();
 
+        sal_Int32 nStart = nCntnt-nLen;
+        sal_Int32 nLength = nLen;
+
+        if (nStart < 0)
+        {
+            nLength += nStart;
+            nStart = 0;
+        }
+
+        pResult = new String(sTxt.copy(nStart, nLength));
     }
 
     return pResult;
commit c96802f0e2e553bfbb3bd036df95ea34d2f5741a
Author: Armin Le Grand <alg at apache.org>
Date:   Wed Jun 5 14:51:49 2013 +0000

    Resolves: #i122418# Added workaround to not use GetBitmap on windows
    
    (cherry picked from commit 136976efb17b8617a83c7f26601cd04031b51e7f)
    
    Conflicts:
    	vcl/inc/vcl/bitmap.hxx
    	vcl/inc/vcl/bitmapex.hxx
    	vcl/source/gdi/bitmap4.cxx
    	vcl/source/gdi/bitmapex.cxx
    
    Change-Id: I9c3aeae76c155c9050404f67adeb91106502c3f1

diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index b4e07fb..49dd147 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -811,35 +811,6 @@ public:
                                     const Link* pProgress = NULL );
 
 public:
-    /** Draw a blend frame to the Bitmap
-
-        @param nAlpha
-        The blend value defines how strong the frame will be blended with the
-        existing content, 255 == full coverage, 0 == no frame will be drawn
-
-        @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
-        The colors defining the frame. If the version without aColorTopRight and
-        aColorBottomLeft is used, these colors are linearly interpolated from
-        aColorTopLeft and aColorBottomRight using the width and height of the area
-
-        @param rTopLeft
-        The start point of the frame in pixels
-
-        @param rSize
-        The size of the frame in pixels
-     */
-    void DrawBlendFrame(
-        sal_uInt8 nAlpha = 128,
-        Color aColorTopLeft = Color(COL_WHITE),
-        Color aColorBottomRight = Color(COL_BLACK));
-    void DrawBlendFrame(
-        const Point& rTopLeft,
-        const Size& rSize,
-        sal_uInt8 nAlpha = 128,
-        Color   aColorTopLeft = Color(COL_WHITE),
-        Color   aColorTopRight = Color(COL_GRAY),
-        Color   aColorBottomRight = Color(COL_BLACK),
-        Color   aColorBottomLeft = Color(COL_GRAY));
 
     BitmapReadAccess*       AcquireReadAccess();
     BitmapWriteAccess*      AcquireWriteAccess();
diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx
index 42b7b99..9a0d159 100644
--- a/include/vcl/bitmapex.hxx
+++ b/include/vcl/bitmapex.hxx
@@ -430,6 +430,38 @@ public:
                  const Size &rSize );
 };
 
+// ------------------------------------------------------------------
+/** Create a blend frame as BitmapEx
+
+    @param nAlpha
+    The blend value defines how strong the frame will be blended with the
+    existing content, 255 == full coverage, 0 == no frame will be drawn
+
+    @param aColorTopLeft, aColorBottomRight, aColorTopRight, aColorBottomLeft
+    The colors defining the frame. If the version without aColorTopRight and
+    aColorBottomLeft is used, these colors are linearly interpolated from
+    aColorTopLeft and aColorBottomRight using the width and height of the area
+
+    @param rSize
+    The size of the frame in pixels
+    */
+
+BitmapEx VCL_DLLPUBLIC createBlendFrame(
+    const Size& rSize,
+    sal_uInt8 nAlpha,
+    Color aColorTopLeft,
+    Color aColorBottomRight);
+
+BitmapEx VCL_DLLPUBLIC createBlendFrame(
+    const Size& rSize,
+    sal_uInt8 nAlpha,
+    Color aColorTopLeft,
+    Color aColorTopRight,
+    Color aColorBottomRight,
+    Color aColorBottomLeft);
+
+// ------------------------------------------------------------------
+
 #endif // _SV_BITMAPEX_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index dce1f9a..e5bab36 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -307,16 +307,14 @@ void ColorListBox::UserDraw( const UserDrawEvent& rUDEvt )
 
             if(nEdgeBlendingPercent)
             {
-                Bitmap aBitmap(rUDEvt.GetDevice()->GetBitmap(aRect.TopLeft(), aRect.GetSize()));
+                const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
+                const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
+                const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
+                const BitmapEx aBlendFrame(createBlendFrame(aRect.GetSize(), nAlpha, rTopLeft, rBottomRight));
 
-                if(!aBitmap.IsEmpty())
+                if(!aBlendFrame.IsEmpty())
                 {
-                    const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
-                    const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
-                    const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
-
-                    aBitmap.DrawBlendFrame(nAlpha, rTopLeft, rBottomRight);
-                    rUDEvt.GetDevice()->DrawBitmap(aRect.TopLeft(), aBitmap);
+                    rUDEvt.GetDevice()->DrawBitmapEx(aRect.TopLeft(), aBlendFrame);
                 }
             }
 
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index 9623b29..75a8d53 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -341,16 +341,14 @@ void ValueSet::ImplFormatItem( ValueSetItem* pItem, Rectangle aRect )
 
         if(nEdgeBlendingPercent)
         {
-            Bitmap aBitmap(maVirDev.GetBitmap(aRect.TopLeft(), aRect.GetSize()));
+            const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
+            const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
+            const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
+            const BitmapEx aBlendFrame(createBlendFrame(aRect.GetSize(), nAlpha, rTopLeft, rBottomRight));
 
-            if(!aBitmap.IsEmpty())
+            if(!aBlendFrame.IsEmpty())
             {
-                const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
-                const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
-                const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
-
-                aBitmap.DrawBlendFrame(nAlpha, rTopLeft, rBottomRight);
-                maVirDev.DrawBitmap(aRect.TopLeft(), aBitmap);
+                maVirDev.DrawBitmapEx(aRect.TopLeft(), aBlendFrame);
             }
         }
     }
diff --git a/vcl/source/control/ilstbox.cxx b/vcl/source/control/ilstbox.cxx
index b15bfc3..7684ca8 100644
--- a/vcl/source/control/ilstbox.cxx
+++ b/vcl/source/control/ilstbox.cxx
@@ -1870,19 +1870,16 @@ void ImplListBoxWindow::DrawEntry( sal_uInt16 nPos, sal_Bool bDrawImage, sal_Boo
             const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
             const sal_uInt16 nEdgeBlendingPercent(GetEdgeBlending() ? rStyleSettings.GetEdgeBlending() : 0);
 
-            if(nEdgeBlendingPercent)
+            if(nEdgeBlendingPercent && aImgSz.Width() && aImgSz.Height())
             {
-                const Rectangle aRect(aPtImg, aImgSz);
-                Bitmap aBitmap(GetBitmap(aRect.TopLeft(), aRect.GetSize()));
+                const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
+                const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
+                const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
+                const BitmapEx aBlendFrame(createBlendFrame(aImgSz, nAlpha, rTopLeft, rBottomRight));
 
-                if(!aBitmap.IsEmpty())
+                if(!aBlendFrame.IsEmpty())
                 {
-                    const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
-                    const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
-                    const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
-
-                    aBitmap.DrawBlendFrame(nAlpha, rTopLeft, rBottomRight);
-                    DrawBitmap(aRect.TopLeft(), aBitmap);
+                    DrawBitmapEx(aPtImg, aBlendFrame);
                 }
             }
         }
@@ -2963,17 +2960,14 @@ void ImplWin::DrawEntry( sal_Bool bDrawImage, sal_Bool bDrawText, sal_Bool bDraw
 
         if(nEdgeBlendingPercent)
         {
-            const Rectangle aRect(aPtImg, aImgSz);
-            Bitmap aBitmap(GetBitmap(aRect.TopLeft(), aRect.GetSize()));
+            const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
+            const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
+            const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
+            const BitmapEx aBlendFrame(createBlendFrame(aImgSz, nAlpha, rTopLeft, rBottomRight));
 
-            if(!aBitmap.IsEmpty())
+            if(!aBlendFrame.IsEmpty())
             {
-                const Color& rTopLeft(rStyleSettings.GetEdgeBlendingTopLeftColor());
-                const Color& rBottomRight(rStyleSettings.GetEdgeBlendingBottomRightColor());
-                const sal_uInt8 nAlpha((nEdgeBlendingPercent * 255) / 100);
-
-                aBitmap.DrawBlendFrame(nAlpha, rTopLeft, rBottomRight);
-                DrawBitmap(aRect.TopLeft(), aBitmap);
+                DrawBitmapEx(aPtImg, aBlendFrame);
             }
         }
     }
diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx
index efe8209..5defb3e 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -981,7 +981,6 @@ sal_Bool Bitmap::ImplPopArt( const BmpFilterParam* /*pFilterParam*/, const Link*
     return bRet;
 }
 
-
 double* MakeBlurKernel(const double radius, int& rows) {
     int intRadius = (int) radius + 1.0;
     rows = intRadius * 2 + 1;
@@ -1164,197 +1163,4 @@ bool Bitmap::ImplSeparableUnsharpenFilter(const double radius) {
     return true;
 }
 
-
-void impMixPixel(BitmapWriteAccess& rAcc, long y, long x, const Color& rColor, sal_uInt8 nAlpha)
-{
-    const BitmapColor aBitmapColor(rColor);
-
-    if(nAlpha)
-    {
-        if(255 != nAlpha)
-        {
-            BitmapColor aTarget(rAcc.GetColor(y, x));
-
-            aTarget.Merge(aBitmapColor, nAlpha);
-            rAcc.SetPixel(y, x, aTarget);
-        }
-    }
-    else
-    {
-        rAcc.SetPixel(y, x, aBitmapColor);
-    }
-}
-
-inline bool impVisibleX(long x, const Size& rSizePixel)
-{
-    return x >= 0 && x < rSizePixel.Width();
-}
-
-inline bool impVisibleY(long y, const Size& rSizePixel)
-{
-    return y >= 0 && y < rSizePixel.Width();
-}
-
-inline bool impVisibleXY(long y, long x, const Size& rSizePixel)
-{
-    return impVisibleX(x, rSizePixel) && impVisibleY(y, rSizePixel);
-}
-
-void Bitmap::DrawBlendFrame(
-    const Point& rTopLeft,
-    const Size& rSize,
-    sal_uInt8 nAlpha,
-    Color aColorTopLeft,
-    Color aColorTopRight,
-    Color aColorBottomRight,
-    Color aColorBottomLeft)
-{
-    if(!IsEmpty())
-    {
-        const Size aSizePixel(GetSizePixel());
-
-        if(aSizePixel.Width() && aSizePixel.Height())
-        {
-            const long nW(rSize.Width());
-            const long nH(rSize.Height());
-
-            if(nW || nH)
-            {
-                BitmapWriteAccess* pAcc = AcquireWriteAccess();
-                const long nStartX(rTopLeft.X());
-                const long nStartY(rTopLeft.X());
-                const long nEndX(rTopLeft.X() + nW);
-                const long nEndY(rTopLeft.X() + nH);
-                long x(nStartX);
-                long y(nStartY);
-
-                if(pAcc)
-                {
-                    if(impVisibleXY(y, x, aSizePixel))
-                    {
-                        // x == nStartX, y == nStartY
-                        impMixPixel(*pAcc, y, x, aColorTopLeft, nAlpha);
-                    }
-
-                    if(impVisibleY(y, aSizePixel))
-                    {
-                        for(x = 1; x < nEndX - 1; x++) // y == nStartY
-                        {
-                            if(impVisibleX(x, aSizePixel))
-                            {
-                                Color aMix(aColorTopLeft);
-                                aMix.Merge(aColorTopRight, 255 - sal_uInt8(((x - nStartX) * 255) / nW));
-                                impMixPixel(*pAcc, y, x, aMix, nAlpha);
-                            }
-                        }
-                    }
-                    else
-                    {
-                        x = nEndX - 1;
-                    }
-
-                    if(impVisibleXY(y, x, aSizePixel))
-                    {
-                        // x == nEndX - 1, y == nStartY
-                        impMixPixel(*pAcc, y, x, aColorTopRight, nAlpha);
-                    }
-
-                    const bool bLeftVisible(impVisibleX(nStartX, aSizePixel));
-                    const bool bRightVisible(impVisibleX(x, aSizePixel));
-
-                    if(bLeftVisible || bRightVisible)
-                    {
-                        if(bLeftVisible)
-                        {
-                            for(y = 1; y < nEndY - 1; y++) // x == nStartX and nEndX-1
-                            {
-                                if(impVisibleY(y, aSizePixel))
-                                {
-                                    Color aMix(aColorTopLeft);
-                                    aMix.Merge(aColorBottomLeft, 255 - sal_uInt8(((y - nStartY) * 255) / nH));
-                                    impMixPixel(*pAcc, y, nStartX, aMix, nAlpha);
-                                }
-                            }
-                        }
-
-                        if(bRightVisible)
-                        {
-                            for(y = 1; y < nEndY - 1; y++) // x == nStartX and nEndX-1
-                            {
-                                if(impVisibleY(y, aSizePixel))
-                                {
-                                    Color aMix(aColorTopRight);
-                                    aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((y -nStartY) * 255) / nH));
-                                    impMixPixel(*pAcc, y, x, aMix, nAlpha);
-                                }
-                            }
-                        }
-                    }
-                    else
-                    {
-                        y = nEndY - 1;
-                    }
-
-                    if(impVisibleXY(y, x, aSizePixel))
-                    {
-                        x = nStartX; // x == nStartX, y == nEndY-1
-                        impMixPixel(*pAcc, y, x, aColorBottomLeft, nAlpha);
-                    }
-
-                    if(impVisibleY(y, aSizePixel))
-                    {
-                        for(x = 1; x < nEndX - 1; x++) // y == nEndY-1
-                        {
-                            if(impVisibleX(x, aSizePixel))
-                            {
-                                Color aMix(aColorBottomLeft);
-                                aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((x - nStartX)* 255) / nW));
-                                impMixPixel(*pAcc, y, x, aMix, nAlpha);
-                            }
-                        }
-                    }
-                    else
-                    {
-                        x = nEndX - 1;
-                    }
-
-                    if(impVisibleXY(y, x, aSizePixel))
-                    {
-                        // x == nEndX - 1, y == nEndY - 1
-                        impMixPixel(*pAcc, y, x, aColorBottomRight, nAlpha);
-                    }
-
-                    ReleaseAccess(pAcc);
-                }
-            }
-        }
-    }
-}
-
-void Bitmap::DrawBlendFrame(
-    sal_uInt8 nAlpha,
-    Color aColorTopLeft,
-    Color aColorBottomRight)
-{
-    if(!IsEmpty())
-    {
-        const Point aTopLeft(0, 0);
-        const Size aSize(GetSizePixel());
-        const sal_uInt32 nW(aSize.Width());
-        const sal_uInt32 nH(aSize.Height());
-
-        if(nW || nH)
-        {
-            Color aColTopRight(aColorTopLeft);
-            Color aColBottomLeft(aColorTopLeft);
-            const sal_uInt32 nDE(nW + nH);
-
-            aColTopRight.Merge(aColorBottomRight, 255 - sal_uInt8((nW * 255) / nDE));
-            aColBottomLeft.Merge(aColorBottomRight, 255 - sal_uInt8((nH * 255) / nDE));
-
-            DrawBlendFrame(aTopLeft, aSize, nAlpha, aColorTopLeft, aColTopRight, aColorBottomRight, aColBottomLeft);
-        }
-    }
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index 6e81c06..7a3ca96 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -1218,4 +1218,153 @@ BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorMod
     }
 }
 
+// -----------------------------------------------------------------------------
+
+BitmapEx VCL_DLLPUBLIC createBlendFrame(
+    const Size& rSize,
+    sal_uInt8 nAlpha,
+    Color aColorTopLeft,
+    Color aColorBottomRight)
+{
+    const sal_uInt32 nW(rSize.Width());
+    const sal_uInt32 nH(rSize.Height());
+
+    if(nW || nH)
+    {
+        Color aColTopRight(aColorTopLeft);
+        Color aColBottomLeft(aColorTopLeft);
+        const sal_uInt32 nDE(nW + nH);
+
+        aColTopRight.Merge(aColorBottomRight, 255 - sal_uInt8((nW * 255) / nDE));
+        aColBottomLeft.Merge(aColorBottomRight, 255 - sal_uInt8((nH * 255) / nDE));
+
+        return createBlendFrame(rSize, nAlpha, aColorTopLeft, aColTopRight, aColorBottomRight, aColBottomLeft);
+    }
+
+    return BitmapEx();
+}
+
+BitmapEx VCL_DLLPUBLIC createBlendFrame(
+    const Size& rSize,
+    sal_uInt8 nAlpha,
+    Color aColorTopLeft,
+    Color aColorTopRight,
+    Color aColorBottomRight,
+    Color aColorBottomLeft)
+{
+    static Size aLastSize(0, 0);
+    static sal_uInt8 nLastAlpha(0);
+    static Color aLastColorTopLeft(COL_BLACK);
+    static Color aLastColorTopRight(COL_BLACK);
+    static Color aLastColorBottomRight(COL_BLACK);
+    static Color aLastColorBottomLeft(COL_BLACK);
+    static BitmapEx aLastResult;
+
+    if(aLastSize == rSize
+        && nLastAlpha == nAlpha
+        && aLastColorTopLeft == aLastColorTopLeft
+        && aLastColorTopRight == aLastColorTopRight
+        && aLastColorBottomRight == aLastColorBottomRight
+        && aLastColorBottomLeft == aLastColorBottomLeft)
+    {
+        return aLastResult;
+    }
+
+    aLastSize = rSize;
+    nLastAlpha = nAlpha;
+    aLastColorTopLeft = aLastColorTopLeft;
+    aLastColorTopRight = aLastColorTopRight;
+    aLastColorBottomRight = aLastColorBottomRight;
+    aLastColorBottomLeft = aLastColorBottomLeft;
+    aLastResult.Clear();
+
+    const long nW(rSize.Width());
+    const long nH(rSize.Height());
+
+    if(nW && nH)
+    {
+        sal_uInt8 aEraseTrans(0xff);
+        Bitmap aContent(rSize, 24);
+        AlphaMask aAlpha(rSize, &aEraseTrans);
+
+        aContent.Erase(COL_BLACK);
+
+        BitmapWriteAccess* pContent = aContent.AcquireWriteAccess();
+        BitmapWriteAccess* pAlpha = aAlpha.AcquireWriteAccess();
+
+        if(pContent && pAlpha)
+        {
+            long x(0);
+            long y(0);
+
+            // x == 0, y == 0
+            pContent->SetPixel(y, x, aColorTopLeft);
+            pAlpha->SetPixelIndex(y, x, nAlpha);
+
+            for(x = 1; x < nW - 1; x++) // y == 0
+            {
+                Color aMix(aColorTopLeft);
+
+                aMix.Merge(aColorTopRight, 255 - sal_uInt8((x * 255) / nW));
+                pContent->SetPixel(y, x, aMix);
+                pAlpha->SetPixelIndex(y, x, nAlpha);
+            }
+
+            // x == nW - 1, y == 0
+            pContent->SetPixel(y, x, aColorTopRight);
+            pAlpha->SetPixelIndex(y, x, nAlpha);
+
+            for(y = 1; y < nH - 1; y++) // x == 0 and nW - 1
+            {
+                Color aMixA(aColorTopLeft);
+                Color aMixB(aColorTopRight);
+
+                aMixA.Merge(aColorBottomLeft, 255 - sal_uInt8((y * 255) / nH));
+                pContent->SetPixel(y, 0, aMixA);
+                pAlpha->SetPixelIndex(y, 0, nAlpha);
+
+                aMixB.Merge(aColorBottomRight, 255 - sal_uInt8((y * 255) / nH));
+                pContent->SetPixel(y, nW - 1, aMixB);
+                pAlpha->SetPixelIndex(y, nW - 1, nAlpha);
+            }
+
+            x = 0; // x == 0, y == nH - 1
+            pContent->SetPixel(y, x, aColorBottomLeft);
+            pAlpha->SetPixelIndex(y, x, nAlpha);
+
+            for(x = 1; x < nW - 1; x++) // y == nH - 1
+            {
+                Color aMix(aColorBottomLeft);
+
+                aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((x - 0)* 255) / nW));
+                pContent->SetPixel(y, x, aMix);
+                pAlpha->SetPixelIndex(y, x, nAlpha);
+            }
+
+            // x == nW - 1, y == nH - 1
+            pContent->SetPixel(y, x, aColorBottomRight);
+            pAlpha->SetPixelIndex(y, x, nAlpha);
+
+            aContent.ReleaseAccess(pContent);
+            aAlpha.ReleaseAccess(pAlpha);
+
+            aLastResult = BitmapEx(aContent, aAlpha);
+        }
+        else
+        {
+            if(pContent)
+            {
+                aContent.ReleaseAccess(pContent);
+            }
+
+            if(pAlpha)
+            {
+                aAlpha.ReleaseAccess(pAlpha);
+            }
+        }
+    }
+
+    return aLastResult;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/outdev2.cxx b/vcl/source/gdi/outdev2.cxx
index 7293609..924fe40 100644
--- a/vcl/source/gdi/outdev2.cxx
+++ b/vcl/source/gdi/outdev2.cxx
@@ -1290,6 +1290,7 @@ void OutputDevice::DrawImage( const Point& rPos, const Size& rSize,
 Bitmap OutputDevice::GetBitmap( const Point& rSrcPt, const Size& rSize ) const
 {
     DBG_CHKTHIS( OutputDevice, ImplDbgCheckOutputDevice );
+    OSL_ENSURE(OUTDEV_PRINTER != GetOutDevType(), "OutputDevice::GetBitmap with sorce type OUTDEV_PRINTER should not be used (!)");
 
     Bitmap  aBmp;
     long    nX = ImplLogicXToDevicePixel( rSrcPt.X() );
@@ -1299,7 +1300,7 @@ Bitmap OutputDevice::GetBitmap( const Point& rSrcPt, const Size& rSize ) const
 
     if ( mpGraphics || ( (OutputDevice*) this )->ImplGetGraphics() )
     {
-        if ( nWidth && nHeight )
+        if ( nWidth > 0 && nHeight  > 0 && nX <= (mnOutWidth + mnOutOffX) && nY <= (mnOutHeight + mnOutOffY))
         {
             Rectangle   aRect( Point( nX, nY ), Size( nWidth, nHeight ) );
             bool        bClipped = false;
@@ -1357,7 +1358,13 @@ Bitmap OutputDevice::GetBitmap( const Point& rSrcPt, const Size& rSize ) const
                         aPosAry.mnDestHeight = nHeight;
 
                         if ( (nWidth > 0) && (nHeight > 0) )
+                        {
                             (((OutputDevice*)&aVDev)->mpGraphics)->CopyBits( aPosAry, mpGraphics, this, this );
+                        }
+                        else
+                        {
+                            OSL_ENSURE(false, "CopyBits with negative width or height (!)");
+                        }
 
                         aBmp = aVDev.GetBitmap( Point(), aVDev.GetOutputSizePixel() );
                      }


More information about the Libreoffice-commits mailing list