1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 
3 /* libstaroffice
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  * StarWriterStruct to read/parse some basic writer structure in StarOffice documents
36  *
37  */
38 #ifndef STAR_WRITER_STRUCT
39 #  define STAR_WRITER_STRUCT
40 
41 #include <ostream>
42 #include <vector>
43 
44 #include "libstaroffice_internal.hxx"
45 
46 #include "STOFFDebug.hxx"
47 
48 namespace StarFormatManagerInternal
49 {
50 struct FormatDef;
51 }
52 class StarAttribute;
53 class StarObject;
54 class StarZone;
55 
56 /** \brief namespace use to keep basic writer structure */
57 namespace StarWriterStruct
58 {
59 /** \brief struct use an attribute and a position
60  */
61 struct Attribute {
62 public:
63   //! constructor
AttributeStarWriterStruct::Attribute64   Attribute()
65     : m_attribute()
66     , m_position(-1,-1)
67   {
68   }
69   //! destructor
70   ~Attribute();
71   //! operator<<
72   friend std::ostream &operator<<(std::ostream &o, Attribute const &attribute);
73   //! try to read a attribute: 'A'
74   bool read(StarZone &zone, StarObject &object);
75   //! try to read a list of attribute: 'S'
76   static bool readList(StarZone &zone, std::vector<Attribute> &attributeList, StarObject &object);
77   //! the attribute
78   std::shared_ptr<StarAttribute> m_attribute;
79   //! the begin/end position
80   STOFFVec2i m_position;
81 };
82 
83 /** \brief structure to store a bookmark
84  */
85 class Bookmark
86 {
87 public:
88   //! the constructor
Bookmark()89   Bookmark()
90     : m_shortName("")
91     , m_name("")
92     , m_offset(0)
93     , m_key(0)
94     , m_modifier(0)
95   {
96   }
97   //! operator<<
98   friend std::ostream &operator<<(std::ostream &o, Bookmark const &mark);
99   //! try to read a mark
100   bool read(StarZone &zone);
101   //! try to read a list of bookmark
102   static bool readList(StarZone &zone, std::vector<Bookmark> &markList);
103   //! the shortname
104   librevenge::RVNGString m_shortName;
105   //! the name
106   librevenge::RVNGString m_name;
107   //! the offset
108   int m_offset;
109   //! the key
110   int m_key;
111   //! the modifier
112   int m_modifier;
113   //! the macros names
114   librevenge::RVNGString m_macroNames[4];
115 };
116 
117 /** \brief structure to store a databaseName in a text zone
118  */
119 struct DatabaseName {
120 public:
121   //! constructor
DatabaseNameStarWriterStruct::DatabaseName122   DatabaseName()
123     : m_sql("")
124     , m_dataList()
125   {
126   }
127   //! operator<<
128   friend std::ostream &operator<<(std::ostream &o, DatabaseName const &databaseName);
129   //! try to read a databaseName: 'D'
130   bool read(StarZone &zone);
131   //! a data of a DatabaseName
132   struct Data {
133     //! constructor
DataStarWriterStruct::DatabaseName::Data134     Data()
135       : m_name("")
136       , m_selection(0,0)
137     {
138     }
139     //! operator<<
operator <<StarWriterStruct::DatabaseName140     friend std::ostream &operator<<(std::ostream &o, Data const &data)
141     {
142       o << data.m_name.cstr() << ",";
143       if (data.m_selection!=STOFFVec2i(0,0)) o << "select=" << STOFFVec2i(0,0) << ",";
144       return o;
145     }
146     //! the name
147     librevenge::RVNGString m_name;
148     //! the start/end position
149     STOFFVec2i m_selection;
150   };
151   //! the names: database, table
152   librevenge::RVNGString m_names[2];
153   //! the SQL string
154   librevenge::RVNGString m_sql;
155   //! the list of data
156   std::vector<Data> m_dataList;
157 };
158 
159 /** \brief structure to store a dictionary in a text zone
160  */
161 struct Dictionary {
162 public:
163   //! constructor
DictionaryStarWriterStruct::Dictionary164   Dictionary()
165     : m_dataList()
166   {
167   }
168   //! operator<<
169   friend std::ostream &operator<<(std::ostream &o, Dictionary const &dictionary);
170   //! try to read a dictionary: 'j'
171   bool read(StarZone &zone);
172   //! a data of a Dictionary
173   struct Data {
174     //! constructor
DataStarWriterStruct::Dictionary::Data175     Data()
176       : m_name("")
177       , m_language(0)
178       , m_id(0)
179       , m_spellWrong(true)
180     {
181     }
182     //! operator<<
operator <<StarWriterStruct::Dictionary183     friend std::ostream &operator<<(std::ostream &o, Data const &data)
184     {
185       o << data.m_name.cstr() << ",";
186       if (data.m_language) o << "language=" << data.m_language << ",";
187       if (data.m_id) o << "id=" << data.m_id << ",";
188       if (data.m_spellWrong) o << "spellWrong,";
189       return o;
190     }
191     //! the name
192     librevenge::RVNGString m_name;
193     //! the language
194     int m_language;
195     //! the id
196     int m_id;
197     //! a flag to know if we do spell or not
198     bool m_spellWrong;
199   };
200   //! the list of data
201   std::vector<Data> m_dataList;
202 };
203 
204 /** \brief the doc statistic
205  */
206 struct DocStats {
207 public:
208   //! constructor
DocStatsStarWriterStruct::DocStats209   DocStats()
210     : m_isModified(false)
211   {
212     for (long &number : m_numbers) number=0;
213   }
214   //! operator<<
215   friend std::ostream &operator<<(std::ostream &o, DocStats const &docStats);
216   //! try to read a docStats: 'd'
217   bool read(StarZone &zone);
218   //! the list of number: tbl, graf, ole, page, para, word, char
219   long m_numbers[7];
220   //! modified flags
221   bool m_isModified;
222 };
223 
224 /** \brief structure to store a macro in a text zone
225  */
226 struct Macro {
227 public:
228   //! constructor
MacroStarWriterStruct::Macro229   Macro()
230     : m_key(0)
231     , m_scriptType(0)
232   {
233   }
234   //! operator<<
235   friend std::ostream &operator<<(std::ostream &o, Macro const &macro);
236   //! try to read a macro: 'm'
237   bool read(StarZone &zone);
238   //! try to read a list of macro: 'M'
239   static bool readList(StarZone &zone, std::vector<Macro> &macroLis);
240   //! the key
241   int m_key;
242   //! the names
243   librevenge::RVNGString m_names[2];
244   //! the scriptType
245   int m_scriptType;
246 };
247 
248 /** \brief structure to store a mark in a text zone
249  */
250 struct Mark {
251 public:
252   //! constructor
MarkStarWriterStruct::Mark253   Mark()
254     : m_type(-1)
255     , m_id(-1)
256     , m_offset(-1)
257   {
258   }
259   //! operator<<
260   friend std::ostream &operator<<(std::ostream &o, Mark const &mark);
261   //! try to read a mark
262   bool read(StarZone &zone);
263   //! the type:  2: bookmark-start, 3:bookmark-end
264   int m_type;
265   //! the id
266   int m_id;
267   //! the offset
268   int m_offset;
269 };
270 
271 /** \brief structure to store a nodeRedline in a text zone
272  */
273 struct NodeRedline {
274 public:
275   //! constructor
NodeRedlineStarWriterStruct::NodeRedline276   NodeRedline()
277     : m_id(-1)
278     , m_offset(-1)
279     , m_flags(0)
280   {
281   }
282   //! operator<<
283   friend std::ostream &operator<<(std::ostream &o, NodeRedline const &nodeRedline);
284   //! try to read a nodeRedline
285   bool read(StarZone &zone);
286   //! the id
287   int m_id;
288   //! the offset
289   int m_offset;
290   //! the flags
291   int m_flags;
292 };
293 
294 /** \brief structure to store a endnoteInfo or a footnoteInfo in a text zone
295  */
296 struct NoteInfo {
297 public:
298   //! constructor
NoteInfoStarWriterStruct::NoteInfo299   explicit NoteInfo(bool isFootnote)
300     : m_isFootnote(isFootnote)
301     , m_type(0)
302     , m_ftnOffset(0)
303     , m_posType(0)
304     , m_numType(0)
305   {
306     for (int &i : m_idx) i=0xFFFF;
307   }
308   //! operator<<
309   friend std::ostream &operator<<(std::ostream &o, NoteInfo const &noteInfo);
310   //! try to read a noteInfo
311   bool read(StarZone &zone);
312   //! a flag to know if this corresponds to a footnote or a endnote
313   bool m_isFootnote;
314   //! the type
315   int m_type;
316   //! the list of idx: the page, the coll, the char and the anchorChar
317   int m_idx[4];
318   //! the ftnOffset
319   int m_ftnOffset;
320   //! the strings: prefix, suffix, quoValis, ergoSum
321   librevenge::RVNGString m_strings[4];
322   //! the posType
323   int m_posType;
324   //! the numType
325   int m_numType;
326 };
327 
328 /** \brief the doc statistic
329  */
330 struct PrintData {
331 public:
332   //! constructor
PrintDataStarWriterStruct::PrintData333   PrintData()
334     : m_flags(0)
335     , m_colRow(1,1)
336   {
337     for (int &spacing : m_spacings) spacing=0;
338   }
339   //! operator<<
340   friend std::ostream &operator<<(std::ostream &o, PrintData const &printData);
341   //! try to read a printData: '8'
342   bool read(StarZone &zone);
343   //! the flags
344   int m_flags;
345   //! the row, col dim
346   STOFFVec2i m_colRow;
347   //! the spaces: left, right, top, bottom, horizontal, verticals
348   int m_spacings[6];
349 };
350 
351 /** \brief structure to store a redline in a text zone
352  */
353 struct Redline {
354 public:
355   //! constructor
RedlineStarWriterStruct::Redline356   Redline()
357     : m_type(0)
358     , m_stringId(0)
359     , m_date(0)
360     , m_time(0)
361     , m_comment()
362   {
363   }
364   //! operator<<
365   friend std::ostream &operator<<(std::ostream &o, Redline const &redline);
366   //! try to read a redline : D
367   bool read(StarZone &zone);
368   //! try to read a list of redline : R
369   static bool readList(StarZone &zone, std::vector<Redline> &redlineList);
370   //! try to read a list of list of redline : V
371   static bool readListList(StarZone &zone, std::vector<std::vector<Redline> > &redlineListList);
372   //! the type
373   int m_type;
374   //! the stringId
375   int m_stringId;
376   //! the date
377   long m_date;
378   //! the time
379   long m_time;
380   //! the comment
381   librevenge::RVNGString m_comment;
382 };
383 
384 /** \brief structure to store a TOX in a text zone
385  */
386 struct TOX {
387 public:
388   //! constructor
TOXStarWriterStruct::TOX389   TOX()
390     : m_type(0)
391     , m_createType(0)
392     , m_captionDisplay(0)
393     , m_styleId(0xFFFF)
394     , m_data(0)
395     , m_formFlags(0)
396     , m_title("")
397     , m_name("")
398     , m_OLEOptions(0)
399     , m_stringIdList()
400     , m_styleList()
401     , m_titleLength()
402     , m_formatList()
403   {
404     for (int &stringId : m_stringIds) stringId=0xFFFF;
405   }
406   //! destructor
407   ~TOX();
408   //! operator<<
409   friend std::ostream &operator<<(std::ostream &o, TOX const &tox);
410   //! try to read a TOX
411   bool read(StarZone &zone, StarObject &object);
412   //! try to read a list of TOX
413   static bool readList(StarZone &zone, std::vector<TOX> &toxList, StarObject &object);
414 
415   //! a style
416   struct Style {
417     //! constructor
StyleStarWriterStruct::TOX::Style418     Style()
419       : m_level(0)
420       , m_names()
421     {
422     }
423     //! operator<<
operator <<StarWriterStruct::TOX424     friend std::ostream &operator<<(std::ostream &o, Style const &style)
425     {
426       o << "level=" << style.m_level << ",";
427       if (!style.m_names.empty()) {
428         o << "names=[";
429         for (auto const &name : style.m_names) o << name.cstr() << ",";
430         o << "],";
431       }
432       return o;
433     }
434     //! the level
435     int m_level;
436     //! the list of names
437     std::vector<librevenge::RVNGString> m_names;
438   };
439   //! the type
440   int m_type;
441   //! the createType
442   int m_createType;
443   //! the captionDisplay
444   int m_captionDisplay;
445   //! the string id, the seq string id, the sect string id
446   int m_stringIds[3];
447   //! the style id
448   int m_styleId;
449   //! the number of data?
450   int m_data;
451   //! the format flags?
452   int m_formFlags;
453   //! the title
454   librevenge::RVNGString m_title;
455   //! the name
456   librevenge::RVNGString m_name;
457   //! the ole options
458   int m_OLEOptions;
459   //! a list of template string ids
460   std::vector<int> m_stringIdList;
461   //! a list of style names?
462   std::vector<Style> m_styleList;
463   //! the title length
464   long m_titleLength;
465   //! the format
466   std::vector<std::shared_ptr<StarFormatManagerInternal::FormatDef> > m_formatList;
467 };
468 
469 /** \brief structure to store a TOX51 in a text zone
470  */
471 struct TOX51 {
472 public:
473   //! constructor
TOX51StarWriterStruct::TOX51474   TOX51()
475     : m_typeName("")
476     , m_type(0)
477     , m_createType(0)
478     , m_firstTabPos(0)
479     , m_title("")
480     , m_patternList()
481     , m_stringIdList()
482     , m_infLevel(0)
483   {
484   }
485   //! destructor
486   ~TOX51();
487   //! operator<<
488   friend std::ostream &operator<<(std::ostream &o, TOX51 const &tox);
489   //! try to read a TOX51
490   bool read(StarZone &zone, StarObject &object);
491   //! try to read a list of TOX51
492   static bool readList(StarZone &zone, std::vector<TOX51> &toxList, StarObject &object);
493 
494   //! the typeName
495   librevenge::RVNGString m_typeName;
496   //! the type
497   int m_type;
498   //! the createType
499   int m_createType;
500   //! the firstTabPos
501   int m_firstTabPos;
502   //! the title
503   librevenge::RVNGString m_title;
504   //! the pattern list
505   std::vector<librevenge::RVNGString> m_patternList;
506   //! a list of template string ids
507   std::vector<int> m_stringIdList;
508   //! the inf level
509   int m_infLevel;
510 };
511 
512 }
513 #endif
514 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
515