[Libreoffice-commits] core.git: Branch 'distro/suse/suse-4.0' - 3 commits - filter/inc filter/source oovbaapi/ooo sc/qa sc/source

Noel Power noel.power at suse.com
Fri Jun 7 11:46:54 PDT 2013


 filter/inc/filter/msfilter/util.hxx   |   15 +++
 filter/source/msfilter/util.cxx       |  140 ++++++++++++++++++++++++++++++++++
 oovbaapi/ooo/vba/excel/XPageSetup.idl |    1 
 sc/qa/unit/data/xls/pagesetup.xls     |binary
 sc/source/filter/oox/pagesettings.cxx |  101 +-----------------------
 sc/source/ui/vba/vbapagesetup.cxx     |   32 +++++++
 sc/source/ui/vba/vbapagesetup.hxx     |    4 
 7 files changed, 199 insertions(+), 94 deletions(-)

New commits:
commit 1ac487f7b3393622bbe339a26a55168f2fc9f376
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 7 16:34:30 2013 +0100

    share spPaperSizeTable ( and associated access code ) in msfilter
    
    PageSetup.PaperSize implementation more or less copy&pasted the
    papersize conversion code from oox, this is a followup to remove
    the duplication. ( Probably the binary filter could be converted
    to use this also saving yet another nearly similar implementation )
    
    Change-Id: I479f0322163161f7819c5d650a9511910ac2e781

diff --git a/filter/inc/filter/msfilter/util.hxx b/filter/inc/filter/msfilter/util.hxx
index 607566a..dc57627 100644
--- a/filter/inc/filter/msfilter/util.hxx
+++ b/filter/inc/filter/msfilter/util.hxx
@@ -33,6 +33,7 @@
 #include <tools/datetime.hxx>
 #include <com/sun/star/lang/Locale.hpp>
 #include "filter/msfilter/msfilterdllapi.h"
+#include <com/sun/star/awt/Size.hpp>
 
 namespace msfilter {
 namespace util {
@@ -88,6 +89,20 @@ enum TextCategory
 */
 MSFILTER_DLLPUBLIC TextCategory categorizeCodePoint(sal_uInt32 codePoint, const rtl::OUString &rBcp47LanguageTag);
 
+/** Paper size in 1/100 millimeters. */
+struct MSFILTER_DLLPUBLIC ApiPaperSize
+{
+    sal_Int32           mnWidth;
+    sal_Int32           mnHeight;
+};
+
+class MSFILTER_DLLPUBLIC PaperSizeConv
+{
+public:
+    static sal_Int32 getMSPaperSizeIndex( const com::sun::star::awt::Size& rSize );
+    static const ApiPaperSize& getApiSizeForMSPaperSizeIndex( sal_Int32 nMSOPaperIndex );
+};
+
 }
 }
 
diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx
index db8aa6c..498d2d5 100644
--- a/filter/source/msfilter/util.cxx
+++ b/filter/source/msfilter/util.cxx
@@ -306,6 +306,146 @@ TextCategory categorizeCodePoint(sal_uInt32 codePoint, const rtl::OUString &rBcp
     return eRet;
 }
 
+OString ConvertColor( const Color &rColor )
+{
+    OString color( "auto" );
+    if ( rColor.GetColor() != COL_AUTO )
+    {
+        const char pHexDigits[] = "0123456789ABCDEF";
+        char pBuffer[] = "000000";
+
+        pBuffer[0] = pHexDigits[ ( rColor.GetRed()   >> 4 ) & 0x0F ];
+        pBuffer[1] = pHexDigits[   rColor.GetRed()          & 0x0F ];
+        pBuffer[2] = pHexDigits[ ( rColor.GetGreen() >> 4 ) & 0x0F ];
+        pBuffer[3] = pHexDigits[   rColor.GetGreen()        & 0x0F ];
+        pBuffer[4] = pHexDigits[ ( rColor.GetBlue()  >> 4 ) & 0x0F ];
+        pBuffer[5] = pHexDigits[   rColor.GetBlue()         & 0x0F ];
+
+        color = OString( pBuffer );
+    }
+    return color;
+}
+
+
+#define IN2MM100( v )    static_cast< sal_Int32 >( (v) * 2540.0 + 0.5 )
+#define MM2MM100( v )    static_cast< sal_Int32 >( (v) * 100.0 + 0.5 )
+
+static const ApiPaperSize spPaperSizeTable[] =
+{
+    { 0, 0 },                                                //  0 - (undefined)
+    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  1 - Letter paper
+    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  2 - Letter small paper
+    { IN2MM100( 11 ),        IN2MM100( 17 )      },          //  3 - Tabloid paper
+    { IN2MM100( 17 ),        IN2MM100( 11 )      },          //  4 - Ledger paper
+    { IN2MM100( 8.5 ),       IN2MM100( 14 )      },          //  5 - Legal paper
+    { IN2MM100( 5.5 ),       IN2MM100( 8.5 )     },          //  6 - Statement paper
+    { IN2MM100( 7.25 ),      IN2MM100( 10.5 )    },          //  7 - Executive paper
+    { MM2MM100( 297 ),       MM2MM100( 420 )     },          //  8 - A3 paper
+    { MM2MM100( 210 ),       MM2MM100( 297 )     },          //  9 - A4 paper
+    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 10 - A4 small paper
+    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 11 - A5 paper
+    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 12 - B4 paper
+    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 13 - B5 paper
+    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 14 - Folio paper
+    { MM2MM100( 215 ),       MM2MM100( 275 )     },          // 15 - Quarto paper
+    { IN2MM100( 10 ),        IN2MM100( 14 )      },          // 16 - Standard paper
+    { IN2MM100( 11 ),        IN2MM100( 17 )      },          // 17 - Standard paper
+    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          // 18 - Note paper
+    { IN2MM100( 3.875 ),     IN2MM100( 8.875 )   },          // 19 - #9 envelope
+    { IN2MM100( 4.125 ),     IN2MM100( 9.5 )     },          // 20 - #10 envelope
+    { IN2MM100( 4.5 ),       IN2MM100( 10.375 )  },          // 21 - #11 envelope
+    { IN2MM100( 4.75 ),      IN2MM100( 11 )      },          // 22 - #12 envelope
+    { IN2MM100( 5 ),         IN2MM100( 11.5 )    },          // 23 - #14 envelope
+    { IN2MM100( 17 ),        IN2MM100( 22 )      },          // 24 - C paper
+    { IN2MM100( 22 ),        IN2MM100( 34 )      },          // 25 - D paper
+    { IN2MM100( 34 ),        IN2MM100( 44 )      },          // 26 - E paper
+    { MM2MM100( 110 ),       MM2MM100( 220 )     },          // 27 - DL envelope
+    { MM2MM100( 162 ),       MM2MM100( 229 )     },          // 28 - C5 envelope
+    { MM2MM100( 324 ),       MM2MM100( 458 )     },          // 29 - C3 envelope
+    { MM2MM100( 229 ),       MM2MM100( 324 )     },          // 30 - C4 envelope
+    { MM2MM100( 114 ),       MM2MM100( 162 )     },          // 31 - C6 envelope
+    { MM2MM100( 114 ),       MM2MM100( 229 )     },          // 32 - C65 envelope
+    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 33 - B4 envelope
+    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 34 - B5 envelope
+    { MM2MM100( 176 ),       MM2MM100( 125 )     },          // 35 - B6 envelope
+    { MM2MM100( 110 ),       MM2MM100( 230 )     },          // 36 - Italy envelope
+    { IN2MM100( 3.875 ),     IN2MM100( 7.5 )     },          // 37 - Monarch envelope
+    { IN2MM100( 3.625 ),     IN2MM100( 6.5 )     },          // 38 - 6 3/4 envelope
+    { IN2MM100( 14.875 ),    IN2MM100( 11 )      },          // 39 - US standard fanfold
+    { IN2MM100( 8.5 ),       IN2MM100( 12 )      },          // 40 - German standard fanfold
+    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 41 - German legal fanfold
+    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 42 - ISO B4
+    { MM2MM100( 200 ),       MM2MM100( 148 )     },          // 43 - Japanese double postcard
+    { IN2MM100( 9 ),         IN2MM100( 11 )      },          // 44 - Standard paper
+    { IN2MM100( 10 ),        IN2MM100( 11 )      },          // 45 - Standard paper
+    { IN2MM100( 15 ),        IN2MM100( 11 )      },          // 46 - Standard paper
+    { MM2MM100( 220 ),       MM2MM100( 220 )     },          // 47 - Invite envelope
+    { 0, 0 },                                                // 48 - (undefined)
+    { 0, 0 },                                                // 49 - (undefined)
+    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 50 - Letter extra paper
+    { IN2MM100( 9.275 ),     IN2MM100( 15 )      },          // 51 - Legal extra paper
+    { IN2MM100( 11.69 ),     IN2MM100( 18 )      },          // 52 - Tabloid extra paper
+    { MM2MM100( 236 ),       MM2MM100( 322 )     },          // 53 - A4 extra paper
+    { IN2MM100( 8.275 ),     IN2MM100( 11 )      },          // 54 - Letter transverse paper
+    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 55 - A4 transverse paper
+    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 56 - Letter extra transverse paper
+    { MM2MM100( 227 ),       MM2MM100( 356 )     },          // 57 - SuperA/SuperA/A4 paper
+    { MM2MM100( 305 ),       MM2MM100( 487 )     },          // 58 - SuperB/SuperB/A3 paper
+    { IN2MM100( 8.5 ),       IN2MM100( 12.69 )   },          // 59 - Letter plus paper
+    { MM2MM100( 210 ),       MM2MM100( 330 )     },          // 60 - A4 plus paper
+    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 61 - A5 transverse paper
+    { MM2MM100( 182 ),       MM2MM100( 257 )     },          // 62 - JIS B5 transverse paper
+    { MM2MM100( 322 ),       MM2MM100( 445 )     },          // 63 - A3 extra paper
+    { MM2MM100( 174 ),       MM2MM100( 235 )     },          // 64 - A5 extra paper
+    { MM2MM100( 201 ),       MM2MM100( 276 )     },          // 65 - ISO B5 extra paper
+    { MM2MM100( 420 ),       MM2MM100( 594 )     },          // 66 - A2 paper
+    { MM2MM100( 297 ),       MM2MM100( 420 )     },          // 67 - A3 transverse paper
+    { MM2MM100( 322 ),       MM2MM100( 445 )     }           // 68 - A3 extra transverse paper
+};
+
+sal_Int32 PaperSizeConv::getMSPaperSizeIndex( const com::sun::star::awt::Size& rSize )
+{
+    sal_Int32 nElems = SAL_N_ELEMENTS( spPaperSizeTable );
+    // Need to find the best match for current size
+    sal_Int32 nDeltaWidth = 0;
+    sal_Int32 nDeltaHeight = 0;
+
+    sal_Int32 nPaperSizeIndex = 0; // Undefined
+    const ApiPaperSize* pItem = spPaperSizeTable;
+    const ApiPaperSize* pEnd =  spPaperSizeTable + nElems;
+    for ( ; pItem != pEnd; ++pItem )
+    {
+        sal_Int32 nCurDeltaHeight = std::abs( pItem->mnHeight - rSize.Height );
+        sal_Int32 nCurDeltaWidth = std::abs( pItem->mnWidth - rSize.Width );
+        if ( pItem == spPaperSizeTable ) // initialise delta with first item
+        {
+            nDeltaWidth = nCurDeltaWidth;
+            nDeltaHeight = nCurDeltaHeight;
+        }
+        else
+        {
+            if ( nCurDeltaWidth < nDeltaWidth && nCurDeltaHeight < nDeltaHeight )
+            {
+                nDeltaWidth = nCurDeltaWidth;
+                nDeltaHeight = nCurDeltaHeight;
+                nPaperSizeIndex = (pItem - spPaperSizeTable);
+            }
+        }
+    }
+    sal_Int32 nTol = 10; // hmm not sure is this the best way
+    if ( nDeltaWidth <= nTol && nDeltaHeight <= nTol )
+        return nPaperSizeIndex;
+    return 0;
+}
+
+const ApiPaperSize& PaperSizeConv::getApiSizeForMSPaperSizeIndex( sal_Int32 nMSOPaperIndex )
+{
+    sal_Int32 nElems = SAL_N_ELEMENTS( spPaperSizeTable );
+    if ( nMSOPaperIndex  < 0 || nMSOPaperIndex > nElems - 1 )
+        return spPaperSizeTable[ 0 ];
+    return spPaperSizeTable[ nMSOPaperIndex ];
+}
+
 }
 }
 
diff --git a/sc/source/filter/oox/pagesettings.cxx b/sc/source/filter/oox/pagesettings.cxx
index 33573ba..ee49ebf 100644
--- a/sc/source/filter/oox/pagesettings.cxx
+++ b/sc/source/filter/oox/pagesettings.cxx
@@ -41,6 +41,8 @@
 #include "stylesbuffer.hxx"
 #include "unitconverter.hxx"
 #include <sax/tools/converter.hxx>
+#include "document.hxx"
+#include <filter/msfilter/util.hxx>
 
 namespace oox {
 namespace xls {
@@ -899,93 +901,6 @@ void HeaderFooterParser::setNewPortion( HFPortionId ePortion )
 
 // ============================================================================
 
-namespace {
-
-/** Paper size in 1/100 millimeters. */
-struct ApiPaperSize
-{
-    sal_Int32           mnWidth;
-    sal_Int32           mnHeight;
-};
-
-#define IN2MM100( v )    static_cast< sal_Int32 >( (v) * 2540.0 + 0.5 )
-#define MM2MM100( v )    static_cast< sal_Int32 >( (v) * 100.0 + 0.5 )
-
-static const ApiPaperSize spPaperSizeTable[] =
-{
-    { 0, 0 },                                                //  0 - (undefined)
-    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  1 - Letter paper
-    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  2 - Letter small paper
-    { IN2MM100( 11 ),        IN2MM100( 17 )      },          //  3 - Tabloid paper
-    { IN2MM100( 17 ),        IN2MM100( 11 )      },          //  4 - Ledger paper
-    { IN2MM100( 8.5 ),       IN2MM100( 14 )      },          //  5 - Legal paper
-    { IN2MM100( 5.5 ),       IN2MM100( 8.5 )     },          //  6 - Statement paper
-    { IN2MM100( 7.25 ),      IN2MM100( 10.5 )    },          //  7 - Executive paper
-    { MM2MM100( 297 ),       MM2MM100( 420 )     },          //  8 - A3 paper
-    { MM2MM100( 210 ),       MM2MM100( 297 )     },          //  9 - A4 paper
-    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 10 - A4 small paper
-    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 11 - A5 paper
-    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 12 - B4 paper
-    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 13 - B5 paper
-    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 14 - Folio paper
-    { MM2MM100( 215 ),       MM2MM100( 275 )     },          // 15 - Quarto paper
-    { IN2MM100( 10 ),        IN2MM100( 14 )      },          // 16 - Standard paper
-    { IN2MM100( 11 ),        IN2MM100( 17 )      },          // 17 - Standard paper
-    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          // 18 - Note paper
-    { IN2MM100( 3.875 ),     IN2MM100( 8.875 )   },          // 19 - #9 envelope
-    { IN2MM100( 4.125 ),     IN2MM100( 9.5 )     },          // 20 - #10 envelope
-    { IN2MM100( 4.5 ),       IN2MM100( 10.375 )  },          // 21 - #11 envelope
-    { IN2MM100( 4.75 ),      IN2MM100( 11 )      },          // 22 - #12 envelope
-    { IN2MM100( 5 ),         IN2MM100( 11.5 )    },          // 23 - #14 envelope
-    { IN2MM100( 17 ),        IN2MM100( 22 )      },          // 24 - C paper
-    { IN2MM100( 22 ),        IN2MM100( 34 )      },          // 25 - D paper
-    { IN2MM100( 34 ),        IN2MM100( 44 )      },          // 26 - E paper
-    { MM2MM100( 110 ),       MM2MM100( 220 )     },          // 27 - DL envelope
-    { MM2MM100( 162 ),       MM2MM100( 229 )     },          // 28 - C5 envelope
-    { MM2MM100( 324 ),       MM2MM100( 458 )     },          // 29 - C3 envelope
-    { MM2MM100( 229 ),       MM2MM100( 324 )     },          // 30 - C4 envelope
-    { MM2MM100( 114 ),       MM2MM100( 162 )     },          // 31 - C6 envelope
-    { MM2MM100( 114 ),       MM2MM100( 229 )     },          // 32 - C65 envelope
-    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 33 - B4 envelope
-    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 34 - B5 envelope
-    { MM2MM100( 176 ),       MM2MM100( 125 )     },          // 35 - B6 envelope
-    { MM2MM100( 110 ),       MM2MM100( 230 )     },          // 36 - Italy envelope
-    { IN2MM100( 3.875 ),     IN2MM100( 7.5 )     },          // 37 - Monarch envelope
-    { IN2MM100( 3.625 ),     IN2MM100( 6.5 )     },          // 38 - 6 3/4 envelope
-    { IN2MM100( 14.875 ),    IN2MM100( 11 )      },          // 39 - US standard fanfold
-    { IN2MM100( 8.5 ),       IN2MM100( 12 )      },          // 40 - German standard fanfold
-    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 41 - German legal fanfold
-    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 42 - ISO B4
-    { MM2MM100( 200 ),       MM2MM100( 148 )     },          // 43 - Japanese double postcard
-    { IN2MM100( 9 ),         IN2MM100( 11 )      },          // 44 - Standard paper
-    { IN2MM100( 10 ),        IN2MM100( 11 )      },          // 45 - Standard paper
-    { IN2MM100( 15 ),        IN2MM100( 11 )      },          // 46 - Standard paper
-    { MM2MM100( 220 ),       MM2MM100( 220 )     },          // 47 - Invite envelope
-    { 0, 0 },                                                // 48 - (undefined)
-    { 0, 0 },                                                // 49 - (undefined)
-    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 50 - Letter extra paper
-    { IN2MM100( 9.275 ),     IN2MM100( 15 )      },          // 51 - Legal extra paper
-    { IN2MM100( 11.69 ),     IN2MM100( 18 )      },          // 52 - Tabloid extra paper
-    { MM2MM100( 236 ),       MM2MM100( 322 )     },          // 53 - A4 extra paper
-    { IN2MM100( 8.275 ),     IN2MM100( 11 )      },          // 54 - Letter transverse paper
-    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 55 - A4 transverse paper
-    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 56 - Letter extra transverse paper
-    { MM2MM100( 227 ),       MM2MM100( 356 )     },          // 57 - SuperA/SuperA/A4 paper
-    { MM2MM100( 305 ),       MM2MM100( 487 )     },          // 58 - SuperB/SuperB/A3 paper
-    { IN2MM100( 8.5 ),       IN2MM100( 12.69 )   },          // 59 - Letter plus paper
-    { MM2MM100( 210 ),       MM2MM100( 330 )     },          // 60 - A4 plus paper
-    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 61 - A5 transverse paper
-    { MM2MM100( 182 ),       MM2MM100( 257 )     },          // 62 - JIS B5 transverse paper
-    { MM2MM100( 322 ),       MM2MM100( 445 )     },          // 63 - A3 extra paper
-    { MM2MM100( 174 ),       MM2MM100( 235 )     },          // 64 - A5 extra paper
-    { MM2MM100( 201 ),       MM2MM100( 276 )     },          // 65 - ISO B5 extra paper
-    { MM2MM100( 420 ),       MM2MM100( 594 )     },          // 66 - A2 paper
-    { MM2MM100( 297 ),       MM2MM100( 420 )     },          // 67 - A3 transverse paper
-    { MM2MM100( 322 ),       MM2MM100( 445 )     }           // 68 - A3 extra transverse paper
-};
-
-} // namespace
-
 // ----------------------------------------------------------------------------
 
 PageSettingsConverter::HFHelperData::HFHelperData( sal_Int32 nLeftPropId, sal_Int32 nRightPropId ) :
@@ -1047,18 +962,18 @@ void PageSettingsConverter::writePageSettingsProperties(
     // paper size
     if( !rModel.mbValidSettings )
     {
-        Size aSize;
+        awt::Size aSize;
         bool bValid = false;
 
-        if( (0 < rModel.mnPaperSize) && (rModel.mnPaperSize < static_cast< sal_Int32 >( STATIC_ARRAY_SIZE( spPaperSizeTable ) )) )
+        if( (0 < rModel.mnPaperSize) )
         {
-            const ApiPaperSize& rPaperSize = spPaperSizeTable[ rModel.mnPaperSize ];
-            aSize = Size( rPaperSize.mnWidth, rPaperSize.mnHeight );
-            bValid = true;
+            const msfilter::util::ApiPaperSize& rPaperSize = msfilter::util::PaperSizeConv::getApiSizeForMSPaperSizeIndex(  rModel.mnPaperSize );
+            aSize = awt::Size( rPaperSize.mnWidth, rPaperSize.mnHeight );
+            bValid = ( rPaperSize.mnWidth != 0 && rPaperSize.mnHeight != 0 );
         }
         if( rModel.mnPaperWidth > 0 && rModel.mnPaperHeight > 0 )
         {
-            aSize = Size( rModel.mnPaperWidth, rModel.mnPaperHeight );
+            aSize = awt::Size( rModel.mnPaperWidth, rModel.mnPaperHeight );
             bValid = true;
         }
 
diff --git a/sc/source/ui/vba/vbapagesetup.cxx b/sc/source/ui/vba/vbapagesetup.cxx
index d6fbd17..6b8272f 100644
--- a/sc/source/ui/vba/vbapagesetup.cxx
+++ b/sc/source/ui/vba/vbapagesetup.cxx
@@ -32,6 +32,7 @@
 #include <i18nutil/paper.hxx>
 #include <sal/macros.h>
 #include <algorithm>
+#include <filter/msfilter/util.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::ooo::vba;
@@ -624,141 +625,28 @@ OUString SAL_CALL ScVbaPageSetup::getPrintTitleColumns() throw (uno::RuntimeExce
 void SAL_CALL ScVbaPageSetup::setPrintTitleColumns( const OUString& /*_printtitlecolumns*/ ) throw (uno::RuntimeException)
 {
 }
-/** Paper size in 1/100 millimeters. */
-struct ApiPaperSize
-{
-    sal_Int32           mnWidth;
-    sal_Int32           mnHeight;
-};
-
-// #FIXME ( this is cut'n'pasted from oox, we need to share it somewhere, msfilter ? )
-
-#define IN2MM100( v )    static_cast< sal_Int32 >( (v) * 2540.0 + 0.5 )
-#define MM2MM100( v )    static_cast< sal_Int32 >( (v) * 100.0 + 0.5 )
-
-static const ApiPaperSize spPaperSizeTable[] =
-{
-    { 0, 0 },                                                //  0 - (undefined)
-    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  1 - Letter paper
-    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  2 - Letter small paper
-    { IN2MM100( 11 ),        IN2MM100( 17 )      },          //  3 - Tabloid paper
-    { IN2MM100( 17 ),        IN2MM100( 11 )      },          //  4 - Ledger paper
-    { IN2MM100( 8.5 ),       IN2MM100( 14 )      },          //  5 - Legal paper
-    { IN2MM100( 5.5 ),       IN2MM100( 8.5 )     },          //  6 - Statement paper
-    { IN2MM100( 7.25 ),      IN2MM100( 10.5 )    },          //  7 - Executive paper
-    { MM2MM100( 297 ),       MM2MM100( 420 )     },          //  8 - A3 paper
-    { MM2MM100( 210 ),       MM2MM100( 297 )     },          //  9 - A4 paper
-    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 10 - A4 small paper
-    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 11 - A5 paper
-    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 12 - B4 paper
-    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 13 - B5 paper
-    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 14 - Folio paper
-    { MM2MM100( 215 ),       MM2MM100( 275 )     },          // 15 - Quarto paper
-    { IN2MM100( 10 ),        IN2MM100( 14 )      },          // 16 - Standard paper
-    { IN2MM100( 11 ),        IN2MM100( 17 )      },          // 17 - Standard paper
-    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          // 18 - Note paper
-    { IN2MM100( 3.875 ),     IN2MM100( 8.875 )   },          // 19 - #9 envelope
-    { IN2MM100( 4.125 ),     IN2MM100( 9.5 )     },          // 20 - #10 envelope
-    { IN2MM100( 4.5 ),       IN2MM100( 10.375 )  },          // 21 - #11 envelope
-    { IN2MM100( 4.75 ),      IN2MM100( 11 )      },          // 22 - #12 envelope
-    { IN2MM100( 5 ),         IN2MM100( 11.5 )    },          // 23 - #14 envelope
-    { IN2MM100( 17 ),        IN2MM100( 22 )      },          // 24 - C paper
-    { IN2MM100( 22 ),        IN2MM100( 34 )      },          // 25 - D paper
-    { IN2MM100( 34 ),        IN2MM100( 44 )      },          // 26 - E paper
-    { MM2MM100( 110 ),       MM2MM100( 220 )     },          // 27 - DL envelope
-    { MM2MM100( 162 ),       MM2MM100( 229 )     },          // 28 - C5 envelope
-    { MM2MM100( 324 ),       MM2MM100( 458 )     },          // 29 - C3 envelope
-    { MM2MM100( 229 ),       MM2MM100( 324 )     },          // 30 - C4 envelope
-    { MM2MM100( 114 ),       MM2MM100( 162 )     },          // 31 - C6 envelope
-    { MM2MM100( 114 ),       MM2MM100( 229 )     },          // 32 - C65 envelope
-    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 33 - B4 envelope
-    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 34 - B5 envelope
-    { MM2MM100( 176 ),       MM2MM100( 125 )     },          // 35 - B6 envelope
-    { MM2MM100( 110 ),       MM2MM100( 230 )     },          // 36 - Italy envelope
-    { IN2MM100( 3.875 ),     IN2MM100( 7.5 )     },          // 37 - Monarch envelope
-    { IN2MM100( 3.625 ),     IN2MM100( 6.5 )     },          // 38 - 6 3/4 envelope
-    { IN2MM100( 14.875 ),    IN2MM100( 11 )      },          // 39 - US standard fanfold
-    { IN2MM100( 8.5 ),       IN2MM100( 12 )      },          // 40 - German standard fanfold
-    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 41 - German legal fanfold
-    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 42 - ISO B4
-    { MM2MM100( 200 ),       MM2MM100( 148 )     },          // 43 - Japanese double postcard
-    { IN2MM100( 9 ),         IN2MM100( 11 )      },          // 44 - Standard paper
-    { IN2MM100( 10 ),        IN2MM100( 11 )      },          // 45 - Standard paper
-    { IN2MM100( 15 ),        IN2MM100( 11 )      },          // 46 - Standard paper
-    { MM2MM100( 220 ),       MM2MM100( 220 )     },          // 47 - Invite envelope
-    { 0, 0 },                                                // 48 - (undefined)
-    { 0, 0 },                                                // 49 - (undefined)
-    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 50 - Letter extra paper
-    { IN2MM100( 9.275 ),     IN2MM100( 15 )      },          // 51 - Legal extra paper
-    { IN2MM100( 11.69 ),     IN2MM100( 18 )      },          // 52 - Tabloid extra paper
-    { MM2MM100( 236 ),       MM2MM100( 322 )     },          // 53 - A4 extra paper
-    { IN2MM100( 8.275 ),     IN2MM100( 11 )      },          // 54 - Letter transverse paper
-    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 55 - A4 transverse paper
-    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 56 - Letter extra transverse paper
-    { MM2MM100( 227 ),       MM2MM100( 356 )     },          // 57 - SuperA/SuperA/A4 paper
-    { MM2MM100( 305 ),       MM2MM100( 487 )     },          // 58 - SuperB/SuperB/A3 paper
-    { IN2MM100( 8.5 ),       IN2MM100( 12.69 )   },          // 59 - Letter plus paper
-    { MM2MM100( 210 ),       MM2MM100( 330 )     },          // 60 - A4 plus paper
-    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 61 - A5 transverse paper
-    { MM2MM100( 182 ),       MM2MM100( 257 )     },          // 62 - JIS B5 transverse paper
-    { MM2MM100( 322 ),       MM2MM100( 445 )     },          // 63 - A3 extra paper
-    { MM2MM100( 174 ),       MM2MM100( 235 )     },          // 64 - A5 extra paper
-    { MM2MM100( 201 ),       MM2MM100( 276 )     },          // 65 - ISO B5 extra paper
-    { MM2MM100( 420 ),       MM2MM100( 594 )     },          // 66 - A2 paper
-    { MM2MM100( 297 ),       MM2MM100( 420 )     },          // 67 - A3 transverse paper
-    { MM2MM100( 322 ),       MM2MM100( 445 )     }           // 68 - A3 extra transverse paper
-};
 
 sal_Int32 SAL_CALL ScVbaPageSetup::getPaperSize() throw (uno::RuntimeException)
 {
-    sal_Int32 nElems = SAL_N_ELEMENTS( spPaperSizeTable );
-    // Need to find the best match for current size
-    sal_Int32 nDeltaWidth = 0;
-    sal_Int32 nDeltaHeight = 0;
     awt::Size aSize; // current papersize
     mxPageProps->getPropertyValue( "Size" ) >>= aSize;
     if ( mbIsLandscape )
         ::std::swap( aSize.Width, aSize.Height );
 
-    sal_Int32 nPaperSizeIndex = 0; // Undefined
-    const ApiPaperSize* pItem = spPaperSizeTable;
-    const ApiPaperSize* pEnd =  spPaperSizeTable + nElems;
-    for ( ; pItem != pEnd; ++pItem )
-    {
-        const ApiPaperSize& rSize = *pItem;
-        sal_Int32 nCurDeltaHeight = std::abs( rSize.mnHeight - aSize.Height );
-        sal_Int32 nCurDeltaWidth = std::abs( rSize.mnWidth - aSize.Width );
-        if ( pItem == spPaperSizeTable ) // initialise delta with first item
-        {
-            nDeltaWidth = nCurDeltaWidth;
-            nDeltaHeight = nCurDeltaHeight;
-        }
-        else
-        {
-            if ( nCurDeltaWidth < nDeltaWidth && nCurDeltaHeight < nDeltaHeight )
-            {
-                nDeltaWidth = nCurDeltaWidth;
-                nDeltaHeight = nCurDeltaHeight;
-                nPaperSizeIndex = (pItem - spPaperSizeTable);
-            }
-        }
-    }
-    sal_Int32 nTol = 10; // hmm not sure is this the best way
-    if ( nDeltaWidth <= nTol && nDeltaHeight <= nTol )
-        return nPaperSizeIndex;
-    return excel::XlPaperSize::xlPaperUser;
+    sal_Int32 nPaperSizeIndex = msfilter::util::PaperSizeConv::getMSPaperSizeIndex( aSize );
+    if ( nPaperSizeIndex == 0 )
+        nPaperSizeIndex = excel::XlPaperSize::xlPaperUser;
+    return nPaperSizeIndex;
 }
 
 void SAL_CALL ScVbaPageSetup::setPaperSize( sal_Int32 papersize ) throw (uno::RuntimeException)
 {
-    sal_Int32 nElems = SAL_N_ELEMENTS( spPaperSizeTable );
     if ( papersize != excel::XlPaperSize::xlPaperUser )
     {
-        if ( papersize < 0 || papersize > nElems - 1 )
-            throw uno::RuntimeException();
         awt::Size aPaperSize;
-        aPaperSize.Height = spPaperSizeTable[ papersize ].mnHeight;
-        aPaperSize.Width = spPaperSizeTable[ papersize ].mnWidth;
+        const msfilter::util::ApiPaperSize& rConvertedSize = msfilter::util::PaperSizeConv::getApiSizeForMSPaperSizeIndex( papersize );
+        aPaperSize.Height = rConvertedSize.mnHeight;
+        aPaperSize.Width = rConvertedSize.mnWidth;
         if ( mbIsLandscape )
             ::std::swap( aPaperSize.Width, aPaperSize.Height );
         mxPageProps->setPropertyValue( "Size", uno::makeAny( aPaperSize ) );
commit b1e46887934804f5929e68f120f9698c5293dd70
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 7 13:04:43 2013 +0100

    remove unintended changes ( from some aborted approach )
    
    Change-Id: I793a635711475ebb1125611ec48d52c130cd20a0
    (cherry picked from commit 0683a7b15ce668efd79fa556f5511de833c7ec12)

diff --git a/sc/source/filter/inc/xlpage.hxx b/sc/source/filter/inc/xlpage.hxx
index 1f9118a..2f5599f 100644
--- a/sc/source/filter/inc/xlpage.hxx
+++ b/sc/source/filter/inc/xlpage.hxx
@@ -23,7 +23,6 @@
 #include <tools/gen.hxx>
 #include <boost/noncopyable.hpp>
 #include "xltools.hxx"
-#include "scdllapi.h"
 
 // Constants and Enumerations =================================================
 
@@ -92,7 +91,7 @@ const sal_uInt16 EXC_PAPERSIZE_USER         = 0xFFFF;
 class SvxBrushItem;
 
 /** Contains all page (print) settings for a single sheet. */
-struct SC_DLLPUBLIC XclPageData : private boost::noncopyable
+struct XclPageData : private boost::noncopyable
 {
     typedef ::std::auto_ptr< SvxBrushItem > SvxBrushItemPtr;
 
commit a649f2b269b654e844f39c87d6d642d754c8f81f
Author: Noel Power <noel.power at suse.com>
Date:   Fri Jun 7 12:48:54 2013 +0100

    add missing PageSetup.PageSize api
    
    Change-Id: If52fb46f61962827acc08025617d9d61a6ab6d40
    (cherry picked from commit 254a2d6c71f7615c7652ca401b9dd3eac1e0d570)

diff --git a/oovbaapi/ooo/vba/excel/XPageSetup.idl b/oovbaapi/ooo/vba/excel/XPageSetup.idl
index c83f2f1..6c39513 100644
--- a/oovbaapi/ooo/vba/excel/XPageSetup.idl
+++ b/oovbaapi/ooo/vba/excel/XPageSetup.idl
@@ -53,6 +53,7 @@ interface XPageSetup : com::sun::star::uno::XInterface
     [attribute] boolean PrintGridlines;
     [attribute] string PrintTitleRows;
     [attribute] string PrintTitleColumns;
+    [attribute] long PaperSize;
 
 };
 
diff --git a/sc/qa/unit/data/xls/pagesetup.xls b/sc/qa/unit/data/xls/pagesetup.xls
index b1f0b9c..db1033a 100644
Binary files a/sc/qa/unit/data/xls/pagesetup.xls and b/sc/qa/unit/data/xls/pagesetup.xls differ
diff --git a/sc/source/filter/inc/xlpage.hxx b/sc/source/filter/inc/xlpage.hxx
index 2f5599f..1f9118a 100644
--- a/sc/source/filter/inc/xlpage.hxx
+++ b/sc/source/filter/inc/xlpage.hxx
@@ -23,6 +23,7 @@
 #include <tools/gen.hxx>
 #include <boost/noncopyable.hpp>
 #include "xltools.hxx"
+#include "scdllapi.h"
 
 // Constants and Enumerations =================================================
 
@@ -91,7 +92,7 @@ const sal_uInt16 EXC_PAPERSIZE_USER         = 0xFFFF;
 class SvxBrushItem;
 
 /** Contains all page (print) settings for a single sheet. */
-struct XclPageData : private boost::noncopyable
+struct SC_DLLPUBLIC XclPageData : private boost::noncopyable
 {
     typedef ::std::auto_ptr< SvxBrushItem > SvxBrushItemPtr;
 
diff --git a/sc/source/ui/vba/vbapagesetup.cxx b/sc/source/ui/vba/vbapagesetup.cxx
index 72e260a..d6fbd17 100644
--- a/sc/source/ui/vba/vbapagesetup.cxx
+++ b/sc/source/ui/vba/vbapagesetup.cxx
@@ -31,6 +31,7 @@
 #include <ooo/vba/excel/Constants.hpp>
 #include <i18nutil/paper.hxx>
 #include <sal/macros.h>
+#include <algorithm>
 
 using namespace ::com::sun::star;
 using namespace ::ooo::vba;
@@ -44,7 +45,7 @@ ScVbaPageSetup::ScVbaPageSetup(const uno::Reference< XHelperInterface >& xParent
                 const uno::Reference< uno::XComponentContext >& xContext,
                 const uno::Reference< sheet::XSpreadsheet >& xSheet,
                 const uno::Reference< frame::XModel >& xModel) throw (uno::RuntimeException):
-           ScVbaPageSetup_BASE( xParent, xContext ), mxSheet( xSheet )
+           ScVbaPageSetup_BASE( xParent, xContext ), mxSheet( xSheet ), mbIsLandscape( false )
 {
     // query for current page style
     mxModel.set( xModel, uno::UNO_QUERY_THROW );
@@ -59,6 +60,7 @@ ScVbaPageSetup::ScVbaPageSetup(const uno::Reference< XHelperInterface >& xParent
     mxPageProps.set( xPageStyle->getByName(aStyleName), uno::UNO_QUERY_THROW );
     mnOrientLandscape = excel::XlPageOrientation::xlLandscape;
     mnOrientPortrait = excel::XlPageOrientation::xlPortrait;
+    mxPageProps->getPropertyValue("IsLandscape") >>= mbIsLandscape;
 }
 
 rtl::OUString SAL_CALL ScVbaPageSetup::getPrintArea() throw (css::uno::RuntimeException)
@@ -622,6 +624,146 @@ OUString SAL_CALL ScVbaPageSetup::getPrintTitleColumns() throw (uno::RuntimeExce
 void SAL_CALL ScVbaPageSetup::setPrintTitleColumns( const OUString& /*_printtitlecolumns*/ ) throw (uno::RuntimeException)
 {
 }
+/** Paper size in 1/100 millimeters. */
+struct ApiPaperSize
+{
+    sal_Int32           mnWidth;
+    sal_Int32           mnHeight;
+};
+
+// #FIXME ( this is cut'n'pasted from oox, we need to share it somewhere, msfilter ? )
+
+#define IN2MM100( v )    static_cast< sal_Int32 >( (v) * 2540.0 + 0.5 )
+#define MM2MM100( v )    static_cast< sal_Int32 >( (v) * 100.0 + 0.5 )
+
+static const ApiPaperSize spPaperSizeTable[] =
+{
+    { 0, 0 },                                                //  0 - (undefined)
+    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  1 - Letter paper
+    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          //  2 - Letter small paper
+    { IN2MM100( 11 ),        IN2MM100( 17 )      },          //  3 - Tabloid paper
+    { IN2MM100( 17 ),        IN2MM100( 11 )      },          //  4 - Ledger paper
+    { IN2MM100( 8.5 ),       IN2MM100( 14 )      },          //  5 - Legal paper
+    { IN2MM100( 5.5 ),       IN2MM100( 8.5 )     },          //  6 - Statement paper
+    { IN2MM100( 7.25 ),      IN2MM100( 10.5 )    },          //  7 - Executive paper
+    { MM2MM100( 297 ),       MM2MM100( 420 )     },          //  8 - A3 paper
+    { MM2MM100( 210 ),       MM2MM100( 297 )     },          //  9 - A4 paper
+    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 10 - A4 small paper
+    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 11 - A5 paper
+    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 12 - B4 paper
+    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 13 - B5 paper
+    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 14 - Folio paper
+    { MM2MM100( 215 ),       MM2MM100( 275 )     },          // 15 - Quarto paper
+    { IN2MM100( 10 ),        IN2MM100( 14 )      },          // 16 - Standard paper
+    { IN2MM100( 11 ),        IN2MM100( 17 )      },          // 17 - Standard paper
+    { IN2MM100( 8.5 ),       IN2MM100( 11 )      },          // 18 - Note paper
+    { IN2MM100( 3.875 ),     IN2MM100( 8.875 )   },          // 19 - #9 envelope
+    { IN2MM100( 4.125 ),     IN2MM100( 9.5 )     },          // 20 - #10 envelope
+    { IN2MM100( 4.5 ),       IN2MM100( 10.375 )  },          // 21 - #11 envelope
+    { IN2MM100( 4.75 ),      IN2MM100( 11 )      },          // 22 - #12 envelope
+    { IN2MM100( 5 ),         IN2MM100( 11.5 )    },          // 23 - #14 envelope
+    { IN2MM100( 17 ),        IN2MM100( 22 )      },          // 24 - C paper
+    { IN2MM100( 22 ),        IN2MM100( 34 )      },          // 25 - D paper
+    { IN2MM100( 34 ),        IN2MM100( 44 )      },          // 26 - E paper
+    { MM2MM100( 110 ),       MM2MM100( 220 )     },          // 27 - DL envelope
+    { MM2MM100( 162 ),       MM2MM100( 229 )     },          // 28 - C5 envelope
+    { MM2MM100( 324 ),       MM2MM100( 458 )     },          // 29 - C3 envelope
+    { MM2MM100( 229 ),       MM2MM100( 324 )     },          // 30 - C4 envelope
+    { MM2MM100( 114 ),       MM2MM100( 162 )     },          // 31 - C6 envelope
+    { MM2MM100( 114 ),       MM2MM100( 229 )     },          // 32 - C65 envelope
+    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 33 - B4 envelope
+    { MM2MM100( 176 ),       MM2MM100( 250 )     },          // 34 - B5 envelope
+    { MM2MM100( 176 ),       MM2MM100( 125 )     },          // 35 - B6 envelope
+    { MM2MM100( 110 ),       MM2MM100( 230 )     },          // 36 - Italy envelope
+    { IN2MM100( 3.875 ),     IN2MM100( 7.5 )     },          // 37 - Monarch envelope
+    { IN2MM100( 3.625 ),     IN2MM100( 6.5 )     },          // 38 - 6 3/4 envelope
+    { IN2MM100( 14.875 ),    IN2MM100( 11 )      },          // 39 - US standard fanfold
+    { IN2MM100( 8.5 ),       IN2MM100( 12 )      },          // 40 - German standard fanfold
+    { IN2MM100( 8.5 ),       IN2MM100( 13 )      },          // 41 - German legal fanfold
+    { MM2MM100( 250 ),       MM2MM100( 353 )     },          // 42 - ISO B4
+    { MM2MM100( 200 ),       MM2MM100( 148 )     },          // 43 - Japanese double postcard
+    { IN2MM100( 9 ),         IN2MM100( 11 )      },          // 44 - Standard paper
+    { IN2MM100( 10 ),        IN2MM100( 11 )      },          // 45 - Standard paper
+    { IN2MM100( 15 ),        IN2MM100( 11 )      },          // 46 - Standard paper
+    { MM2MM100( 220 ),       MM2MM100( 220 )     },          // 47 - Invite envelope
+    { 0, 0 },                                                // 48 - (undefined)
+    { 0, 0 },                                                // 49 - (undefined)
+    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 50 - Letter extra paper
+    { IN2MM100( 9.275 ),     IN2MM100( 15 )      },          // 51 - Legal extra paper
+    { IN2MM100( 11.69 ),     IN2MM100( 18 )      },          // 52 - Tabloid extra paper
+    { MM2MM100( 236 ),       MM2MM100( 322 )     },          // 53 - A4 extra paper
+    { IN2MM100( 8.275 ),     IN2MM100( 11 )      },          // 54 - Letter transverse paper
+    { MM2MM100( 210 ),       MM2MM100( 297 )     },          // 55 - A4 transverse paper
+    { IN2MM100( 9.275 ),     IN2MM100( 12 )      },          // 56 - Letter extra transverse paper
+    { MM2MM100( 227 ),       MM2MM100( 356 )     },          // 57 - SuperA/SuperA/A4 paper
+    { MM2MM100( 305 ),       MM2MM100( 487 )     },          // 58 - SuperB/SuperB/A3 paper
+    { IN2MM100( 8.5 ),       IN2MM100( 12.69 )   },          // 59 - Letter plus paper
+    { MM2MM100( 210 ),       MM2MM100( 330 )     },          // 60 - A4 plus paper
+    { MM2MM100( 148 ),       MM2MM100( 210 )     },          // 61 - A5 transverse paper
+    { MM2MM100( 182 ),       MM2MM100( 257 )     },          // 62 - JIS B5 transverse paper
+    { MM2MM100( 322 ),       MM2MM100( 445 )     },          // 63 - A3 extra paper
+    { MM2MM100( 174 ),       MM2MM100( 235 )     },          // 64 - A5 extra paper
+    { MM2MM100( 201 ),       MM2MM100( 276 )     },          // 65 - ISO B5 extra paper
+    { MM2MM100( 420 ),       MM2MM100( 594 )     },          // 66 - A2 paper
+    { MM2MM100( 297 ),       MM2MM100( 420 )     },          // 67 - A3 transverse paper
+    { MM2MM100( 322 ),       MM2MM100( 445 )     }           // 68 - A3 extra transverse paper
+};
+
+sal_Int32 SAL_CALL ScVbaPageSetup::getPaperSize() throw (uno::RuntimeException)
+{
+    sal_Int32 nElems = SAL_N_ELEMENTS( spPaperSizeTable );
+    // Need to find the best match for current size
+    sal_Int32 nDeltaWidth = 0;
+    sal_Int32 nDeltaHeight = 0;
+    awt::Size aSize; // current papersize
+    mxPageProps->getPropertyValue( "Size" ) >>= aSize;
+    if ( mbIsLandscape )
+        ::std::swap( aSize.Width, aSize.Height );
+
+    sal_Int32 nPaperSizeIndex = 0; // Undefined
+    const ApiPaperSize* pItem = spPaperSizeTable;
+    const ApiPaperSize* pEnd =  spPaperSizeTable + nElems;
+    for ( ; pItem != pEnd; ++pItem )
+    {
+        const ApiPaperSize& rSize = *pItem;
+        sal_Int32 nCurDeltaHeight = std::abs( rSize.mnHeight - aSize.Height );
+        sal_Int32 nCurDeltaWidth = std::abs( rSize.mnWidth - aSize.Width );
+        if ( pItem == spPaperSizeTable ) // initialise delta with first item
+        {
+            nDeltaWidth = nCurDeltaWidth;
+            nDeltaHeight = nCurDeltaHeight;
+        }
+        else
+        {
+            if ( nCurDeltaWidth < nDeltaWidth && nCurDeltaHeight < nDeltaHeight )
+            {
+                nDeltaWidth = nCurDeltaWidth;
+                nDeltaHeight = nCurDeltaHeight;
+                nPaperSizeIndex = (pItem - spPaperSizeTable);
+            }
+        }
+    }
+    sal_Int32 nTol = 10; // hmm not sure is this the best way
+    if ( nDeltaWidth <= nTol && nDeltaHeight <= nTol )
+        return nPaperSizeIndex;
+    return excel::XlPaperSize::xlPaperUser;
+}
+
+void SAL_CALL ScVbaPageSetup::setPaperSize( sal_Int32 papersize ) throw (uno::RuntimeException)
+{
+    sal_Int32 nElems = SAL_N_ELEMENTS( spPaperSizeTable );
+    if ( papersize != excel::XlPaperSize::xlPaperUser )
+    {
+        if ( papersize < 0 || papersize > nElems - 1 )
+            throw uno::RuntimeException();
+        awt::Size aPaperSize;
+        aPaperSize.Height = spPaperSizeTable[ papersize ].mnHeight;
+        aPaperSize.Width = spPaperSizeTable[ papersize ].mnWidth;
+        if ( mbIsLandscape )
+            ::std::swap( aPaperSize.Width, aPaperSize.Height );
+        mxPageProps->setPropertyValue( "Size", uno::makeAny( aPaperSize ) );
+    }
+}
 
 OUString
 ScVbaPageSetup::getServiceImplName()
diff --git a/sc/source/ui/vba/vbapagesetup.hxx b/sc/source/ui/vba/vbapagesetup.hxx
index 9431c75..c9d3576 100644
--- a/sc/source/ui/vba/vbapagesetup.hxx
+++ b/sc/source/ui/vba/vbapagesetup.hxx
@@ -26,12 +26,14 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <vbahelper/vbahelperinterface.hxx>
 #include <vbahelper/vbapagesetupbase.hxx>
+#include <ooo/vba/excel/XlPaperSize.hpp>
 
 typedef cppu::ImplInheritanceHelper1< VbaPageSetupBase, ov::excel::XPageSetup > ScVbaPageSetup_BASE;
 
 class ScVbaPageSetup :  public ScVbaPageSetup_BASE
 {
     css::uno::Reference< css::sheet::XSpreadsheet > mxSheet;
+    bool mbIsLandscape;
 public:
     ScVbaPageSetup( const css::uno::Reference< ov::XHelperInterface >& xParent,
                     const css::uno::Reference< css::uno::XComponentContext >& xContext,
@@ -81,6 +83,8 @@ public:
     virtual void SAL_CALL setPrintTitleRows( const ::rtl::OUString& _printtitlerows ) throw (css::uno::RuntimeException);
     virtual ::rtl::OUString SAL_CALL getPrintTitleColumns() throw (css::uno::RuntimeException);
     virtual void SAL_CALL setPrintTitleColumns( const ::rtl::OUString& _printtitlecolumns ) throw (css::uno::RuntimeException);
+    virtual sal_Int32 SAL_CALL getPaperSize() throw (css::uno::RuntimeException);
+    virtual void SAL_CALL setPaperSize( sal_Int32 papersize ) throw (css::uno::RuntimeException);
     // XHelperInterface
     virtual rtl::OUString getServiceImplName();
     virtual css::uno::Sequence<rtl::OUString> getServiceNames();


More information about the Libreoffice-commits mailing list