Debian Codegraph @

src/lib/MacWrtProParser.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
35 #ifndef MAC_WRT_PRO_PARSER
36 # define MAC_WRT_PRO_PARSER
37
38 #include <list>
39 #include <string>
40 #include <vector>
41
42 #include "MWAWDebug.hxx"
43 #include "MWAWEntry.hxx"
44 #include "MWAWGraphicStyle.hxx"
45 #include "MWAWInputStream.hxx"
46
47 #include "MWAWParser.hxx"
48
49 namespace MacWrtProParserInternal
50 {
51 struct State;
52 struct TextZoneData;
53 struct TextZone;
54 struct Token;
55 struct Zone;
56 class SubDocument;
57 }
58
59 class MacWrtProStructures;
60 class MacWrtProStructuresListenerState;
61
62 /** \brief the main class to read a MacWrite II and MacWrite Pro file
63 *
64 *
65 *
66 */
67 class MacWrtProParser final : public MWAWTextParser
68 {
69 friend class MacWrtProStructures;
70 friend class MacWrtProStructuresListenerState;
71 friend class MacWrtProParserInternal::SubDocument;
72
73 public:
74 //! constructor
75 MacWrtProParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
76 //! destructor
77 ~MacWrtProParser() final;
78
79 //! checks if the document header is correct (or not)
80 bool checkHeader(MWAWHeader *header, bool strict=false) final;
81
82 // the main parse function
83 void parse(librevenge::RVNGTextInterface *documentInterface) final;
84
85 protected:
86 //! inits all internal variables
87 void init();
88
89 //! creates the listener which will be associated to the document
90 void createDocument(librevenge::RVNGTextInterface *documentInterface);
91
92 //! finds the different objects zones
93 bool createZones();
94
95 //! returns a stream corresponding to a block
96 std::shared_ptr<MWAWStream> getStreamForBlock(int bId);
97
98 //! return the chain list of block ( used to get free blocks): MWPro only
99 bool getFreeZoneList(std::vector<int> &blockLists);
100
101 /** parse a data zone
102
103 \note type=0 ( text entry), type = 1 ( graphic entry ), other unknown
104 */
105 bool parseDataZone(int blockId, int type);
106
107 /** parse a text zone */
108 bool parseTextZone(std::shared_ptr<MacWrtProParserInternal::Zone> zone);
109
110 /** try to read the text block entries */
111 bool readTextEntries(std::shared_ptr<MacWrtProParserInternal::Zone> zone,
112 std::vector<MWAWEntry> &res, int textLength);
113 /** try to read the text id entries */
114 bool readTextIds(std::shared_ptr<MacWrtProParserInternal::Zone> zone,
115 std::vector<MacWrtProParserInternal::TextZoneData> &res,
116 int textLength, int type);
117 /** try to read the text token entries */
118 bool readTextTokens(std::shared_ptr<MacWrtProParserInternal::Zone> zone,
119 std::vector<MacWrtProParserInternal::Token> &res,
120 int textLength);
121
122 /** return the list of graphicid called by token. A hack to help
123 structures to retrieve the page attachment */
124 std::vector<int> const &getGraphicIdCalledByToken() const;
125
126 //! returns the page height, ie. paper size less margin (in inches)
127 float pageHeight() const;
128 //! returns the document number of columns and the column separator width in inch( filed in MWII)
129 int numColumns(double &sep) const;
130
131 //! adds a new page
132 void newPage(int number, bool softBreak=false);
133 //! returns true if the document has a title page
134 bool hasTitlePage() const;
135 //! returns a subdocument corresponding to a blockid
136 std::shared_ptr<MWAWSubDocument> getSubDocument(int blockId);
137
138 //
139 // interface with MacWrtProParserStructures
140 //
141
142 //! send a text box
143 bool sendTextZone(int blockId, bool mainZone = false);
144
145 //! compute the number of hard page break
146 int findNumHardBreaks(int blockId);
147
148 //! try to send a picture
149 bool sendPictureZone(int blockId, MWAWPosition const &pictPos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
150
151 //! send a textbox zone
152 bool sendTextBoxZone(int blockId, MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
153 //! try to send an empty zone (can exist in MacWrtPro1.5)
154 bool sendEmptyFrameZone(MWAWPosition const &pos, MWAWGraphicStyle const &style);
155
156 //
157 // low level
158 //
159
160 //! read the print info zone
161 bool readPrintInfo();
162
163 //! try to read the doc header zone
164 bool readDocHeader();
165
166 //! try to send a picture
167 bool sendPicture(std::shared_ptr<MacWrtProParserInternal::Zone> zone, MWAWPosition pictPos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
168
169 //! try to send a text
170 bool sendText(std::shared_ptr<MacWrtProParserInternal::TextZone> zone, bool mainZone = false);
171
172 //! compute the number of hard page break
173 int findNumHardBreaks(std::shared_ptr<MacWrtProParserInternal::TextZone> zone);
174
175 //! convert a date in a string (for debugging)
176 static std::string convertDateToDebugString(unsigned date);
177 //! a debug function which can be used to save the unparsed block
178 void checkUnparsed();
179
180 protected:
181 //
182 // data
183 //
184 //! the state
185 std::shared_ptr<MacWrtProParserInternal::State> m_state;
186
187 //! the structures parser
188 std::shared_ptr<MacWrtProStructures> m_structures;
189 };
190 #endif
191 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: