Debian Codegraph @

src/lib/MacWrtProStructures.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 MAC_WRT_PRO_STRUCTURES
35 # define MAC_WRT_PRO_STRUCTURES
36
37 #include <string>
38 #include <vector>
39
40 #include "MWAWDebug.hxx"
41 #include "MWAWEntry.hxx"
42 #include "MWAWInputStream.hxx"
43 #include "MWAWPosition.hxx"
44 #include "MWAWStream.hxx"
45
46 class MacWrtProParser;
47
48 namespace MacWrtProParserInternal
49 {
50 class SubDocument;
51 }
52
53 namespace MacWrtProStructuresInternal
54 {
55 struct Graphic;
56 struct Page;
57 struct Cell;
58 struct Font;
59 struct Paragraph;
60 struct Section;
61 struct State;
62 class SubDocument;
63 }
64
65 class MacWrtProStructures;
66
67 /** \brief an interface to transmit the info of MacWrtProStructures to a listener
68 */
69 class MacWrtProStructuresListenerState
70 {
71 public:
72 //! the constructor
73 MacWrtProStructuresListenerState(std::shared_ptr<MacWrtProStructures> const &structures, bool mainZone, int version);
74 //! the destructor
75 ~MacWrtProStructuresListenerState();
76
77 //! returns true if the graphic is already sent ( or does not exists)
78 bool isSent(int graphicId);
79 //! try to send a graphic which corresponds to graphicid
80 bool send(int graphicId);
81
82 //! try to send the i^th section
83 void sendSection(int numSection);
84 //! try to send a character style
85 bool sendFont(int id);
86 //! try to send a paragraph
87 bool sendParagraph(int id);
88 //! send a character
89 void sendChar(char c);
90
91 //! returns the actual section
92 int numSection() const
93 {
94 if (!m_isMainZone) {
95 MWAW_DEBUG_MSG(("MacWrtProStructuresListenerState::numSection: not called in main zone\n"));
96 return 0;
97 }
98 return m_section;
99 }
100
101 //! return a list of page break position ( as some page break are soft )
102 std::vector<int> getPageBreaksPos() const;
103 //! insert a page break ( if we are not on a new page )
104 void insertSoftPageBreak();
105
106 protected:
107 //! create a new page
108 bool newPage(bool softBreak=false);
109
110 // true if this is the mainZone
111 bool m_isMainZone;
112 // the file version
113 int m_version;
114 // the actual page
115 int m_actPage;
116 // the actual tab
117 int m_actTab;
118 // the number of tab
119 int m_numTab;
120 // the actual section ( if mainZone )
121 int m_section;
122 // the actual number of columns
123 int m_numCols;
124 // a flag to know if a new page has just been open
125 bool m_newPageDone;
126 // the main structure parser
127 std::shared_ptr<MacWrtProStructures> m_structures;
128 };
129
130 /** \brief the main class to read the structures part of MacWrite Pro file
131 *
132 *
133 *
134 */
135 class MacWrtProStructures
136 {
137 friend class MacWrtProParser;
138 friend class MacWrtProParserInternal::SubDocument;
139 friend struct MacWrtProStructuresInternal::Cell;
140 friend class MacWrtProStructuresListenerState;
141 public:
142 //! constructor
143 explicit MacWrtProStructures(MacWrtProParser &mainParser);
144 //! destructor
145 virtual ~MacWrtProStructures();
146
147 /** returns the file version.
148 *
149 * this version is only correct after the header is parsed */
150 int version() const;
151
152 protected:
153 //! inits all internal variables
154 void init();
155
156 //! finds the different objects zones
157 bool createZones(std::shared_ptr<MWAWStream> &stream, int numPages);
158
159 /** finds the different objects zones in a MacWriteII file
160
161 \note: this function is called by createZones
162 */
163 bool createZonesII(std::shared_ptr<MWAWStream> &stream, int numPages);
164
165 //! returns the number of pages
166 int numPages() const;
167
168 //! send the main zone
169 bool sendMainZone();
170
171 //! update the page span
172 void updatePageSpan(int page, bool hasTitlePage, MWAWPageSpan &pageSpan);
173
174 //! flush not send zones
175 void flushExtra();
176
177 //! look for pages structures
178 void buildPageStructures();
179
180 //! look for tables structures and if so, prepare data
181 void buildTableStructures();
182
183 //
184 // low level
185 //
186
187 //! try to read the paragraph styles zone which begins at address 0x200
188 bool readStyles(std::shared_ptr<MWAWStream> &stream);
189
190 //! try to read a style
191 bool readStyle(std::shared_ptr<MWAWStream> &stream, int styleId);
192
193 //! try to read the character styles zone
194 bool readCharStyles(std::shared_ptr<MWAWStream> &stream);
195
196 //! try to read a list of paragraph
197 bool readParagraphs(std::shared_ptr<MWAWStream> &stream);
198
199 //! try to read a paragraph
200 bool readParagraph(std::shared_ptr<MWAWStream> &stream, MacWrtProStructuresInternal::Paragraph &para);
201
202 //! try to read the list of graphic entries: 1.0 1.5
203 bool readGraphicsList(std::shared_ptr<MWAWStream> &stream, int nuumPages);
204 //! try to read a graphic entry: 1.0, 1.5
205 std::shared_ptr<MacWrtProStructuresInternal::Graphic> readGraphic(std::shared_ptr<MWAWStream> &stream);
206
207 //! try to parse the list of page: II
208 bool readPagesListII(std::shared_ptr<MWAWStream> const &stream, int numPages);
209 //! try to read a page entry: II
210 bool readPageII(std::shared_ptr<MWAWStream> const &stream, int wh, MacWrtProStructuresInternal::Page &page);
211 //! try to read a graphic structure: II
212 bool readGraphicII(std::shared_ptr<MWAWStream> const &stream, int id, bool mainGraphic, MacWrtProStructuresInternal::Graphic &graphic);
213
214 //! try to read the fonts zone
215 bool readFontsName(std::shared_ptr<MWAWStream> &stream);
216
217 //! try to read the list of fonts
218 bool readFontsDef(std::shared_ptr<MWAWStream> &stream);
219
220 //! try to read a font
221 bool readFont(std::shared_ptr<MWAWStream> &stream, MacWrtProStructuresInternal::Font &font);
222
223 //! try to read the section info ?
224 bool readSections(std::shared_ptr<MWAWStream> &stream, std::vector<MacWrtProStructuresInternal::Section> &sections);
225
226 //! try to read a 16 bytes the zone which follow the char styles zone ( the selection?)
227 bool readSelection(std::shared_ptr<MWAWStream> &stream);
228
229 //! try to read a zone which follow the fonts zone(checkme)
230 bool readStructB(std::shared_ptr<MWAWStream> &stream);
231
232 //! try to read a string
233 static bool readString(MWAWInputStreamPtr input, std::string &res);
234
235 //! try to return the color corresponding to colId
236 bool getColor(int colId, MWAWColor &color) const;
237
238 //! try to return the pattern corresponding to patId
239 bool getPattern(int patId, float &patternPercent) const;
240
241 //! try to return the color corresponding to colId and patId
242 bool getColor(int colId, int patId, MWAWColor &color) const;
243
244 //! returns true if the graphic is already sent ( or does not exists)
245 bool isSent(int graphicId);
246
247 /** try to send a graphic which corresponds to graphicid
248
249 note: graphicId=-noteId to send footnote in MW2
250 */
251 bool send(int graphicId, bool mainZone=false);
252
253 //! returns the actual listener
254 MWAWTextListenerPtr &getTextListener();
255
256 protected:
257 //
258 // data
259 //
260
261 //! the parser state
262 MWAWParserStatePtr m_parserState;
263
264 //! the main parser
265 MacWrtProParser &m_mainParser;
266
267 //! the state
268 std::shared_ptr<MacWrtProStructuresInternal::State> m_state;
269
270 //! the debug file name
271 std::string m_asciiName;
272 };
273 #endif
274 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: