MacWrtProStructures.hxx Source File documentation

MacWrtProStructures.hxx
Go to the documentation of this file.
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 (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 #ifndef MAC_WRT_PRO_STRUCTURES
35 # define MAC_WRT_PRO_STRUCTURES
36
37 #include <list>
38 #include <string>
39 #include <vector>
40
41 #include "MWAWPosition.hxx"
42
43 #include "MWAWEntry.hxx"
44
45 #include "MWAWDebug.hxx"
46 #include "MWAWInputStream.hxx"
47
48 class MacWrtProParser;
49
50 namespace MacWrtProParserInternal
51 {
52 class SubDocument;
53 }
54
55 namespace MacWrtProStructuresInternal
56 {
57 struct Block;
58 struct Cell;
59 struct Font;
60 struct Paragraph;
61 struct Section;
62 struct State;
63 class SubDocument;
64 }
65
66 class MacWrtProStructures;
67
70 class MacWrtProStructuresListenerState
71 {
72 public:
74 MacWrtProStructuresListenerState(std::shared_ptr<MacWrtProStructures> const &structures, bool mainZone, int version);
76 ~MacWrtProStructuresListenerState();
77
79 bool isSent(int blockId);
81 bool send(int blockId);
82
84 void sendSection(int numSection);
86 bool sendFont(int id);
88 bool sendParagraph(int id);
90 void sendChar(char c);
91
93 bool resendAll();
94
96 int numSection() const
97 {
98 if (!m_isMainZone) {
99 MWAW_DEBUG_MSG(("MacWrtProStructuresListenerState::numSection: not called in main zone\n"));
100 return 0;
101 }
102 return m_section;
103 }
104
106 std::vector<int> getPageBreaksPos() const;
108 void insertSoftPageBreak();
109
111 std::string getFontDebugString(int fontId);
112
114 std::string getParagraphDebugString(int paraId);
115
116 protected:
118 bool newPage(bool softBreak=false);
119
121 void sendFont(MacWrtProStructuresInternal::Font const &font);
123 void sendParagraph(MacWrtProStructuresInternal::Paragraph const &para);
124
125 // true if this is the mainZone
126 bool m_isMainZone;
127 // the file version
128 int m_version;
129 // the actual page
130 int m_actPage;
131 // the actual tab
132 int m_actTab;
133 // the number of tab
134 int m_numTab;
135 // the actual section ( if mainZone )
136 int m_section;
137 // the actual number of columns
138 int m_numCols;
139 // a flag to know if a new page has just been open
140 bool m_newPageDone;
141 // the main structure parser
142 std::shared_ptr<MacWrtProStructures> m_structures;
143 // the current font
144 std::shared_ptr<MacWrtProStructuresInternal::Font> m_font;
145 // the current paragraph
146 std::shared_ptr<MacWrtProStructuresInternal::Paragraph> m_paragraph;
147 };
148
154 class MacWrtProStructures
155 {
156 friend class MacWrtProParser;
157 friend class MacWrtProParserInternal::SubDocument;
158 friend struct MacWrtProStructuresInternal::Cell;
159 friend class MacWrtProStructuresListenerState;
160 public:
162 explicit MacWrtProStructures(MacWrtProParser &mainParser);
164 virtual ~MacWrtProStructures();
165
169 int version() const;
170
172 void setAsciiName(char const *name)
173 {
174 m_asciiName = name;
175 }
176
177 protected:
179 void init();
180
182 bool createZones();
183
188 bool createZonesV2();
189
191 int numPages() const;
192
194 bool sendMainZone();
195
197 void updatePageSpan(int page, bool hasTitlePage, MWAWPageSpan &pageSpan);
198
200 void flushExtra();
201
203 void buildPageStructures();
204
206 void buildTableStructures();
207
208 //
209 // low level
210 //
211
213 bool readStyles();
214
216 bool readStyle(int styleId);
217
219 bool readCharStyles();
220
222 bool readParagraphs();
223
225 bool readParagraph(MacWrtProStructuresInternal::Paragraph &para);
226
228 std::shared_ptr<MacWrtProStructuresInternal::Block> readBlock();
229
231 std::shared_ptr<MacWrtProStructuresInternal::Block> readBlockV2(int id);
232
234 bool readBlocksList();
235
237 bool readFontsName();
238
240 bool readFontsDef();
241
243 bool readFont(MacWrtProStructuresInternal::Font &font);
244
246 bool readSections(std::vector<MacWrtProStructuresInternal::Section> &sections);
247
249 bool readSelection();
250
252 bool readStructB();
253
255 static bool readString(MWAWInputStreamPtr input, std::string &res);
256
258 bool getColor(int colId, MWAWColor &color) const;
259
261 bool getPattern(int patId, float &patternPercent) const;
262
264 bool getColor(int colId, int patId, MWAWColor &color) const;
265
267 bool isSent(int blockId);
268
273 bool send(int blockId, bool mainZone=false);
274
276 MWAWTextListenerPtr &getTextListener();
277
279 libmwaw::DebugFile &ascii()
280 {
281 return m_asciiFile;
282 }
283
285 std::string const &asciiName() const
286 {
287 return m_asciiName;
288 }
289
290 protected:
291 //
292 // data
293 //
294
296 MWAWParserStatePtr m_parserState;
297
299 MWAWInputStreamPtr m_input;
300
302 MacWrtProParser &m_mainParser;
303
305 std::shared_ptr<MacWrtProStructuresInternal::State> m_state;
306
308 libmwaw::DebugFile m_asciiFile;
309
311 std::string m_asciiName;
312 };
313 #endif
314 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWTextListenerPtr
std::shared_ptr< MWAWTextListener > MWAWTextListenerPtr
a smart pointer of MWAWTextListener
Definition: libmwaw_internal.hxx:565
MacWrtProStructures::send
bool send(int blockId, bool mainZone=false)
try to send a block which corresponds to blockid
Definition: MacWrtProStructures.cxx:2650
MacWrtProStructuresListenerState::sendParagraph
bool sendParagraph(int id)
try to send a paragraph
Definition: MacWrtProStructures.cxx:3000
MacWrtProStructuresListenerState::getParagraphDebugString
std::string getParagraphDebugString(int paraId)
debug function which returns a string corresponding to a paragrapId
Definition: MacWrtProStructures.cxx:3023
MacWrtProStructures::readCharStyles
bool readCharStyles()
try to read the character styles zone
Definition: MacWrtProStructures.cxx:1609
MacWrtProStructures::m_mainParser
MacWrtProParser & m_mainParser
the main parser
Definition: MacWrtProStructures.hxx:302
MWAWParserStatePtr
std::shared_ptr< MWAWParserState > MWAWParserStatePtr
a smart pointer of MWAWParserState
Definition: libmwaw_internal.hxx:555
MacWrtProStructures
the main class to read the structures part of MacWrite Pro file
Definition: MacWrtProStructures.hxx:154
MacWrtProStructuresListenerState::sendChar
void sendChar(char c)
send a character
Definition: MacWrtProStructures.cxx:2870
MWAWPageSpan
A class which defines the page properties.
Definition: MWAWPageSpan.hxx:97
MWAWEntry.hxx
libmwaw::DebugFile
an interface used to insert comment in a binary file, written in ascii form (if debug_with_files is n...
Definition: MWAWDebug.hxx:65
MacWrtProStructuresListenerState::newPage
bool newPage(bool softBreak=false)
create a new page
Definition: MacWrtProStructures.cxx:2827
MacWrtProStructuresListenerState::m_numCols
int m_numCols
Definition: MacWrtProStructures.hxx:138
MacWrtProStructuresListenerState::MacWrtProStructuresListenerState
MacWrtProStructuresListenerState(std::shared_ptr< MacWrtProStructures > const &structures, bool mainZone, int version)
the constructor
Definition: MacWrtProStructures.cxx:2781
MacWrtProStructures::buildTableStructures
void buildTableStructures()
look for tables structures and if so, prepare data
Definition: MacWrtProStructures.cxx:1135
MacWrtProStructures::createZonesV2
bool createZonesV2()
finds the different objects zones in a MacWriteII file
Definition: MacWrtProStructures.cxx:931
MacWrtProStructuresListenerState::sendSection
void sendSection(int numSection)
try to send the i^th section
Definition: MacWrtProStructures.cxx:3040
MacWrtProStructuresListenerState::numSection
int numSection() const
returns the actual section
Definition: MacWrtProStructures.hxx:96
MacWrtProStructuresListenerState::~MacWrtProStructuresListenerState
~MacWrtProStructuresListenerState()
the destructor
Definition: MacWrtProStructures.cxx:2804
MacWrtProStructures::readStyle
bool readStyle(int styleId)
try to read a style
Definition: MacWrtProStructures.cxx:1738
MacWrtProStructuresListenerState::insertSoftPageBreak
void insertSoftPageBreak()
insert a page break ( if we are not on a new page )
Definition: MacWrtProStructures.cxx:2821
MacWrtProStructures::numPages
int numPages() const
returns the number of pages
Definition: MacWrtProStructures.cxx:660
MacWrtProStructuresListenerState::m_actPage
int m_actPage
Definition: MacWrtProStructures.hxx:130
MacWrtProStructures::version
int version() const
returns the file version.
Definition: MacWrtProStructures.cxx:648
MacWrtProStructuresListenerState::getFontDebugString
std::string getFontDebugString(int fontId)
debug function which returns a string corresponding to a fontId
Definition: MacWrtProStructures.cxx:2977
MacWrtProParserInternal::SubDocument
Internal: the subdocument of a MacWrtProParser.
Definition: MacWrtProParser.cxx:267
MacWrtProStructuresListenerState::m_actTab
int m_actTab
Definition: MacWrtProStructures.hxx:132
MacWrtProStructuresListenerState::m_newPageDone
bool m_newPageDone
Definition: MacWrtProStructures.hxx:140
MacWrtProStructures::init
void init()
inits all internal variables
Definition: MacWrtProStructures.cxx:642
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:192
MacWrtProStructures::readBlocksList
bool readBlocksList()
try to read the list of block entries
Definition: MacWrtProStructures.cxx:1834
MacWrtProStructuresListenerState::m_paragraph
std::shared_ptr< MacWrtProStructuresInternal::Paragraph > m_paragraph
Definition: MacWrtProStructures.hxx:146
MacWrtProStructures::flushExtra
void flushExtra()
flush not send zones
Definition: MacWrtProStructures.cxx:2735
MacWrtProStructures::readBlock
std::shared_ptr< MacWrtProStructuresInternal::Block > readBlock()
try to read a block entry
Definition: MacWrtProStructures.cxx:2121
MacWrtProStructuresListenerState::m_font
std::shared_ptr< MacWrtProStructuresInternal::Font > m_font
Definition: MacWrtProStructures.hxx:144
MacWrtProStructures::readString
static bool readString(MWAWInputStreamPtr input, std::string &res)
try to read a string
Definition: MacWrtProStructures.cxx:2556
MacWrtProStructures::setAsciiName
void setAsciiName(char const *name)
Debugging: change the default ascii file (by default struct )
Definition: MacWrtProStructures.hxx:172
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
MacWrtProStructures::ascii
libmwaw::DebugFile & ascii()
returns the debug file
Definition: MacWrtProStructures.hxx:279
MacWrtProStructuresListenerState::sendFont
bool sendFont(int id)
try to send a character style
Definition: MacWrtProStructures.cxx:2954
MacWrtProStructures::readFontsName
bool readFontsName()
try to read the fonts zone
Definition: MacWrtProStructures.cxx:1192
MacWrtProStructures::getPattern
bool getPattern(int patId, float &patternPercent) const
try to return the pattern corresponding to patId
Definition: MacWrtProStructures.cxx:772
MacWrtProStructuresListenerState::m_structures
std::shared_ptr< MacWrtProStructures > m_structures
Definition: MacWrtProStructures.hxx:142
MacWrtProStructures::readParagraphs
bool readParagraphs()
try to read a list of paragraph
Definition: MacWrtProStructures.cxx:1397
MacWrtProStructures::asciiName
std::string const & asciiName() const
return the ascii file name
Definition: MacWrtProStructures.hxx:285
MacWrtProStructuresListenerState::send
bool send(int blockId)
try to send a block which corresponds to blockid
Definition: MacWrtProStructures.cxx:2814
MacWrtProStructures::createZones
bool createZones()
finds the different objects zones
Definition: MacWrtProStructures.cxx:813
MacWrtProStructures::m_input
MWAWInputStreamPtr m_input
the main input
Definition: MacWrtProStructures.hxx:299
MacWrtProStructures::buildPageStructures
void buildPageStructures()
look for pages structures
Definition: MacWrtProStructures.cxx:1070
MacWrtProStructuresInternal::Font
Internal: the fonts.
Definition: MacWrtProStructures.cxx:322
MacWrtProStructuresInternal::Cell
Internal: the cell of a MacWrtProStructure.
Definition: MacWrtProStructures.cxx:388
MacWrtProStructures::readSelection
bool readSelection()
try to read a 16 bytes the zone which follow the char styles zone ( the selection?...
Definition: MacWrtProStructures.cxx:2516
MacWrtProStructures::~MacWrtProStructures
virtual ~MacWrtProStructures()
destructor
Definition: MacWrtProStructures.cxx:637
MacWrtProStructuresListenerState::isSent
bool isSent(int blockId)
returns true if the block is already sent ( or does not exists)
Definition: MacWrtProStructures.cxx:2808
MacWrtProStructures::isSent
bool isSent(int blockId)
returns true if the block is already sent ( or does not exists)
Definition: MacWrtProStructures.cxx:2631
MacWrtProStructuresListenerState::getPageBreaksPos
std::vector< int > getPageBreaksPos() const
return a list of page break position ( as some page break are soft )
Definition: MacWrtProStructures.cxx:2858
MacWrtProStructuresListenerState
an interface to transmit the info of MacWrtProStructures to a listener
Definition: MacWrtProStructures.hxx:70
MWAWInputStream.hxx
MWAWDebug.hxx
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:549
MacWrtProStructuresListenerState::m_version
int m_version
Definition: MacWrtProStructures.hxx:128
MacWrtProStructuresListenerState::resendAll
bool resendAll()
force resent data : font + paragraph
Definition: MacWrtProStructures.cxx:2945
MacWrtProStructures::m_asciiName
std::string m_asciiName
the debug file name
Definition: MacWrtProStructures.hxx:311
MacWrtProStructuresInternal::Paragraph
Internal: class to store the paragraph properties.
Definition: MacWrtProStructures.cxx:361
MacWrtProStructures::m_parserState
MWAWParserStatePtr m_parserState
the parser state
Definition: MacWrtProStructures.hxx:296
MacWrtProStructures::m_state
std::shared_ptr< MacWrtProStructuresInternal::State > m_state
the state
Definition: MacWrtProStructures.hxx:305
MacWrtProStructures::updatePageSpan
void updatePageSpan(int page, bool hasTitlePage, MWAWPageSpan &pageSpan)
update the page span
Definition: MacWrtProStructures.cxx:667
MacWrtProStructures::MacWrtProStructures
MacWrtProStructures(MacWrtProParser &mainParser)
constructor
Definition: MacWrtProStructures.cxx:626
MacWrtProStructuresListenerState::m_section
int m_section
Definition: MacWrtProStructures.hxx:136
MacWrtProStructures::getTextListener
MWAWTextListenerPtr & getTextListener()
returns the actual listener
Definition: MacWrtProStructures.cxx:655
MacWrtProParser
the main class to read a MacWrite II and MacWrite Pro file
Definition: MacWrtProParser.hxx:67
MWAWPosition.hxx
MacWrtProStructures::readStyles
bool readStyles()
try to read the paragraph styles zone which begins at address 0x200
Definition: MacWrtProStructures.cxx:1697
MacWrtProStructures::sendMainZone
bool sendMainZone()
send the main zone
Definition: MacWrtProStructures.cxx:1040
MacWrtProStructures::readSections
bool readSections(std::vector< MacWrtProStructuresInternal::Section > &sections)
try to read the section info ?
Definition: MacWrtProStructures.cxx:2394
MacWrtProParserInternal
Internal: the structures of a MacWrtProParser.
Definition: MacWrtProParser.cxx:61
MacWrtProStructures::m_asciiFile
libmwaw::DebugFile m_asciiFile
the debug file
Definition: MacWrtProStructures.hxx:308
MacWrtProStructuresListenerState::m_isMainZone
bool m_isMainZone
Definition: MacWrtProStructures.hxx:126
MacWrtProStructures::readFontsDef
bool readFontsDef()
try to read the list of fonts
Definition: MacWrtProStructures.cxx:1258
MacWrtProStructures::readParagraph
bool readParagraph(MacWrtProStructuresInternal::Paragraph &para)
try to read a paragraph
Definition: MacWrtProStructures.cxx:1452
MacWrtProStructuresInternal
Internal: the structures of a MacWrtProStructures.
Definition: MacWrtProStructures.cxx:58
MacWrtProStructuresListenerState::m_numTab
int m_numTab
Definition: MacWrtProStructures.hxx:134
MacWrtProStructures::readFont
bool readFont(MacWrtProStructuresInternal::Font &font)
try to read a font
Definition: MacWrtProStructures.cxx:1310
MacWrtProStructures::readStructB
bool readStructB()
try to read a zone which follow the fonts zone(checkme)
Definition: MacWrtProStructures.cxx:2589
MacWrtProStructures::getColor
bool getColor(int colId, MWAWColor &color) const
try to return the color corresponding to colId
Definition: MacWrtProStructures.cxx:714
MacWrtProStructures::readBlockV2
std::shared_ptr< MacWrtProStructuresInternal::Block > readBlockV2(int id)
try to read a block entry
Definition: MacWrtProStructures.cxx:1915