diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-10-25 11:10:42 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-10-25 14:55:57 +0200 |
commit | f6c9d1012d20541f6373b51ff3c25d8fd7bc8c69 (patch) | |
tree | 5fc85e3de54d7afb81205533acae385474b3cb81 | |
parent | 7a802001b06939476a8d8a3f4dc7e5c234d376a4 (diff) |
flatten ImpGetScaledGraphic a little
Change-Id: Iaefbfcb8d2f062c3b2f6a7d0c336ec46323de371
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175635
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 138 |
1 files changed, 67 insertions, 71 deletions
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 0f09428e6c0c..ecd506a42548 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -186,94 +186,90 @@ ErrCode GraphicFilter::ImpTestOrFindFormat( std::u16string_view rPath, SvStream& static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& rConfigItem ) { - Graphic aGraphic; + if ( rGraphic.GetType() == GraphicType::NONE ) + return rGraphic; sal_Int32 nLogicalWidth = rConfigItem.ReadInt32( u"LogicalWidth"_ustr, 0 ); sal_Int32 nLogicalHeight = rConfigItem.ReadInt32( u"LogicalHeight"_ustr, 0 ); + sal_Int32 nMode = rConfigItem.ReadInt32( u"ExportMode"_ustr, -1 ); + if ( nMode == -1 ) // the property is not there, this is possible, if the graphic filter + { // is called via UnoGraphicExporter and not from a graphic export Dialog + nMode = 0; // then we are defaulting this mode to 0 + if ( nLogicalWidth || nLogicalHeight ) + nMode = 2; + } - if ( rGraphic.GetType() != GraphicType::NONE ) - { - sal_Int32 nMode = rConfigItem.ReadInt32( u"ExportMode"_ustr, -1 ); + Graphic aGraphic; + Size aPrefSize( rGraphic.GetPrefSize() ); + Size aOriginalSize; + MapMode aPrefMapMode( rGraphic.GetPrefMapMode() ); + if (aPrefMapMode.GetMapUnit() == MapUnit::MapPixel) + aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM)); + else + aOriginalSize = OutputDevice::LogicToLogic(aPrefSize, aPrefMapMode, MapMode(MapUnit::Map100thMM)); + if ( !nLogicalWidth ) + nLogicalWidth = aOriginalSize.Width(); + if ( !nLogicalHeight ) + nLogicalHeight = aOriginalSize.Height(); - if ( nMode == -1 ) // the property is not there, this is possible, if the graphic filter - { // is called via UnoGraphicExporter and not from a graphic export Dialog - nMode = 0; // then we are defaulting this mode to 0 - if ( nLogicalWidth || nLogicalHeight ) - nMode = 2; - } + if( rGraphic.GetType() == GraphicType::Bitmap ) + { - Size aOriginalSize; - Size aPrefSize( rGraphic.GetPrefSize() ); - MapMode aPrefMapMode( rGraphic.GetPrefMapMode() ); - if (aPrefMapMode.GetMapUnit() == MapUnit::MapPixel) - aOriginalSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MapMode(MapUnit::Map100thMM)); - else - aOriginalSize = OutputDevice::LogicToLogic(aPrefSize, aPrefMapMode, MapMode(MapUnit::Map100thMM)); - if ( !nLogicalWidth ) - nLogicalWidth = aOriginalSize.Width(); - if ( !nLogicalHeight ) - nLogicalHeight = aOriginalSize.Height(); - if( rGraphic.GetType() == GraphicType::Bitmap ) + // Resolution is set + if( nMode == 1 ) { + BitmapEx aBitmap( rGraphic.GetBitmapEx() ); + MapMode aMap( MapUnit::Map100thInch ); - // Resolution is set - if( nMode == 1 ) - { - BitmapEx aBitmap( rGraphic.GetBitmapEx() ); - MapMode aMap( MapUnit::Map100thInch ); - - sal_Int32 nDPI = rConfigItem.ReadInt32( u"Resolution"_ustr, 75 ); - Fraction aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) ); - - aMap.SetScaleX( aFrac ); - aMap.SetScaleY( aFrac ); + sal_Int32 nDPI = rConfigItem.ReadInt32( u"Resolution"_ustr, 75 ); + Fraction aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) ); - Size aOldSize = aBitmap.GetSizePixel(); - aGraphic = rGraphic; - aGraphic.SetPrefMapMode( aMap ); - aGraphic.SetPrefSize( Size( aOldSize.Width() * 100, - aOldSize.Height() * 100 ) ); - } - // Size is set - else if( nMode == 2 ) - { - aGraphic = rGraphic; - aGraphic.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) ); - aGraphic.SetPrefSize( Size( nLogicalWidth, nLogicalHeight ) ); - } - else - aGraphic = rGraphic; + aMap.SetScaleX( aFrac ); + aMap.SetScaleY( aFrac ); - sal_Int32 nColors = rConfigItem.ReadInt32( u"Color"_ustr, 0 ); - if ( nColors ) // graphic conversion necessary ? - { - BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); - aBmpEx.Convert( static_cast<BmpConversion>(nColors) ); // the entries in the xml section have the same meaning as - aGraphic = aBmpEx; // they have in the BmpConversion enum, so it should be - } // allowed to cast them + Size aOldSize = aBitmap.GetSizePixel(); + aGraphic = rGraphic; + aGraphic.SetPrefMapMode( aMap ); + aGraphic.SetPrefSize( Size( aOldSize.Width() * 100, + aOldSize.Height() * 100 ) ); + } + // Size is set + else if( nMode == 2 ) + { + aGraphic = rGraphic; + aGraphic.SetPrefMapMode( MapMode( MapUnit::Map100thMM ) ); + aGraphic.SetPrefSize( Size( nLogicalWidth, nLogicalHeight ) ); } else + aGraphic = rGraphic; + + sal_Int32 nColors = rConfigItem.ReadInt32( u"Color"_ustr, 0 ); + if ( nColors ) // graphic conversion necessary ? { - if( ( nMode == 1 ) || ( nMode == 2 ) ) - { - GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() ); - Size aNewSize( OutputDevice::LogicToLogic(Size(nLogicalWidth, nLogicalHeight), MapMode(MapUnit::Map100thMM), aMtf.GetPrefMapMode()) ); + BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); + aBmpEx.Convert( static_cast<BmpConversion>(nColors) ); // the entries in the xml section have the same meaning as + aGraphic = aBmpEx; // they have in the BmpConversion enum, so it should be + } // allowed to cast them + } + else + { + if( ( nMode == 1 ) || ( nMode == 2 ) ) + { + GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() ); + Size aNewSize( OutputDevice::LogicToLogic(Size(nLogicalWidth, nLogicalHeight), MapMode(MapUnit::Map100thMM), aMtf.GetPrefMapMode()) ); - if( aNewSize.Width() && aNewSize.Height() ) - { - const Size aPreferredSize( aMtf.GetPrefSize() ); - aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ), - Fraction( aNewSize.Height(), aPreferredSize.Height() ) ); - } - aGraphic = Graphic( aMtf ); + if( aNewSize.Width() && aNewSize.Height() ) + { + const Size aPreferredSize( aMtf.GetPrefSize() ); + aMtf.Scale( Fraction( aNewSize.Width(), aPreferredSize.Width() ), + Fraction( aNewSize.Height(), aPreferredSize.Height() ) ); } - else - aGraphic = rGraphic; + aGraphic = Graphic( aMtf ); } - + else + aGraphic = rGraphic; } - else - aGraphic = rGraphic; + return aGraphic; } |