Debian Codegraph @

src/lib/MWAWPageSpan.hxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #ifndef MWAWPAGESPAN_H
35 #define MWAWPAGESPAN_H
36
37 #include <vector>
38
39 #include "libmwaw_internal.hxx"
40
41 #include "MWAWFont.hxx"
42
43 /** a class which stores the header/footer data */
44 class MWAWHeaderFooter
45 {
46 public:
47 /** the header/footer type */
48 enum Type { HEADER, FOOTER, UNDEF };
49 /** the header/footer occurrence in the file */
50 enum Occurrence { ODD, EVEN, ALL, NEVER };
51 /** a fixed page number position */
52 enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight, BottomLeft, BottomCenter, BottomRight };
53
54 //! constructor
55 explicit MWAWHeaderFooter(Type const type=UNDEF, Occurrence const occurrence=NEVER);
56 MWAWHeaderFooter(MWAWHeaderFooter const &)=default;
57 MWAWHeaderFooter &operator=(MWAWHeaderFooter const &)=default;
58 MWAWHeaderFooter &operator=(MWAWHeaderFooter &&)=default;
59 //! destructor
60 ~MWAWHeaderFooter();
61 //! returns true if the header footer is defined
62 bool isDefined() const
63 {
64 return m_type != UNDEF;
65 }
66 /** send to header to the listener */
67 void send(MWAWListener *listener) const;
68 //! operator==
69 bool operator==(MWAWHeaderFooter const &headerFooter) const;
70 //! operator!=
71 bool operator!=(MWAWHeaderFooter const &headerFooter) const
72 {
73 return !operator==(headerFooter);
74 }
75 //! insert a page number
76 void insertPageNumberParagraph(MWAWListener *listener) const;
77
78 public:
79 //! the type header/footer
80 Type m_type;
81 //! the actual occurrence
82 Occurrence m_occurrence;
83 //! the height ( if known )
84 double m_height;
85 //! the page number position ( or none)
86 PageNumberPosition m_pageNumberPosition;
87 //! the page numbering type
88 libmwaw::NumberingType m_pageNumberType;
89 //! the page numbering font
90 MWAWFont m_pageNumberFont;
91 //! the document data
92 MWAWSubDocumentPtr m_subDocument;
93 };
94
95 typedef std::shared_ptr<MWAWHeaderFooter> MWAWHeaderFooterPtr;
96
97 /** A class which defines the page properties */
98 class MWAWPageSpan
99 {
100 public:
101 /** the page orientation */
102 enum FormOrientation { PORTRAIT, LANDSCAPE };
103 /** a fixed page number position */
104 enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight,
105 BottomLeft, BottomCenter, BottomRight
106 };
107 public:
108 //! constructor
109 MWAWPageSpan();
110 MWAWPageSpan(MWAWPageSpan const &)=default;
111 MWAWPageSpan &operator=(MWAWPageSpan const &)=default;
112 MWAWPageSpan &operator=(MWAWPageSpan &&)=default;
113 //! destructor
114 ~MWAWPageSpan();
115
116 //! returns the page length
117 double getFormLength() const
118 {
119 return m_formLength;
120 }
121 //! returns the page width
122 double getFormWidth() const
123 {
124 return m_formWidth;
125 }
126 //! returns the page orientation
127 FormOrientation getFormOrientation() const
128 {
129 return m_formOrientation;
130 }
131 //! returns the left margin
132 double getMarginLeft() const
133 {
134 return m_margins[libmwaw::Left];
135 }
136 //! returns the right margin
137 double getMarginRight() const
138 {
139 return m_margins[libmwaw::Right];
140 }
141 //! returns the top margin
142 double getMarginTop() const
143 {
144 return m_margins[libmwaw::Top];
145 }
146 //! returns the bottom margin
147 double getMarginBottom() const
148 {
149 return m_margins[libmwaw::Bottom];
150 }
151 //! returns the page length (form width without margin )
152 double getPageLength() const
153 {
154 return m_formLength-m_margins[libmwaw::Top]-m_margins[libmwaw::Bottom];
155 }
156 //! returns the page width (form width without margin )
157 double getPageWidth() const
158 {
159 return m_formWidth-m_margins[libmwaw::Left]-m_margins[libmwaw::Right];
160 }
161 //! returns the background color
162 MWAWColor backgroundColor() const
163 {
164 return m_backgroundColor;
165 }
166 int getPageNumber() const
167 {
168 return m_pageNumber;
169 }
170 int getPageSpan() const
171 {
172 return m_pageSpan;
173 }
174
175 //! add a header/footer on some page
176 void setHeaderFooter(MWAWHeaderFooter const &headerFooter);
177 //! set the total page length
178 void setFormLength(const double formLength)
179 {
180 m_formLength = formLength;
181 }
182 //! set the total page width
183 void setFormWidth(const double formWidth)
184 {
185 m_formWidth = formWidth;
186 }
187 //! set the form orientation
188 void setFormOrientation(const FormOrientation formOrientation)
189 {
190 m_formOrientation = formOrientation;
191 }
192 //! set the page left margin
193 void setMarginLeft(const double marginLeft)
194 {
195 m_margins[libmwaw::Left] = (marginLeft >= 0) ? marginLeft : 0.01;
196 }
197 //! set the page right margin
198 void setMarginRight(const double marginRight)
199 {
200 m_margins[libmwaw::Right] = (marginRight >= 0) ? marginRight : 0.01;
201 }
202 //! set the page top margin
203 void setMarginTop(const double marginTop)
204 {
205 m_margins[libmwaw::Top] =(marginTop >= 0) ? marginTop : 0.01;
206 }
207 //! set the page bottom margin
208 void setMarginBottom(const double marginBottom)
209 {
210 m_margins[libmwaw::Bottom] = (marginBottom >= 0) ? marginBottom : 0.01;
211 }
212 //! set all the margins
213 void setMargins(double margin, int wh=libmwaw::LeftBit|libmwaw::RightBit|libmwaw::TopBit|libmwaw::BottomBit)
214 {
215 if (margin < 0.0) margin = 0.01;
216 if (wh&libmwaw::LeftBit)
217 m_margins[libmwaw::Left]=margin;
218 if (wh&libmwaw::RightBit)
219 m_margins[libmwaw::Right]=margin;
220 if (wh&libmwaw::TopBit)
221 m_margins[libmwaw::Top]=margin;
222 if (wh&libmwaw::BottomBit)
223 m_margins[libmwaw::Bottom]=margin;
224 }
225 //! check if the page margins are consistent with the page dimension, if not update them
226 void checkMargins();
227 //! set the page name
228 void setPageName(librevenge::RVNGString const &name)
229 {
230 m_name=name;
231 }
232 //! return true if the page has a name
233 bool hasPageName() const
234 {
235 return !m_name.empty();
236 }
237 //! return the page name
238 librevenge::RVNGString const &getPageName() const
239 {
240 return m_name;
241 }
242 //! set the page master name
243 void setMasterPageName(librevenge::RVNGString const &name)
244 {
245 m_masterName=name;
246 }
247 //! return true if the masterPage has a name
248 bool hasMasterPageName() const
249 {
250 return !m_masterName.empty();
251 }
252 //! return the page master name
253 librevenge::RVNGString const &getMasterPageName() const
254 {
255 return m_masterName;
256 }
257 //! set the background color
258 void setBackgroundColor(MWAWColor color=MWAWColor::white())
259 {
260 m_backgroundColor=color;
261 }
262 //! set the page number
263 void setPageNumber(const int pageNumber)
264 {
265 m_pageNumber = pageNumber;
266 }
267 //! set the page span ( default 1)
268 void setPageSpan(const int pageSpan)
269 {
270 m_pageSpan = pageSpan;
271 }
272 //! operator==
273 bool operator==(std::shared_ptr<MWAWPageSpan> const &pageSpan) const;
274 //! operator!=
275 bool operator!=(std::shared_ptr<MWAWPageSpan> const &pageSpan) const
276 {
277 return !operator==(pageSpan);
278 }
279
280 // interface with MWAWListener
281 //! add the page properties in pList
282 void getPageProperty(librevenge::RVNGPropertyList &pList, bool isPresentation=false) const;
283 //! send the page's headers/footers if some exists
284 void sendHeaderFooters(MWAWListener *listener) const;
285 //! send the page's headers/footers corresponding to an occurrence if some exists
286 void sendHeaderFooters(MWAWListener *listener, MWAWHeaderFooter::Occurrence occurrence) const;
287
288 protected:
289 //! return the header footer positions in m_headerFooterList
290 int getHeaderFooterPosition(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurrence occurrence);
291 //! remove a header footer
292 void removeHeaderFooter(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurrence occurrence);
293 //! return true if we have a header footer in this position
294 bool containsHeaderFooter(MWAWHeaderFooter::Type type, MWAWHeaderFooter::Occurrence occurrence);
295 private:
296 double m_formLength/** the form length*/, m_formWidth /** the form width */;
297 /** the margins: libmwaw::Left, ... */
298 double m_margins[4];
299 //! the page name
300 librevenge::RVNGString m_name;
301 //! the page master name
302 librevenge::RVNGString m_masterName;
303 /** the form orientation */
304 FormOrientation m_formOrientation;
305 /** the page background color: default white */
306 MWAWColor m_backgroundColor;
307 //! the list of header
308 std::vector<MWAWHeaderFooter> m_headerFooterList;
309 //! the page number ( or -1)
310 int m_pageNumber;
311 //! the number of page
312 int m_pageSpan;
313 };
314
315 #endif
316 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: