summaryrefslogtreecommitdiffstats
path: root/filters/kword/libexport/KWEFStructures.h
blob: 682606feb8797d1c615ece7dbc432f2fc348b347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
   This file is part of the KDE project
   Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE <goutte@kde.org>
   Copyright (c) 2001 IABG mbH. All rights reserved.
                      Contact: Wolf-Michael Bolle <Bolle@IABG.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

/*
   The classes in this file are based on a class in the old files:
    /home/kde/koffice/filters/kword/ascii/asciiexport.cc
    /home/kde/koffice/filters/kword/docbookexpert/docbookexport.cc

   The old file was copyrighted by
    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
    Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved.
                       Contact: Wolf-Michael Bolle <Wolf-Michael.Bolle@GMX.de>
*/

/*
   Part of the code is based on code licensed under the terms of the
   GNU Library General Public License version 2:
   Copyright 2001 Michael Johnson <mikej@xnet.com>
*/

#ifndef EXPORTFILTERSSTRUCTURES_H
#define EXPORTFILTERSSTRUCTURES_H

#include <tqvaluelist.h>
#include <tqstring.h>
#include <tqmap.h>
#include <tqcolor.h>
#include <tqdom.h>
#include <tqdatetime.h>

#include <KoPictureKey.h>
#include <koffice_export.h>
/**
 * TextFormatting is a container for data retrieved from the \<FORMAT\> tag
 * and its subtags to be used in the \<PARAGRAPH\> tag.
 */
class TextFormatting
{
    public:
        TextFormatting(): italic (false), underline (false), underlineWord(false),
            strikeout (false), strikeoutWord( false ),
            weight (50), fontSize (0), verticalAlignment (0), missing (true) {}

        TextFormatting(const bool newMissing) : italic (false),
            underline (false), underlineWord(false), strikeout (false), strikeoutWord( false ),
            weight (50), fontSize (0), verticalAlignment (0),
            missing (newMissing) {}

        TextFormatting ( TQString f,
                         bool    i,
                         bool    u,
                         bool    s,
                         int     w,
                         int     sz,
                         TQColor  fg,
                         TQColor  bg,
                         int     v) :
            fontName (f), italic (i), underline (u), underlineWord(false),
            strikeout(s), strikeoutWord( false ),
            weight (w), fontSize (sz), fgColor (fg),
            bgColor (bg), verticalAlignment (v), missing (false) {}

        TQString fontName;

        bool    italic;

        bool    underline;       ///< Any underline? (If true, we do not know if simple or double or what else)

        TQString    underlineValue; ///< "value" of the underline: single, double, bold-single...
        TQString    underlineStyle; ///< underline style: solid, dash, dot dash, ....
        bool       underlineWord;  ///< true if word-by-word (i.e spaces are not underlined)
        TQColor     underlineColor; ///< color of the line

        bool    strikeout;             ///< true if strikeout
        TQString strikeoutType;         ///< type of strikeout: single, bold, double
        TQString strikeoutLineStyle;    ///< type of the strikeout line: solid, dash, dot, ....
	bool 	strikeoutWord;	///< \todo: not finished ###

        int     weight;
        int     fontSize;
        TQColor  fgColor;
        TQColor  bgColor;
        int     verticalAlignment;

        TQString fontAttribute;
        /**
         * Language code
         * @note the test language "xx" in converted to "en_US"
         */
        TQString language;

        bool    missing;   ///< true if this TextFormatting object does not correspond to a real \<FORMAT\> element
};


class Picture
{
    public:
        Picture () {}

        KoPictureKey key;      ///< Picture key: where the picture came from
        TQString koStoreName;   ///< Picture store name: filename within KWord archive
};

/**
 * For \<FRAME\> Tag.
 * Look at kword.dtd for a complete description
 * of individuals class members
 */
class FrameData
{
public:
    double right;
    double left;
    double top;
    double bottom;
    double minHeight;
    int runaround;
    TQString runaroundSide;
    double runaroundGap;
    int autoCreateNewFrame;
    int newFrameBehavior;
    int copy;
    int sheetSide;

    double lWidth, rWidth, tWidth, bWidth;

    TQColor lColor;
    TQColor rColor;
    TQColor tColor;
    TQColor bColor;

    int lStyle, rStyle, tStyle, bStyle;

    TQColor bkColor;
    int    bkStyle;
    double bleftpt, brightpt, btoppt, bbottompt;
};


class ParaData;

class KOFFICEFILTER_EXPORT TableCell
{
   public:
      TableCell (): col( 0 ), row( 0 ), m_cols( 0 ), m_rows( 0 ), paraList( 0 ) {}

      /// \since 1.4 (changes of parameters)
      TableCell ( int c, int r, int _cols, int _rows, TQValueList<ParaData> *p, FrameData &frameData  )
         : col (c), row (r), m_cols( _cols ), m_rows( _rows ), paraList (p), frame (frameData) {}

      ~TableCell ();

      int                   col;
      int                   row;
      int m_cols; ///< \since 1.4
      int m_rows; ///< \since 1.4
      TQValueList<ParaData> *paraList;
      FrameData   frame;
};


class Table
{
   public:
      Table () : cols (0) {}

      /// \since 1.4 (change of parameters)
      void addCell ( int c, int r, int _cols, int _rows, TQValueList<ParaData> &p, FrameData &frameData );

      int                   cols;
      TQValueList<TableCell> cellList;
};


/// This is basically \<FRAMESET\> tag
class FrameAnchor
{
   public:
      FrameAnchor ():
       type(-1) {}

      FrameAnchor ( const KoPictureKey& n  ) : key (n), type (-1) {}

      KoPictureKey key; ///< Picture key
      int     type;
      FrameData   frame;

      Picture picture;
      Table   table;
};

/**
 * Data of variables
 */
class KOFFICEFILTER_EXPORT VariableData
{
public:
    VariableData (): m_type(-1), footnotePara(0) {}
    VariableData ( const TQString& text ) : m_text(text), m_type(-1) {}
    VariableData ( const VariableData& other ) :
      m_key(other.m_key), m_text(other.m_text),
      m_type(other.m_type), propertyMap(other.propertyMap),
      footnotePara(other.footnotePara) {}
public:
    /**
     * Set parameters of a LINK element
     */
    void setLink(const TQString& linkName, const TQString& hrefName);
    TQString getLinkName(void) const; ///< Name of link (attribute "linkName" of \<LINK\>)
    TQString getHrefName(void) const; ///< Reference of link (attribute "hrefName" of \<LINK\>)
    /**
     * Set parameters of a PGNUM element
     */
    void setPgNum(const TQString& subtype, const TQString& value);
    bool isPageNumber(void) const;
    bool isPageCount(void) const;
    /**
     * Set parameters of a FIELD element
     */
    void setField(const TQString& subtype, const TQString& value);
    TQString getFieldName(void) const;
    TQString getFieldValue(void) const;
    /**
     * Set parameters of a \<FOOTNOTE\> element
     * @since 1.4 (change of parameters)
     */
    void setFootnote( const TQString& notetype, const TQString& automatic, const TQString& value, TQValueList<ParaData>* para );
    /**
     * Is the footnote an automatic one?
     * @return true for an automatical foornote, false for a manual footnote
     */
    bool getFootnoteAuto(void) const;
    /// Get the value (counter) of the footnote
    TQString getFootnoteValue(void) const;
    /**
     * Get type of footnote
     * @return true for footnote, false for endnote
     * @since 1.4
     */
    bool getFootnoteType( void ) const;
    /// Paragrapgh of the footnote
    TQValueList<ParaData>* getFootnotePara(void) const;

    /**
     * Set generic variable data
     * @since 1.3.1, 1.4
     */
    void setGenericData( const TQString& key, const TQString& data );
    /**
     * Get generic variable data
     * @since 1.3.1, 1.4
     */
    TQString getGenericData( const TQString& key ) const;

    TQString m_key;
    TQString m_text;
    int m_type;

protected:
    TQMap<TQString,TQString> propertyMap;
    TQValueList<ParaData>* footnotePara;
};

class FormatData
{
public:
    FormatData ()
        : id (-1), pos (-1), len (-1), text(true) {}

    FormatData ( const int p, const int l, const bool missing  )
        : id (1), pos (p), len (l), text(missing) {}

    FormatData ( const int i, const int p, const int l  )
        : id (i), pos (p), len (l), text(false) {}

    FormatData ( const int p, const int l, const FrameAnchor& t )
        : id (6), pos (p), len (l), frameAnchor (t) {}

    FormatData ( const FormatData& other )
        : id(other.id), pos(other.pos), len(other.len),
          text(other.text), frameAnchor(other.frameAnchor), variable(other.variable) {}
public:
    int id;
    int pos;    ///< Start position of text to which this format applies
    int len;

    TextFormatting  text;
    FrameAnchor     frameAnchor;
    VariableData    variable;
};


class ValueListFormatData : public TQValueList<FormatData>
{
public:
    ValueListFormatData (void) { }
    virtual ~ValueListFormatData (void) { }
};


/// Counter structure, for LayoutData
class CounterData
{
public:
    CounterData()
        : numbering (NUM_NONE), style (STYLE_NONE), depth(0), start(0), customCharacter(0)
        {}

    enum Numbering
    {
        NUM_LIST    = 0,   ///< Numbered as a list item
        NUM_CHAPTER = 1,   ///< Numbered as a heading
        NUM_NONE    = 2    ///< No counter
    };

    enum Style
    {
        STYLE_NONE         = 0,
        STYLE_NUM          = 1,
        STYLE_ALPHAB_L     = 2,
        STYLE_ALPHAB_U     = 3,
        STYLE_ROM_NUM_L    = 4,
        STYLE_ROM_NUM_U    = 5,
        STYLE_CUSTOMBULLET = 6,
        STYLE_CUSTOM       = 7,
        STYLE_CIRCLEBULLET = 8,
        STYLE_SQUAREBULLET = 9,
        STYLE_DISCBULLET   = 10,
        STYLE_BOXBULLET    = 11
    };

    Numbering numbering;
    Style style;
    /*unsigned*/ int depth;
    int start;
    TQString lefttext;
    TQString righttext;

    int /*TQChar*/ customCharacter;
    TQString customFont;
    //TQString custom;

    TQString text;   ///< text at the time of saving (no formatting info though)
};


/// Border
class BorderData
{
public:
    BorderData() : style(0), width(0.0) {}
public:
    TQColor color;
    int style;
    double width;
};

/**
  * Tabulator (see also \<TABULATOR\> element in KWord's DTD)
  */
class KOFFICEFILTER_EXPORT TabulatorData
{
public:

    enum
    {
        TF_NONE       = 0,
        TF_DOT        = 1,
        TF_LINE       = 2,
        TF_DASH       = 3,
        TF_DASHDOT    = 4,
        TF_DASHDOTDOT = 5
    };

    TabulatorData() : m_type(0), m_ptpos(0.0), m_filling(0), m_width(0.0) {}
public:
    bool operator == (const TabulatorData& other) const;
public:
    int m_type;
    double m_ptpos;
    int m_filling;
    double m_width;
};

/**
  * List of tabulators
  */
class TabulatorList : public TQValueList<TabulatorData>
{
public:
    TabulatorList(void) {}
    virtual ~TabulatorList(void) {}
};

/// Paragraph layout
class LayoutData
{
public:
    LayoutData():indentFirst(0.0), indentLeft(-1.0), indentRight(-1.0), marginTop(-1.0), marginBottom(-1.0),
        lineSpacingType(10), lineSpacing(0.0), pageBreakBefore(false), pageBreakAfter(false),
        keepLinesTogether(false),
        shadowDistance(0.0), shadowDirection(0)
        { }


    enum { LS_CUSTOM = 0, LS_SINGLE = 10, LS_ONEANDHALF = 15, LS_DOUBLE = 20,
      LS_ATLEAST = 30, LS_MULTIPLE = 40, LS_FIXED = 50 };

    TQString     styleName;
    TQString     styleFollowing;
    TQString     alignment;      ///< left, right, center, justify
    CounterData counter;
    FormatData  formatData;
    double      indentFirst;    ///< indentation correction of first line (can be negative!)
    double      indentLeft;     ///< left indentation (a negative value means invalid)
    double      indentRight;    ///< right indentation (a negative value means invalid)
    double      marginTop;      ///< space before the paragraph  (a negative value means invalid)
    double      marginBottom;   ///< space after the paragraph (a negative value means invalid)

    int         lineSpacingType;///< 0=custom, 10=one line, 15=one and half lines, 20= 2 lines \todo: document the other values
    double      lineSpacing;    ///< Space between lines in pt, if lineSpacingType==0

    bool        pageBreakBefore;
    bool        pageBreakAfter;
    bool        keepLinesTogether;

    double      shadowDistance; ///< distance of \<SHADOW\>
    int         shadowDirection;///< direction of \<SHADOW\>
    TQColor      shadowColor;    ///< red, green, blue of \<SHADOW\>
    BorderData  leftBorder;
    BorderData  rightBorder;
    BorderData  topBorder;
    BorderData  bottomBorder;
    TabulatorList tabulatorList; ///< List of tabulators
};


struct ParaData
{
    TQString                    text;
    ValueListFormatData        formattingList;
    LayoutData                 layout;
};

struct HeaderFooterData
{
    enum HeaderFooterPage
    {
      PAGE_FIRST,
      PAGE_ODD,
      PAGE_EVEN,
      PAGE_ALL
    };

    HeaderFooterPage page;
    TQValueList<ParaData> para;
};

typedef HeaderFooterData HeaderData;
typedef HeaderFooterData FooterData;

/// data for \<FRAMESET\> which holds footnotes
struct FootnoteData
{
    TQString frameName;
    TQValueList<ParaData> para;
};

/// see \<VARIABLESETTINGS\> in the KWord DTD
class VariableSettingsData
{
public:
    VariableSettingsData () : startingPageNumber (1),
                              displaylink (true),
                              underlinelink (true),
                              displaycomment (true),
                              displayfieldcode (false)
    {
    }

    int startingPageNumber;
    bool displaylink;
    bool underlinelink;
    bool displaycomment;
    bool displayfieldcode;
    TQDateTime creationTime;
    TQDateTime modificationTime;
    TQDateTime printTime;
};

class KWEFDocumentInfo
{
public:
    KWEFDocumentInfo(void) { } // Initiate all TQString
public:
    // <ABOUT>
    TQString title;
    TQString abstract;
    TQString keywords;
    TQString subject;
    // <AUTHOR>
    TQString fullName;
    TQString jobTitle;
    TQString company;
    TQString email;
    TQString telephone;
    TQString fax;
    TQString country;
    TQString postalCode;
    TQString city;
    TQString street;
    TQString initial;
    TQString position;
    TQString telephonework;
};

/// \since 1.4
class Bookmark
{
public:
    Bookmark();
    /// Bookmark name
    TQString m_name;
    /// Name of the frameset where the bookmark is
    TQString m_frameset;
    /// Number of the paragrapgh where the booksmark starts
    int m_startparag;
    /// Number of the paragrapgh where the booksmark starts
    int m_endparag;
    /// Position where the bookmark starts in the paragraph
    int m_cursorIndexStart;
    /// Position where the bookmark ends in the paragraph
    int m_cursorIndexEnd;
};

// Helper functions

void CreateMissingFormatData ( TQString &paraText, ValueListFormatData &paraFormatDataList );

#endif /* EXPORTFILTERSSTRUCTURES_H */