summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2017-10-20 10:17:01 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2017-10-20 10:33:12 +0200
commit377b8ee94e5aad0c517101ab1161280fcc39b029 (patch)
treee21a730e5ac12638a4f501e841c577fa8e5d2236
parent1c80246e5ff8aeb3e05384d86766a56aa878c7be (diff)
pdfextoutdevdata: Rearrange code for readability and efficiency
Change-Id: I506e77d97940570b076274a35cc92d3ec7278d3c Reviewed-on: https://gerrit.libreoffice.org/43584 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx61
1 files changed, 30 insertions, 31 deletions
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);
}
}