summaryrefslogtreecommitdiff
path: root/src/lib/SW602PageSpan.h
blob: 038cc61642236e121beea5efc7cac2573e615bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libsw602 project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef SW602PAGESPAN_H
#define SW602PAGESPAN_H

#include <vector>

#include "SW602Font.h"
#include "SW602Types.h"

namespace libsw602
{

/** a class which stores the header/footer data */
class SW602HeaderFooter
{
public:
  /** the header/footer type */
  enum Type { HEADER, FOOTER, UNDEF };
  /** the header/footer occurrence in the file */
  enum Occurrence { ODD, EVEN, ALL, NEVER };
  /** a fixed page number position */
  enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight, BottomLeft, BottomCenter, BottomRight };

  //! constructor
  SW602HeaderFooter(Type const type=UNDEF, Occurrence const occurrence=NEVER);
  //! destructor
  ~SW602HeaderFooter();
  //! returns true if the header footer is defined
  bool isDefined() const
  {
    return m_type != UNDEF;
  }
  /** send to header to the listener */
  void send(SW602Listener *listener) const;
  //! operator==
  bool operator==(SW602HeaderFooter const &headerFooter) const;
  //! operator!=
  bool operator!=(SW602HeaderFooter const &headerFooter) const
  {
    return !operator==(headerFooter);
  }
  //! insert a page number
  void insertPageNumberParagraph(SW602Listener *listener) const;

public:
  //! the type header/footer
  Type m_type;
  //! the actual occurrence
  Occurrence m_occurrence;
  //! the height ( if known )
  double m_height;
  //! the page number position ( or none)
  PageNumberPosition m_pageNumberPosition;
  //! the page numbering type
  libsw602::NumberingType m_pageNumberType;
  //! the page numbering font
  SW602Font m_pageNumberFont;
  //! the document data
  SW602SubDocumentPtr m_subDocument;
};

typedef boost::shared_ptr<SW602HeaderFooter> SW602HeaderFooterPtr;

/** A class which defines the page properties */
class SW602PageSpan
{
public:
  /** the page orientation */
  enum FormOrientation { PORTRAIT, LANDSCAPE };
  /** a fixed page number position */
  enum PageNumberPosition { None = 0, TopLeft, TopCenter, TopRight,
                            BottomLeft, BottomCenter, BottomRight
                          };
public:
  //! constructor
  SW602PageSpan();
  //! destructor
  virtual ~SW602PageSpan();

  //! returns the page length
  double getFormLength() const
  {
    return m_formLength;
  }
  //! returns the page width
  double getFormWidth() const
  {
    return m_formWidth;
  }
  //! returns the page orientation
  FormOrientation getFormOrientation() const
  {
    return m_formOrientation;
  }
  //! returns the left margin
  double getMarginLeft() const
  {
    return m_margins[libsw602::Left];
  }
  //! returns the right margin
  double getMarginRight() const
  {
    return m_margins[libsw602::Right];
  }
  //! returns the top margin
  double getMarginTop() const
  {
    return m_margins[libsw602::Top];
  }
  //! returns the bottom margin
  double getMarginBottom() const
  {
    return m_margins[libsw602::Bottom];
  }
  //! returns the page length (form width without margin )
  double getPageLength() const
  {
    return m_formLength-m_margins[libsw602::Top]-m_margins[libsw602::Bottom];
  }
  //! returns the page width (form width without margin )
  double getPageWidth() const
  {
    return m_formWidth-m_margins[libsw602::Left]-m_margins[libsw602::Right];
  }
  //! returns the background color
  SW602Color backgroundColor() const
  {
    return m_backgroundColor;
  }
  int getPageNumber() const
  {
    return m_pageNumber;
  }
  int getPageSpan() const
  {
    return m_pageSpan;
  }

  //! add a header/footer on some page
  void setHeaderFooter(SW602HeaderFooter const &headerFooter);
  //! set the total page length
  void setFormLength(const double formLength)
  {
    m_formLength = formLength;
  }
  //! set the total page width
  void setFormWidth(const double formWidth)
  {
    m_formWidth = formWidth;
  }
  //! set the form orientation
  void setFormOrientation(const FormOrientation formOrientation)
  {
    m_formOrientation = formOrientation;
  }
  //! set the page left margin
  void setMarginLeft(const double marginLeft)
  {
    m_margins[libsw602::Left] = (marginLeft >= 0) ? marginLeft : 0.01;
  }
  //! set the page right margin
  void setMarginRight(const double marginRight)
  {
    m_margins[libsw602::Right] = (marginRight >= 0) ? marginRight : 0.01;
  }
  //! set the page top margin
  void setMarginTop(const double marginTop)
  {
    m_margins[libsw602::Top] =(marginTop >= 0) ? marginTop : 0.01;
  }
  //! set the page bottom margin
  void setMarginBottom(const double marginBottom)
  {
    m_margins[libsw602::Bottom] = (marginBottom >= 0) ? marginBottom : 0.01;
  }
  //! set all the margins
  void setMargins(double margin, int wh=libsw602::LeftBit|libsw602::RightBit|libsw602::TopBit|libsw602::BottomBit)
  {
    if (margin < 0.0) margin = 0.01;
    if (wh&libsw602::LeftBit)
      m_margins[libsw602::Left]=margin;
    if (wh&libsw602::RightBit)
      m_margins[libsw602::Right]=margin;
    if (wh&libsw602::TopBit)
      m_margins[libsw602::Top]=margin;
    if (wh&libsw602::BottomBit)
      m_margins[libsw602::Bottom]=margin;
  }
  //! check if the page margins are consistent with the page dimension, if not update them
  void checkMargins();
  //! set the page name
  void setPageName(librevenge::RVNGString const &name)
  {
    m_name=name;
  }
  //! return true if the page has a name
  bool hasPageName() const
  {
    return !m_name.empty();
  }
  //! return the page name
  librevenge::RVNGString const &getPageName() const
  {
    return m_name;
  }
  //! set the page master name
  void setMasterPageName(librevenge::RVNGString const &name)
  {
    m_masterName=name;
  }
  //! return true if the masterPage has a name
  bool hasMasterPageName() const
  {
    return !m_masterName.empty();
  }
  //! return the page master name
  librevenge::RVNGString const &getMasterPageName() const
  {
    return m_masterName;
  }
  //! set the background color
  void setBackgroundColor(SW602Color color=SW602Color::white())
  {
    m_backgroundColor=color;
  }
  //! set the page number
  void setPageNumber(const int pageNumber)
  {
    m_pageNumber = pageNumber;
  }
  //! set the page span ( default 1)
  void setPageSpan(const int pageSpan)
  {
    m_pageSpan = pageSpan;
  }
  //! operator==
  bool operator==(const SW602PageSpan &pageSpan) const;
  //! operator!=
  bool operator!=(const SW602PageSpan &pageSpan) const
  {
    return !operator==(pageSpan);
  }

  // interface with SW602Listener
  //! add the page properties in pList
  void getPageProperty(librevenge::RVNGPropertyList &pList) const;
  //! send the page's headers/footers if some exists
  void sendHeaderFooters(SW602Listener *listener) const;
  //! send the page's headers/footers corresponding to an occurrence if some exists
  void sendHeaderFooters(SW602Listener *listener, SW602HeaderFooter::Occurrence occurrence) const;

protected:
  //! return the header footer positions in m_headerFooterList
  int getHeaderFooterPosition(SW602HeaderFooter::Type type, SW602HeaderFooter::Occurrence occurrence);
  //! remove a header footer
  void removeHeaderFooter(SW602HeaderFooter::Type type, SW602HeaderFooter::Occurrence occurrence);
  //! return true if we have a header footer in this position
  bool containsHeaderFooter(SW602HeaderFooter::Type type, SW602HeaderFooter::Occurrence occurrence);
private:
  double m_formLength/** the form length*/, m_formWidth /** the form width */;
  /** the form orientation */
  FormOrientation m_formOrientation;
  /** the margins: libsw602::Left, ... */
  double m_margins[4];
  //! the page name
  librevenge::RVNGString m_name;
  //! the page master name
  librevenge::RVNGString m_masterName;
  /** the page background color: default white */
  SW602Color m_backgroundColor;
  //! the page number ( or -1)
  int m_pageNumber;
  //! the list of header
  std::vector<SW602HeaderFooter> m_headerFooterList;
  //! the number of page
  int m_pageSpan;
};

}

#endif

/* vim:set shiftwidth=2 softtabstop=2 expandtab: */