summaryrefslogtreecommitdiffstats
path: root/filters/kword/oowriter/ExportFilter.h
blob: c89e15acb2104991fe7a7069a1f1836a4c4ae203 (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
/* This file is part of the KDE project
   Copyright (C) 2001, 2002, 2003, 2004 Nicolas GOUTTE <goutte@kde.org>

   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.
*/

/*
   This file is based on the old file:
    /home/kde/koffice/filters/kword/ascii/asciiexport.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 <Bolle@ID-PRO.de>

   The old file was licensed under the terms of the GNU Library General Public
   License version 2.
*/

#ifndef _EXPORTFILTER_H
#define _EXPORTFILTER_H

#include <KWEFStructures.h>
#include <KWEFUtil.h>
#include <KWEFBaseWorker.h>
#include <KWEFKWordLeader.h>

#define STRICT_OOWRITER_VERSION_1

class KZip;

class StyleMap : public TQMap<TQString,LayoutData>
{
public:
    StyleMap(void) {}
    ~StyleMap(void) {}
};

class OOWriterWorker : public KWEFBaseWorker
{
public:
    OOWriterWorker(void);
    virtual ~OOWriterWorker(void) { delete m_streamOut; }
public:
    /// What is the type of the frameset anchor
    enum AnchorType
    {
        AnchorUnknown = 0, // ### TODO: is this really needed?
        AnchorInlined, ///< The frameset is inlined
        AnchorNonInlined, ///< the frameset is not inlined
        AnchorTextImage ///< This is a text image (KWord 0.8; inlined; only for pictures)
    };
public:
    virtual bool doOpenFile(const TQString& filenameOut, const TQString& to);
    virtual bool doCloseFile(void); ///< Close file in normal conditions
    virtual bool doOpenDocument(void);
    virtual bool doCloseDocument(void);
    virtual bool doFullParagraph(const TQString& paraText, const LayoutData& layout,
        const ValueListFormatData& paraFormatDataList);
    virtual bool doFullPaperFormat(const int format,
        const double width, const double height, const int orientation);
    virtual bool doFullPaperBorders (const double top, const double left,
        const double bottom, const double right);
    /**
     * Other data of KWord's \<PAPER\> which are not in @see doFullPaperFormat
     * @since 1.4
     */
    virtual bool doFullPaperFormatOther ( const int columns, const double columnspacing, const int numPages );        
    virtual bool doOpenStyles(void);
    virtual bool doCloseStyles(void);
    virtual bool doFullDefineStyle(LayoutData& layout);
    virtual bool doFullDocumentInfo(const KWEFDocumentInfo& docInfo);
    virtual bool doVariableSettings(const VariableSettingsData& vs);
    virtual bool doOpenBody (void);
    virtual bool doDeclareNonInlinedFramesets( TQValueList<FrameAnchor>& pictureAnchors, TQValueList<FrameAnchor>& tableAnchors ); ///< @since 1.4
private:
    void processParagraphData (const TQString& paraText,
        const TextFormatting& formatLayout,
        const ValueListFormatData& paraFormatDataList);
    void processNormalText ( const TQString& paraText,
        const TextFormatting& formatLayout,
        const FormatData& formatData);
    void processFootnote( const VariableData& variable );
    void processNote( const VariableData& variable );
    void processVariable ( const TQString& paraText,
        const TextFormatting& formatLayout,
        const FormatData& formatData);
    void processAnchor ( const TQString& paraText,
        const TextFormatting& formatLayout,
        const FormatData& formatData);
    void processTextImage ( const TQString&,
        const TextFormatting& formatLayout,
        const FormatData& formatData);
    TQString textFormatToStyle(const TextFormatting& formatOrigin,
        const TextFormatting& formatData, const bool force, TQString& key);
    TQString layoutToParagraphStyle(const LayoutData& layoutOrigin,
        const LayoutData& layout, const bool force, TQString& styleKey);
    TQString escapeOOText(const TQString& strText) const;
    TQString escapeOOSpan(const TQString& strText) const;
    TQString cellToProperties( const TableCell& cell, TQString& key) const;
    bool makeTableRows( const TQString& tableName, const Table& table, int firstRowNumber );
    bool makeTable( const FrameAnchor& anchor, const AnchorType anchorType );
    bool makePicture( const FrameAnchor& anchor, const AnchorType anchorType );
    bool convertUnknownPicture(const TQString& name, const TQString& extension, TQByteArray& image);
    void declareFont(const TQString& fontName);
    void writeFontDeclaration(void);
    void writeContentXml(void);
    void writeStylesXml(void);
    void writeMetaXml(void);
    void writeStartOfFile(const TQString& type);
    /**
     * For automatic styles: create the name from @p prefix and from the increased @p counter
     * (Yes, the counter is increased by the method.)
     */
    TQString makeAutomaticStyleName(const TQString& prefix, ulong& counter) const;
private: // ZIP methods
    bool zipPrepareWriting(const TQString& name);
    bool zipDoneWriting(void);
    bool zipWriteData(const char* str);
    bool zipWriteData(const TQByteArray& array);
    bool zipWriteData(const TQCString& cstr);
    bool zipWriteData(const TQString& str); ///< Assumes UTF-8
private:
    TQTextStream* m_streamOut;
    TQString m_pagesize;
    StyleMap m_styleMap;
    double m_paperBorderTop,m_paperBorderLeft,m_paperBorderBottom,m_paperBorderRight;
    KWEFDocumentInfo m_docInfo; ///< document information
    TQByteArray m_contentBody; ///< office:body element of content.xml
    KZip* m_zip; ///< Output OOWriter file
    TQMap<TQString,TQString> m_fontNames; ///< List of used font names (the data() are extra attributes for font declaration time.)

    ulong m_pictureNumber; ///< Number of picture (increment *before* use)
    ulong m_automaticParagraphStyleNumber; ///< Number of paragraph-based automatic styles (increment *before* use)
    ulong m_automaticTextStyleNumber; ///< Number of text-based automatic styles (increment *before* use)
    ulong m_footnoteNumber; ///< Number of footnote (for text:id) (increment *before* use)
    ulong m_tableNumber; ///< Number of table (for table:name) (increment *before* use)
    ulong m_textBoxNumber; ///< Number of a textbox (for draw:text-box) (increment *before* use)
    

    TQString m_styles; ///< Normal paragraph styles (in OO format)
    TQString m_contentAutomaticStyles; ///< Automatic styles for content.xml (in OO format)

    uint m_size; ///< Size of ZIP entry
    int m_paperFormat;
    double m_paperWidth;
    double m_paperHeight;
    int m_paperOrientation;

    TQMap<TQString,TQString> m_mapTextStyleKeys; ///< Map of keys to automatic text styles
    TQMap<TQString,TQString> m_mapParaStyleKeys; ///< Map of keys to automatic paragraph styles
    VariableSettingsData m_varSet; ///< KWord's \<VARIABLESETTINGS\>
    int m_numPages; ///< Number of pages @note if the input file comes from a filter, this data is often missing.
    double m_columnspacing; ///< Spacing between columns
    int m_columns; ///< Number of columns
private: // Variable that would need a link/glue from libexport
    TQValueList<FrameAnchor> m_nonInlinedPictureAnchors; ///< Pseudo-anchors for non-inlined anchors  \todo: connection to libexport
    TQValueList<FrameAnchor> m_nonInlinedTableAnchors; ///< Pseudo-anchors for non-inlined tables  \todo: connection to libexport

};
#endif // _EXPORTFILTER_H