vcl/source/filter/idxf/dxf2mtf.cxx |    2 +-
 vcl/source/filter/imet/ios2met.cxx |    9 ++-------
 vcl/source/filter/ipict/ipict.cxx  |    2 +-
 vcl/source/filter/ipict/shape.cxx  |    8 +++++---
 vcl/source/gdi/virdev.cxx          |   17 ++++++++++++++++-
 vcl/source/outdev/fill.cxx         |    7 +++++++
 vcl/unx/gtk3/gtkinst.cxx           |    2 +-
 7 files changed, 33 insertions(+), 14 deletions(-)

New commits:
commit 6da27d87237354fb3b6bff9effd8c0813a7098ea
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Jun 4 11:44:09 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jul 2 10:43:24 2025 +0200

    tdf#166842 do not use FillColor==COL_TRANSPARENT...
    
    .. on OutputDevice if that OutputDevice does not support alpha
    
    Change-Id: I9487effd88106b9e6e7e122a1fd5ab331a9624bb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186189
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/source/filter/idxf/dxf2mtf.cxx 
b/vcl/source/filter/idxf/dxf2mtf.cxx
index 53bdcfd98bc1..f9b0ac8bd66b 100644
--- a/vcl/source/filter/idxf/dxf2mtf.cxx
+++ b/vcl/source/filter/idxf/dxf2mtf.cxx
@@ -159,7 +159,7 @@ bool DXF2GDIMetaFile::SetLineAttribute(const DXFBasicEntity 
& rE)
 
     if (aActFillColor!=COL_TRANSPARENT) {
         aActFillColor = COL_TRANSPARENT;
-        pVirDev->SetFillColor(aActFillColor);
+        pVirDev->SetFillColor();
     }
     return true;
 }
diff --git a/vcl/source/filter/imet/ios2met.cxx 
b/vcl/source/filter/imet/ios2met.cxx
index e0c53089348f..0c1107700852 100644
--- a/vcl/source/filter/imet/ios2met.cxx
+++ b/vcl/source/filter/imet/ios2met.cxx
@@ -731,15 +731,10 @@ void OS2METReader::PopAttr()
 
 void OS2METReader::ChangeBrush(const Color& rPatColor, bool bFill )
 {
-    Color aColor;
-
     if( bFill )
-        aColor = rPatColor;
+        pVirDev->SetFillColor( rPatColor );
     else
-        aColor = COL_TRANSPARENT;
-
-    if( pVirDev->GetFillColor() != aColor )
-        pVirDev->SetFillColor( aColor );
+        pVirDev->SetFillColor();
 }
 
 void OS2METReader::SetPen( const Color& rColor, sal_uInt16 nLineWidth, 
PenStyle ePenStyle )
diff --git a/vcl/source/filter/ipict/ipict.cxx 
b/vcl/source/filter/ipict/ipict.cxx
index 2d9be6f8cd9c..de29adbc7f5f 100644
--- a/vcl/source/filter/ipict/ipict.cxx
+++ b/vcl/source/filter/ipict/ipict.cxx
@@ -643,7 +643,7 @@ void PictReader::DrawingMethod(PictDrawingMethod eMethod)
               SetLineColor( aActForeColor );
             else
               SetLineColor(eActPenPattern.getColor(aActBackColor, 
aActForeColor));
-            SetFillColor( COL_TRANSPARENT );
+            pVirDev->SetFillColor();
             pVirDev->SetRasterOp(eActROP);
             break;
         case PictDrawingMethod::PAINT:
diff --git a/vcl/source/filter/ipict/shape.cxx 
b/vcl/source/filter/ipict/shape.cxx
index 88a62cfd2ff2..c1e30c541c23 100644
--- a/vcl/source/filter/ipict/shape.cxx
+++ b/vcl/source/filter/ipict/shape.cxx
@@ -98,10 +98,12 @@ namespace PictReaderShape {
     // HACK: here we use the line coloring when drawing the shape
     //       must be changed if other parameter are changed to draw
     //       a line/fill shape
-    Color oldFColor = dev->GetFillColor(), oldLColor = dev->GetLineColor();
-    dev->SetFillColor(oldLColor); dev->SetLineColor(COL_TRANSPARENT);
+    dev->Push(vcl::PushFlags::LINECOLOR | vcl::PushFlags::FILLCOLOR);
+    Color oldLColor = dev->GetLineColor();
+    dev->SetFillColor(oldLColor);
+    dev->SetLineColor();
     dev->DrawPolygon(poly);
-    dev->SetLineColor(oldLColor); dev->SetFillColor(oldFColor);
+    dev->Pop();
     return true;
   }
 
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index 497e9be6fe39..40977754b31b 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -203,6 +203,21 @@ void VirtualDevice::ImplInitVirDev( const OutputDevice* 
pOutDev,
     if ( mpNext )
         mpNext->mpPrev = this;
     pSVData->maGDIData.mpFirstVirDev = this;
+
+    // initialise alpha layer
+    if (meFormatAndAlpha != DeviceFormat::WITHOUT_ALPHA)
+    {
+        mpAlphaVDev = VclPtr<VirtualDevice>::Create(*this, 
DeviceFormat::WITHOUT_ALPHA);
+        mpAlphaVDev->InnerImplSetOutputSizePixel(Size(nDX, nDY), bErase);
+        mpAlphaVDev->SetBackground( Wallpaper(COL_ALPHA_OPAQUE) );
+        mpAlphaVDev->Erase();
+        if( GetLineColor() != COL_TRANSPARENT )
+            mpAlphaVDev->SetLineColor( COL_ALPHA_OPAQUE );
+        if( GetFillColor() != COL_TRANSPARENT )
+            mpAlphaVDev->SetFillColor( COL_ALPHA_OPAQUE );
+        mpAlphaVDev->SetMapMode( GetMapMode() );
+        mpAlphaVDev->SetAntialiasing( GetAntialiasing() );
+    }
 }
 
 VirtualDevice::VirtualDevice(const OutputDevice* pCompDev, DeviceFormat 
eFormatAndAlpha,
@@ -365,7 +380,7 @@ bool VirtualDevice::SetOutputSizePixel( const Size& 
rNewSize, bool bErase, bool
 
             if( !mpAlphaVDev )
             {
-                mpAlphaVDev = VclPtr<VirtualDevice>::Create(*this, 
meFormatAndAlpha);
+                mpAlphaVDev = VclPtr<VirtualDevice>::Create(*this, 
DeviceFormat::WITHOUT_ALPHA);
                 mpAlphaVDev->InnerImplSetOutputSizePixel(rNewSize, bErase);
                 mpAlphaVDev->SetBackground( Wallpaper(bAlphaMaskTransparent ? 
COL_ALPHA_TRANSPARENT : COL_ALPHA_OPAQUE) );
                 mpAlphaVDev->Erase();
diff --git a/vcl/source/outdev/fill.cxx b/vcl/source/outdev/fill.cxx
index 067762d17838..16bb327a0cef 100644
--- a/vcl/source/outdev/fill.cxx
+++ b/vcl/source/outdev/fill.cxx
@@ -47,6 +47,13 @@ void OutputDevice::SetFillColor( const Color& rColor )
 {
     Color aColor(vcl::drawmode::GetFillColor(rColor, GetDrawMode(), 
GetSettings().GetStyleSettings()));
 
+    // If this assert fires, and this is a VirtualDevice, you likely need to 
either
+    // (a) create this VirtualDevice with the WITH_ALPHA flag
+    // or
+    // (b) call SetFillColor() to set no fill
+    assert((mpAlphaVDev || !aColor.IsTransparent())
+        && "transparent color on a device that has no alpha layer will turn 
out wrong");
+
     if ( mpMetaFile )
         mpMetaFile->AddAction( new MetaFillColorAction( aColor, true ) );
 
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 546f91b03c6a..a5775cb31a12 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -4405,7 +4405,7 @@ public:
     {
         // create with no separate alpha layer like everything sane does
         auto xRet = VclPtr<VirtualDevice>::Create();
-        xRet->SetBackground(COL_TRANSPARENT);
+        xRet->SetBackground();
         return xRet;
     }
 

Reply via email to