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 /*
35  * Document data used by the Claris Works parser
36  *
37  */
38 #ifndef CLARIS_WKS_DOCUMENT
39 #  define CLARIS_WKS_DOCUMENT
40 
41 #include <vector>
42 
43 #include "libmwaw_internal.hxx"
44 
45 #include "MWAWParser.hxx"
46 #include "MWAWPosition.hxx"
47 
48 #include "ClarisWksStruct.hxx"
49 
50 class MWAWSection;
51 
52 namespace ClarisWksDocumentInternal
53 {
54 class SubDocument;
55 
56 struct State;
57 }
58 
59 class ClarisWksParser;
60 class ClarisWksBMParser;
61 class ClarisWksPRParser;
62 class ClarisWksSSParser;
63 
64 class ClarisWksDatabase;
65 class ClarisWksGraph;
66 class ClarisWksStyleManager;
67 class ClarisWksPresentation;
68 class ClarisWksSpreadsheet;
69 class ClarisWksTable;
70 class ClarisWksText;
71 
72 //! main document information used to create a ClarisWorks file
73 class ClarisWksDocument
74 {
75 public:
76   friend class ClarisWksParser;
77   friend class ClarisWksBMParser;
78   friend class ClarisWksPRParser;
79   friend class ClarisWksSSParser;
80   friend class ClarisWksDocumentInternal::SubDocument;
81   //! constructor
82   explicit ClarisWksDocument(MWAWParser &parser);
83   //! virtual destructor
84   ~ClarisWksDocument();
85 
86   //! checks if the document header is correct (or not)
87   bool checkHeader(MWAWHeader *header, bool strict=false);
88 
89   //! finds the different objects zones
90   bool createZones();
91 
92   //! returns the document number of page
93   int numPages() const;
94   //! returns the number of expected pages ( accross pages x down page)
95   MWAWVec2i getDocumentPages();
96   /** returns the document meta data */
97   librevenge::RVNGPropertyList const &getDocumentMetaData() const;
98   //! returns the page height, ie. paper size less margin (in inches) less header/footer size
99   double getTextHeight() const;
100   //! returns the page left top point ( in inches)
101   MWAWVec2f getPageLeftTop() const;
102   /** updates the page span list */
103   void updatePageSpanList(std::vector<MWAWPageSpan> &spanList);
104   /** updates the page span list (and returns a master page)*/
105   void updatePageSpanList(std::vector<MWAWPageSpan> &spanList, MWAWPageSpan &master);
106 
107   //! returns the main document section
108   MWAWSection getMainSection() const;
109   //! return the zone corresponding to an id ( low level)
110   std::shared_ptr<ClarisWksStruct::DSET> getZone(int zId) const;
111   //! try to update the child page of each zone
112   void updateChildPositions();
113   /** send a page break */
114   void newPage(int page, bool softBreak=false);
115   /** returns the list of the main zones */
116   std::vector<int> const &getMainZonesList() const;
117   //! indicates that a zone is parser
118   void forceParsed(int zoneId);
119   //! check if we can send a zone as a graphic
120   bool canSendZoneAsGraphic(int number) const;
121   //! try to send a zone
122   bool sendZone(int zoneId, MWAWListenerPtr listener=MWAWListenerPtr(), MWAWPosition pos=MWAWPosition());
123   //! try to send a database picture
124   bool sendDatabasePictZone(int pictId, MWAWListenerPtr listener=MWAWListenerPtr(), MWAWPosition pos=MWAWPosition());
125   /** ask the main parser to create a document to send a footnote */
126   void sendFootnote(int zoneId);
127 
128   //! returns the main parser
getMainParser()129   MWAWParser &getMainParser()
130   {
131     return *m_parser;
132   }
133   //! returns the style manager
getStyleManager()134   std::shared_ptr<ClarisWksStyleManager> getStyleManager()
135   {
136     return m_styleManager;
137   }
138   //! returns the database parser
getDatabaseParser()139   std::shared_ptr<ClarisWksDatabase> getDatabaseParser()
140   {
141     return m_databaseParser;
142   }
143   //! returns the graph parser
getGraphParser()144   std::shared_ptr<ClarisWksGraph> getGraphParser()
145   {
146     return m_graphParser;
147   }
148   //! returns the presentation parser
getPresentationParser()149   std::shared_ptr<ClarisWksPresentation> getPresentationParser()
150   {
151     return m_presentationParser;
152   }
153   //! returns the spreadsheet parser
getSpreadsheetParser()154   std::shared_ptr<ClarisWksSpreadsheet> getSpreadsheetParser()
155   {
156     return m_spreadsheetParser;
157   }
158   //! returns the table parser
getTableParser()159   std::shared_ptr<ClarisWksTable> getTableParser()
160   {
161     return m_tableParser;
162   }
163   //! returns the text parser
getTextParser()164   std::shared_ptr<ClarisWksText> getTextParser()
165   {
166     return m_textParser;
167   }
168 
169   //! read a zone
170   bool readZone();
171   //! reads the document header
172   bool readDocHeader();
173   //! reads the document info part ( end of the header)
174   bool readDocInfo();
175   //! read the print info zone
176   bool readPrintInfo();
177 
178   // THE NAMED ENTRY
179 
180   //! reads the end table ( appears in v3.0 : file version ? )
181   bool readEndTable(long &eof);
182 
183   /* sequence of plist of printer : in v6 */
184   bool readCPRT(MWAWEntry const &entry);
185 
186   /* read the list of mark */
187   bool readMARKList(MWAWEntry const &entry);
188   /* read a URL mark */
189   bool readURL(long endPos);
190   /* read a bookmark mark */
191   bool readBookmark(long endPos);
192   /* read a document mark */
193   bool readDocumentMark(long endPos);
194   /* read a end mark */
195   bool readEndMark(long endPos);
196 
197   /* read the document summary */
198   bool readDSUM(MWAWEntry const &entry, bool inHeader);
199   /* SNAP (in v6) : size[4]/size[2] picture... */
200   bool readSNAP(MWAWEntry const &entry);
201   /* read the temporary file name ? */
202   bool readTNAM(MWAWEntry const &entry);
203 
204   //
205   // low level
206   //
207 
208   /** reads the zone DSET
209 
210       \note set complete to true if we read all the zone */
211   std::shared_ptr<ClarisWksStruct::DSET> readDSET(bool &complete);
212   /** try to type the main zones */
213   void typeMainZones();
214   /** try to type the main zones recursif, returns the father id*/
215   int typeMainZonesRec(int zId, ClarisWksStruct::DSET::Position type, int maxHeight);
216   /** try to find the zone dags structure... */
217   bool exploreZonesGraph();
218   /** try to find the zone tree graph ( DSF) function*/
219   bool exploreZonesGraphRec(int zId, std::set<int> &notDoneList);
220   /** remove uneeded edge (mainly header/footer edges in main graph) */
221   void cleanZonesGraph();
222 
223   /** try to read a structured zone list of cells */
224   bool readStructCellZone(char const *zoneName, bool hasEntete, std::vector<MWAWVec2i> &res);
225   /* read a list of string zone */
226   bool readStringList(char const *zoneName, bool hasEntete, std::vector<std::string> &res);
227   /** try to read a structured zone list of picture definition: v5-v6 */
228   bool readDataLinkList();
229 
230   //! try to read a unknown zone which appear to be filled at least in some v2 database file
231   bool readZoneA();
232   /** small fonction used to check unusual endian ordering of a list of int16_t, int32_t*/
233   void checkOrdering(std::vector<int16_t> &vec16, std::vector<int32_t> &vec32) const;
234 
235 protected:
236   //! returns the final page span to use for the document
237   MWAWPageSpan getFinalPageSpan() const;
238   //! the state
239   std::shared_ptr<ClarisWksDocumentInternal::State> m_state;
240 public:
241   //! the parser state
242   std::shared_ptr<MWAWParserState> m_parserState;
243 
244 protected:
245   //! the main parser
246   MWAWParser *m_parser;
247   //! the style manager
248   std::shared_ptr<ClarisWksStyleManager> m_styleManager;
249 
250   //! the database parser
251   std::shared_ptr<ClarisWksDatabase> m_databaseParser;
252   //! the graph parser
253   std::shared_ptr<ClarisWksGraph> m_graphParser;
254   //! the spreadsheet parser
255   std::shared_ptr<ClarisWksPresentation> m_presentationParser;
256   //! the spreadsheet parser
257   std::shared_ptr<ClarisWksSpreadsheet> m_spreadsheetParser;
258   //! the table parser
259   std::shared_ptr<ClarisWksTable> m_tableParser;
260   //! the text parser
261   std::shared_ptr<ClarisWksText> m_textParser;
262 
263   //
264   // the callback
265   //
266 
267   /** callback used to send a page break */
268   typedef void (MWAWParser::* NewPage)(int page, bool softBreak);
269   //! callback used to send a footnote
270   typedef void (MWAWParser::* SendFootnote)(int zoneId);
271 
272   /** the new page callback */
273   NewPage m_newPage;
274   /** the send footnote callback */
275   SendFootnote m_sendFootnote;
276 
277 private:
278   ClarisWksDocument(ClarisWksDocument const &orig) = delete;
279   ClarisWksDocument operator=(ClarisWksDocument const &orig) = delete;
280 };
281 
282 #endif
283 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
284