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
5 * Copyright (C) 2002-2003 William Lachance (william.lachance@sympatico.ca)
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * For further information visit http://libwpd.sourceforge.net
25 /* "This product is not manufactured, approved, or supported by
26 * Corel Corporation or Corel Corporation Limited."
28 #include "FilterInternal.hxx"
29 #include "PageSpan.hxx"
30 #include "DocumentElement.hxx"
32 PageSpan::PageSpan(const WPXPropertyList
&xPropList
) :
33 mxPropList(xPropList
),
34 mpHeaderContent(NULL
),
35 mpFooterContent(NULL
),
36 mpHeaderLeftContent(NULL
),
37 mpFooterLeftContent(NULL
)
43 typedef std::vector
<DocumentElement
*>::iterator DEVIter
;
47 for (DEVIter iterHeaderContent
= mpHeaderContent
->begin();
48 iterHeaderContent
!= mpHeaderContent
->end();
50 delete(*iterHeaderContent
);
51 delete mpHeaderContent
;
54 if (mpHeaderLeftContent
)
56 for (DEVIter iterHeaderLeftContent
= mpHeaderLeftContent
->begin();
57 iterHeaderLeftContent
!= mpHeaderLeftContent
->end();
58 iterHeaderLeftContent
++)
59 delete(*iterHeaderLeftContent
);
60 delete mpHeaderLeftContent
;
65 for (DEVIter iterFooterContent
= mpFooterContent
->begin();
66 iterFooterContent
!= mpFooterContent
->end();
68 delete(*iterFooterContent
);
69 delete mpFooterContent
;
72 if (mpFooterLeftContent
)
74 for (DEVIter iterFooterLeftContent
= mpFooterLeftContent
->begin();
75 iterFooterLeftContent
!= mpFooterLeftContent
->end();
76 iterFooterLeftContent
++)
77 delete(*iterFooterLeftContent
);
78 delete mpFooterLeftContent
;
82 int PageSpan::getSpan() const
84 if (mxPropList
["libwpd:num-pages"])
85 return mxPropList
["libwpd:num-pages"]->getInt();
87 return 0; // should never happen
90 void PageSpan::writePageMaster(const int iNum
, DocumentHandler
*pHandler
) const
92 WPXPropertyList propList
;
94 WPXString sPageMasterName
;
95 sPageMasterName
.sprintf("PM%i", iNum
/* +2 */);
96 propList
.insert("style:name", sPageMasterName
);
98 pHandler
->startElement("style:page-master", propList
);
100 WPXPropertyList tempPropList
= mxPropList
;
101 if (!tempPropList
["style:writing-mode"])
102 tempPropList
.insert("style:writing-mode", WPXString("lr-tb"));
103 if (!tempPropList
["style:footnote-max-height"])
104 tempPropList
.insert("style:footnote-max-height", WPXString("0inch"));
105 pHandler
->startElement("style:properties", tempPropList
);
107 WPXPropertyList footnoteSepPropList
;
108 footnoteSepPropList
.insert("style:width", WPXString("0.0071inch"));
109 footnoteSepPropList
.insert("style:distance-before-sep", WPXString("0.0398inch"));
110 footnoteSepPropList
.insert("style:distance-after-sep", WPXString("0.0398inch"));
111 footnoteSepPropList
.insert("style:adjustment", WPXString("left"));
112 footnoteSepPropList
.insert("style:rel-width", WPXString("25%"));
113 footnoteSepPropList
.insert("style:color", WPXString("#000000"));
114 pHandler
->startElement("style:footnote-sep", footnoteSepPropList
);
116 pHandler
->endElement("style:footnote-sep");
117 pHandler
->endElement("style:properties");
118 pHandler
->endElement("style:page-master");
121 void PageSpan::writeMasterPages(const int iStartingNum
, const int iPageMasterNum
, const bool bLastPageSpan
,
122 DocumentHandler
*pHandler
) const
125 (bLastPageSpan
) ? iSpan
= 1 : iSpan
= getSpan();
127 for (int i
=iStartingNum
; i
<(iStartingNum
+iSpan
); i
++)
129 TagOpenElement
masterPageOpen("style:master-page");
130 WPXString sMasterPageName
;
131 sMasterPageName
.sprintf("Page Style %i", i
);
132 WPXString sPageMasterName
;
133 sPageMasterName
.sprintf("PM%i", iPageMasterNum
/* +2 */);
134 WPXPropertyList propList
;
135 propList
.insert("style:name", sMasterPageName
);
136 propList
.insert("style:page-master-name", sPageMasterName
);
139 WPXString sNextMasterPageName
;
140 sNextMasterPageName
.sprintf("Page Style %i", (i
+1));
141 propList
.insert("style:next-style-name", sNextMasterPageName
);
143 pHandler
->startElement("style:master-page", propList
);
146 _writeHeaderFooter("style:header", *mpHeaderContent
, pHandler
);
147 if (mpHeaderLeftContent
)
148 _writeHeaderFooter("style:header-left", *mpHeaderLeftContent
, pHandler
);
150 _writeHeaderFooter("style:footer", *mpFooterContent
, pHandler
);
151 if (mpFooterLeftContent
)
152 _writeHeaderFooter("style:footer-left", *mpFooterLeftContent
, pHandler
);
154 pHandler
->endElement("style:master-page");
159 void PageSpan::_writeHeaderFooter(const char *headerFooterTagName
,
160 const std::vector
<DocumentElement
*> & headerFooterContent
,
161 DocumentHandler
*pHandler
) const
163 TagOpenElement
headerFooterOpen(headerFooterTagName
);
164 headerFooterOpen
.write(pHandler
);
165 for (std::vector
<DocumentElement
*>::const_iterator iter
= headerFooterContent
.begin();
166 iter
!= headerFooterContent
.end();
168 (*iter
)->write(pHandler
);
170 TagCloseElement
headerFooterClose(headerFooterTagName
);
171 headerFooterClose
.write(pHandler
);