From 58056cd73efbbda3065692427b69ed926700c9ca Mon Sep 17 00:00:00 2001 From: Vishv Brahmbhatt Date: Tue, 25 Jun 2013 18:59:00 +0530 Subject: Creation of XML parser function Updating the first working version of parser function "readLayoutPropFromFile".And it parses information from XML file for layout "AUTOLAYOUT_TITLE_2VTEXT". Change-Id: I24a52ae8c2b0c18ef806d9723d7eb6a7e43a20ec --- sd/source/core/sdpage.cxx | 101 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 2 deletions(-) diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx index 180bf6b52007..090577432c7f 100644 --- a/sd/source/core/sdpage.cxx +++ b/sd/source/core/sdpage.cxx @@ -48,6 +48,15 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "../ui/inc/DrawDocShell.hxx" #include "Outliner.hxx" @@ -72,6 +81,9 @@ using namespace ::sd; using namespace ::com::sun::star; +using namespace com::sun::star::xml::dom; +using ::com::sun::star::uno::Reference; + TYPEINIT2( SdPage, FmFormPage, SdrObjUserCall ); @@ -1088,6 +1100,7 @@ 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 { @@ -1160,10 +1173,81 @@ static const LayoutDescriptor& GetLayoutDescriptor( AutoLayout eLayout ) return aLayouts[ eLayout - AUTOLAYOUT__START ]; } +//to get the root element of the xml file +Reference getRootElement() +{ + rtl::OUString filepath="/home/vishv/layoutlist.xml"; + const Reference xContext(comphelper_getProcessComponentContext()); + const Reference xDocBuilder(css::xml::dom::DocumentBuilder::create(xContext)); + const Reference xDoc = xDocBuilder->parseURI(filepath); + const Reference xRoot = xDoc->getDocumentElement(); + return xRoot; +} + +//read the information from XML file(traversing from layout node) +void readLayoutPropFromFile(const Reference& root, const rtl::OUString& sLayoutType, const rtl::OUString& sPresObjKind, double propvalue[]) +{ + long presobjsize; + long layoutlistsize; + rtl::OUString sLayoutAttName; + rtl::OUString sPresObjKindAttName; + bool bnoprop=true; //use it to skip the remaining loop ,once propvalue is obtained + const Reference layoutlist = root->getElementsByTagName("layout"); + layoutlistsize=layoutlist->getLength(); + + for( long i=0; i layoutnode = layoutlist->item(i); //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) + + if(sLayoutAttName==sLayoutType)//check string comparision func //compare it with the given parameter of the function + { + Reference layoutchildrens = layoutnode->getChildNodes(); + presobjsize = layoutchildrens->getLength(); //get the length of that of the layout(number of pres objects) + for( long j=0; j< presobjsize ; j++) + { + Reference presobj = layoutchildrens->item(j); //get the j'th presobj for that layout + Reference presObjAttributes = presobj->getAttributes(); + Reference presObjKindAttr = presObjAttributes->getNamedItem("kind"); + sPresObjKindAttName = presObjKindAttr->getNodeValue(); //get the value of it's presobj kind + if(sPresObjKindAttName==sPresObjKind) + { + Reference presObjPosX = presObjAttributes->getNamedItem("layout-pos-x"); + rtl::OUString sValue = presObjPosX->getNodeValue(); + propvalue[0] = sValue.toDouble(); + Reference presObjPosY = presObjAttributes->getNamedItem("layout-pos-y"); + sValue = presObjPosY->getNodeValue(); + propvalue[1] = sValue.toDouble(); + Reference presObjSizeHeight = presObjAttributes->getNamedItem("layout-size-height"); + sValue = presObjSizeHeight->getNodeValue(); + propvalue[2] = sValue.toDouble(); + Reference presObjSizeWidth = presObjAttributes->getNamedItem("layout-size-width"); + sValue = presObjSizeWidth->getNodeValue(); + propvalue[3] = sValue.toDouble(); + bnoprop=false; + break; + } + else + continue; + } + } + else + continue; + } + else + break; + } +} + static void CalcAutoLayoutRectangles( SdPage& rPage, int nLayout, Rectangle* rRectangle ) { Rectangle aTitleRect; Rectangle aLayoutRect; + double propvalue[4]; if( rPage.GetPageKind() != PK_HANDOUT ) { @@ -1191,6 +1275,11 @@ static void CalcAutoLayoutRectangles( SdPage& rPage, int nLayout, Rectangle* rRe int i; for( i = 1; i < MAX_PRESOBJS; i++ ) rRectangle[i] = aLayoutRect; + i=0; + for(i=0; i< PRESOBJPROP; i++) + propvalue[i]=0; + + const Reference root= getRootElement();//get the root element of my xml file Point aTitlePos( aTitleRect.TopLeft() ); Size aLayoutSize( aLayoutRect.GetSize() ); @@ -1206,10 +1295,18 @@ static void CalcAutoLayoutRectangles( SdPage& rPage, int nLayout, Rectangle* rRe break; // do nothing case 1: // title, 2 shapes case 9: // title, 2 vertical shapes - aLayoutSize.Width() = long (aLayoutSize.Width() * 0.488); + readLayoutPropFromFile(root, "AUTOLAYOUT_TITLE_2VTEXT" ,"PRESOBJ_OUTLINE1" ,propvalue); + aLayoutPos.X() = propvalue[0]; + aLayoutPos.Y() = propvalue[1]; + aLayoutSize.Height() = propvalue[2]; + aLayoutSize.Width() = propvalue[3]; rRectangle[1] = Rectangle (aLayoutPos, aLayoutSize); - aLayoutPos.X() = long (aLayoutPos.X() + aLayoutSize.Width() * 1.05); + readLayoutPropFromFile(root, "AUTOLAYOUT_TITLE_2VTEXT" ,"PRESOBJ_OUTLINE2" ,propvalue); + aLayoutPos.X() = propvalue[0]; + aLayoutPos.Y() = propvalue[1]; + aLayoutSize.Height() = propvalue[2]; + aLayoutSize.Width() = propvalue[3]; rRectangle[2] = Rectangle (aLayoutPos, aLayoutSize); if( bRightToLeft && (nLayout != 9) ) -- cgit