[Libreoffice-commits] core.git: Branch 'feature/gsoc-impresslayout' - officecfg/registry sd/inc sd/source sd/xml

Thorsten Behrens tbehrens at suse.com
Fri Aug 23 16:25:10 PDT 2013


 officecfg/registry/schema/org/openoffice/Office/Impress.xcs |   12 -
 sd/inc/drawdoc.hxx                                          |    8 
 sd/source/core/drawdoc.cxx                                  |   89 ++++-----
 sd/source/core/sdpage.cxx                                   |  110 ++++--------
 sd/xml/layoutlist.xml                                       |    9 
 5 files changed, 95 insertions(+), 133 deletions(-)

New commits:
commit 58050b870ee31d1790c930c80ecf9968701bfffc
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Sat Aug 24 01:23:36 2013 +0200

    Some cleanup and consolidation of the Impress layout work.
    
    Change-Id: I13eae20141650e1d1d826a794d1f19baaef5f561

diff --git a/officecfg/registry/schema/org/openoffice/Office/Impress.xcs b/officecfg/registry/schema/org/openoffice/Office/Impress.xcs
index 61c7cab1..6a17f53 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Impress.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Impress.xcs
@@ -472,13 +472,13 @@
       <prop oor:name="LayoutListFiles" oor:type="oor:string-list" oor:nillable="false">
         <info>
           <desc>
-            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.
           </desc>
-          <label>List of files containing list of layouts</label>
+          <label>List of files containing Impress slide layouts</label>
         </info>
         <value oor:separator=";">vnd.sun.star.expand:$BRAND_BASE_DIR/share/config/soffice.cfg/simpress/layoutlist.xml</value>
       </prop>
diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index 2320885..e2b058c 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -259,8 +259,12 @@ public:
 
     bool IsStartWithPresentation() const;
     void SetStartWithPresentation( bool bStartWithPresentation );
-    void SetLayoutVector();
-    std::vector<com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode>> &GetLayoutVector() { return maLayoutInfo; }
+
+    /// load xml-based impress layout definitions into document
+    void InitLayoutVector();
+    /// return reference to vector of Impress layout definitions
+    const std::vector<com::sun::star::uno::Reference<com::sun::star::xml::dom::XNode>>& GetLayoutVector() const { return maLayoutInfo; }
+
     /** Insert pages into this document
 
         This method inserts whole pages into this document, either
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index f7515be..49588b2 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -30,6 +30,7 @@
 #include <editeng/scriptspaceitem.hxx>
 
 #include <unotools/useroptions.hxx>
+#include <officecfg/Office/Impress.hxx>
 
 #include <sfx2/printer.hxx>
 #include <sfx2/app.hxx>
@@ -72,9 +73,6 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/io/XInputStream.hpp>
 #include <com/sun/star/util/theMacroExpander.hpp>
-#include <com/sun/star/container/XNameAccess.hpp>
-#include <com/sun/star/configuration/theDefaultProvider.hpp>
-#include <com/sun/star/beans/PropertyValue.hpp>
 #include <rtl/ustring.hxx>
 #include <rtl/uri.hxx>
 #include <osl/file.h>
@@ -192,7 +190,7 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh)
     mpMasterPageListWatcher = ::std::auto_ptr<ImpMasterPageListWatcher>(
         new ImpMasterPageListWatcher(*this));
 
-    SetLayoutVector();
+    InitLayoutVector();
     SetObjectShell(pDrDocSh);       // for VCDrawModel
 
     if (mpDocSh)
@@ -1002,66 +1000,53 @@ sal_uInt16 SdDrawDocument::GetAnnotationAuthorIndex( const OUString& rAuthor )
     return idx;
 }
 
-// to get the root element of the xml file
-Reference<XElement> getRoot()
+void SdDrawDocument::InitLayoutVector()
 {
-    const Reference<css::uno::XComponentContext> 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<container::XNameAccess> xNameAccess(
-        xConfigProvider->createInstanceWithArguments(
-            "com.sun.star.configuration.ConfigurationAccess",
-            Sequence<Any>( &propValue, 1 ) ), UNO_QUERY_THROW );
-
-    Sequence< rtl::OUString > aFiles;
-    xNameAccess->getByName( "LayoutListFiles" ) >>= aFiles;
-    rtl::OUString aURL;
+    const Reference<css::uno::XComponentContext> 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<XDocumentBuilder> xDocBuilder( DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) ));
-    const Reference<XDocument> xDoc = xDocBuilder->parseURI( aURL );
-    const Reference<XElement> 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<XElement> root = getRoot();                     //get the root element of my xml file
-    const Reference<XNodeList> layoutlist = root->getElementsByTagName("layout");
-    layoutlistsize=layoutlist->getLength();
-    for(int index=0; index < layoutlistsize; index++)
-    {
-        Reference<XNode> 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<XDocumentBuilder> xDocBuilder(
+            DocumentBuilder::create( comphelper::getComponentContext (xServiceFactory) ));
+
+        // loop over every layout entry in current file
+        const Reference<XDocument> xDoc = xDocBuilder->parseURI( aFilename );
+        const Reference<XNodeList> 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 9fd6b68..244c375 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -48,25 +48,11 @@
 #include <editeng/flditem.hxx>
 #include <svx/sdr/contact/displayinfo.hxx>
 #include <svx/svditer.hxx>
-#include <com/sun/star/xml/dom/XDocumentBuilder.hpp>
-#include <com/sun/star/xml/dom/XDocument.hpp>
 #include <com/sun/star/xml/dom/XNode.hpp>
 #include <com/sun/star/xml/dom/XNodeList.hpp>
 #include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
-#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
 #include <rtl/ustring.hxx>
-#include <comphelper/processfactory.hxx>
-#include <com/sun/star/uno/XComponentContext.hpp>
-#include <com/sun/star/io/XInputStream.hpp>
-#include <com/sun/star/util/theMacroExpander.hpp>
-#include <com/sun/star/container/XNameAccess.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/configuration/theDefaultProvider.hpp>
-#include <com/sun/star/beans/PropertyValue.hpp>
-#include <unotools/streamwrap.hxx>
-#include <rtl/uri.hxx>
-#include <unotools/ucbstreamhelper.hxx>
-#include <osl/file.h>
+#include <basegfx/tools/tools.hxx>
 
 #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<Reference<XNode>>  &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<XNode> >& layoutInfo = static_cast<const SdDrawDocument*>(rPage.GetModel())->GetLayoutVector();
+    for( std::vector< Reference<XNode> >::const_iterator aIter=layoutInfo.begin(); aIter != layoutInfo.end(); ++aIter )
     {
-        Reference<XNode> layoutnode = layoutinfo[y];      //get i'th layout element
-        Reference<XNamedNodeMap> layoutattrlist =layoutnode->getAttributes();
-        Reference<XNode> layoutattr = layoutattrlist->getNamedItem("type");
-        sLayoutAttName=layoutattr->getNodeValue();              //get the attribute value of layout(i.e it's type)
-        rtl::OUString sLayoutType = autolayout;
+        Reference<XNode> layoutNode = *aIter;
+        Reference<XNamedNodeMap> 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<XNodeList> layoutchildrens = layoutnode->getChildNodes();
-            presobjsize = layoutchildrens->getLength();         //get the length of that of the layout(number of pres objects)
+            Reference<XNodeList> 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<XNode> presobj = layoutchildrens->item(j);    //get the j'th presobj for that layout
+                Reference<XNode> 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<XNamedNodeMap> 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 d7338ad..c5f8d5e 100644
--- a/sd/xml/layoutlist.xml
+++ b/sd/xml/layoutlist.xml
@@ -1,5 +1,10 @@
 <?xml version="1.0"?>
-<!-- At present I am not sure about corect XML namespace,so once I am aware of it.I am ready to add it.
+<!-- Configurable definitions of Impress slide layouts.
+
+     Currently the layout type name needs to match a set of predefined strings.
+     Per entry, you can declare up to one Title object, and up to four
+     Outline objects. All values are relative to Impress' 'layout
+     rect', which is roughly 90% of the available slide area.
 -->
 <layout-list>
     <layout type="AUTOLAYOUT_TITLE_CONTENT">
@@ -78,4 +83,4 @@
         <presobj kind="PRESOBJ_OUTLINE1" relative-height="1" relative-width="0.488" relative-posX="0" relative-posY="0"/>
         <presobj kind="PRESOBJ_OUTLINE2" relative-height="1" relative-width="0.488" relative-posX="1.05" relative-posY="0"/>
     </layout>
-</layout-list>
\ No newline at end of file
+</layout-list>


More information about the Libreoffice-commits mailing list