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 <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
69 class MacWrtProStructuresListenerState
70 {
71 public:
73 MacWrtProStructuresListenerState(std::shared_ptr<MacWrtProStructures> const &structures, bool mainZone, int version);
75 ~MacWrtProStructuresListenerState();
76
78 bool isSent(int graphicId);
80 bool send(int graphicId);
81
83 void sendSection(int numSection);
85 bool sendFont(int id);
87 bool sendParagraph(int id);
89 void sendChar(char c);
90
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
102 std::vector<int> getPageBreaksPos() const;
104 void insertSoftPageBreak();
105
106 protected:
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
135 class MacWrtProStructures
136 {
137 friend class MacWrtProParser;
138 friend class MacWrtProParserInternal::SubDocument;
139 friend struct MacWrtProStructuresInternal::Cell;
140 friend class MacWrtProStructuresListenerState;
141 public:
143 explicit MacWrtProStructures(MacWrtProParser &mainParser);
145 virtual ~MacWrtProStructures();
146
150 int version() const;
151
152 protected:
154 void init();
155
157 bool createZones(std::shared_ptr<MWAWStream> &stream, int numPages);
158
163 bool createZonesII(std::shared_ptr<MWAWStream> &stream, int numPages);
164
166 int numPages() const;
167
169 bool sendMainZone();
170
172 void updatePageSpan(int page, bool hasTitlePage, MWAWPageSpan &pageSpan);
173
175 void flushExtra();
176
178 void buildPageStructures();
179
181 void buildTableStructures();
182
183 //
184 // low level
185 //
186
188 bool readStyles(std::shared_ptr<MWAWStream> &stream);
189
191 bool readStyle(std::shared_ptr<MWAWStream> &stream, int styleId);
192
194 bool readCharStyles(std::shared_ptr<MWAWStream> &stream);
195
197 bool readParagraphs(std::shared_ptr<MWAWStream> &stream);
198
200 bool readParagraph(std::shared_ptr<MWAWStream> &stream, MacWrtProStructuresInternal::Paragraph &para);
201
203 bool readGraphicsList(std::shared_ptr<MWAWStream> &stream, int nuumPages);
205 std::shared_ptr<MacWrtProStructuresInternal::Graphic> readGraphic(std::shared_ptr<MWAWStream> &stream);
206
208 bool readPagesListII(std::shared_ptr<MWAWStream> const &stream, int numPages);
210 bool readPageII(std::shared_ptr<MWAWStream> const &stream, int wh, MacWrtProStructuresInternal::Page &page);
212 bool readGraphicII(std::shared_ptr<MWAWStream> const &stream, int id, bool mainGraphic, MacWrtProStructuresInternal::Graphic &graphic);
213
215 bool readFontsName(std::shared_ptr<MWAWStream> &stream);
216
218 bool readFontsDef(std::shared_ptr<MWAWStream> &stream);
219
221 bool readFont(std::shared_ptr<MWAWStream> &stream, MacWrtProStructuresInternal::Font &font);
222
224 bool readSections(std::shared_ptr<MWAWStream> &stream, std::vector<MacWrtProStructuresInternal::Section> &sections);
225
227 bool readSelection(std::shared_ptr<MWAWStream> &stream);
228
230 bool readStructB(std::shared_ptr<MWAWStream> &stream);
231
233 static bool readString(MWAWInputStreamPtr input, std::string &res);
234
236 bool getColor(int colId, MWAWColor &color) const;
237
239 bool getPattern(int patId, float &patternPercent) const;
240
242 bool getColor(int colId, int patId, MWAWColor &color) const;
243
245 bool isSent(int graphicId);
246
251 bool send(int graphicId, bool mainZone=false);
252
254 MWAWTextListenerPtr &getTextListener();
255
256 protected:
257 //
258 // data
259 //
260
262 MWAWParserStatePtr m_parserState;
263
265 MacWrtProParser &m_mainParser;
266
268 std::shared_ptr<MacWrtProStructuresInternal::State> m_state;
269
271 std::string m_asciiName;
272 };
273 #endif
274 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWDebug.hxx
MWAWEntry.hxx
MWAWInputStream.hxx
MWAWPosition.hxx
MWAWStream.hxx
MWAWPageSpan
A class which defines the page properties.
Definition: MWAWPageSpan.hxx:99
MacWrtProParserInternal::SubDocument
Internal: the subdocument of a MacWrtProParser.
Definition: MacWrtProParser.cxx:255
MacWrtProParser
the main class to read a MacWrite II and MacWrite Pro file
Definition: MacWrtProParser.hxx:68
MacWrtProStructuresListenerState
an interface to transmit the info of MacWrtProStructures to a listener
Definition: MacWrtProStructures.hxx:70
MacWrtProStructuresListenerState::m_numTab
int m_numTab
Definition: MacWrtProStructures.hxx:119
MacWrtProStructuresListenerState::MacWrtProStructuresListenerState
MacWrtProStructuresListenerState(std::shared_ptr< MacWrtProStructures > const &structures, bool mainZone, int version)
the constructor
Definition: MacWrtProStructures.cxx:2838
MacWrtProStructuresListenerState::sendChar
void sendChar(char c)
send a character
Definition: MacWrtProStructures.cxx:2939
MacWrtProStructuresListenerState::newPage
bool newPage(bool softBreak=false)
create a new page
Definition: MacWrtProStructures.cxx:2885
MacWrtProStructuresListenerState::m_structures
std::shared_ptr< MacWrtProStructures > m_structures
Definition: MacWrtProStructures.hxx:127
MacWrtProStructuresListenerState::sendFont
bool sendFont(int id)
try to send a character style
Definition: MacWrtProStructures.cxx:3014
MacWrtProStructuresListenerState::insertSoftPageBreak
void insertSoftPageBreak()
insert a page break ( if we are not on a new page )
Definition: MacWrtProStructures.cxx:2879
MacWrtProStructuresListenerState::send
bool send(int graphicId)
try to send a graphic which corresponds to graphicid
Definition: MacWrtProStructures.cxx:2869
MacWrtProStructuresListenerState::isSent
bool isSent(int graphicId)
returns true if the graphic is already sent ( or does not exists)
Definition: MacWrtProStructures.cxx:2863
MacWrtProStructuresListenerState::sendParagraph
bool sendParagraph(int id)
try to send a paragraph
Definition: MacWrtProStructures.cxx:3028
MacWrtProStructuresListenerState::m_actPage
int m_actPage
Definition: MacWrtProStructures.hxx:115
MacWrtProStructuresListenerState::m_section
int m_section
Definition: MacWrtProStructures.hxx:121
MacWrtProStructuresListenerState::m_version
int m_version
Definition: MacWrtProStructures.hxx:113
MacWrtProStructuresListenerState::m_numCols
int m_numCols
Definition: MacWrtProStructures.hxx:123
MacWrtProStructuresListenerState::sendSection
void sendSection(int numSection)
try to send the i^th section
Definition: MacWrtProStructures.cxx:3043
MacWrtProStructuresListenerState::numSection
int numSection() const
returns the actual section
Definition: MacWrtProStructures.hxx:92
MacWrtProStructuresListenerState::getPageBreaksPos
std::vector< int > getPageBreaksPos() const
return a list of page break position ( as some page break are soft )
Definition: MacWrtProStructures.cxx:2916
MacWrtProStructuresListenerState::m_newPageDone
bool m_newPageDone
Definition: MacWrtProStructures.hxx:125
MacWrtProStructuresListenerState::~MacWrtProStructuresListenerState
~MacWrtProStructuresListenerState()
the destructor
Definition: MacWrtProStructures.cxx:2859
MacWrtProStructuresListenerState::m_isMainZone
bool m_isMainZone
Definition: MacWrtProStructures.hxx:111
MacWrtProStructuresListenerState::m_actTab
int m_actTab
Definition: MacWrtProStructures.hxx:117
MacWrtProStructures
the main class to read the structures part of MacWrite Pro file
Definition: MacWrtProStructures.hxx:136
MacWrtProStructures::createZones
bool createZones(std::shared_ptr< MWAWStream > &stream, int numPages)
finds the different objects zones
Definition: MacWrtProStructures.cxx:921
MacWrtProStructures::readSelection
bool readSelection(std::shared_ptr< MWAWStream > &stream)
try to read a 16 bytes the zone which follow the char styles zone ( the selection?...
Definition: MacWrtProStructures.cxx:2561
MacWrtProStructures::readGraphicII
bool readGraphicII(std::shared_ptr< MWAWStream > const &stream, int id, bool mainGraphic, MacWrtProStructuresInternal::Graphic &graphic)
try to read a graphic structure: II
Definition: MacWrtProStructures.cxx:1949
MacWrtProStructures::getColor
bool getColor(int colId, MWAWColor &color) const
try to return the color corresponding to colId
Definition: MacWrtProStructures.cxx:822
MacWrtProStructures::readPagesListII
bool readPagesListII(std::shared_ptr< MWAWStream > const &stream, int numPages)
try to parse the list of page: II
Definition: MacWrtProStructures.cxx:1874
MacWrtProStructures::readFont
bool readFont(std::shared_ptr< MWAWStream > &stream, MacWrtProStructuresInternal::Font &font)
try to read a font
Definition: MacWrtProStructures.cxx:1356
MacWrtProStructures::readString
static bool readString(MWAWInputStreamPtr input, std::string &res)
try to read a string
Definition: MacWrtProStructures.cxx:2600
MacWrtProStructures::readStructB
bool readStructB(std::shared_ptr< MWAWStream > &stream)
try to read a zone which follow the fonts zone(checkme)
Definition: MacWrtProStructures.cxx:2633
MacWrtProStructures::init
void init()
inits all internal variables
Definition: MacWrtProStructures.cxx:746
MacWrtProStructures::readStyles
bool readStyles(std::shared_ptr< MWAWStream > &stream)
try to read the paragraph styles zone which begins at address 0x200
Definition: MacWrtProStructures.cxx:1738
MacWrtProStructures::readGraphic
std::shared_ptr< MacWrtProStructuresInternal::Graphic > readGraphic(std::shared_ptr< MWAWStream > &stream)
try to read a graphic entry: 1.0, 1.5
Definition: MacWrtProStructures.cxx:2162
MacWrtProStructures::numPages
int numPages() const
returns the number of pages
Definition: MacWrtProStructures.cxx:763
MacWrtProStructures::readStyle
bool readStyle(std::shared_ptr< MWAWStream > &stream, int styleId)
try to read a style
Definition: MacWrtProStructures.cxx:1780
MacWrtProStructures::version
int version() const
returns the file version.
Definition: MacWrtProStructures.cxx:751
MacWrtProStructures::readFontsDef
bool readFontsDef(std::shared_ptr< MWAWStream > &stream)
try to read the list of fonts
Definition: MacWrtProStructures.cxx:1309
MacWrtProStructures::m_state
std::shared_ptr< MacWrtProStructuresInternal::State > m_state
the state
Definition: MacWrtProStructures.hxx:268
MacWrtProStructures::buildPageStructures
void buildPageStructures()
look for pages structures
Definition: MacWrtProStructures.cxx:1121
MacWrtProStructures::MacWrtProStructures
MacWrtProStructures(MacWrtProParser &mainParser)
constructor
Definition: MacWrtProStructures.cxx:733
MacWrtProStructures::m_mainParser
MacWrtProParser & m_mainParser
the main parser
Definition: MacWrtProStructures.hxx:265
MacWrtProStructures::readFontsName
bool readFontsName(std::shared_ptr< MWAWStream > &stream)
try to read the fonts zone
Definition: MacWrtProStructures.cxx:1243
MacWrtProStructures::readParagraph
bool readParagraph(std::shared_ptr< MWAWStream > &stream, MacWrtProStructuresInternal::Paragraph &para)
try to read a paragraph
Definition: MacWrtProStructures.cxx:1494
MacWrtProStructures::flushExtra
void flushExtra()
flush not send zones
Definition: MacWrtProStructures.cxx:2774
MacWrtProStructures::readPageII
bool readPageII(std::shared_ptr< MWAWStream > const &stream, int wh, MacWrtProStructuresInternal::Page &page)
try to read a page entry: II
Definition: MacWrtProStructures.cxx:1894
MacWrtProStructures::isSent
bool isSent(int graphicId)
returns true if the graphic is already sent ( or does not exists)
Definition: MacWrtProStructures.cxx:2677
MacWrtProStructures::readSections
bool readSections(std::shared_ptr< MWAWStream > &stream, std::vector< MacWrtProStructuresInternal::Section > &sections)
try to read the section info ?
Definition: MacWrtProStructures.cxx:2437
MacWrtProStructures::readParagraphs
bool readParagraphs(std::shared_ptr< MWAWStream > &stream)
try to read a list of paragraph
Definition: MacWrtProStructures.cxx:1444
MacWrtProStructures::send
bool send(int graphicId, bool mainZone=false)
try to send a graphic which corresponds to graphicid
Definition: MacWrtProStructures.cxx:2688
MacWrtProStructures::createZonesII
bool createZonesII(std::shared_ptr< MWAWStream > &stream, int numPages)
finds the different objects zones in a MacWriteII file
Definition: MacWrtProStructures.cxx:1024
MacWrtProStructures::buildTableStructures
void buildTableStructures()
look for tables structures and if so, prepare data
Definition: MacWrtProStructures.cxx:1186
MacWrtProStructures::getPattern
bool getPattern(int patId, float &patternPercent) const
try to return the pattern corresponding to patId
Definition: MacWrtProStructures.cxx:880
MacWrtProStructures::~MacWrtProStructures
virtual ~MacWrtProStructures()
destructor
Definition: MacWrtProStructures.cxx:742
MacWrtProStructures::getTextListener
MWAWTextListenerPtr & getTextListener()
returns the actual listener
Definition: MacWrtProStructures.cxx:758
MacWrtProStructures::updatePageSpan
void updatePageSpan(int page, bool hasTitlePage, MWAWPageSpan &pageSpan)
update the page span
Definition: MacWrtProStructures.cxx:770
MacWrtProStructures::readGraphicsList
bool readGraphicsList(std::shared_ptr< MWAWStream > &stream, int nuumPages)
try to read the list of graphic entries: 1.0 1.5
Definition: MacWrtProStructures.cxx:2076
MacWrtProStructures::m_parserState
MWAWParserStatePtr m_parserState
the parser state
Definition: MacWrtProStructures.hxx:262
MacWrtProStructures::readCharStyles
bool readCharStyles(std::shared_ptr< MWAWStream > &stream)
try to read the character styles zone
Definition: MacWrtProStructures.cxx:1650
MacWrtProStructures::m_asciiName
std::string m_asciiName
the debug file name
Definition: MacWrtProStructures.hxx:271
MacWrtProStructures::sendMainZone
bool sendMainZone()
send the main zone
Definition: MacWrtProStructures.cxx:1091
MWAWParserStatePtr
std::shared_ptr< MWAWParserState > MWAWParserStatePtr
a smart pointer of MWAWParserState
Definition: libmwaw_internal.hxx:557
MWAWTextListenerPtr
std::shared_ptr< MWAWTextListener > MWAWTextListenerPtr
a smart pointer of MWAWTextListener
Definition: libmwaw_internal.hxx:567
MWAW_DEBUG_MSG
#define MWAW_DEBUG_MSG(M)
Definition: libmwaw_internal.hxx:129
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:551
MacWrtProParserInternal
Internal: the structures of a MacWrtProParser.
Definition: MacWrtProParser.cxx:62
MacWrtProStructuresInternal
Internal: the structures of a MacWrtProStructures.
Definition: MacWrtProStructures.cxx:59
MWAWColor
the class to store a color
Definition: libmwaw_internal.hxx:192
MacWrtProStructuresInternal::Cell
Internal: the cell of a MacWrtProStructure.
Definition: MacWrtProStructures.cxx:495
MacWrtProStructuresInternal::Font
Internal: the fonts.
Definition: MacWrtProStructures.cxx:428
MacWrtProStructuresInternal::Graphic
Internal: the graphic structure.
Definition: MacWrtProStructures.cxx:61
MacWrtProStructuresInternal::Page
Internal: a page.
Definition: MacWrtProStructures.cxx:398
MacWrtProStructuresInternal::Paragraph
Internal: class to store the paragraph properties.
Definition: MacWrtProStructures.cxx:467