PageSpan.cpp
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 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, 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 <config.h>
30
31#include "FilterInternal.h"
32#include "PageSpan.h"
33#include "DocumentElement.h"
34
35
36PageSpan::PageSpan(const _SH_PropertyList &xPropList) :
37#if 0
38const int iSpan, const float fFormLength, const float fFormWidth, const WPXFormQt::Orientation fFormQt::Orientation,
39 const float fLeftMargin, const float fRightMargin, const float fTopMargin, const float fBottomMargin):
40 miSpan(iSpan),
41 mfFormLength(fFormLength),
42 mfFormWidth(fFormWidth),
43 mfFormQt::Orientation(fFormQt::Orientation),
44 mfMarginLeft(fLeftMargin),
45 mfMarginRight(fRightMargin),
46 mfMarginTop(fTopMargin),
47 mfMarginBottom(fBottomMargin),
48#endif
49 mxPropList(xPropList),
50 mpHeaderContent(NULL),
51 mpFooterContent(NULL),
52 mpHeaderLeftContent(NULL),
53 mpFooterLeftContent(NULL)
54{
55}
56
57PageSpan::~PageSpan()
58{
59 delete mpHeaderContent;
60 delete mpHeaderLeftContent;
61 delete mpFooterContent;
62 delete mpFooterLeftContent;
63}
64
65int PageSpan::getSpan() const
66{
67 if (mxPropList["libwpd:num-pages"])
68 return mxPropList["libwpd:num-pages"]->getInt();
69
70 return 0; // should never happen
71}
72
73float PageSpan::getMarginLeft() const
74{
75 if (mxPropList["fo:margin-left"])
76#if defined(HAVE_LIBWPD_090) || defined(HAVE_LIBWPD_0100)
77 return mxPropList["fo:margin-left"]->getDouble();
78#else
79 return mxPropList["fo:margin-left"]->getFloat();
80#endif
81
82 return 0.0f;
83}
84
85float PageSpan::getMarginRight() const
86{
87 if (mxPropList["fo:margin-right"])
88#if defined(HAVE_LIBWPD_090) || defined(HAVE_LIBWPD_0100)
89 return mxPropList["fo:margin-right"]->getDouble();
90#else
91 return mxPropList["fo:margin-right"]->getFloat();
92#endif
93
94 return 0.0f;
95}
96
97void PageSpan::writePageMaster(const int iNum, DocumentHandler &xHandler) const
98{
99 _SH_PropertyList propList;
100
101 _SH_String sPageMasterName;
102 sPageMasterName.sprintf("PM%i", iNum+2);
103 propList.insert("style:name", sPageMasterName);
104 xHandler.startElement("style:page-master", propList);
105
106 _SH_PropertyList tempPropList = mxPropList;
107 if (!tempPropList["style:writing-mode"])
108 tempPropList.insert("style:writing-mode", _SH_String("lr-tb"));
109 if (!tempPropList["style:footnote-max-height"])
110 tempPropList.insert("style:footnote-max-height", _SH_String("0inch"));
111 xHandler.startElement("style:properties", tempPropList);
112
113 _SH_PropertyList footnoteSepPropList;
114 footnoteSepPropList.insert("style:width", _SH_String("0.0071inch"));
115 footnoteSepPropList.insert("style:distance-before-sep", _SH_String("0.0398inch"));
116 footnoteSepPropList.insert("style:distance-after-sep", _SH_String("0.0398inch"));
117 footnoteSepPropList.insert("style:adjustment", _SH_String("left"));
118 footnoteSepPropList.insert("style:rel-width", _SH_String("25\%"));
119 footnoteSepPropList.insert("style:color", _SH_String("#000000"));
120 xHandler.startElement("style:footnote-sep", footnoteSepPropList);
121
122 xHandler.endElement("style:footnote-sep");
123 xHandler.endElement("style:properties");
124 xHandler.endElement("style:page-master");
125}
126
127void PageSpan::writeMasterPages(const int iStartingNum, const int iPageMasterNum, const bool bLastPageSpan,
128 DocumentHandler &xHandler) const
129{
130 _SH_PropertyList propList; // scratch space
131
132 int iSpan = 0;
133 (bLastPageSpan) ? iSpan = 1 : iSpan = getSpan();
134
135 for (int i=iStartingNum; i<(iStartingNum+iSpan); i++)
136 {
137 TagOpenElement masterPageOpen("style:master-page");
138 _SH_String sMasterPageName;
139 sMasterPageName.sprintf("Page Style %i", i);
140 _SH_String sPageMasterName;
141 sPageMasterName.sprintf("PM%i", iPageMasterNum+2);
142 propList.insert("style:name", sMasterPageName);
143 propList.insert("style:page-master-name", sPageMasterName);
144 if (!bLastPageSpan)
145 {
146 _SH_String sNextMasterPageName;
147 sNextMasterPageName.sprintf("Page Style %i", (i+1));
148 propList.insert("style:next-style-name", sNextMasterPageName);
149 }
150 xHandler.startElement("style:master-page", propList);
151
152 if (mpHeaderContent)
153 _writeHeaderFooter("style:header", *mpHeaderContent, xHandler);
154 if (mpHeaderLeftContent)
155 _writeHeaderFooter("style:header-left", *mpHeaderLeftContent, xHandler);
156 if (mpFooterContent)
157 _writeHeaderFooter("style:footer", *mpFooterContent, xHandler);
158 if (mpFooterLeftContent)
159 _writeHeaderFooter("style:footer-left", *mpFooterLeftContent, xHandler);
160
161 xHandler.endElement("style:master-page");
162 }
163
164}
165
166void PageSpan::_writeHeaderFooter(const char *headerFooterTagName,
167 const std::vector<DocumentElement *> & headerFooterContent,
168 DocumentHandler &xHandler) const
169{
170 TagOpenElement headerFooterOpen(headerFooterTagName);
171 headerFooterOpen.write(xHandler);
172 for (std::vector<DocumentElement *>::const_iterator iter = headerFooterContent.begin();
173 iter != headerFooterContent.end();
174 iter++) {
175 (*iter)->write(xHandler);
176 }
177 TagCloseElement headerFooterClose(headerFooterTagName);
178 headerFooterClose.write(xHandler);
179}
180