Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libstaroffice/src/lib/StarWriterStruct.hxx
Line
Count
Source
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
64
  Attribute()
65
312k
    : m_attribute()
66
312k
    , m_position(-1,-1)
67
312k
  {
68
312k
  }
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
89
  Bookmark()
90
1.87k
    : m_shortName("")
91
1.87k
    , m_name("")
92
1.87k
    , m_offset(0)
93
1.87k
    , m_key(0)
94
1.87k
    , m_modifier(0)
95
1.87k
  {
96
1.87k
  }
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
122
  DatabaseName()
123
9.66k
    : m_sql("")
124
9.66k
    , m_dataList()
125
9.66k
  {
126
9.66k
  }
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
134
    Data()
135
1.66k
      : m_name("")
136
1.66k
      , m_selection(0,0)
137
1.66k
    {
138
1.66k
    }
139
    //! operator<<
140
    friend std::ostream &operator<<(std::ostream &o, Data const &data)
141
0
    {
142
0
      o << data.m_name.cstr() << ",";
143
0
      if (data.m_selection!=STOFFVec2i(0,0)) o << "select=" << STOFFVec2i(0,0) << ",";
144
0
      return o;
145
0
    }
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
164
  Dictionary()
165
2.72k
    : m_dataList()
166
2.72k
  {
167
2.72k
  }
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
175
    Data()
176
10.4k
      : m_name("")
177
10.4k
      , m_language(0)
178
10.4k
      , m_id(0)
179
10.4k
      , m_spellWrong(true)
180
10.4k
    {
181
10.4k
    }
182
    //! operator<<
183
    friend std::ostream &operator<<(std::ostream &o, Data const &data)
184
0
    {
185
0
      o << data.m_name.cstr() << ",";
186
0
      if (data.m_language) o << "language=" << data.m_language << ",";
187
0
      if (data.m_id) o << "id=" << data.m_id << ",";
188
0
      if (data.m_spellWrong) o << "spellWrong,";
189
0
      return o;
190
0
    }
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
209
  DocStats()
210
7.61k
    : m_isModified(false)
211
7.61k
  {
212
53.3k
    for (long &number : m_numbers) number=0;
213
7.61k
  }
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
229
  Macro()
230
0
    : m_key(0)
231
0
    , m_scriptType(0)
232
0
  {
233
0
  }
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
253
  Mark()
254
3.85k
    : m_type(-1)
255
3.85k
    , m_id(-1)
256
3.85k
    , m_offset(-1)
257
3.85k
  {
258
3.85k
  }
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
276
  NodeRedline()
277
1.01k
    : m_id(-1)
278
1.01k
    , m_offset(-1)
279
1.01k
    , m_flags(0)
280
1.01k
  {
281
1.01k
  }
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
299
  explicit NoteInfo(bool isFootnote)
300
13.1k
    : m_isFootnote(isFootnote)
301
13.1k
    , m_type(0)
302
13.1k
    , m_ftnOffset(0)
303
13.1k
    , m_posType(0)
304
13.1k
    , m_numType(0)
305
13.1k
  {
306
52.4k
    for (int &i : m_idx) i=0xFFFF;
307
13.1k
  }
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
333
  PrintData()
334
278
    : m_flags(0)
335
278
    , m_colRow(1,1)
336
278
  {
337
1.66k
    for (int &spacing : m_spacings) spacing=0;
338
278
  }
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
356
  Redline()
357
1
    : m_type(0)
358
1
    , m_stringId(0)
359
1
    , m_date(0)
360
1
    , m_time(0)
361
1
    , m_comment()
362
1
  {
363
1
  }
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
389
  TOX()
390
1.19k
    : m_type(0)
391
1.19k
    , m_createType(0)
392
1.19k
    , m_captionDisplay(0)
393
1.19k
    , m_styleId(0xFFFF)
394
1.19k
    , m_data(0)
395
1.19k
    , m_formFlags(0)
396
1.19k
    , m_title("")
397
1.19k
    , m_name("")
398
1.19k
    , m_OLEOptions(0)
399
1.19k
    , m_stringIdList()
400
1.19k
    , m_styleList()
401
    , m_titleLength()
402
1.19k
    , m_formatList()
403
1.19k
  {
404
3.58k
    for (int &stringId : m_stringIds) stringId=0xFFFF;
405
1.19k
  }
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
418
    Style()
419
2.82k
      : m_level(0)
420
2.82k
      , m_names()
421
2.82k
    {
422
2.82k
    }
423
    //! operator<<
424
    friend std::ostream &operator<<(std::ostream &o, Style const &style)
425
0
    {
426
0
      o << "level=" << style.m_level << ",";
427
0
      if (!style.m_names.empty()) {
428
0
        o << "names=[";
429
0
        for (auto const &name : style.m_names) o << name.cstr() << ",";
430
0
        o << "],";
431
0
      }
432
0
      return o;
433
0
    }
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
474
  TOX51()
475
1.38k
    : m_typeName("")
476
1.38k
    , m_type(0)
477
1.38k
    , m_createType(0)
478
1.38k
    , m_firstTabPos(0)
479
1.38k
    , m_title("")
480
1.38k
    , m_patternList()
481
1.38k
    , m_stringIdList()
482
1.38k
    , m_infLevel(0)
483
1.38k
  {
484
1.38k
  }
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: