vcl/qa/cppunit/outdev.cxx | 51 ++++++++++++++++++++++++++------------------- vcl/source/outdev/line.cxx | 20 +++-------------- 2 files changed, 34 insertions(+), 37 deletions(-)
New commits: commit 65901e1d7d94c5497bf93a60d0fb22b8110d31b7 Author: Noel Grandin <[email protected]> AuthorDate: Fri Oct 17 14:32:43 2025 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Sat Oct 18 19:49:41 2025 +0200 Change alpha behavour of OutputDevice::SetLineColor see rationale in commit e0d4d178caff1414a9a21fa57f06bc8d4d2c389a Author: Noel Grandin <[email protected]> Date: Mon Jan 13 15:03:05 2025 +0200 Change alpha behavour of OutputDevice::SetFillColor Change-Id: Iba426cc21b1107cb4f32564fd8111923c84e6a64 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192575 Reviewed-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx index 1f1652174580..0573ac8043e9 100644 --- a/vcl/qa/cppunit/outdev.cxx +++ b/vcl/qa/cppunit/outdev.cxx @@ -502,27 +502,6 @@ CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDefaultLineColor) CPPUNIT_ASSERT_EQUAL(Color(), rColor); } -CPPUNIT_TEST_FIXTURE(VclOutdevTest, testTransparentLineColor) -{ - // Create a virtual device, and connect a metafile to it. - ScopedVclPtrInstance<VirtualDevice> pVDev(DeviceFormat::WITH_ALPHA); - - GDIMetaFile aMtf; - aMtf.Record(pVDev.get()); - - CPPUNIT_ASSERT(pVDev->IsLineColor()); - CPPUNIT_ASSERT_EQUAL(COL_BLACK, pVDev->GetLineColor()); - - pVDev->SetLineColor(COL_TRANSPARENT); - CPPUNIT_ASSERT(!pVDev->IsLineColor()); - CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, pVDev->GetLineColor()); - MetaAction* pAction = aMtf.GetAction(0); - CPPUNIT_ASSERT_EQUAL(MetaActionType::LINECOLOR, pAction->GetType()); - auto pLineAction = static_cast<MetaLineColorAction*>(pAction); - const Color& rColor = pLineAction->GetColor(); - CPPUNIT_ASSERT_EQUAL(COL_TRANSPARENT, rColor); -} - CPPUNIT_TEST_FIXTURE(VclOutdevTest, testLineColor) { // Create a virtual device, and connect a metafile to it. @@ -1847,6 +1826,36 @@ CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawPolyPolygon) } } +CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawRectAlpha1) +{ + Size aSize(100, 100); + ScopedVclPtrInstance<VirtualDevice> pVDev(DeviceFormat::WITH_ALPHA); + pVDev->SetOutputSizePixel(aSize, true, true); + + const Color RED_OPAQUE(ColorAlpha, 255, 255, 0, 0); // opaque red + pVDev->SetLineColor(RED_OPAQUE); + pVDev->SetFillColor(RED_OPAQUE); + pVDev->DrawRect(tools::Rectangle(0, 0, 100, 100)); + + CPPUNIT_ASSERT_EQUAL(RED_OPAQUE, pVDev->GetPixel(Point(0, 0))); + CPPUNIT_ASSERT_EQUAL(RED_OPAQUE, pVDev->GetPixel(Point(1, 1))); +} + +CPPUNIT_TEST_FIXTURE(VclOutdevTest, testDrawRectAlpha2) +{ + Size aSize(100, 100); + ScopedVclPtrInstance<VirtualDevice> pVDev(DeviceFormat::WITH_ALPHA); + pVDev->SetOutputSizePixel(aSize, true, true); + + const Color RED_TRANSPARENT(ColorAlpha, 127, 255, 0, 0); // 50% transparent red + pVDev->SetLineColor(RED_TRANSPARENT); + pVDev->SetFillColor(RED_TRANSPARENT); + pVDev->DrawRect(tools::Rectangle(0, 0, 100, 100)); + + CPPUNIT_ASSERT_EQUAL(RED_TRANSPARENT, pVDev->GetPixel(Point(0, 0))); + CPPUNIT_ASSERT_EQUAL(RED_TRANSPARENT, pVDev->GetPixel(Point(1, 1))); +} + static size_t ClipGradientTest(GDIMetaFile& rMtf, size_t nIndex) { MetaAction* pAction = rMtf.GetAction(nIndex); diff --git a/vcl/source/outdev/line.cxx b/vcl/source/outdev/line.cxx index f4d590fe5311..6c2ba506b907 100644 --- a/vcl/source/outdev/line.cxx +++ b/vcl/source/outdev/line.cxx @@ -54,23 +54,11 @@ void OutputDevice::SetLineColor( const Color& rColor ) if( mpMetaFile ) mpMetaFile->AddAction( new MetaLineColorAction( aColor, true ) ); - if( aColor.IsTransparent() ) + if( maLineColor != aColor ) { - if ( mbLineColor ) - { - mbInitLineColor = true; - mbLineColor = false; - maLineColor = COL_TRANSPARENT; - } - } - else - { - if( maLineColor != aColor ) - { - mbInitLineColor = true; - mbLineColor = true; - maLineColor = aColor; - } + mbInitLineColor = true; + mbLineColor = true; + maLineColor = aColor; } }
