diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-10 12:26:37 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-10 22:20:00 +0200 |
commit | 37217909f2e7c042eab9a8b5eb1ab0a88cdda513 (patch) | |
tree | 40b360914dd3a1cd353b9cfa822eb6669eab403e /svx | |
parent | b2cb093d8bd8fbfa4204cb10daec52ec6c283e04 (diff) |
tdf#161979: Render GDI metafile using drawinglayer in XOutBitmap
After the changes related to EMF+ reworking, much of the code was removed
from VCL, e.g. commit 217ad59a412ebab07a106b14c8976d20bddb9356 (tdf#111486
Removed not used EMF+ code, 2018-12-07). EMF+ code is now in drawinglayer
(see EmfPlusHelperData::processEmfPlusData). Unfortunately, we can't make
ImpGraphic::draw in VCL to use drawinglayer for rendering, because VCL is
lower in dependency tree (it only can use drawinglayercore).
Change-Id: I08f8c8ec66baf3dde1f35481144d5e1819bb5fc1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170311
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/inc/UnoGraphicExporter.hxx (renamed from svx/source/unodraw/UnoGraphicExporter.hxx) | 9 | ||||
-rw-r--r-- | svx/source/unodraw/UnoGraphicExporter.cxx | 69 | ||||
-rw-r--r-- | svx/source/unodraw/tableshape.cxx | 2 | ||||
-rw-r--r-- | svx/source/xoutdev/_xoutbmp.cxx | 85 |
4 files changed, 86 insertions, 79 deletions
diff --git a/svx/source/unodraw/UnoGraphicExporter.hxx b/svx/source/inc/UnoGraphicExporter.hxx index ace0db252919..65014c4d7290 100644 --- a/svx/source/unodraw/UnoGraphicExporter.hxx +++ b/svx/source/inc/UnoGraphicExporter.hxx @@ -17,17 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVX_SOURCE_UNODRAW_UNOGRAPHICEXPORTER_HXX -#define INCLUDED_SVX_SOURCE_UNODRAW_UNOGRAPHICEXPORTER_HXX +#pragma once #include <sal/config.h> +#include <vcl/bitmapex.hxx> #include <vcl/graph.hxx> +class Size; +class GDIMetaFile; class SdrObject; +BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize); Graphic SvxGetGraphicForShape(SdrObject& rShape); -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx index 451b95b0e58b..72ae293ee4e2 100644 --- a/svx/source/unodraw/UnoGraphicExporter.cxx +++ b/svx/source/unodraw/UnoGraphicExporter.cxx @@ -66,7 +66,7 @@ #include <comphelper/sequenceashashmap.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/sequence.hxx> -#include "UnoGraphicExporter.hxx" +#include <UnoGraphicExporter.hxx> #include <memory> // #i102251# #include <editeng/editstat.hxx> @@ -171,37 +171,6 @@ namespace { SdrModel* mpDoc; }; - /** creates a bitmap that is optionally transparent from a metafile - */ - BitmapEx GetBitmapFromMetaFile( const GDIMetaFile& rMtf, const Size* pSize ) - { - // use new primitive conversion tooling - basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0)); - sal_uInt32 nMaximumQuadraticPixels(500000); - - if(pSize) - { - // use 100th mm for primitive bitmap converter tool, input is pixel - // use a real OutDev to get the correct DPI, the static LogicToLogic assumes 72dpi which is wrong (!) - const Size aSize100th(Application::GetDefaultDevice()->PixelToLogic(*pSize, MapMode(MapUnit::Map100thMM))); - - aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height())); - - // when explicitly pixels are requested from the GraphicExporter, use a *very* high limit - // of 16gb (4096x4096 pixels), else use the default for the converters - nMaximumQuadraticPixels = std::min(sal_uInt32(4096 * 4096), sal_uInt32(pSize->Width() * pSize->Height())); - } - else - { - // use 100th mm for primitive bitmap converter tool - const Size aSize100th(OutputDevice::LogicToLogic(rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MapMode(MapUnit::Map100thMM))); - - aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height())); - } - - return convertMetafileToBitmapEx(rMtf, aRange, nMaximumQuadraticPixels); - } - Size* CalcSize( sal_Int32 nWidth, sal_Int32 nHeight, const Size& aBoundSize, Size& aOutSize ) { if( (nWidth == 0) && (nHeight == 0) ) @@ -1289,6 +1258,42 @@ Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames( ) } +/** creates a bitmap that is optionally transparent from a metafile + */ +BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize) +{ + // use new primitive conversion tooling + basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0)); + sal_uInt32 nMaximumQuadraticPixels; + + if (pSize) + { + // use 100th mm for primitive bitmap converter tool, input is pixel + // use a real OutDev to get the correct DPI, the static LogicToLogic assumes 72dpi which is wrong (!) + const Size aSize100th( + Application::GetDefaultDevice()->PixelToLogic(*pSize, MapMode(MapUnit::Map100thMM))); + + aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height())); + + // when explicitly pixels are requested from the GraphicExporter, use a *very* high limit + // of 16gb (4096x4096 pixels) + nMaximumQuadraticPixels = 4096 * 4096; + } + else + { + // use 100th mm for primitive bitmap converter tool + const Size aSize100th(OutputDevice::LogicToLogic(rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), + MapMode(MapUnit::Map100thMM))); + + aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height())); + + // limit to 2048x2048 pixels, as in ImpGraphic::getBitmap (vcl/source/gdi/impgraph.cxx): + nMaximumQuadraticPixels = 2048 * 2048; + } + + return convertMetafileToBitmapEx(rMtf, aRange, nMaximumQuadraticPixels); +} + Graphic SvxGetGraphicForShape( SdrObject& rShape ) { Graphic aGraphic; diff --git a/svx/source/unodraw/tableshape.cxx b/svx/source/unodraw/tableshape.cxx index c0df40ddc9f2..ebefa12fec3f 100644 --- a/svx/source/unodraw/tableshape.cxx +++ b/svx/source/unodraw/tableshape.cxx @@ -19,7 +19,7 @@ #include <sal/config.h> -#include "UnoGraphicExporter.hxx" +#include <UnoGraphicExporter.hxx> #include "shapeimpl.hxx" #include <svx/unodraw/SvxTableShape.hxx> #include <svx/unoshprp.hxx> diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index db4ef7152089..f722dc394530 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -25,9 +25,15 @@ #include <tools/debug.hxx> #include <vcl/virdev.hxx> #include <sfx2/docfile.hxx> +#include <svx/svdpntv.hxx> #include <svx/xoutbmp.hxx> #include <vcl/graphicfilter.hxx> #include <vcl/cvtgrf.hxx> +#include <vcl/gdimtf.hxx> +#include <vcl/svapp.hxx> + +#include <UnoGraphicExporter.hxx> + #include <memory> #include <com/sun/star/beans/XPropertySet.hpp> @@ -271,63 +277,58 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, Graphic aGraphic; OUString aExt = rFilter.GetExportFormatShortName( nFilter ).toAsciiLowerCase(); - if( bWriteTransGrf ) + if (bAnimated) + aGraphic = rGraphic; + else if (rGraphic.GetType() == GraphicType::GdiMetafile + && rGraphic.GetGDIMetaFile().GetActionSize()) { - if( bAnimated ) - aGraphic = rGraphic; - else + Size aSize; + const Size* pSize = nullptr; + if (pMtfSize_100TH_MM) { - if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GraphicType::Bitmap ) ) - { - ScopedVclPtrInstance< VirtualDevice > pVDev; - const Size aSize(pVDev->LogicToPixel(*pMtfSize_100TH_MM, MapMode(MapUnit::Map100thMM))); - - if( pVDev->SetOutputSizePixel( aSize ) ) - { - const Wallpaper aWallpaper( pVDev->GetBackground() ); - const Point aPt; - - pVDev->SetBackground( Wallpaper( COL_BLACK ) ); - pVDev->Erase(); - rGraphic.Draw(*pVDev, aPt, aSize); - - const Bitmap aBitmap( pVDev->GetBitmap( aPt, aSize ) ); - - pVDev->SetBackground( aWallpaper ); - pVDev->Erase(); - rGraphic.Draw(*pVDev, aPt, aSize); - - pVDev->SetRasterOp( RasterOp::Xor ); - pVDev->DrawBitmap( aPt, aSize, aBitmap ); - aGraphic = BitmapEx( aBitmap, pVDev->GetBitmap( aPt, aSize ) ); - } - else - aGraphic = rGraphic.GetBitmapEx(); - } - else - aGraphic = rGraphic.GetBitmapEx(); + aSize = Application::GetDefaultDevice()->LogicToPixel(*pMtfSize_100TH_MM, + MapMode(MapUnit::Map100thMM)); + pSize = &aSize; } + aGraphic = GetBitmapFromMetaFile(rGraphic.GetGDIMetaFile(), pSize); } - else + else if (pMtfSize_100TH_MM && (rGraphic.GetType() != GraphicType::Bitmap)) { - if (bAnimated) - aGraphic = rGraphic; - else if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GraphicType::Bitmap ) ) + ScopedVclPtrInstance< VirtualDevice > pVDev; + const Size aSize(pVDev->LogicToPixel(*pMtfSize_100TH_MM, MapMode(MapUnit::Map100thMM))); + + if( pVDev->SetOutputSizePixel( aSize ) ) { - ScopedVclPtrInstance< VirtualDevice > pVDev; - const Size aSize(pVDev->LogicToPixel(*pMtfSize_100TH_MM, MapMode(MapUnit::Map100thMM))); + if (bWriteTransGrf) + { + const Wallpaper aWallpaper( pVDev->GetBackground() ); + const Point aPt; + + pVDev->SetBackground( Wallpaper( COL_BLACK ) ); + pVDev->Erase(); + rGraphic.Draw(*pVDev, aPt, aSize); + + const Bitmap aBitmap( pVDev->GetBitmap( aPt, aSize ) ); + + pVDev->SetBackground( aWallpaper ); + pVDev->Erase(); + rGraphic.Draw(*pVDev, aPt, aSize); - if( pVDev->SetOutputSizePixel( aSize ) ) + pVDev->SetRasterOp( RasterOp::Xor ); + pVDev->DrawBitmap( aPt, aSize, aBitmap ); + aGraphic = BitmapEx( aBitmap, pVDev->GetBitmap( aPt, aSize ) ); + } + else { rGraphic.Draw(*pVDev, Point(), aSize); aGraphic = BitmapEx(pVDev->GetBitmap(Point(), aSize)); } - else - aGraphic = rGraphic.GetBitmapEx(); } else aGraphic = rGraphic.GetBitmapEx(); } + else + aGraphic = rGraphic.GetBitmapEx(); // mirror? if( ( nFlags & XOutFlags::MirrorHorz ) || ( nFlags & XOutFlags::MirrorVert ) ) |