tdf#156853: Fix PDF export of bitmap color fonts
Move the alpha inversion down to createBitmapEmit() so that it gets
applied to any bitmap embedded in the PDF, especially since embedded
color bitmap glyphs don't go through the higher level code path.
Regression from:
commit 81994cb2b8b32453a92bcb011830fcb884f22ff3
Date: Fri Apr 16 20:33:10 2021 +0200
Convert internal vcl bitmap formats transparency->alpha (II)
Change-Id: I68601a7a0d9ac01f5e8054f074f8e18fcbdea1be
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155930
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@libreoffice.org>
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 429efe3..4cda5a0 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9799,6 +9799,16 @@ void PDFWriterImpl::drawBitmap( const Point& rDestPoint, const Size& rDestSize,
const BitmapEmit& PDFWriterImpl::createBitmapEmit(const BitmapEx& i_rBitmap, const Graphic& rGraphic, std::list<BitmapEmit>& rBitmaps, ResourceDict& rResourceDict, std::list<StreamRedirect>& rOutputStreams)
{
BitmapEx aBitmap( i_rBitmap );
// When rendering an image with an alpha mask during PDF export, the alpha
// mask needs to be inverted
if (aBitmap.IsAlpha())
{
AlphaMask aAlpha = aBitmap.GetAlphaMask();
aAlpha.Invert();
aBitmap = BitmapEx(aBitmap.GetBitmap(), aAlpha);
}
auto ePixelFormat = aBitmap.GetBitmap().getPixelFormat();
if( m_aContext.ColorMode == PDFWriter::DrawGreyscale )
aBitmap.Convert(BmpConversion::N8BitGreys);
diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx
index 54ff220..a9b2a12 100644
--- a/vcl/source/gdi/pdfwriter_impl2.cxx
+++ b/vcl/source/gdi/pdfwriter_impl2.cxx
@@ -763,15 +763,7 @@ 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
BitmapEx aBitmapEx( pA->GetBitmapEx() );
if ( aBitmapEx.IsAlpha())
{
AlphaMask aAlpha = aBitmapEx.GetAlphaMask();
aAlpha.Invert();
aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aAlpha);
}
const BitmapEx& aBitmapEx( pA->GetBitmapEx() );
Size aSize( OutputDevice::LogicToLogic( aBitmapEx.GetPrefSize(),
aBitmapEx.GetPrefMapMode(), pDummyVDev->GetMapMode() ) );
@@ -784,18 +776,8 @@ 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
BitmapEx aBitmapEx( pA->GetBitmapEx() );
if ( aBitmapEx.IsAlpha())
{
AlphaMask aAlpha = aBitmapEx.GetAlphaMask();
aAlpha.Invert();
aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aAlpha);
}
Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic();
implWriteBitmapEx( pA->GetPoint(), pA->GetSize(), aBitmapEx, aGraphic, pDummyVDev, i_rContext );
implWriteBitmapEx( pA->GetPoint(), pA->GetSize(), pA->GetBitmapEx(), aGraphic, pDummyVDev, i_rContext );
}
break;
@@ -803,15 +785,7 @@ 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
BitmapEx aBitmapEx( pA->GetBitmapEx() );
if ( aBitmapEx.IsAlpha())
{
AlphaMask aAlpha = aBitmapEx.GetAlphaMask();
aAlpha.Invert();
aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aAlpha);
}
aBitmapEx.Crop( tools::Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) );
Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic();