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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  *
21  * For further information visit http://libwpd.sourceforge.net
22  *
23  */
24 
25 /* "This product is not manufactured, approved, or supported by
26  * Corel Corporation or Corel Corporation Limited."
27  */
28 #include "FilterInternal.hxx"
29 #include "PageSpan.hxx"
30 #include "DocumentElement.hxx"
31 
PageSpan(const WPXPropertyList & xPropList)32 PageSpan::PageSpan(const WPXPropertyList &xPropList) :
33         mxPropList(xPropList),
34 	mpHeaderContent(NULL),
35 	mpFooterContent(NULL),
36 	mpHeaderLeftContent(NULL),
37 	mpFooterLeftContent(NULL)
38 {
39 }
40 
~PageSpan()41 PageSpan::~PageSpan()
42 {
43 	typedef std::vector<DocumentElement *>::iterator DEVIter;
44 
45 	if (mpHeaderContent)
46 	{
47 		for (DEVIter iterHeaderContent = mpHeaderContent->begin();
48 			iterHeaderContent != mpHeaderContent->end();
49 			iterHeaderContent++)
50 				delete(*iterHeaderContent);
51 		delete mpHeaderContent;
52 	}
53 
54 	if (mpHeaderLeftContent)
55 	{
56 		for (DEVIter iterHeaderLeftContent = mpHeaderLeftContent->begin();
57 			iterHeaderLeftContent != mpHeaderLeftContent->end();
58 			iterHeaderLeftContent++)
59 				delete(*iterHeaderLeftContent);
60 		delete mpHeaderLeftContent;
61 	}
62 
63 	if (mpFooterContent)
64 	{
65 		for (DEVIter iterFooterContent = mpFooterContent->begin();
66 			iterFooterContent != mpFooterContent->end();
67 			iterFooterContent++)
68 				delete(*iterFooterContent);
69 		delete mpFooterContent;
70 	}
71 
72 	if (mpFooterLeftContent)
73 	{
74 		for (DEVIter iterFooterLeftContent = mpFooterLeftContent->begin();
75 			iterFooterLeftContent != mpFooterLeftContent->end();
76 			iterFooterLeftContent++)
77 				delete(*iterFooterLeftContent);
78 		delete mpFooterLeftContent;
79 	}
80 }
81 
getSpan() const82 int PageSpan::getSpan() const
83 {
84         if (mxPropList["libwpd:num-pages"])
85                 return mxPropList["libwpd:num-pages"]->getInt();
86 
87         return 0; // should never happen
88 }
89 
writePageMaster(const int iNum,DocumentHandler * pHandler) const90 void PageSpan::writePageMaster(const int iNum, DocumentHandler *pHandler) const
91 {
92         WPXPropertyList propList;
93 
94 	WPXString sPageMasterName;
95         sPageMasterName.sprintf("PM%i", iNum /* +2 */);
96         propList.insert("style:name", sPageMasterName);
97 
98 	pHandler->startElement("style:page-master", propList);
99 
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);
106 
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);
115 
116 	pHandler->endElement("style:footnote-sep");
117         pHandler->endElement("style:properties");
118         pHandler->endElement("style:page-master");
119 }
120 
writeMasterPages(const int iStartingNum,const int iPageMasterNum,const bool bLastPageSpan,DocumentHandler * pHandler) const121 void PageSpan::writeMasterPages(const int iStartingNum, const int iPageMasterNum, const bool bLastPageSpan,
122                                 DocumentHandler *pHandler) const
123 {
124 	int iSpan = 0;
125 	(bLastPageSpan) ? iSpan = 1 : iSpan = getSpan();
126 
127 	for (int i=iStartingNum; i<(iStartingNum+iSpan); i++)
128 	{
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);
137 		if (!bLastPageSpan)
138 		{
139 			WPXString sNextMasterPageName;
140 			sNextMasterPageName.sprintf("Page Style %i", (i+1));
141                         propList.insert("style:next-style-name", sNextMasterPageName);
142 		}
143                 pHandler->startElement("style:master-page", propList);
144 
145 		if (mpHeaderContent)
146 			_writeHeaderFooter("style:header", *mpHeaderContent, pHandler);
147 		if (mpHeaderLeftContent)
148 			_writeHeaderFooter("style:header-left", *mpHeaderLeftContent, pHandler);
149 		if (mpFooterContent)
150 			_writeHeaderFooter("style:footer", *mpFooterContent, pHandler);
151 		if (mpFooterLeftContent)
152 			_writeHeaderFooter("style:footer-left", *mpFooterLeftContent, pHandler);
153 
154                 pHandler->endElement("style:master-page");
155 	}
156 
157 }
158 
_writeHeaderFooter(const char * headerFooterTagName,const std::vector<DocumentElement * > & headerFooterContent,DocumentHandler * pHandler) const159 void PageSpan::_writeHeaderFooter(const char *headerFooterTagName,
160 				  const std::vector<DocumentElement *> & headerFooterContent,
161 				  DocumentHandler *pHandler) const
162 {
163 	TagOpenElement headerFooterOpen(headerFooterTagName);
164 	headerFooterOpen.write(pHandler);
165 	for (std::vector<DocumentElement *>::const_iterator iter = headerFooterContent.begin();
166 	     iter != headerFooterContent.end();
167 	     iter++) {
168 		(*iter)->write(pHandler);
169 	}
170 	TagCloseElement headerFooterClose(headerFooterTagName);
171 	headerFooterClose.write(pHandler);
172 }
173 
174