xref: /AOO41X/main/writerperfect/source/filter/SectionStyle.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /* SectionStyle: Stores (and writes) section-based information (e.g.: a column
2  * break needs a new section) that is needed at the head of an OO document and
3  * is referenced throughout the entire document
4  *
5  * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
6  * Copyright (c) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  *
22  * For further information visit http://libwpd.sourceforge.net
23  *
24  */
25 
26 /* "This product is not manufactured, approved, or supported by
27  * Corel Corporation or Corel Corporation Limited."
28  */
29 #include "FilterInternal.hxx"
30 #include "SectionStyle.hxx"
31 #include "DocumentElement.hxx"
32 #include <math.h>
33 
34 #ifdef _MSC_VER
35 double rint(double x);
36 #endif /* _WIN32 */
37 
SectionStyle(const WPXPropertyList & xPropList,const WPXPropertyListVector & xColumns,const char * psName)38 SectionStyle::SectionStyle(const WPXPropertyList &xPropList,
39                            const WPXPropertyListVector &xColumns,
40                            const char *psName) :
41         Style(psName),
42         mPropList(xPropList),
43         mColumns(xColumns)
44 {
45 }
46 
write(DocumentHandler * pHandler) const47 void SectionStyle::write(DocumentHandler *pHandler) const
48 {
49     TagOpenElement styleOpen("style:style");
50     styleOpen.addAttribute("style:name", getName());
51     styleOpen.addAttribute("style:family", "section");
52     styleOpen.write(pHandler);
53 
54     // if the number of columns is <= 1, we will never come here. This is only an additional check
55     // style properties
56     pHandler->startElement("style:properties", mPropList);
57 
58     // column properties
59     WPXPropertyList columnProps;
60 
61     if (mColumns.count() > 1)
62     {
63                 columnProps.insert("fo:column-count", (int)mColumns.count());
64                 pHandler->startElement("style:columns", columnProps);
65 
66                 WPXPropertyListVector::Iter i(mColumns);
67                 for (i.rewind(); i.next();)
68         {
69                         pHandler->startElement("style:column", i());
70                         pHandler->endElement("style:column");
71         }
72     }
73     else
74     {
75         columnProps.insert("fo:column-count", 0);
76         columnProps.insert("fo:column-gap", 0.0f);
77         pHandler->startElement("style:columns", columnProps);
78     }
79 
80     pHandler->endElement("style:columns");
81 
82 
83     pHandler->endElement("style:properties");
84 
85     pHandler->endElement("style:style");
86 }
87