diff options
Diffstat (limited to 'oox/source/xls')
-rw-r--r-- | oox/source/xls/biffcodec.cxx | 92 | ||||
-rwxr-xr-x | oox/source/xls/excelvbaproject.cxx | 161 | ||||
-rw-r--r-- | oox/source/xls/makefile.mk | 1 | ||||
-rw-r--r-- | oox/source/xls/workbookhelper.cxx | 4 | ||||
-rw-r--r-- | oox/source/xls/worksheethelper.cxx | 134 |
5 files changed, 341 insertions, 51 deletions
diff --git a/oox/source/xls/biffcodec.cxx b/oox/source/xls/biffcodec.cxx index 2021c21cb08c..0872dcc654df 100644 --- a/oox/source/xls/biffcodec.cxx +++ b/oox/source/xls/biffcodec.cxx @@ -36,6 +36,8 @@ using ::rtl::OUString; using ::rtl::OStringToOUString; using ::oox::core::FilterBase; +using namespace ::com::sun::star; + namespace oox { namespace xls { @@ -50,9 +52,16 @@ BiffDecoderBase::~BiffDecoderBase() { } -::comphelper::DocPasswordVerifierResult BiffDecoderBase::verifyPassword( const OUString& rPassword ) +::comphelper::DocPasswordVerifierResult BiffDecoderBase::verifyPassword( const ::rtl::OUString& rPassword, uno::Sequence< beans::NamedValue >& o_rEncryptionData ) +{ + o_rEncryptionData = implVerifyPassword( rPassword ); + mbValid = ( o_rEncryptionData.getLength() > 0 ); + return mbValid ? ::comphelper::DocPasswordVerifierResult_OK : ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; +} + +::comphelper::DocPasswordVerifierResult BiffDecoderBase::verifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) { - mbValid = implVerify( rPassword ); + mbValid = implVerifyEncryptionData( rEncryptionData ); return mbValid ? ::comphelper::DocPasswordVerifierResult_OK : ::comphelper::DocPasswordVerifierResult_WRONG_PASSWORD; } @@ -71,7 +80,6 @@ void BiffDecoderBase::decode( sal_uInt8* pnDestData, const sal_uInt8* pnSrcData, BiffDecoder_XOR::BiffDecoder_XOR( sal_uInt16 nKey, sal_uInt16 nHash ) : maCodec( ::oox::core::BinaryCodec_XOR::CODEC_EXCEL ), - maPassword( 16 ), mnKey( nKey ), mnHash( nHash ) { @@ -80,12 +88,12 @@ BiffDecoder_XOR::BiffDecoder_XOR( sal_uInt16 nKey, sal_uInt16 nHash ) : BiffDecoder_XOR::BiffDecoder_XOR( const BiffDecoder_XOR& rDecoder ) : BiffDecoderBase(), // must be called to prevent compiler warning maCodec( ::oox::core::BinaryCodec_XOR::CODEC_EXCEL ), - maPassword( rDecoder.maPassword ), + maEncryptionData( rDecoder.maEncryptionData ), mnKey( rDecoder.mnKey ), mnHash( rDecoder.mnHash ) { if( isValid() ) - maCodec.initKey( &maPassword.front() ); + maCodec.initCodec( maEncryptionData ); } BiffDecoder_XOR* BiffDecoder_XOR::implClone() @@ -93,24 +101,40 @@ BiffDecoder_XOR* BiffDecoder_XOR::implClone() return new BiffDecoder_XOR( *this ); } -bool BiffDecoder_XOR::implVerify( const OUString& rPassword ) +uno::Sequence< beans::NamedValue > BiffDecoder_XOR::implVerifyPassword( const ::rtl::OUString& rPassword ) { + maEncryptionData.realloc( 0 ); + /* Convert password to a byte string. TODO: this needs some finetuning according to the spec... */ OString aBytePassword = OUStringToOString( rPassword, osl_getThreadTextEncoding() ); sal_Int32 nLen = aBytePassword.getLength(); if( (0 < nLen) && (nLen < 16) ) { - // copy byte string to sal_uInt8 array - maPassword.clear(); - maPassword.resize( 16, 0 ); - memcpy( &maPassword.front(), aBytePassword.getStr(), static_cast< size_t >( nLen ) ); + // init codec + maCodec.initKey( (sal_uInt8*)aBytePassword.getStr() ); + if ( maCodec.verifyKey( mnKey, mnHash ) ) + maEncryptionData = maCodec.getEncryptionData(); + } + + return maEncryptionData; +} + +bool BiffDecoder_XOR::implVerifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) +{ + maEncryptionData.realloc( 0 ); + + if( rEncryptionData.getLength() ) + { // init codec - maCodec.initKey( &maPassword.front() ); - return maCodec.verifyKey( mnKey, mnHash ); + maCodec.initCodec( rEncryptionData ); + + if ( maCodec.verifyKey( mnKey, mnHash ) ) + maEncryptionData = rEncryptionData; } - return false; + + return maEncryptionData.getLength(); } void BiffDecoder_XOR::implDecode( sal_uInt8* pnDestData, const sal_uInt8* pnSrcData, sal_Int64 nStreamPos, sal_uInt16 nBytes ) @@ -141,7 +165,6 @@ sal_Int32 lclGetRcfOffset( sal_Int64 nStreamPos ) // ---------------------------------------------------------------------------- BiffDecoder_RCF::BiffDecoder_RCF( sal_uInt8 pnSalt[ 16 ], sal_uInt8 pnVerifier[ 16 ], sal_uInt8 pnVerifierHash[ 16 ] ) : - maPassword( 16, 0 ), maSalt( pnSalt, pnSalt + 16 ), maVerifier( pnVerifier, pnVerifier + 16 ), maVerifierHash( pnVerifierHash, pnVerifierHash + 16 ) @@ -150,13 +173,13 @@ BiffDecoder_RCF::BiffDecoder_RCF( sal_uInt8 pnSalt[ 16 ], sal_uInt8 pnVerifier[ BiffDecoder_RCF::BiffDecoder_RCF( const BiffDecoder_RCF& rDecoder ) : BiffDecoderBase(), // must be called to prevent compiler warning - maPassword( rDecoder.maPassword ), + maEncryptionData( rDecoder.maEncryptionData ), maSalt( rDecoder.maSalt ), maVerifier( rDecoder.maVerifier ), maVerifierHash( rDecoder.maVerifierHash ) { if( isValid() ) - maCodec.initKey( &maPassword.front(), &maSalt.front() ); + maCodec.initCodec( maEncryptionData ); } BiffDecoder_RCF* BiffDecoder_RCF::implClone() @@ -164,27 +187,48 @@ BiffDecoder_RCF* BiffDecoder_RCF::implClone() return new BiffDecoder_RCF( *this ); } -bool BiffDecoder_RCF::implVerify( const OUString& rPassword ) +uno::Sequence< beans::NamedValue > BiffDecoder_RCF::implVerifyPassword( const ::rtl::OUString& rPassword ) { + maEncryptionData.realloc( 0 ); + sal_Int32 nLen = rPassword.getLength(); if( (0 < nLen) && (nLen < 16) ) { // copy string to sal_uInt16 array - maPassword.clear(); - maPassword.resize( 16, 0 ); + ::std::vector< sal_uInt16 > aPassVect( 16 ); const sal_Unicode* pcChar = rPassword.getStr(); const sal_Unicode* pcCharEnd = pcChar + nLen; - ::std::vector< sal_uInt16 >::iterator aIt = maPassword.begin(); + ::std::vector< sal_uInt16 >::iterator aIt = aPassVect.begin(); for( ; pcChar < pcCharEnd; ++pcChar, ++aIt ) *aIt = static_cast< sal_uInt16 >( *pcChar ); // init codec - maCodec.initKey( &maPassword.front(), &maSalt.front() ); - return maCodec.verifyKey( &maVerifier.front(), &maVerifierHash.front() ); + maCodec.initKey( &aPassVect.front(), &maSalt.front() ); + if ( maCodec.verifyKey( &maVerifier.front(), &maVerifierHash.front() ) ) + maEncryptionData = maCodec.getEncryptionData(); + } + + return maEncryptionData; +} + +bool BiffDecoder_RCF::implVerifyEncryptionData( const uno::Sequence< beans::NamedValue >& rEncryptionData ) +{ + maEncryptionData.realloc( 0 ); + + if( rEncryptionData.getLength() ) + { + // init codec + maCodec.initCodec( rEncryptionData ); + + if ( maCodec.verifyKey( &maVerifier.front(), &maVerifierHash.front() ) ) + maEncryptionData = rEncryptionData; } - return false; + + return maEncryptionData.getLength(); } + + void BiffDecoder_RCF::implDecode( sal_uInt8* pnDestData, const sal_uInt8* pnSrcData, sal_Int64 nStreamPos, sal_uInt16 nBytes ) { sal_uInt8* pnCurrDest = pnDestData; @@ -316,7 +360,7 @@ bool BiffCodecHelper::importFilePass( BiffInputStream& rStrm ) mxDecoder = implReadFilePass( rStrm, getBiff() ); // request and verify a password (decoder implements IDocPasswordVerifier) if( mxDecoder.get() ) - getBaseFilter().requestPassword( *mxDecoder ); + getBaseFilter().requestEncryptionData( *mxDecoder ); // correct password is indicated by isValid() function of decoder return mxDecoder.get() && mxDecoder->isValid(); } diff --git a/oox/source/xls/excelvbaproject.cxx b/oox/source/xls/excelvbaproject.cxx new file mode 100755 index 000000000000..ee22dc8398ba --- /dev/null +++ b/oox/source/xls/excelvbaproject.cxx @@ -0,0 +1,161 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "oox/xls/excelvbaproject.hxx" + +#include <list> +#include <set> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/script/ModuleType.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <rtl/ustrbuf.hxx> +#include "oox/helper/helper.hxx" +#include "oox/helper/propertyset.hxx" +#include "properties.hxx" + +namespace oox { +namespace xls { + +// ============================================================================ + +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::script; +using namespace ::com::sun::star::sheet; +using namespace ::com::sun::star::uno; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +// ============================================================================ + +ExcelVbaProject::ExcelVbaProject( const Reference< XMultiServiceFactory >& rxGlobalFactory, const Reference< XSpreadsheetDocument >& rxDocument ) : + ::oox::ole::VbaProject( rxGlobalFactory, Reference< XModel >( rxDocument, UNO_QUERY ), CREATE_OUSTRING( "Calc" ) ), + mxDocument( rxDocument ) +{ +} + +void ExcelVbaProject::createMissingModules() +{ + /* !! HACK !! This function is called from old XLS filter only, must be + removed when this filter uses the OOX VBA import instead of the old SVX + VBA import. + */ + + // collect and register all sheets without codenames + prepareImport(); + // manually create the registered dummy modules + createDummyModules(); +} + +// protected ------------------------------------------------------------------ + +namespace { + +struct SheetCodeNameInfo +{ + PropertySet maSheetProps; /// Property set of the sheet without codename. + OUString maPrefix; /// Prefix for the codename to be generated. + + inline explicit SheetCodeNameInfo( PropertySet& rSheetProps, const OUString& rPrefix ) : + maSheetProps( rSheetProps ), maPrefix( rPrefix ) {} +}; + +typedef ::std::set< OUString > CodeNameSet; +typedef ::std::list< SheetCodeNameInfo > SheetCodeNameInfoList; + +} // namespace + +void ExcelVbaProject::prepareImport() +{ + /* Check if the sheets have imported codenames. Generate new unused + codenames if not. */ + if( mxDocument.is() ) try + { + // collect existing codenames (do not use them when creating new codenames) + CodeNameSet aUsedCodeNames; + + // collect sheets without codenames + SheetCodeNameInfoList aCodeNameInfos; + + // iterate over all imported sheets + Reference< XEnumerationAccess > xSheetsEA( mxDocument->getSheets(), UNO_QUERY_THROW ); + Reference< XEnumeration > xSheetsEnum( xSheetsEA->createEnumeration(), UNO_SET_THROW ); + // own try/catch for every sheet + while( xSheetsEnum->hasMoreElements() ) try + { + PropertySet aSheetProp( xSheetsEnum->nextElement() ); + OUString aCodeName; + aSheetProp.getProperty( aCodeName, PROP_CodeName ); + if( aCodeName.getLength() > 0 ) + { + aUsedCodeNames.insert( aCodeName ); + } + else + { + // TODO: once we have chart sheets we need a switch/case on sheet type ('SheetNNN' vs. 'ChartNNN') + aCodeNameInfos.push_back( SheetCodeNameInfo( aSheetProp, CREATE_OUSTRING( "Sheet" ) ) ); + } + } + catch( Exception& ) + { + } + + // create new codenames if sheets do not have one + for( SheetCodeNameInfoList::iterator aIt = aCodeNameInfos.begin(), aEnd = aCodeNameInfos.end(); aIt != aEnd; ++aIt ) + { + // search for an unused codename + sal_Int32 nCounter = 1; + OUString aCodeName; + do + { + aCodeName = OUStringBuffer( aIt->maPrefix ).append( nCounter++ ).makeStringAndClear(); + } + while( aUsedCodeNames.count( aCodeName ) > 0 ); + aUsedCodeNames.insert( aCodeName ); + + // set codename at sheet + aIt->maSheetProps.setProperty( PROP_CodeName, aCodeName ); + + // tell base class to create a dummy module + addDummyModule( aCodeName, ModuleType::DOCUMENT ); + } + } + catch( Exception& ) + { + } +} + +// ============================================================================ + +} // namespace xls +} // namespace oox diff --git a/oox/source/xls/makefile.mk b/oox/source/xls/makefile.mk index cdb2e18c262d..b5ede953bbfe 100644 --- a/oox/source/xls/makefile.mk +++ b/oox/source/xls/makefile.mk @@ -59,6 +59,7 @@ SLOFILES = \ $(SLO)$/excelchartconverter.obj \ $(SLO)$/excelfilter.obj \ $(SLO)$/excelhandlers.obj \ + $(SLO)$/excelvbaproject.obj \ $(SLO)$/externallinkbuffer.obj \ $(SLO)$/externallinkfragment.obj \ $(SLO)$/formulabase.obj \ diff --git a/oox/source/xls/workbookhelper.cxx b/oox/source/xls/workbookhelper.cxx index 5684fbd8ae75..ceba5690004c 100644 --- a/oox/source/xls/workbookhelper.cxx +++ b/oox/source/xls/workbookhelper.cxx @@ -43,7 +43,6 @@ #include "properties.hxx" #include "oox/helper/progressbar.hxx" #include "oox/helper/propertyset.hxx" -#include "oox/ole/vbaproject.hxx" #include "oox/drawingml/theme.hxx" #include "oox/xls/addressconverter.hxx" #include "oox/xls/biffinputstream.hxx" @@ -51,6 +50,7 @@ #include "oox/xls/defnamesbuffer.hxx" #include "oox/xls/excelchartconverter.hxx" #include "oox/xls/excelfilter.hxx" +#include "oox/xls/excelvbaproject.hxx" #include "oox/xls/externallinkbuffer.hxx" #include "oox/xls/formulaparser.hxx" #include "oox/xls/pagesettings.hxx" @@ -691,7 +691,7 @@ void WorkbookHelper::finalizeWorkbookImport() StorageRef xVbaPrjStrg = mrBookData.getVbaProjectStorage(); if( xVbaPrjStrg.get() && xVbaPrjStrg->isStorage() ) { - ::oox::ole::VbaProject aVbaProject( getGlobalFactory(), getBaseFilter().getModel(), CREATE_OUSTRING( "Calc" ) ); + ExcelVbaProject aVbaProject( getGlobalFactory(), getDocument() ); aVbaProject.importVbaProject( *xVbaPrjStrg, getBaseFilter().getGraphicHelper() ); } } diff --git a/oox/source/xls/worksheethelper.cxx b/oox/source/xls/worksheethelper.cxx index 99c2d844f4b5..d2d42f2be369 100644 --- a/oox/source/xls/worksheethelper.cxx +++ b/oox/source/xls/worksheethelper.cxx @@ -404,7 +404,7 @@ public: Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const; /** Returns the address of the cell that contains the passed point in 1/100 mm. */ - CellAddress getCellAddressFromPosition( const Point& rPosition, const CellAddress* pStartAddr = 0 ) const; + CellAddress getCellAddressFromPosition( const Point& rPosition, const Size& rDrawPageSize ) const; /** Returns the cell range address that contains the passed rectangle in 1/100 mm. */ CellRangeAddress getCellRangeFromRectangle( const Rectangle& rRect ) const; @@ -795,41 +795,117 @@ Size WorksheetData::getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const return aSize; } -CellAddress WorksheetData::getCellAddressFromPosition( const Point& rPosition, const CellAddress* pStartAddr ) const +namespace { + +inline sal_Int32 lclGetMidAddr( sal_Int32 nBegAddr, sal_Int32 nEndAddr, sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos ) +{ + // use sal_Int64 to prevent integer overflow + return nBegAddr + 1 + static_cast< sal_Int32 >( static_cast< sal_Int64 >( nEndAddr - nBegAddr - 2 ) * (nSearchPos - nBegPos) / (nEndPos - nBegPos) ); +} + +bool lclPrepareInterval( sal_Int32 nBegAddr, sal_Int32& rnMidAddr, sal_Int32 nEndAddr, + sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos ) { - // prepare start address for search loop - sal_Int32 nCol = pStartAddr ? ::std::min< sal_Int32 >( pStartAddr->Column + 1, mrMaxApiPos.Column ) : 1; - sal_Int32 nRow = pStartAddr ? ::std::min< sal_Int32 >( pStartAddr->Row + 1, mrMaxApiPos.Row ) : 1; + // searched position before nBegPos -> use nBegAddr + if( nSearchPos <= nBegPos ) + { + rnMidAddr = nBegAddr; + return false; + } + + // searched position after nEndPos, or begin next to end -> use nEndAddr + if( (nSearchPos >= nEndPos) || (nBegAddr + 1 >= nEndAddr) ) + { + rnMidAddr = nEndAddr; + return false; + } + + /* Otherwise find mid address according to position. lclGetMidAddr() will + return an address between nBegAddr and nEndAddr. */ + rnMidAddr = lclGetMidAddr( nBegAddr, nEndAddr, nBegPos, nEndPos, nSearchPos ); + return true; +} + +bool lclUpdateInterval( sal_Int32& rnBegAddr, sal_Int32& rnMidAddr, sal_Int32& rnEndAddr, + sal_Int32& rnBegPos, sal_Int32 nMidPos, sal_Int32& rnEndPos, sal_Int32 nSearchPos ) +{ + // nSearchPos < nMidPos: use the interval [begin,mid] in the next iteration + if( nSearchPos < nMidPos ) + { + // if rnBegAddr is next to rnMidAddr, the latter is the column/row in question + if( rnBegAddr + 1 >= rnMidAddr ) + return false; + // otherwise, set interval end to mid + rnEndPos = nMidPos; + rnEndAddr = rnMidAddr; + rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos ); + return true; + } + + // nSearchPos > nMidPos: use the interval [mid,end] in the next iteration + if( nSearchPos > nMidPos ) + { + // if rnMidAddr is next to rnEndAddr, the latter is the column/row in question + if( rnMidAddr + 1 >= rnEndAddr ) + { + rnMidAddr = rnEndAddr; + return false; + } + // otherwise, set interval start to mid + rnBegPos = nMidPos; + rnBegAddr = rnMidAddr; + rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos ); + return true; + } + + // nSearchPos == nMidPos: rnMidAddr is the column/row in question, do not loop anymore + return false; +} + +} // namespace + +CellAddress WorksheetData::getCellAddressFromPosition( const Point& rPosition, const Size& rDrawPageSize ) const +{ + // starting cell address and its position in drawing layer (top-left edge) + sal_Int32 nBegCol = 0; + sal_Int32 nBegRow = 0; + Point aBegPos( 0, 0 ); + + // end cell address and its position in drawing layer (bottom-right edge) + sal_Int32 nEndCol = mrMaxApiPos.Column + 1; + sal_Int32 nEndRow = mrMaxApiPos.Row + 1; + Point aEndPos( rDrawPageSize.Width, rDrawPageSize.Height ); + + // starting point for interval search + sal_Int32 nMidCol, nMidRow; + bool bLoopCols = lclPrepareInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aEndPos.X, rPosition.X ); + bool bLoopRows = lclPrepareInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aEndPos.Y, rPosition.Y ); + Point aMidPos = getCellPosition( nMidCol, nMidRow ); /* The loop will find the column/row index of the cell right of/below the cell containing the passed point, unless the point is located at the top or left border of the containing cell. */ - bool bNextCol = true; - bool bNextRow = true; - Point aCellPos; - do + while( bLoopCols || bLoopRows ) { - aCellPos = getCellPosition( nCol, nRow ); - if( bNextCol && ((bNextCol = (aCellPos.X < rPosition.X) && (nCol < mrMaxApiPos.Column)) == true) ) - ++nCol; - if( bNextRow && ((bNextRow = (aCellPos.Y < rPosition.Y) && (nRow < mrMaxApiPos.Row)) == true) ) - ++nRow; + bLoopCols = bLoopCols && lclUpdateInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aMidPos.X, aEndPos.X, rPosition.X ); + bLoopRows = bLoopRows && lclUpdateInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aMidPos.Y, aEndPos.Y, rPosition.Y ); + aMidPos = getCellPosition( nMidCol, nMidRow ); } - while( bNextCol || bNextRow ); /* The cell left of/above the current search position contains the passed point, unless the point is located on the top/left border of the cell, or the last column/row of the sheet has been reached. */ - if( aCellPos.X > rPosition.X ) --nCol; - if( aCellPos.Y > rPosition.Y ) --nRow; - return CellAddress( getSheetIndex(), nCol, nRow ); + if( aMidPos.X > rPosition.X ) --nMidCol; + if( aMidPos.Y > rPosition.Y ) --nMidRow; + return CellAddress( getSheetIndex(), nMidCol, nMidRow ); } CellRangeAddress WorksheetData::getCellRangeFromRectangle( const Rectangle& rRect ) const { - CellAddress aStartAddr = getCellAddressFromPosition( Point( rRect.X, rRect.Y ) ); + Size aPageSize = getDrawPageSize(); + CellAddress aStartAddr = getCellAddressFromPosition( Point( rRect.X, rRect.Y ), aPageSize ); Point aBotRight( rRect.X + rRect.Width, rRect.Y + rRect.Height ); - CellAddress aEndAddr = getCellAddressFromPosition( aBotRight ); + CellAddress aEndAddr = getCellAddressFromPosition( aBotRight, aPageSize ); bool bMultiCols = aStartAddr.Column < aEndAddr.Column; bool bMultiRows = aStartAddr.Row < aEndAddr.Row; if( bMultiCols || bMultiRows ) @@ -945,17 +1021,25 @@ void WorksheetData::extendUsedArea( const CellRangeAddress& rRange ) void WorksheetData::extendShapeBoundingBox( const Rectangle& rShapeRect ) { + // scale EMUs to 1/100 mm + const UnitConverter& rUnitConv = getUnitConverter(); + Rectangle aShapeRectHmm( + rUnitConv.scaleToMm100( rShapeRect.X, UNIT_EMU ), + rUnitConv.scaleToMm100( rShapeRect.Y, UNIT_EMU ), + rUnitConv.scaleToMm100( rShapeRect.Width, UNIT_EMU ), + rUnitConv.scaleToMm100( rShapeRect.Height, UNIT_EMU ) ); + if( (maShapeBoundingBox.Width == 0) && (maShapeBoundingBox.Height == 0) ) { // width and height of maShapeBoundingBox are assumed to be zero on first cell - maShapeBoundingBox = rShapeRect; + maShapeBoundingBox = aShapeRectHmm; } else { - sal_Int32 nEndX = ::std::max( maShapeBoundingBox.X + maShapeBoundingBox.Width, rShapeRect.X + rShapeRect.Width ); - sal_Int32 nEndY = ::std::max( maShapeBoundingBox.Y + maShapeBoundingBox.Height, rShapeRect.Y + rShapeRect.Height ); - maShapeBoundingBox.X = ::std::min( maShapeBoundingBox.X, rShapeRect.X ); - maShapeBoundingBox.Y = ::std::min( maShapeBoundingBox.Y, rShapeRect.Y ); + sal_Int32 nEndX = ::std::max( maShapeBoundingBox.X + maShapeBoundingBox.Width, aShapeRectHmm.X + aShapeRectHmm.Width ); + sal_Int32 nEndY = ::std::max( maShapeBoundingBox.Y + maShapeBoundingBox.Height, aShapeRectHmm.Y + aShapeRectHmm.Height ); + maShapeBoundingBox.X = ::std::min( maShapeBoundingBox.X, aShapeRectHmm.X ); + maShapeBoundingBox.Y = ::std::min( maShapeBoundingBox.Y, aShapeRectHmm.Y ); maShapeBoundingBox.Width = nEndX - maShapeBoundingBox.X; maShapeBoundingBox.Height = nEndY - maShapeBoundingBox.Y; } |