Kaydet (Commit) 1eecb8df authored tarafından Thorsten Behrens's avatar Thorsten Behrens

Some cleanup and consolidation of the Impress layout work.

Also make unit test work again after Mac-app like path changes.

Change-Id: I13eae20141650e1d1d826a794d1f19baaef5f561
üst f78db7cb
......@@ -472,15 +472,15 @@
<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>
<value oor:separator=";">vnd.sun.star.expand:$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/config/soffice.cfg/simpress/layoutlist.xml</value>
</prop>
<prop oor:name="PreviewNewEffects" oor:type="xs:boolean" oor:nillable="false">
<!-- OldPath: -->
......
......@@ -264,8 +264,10 @@ public:
bool IsExitAfterPresenting() const;
void SetExitAfterPresenting( bool bExitAfterPresenting );
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
......
......@@ -29,6 +29,7 @@
#include <editeng/scriptspaceitem.hxx>
#include <unotools/useroptions.hxx>
#include <officecfg/Office/Impress.hxx>
#include <sfx2/printer.hxx>
#include <sfx2/app.hxx>
......@@ -71,9 +72,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)
......@@ -1012,66 +1010,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: */
......@@ -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 );
......
<?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>
......@@ -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))") \
......
......@@ -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))
......
<?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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment