From 1eecb8df22b77a6982601bf877067a685d913a7d Mon Sep 17 00:00:00 2001 From: Thorsten Behrens Date: Sat, 24 Aug 2013 01:23:36 +0200 Subject: Some cleanup and consolidation of the Impress layout work. Also make unit test work again after Mac-app like path changes. Change-Id: I13eae20141650e1d1d826a794d1f19baaef5f561 --- .../schema/org/openoffice/Office/Impress.xcs | 14 +-- sd/inc/drawdoc.hxx | 6 +- sd/source/core/drawdoc.cxx | 89 +++++++---------- sd/source/core/sdpage.cxx | 110 ++++++++------------- sd/xml/layoutlist.xml | 9 +- solenv/gbuild/CppunitTest.mk | 1 + test/Package_unittest.mk | 2 +- .../config/soffice.cfg/simpress/layoutlist.xml | 9 +- 8 files changed, 103 insertions(+), 137 deletions(-) diff --git a/officecfg/registry/schema/org/openoffice/Office/Impress.xcs b/officecfg/registry/schema/org/openoffice/Office/Impress.xcs index efeb62734b73..c971846a8ff2 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Impress.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Impress.xcs @@ -472,15 +472,15 @@ - Contains a list of layout type.It contains - properties of presobj like their Position, - Height and Width.Values are put through - macro expansion, so, vnd.sun.star.expand prefix - is allowed. + Contains a list of xml files defining the Impress slide + "layouts". It contains properties of presentation objects, + like their position, width, and height. Entries are run + through macro expansion, so, vnd.sun.star.expand prefix is + allowed. - + - vnd.sun.star.expand:$BRAND_BASE_DIR/share/config/soffice.cfg/simpress/layoutlist.xml + vnd.sun.star.expand:$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/config/soffice.cfg/simpress/layoutlist.xml diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index 88d11c92793d..6ef4c27ab0c9 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -264,8 +264,10 @@ public: bool IsExitAfterPresenting() const; void SetExitAfterPresenting( bool bExitAfterPresenting ); - void SetLayoutVector(); - std::vector> &GetLayoutVector() { return maLayoutInfo; } + /// load xml-based impress layout definitions into document + void InitLayoutVector(); + /// return reference to vector of Impress layout definitions + const std::vector>& GetLayoutVector() const { return maLayoutInfo; } /** Insert pages into this document diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx index a4089cbf91d5..2295c97d07b6 100644 --- a/sd/source/core/drawdoc.cxx +++ b/sd/source/core/drawdoc.cxx @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -71,9 +72,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -192,7 +190,7 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh) mpMasterPageListWatcher = ::std::auto_ptr( new ImpMasterPageListWatcher(*this)); - SetLayoutVector(); + InitLayoutVector(); SetObjectShell(pDrDocSh); // for VCDrawModel if (mpDocSh) @@ -1012,66 +1010,53 @@ sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const OUString& rAuthor ) return idx; } -// to get the root element of the xml file -Reference getRoot() +void SdDrawDocument::InitLayoutVector() { - const Reference xContext( ::comphelper::getProcessComponentContext() ); - Reference< XMultiServiceFactory > xServiceFactory( xContext->getServiceManager() , UNO_QUERY_THROW ); - Reference< util::XMacroExpander > xMacroExpander = util::theMacroExpander::get( xContext ); - Reference< XMultiServiceFactory > xConfigProvider = configuration::theDefaultProvider::get( xContext ); - - Any propValue = uno::makeAny( - beans::PropertyValue( - "nodepath", -1, - uno::makeAny( OUString( "/org.openoffice.Office.Impress/Misc" )), - beans::PropertyState_DIRECT_VALUE ) ); - - Reference xNameAccess( - xConfigProvider->createInstanceWithArguments( - "com.sun.star.configuration.ConfigurationAccess", - Sequence( &propValue, 1 ) ), UNO_QUERY_THROW ); - - Sequence< rtl::OUString > aFiles; - xNameAccess->getByName( "LayoutListFiles" ) >>= aFiles; - rtl::OUString aURL; + const Reference xContext( + ::comphelper::getProcessComponentContext() ); + Reference< util::XMacroExpander > xMacroExpander( + util::theMacroExpander::get( xContext ) ); + // get file list from configuration + Sequence< rtl::OUString > aFiles( + officecfg::Office::Impress::Misc::LayoutListFiles::get(xContext) ); + + // loop over each file in sequence + rtl::OUString aFilename; for( sal_Int32 i=0; i < aFiles.getLength(); ++i ) { - aURL = aFiles[i]; - if( aURL.startsWith( "vnd.sun.star.expand:" ) ) + aFilename = aFiles[i]; + if( aFilename.startsWith( "vnd.sun.star.expand:" ) ) { // cut protocol - rtl::OUString aMacro( aURL.copy( sizeof ( "vnd.sun.star.expand:" ) -1 ) ); + rtl::OUString aMacro( aFilename.copy( sizeof ( "vnd.sun.star.expand:" ) -1 ) ); + // decode uric class chars aMacro = rtl::Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); + // expand macro string - aURL = xMacroExpander->expandMacros( aMacro ); + aFilename = xMacroExpander->expandMacros( aMacro ); } - } - - if( aURL.startsWith( "file://" ) ) - { - rtl::OUString aSysPath; - if( osl_getSystemPathFromFileURL( aURL.pData, &aSysPath.pData ) == osl_File_E_None ) - aURL = aSysPath; - } - const Reference xDocBuilder( DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) )); - const Reference xDoc = xDocBuilder->parseURI( aURL ); - const Reference xRoot = xDoc->getDocumentElement(); - return xRoot; //this loops seems to work only once,so returning the root element -} + if( aFilename.startsWith( "file://" ) ) + { + rtl::OUString aSysPath; + if( osl_getSystemPathFromFileURL( aFilename.pData, &aSysPath.pData ) == osl_File_E_None ) + aFilename = aSysPath; + } -void SdDrawDocument::SetLayoutVector() -{ - int layoutlistsize; - const Reference root = getRoot(); //get the root element of my xml file - const Reference layoutlist = root->getElementsByTagName("layout"); - layoutlistsize=layoutlist->getLength(); - for(int index=0; index < layoutlistsize; index++) - { - Reference layoutnode = layoutlist->item(index); //get i'th layout element - maLayoutInfo.push_back(layoutnode); + // load layout file into DOM + Reference< XMultiServiceFactory > xServiceFactory( + xContext->getServiceManager() , UNO_QUERY_THROW ); + const Reference xDocBuilder( + DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) )); + + // loop over every layout entry in current file + const Reference xDoc = xDocBuilder->parseURI( aFilename ); + const Reference layoutlist = xDoc->getElementsByTagName("layout"); + const int nElements = layoutlist->getLength(); + for(int index=0; index < nElements; index++) + maLayoutInfo.push_back( layoutlist->item(index) ); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index 64dbefd31363..7be55e1b920c 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -48,25 +48,11 @@ #include #include #include -#include -#include #include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include "../ui/inc/DrawDocShell.hxx" #include "Outliner.hxx" @@ -95,12 +81,6 @@ using namespace ::com::sun::star::uno; using namespace com::sun::star::xml::dom; using ::com::sun::star::uno::Reference; -using ::com::sun::star::io::XInputStream; -using ::com::sun::star::lang::XMultiServiceFactory; -using ::com::sun::star::container::XNameAccess; -using ::com::sun::star::beans::PropertyValue; - - TYPEINIT2( SdPage, FmFormPage, SdrObjUserCall ); /************************************************************************* @@ -1116,7 +1096,6 @@ Rectangle SdPage::GetLayoutRect() const const int MAX_PRESOBJS = 7; // maximum number of presentation objects per layout const int VERTICAL = 0x8000; -const int PRESOBJPROP = 4; struct LayoutDescriptor { @@ -1247,14 +1226,10 @@ rtl::OUString enumtoString(AutoLayout aut) return retstr; } -static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const rtl::OUString& autolayout) +static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const rtl::OUString& sLayoutType ) { Rectangle aTitleRect; Rectangle aLayoutRect; - int presobjsize; - rtl::OUString sLayoutAttName; - rtl::OUString sPresObjKindAttName; - double propvalue[4]; if( rPage.GetPageKind() != PK_HANDOUT ) { @@ -1278,42 +1253,39 @@ static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const } rRectangle[0] = aTitleRect; - - int i; - for( i = 1; i < MAX_PRESOBJS; i++ ) + for( int i = 1; i < MAX_PRESOBJS; i++ ) rRectangle[i] = aLayoutRect; - i=0; - for(i=0; i< PRESOBJPROP; i++) - propvalue[i]=0; - Point aTitlePos( aTitleRect.TopLeft() ); - Size aLayoutSize( aLayoutRect.GetSize() ); - Point aLayoutPos( aLayoutRect.TopLeft() ); - Size aTempSize; - Point aTempPnt; - aTempSize = aLayoutSize; - aTempPnt = aLayoutPos; + const Point aTitlePos( aTitleRect.TopLeft() ); + const Size aLayoutSize( aLayoutRect.GetSize() ); + const Point aLayoutPos( aLayoutRect.TopLeft() ); + double propvalue[] = {0,0,0,0}; - const std::vector> &layoutinfo = static_cast< SdDrawDocument* >( rPage.GetModel() )->GetLayoutVector(); //getting vector from "SdDrawDocument" ,not sure about the correct mechanism - for(size_t y=0; y < layoutinfo.size(); y++) //loop through vector of Xnodes + const std::vector< Reference >& layoutInfo = static_cast(rPage.GetModel())->GetLayoutVector(); + for( std::vector< Reference >::const_iterator aIter=layoutInfo.begin(); aIter != layoutInfo.end(); ++aIter ) { - Reference layoutnode = layoutinfo[y]; //get i'th layout element - Reference layoutattrlist =layoutnode->getAttributes(); - Reference layoutattr = layoutattrlist->getNamedItem("type"); - sLayoutAttName=layoutattr->getNodeValue(); //get the attribute value of layout(i.e it's type) - rtl::OUString sLayoutType = autolayout; + Reference layoutNode = *aIter; + Reference layoutAttrList =layoutNode->getAttributes(); - if(sLayoutAttName==sLayoutType) + // get the attribute value of layout (i.e it's type) + rtl::OUString sLayoutAttName = + layoutAttrList->getNamedItem("type")->getNodeValue(); + if(sLayoutAttName == sLayoutType) { int count=0; - Reference layoutchildrens = layoutnode->getChildNodes(); - presobjsize = layoutchildrens->getLength(); //get the length of that of the layout(number of pres objects) + Reference layoutChildren = layoutNode->getChildNodes(); + const int presobjsize = layoutChildren->getLength(); for( int j=0; j< presobjsize ; j++) { + // TODO: rework sd to permit arbitrary number of presentation objects + OSL_ASSERT(count < MAX_PRESOBJS); + rtl::OUString nodename; - Reference presobj = layoutchildrens->item(j); //get the j'th presobj for that layout + Reference presobj = layoutChildren->item(j); nodename=presobj->getNodeName(); - if(nodename=="presobj")//check whether children is blank 'text-node' or 'presobj' node + + //check whether children is blank 'text-node' or 'presobj' node + if(nodename == "presobj") { Reference presObjAttributes = presobj->getAttributes(); @@ -1333,26 +1305,24 @@ static void CalcAutoLayoutRectangles( SdPage& rPage,Rectangle* rRectangle ,const sValue = presObjPosY->getNodeValue(); propvalue[3] = sValue.toDouble(); - if(count==0) + if(count == 0) { - Size aTitleSize ( aTitleRect.GetSize() ); - aTitleSize.Height() = sal_Int32(aTitleSize.Height() * propvalue[0]); - aTitleSize.Width() = sal_Int32(aTitleSize.Width() * propvalue[1]); - aTitlePos.X() = sal_Int32(aTitlePos.X() +(aTitleSize.Width() * propvalue[2])); - aTitlePos.Y() = sal_Int32(aTitlePos.Y() + (aTitleSize.Height() * propvalue[3])); - rRectangle[count] = Rectangle (aTitlePos, aTitleSize); + Size aSize ( aTitleRect.GetSize() ); + aSize.Height() = basegfx::fround(aSize.Height() * propvalue[0]); + aSize.Width() = basegfx::fround(aSize.Width() * propvalue[1]); + Point aPos( basegfx::fround(aTitlePos.X() +(aSize.Width() * propvalue[2])), + basegfx::fround(aTitlePos.Y() + (aSize.Height() * propvalue[3])) ); + rRectangle[count] = Rectangle(aPos, aSize); count = count+1; } else { - aLayoutSize = aTempSize; //to re-gain fixed layout size - aLayoutPos = aTempPnt; //to re-gain fixed layout pos - aLayoutSize.Height() = sal_Int32(aLayoutSize.Height() * propvalue[0]); - aLayoutSize.Width() = sal_Int32(aLayoutSize.Width() * propvalue[1]); - aLayoutPos.X() = sal_Int32(aLayoutPos.X() +(aLayoutSize.Width() * propvalue[2])); - aLayoutPos.Y() = sal_Int32(aLayoutPos.Y() + (aLayoutSize.Height() * propvalue[3])); - rRectangle[count] = Rectangle (aLayoutPos, aLayoutSize); - count=count+1; + Size aSize( basegfx::fround(aLayoutSize.Width() * propvalue[1]), + basegfx::fround(aLayoutSize.Height() * propvalue[0]) ); + Point aPos( basegfx::fround(aLayoutPos.X() +(aLayoutSize.Width() * propvalue[2])), + basegfx::fround(aLayoutPos.Y() + (aLayoutSize.Height() * propvalue[3])) ); + rRectangle[count] = Rectangle (aPos, aSize); + count = count+1; } } } @@ -1525,7 +1495,6 @@ void findAutoLayoutShapesImpl( SdPage& rPage, const LayoutDescriptor& rDescripto void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate ) { - rtl::OUString autolayout; sd::ScopeLockGuard aGuard( maLockAutoLayoutArrangement ); const bool bSwitchLayout = eLayout != GetAutoLayout(); @@ -1546,12 +1515,11 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, sal_Bool bInit, sal_Bool bCreate Rectangle aRectangle[MAX_PRESOBJS]; const LayoutDescriptor& aDescriptor = GetLayoutDescriptor( meAutoLayout ); - autolayout=enumtoString(meAutoLayout); - CalcAutoLayoutRectangles( *this, aRectangle, autolayout); + rtl::OUString sLayoutName( enumtoString(meAutoLayout) ); + CalcAutoLayoutRectangles( *this, aRectangle, sLayoutName); std::set< SdrObject* > aUsedPresentationObjects; - std::vector< SdrObject* > aLayoutShapes(PRESOBJ_MAX, 0); findAutoLayoutShapesImpl( *this, aDescriptor, aLayoutShapes, bInit, bSwitchLayout ); diff --git a/sd/xml/layoutlist.xml b/sd/xml/layoutlist.xml index d7338ad38ccf..c5f8d5ef3ecf 100644 --- a/sd/xml/layoutlist.xml +++ b/sd/xml/layoutlist.xml @@ -1,5 +1,10 @@ - @@ -78,4 +83,4 @@ - \ No newline at end of file + diff --git a/solenv/gbuild/CppunitTest.mk b/solenv/gbuild/CppunitTest.mk index fb36b1ba4007..48de32881c1d 100644 --- a/solenv/gbuild/CppunitTest.mk +++ b/solenv/gbuild/CppunitTest.mk @@ -53,6 +53,7 @@ gb_CppunitTest__get_linktargetname = CppunitTest/$(call gb_CppunitTest_get_filen define gb_CppunitTest__make_args $(HEADLESS) \ "-env:BRAND_BASE_DIR=$(call gb_Helper_make_url,$(OUTDIR)/unittest/install)" \ +"-env:BRAND_SHARE_SUBDIR=share" \ $(if $(URE),\ $(if $(strip $(CONFIGURATION_LAYERS)),\ "-env:CONFIGURATION_LAYERS=$(strip $(CONFIGURATION_LAYERS))") \ diff --git a/test/Package_unittest.mk b/test/Package_unittest.mk index 1a83b4c27eb9..6edfc9c6ddf6 100644 --- a/test/Package_unittest.mk +++ b/test/Package_unittest.mk @@ -19,7 +19,7 @@ $(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/sta $(eval $(call gb_Package_add_file,test_unittest,unittest/user/autotext/en-US/crdbus50.bau,user/autotext/en-US/crdbus50.bau)) $(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/psetup.xpm,user/config/psetup.xpm)) $(eval $(call gb_Package_add_file,test_unittest,unittest/install/share/config/soffice.cfg/simpress/transitions.xml,user/config/soffice.cfg/simpress/transitions.xml)) -$(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/soffice.cfg/simpress/transitions-ogl.xml,user/config/soffice.cfg/simpress/transitions-ogl.xml)) +$(eval $(call gb_Package_add_file,test_unittest,unittest/install/share/config/soffice.cfg/simpress/transitions-ogl.xml,user/config/soffice.cfg/simpress/transitions-ogl.xml)) $(eval $(call gb_Package_add_file,test_unittest,unittest/install/share/config/soffice.cfg/simpress/effects.xml,user/config/soffice.cfg/simpress/effects.xml)) $(eval $(call gb_Package_add_file,test_unittest,unittest/install/share/config/soffice.cfg/simpress/layoutlist.xml,user/config/soffice.cfg/simpress/layoutlist.xml)) $(eval $(call gb_Package_add_file,test_unittest,unittest/user/config/psetupl.xpm,user/config/psetupl.xpm)) diff --git a/test/user-template/user/config/soffice.cfg/simpress/layoutlist.xml b/test/user-template/user/config/soffice.cfg/simpress/layoutlist.xml index d7338ad38ccf..c5f8d5ef3ecf 100644 --- a/test/user-template/user/config/soffice.cfg/simpress/layoutlist.xml +++ b/test/user-template/user/config/soffice.cfg/simpress/layoutlist.xml @@ -1,5 +1,10 @@ - @@ -78,4 +83,4 @@ - \ No newline at end of file + -- cgit