[Libreoffice-commits] core.git: svx/source

Noel (via logerrit) logerrit at kemper.freedesktop.org
Sat Feb 27 18:34:34 UTC 2021


 svx/source/xoutdev/_xoutbmp.cxx |  330 +++++++++++++++++++---------------------
 1 file changed, 159 insertions(+), 171 deletions(-)

New commits:
commit d87e95289363e95eec2c6603f248253e6c7598df
Author:     Noel <noel.grandin at collabora.co.uk>
AuthorDate: Sat Feb 27 15:33:26 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Feb 27 19:33:55 2021 +0100

    flatten XOutBitmap::WriteGraphic a little
    
    Change-Id: I91f456673ff54649f6e3f837d9ec8fb6d5dd2b2f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111678
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx
index 9f53d9c22d41..60e11abdba56 100644
--- a/svx/source/xoutdev/_xoutbmp.cxx
+++ b/svx/source/xoutdev/_xoutbmp.cxx
@@ -105,219 +105,207 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName,
                                  const Size* pMtfSize_100TH_MM,
                                  const css::uno::Sequence< css::beans::PropertyValue >* pFilterData )
 {
-    if( rGraphic.GetType() != GraphicType::NONE )
-    {
-        INetURLObject   aURL( rFileName );
-        Graphic         aGraphic;
-        OUString        aExt;
-        GraphicFilter&  rFilter = GraphicFilter::GetGraphicFilter();
-        ErrCode         nErr = ERRCODE_GRFILTER_FILTERERROR;
-        bool            bTransparent = rGraphic.IsTransparent(), bAnimated = rGraphic.IsAnimated();
+    if( rGraphic.GetType() == GraphicType::NONE )
+        return ERRCODE_NONE;
 
-        DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "XOutBitmap::WriteGraphic(...): invalid URL" );
+    INetURLObject   aURL( rFileName );
+    Graphic         aGraphic;
+    OUString        aExt;
+    GraphicFilter&  rFilter = GraphicFilter::GetGraphicFilter();
+    ErrCode         nErr = ERRCODE_GRFILTER_FILTERERROR;
+    bool            bTransparent = rGraphic.IsTransparent(), bAnimated = rGraphic.IsAnimated();
 
-        // calculate correct file name
-        if( !( nFlags & XOutFlags::DontExpandFilename ) )
-        {
-            OUString aStr( OUString::number( rGraphic.GetChecksum(), 16 ) );
-            if ( aStr[0] == '-' )
-                aStr = OUString::Concat("m") + aStr.subView(1);
-            OUString aName = aURL.getBase() + "_" + aURL.getExtension() + "_" + aStr;
-            aURL.setBase( aName );
-        }
+    DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "XOutBitmap::WriteGraphic(...): invalid URL" );
+
+    // calculate correct file name
+    if( !( nFlags & XOutFlags::DontExpandFilename ) )
+    {
+        OUString aStr( OUString::number( rGraphic.GetChecksum(), 16 ) );
+        if ( aStr[0] == '-' )
+            aStr = OUString::Concat("m") + aStr.subView(1);
+        OUString aName = aURL.getBase() + "_" + aURL.getExtension() + "_" + aStr;
+        aURL.setBase( aName );
+    }
 
-        // #i121128# use shortcut to write Vector Graphic Data data in original form (if possible)
-        auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
+    // #i121128# use shortcut to write Vector Graphic Data data in original form (if possible)
+    auto const & rVectorGraphicDataPtr(rGraphic.getVectorGraphicData());
 
-        if (rVectorGraphicDataPtr && rVectorGraphicDataPtr->getBinaryDataContainer().getSize())
-        {
-            const bool bIsSvg(rFilterName.equalsIgnoreAsciiCase("svg") && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getType());
-            const bool bIsWmf(rFilterName.equalsIgnoreAsciiCase("wmf") && VectorGraphicDataType::Wmf == rVectorGraphicDataPtr->getType());
-            const bool bIsEmf(rFilterName.equalsIgnoreAsciiCase("emf") && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getType());
-            const bool bIsPdf(rFilterName.equalsIgnoreAsciiCase("pdf") && VectorGraphicDataType::Pdf == rVectorGraphicDataPtr->getType());
+    if (rVectorGraphicDataPtr && rVectorGraphicDataPtr->getBinaryDataContainer().getSize())
+    {
+        const bool bIsSvg(rFilterName.equalsIgnoreAsciiCase("svg") && VectorGraphicDataType::Svg == rVectorGraphicDataPtr->getType());
+        const bool bIsWmf(rFilterName.equalsIgnoreAsciiCase("wmf") && VectorGraphicDataType::Wmf == rVectorGraphicDataPtr->getType());
+        const bool bIsEmf(rFilterName.equalsIgnoreAsciiCase("emf") && VectorGraphicDataType::Emf == rVectorGraphicDataPtr->getType());
+        const bool bIsPdf(rFilterName.equalsIgnoreAsciiCase("pdf") && VectorGraphicDataType::Pdf == rVectorGraphicDataPtr->getType());
 
-            if (bIsSvg || bIsWmf || bIsEmf || bIsPdf)
+        if (bIsSvg || bIsWmf || bIsEmf || bIsPdf)
+        {
+            if (!(nFlags & XOutFlags::DontAddExtension))
             {
-                if (!(nFlags & XOutFlags::DontAddExtension))
-                {
-                    aURL.setExtension(rFilterName);
-                }
+                aURL.setExtension(rFilterName);
+            }
 
-                rFileName = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
-                SfxMedium aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE | StreamMode::SHARE_DENYNONE | StreamMode::TRUNC);
-                SvStream* pOStm = aMedium.GetOutStream();
+            rFileName = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE);
+            SfxMedium aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE | StreamMode::SHARE_DENYNONE | StreamMode::TRUNC);
+            SvStream* pOStm = aMedium.GetOutStream();
 
-                if (pOStm)
-                {
-                    auto & rDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
-                    pOStm->WriteBytes(rDataContainer.getData(), rDataContainer.getSize());
-                    aMedium.Commit();
+            if (pOStm)
+            {
+                auto & rDataContainer = rVectorGraphicDataPtr->getBinaryDataContainer();
+                pOStm->WriteBytes(rDataContainer.getData(), rDataContainer.getSize());
+                aMedium.Commit();
 
-                    if (!aMedium.GetError())
-                    {
-                        nErr = ERRCODE_NONE;
-                    }
-                }
+                if (!aMedium.GetError())
+                    return ERRCODE_NONE;
             }
         }
+    }
 
-        if( ERRCODE_NONE != nErr )
-        {
-            if( ( nFlags & XOutFlags::UseNativeIfPossible ) &&
-                !( nFlags & XOutFlags::MirrorHorz ) &&
-                !( nFlags & XOutFlags::MirrorVert ) &&
-                ( rGraphic.GetType() != GraphicType::GdiMetafile ) && rGraphic.IsGfxLink() )
-            {
-                // try to write native link
-                const GfxLink aGfxLink( rGraphic.GetGfxLink() );
+    if( ( nFlags & XOutFlags::UseNativeIfPossible ) &&
+        !( nFlags & XOutFlags::MirrorHorz ) &&
+        !( nFlags & XOutFlags::MirrorVert ) &&
+        ( rGraphic.GetType() != GraphicType::GdiMetafile ) && rGraphic.IsGfxLink() )
+    {
+        // try to write native link
+        const GfxLink aGfxLink( rGraphic.GetGfxLink() );
 
-                switch( aGfxLink.GetType() )
-                {
-                    case GfxLinkType::NativeGif: aExt = FORMAT_GIF; break;
+        switch( aGfxLink.GetType() )
+        {
+            case GfxLinkType::NativeGif: aExt = FORMAT_GIF; break;
 
-                    // #i15508# added BMP type for better exports (no call/trigger found, prob used in HTML export)
-                    case GfxLinkType::NativeBmp: aExt = FORMAT_BMP; break;
+            // #i15508# added BMP type for better exports (no call/trigger found, prob used in HTML export)
+            case GfxLinkType::NativeBmp: aExt = FORMAT_BMP; break;
 
-                    case GfxLinkType::NativeJpg: aExt = FORMAT_JPG; break;
-                    case GfxLinkType::NativePng: aExt = FORMAT_PNG; break;
+            case GfxLinkType::NativeJpg: aExt = FORMAT_JPG; break;
+            case GfxLinkType::NativePng: aExt = FORMAT_PNG; break;
 
-                    default:
-                    break;
-                }
+            default:
+            break;
+        }
 
-                // tdf#60684: use native format if possible but it must correspond to filter name
-                // or no specific format has been required
-                // without this, you may save for example file with png extension but jpg content
-                if( !aExt.isEmpty() && (aExt == rFilterName || rFilterName.isEmpty()) )
-                {
-                    if( !(nFlags & XOutFlags::DontAddExtension) )
-                        aURL.setExtension( aExt );
-                    rFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+        // tdf#60684: use native format if possible but it must correspond to filter name
+        // or no specific format has been required
+        // without this, you may save for example file with png extension but jpg content
+        if( !aExt.isEmpty() && (aExt == rFilterName || rFilterName.isEmpty()) )
+        {
+            if( !(nFlags & XOutFlags::DontAddExtension) )
+                aURL.setExtension( aExt );
+            rFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
 
-                    SfxMedium   aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE | StreamMode::SHARE_DENYNONE | StreamMode::TRUNC);
-                    SvStream*   pOStm = aMedium.GetOutStream();
+            SfxMedium   aMedium(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::WRITE | StreamMode::SHARE_DENYNONE | StreamMode::TRUNC);
+            SvStream*   pOStm = aMedium.GetOutStream();
 
-                    if( pOStm && aGfxLink.GetDataSize() && aGfxLink.GetData() )
-                    {
-                        pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
-                        aMedium.Commit();
+            if( pOStm && aGfxLink.GetDataSize() && aGfxLink.GetData() )
+            {
+                pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
+                aMedium.Commit();
 
-                        if( !aMedium.GetError() )
-                            nErr = ERRCODE_NONE;
-                    }
-                }
+                if( !aMedium.GetError() )
+                    return ERRCODE_NONE;
             }
         }
+    }
 
-        if( ERRCODE_NONE != nErr )
-        {
-            OUString  aFilter( rFilterName );
-            bool    bWriteTransGrf = ( aFilter.equalsIgnoreAsciiCase( "transgrf" ) ) ||
-                                     ( aFilter.equalsIgnoreAsciiCase( "gif" ) ) ||
-                                     ( nFlags & XOutFlags::UseGifIfPossible ) ||
-                                     ( ( nFlags & XOutFlags::UseGifIfSensible ) && ( bAnimated || bTransparent ) );
+    OUString  aFilter( rFilterName );
+    bool    bWriteTransGrf = ( aFilter.equalsIgnoreAsciiCase( "transgrf" ) ) ||
+                                ( aFilter.equalsIgnoreAsciiCase( "gif" ) ) ||
+                                ( nFlags & XOutFlags::UseGifIfPossible ) ||
+                                ( ( nFlags & XOutFlags::UseGifIfSensible ) && ( bAnimated || bTransparent ) );
 
-            // get filter and extension
-            if( bWriteTransGrf )
-                aFilter = FORMAT_GIF;
+    // get filter and extension
+    if( bWriteTransGrf )
+        aFilter = FORMAT_GIF;
 
-            sal_uInt16 nFilter = rFilter.GetExportFormatNumberForShortName( aFilter );
+    sal_uInt16 nFilter = rFilter.GetExportFormatNumberForShortName( aFilter );
 
-            if( GRFILTER_FORMAT_NOTFOUND == nFilter )
-            {
-                nFilter = rFilter.GetExportFormatNumberForShortName( FORMAT_PNG );
+    if( GRFILTER_FORMAT_NOTFOUND == nFilter )
+    {
+        nFilter = rFilter.GetExportFormatNumberForShortName( FORMAT_PNG );
 
-                if( GRFILTER_FORMAT_NOTFOUND == nFilter )
-                    nFilter = rFilter.GetExportFormatNumberForShortName( FORMAT_BMP );
-            }
+        if( GRFILTER_FORMAT_NOTFOUND == nFilter )
+            nFilter = rFilter.GetExportFormatNumberForShortName( FORMAT_BMP );
+    }
 
-            if( GRFILTER_FORMAT_NOTFOUND != nFilter )
-            {
-                aExt = rFilter.GetExportFormatShortName( nFilter ).toAsciiLowerCase();
+    if( GRFILTER_FORMAT_NOTFOUND != nFilter )
+    {
+        aExt = rFilter.GetExportFormatShortName( nFilter ).toAsciiLowerCase();
 
-                if( bWriteTransGrf )
-                {
-                    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 ) )
-                            {
-                                const Wallpaper aWallpaper( pVDev->GetBackground() );
-                                const Point     aPt;
-
-                                pVDev->SetBackground( Wallpaper( COL_BLACK ) );
-                                pVDev->Erase();
-                                rGraphic.Draw( pVDev.get(), aPt, aSize );
-
-                                const Bitmap aBitmap( pVDev->GetBitmap( aPt, aSize ) );
-
-                                pVDev->SetBackground( aWallpaper );
-                                pVDev->Erase();
-                                rGraphic.Draw( pVDev.get(), 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();
-                    }
-                }
-                else
+        if( bWriteTransGrf )
+        {
+            if( bAnimated  )
+                aGraphic = rGraphic;
+            else
+            {
+                if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GraphicType::Bitmap ) )
                 {
-                    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( pVDev->SetOutputSizePixel( aSize ) )
-                        {
-                            rGraphic.Draw( pVDev.get(), Point(), aSize );
-                            aGraphic = BitmapEx(pVDev->GetBitmap(Point(), aSize));
-                        }
-                        else
-                            aGraphic = rGraphic.GetBitmapEx();
+                        const Wallpaper aWallpaper( pVDev->GetBackground() );
+                        const Point     aPt;
+
+                        pVDev->SetBackground( Wallpaper( COL_BLACK ) );
+                        pVDev->Erase();
+                        rGraphic.Draw( pVDev.get(), aPt, aSize );
+
+                        const Bitmap aBitmap( pVDev->GetBitmap( aPt, aSize ) );
+
+                        pVDev->SetBackground( aWallpaper );
+                        pVDev->Erase();
+                        rGraphic.Draw( pVDev.get(), 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();
+            }
+        }
+        else
+        {
+            if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GraphicType::Bitmap ) )
+            {
+                ScopedVclPtrInstance< VirtualDevice > pVDev;
+                const Size aSize(pVDev->LogicToPixel(*pMtfSize_100TH_MM, MapMode(MapUnit::Map100thMM)));
 
-                // mirror?
-                if( ( nFlags & XOutFlags::MirrorHorz ) || ( nFlags & XOutFlags::MirrorVert ) )
-                {
-                    BmpMirrorFlags nBmpMirrorFlags = BmpMirrorFlags::NONE;
-                    if( nFlags & XOutFlags::MirrorHorz )
-                      nBmpMirrorFlags |= BmpMirrorFlags::Horizontal;
-                    if( nFlags & XOutFlags::MirrorVert )
-                      nBmpMirrorFlags |= BmpMirrorFlags::Vertical;
-                    aGraphic = MirrorGraphic( aGraphic, nBmpMirrorFlags );
-                }
-
-                if (aGraphic.GetType() != GraphicType::NONE)
+                if( pVDev->SetOutputSizePixel( aSize ) )
                 {
-                    if( !(nFlags & XOutFlags::DontAddExtension) )
-                        aURL.setExtension( aExt );
-                    rFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
-                    nErr = ExportGraphic( aGraphic, aURL, rFilter, nFilter, pFilterData );
+                    rGraphic.Draw( pVDev.get(), Point(), aSize );
+                    aGraphic = BitmapEx(pVDev->GetBitmap(Point(), aSize));
                 }
+                else
+                    aGraphic = rGraphic.GetBitmapEx();
             }
+            else
+                aGraphic = rGraphic.GetBitmapEx();
         }
 
-        return nErr;
-    }
-    else
-    {
-        return ERRCODE_NONE;
+        // mirror?
+        if( ( nFlags & XOutFlags::MirrorHorz ) || ( nFlags & XOutFlags::MirrorVert ) )
+        {
+            BmpMirrorFlags nBmpMirrorFlags = BmpMirrorFlags::NONE;
+            if( nFlags & XOutFlags::MirrorHorz )
+                nBmpMirrorFlags |= BmpMirrorFlags::Horizontal;
+            if( nFlags & XOutFlags::MirrorVert )
+                nBmpMirrorFlags |= BmpMirrorFlags::Vertical;
+            aGraphic = MirrorGraphic( aGraphic, nBmpMirrorFlags );
+        }
+
+        if (aGraphic.GetType() != GraphicType::NONE)
+        {
+            if( !(nFlags & XOutFlags::DontAddExtension) )
+                aURL.setExtension( aExt );
+            rFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+            nErr = ExportGraphic( aGraphic, aURL, rFilter, nFilter, pFilterData );
+        }
     }
+
+    return nErr;
 }
 
 bool XOutBitmap::GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, bool bAddPrefix,


More information about the Libreoffice-commits mailing list