vcl/source/gdi/pdfwriter_impl.cxx | 13 ++++++++++++- vcl/source/gdi/pdfwriter_impl2.cxx | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-)
New commits: commit 7d745697eec8dc5702eb0ebaa8c4b5122c31edab Author: Patrick Luby <plub...@neooffice.org> AuthorDate: Tue Aug 22 18:06:39 2023 -0400 Commit: Patrick Luby <plub...@neooffice.org> CommitDate: Wed Aug 23 13:25:44 2023 +0200 tdf#156853: Fix PDF export of bitmap color fonts Emoji bitmaps need to have their alpha mask inverted like is done with transparent images and shapes. So, invert the alpha mask of Type 3 font bitmaps. Also, add links to test documents for future development and testing. Regression from: commit 81994cb2b8b32453a92bcb011830fcb884f22ff3 Date: Fri Apr 16 20:33:10 2021 +0200 Convert internal vcl bitmap formats transparency->alpha (II) Change-Id: I18223a231ab751945883ede029d660949a406f7d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155960 Tested-by: Jenkins Reviewed-by: خالد حسني <kha...@libreoffice.org> Reviewed-by: Patrick Luby <plub...@neooffice.org> diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 2f74cfa474e2..bf118a33d22f 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -2713,7 +2713,18 @@ bool PDFWriterImpl::emitType3Font(const vcl::font::PhysicalFontFace* pFace, SvMemoryStream aStream(const_cast<uint8_t*>(rBitmapData.data()), rBitmapData.size(), StreamMode::READ); vcl::PngImageReader aReader(aStream); - auto aBitmapEmit = createBitmapEmit(std::move(aReader.read()), Graphic(), + + // When rendering an image with an alpha mask during PDF + // export, the alpha mask needs to be inverted + BitmapEx aBitmapEx = std::move(aReader.read()); + if ( aBitmapEx.IsAlpha()) + { + AlphaMask aAlpha = aBitmapEx.GetAlphaMask(); + aAlpha.Invert(); + aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aAlpha); + } + + auto aBitmapEmit = createBitmapEmit(aBitmapEx, Graphic(), aUsedBitmaps, aResourceDict, aOutputStreams); auto nObject = aBitmapEmit.m_aReferenceXObject.getObject(); diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index 54ff2201ead9..cd46a6a2e9fe 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -499,8 +499,13 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa AlphaMask aAlpha(xVDev->GetBitmap(Point(), xVDev->GetOutputSizePixel())); AlphaMask aPaintAlpha(aPaint.GetAlphaMask()); - // The alpha mask is inverted from what - // is expected so invert it again + // The alpha mask is inverted from what is + // expected so invert it again. To test this + // code, export to PDF the transparent shapes, + // gradients, and images in the documents + // attached to the following bug reports: + // https://bugs.documentfoundation.org/show_bug.cgi?id=155912 + // https://bugs.documentfoundation.org/show_bug.cgi?id=156630 aAlpha.Invert(); // convert to alpha aAlpha.BlendWith(aPaintAlpha); #if HAVE_FEATURE_SKIA @@ -763,8 +768,13 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa { const MetaBmpExAction* pA = static_cast<const MetaBmpExAction*>(pAction); - // When rendering an image with an alpha mask during PDF - // export, the alpha mask needs to be inverted + // The alpha mask is inverted from what is + // expected so invert it again. To test this + // code, export to PDF the transparent shapes, + // gradients, and images in the documents + // attached to the following bug reports: + // https://bugs.documentfoundation.org/show_bug.cgi?id=155912 + // https://bugs.documentfoundation.org/show_bug.cgi?id=156630 BitmapEx aBitmapEx( pA->GetBitmapEx() ); if ( aBitmapEx.IsAlpha()) { @@ -784,8 +794,13 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa { const MetaBmpExScaleAction* pA = static_cast<const MetaBmpExScaleAction*>(pAction); - // When rendering an image with an alpha mask during PDF - // export, the alpha mask needs to be inverted + // The alpha mask is inverted from what is + // expected so invert it again. To test this + // code, export to PDF the transparent shapes, + // gradients, and images in the documents + // attached to the following bug reports: + // https://bugs.documentfoundation.org/show_bug.cgi?id=155912 + // https://bugs.documentfoundation.org/show_bug.cgi?id=156630 BitmapEx aBitmapEx( pA->GetBitmapEx() ); if ( aBitmapEx.IsAlpha()) { @@ -803,8 +818,13 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa { const MetaBmpExScalePartAction* pA = static_cast<const MetaBmpExScalePartAction*>(pAction); - // When rendering an image with an alpha mask during PDF - // export, the alpha mask needs to be inverted + // The alpha mask is inverted from what is + // expected so invert it again. To test this + // code, export to PDF the transparent shapes, + // gradients, and images in the documents + // attached to the following bug reports: + // https://bugs.documentfoundation.org/show_bug.cgi?id=155912 + // https://bugs.documentfoundation.org/show_bug.cgi?id=156630 BitmapEx aBitmapEx( pA->GetBitmapEx() ); if ( aBitmapEx.IsAlpha()) {