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

Mike Kaganski mike.kaganski at collabora.com
Fri Oct 20 08:33:38 UTC 2017


 vcl/source/gdi/pdfextoutdevdata.cxx |   61 +++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 31 deletions(-)

New commits:
commit 377b8ee94e5aad0c517101ab1161280fcc39b029
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Fri Oct 20 10:17:01 2017 +0300

    pdfextoutdevdata: Rearrange code for readability and efficiency
    
    Change-Id: I506e77d97940570b076274a35cc92d3ec7278d3c
    Reviewed-on: https://gerrit.libreoffice.org/43584
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index 015db9888d1c..42c3f853191a 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -399,18 +399,18 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc
                     if ( aBeg->eAct == PDFExtOutDevDataSync::EndGroupGfxLink )
                     {
                         Graphic& rGraphic = mGraphics.front();
-                        if ( rGraphic.IsLink() )
+                        if ( rGraphic.IsLink() && mParaRects.size() >= 2 )
                         {
                             GfxLinkType eType = rGraphic.GetLink().GetType();
-                            if ( eType == GfxLinkType::NativeJpg && mParaRects.size() >= 2 )
+                            if ( eType == GfxLinkType::NativeJpg )
                             {
                                 mbGroupIgnoreGDIMtfActions = rOutDevData.HasAdequateCompression(rGraphic);
                                 if ( !mbGroupIgnoreGDIMtfActions )
                                     mCurrentGraphic = rGraphic;
                             }
-                            else if ((eType == GfxLinkType::NativePng || eType == GfxLinkType::NativePdf) && mParaRects.size() >= 2)
+                            else if ( eType == GfxLinkType::NativePng || eType == GfxLinkType::NativePdf )
                             {
-                                if ( rOutDevData.HasAdequateCompression(rGraphic) || eType == GfxLinkType::NativePdf )
+                                if ( eType == GfxLinkType::NativePdf || rOutDevData.HasAdequateCompression(rGraphic) )
                                     mCurrentGraphic = rGraphic;
                             }
                         }
@@ -804,44 +804,43 @@ bool PDFExtOutDevData::HasAdequateCompression( const Graphic &rGraphic ) const
             rGraphic.GetLink().GetType() == GfxLinkType::NativePng ||
             rGraphic.GetLink().GetType() == GfxLinkType::NativePdf));
 
-    // small items better off as PNG anyway
-    if ( rGraphic.GetSizePixel().Width() < 32 &&
-         rGraphic.GetSizePixel().Height() < 32 )
+    if (rGraphic.GetLink().GetDataSize() == 0)
         return false;
 
-    // FIXME: ideally we'd also pre-empt the DPI related scaling too.
-
     Size aSize = rGraphic.GetSizePixel();
-    if (rGraphic.GetLink().GetDataSize() == 0)
+
+    // small items better off as PNG anyway
+    if ( aSize.Width() < 32 &&
+         aSize.Height() < 32 )
         return false;
+
+    if (GetIsLosslessCompression())
+        return !GetIsReduceImageResolution();
+
+    // FIXME: ideally we'd also pre-empt the DPI related scaling too.
     sal_Int32 nCurrentRatio = (100 * aSize.Width() * aSize.Height() * 4) /
                                rGraphic.GetLink().GetDataSize();
 
-    if ( GetIsLosslessCompression() )
-        return !GetIsReduceImageResolution();
-    else
+    static const struct {
+        sal_Int32 mnQuality;
+        sal_Int32 mnRatio;
+    } aRatios[] = { // minimum tolerable compression ratios
+        { 100, 400 }, { 95, 700 }, { 90, 1000 }, { 85, 1200 },
+        { 80, 1500 }, { 75, 1700 }
+    };
+    sal_Int32 nTargetRatio = 10000;
+    bool bIsTargetRatioReached = false;
+    for (auto & rRatio : aRatios)
     {
-        static const struct {
-            sal_Int32 mnQuality;
-            sal_Int32 mnRatio;
-        } aRatios[] = { // minimum tolerable compression ratios
-            { 100, 400 }, { 95, 700 }, { 90, 1000 }, { 85, 1200 },
-            { 80, 1500 }, { 75, 1700 }
-        };
-        sal_Int32 nTargetRatio = 10000;
-        bool bIsTargetRatioReached = false;
-        for (auto & rRatio : aRatios)
+        if ( mnCompressionQuality > rRatio.mnQuality )
         {
-            if ( mnCompressionQuality > rRatio.mnQuality )
-            {
-                bIsTargetRatioReached = true;
-                break;
-            }
-            nTargetRatio = rRatio.mnRatio;
+            bIsTargetRatioReached = true;
+            break;
         }
-
-        return ((nCurrentRatio > nTargetRatio) && bIsTargetRatioReached);
+        nTargetRatio = rRatio.mnRatio;
     }
+
+    return ((nCurrentRatio > nTargetRatio) && bIsTargetRatioReached);
 }
 
 }


More information about the Libreoffice-commits mailing list