emfio/qa/cppunit/emf/EmfImportTest.cxx | 22 ++++++++++ emfio/qa/cppunit/emf/data/TestUnderlineTransparentBackground.emf |binary emfio/source/reader/mtftools.cxx | 7 ++- 3 files changed, 28 insertions(+), 1 deletion(-)
New commits: commit eddbe3b36d257ca2163c9e971fff47e29ccc0ccf Author: Andras Timar <[email protected]> AuthorDate: Sat Feb 7 21:18:19 2026 +0100 Commit: Andras Timar <[email protected]> CommitDate: Sat Feb 7 23:43:38 2026 +0100 tdf#126965 emfio: fix opaque background on underlined text... when BkMode is TRANSPARENT In DrawText, the font's fill color was unconditionally set to maBkColor before checking the background mode. When BkMode is TRANSPARENT, VCL's underline rendering uses the font's fill color directly, ignoring the transparency flag, causing an unwanted opaque background behind underlined text. Set COL_TRANSPARENT as the fill color when BkMode is TRANSPARENT, and only use maBkColor when OPAQUE. Change-Id: I0e94d2a1beae8ce2feecb0f7c0f8e03b36d2d80a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198889 Reviewed-by: Andras Timar <[email protected]> Tested-by: Jenkins diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx index 67751c5451cc..b032ed4b33b1 100644 --- a/emfio/qa/cppunit/emf/EmfImportTest.cxx +++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx @@ -23,7 +23,9 @@ #include <drawinglayer/primitive2d/Primitive2DContainer.hxx> #include <drawinglayer/tools/primitive2dxmldump.hxx> #include <vcl/filter/PDFiumLibrary.hxx> +#include <vcl/gdimtf.hxx> #include <vcl/vectorgraphicdata.hxx> +#include <vcl/wmf.hxx> #include <memory> #include <string_view> @@ -1283,6 +1285,26 @@ CPPUNIT_TEST_FIXTURE(Test, testExtTextOutOpaqueAndClipTransform) u"#000000"); } +CPPUNIT_TEST_FIXTURE(Test, testUnderlineTransparentBackground) +{ + // EMF with SETBKMODE=TRANSPARENT, SETBKCOLOR=black, underlined font, and EXTTEXTOUTW "TEST". + // The font's fill color must be COL_TRANSPARENT when BkMode is TRANSPARENT. + // Before the fix, the fill color was unconditionally set to maBkColor (black), + // causing VCL's underline rendering to draw an opaque background. + OUString aUrl = m_directories.getURLFromSrc( + u"/emfio/qa/cppunit/emf/data/TestUnderlineTransparentBackground.emf"); + SvFileStream aFileStream(aUrl, StreamMode::READ); + GDIMetaFile aGDIMetaFile; + ReadWindowMetafile(aFileStream, aGDIMetaFile); + + xmlDocUniquePtr pDoc = dumpAndParse(aGDIMetaFile); + CPPUNIT_ASSERT(pDoc); + + // The font must have fillcolor="#ffffff" (COL_TRANSPARENT), not "#000000" (maBkColor). + assertXPath(pDoc, "/metafile/push[2]/font", "fillcolor", u"#ffffff"); + assertXPathContent(pDoc, "/metafile/push[2]/textarray/text", u"TEST"); +} + CPPUNIT_TEST_FIXTURE(Test, testNegativeWinOrg) { Primitive2DSequence aSequence = parseEmf(u"/emfio/qa/cppunit/emf/data/TestNegativeWinOrg.emf"); diff --git a/emfio/qa/cppunit/emf/data/TestUnderlineTransparentBackground.emf b/emfio/qa/cppunit/emf/data/TestUnderlineTransparentBackground.emf new file mode 100644 index 000000000000..8268d14f0b0a Binary files /dev/null and b/emfio/qa/cppunit/emf/data/TestUnderlineTransparentBackground.emf differ diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx index a2145510cf6f..5e2783e603be 100644 --- a/emfio/source/reader/mtftools.cxx +++ b/emfio/source/reader/mtftools.cxx @@ -1774,12 +1774,17 @@ namespace emfio } vcl::Font aTmp( maFont ); aTmp.SetColor( maTextColor ); - aTmp.SetFillColor( maBkColor ); if( mnBkMode == BackgroundMode::Transparent ) + { + aTmp.SetFillColor( COL_TRANSPARENT ); aTmp.SetTransparent( true ); + } else + { + aTmp.SetFillColor( maBkColor ); aTmp.SetTransparent( false ); + } aTmp.SetAlignment( eTextAlign );
