/src/libstaroffice/src/lib/STOFFPageSpan.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
2 | | |
3 | | /* libstaroffice |
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 (wrlach@gmail.com) |
18 | | * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net) |
19 | | * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch) |
20 | | * Copyright (C) 2006, 2007 Andrew Ziem |
21 | | * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr) |
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 | | #include <librevenge/librevenge.h> |
35 | | |
36 | | #include "libstaroffice_internal.hxx" |
37 | | #include "STOFFListener.hxx" |
38 | | #include "STOFFParagraph.hxx" |
39 | | #include "STOFFSubDocument.hxx" |
40 | | |
41 | | #include "STOFFPageSpan.hxx" |
42 | | |
43 | | // ----------------- STOFFHeaderFooter ------------------------ |
44 | | bool STOFFHeaderFooter::operator==(STOFFHeaderFooter const &hF) const |
45 | 0 | { |
46 | 0 | for (int step=0; step<4; ++step) { |
47 | 0 | if (m_subDocument[step]) { |
48 | 0 | if (!hF.m_subDocument[step] || *m_subDocument[step]!=hF.m_subDocument[step]) |
49 | 0 | return false; |
50 | 0 | } |
51 | 0 | else if (hF.m_subDocument[step]) |
52 | 0 | return false; |
53 | 0 | } |
54 | 0 | return true; |
55 | 0 | } |
56 | | |
57 | | void STOFFHeaderFooter::send(STOFFListener *listener, bool isHeader) const |
58 | 9.55k | { |
59 | 9.55k | librevenge::RVNGPropertyList propList; |
60 | 9.55k | if (!listener) { |
61 | 0 | STOFF_DEBUG_MSG(("STOFFHeaderFooter::send: called without listener\n")); |
62 | 0 | return; |
63 | 0 | } |
64 | 47.7k | for (int i=0; i<4; ++i) { |
65 | 38.2k | char const *wh[]= {"region-left", "region-center", "region-right", ""}; |
66 | 38.2k | if (!m_subDocument[i]) continue; |
67 | 27.8k | if (isHeader) |
68 | 12.8k | listener->insertHeaderRegion(m_subDocument[i], wh[i]); |
69 | 14.9k | else |
70 | 14.9k | listener->insertFooterRegion(m_subDocument[i], wh[i]); |
71 | 27.8k | } |
72 | 9.55k | } |
73 | | |
74 | | // ----------------- STOFFPageSpan ------------------------ |
75 | | STOFFPageSpan::STOFFPageSpan() |
76 | 1.30M | : m_pageSpan(1) |
77 | 1.30M | , m_section() |
78 | 1.30M | , m_pageNumber(-1) |
79 | 1.30M | { |
80 | 1.30M | m_propertiesList[0].insert("fo:page-height", 11., librevenge::RVNG_INCH); |
81 | 1.30M | m_propertiesList[0].insert("fo:page-width", 8.5, librevenge::RVNG_INCH); |
82 | 1.30M | m_propertiesList[0].insert("style:print-orientation", "portrait"); |
83 | 1.30M | } |
84 | | |
85 | | STOFFPageSpan::~STOFFPageSpan() |
86 | 1.59M | { |
87 | 1.59M | } |
88 | | |
89 | | void STOFFPageSpan::addHeaderFooter(bool header, std::string const &occurrence, STOFFHeaderFooter const &hf) |
90 | 19.0k | { |
91 | 19.0k | m_occurrenceHFMap[header ? 0 : 1][occurrence]=hf; |
92 | 19.0k | } |
93 | | |
94 | | void STOFFPageSpan::sendHeaderFooters(STOFFListener *listener) const |
95 | 135k | { |
96 | 135k | if (!listener) { |
97 | 0 | STOFF_DEBUG_MSG(("STOFFPageSpan::sendHeaderFooters: no listener\n")); |
98 | 0 | return; |
99 | 0 | } |
100 | | |
101 | 406k | for (int i=0; i<2; ++i) { |
102 | 270k | for (auto &hf : m_occurrenceHFMap[i]) { |
103 | 9.55k | std::string const &occurrence=hf.first; |
104 | 9.55k | if (occurrence.empty()) continue; |
105 | 9.55k | librevenge::RVNGPropertyList propList; |
106 | 9.55k | propList.insert("librevenge:occurrence", occurrence.c_str()); |
107 | 9.55k | if (i==0) |
108 | 4.42k | listener->openHeader(propList); |
109 | 5.13k | else |
110 | 5.13k | listener->openFooter(propList); |
111 | 9.55k | hf.second.send(listener, i==0); |
112 | 9.55k | if (i==0) |
113 | 4.42k | listener->closeHeader(); |
114 | 5.13k | else |
115 | 5.13k | listener->closeFooter(); |
116 | 9.55k | } |
117 | 270k | } |
118 | 135k | } |
119 | | |
120 | | void STOFFPageSpan::getPageProperty(librevenge::RVNGPropertyList &propList) const |
121 | 138k | { |
122 | 138k | propList=m_propertiesList[0]; |
123 | 138k | propList.insert("librevenge:num-pages", m_pageSpan); |
124 | 416k | for (int i=1; i<3; ++i) { |
125 | 277k | if (m_propertiesList[i].empty()) |
126 | 270k | continue; |
127 | 7.59k | librevenge::RVNGPropertyListVector vect; |
128 | 7.59k | vect.append(m_propertiesList[i]); |
129 | 7.59k | propList.insert(i==1 ? "librevenge:header" : "librevenge:footer", vect); |
130 | 7.59k | } |
131 | 138k | } |
132 | | |
133 | | |
134 | | bool STOFFPageSpan::operator==(std::shared_ptr<STOFFPageSpan> const &page2) const |
135 | 0 | { |
136 | 0 | if (!page2) return false; |
137 | 0 | if (page2.get() == this) return true; |
138 | | |
139 | 0 | for (int i=0; i<3; ++i) { |
140 | 0 | if (m_propertiesList[i].getPropString() != page2->m_propertiesList[i].getPropString()) |
141 | 0 | return false; |
142 | 0 | } |
143 | 0 | for (int i=0; i<2; ++i) { |
144 | 0 | if (m_occurrenceHFMap[i].size()!=page2->m_occurrenceHFMap[i].size()) |
145 | 0 | return false; |
146 | 0 | std::map<std::string,STOFFHeaderFooter>::const_iterator it1, it2; |
147 | 0 | for (auto &hf : m_occurrenceHFMap[i]) { |
148 | 0 | it2=page2->m_occurrenceHFMap[i].find(hf.first); |
149 | 0 | if (it2==page2->m_occurrenceHFMap[i].end() || hf.second!=it2->second) return false; |
150 | 0 | } |
151 | 0 | } |
152 | 0 | STOFF_DEBUG_MSG(("WordPerfect: STOFFPageSpan == comparison finished, found no differences\n")); |
153 | |
|
154 | 0 | return true; |
155 | 0 | } |
156 | | |
157 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |