Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi,

This patch adds PPI resolution to the default image size data in the
Picture dialog (only for bitmap images), see the attached screenshot.

Explanation: LibreOffice supports explicite resolutions of JPEG/PNG
picture formats to set default image size, but this important data is
missing from the UI, so we cannot verify the picture quality.

Best regards,
László

PS. There are some old bugs in the default image handling in
LibreOffice, see the attached test file, but the most important
picture format (JPEG with equal explicite x-y resolutions) works well
(except the rounding error in the percent data, see 101% on the
screenshot). This patch helps to handle these problems, too.
From f0bb7abb3eef37001fa37b29936411a0fe8bc5ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A1szl=C3=B3=20N=C3=A9meth?= <nemeth@numbertext.org>
Date: Fri, 28 Oct 2011 11:19:52 +0200
Subject: [PATCH] Display resolution in PPI with the original size on Picture/Crop (in Writer)

---
 cui/source/inc/grfpage.hxx      |    1 +
 cui/source/tabpages/grfpage.cxx |   36 ++++++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/cui/source/inc/grfpage.hxx b/cui/source/inc/grfpage.hxx
index 2dad974..c3dd1a1 100644
--- a/cui/source/inc/grfpage.hxx
+++ b/cui/source/inc/grfpage.hxx
@@ -97,6 +97,7 @@ class SvxGrfCropPage : public SfxTabPage
     Timer                      aTimer;
     String                     aGraphicName;
     Size                       aOrigSize;
+    Size                       aOrigPixelSize;
     Size                       aPageSize;
     const MetricField*         pLastCropField;
     long                       nOldWidth;
diff --git a/cui/source/tabpages/grfpage.cxx b/cui/source/tabpages/grfpage.cxx
index 167280c..261a6fa 100644
--- a/cui/source/tabpages/grfpage.cxx
+++ b/cui/source/tabpages/grfpage.cxx
@@ -42,6 +42,7 @@
 #include <svx/dialogs.hrc> // for RID_SVXPAGE_GRFCROP
 
 #define CM_1_TO_TWIP           567
+#define TWIP_TO_INCH           1440
 
 
 inline long lcl_GetValue( MetricField& rMetric, FieldUnit eUnit )
@@ -214,8 +215,13 @@ void SvxGrfCropPage::Reset( const SfxItemSet &rSet )
     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, sal_False, &pItem ) )
     {
         const Graphic* pGrf = ((SvxBrushItem*)pItem)->GetGraphic();
-        if( pGrf )
+        if( pGrf ) {
             aOrigSize = GetGrfOrigSize( *pGrf );
+            if (pGrf->GetType() == GRAPHIC_BITMAP && aOrigSize.Width() && aOrigSize.Height()) {
+                Bitmap aBitmap = pGrf->GetBitmap();
+                aOrigPixelSize = aBitmap.GetSizePixel();
+            }
+        }
 
         if( aOrigSize.Width() && aOrigSize.Height() )
         {
@@ -360,6 +366,10 @@ void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet)
         {
             aExampleWN.SetGraphic( *pGrf );
             aOrigSize = GetGrfOrigSize( *pGrf );
+            if (pGrf->GetType() == GRAPHIC_BITMAP && aOrigSize.Width() > 1 && aOrigSize.Height() > 
1) {
+                Bitmap aBitmap = pGrf->GetBitmap();
+                aOrigPixelSize = aBitmap.GetSizePixel();
+            }
             aExampleWN.SetFrameSize(aOrigSize);
             GraphicHasChanged( aOrigSize.Width() && aOrigSize.Height() );
             CalcMinMaxBorder();
@@ -664,8 +674,30 @@ void SvxGrfCropPage::GraphicHasChanged( sal_Bool bFound )
         aFld.SetValue( aFld.Normalize( aOrigSize.Width() ), eUnit );
         String sTemp = aFld.GetText();
         aFld.SetValue( aFld.Normalize( aOrigSize.Height() ), eUnit );
-        sTemp += UniString::CreateFromAscii(" x ");
+        // multiplication sign (U+00D7)
+        sTemp += UniString("\xc3\x97", RTL_TEXTENCODING_UTF8);
         sTemp += aFld.GetText();
+
+        if ( aOrigPixelSize.Width() && aOrigPixelSize.Height() ) {
+             int ax = int(floor((float)aOrigPixelSize.Width() /
+                        ((float)aOrigSize.Width()/TWIP_TO_INCH)+0.5));
+             int ay = int(floor((float)aOrigPixelSize.Height() /
+                        ((float)aOrigSize.Height()/TWIP_TO_INCH)+0.5));
+             sTemp += UniString::CreateFromAscii(" (");
+             sTemp += UniString::CreateFromInt32(ax);
+             if (abs(ax - ay) > 1) {
+                sTemp += UniString("\xc3\x97", RTL_TEXTENCODING_UTF8);
+                sTemp += UniString::CreateFromInt32(ay);
+             }
+             sTemp += UniString::CreateFromAscii(" PPI)");
+        }
+
+        // compact format
+        sTemp.SearchAndReplaceAscii("cm", UniString());
+        sTemp.SearchAndReplaceAscii("mm", UniString());
+        sTemp.SearchAndReplaceAscii("pt", UniString());
+        sTemp.SearchAndReplaceAscii("pc", UniString());
+
         aOrigSizeFT.SetText(sTemp);
     }
     aLeftFT                    .Enable(bFound);
-- 
1.7.4.1

Attachment: ppi.png
Description: PNG image

Attachment: pictest.odt
Description: application/vnd.oasis.opendocument.text


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.