31
31
#include <QFontInfo>
32
32
#include <QTextStream>
34
#include <kopicture/KoPicture.h>
35
35
#include <KoFilterManager.h>
38
38
typedef KGenericFactory<RTFImport> RTFImportFactory;
39
K_EXPORT_COMPONENT_FACTORY( librtfimport, RTFImportFactory( "kofficefilters" ) )
39
K_EXPORT_COMPONENT_FACTORY(librtfimport, RTFImportFactory("kofficefilters"))
41
41
// defines a property
42
#define PROP(a,b,c,d,e) { a, b, &RTFImport::c, d, e }
42
#define PROP(a,b,c,d,e) { a, b, &RTFImport::c, d, e }
44
44
// defines a member variable of RTFImport as a property (DEPRECATED)
45
#define MEMBER(a,b,c,d,e) PROP(a,b,c,offsetof(RTFImport,d),e)
45
#define MEMBER(a,b,c,d,e) PROP(a,b,c,offsetof(RTFImport,d),e)
47
static RTFProperty destinationPropertyTable[] =
49
// only-valid-in control word function offset, value
50
PROP( 0L, "@*", skipGroup, 0L, false ),
51
MEMBER( "@info", "@author", parsePlainText, author, false ),
52
PROP( "@pict", "@blipuid", parseBlipUid, 0, 0 ),
53
PROP( "@rtf", "@colortbl", parseColorTable, 0L, true ),
54
MEMBER( "@info", "@company", parsePlainText, company, false ),
55
MEMBER( "@info", "@doccomm", parsePlainText, doccomm, false ),
56
PROP( "Text", "@field", parseField, 0L, false ),
57
PROP( "@field", "@fldinst", parseFldinst, 0L, false ),
58
PROP( "@field", "@fldrslt", parseFldrslt, 0L, false ),
59
PROP( "@rtf", "@fonttbl", parseFontTable, 0L, true ),
60
MEMBER( "@rtf", "@footer", parseRichText, oddPagesFooter, true ),
61
PROP( "@rtf", "@footnote", parseFootNote, 0L, true ),
62
MEMBER( "@rtf", "@footerf", parseRichText, firstPageFooter, true ),
63
MEMBER( "@rtf", "@footerl", parseRichText, oddPagesFooter, true ),
64
MEMBER( "@rtf", "@footerr", parseRichText, evenPagesFooter, true ),
65
MEMBER( "@rtf", "@header", parseRichText, oddPagesHeader, true ),
66
MEMBER( "@rtf", "@headerf", parseRichText, firstPageHeader, true ),
67
MEMBER( "@rtf", "@headerl", parseRichText, oddPagesHeader, true ),
68
MEMBER( "@rtf", "@headerr", parseRichText, evenPagesHeader, true ),
69
PROP( "@rtf", "@info", parseGroup, 0L, true ),
70
PROP( "Text", "@nonshppict", skipGroup, 0L, false ),
71
PROP( 0L, "@panose", skipGroup, 0L, 0 ), // Not supported
72
PROP( "Text", "@pict", parsePicture, 0L, true ),
73
MEMBER( "@", "@rtf", parseRichText, bodyText, true ),
74
PROP( "Text", "@shpinst", skipGroup, 0L, true ),
75
PROP( "Text", "@shppict", parseGroup, 0L, false ),
76
PROP( "@rtf", "@stylesheet", parseStyleSheet, 0L, true ),
77
MEMBER( "@info", "@title", parsePlainText, title, false ),
47
static RTFProperty destinationPropertyTable[] = {
48
// only-valid-in control word function offset, value
49
PROP(0L, "@*", skipGroup, 0L, false),
50
MEMBER("@info", "@author", parsePlainText, author, false),
51
PROP("@pict", "@blipuid", parseBlipUid, 0, 0),
52
PROP("@rtf", "@colortbl", parseColorTable, 0L, true),
53
MEMBER("@info", "@company", parsePlainText, company, false),
54
MEMBER("@info", "@doccomm", parsePlainText, doccomm, false),
55
PROP("Text", "@field", parseField, 0L, false),
56
PROP("@field", "@fldinst", parseFldinst, 0L, false),
57
PROP("@field", "@fldrslt", parseFldrslt, 0L, false),
58
PROP("@rtf", "@fonttbl", parseFontTable, 0L, true),
59
MEMBER("@rtf", "@footer", parseRichText, oddPagesFooter, true),
60
PROP("@rtf", "@footnote", parseFootNote, 0L, true),
61
MEMBER("@rtf", "@footerf", parseRichText, firstPageFooter, true),
62
MEMBER("@rtf", "@footerl", parseRichText, oddPagesFooter, true),
63
MEMBER("@rtf", "@footerr", parseRichText, evenPagesFooter, true),
64
MEMBER("@rtf", "@header", parseRichText, oddPagesHeader, true),
65
MEMBER("@rtf", "@headerf", parseRichText, firstPageHeader, true),
66
MEMBER("@rtf", "@headerl", parseRichText, oddPagesHeader, true),
67
MEMBER("@rtf", "@headerr", parseRichText, evenPagesHeader, true),
68
PROP("@rtf", "@info", parseGroup, 0L, true),
69
PROP("Text", "@nonshppict", skipGroup, 0L, false),
70
PROP(0L, "@panose", skipGroup, 0L, 0), // Not supported
71
PROP("Text", "@pict", parsePicture, 0L, true),
72
MEMBER("@", "@rtf", parseRichText, bodyText, true),
73
PROP("Text", "@shpinst", skipGroup, 0L, true),
74
PROP("Text", "@shppict", parseGroup, 0L, false),
75
PROP("@rtf", "@stylesheet", parseStyleSheet, 0L, true),
76
MEMBER("@info", "@title", parsePlainText, title, false),
80
79
static RTFProperty propertyTable[] =
81
80
// Alphabetical order
83
// only-valid-in control word function offset, value
84
PROP( "Text", "\n", insertParagraph, 0L, 0 ),
85
PROP( "Text", "\r", insertParagraph, 0L, 0 ),
86
PROP( 0L, "\'", insertHexSymbol, 0L, 0 ),
87
PROP( 0L, "\\", insertSymbol, 0L, '\\' ),
88
PROP( 0L, "_", insertSymbol, 0L, 0x2011 ),
89
PROP( 0L, "{", insertSymbol, 0L, '{' ),
90
PROP( 0L, "|", insertSymbol, 0L, 0x00b7 ),
91
PROP( 0L, "}", insertSymbol, 0L, '}' ),
92
PROP( 0L, "~", insertSymbol, 0L, 0x00a0 ),
93
PROP( 0L, "-", insertSymbol, 0L, 0x00ad ),
94
PROP( 0L, "adjustright", ignoreKeyword, 0L, 0 ), // Not supported, KWord has no grid
95
PROP( 0L, "ansi", setAnsiCodepage, 0L, 0 ),
96
PROP( 0L, "ansicpg", setCodepage, 0L, 0 ),
97
MEMBER( 0L, "b", setToggleProperty, state.format.bold, 0 ),
98
// \bin is handled in the tokenizer
99
MEMBER( "@colortbl", "blue", setNumericProperty, blue, 0 ),
100
MEMBER( 0L, "box", setEnumProperty, state.layout.border, 0 ),
101
PROP( 0L, "brdrb", selectLayoutBorder, 0L, 3 ),
102
PROP( 0L, "brdrcf", setBorderColor, 0L, 0 ),
103
PROP( 0L, "brdrdash", setBorderStyle, 0L, RTFBorder::Dashes ),
104
PROP( 0L, "brdrdashd", setBorderStyle, 0L, RTFBorder::DashDot ),
105
PROP( 0L, "brdrdashdd", setBorderStyle, 0L, RTFBorder::DashDotDot ),
106
PROP( 0L, "brdrdashsm", setBorderStyle, 0L, RTFBorder::Dashes ),
107
PROP( 0L, "brdrdb", setBorderStyle, 0L, RTFBorder::Solid ),
108
PROP( 0L, "brdrdot", setBorderStyle, 0L, RTFBorder::Dots ),
109
PROP( 0L, "brdrhairline", setBorderStyle, 0L, RTFBorder::Solid ),
110
PROP( 0L, "brdrl", selectLayoutBorder, 0L, 0 ),
111
PROP( 0L, "brdrr", selectLayoutBorder, 0L, 1 ),
112
PROP( 0L, "brdrs", setBorderStyle, 0L, RTFBorder::Solid ),
113
PROP( 0L, "brdrsh", setBorderStyle, 0L, RTFBorder::Solid ),
114
PROP( 0L, "brdrt", selectLayoutBorder, 0L, 2 ),
115
PROP( 0L, "brdrth", setBorderStyle, 0L, RTFBorder::Solid ),
116
PROP( 0L, "brdrw", setBorderProperty, offsetof(RTFBorder,width), 0 ),
117
PROP( 0L, "bullet", insertSymbol, 0L, 0x2022 ),
118
PROP( 0L, "brsp", setBorderProperty, offsetof(RTFBorder,space), 0 ),
119
MEMBER( 0L, "caps", setToggleProperty, state.format.caps, 0 ),
120
MEMBER( 0L, "cb", setNumericProperty, state.format.bgcolor, 0 ),
121
MEMBER( 0L, "highlight", setNumericProperty, state.format.bgcolor, 0 ),
122
PROP( "Text", "cell", insertTableCell, 0L, 0 ),
123
PROP( 0L, "cellx", insertCellDef, 0L, 0 ),
124
MEMBER( 0L, "cf", setNumericProperty, state.format.color, 0 ),
125
PROP( 0L, "chdate", insertDateTime, 0L, true ),
126
PROP( 0L, "chpgn", insertPageNumber, 0L, 0 ),
127
PROP( 0L, "chtime", insertDateTime, 0L, false ),
128
PROP( 0L, "clbrdrb", selectLayoutBorderFromCell, 0L, 3 ),
129
PROP( 0L, "clbrdrl", selectLayoutBorderFromCell, 0L, 0 ),
130
PROP( 0L, "clbrdrr", selectLayoutBorderFromCell, 0L, 1 ),
131
PROP( 0L, "clbrdrt", selectLayoutBorderFromCell, 0L, 2 ),
132
MEMBER( 0L, "clcbpat", setNumericProperty, state.tableCell.bgcolor, 0 ),
133
PROP( 0L, "cs", ignoreKeyword, 0L, 0 ), // Not supported by KWord 1.3
134
PROP( 0L, "datafield", skipGroup, 0L, 0 ), // Binary data in variables are not supported
135
MEMBER( "@rtf", "deff", setNumericProperty, defaultFont, 0 ),
136
MEMBER( "@rtf", "deftab", setNumericProperty, defaultTab, 0 ),
137
PROP( "@pict", "dibitmap", setPictureType, 0L, RTFPicture::BMP ),
138
MEMBER( 0L, "dn", setNumericProperty, state.format.baseline, 6 ),
139
PROP( 0L, "emdash", insertSymbol, 0L, 0x2014 ),
140
PROP( "@pict", "emfblip", setPictureType, 0L, RTFPicture::EMF ),
141
PROP( 0L, "emspace", insertSymbol, 0L, 0x2003 ),
142
PROP( 0L, "endash", insertSymbol, 0L, 0x2013 ),
143
PROP( 0L, "enspace", insertSymbol, 0L, 0x2002 ),
144
PROP( 0L, "expnd", ignoreKeyword, 0L, 0 ), // Expansion/compression of character inter-space not supported
145
PROP( 0L, "expndtw", ignoreKeyword, 0L, 0 ), // Expansion/compression of character inter-space not supported
146
MEMBER( 0L, "f", setNumericProperty, state.format.font, 0 ),
147
MEMBER( "@rtf", "facingp", setFlagProperty, facingPages, true ),
148
PROP( 0L, "fcharset", setCharset, 0L, 0 ), // Not needed with Qt
149
PROP( "@fonttbl", "fdecor", setFontStyleHint, 0L, QFont::Decorative ),
150
MEMBER( 0L, "fi", setNumericProperty, state.layout.firstIndent, 0 ),
151
PROP( "@fonttbl", "fmodern", setFontStyleHint, 0L, QFont::TypeWriter ),
152
PROP( "@fonttbl", "fnil", setFontStyleHint, 0L, QFont::AnyStyle ),
153
MEMBER( 0L, "footery", setNumericProperty, state.section.footerMargin, 0 ),
154
PROP( 0L, "formshade", ignoreKeyword, 0L, 0 ), // Not supported, KWord has no form support
155
MEMBER( "@fonttbl", "fprq", setNumericProperty, font.fixedPitch, 0 ),
156
PROP( "@fonttbl", "froman", setFontStyleHint, 0L, QFont::Serif ),
157
MEMBER( 0L, "fs", setNumericProperty, state.format.fontSize, 0 ),
158
PROP( "@fonttbl", "fscript", setFontStyleHint, 0L, QFont::AnyStyle ),
159
PROP( "@fonttbl", "fswiss", setFontStyleHint, 0L, QFont::SansSerif ),
160
PROP( "@fonttbl", "ftech", setFontStyleHint, 0L, QFont::AnyStyle ),
161
MEMBER( "@colortbl", "green", setNumericProperty, green, 0 ),
162
MEMBER( 0L, "headery", setNumericProperty, state.section.headerMargin, 0 ),
163
MEMBER( 0L, "i", setToggleProperty, state.format.italic, 0 ),
164
MEMBER( 0L, "intbl", setFlagProperty, state.layout.inTable, true ),
165
PROP( "@pict", "jpegblip", setPictureType, 0L, RTFPicture::JPEG ),
166
MEMBER( 0L, "keep", setFlagProperty, state.layout.keep, true ),
167
MEMBER( 0L, "keepn", setFlagProperty, state.layout.keepNext, true ),
168
MEMBER( "@rtf", "landscape", setFlagProperty, landscape, true ),
169
PROP( 0L, "ldblquote", insertSymbol, 0L, 0x201c ),
170
MEMBER( 0L, "li", setNumericProperty, state.layout.leftIndent, 0 ),
171
PROP( 0L, "line", insertSymbol, 0L, 0x000a ),
172
PROP( 0L, "lquote", insertSymbol, 0L, 0x2018 ),
173
PROP( 0L, "ltrmark", insertSymbol, 0L, 0x200e ),
174
PROP( 0L, "mac", setMacCodepage, 0L, 0 ),
175
PROP( "@pict", "macpict", setPictureType, 0L, RTFPicture::MacPict ),
176
MEMBER( "@rtf", "margb", setNumericProperty, bottomMargin, 0 ),
177
MEMBER( "@rtf", "margl", setNumericProperty, leftMargin, 0 ),
178
MEMBER( "@rtf", "margr", setNumericProperty, rightMargin, 0 ),
179
MEMBER( "@rtf", "margt", setNumericProperty, topMargin, 0 ),
180
MEMBER( 0L, "nosupersub", setEnumProperty, state.format.vertAlign, RTFFormat::Normal ),
181
PROP( "Text", "page", insertPageBreak, 0L, 0 ),
182
MEMBER( 0L, "pagebb", setFlagProperty, state.layout.pageBB, true ),
183
MEMBER( "@rtf", "paperh", setNumericProperty, paperHeight, 0 ),
184
MEMBER( "@rtf", "paperw", setNumericProperty, paperWidth, 0 ),
185
PROP( "Text", "par", insertParagraph, 0L, 0 ),
186
PROP( 0L, "pard", setParagraphDefaults, 0L, 0 ),
187
PROP( 0L, "pc", setPcCodepage, 0L, 0 ),
188
PROP( 0L, "pca", setPcaCodepage, 0L, 0 ),
189
MEMBER( 0L, "pgbrk", setToggleProperty, state.layout.pageBA, true ),
190
MEMBER( "@pict", "piccropb", setNumericProperty, picture.cropBottom, 0 ),
191
MEMBER( "@pict", "piccropl", setNumericProperty, picture.cropLeft, 0 ),
192
MEMBER( "@pict", "piccropr", setNumericProperty, picture.cropRight, 0 ),
193
MEMBER( "@pict", "piccropt", setNumericProperty, picture.cropTop, 0 ),
194
MEMBER( "@pict", "pich", setNumericProperty, picture.height, 0 ),
195
MEMBER( "@pict", "pichgoal", setNumericProperty, picture.desiredHeight, 0 ),
196
MEMBER( "@pict", "picscaled", setFlagProperty, picture.scaled, true ),
197
MEMBER( "@pict", "picscalex", setNumericProperty, picture.scalex, 0 ),
198
MEMBER( "@pict", "picscaley", setNumericProperty, picture.scaley, 0 ),
199
MEMBER( "@pict", "picw", setNumericProperty, picture.width, 0 ),
200
MEMBER( "@pict", "picwgoal", setNumericProperty, picture.desiredWidth, 0 ),
201
PROP( 0L, "plain", setPlainFormatting, 0L, 0 ),
202
PROP( "@pict", "pmmetafile", setPictureType, 0L, RTFPicture::WMF ),
203
PROP( "@pict", "pngblip", setPictureType, 0L, RTFPicture::PNG ),
204
MEMBER( 0L, "qc", setEnumProperty, state.layout.alignment, RTFLayout::Centered ),
205
MEMBER( 0L, "qj", setEnumProperty, state.layout.alignment, RTFLayout::Justified ),
206
MEMBER( 0L, "ql", setEnumProperty, state.layout.alignment, RTFLayout::Left ),
207
PROP( 0L, "qmspace", insertSymbol, 0L, 0x2004 ),
208
MEMBER( 0L, "qr", setEnumProperty, state.layout.alignment, RTFLayout::Right ),
209
PROP( 0L, "rdblquote", insertSymbol, 0L, 0x201d ),
210
MEMBER( "@colortbl", "red", setNumericProperty, red, 0 ),
211
MEMBER( 0L, "ri", setNumericProperty, state.layout.rightIndent, 0 ),
212
PROP( "Text", "row", insertTableRow, 0L, 0 ),
213
PROP( 0L, "rquote", insertSymbol, 0L, 0x2019 ),
214
PROP( 0L, "rtlmark", insertSymbol, 0L, 0x200f ),
215
MEMBER( 0L, "s", setNumericProperty, state.layout.style, 0 ),
216
MEMBER( 0L, "sa", setNumericProperty, state.layout.spaceAfter, 0 ),
217
MEMBER( 0L, "sb", setNumericProperty, state.layout.spaceBefore, 0 ),
218
MEMBER( 0L, "scaps", setToggleProperty, state.format.smallCaps, 0 ),
219
PROP( "Text", "sect", insertPageBreak, 0L, 0 ),
220
PROP( 0L, "sectd", setSectionDefaults, 0L, 0 ),
221
MEMBER( 0L, "sl", setNumericProperty, state.layout.spaceBetween, 0 ),
222
MEMBER( 0L, "slmult", setToggleProperty, state.layout.spaceBetweenMultiple, 0 ),
223
MEMBER( "@stylesheet", "snext", setNumericProperty, style.next, 0 ),
224
MEMBER( 0L, "strike", setToggleProperty, state.format.strike, 0 ),
225
MEMBER( 0L, "striked", setToggleProperty, state.format.striked, 0 ),
226
MEMBER( 0L, "sub", setEnumProperty, state.format.vertAlign, RTFFormat::SubScript ),
227
MEMBER( 0L, "super", setEnumProperty, state.format.vertAlign, RTFFormat::SuperScript ),
228
PROP( 0L, "tab", insertSymbol, 0L, 0x0009 ),
229
MEMBER( 0L, "titlepg", setFlagProperty, state.section.titlePage, true ),
230
MEMBER( 0L, "tldot", setEnumProperty, state.layout.tab.leader, RTFTab::Dots ),
231
MEMBER( 0L, "tlhyph", setEnumProperty, state.layout.tab.leader, RTFTab::Hyphens ),
232
MEMBER( 0L, "tlth", setEnumProperty, state.layout.tab.leader, RTFTab::ThickLine ),
233
MEMBER( 0L, "tlul", setEnumProperty, state.layout.tab.leader, RTFTab::Underline ),
234
MEMBER( 0L, "tqc", setEnumProperty, state.layout.tab.type, RTFTab::Centered ),
235
MEMBER( 0L, "tqdec", setEnumProperty, state.layout.tab.type, RTFTab::Decimal ),
236
MEMBER( 0L, "tqr", setEnumProperty, state.layout.tab.type, RTFTab::FlushRight ),
237
MEMBER( 0L, "trleft", setNumericProperty, state.tableRow.left, 0 ),
238
MEMBER( 0L, "trowd", setTableRowDefaults, state.tableRow, 0 ),
239
MEMBER( 0L, "trqc", setEnumProperty, state.tableRow.alignment, RTFLayout::Centered ),
240
MEMBER( 0L, "trql", setEnumProperty, state.tableRow.alignment, RTFLayout::Left ),
241
MEMBER( 0L, "trqr", setEnumProperty, state.tableRow.alignment, RTFLayout::Right ),
242
MEMBER( 0L, "trrh", setNumericProperty, state.tableRow.height, 0 ),
243
PROP( 0L, "tx", insertTabDef, 0L, 0 ),
244
MEMBER( 0L, "u", insertUnicodeSymbol, state.format.uc, 0 ),
245
MEMBER( 0L, "uc", setNumericProperty, state.format.uc, 0 ),
246
PROP( 0L, "ul", setSimpleUnderlineProperty, 0L, 0 ),
247
MEMBER( 0L, "ulc", setNumericProperty, state.format.underlinecolor, 0 ),
248
PROP( 0L, "uld", setUnderlineProperty, 0L, RTFFormat::UnderlineDot ),
249
PROP( 0L, "uldash", setUnderlineProperty, 0L, RTFFormat::UnderlineDash ),
250
PROP( 0L, "uldashd", setUnderlineProperty, 0L, RTFFormat::UnderlineDashDot ),
251
PROP( 0L, "uldashdd", setUnderlineProperty, 0L, RTFFormat::UnderlineDashDotDot ),
252
PROP( 0L, "uldb", setUnderlineProperty, 0L, RTFFormat::UnderlineDouble ),
253
PROP( 0L, "ulnone", setUnderlineProperty, 0L, RTFFormat::UnderlineNone ),
254
PROP( 0L, "ulth", setUnderlineProperty, 0L, RTFFormat::UnderlineThick ),
255
PROP( 0L, "ulw", setUnderlineProperty, 0L, RTFFormat::UnderlineWordByWord ),
256
PROP( 0L, "ulwave", setUnderlineProperty, 0L, RTFFormat::UnderlineWave ),
257
PROP( 0L, "ulhwave", setUnderlineProperty, 0L, RTFFormat::UnderlineWave ),
258
PROP( 0L, "ululdbwave", setUnderlineProperty, 0L, RTFFormat::UnderlineWave ),
259
MEMBER( 0L, "up", setUpProperty, state.format.baseline, 6 ),
260
MEMBER( 0L, "v", setToggleProperty, state.format.hidden, 0 ),
261
// ### TODO: \wbitmap: a Windows Device-Dependent Bitmap is not a BMP
262
PROP( "@pict", "wbitmap", setPictureType, 0L, RTFPicture::BMP ),
263
PROP( "@pict", "wmetafile", setPictureType, 0L, RTFPicture::EMF ),
264
PROP( 0L, "zwj", insertSymbol, 0L, 0x200d ),
265
PROP( 0L, "zwnj", insertSymbol, 0L, 0x200c )
82
// only-valid-in control word function offset, value
83
PROP("Text", "\n", insertParagraph, 0L, 0),
84
PROP("Text", "\r", insertParagraph, 0L, 0),
85
PROP(0L, "\'", insertHexSymbol, 0L, 0),
86
PROP(0L, "\\", insertSymbol, 0L, '\\'),
87
PROP(0L, "_", insertSymbol, 0L, 0x2011),
88
PROP(0L, "{", insertSymbol, 0L, '{'),
89
PROP(0L, "|", insertSymbol, 0L, 0x00b7),
90
PROP(0L, "}", insertSymbol, 0L, '}'),
91
PROP(0L, "~", insertSymbol, 0L, 0x00a0),
92
PROP(0L, "-", insertSymbol, 0L, 0x00ad),
93
PROP(0L, "adjustright", ignoreKeyword, 0L, 0), // Not supported, KWord has no grid
94
PROP(0L, "ansi", setAnsiCodepage, 0L, 0),
95
PROP(0L, "ansicpg", setCodepage, 0L, 0),
96
MEMBER(0L, "b", setToggleProperty, state.format.bold, 0),
97
// \bin is handled in the tokenizer
98
MEMBER("@colortbl", "blue", setNumericProperty, blue, 0),
99
MEMBER(0L, "box", setEnumProperty, state.layout.border, 0),
100
PROP(0L, "brdrb", selectLayoutBorder, 0L, 3),
101
PROP(0L, "brdrcf", setBorderColor, 0L, 0),
102
PROP(0L, "brdrdash", setBorderStyle, 0L, RTFBorder::Dashes),
103
PROP(0L, "brdrdashd", setBorderStyle, 0L, RTFBorder::DashDot),
104
PROP(0L, "brdrdashdd", setBorderStyle, 0L, RTFBorder::DashDotDot),
105
PROP(0L, "brdrdashsm", setBorderStyle, 0L, RTFBorder::Dashes),
106
PROP(0L, "brdrdb", setBorderStyle, 0L, RTFBorder::Solid),
107
PROP(0L, "brdrdot", setBorderStyle, 0L, RTFBorder::Dots),
108
PROP(0L, "brdrhairline", setBorderStyle, 0L, RTFBorder::Solid),
109
PROP(0L, "brdrl", selectLayoutBorder, 0L, 0),
110
PROP(0L, "brdrr", selectLayoutBorder, 0L, 1),
111
PROP(0L, "brdrs", setBorderStyle, 0L, RTFBorder::Solid),
112
PROP(0L, "brdrsh", setBorderStyle, 0L, RTFBorder::Solid),
113
PROP(0L, "brdrt", selectLayoutBorder, 0L, 2),
114
PROP(0L, "brdrth", setBorderStyle, 0L, RTFBorder::Solid),
115
PROP(0L, "brdrw", setBorderProperty, offsetof(RTFBorder, width), 0),
116
PROP(0L, "bullet", insertSymbol, 0L, 0x2022),
117
PROP(0L, "brsp", setBorderProperty, offsetof(RTFBorder, space), 0),
118
MEMBER(0L, "caps", setToggleProperty, state.format.caps, 0),
119
MEMBER(0L, "cb", setNumericProperty, state.format.bgcolor, 0),
120
MEMBER(0L, "highlight", setNumericProperty, state.format.bgcolor, 0),
121
PROP("Text", "cell", insertTableCell, 0L, 0),
122
PROP(0L, "cellx", insertCellDef, 0L, 0),
123
MEMBER(0L, "cf", setNumericProperty, state.format.color, 0),
124
PROP(0L, "chdate", insertDateTime, 0L, true),
125
PROP(0L, "chpgn", insertPageNumber, 0L, 0),
126
PROP(0L, "chtime", insertDateTime, 0L, false),
127
PROP(0L, "clbrdrb", selectLayoutBorderFromCell, 0L, 3),
128
PROP(0L, "clbrdrl", selectLayoutBorderFromCell, 0L, 0),
129
PROP(0L, "clbrdrr", selectLayoutBorderFromCell, 0L, 1),
130
PROP(0L, "clbrdrt", selectLayoutBorderFromCell, 0L, 2),
131
MEMBER(0L, "clcbpat", setNumericProperty, state.tableCell.bgcolor, 0),
132
PROP(0L, "cs", ignoreKeyword, 0L, 0), // Not supported by KWord 1.3
133
PROP(0L, "datafield", skipGroup, 0L, 0), // Binary data in variables are not supported
134
MEMBER("@rtf", "deff", setNumericProperty, defaultFont, 0),
135
MEMBER("@rtf", "deftab", setNumericProperty, defaultTab, 0),
136
PROP("@pict", "dibitmap", setPictureType, 0L, RTFPicture::BMP),
137
MEMBER(0L, "dn", setNumericProperty, state.format.baseline, 6),
138
PROP(0L, "emdash", insertSymbol, 0L, 0x2014),
139
PROP("@pict", "emfblip", setPictureType, 0L, RTFPicture::EMF),
140
PROP(0L, "emspace", insertSymbol, 0L, 0x2003),
141
PROP(0L, "endash", insertSymbol, 0L, 0x2013),
142
PROP(0L, "enspace", insertSymbol, 0L, 0x2002),
143
PROP(0L, "expnd", ignoreKeyword, 0L, 0), // Expansion/compression of character inter-space not supported
144
PROP(0L, "expndtw", ignoreKeyword, 0L, 0), // Expansion/compression of character inter-space not supported
145
MEMBER(0L, "f", setNumericProperty, state.format.font, 0),
146
MEMBER("@rtf", "facingp", setFlagProperty, facingPages, true),
147
PROP(0L, "fcharset", setCharset, 0L, 0), // Not needed with Qt
148
PROP("@fonttbl", "fdecor", setFontStyleHint, 0L, QFont::Decorative),
149
MEMBER(0L, "fi", setNumericProperty, state.layout.firstIndent, 0),
150
PROP("@fonttbl", "fmodern", setFontStyleHint, 0L, QFont::TypeWriter),
151
PROP("@fonttbl", "fnil", setFontStyleHint, 0L, QFont::AnyStyle),
152
MEMBER(0L, "footery", setNumericProperty, state.section.footerMargin, 0),
153
PROP(0L, "formshade", ignoreKeyword, 0L, 0), // Not supported, KWord has no form support
154
MEMBER("@fonttbl", "fprq", setNumericProperty, font.fixedPitch, 0),
155
PROP("@fonttbl", "froman", setFontStyleHint, 0L, QFont::Serif),
156
MEMBER(0L, "fs", setNumericProperty, state.format.fontSize, 0),
157
PROP("@fonttbl", "fscript", setFontStyleHint, 0L, QFont::AnyStyle),
158
PROP("@fonttbl", "fswiss", setFontStyleHint, 0L, QFont::SansSerif),
159
PROP("@fonttbl", "ftech", setFontStyleHint, 0L, QFont::AnyStyle),
160
MEMBER("@colortbl", "green", setNumericProperty, green, 0),
161
MEMBER(0L, "headery", setNumericProperty, state.section.headerMargin, 0),
162
MEMBER(0L, "i", setToggleProperty, state.format.italic, 0),
163
MEMBER(0L, "intbl", setFlagProperty, state.layout.inTable, true),
164
PROP("@pict", "jpegblip", setPictureType, 0L, RTFPicture::JPEG),
165
MEMBER(0L, "keep", setFlagProperty, state.layout.keep, true),
166
MEMBER(0L, "keepn", setFlagProperty, state.layout.keepNext, true),
167
MEMBER("@rtf", "landscape", setFlagProperty, landscape, true),
168
PROP(0L, "ldblquote", insertSymbol, 0L, 0x201c),
169
MEMBER(0L, "li", setNumericProperty, state.layout.leftIndent, 0),
170
PROP(0L, "line", insertSymbol, 0L, 0x000a),
171
PROP(0L, "lquote", insertSymbol, 0L, 0x2018),
172
PROP(0L, "ltrmark", insertSymbol, 0L, 0x200e),
173
PROP(0L, "mac", setMacCodepage, 0L, 0),
174
PROP("@pict", "macpict", setPictureType, 0L, RTFPicture::MacPict),
175
MEMBER("@rtf", "margb", setNumericProperty, bottomMargin, 0),
176
MEMBER("@rtf", "margl", setNumericProperty, leftMargin, 0),
177
MEMBER("@rtf", "margr", setNumericProperty, rightMargin, 0),
178
MEMBER("@rtf", "margt", setNumericProperty, topMargin, 0),
179
MEMBER(0L, "nosupersub", setEnumProperty, state.format.vertAlign, RTFFormat::Normal),
180
PROP("Text", "page", insertPageBreak, 0L, 0),
181
MEMBER(0L, "pagebb", setFlagProperty, state.layout.pageBB, true),
182
MEMBER("@rtf", "paperh", setNumericProperty, paperHeight, 0),
183
MEMBER("@rtf", "paperw", setNumericProperty, paperWidth, 0),
184
PROP("Text", "par", insertParagraph, 0L, 0),
185
PROP(0L, "pard", setParagraphDefaults, 0L, 0),
186
PROP(0L, "pc", setPcCodepage, 0L, 0),
187
PROP(0L, "pca", setPcaCodepage, 0L, 0),
188
MEMBER(0L, "pgbrk", setToggleProperty, state.layout.pageBA, true),
189
MEMBER("@pict", "piccropb", setNumericProperty, picture.cropBottom, 0),
190
MEMBER("@pict", "piccropl", setNumericProperty, picture.cropLeft, 0),
191
MEMBER("@pict", "piccropr", setNumericProperty, picture.cropRight, 0),
192
MEMBER("@pict", "piccropt", setNumericProperty, picture.cropTop, 0),
193
MEMBER("@pict", "pich", setNumericProperty, picture.height, 0),
194
MEMBER("@pict", "pichgoal", setNumericProperty, picture.desiredHeight, 0),
195
MEMBER("@pict", "picscaled", setFlagProperty, picture.scaled, true),
196
MEMBER("@pict", "picscalex", setNumericProperty, picture.scalex, 0),
197
MEMBER("@pict", "picscaley", setNumericProperty, picture.scaley, 0),
198
MEMBER("@pict", "picw", setNumericProperty, picture.width, 0),
199
MEMBER("@pict", "picwgoal", setNumericProperty, picture.desiredWidth, 0),
200
PROP(0L, "plain", setPlainFormatting, 0L, 0),
201
PROP("@pict", "pmmetafile", setPictureType, 0L, RTFPicture::WMF),
202
PROP("@pict", "pngblip", setPictureType, 0L, RTFPicture::PNG),
203
MEMBER(0L, "qc", setEnumProperty, state.layout.alignment, RTFLayout::Centered),
204
MEMBER(0L, "qj", setEnumProperty, state.layout.alignment, RTFLayout::Justified),
205
MEMBER(0L, "ql", setEnumProperty, state.layout.alignment, RTFLayout::Left),
206
PROP(0L, "qmspace", insertSymbol, 0L, 0x2004),
207
MEMBER(0L, "qr", setEnumProperty, state.layout.alignment, RTFLayout::Right),
208
PROP(0L, "rdblquote", insertSymbol, 0L, 0x201d),
209
MEMBER("@colortbl", "red", setNumericProperty, red, 0),
210
MEMBER(0L, "ri", setNumericProperty, state.layout.rightIndent, 0),
211
PROP("Text", "row", insertTableRow, 0L, 0),
212
PROP(0L, "rquote", insertSymbol, 0L, 0x2019),
213
PROP(0L, "rtlmark", insertSymbol, 0L, 0x200f),
214
MEMBER(0L, "s", setNumericProperty, state.layout.style, 0),
215
MEMBER(0L, "sa", setNumericProperty, state.layout.spaceAfter, 0),
216
MEMBER(0L, "sb", setNumericProperty, state.layout.spaceBefore, 0),
217
MEMBER(0L, "scaps", setToggleProperty, state.format.smallCaps, 0),
218
PROP("Text", "sect", insertPageBreak, 0L, 0),
219
PROP(0L, "sectd", setSectionDefaults, 0L, 0),
220
MEMBER(0L, "sl", setNumericProperty, state.layout.spaceBetween, 0),
221
MEMBER(0L, "slmult", setToggleProperty, state.layout.spaceBetweenMultiple, 0),
222
MEMBER("@stylesheet", "snext", setNumericProperty, style.next, 0),
223
MEMBER(0L, "strike", setToggleProperty, state.format.strike, 0),
224
MEMBER(0L, "striked", setToggleProperty, state.format.striked, 0),
225
MEMBER(0L, "sub", setEnumProperty, state.format.vertAlign, RTFFormat::SubScript),
226
MEMBER(0L, "super", setEnumProperty, state.format.vertAlign, RTFFormat::SuperScript),
227
PROP(0L, "tab", insertSymbol, 0L, 0x0009),
228
MEMBER(0L, "titlepg", setFlagProperty, state.section.titlePage, true),
229
MEMBER(0L, "tldot", setEnumProperty, state.layout.tab.leader, RTFTab::Dots),
230
MEMBER(0L, "tlhyph", setEnumProperty, state.layout.tab.leader, RTFTab::Hyphens),
231
MEMBER(0L, "tlth", setEnumProperty, state.layout.tab.leader, RTFTab::ThickLine),
232
MEMBER(0L, "tlul", setEnumProperty, state.layout.tab.leader, RTFTab::Underline),
233
MEMBER(0L, "tqc", setEnumProperty, state.layout.tab.type, RTFTab::Centered),
234
MEMBER(0L, "tqdec", setEnumProperty, state.layout.tab.type, RTFTab::Decimal),
235
MEMBER(0L, "tqr", setEnumProperty, state.layout.tab.type, RTFTab::FlushRight),
236
MEMBER(0L, "trleft", setNumericProperty, state.tableRow.left, 0),
237
MEMBER(0L, "trowd", setTableRowDefaults, state.tableRow, 0),
238
MEMBER(0L, "trqc", setEnumProperty, state.tableRow.alignment, RTFLayout::Centered),
239
MEMBER(0L, "trql", setEnumProperty, state.tableRow.alignment, RTFLayout::Left),
240
MEMBER(0L, "trqr", setEnumProperty, state.tableRow.alignment, RTFLayout::Right),
241
MEMBER(0L, "trrh", setNumericProperty, state.tableRow.height, 0),
242
PROP(0L, "tx", insertTabDef, 0L, 0),
243
MEMBER(0L, "u", insertUnicodeSymbol, state.format.uc, 0),
244
MEMBER(0L, "uc", setNumericProperty, state.format.uc, 0),
245
PROP(0L, "ul", setSimpleUnderlineProperty, 0L, 0),
246
MEMBER(0L, "ulc", setNumericProperty, state.format.underlinecolor, 0),
247
PROP(0L, "uld", setUnderlineProperty, 0L, RTFFormat::UnderlineDot),
248
PROP(0L, "uldash", setUnderlineProperty, 0L, RTFFormat::UnderlineDash),
249
PROP(0L, "uldashd", setUnderlineProperty, 0L, RTFFormat::UnderlineDashDot),
250
PROP(0L, "uldashdd", setUnderlineProperty, 0L, RTFFormat::UnderlineDashDotDot),
251
PROP(0L, "uldb", setUnderlineProperty, 0L, RTFFormat::UnderlineDouble),
252
PROP(0L, "ulnone", setUnderlineProperty, 0L, RTFFormat::UnderlineNone),
253
PROP(0L, "ulth", setUnderlineProperty, 0L, RTFFormat::UnderlineThick),
254
PROP(0L, "ulw", setUnderlineProperty, 0L, RTFFormat::UnderlineWordByWord),
255
PROP(0L, "ulwave", setUnderlineProperty, 0L, RTFFormat::UnderlineWave),
256
PROP(0L, "ulhwave", setUnderlineProperty, 0L, RTFFormat::UnderlineWave),
257
PROP(0L, "ululdbwave", setUnderlineProperty, 0L, RTFFormat::UnderlineWave),
258
MEMBER(0L, "up", setUpProperty, state.format.baseline, 6),
259
MEMBER(0L, "v", setToggleProperty, state.format.hidden, 0),
260
// ### TODO: \wbitmap: a Windows Device-Dependent Bitmap is not a BMP
261
PROP("@pict", "wbitmap", setPictureType, 0L, RTFPicture::BMP),
262
PROP("@pict", "wmetafile", setPictureType, 0L, RTFPicture::EMF),
263
PROP(0L, "zwj", insertSymbol, 0L, 0x200d),
264
PROP(0L, "zwnj", insertSymbol, 0L, 0x200c)
268
static RTFField fieldTable[] =
270
// id type subtype default value
271
{ "AUTHOR", 8, 2, "NO AUTHOR" },
272
{ "FILENAME", 8, 0, "NO FILENAME" },
273
{ "TITLE", 8, 10, "NO TITLE" },
274
{ "NUMPAGES", 4, 1, 0 },
276
{ "TIME", -1, -1, 0 },
277
{ "DATE", -1, -1, 0 },
278
{ "HYPERLINK", 9, -1, 0 },
279
{ "SYMBOL", -1, -1, 0 },
280
{ "IMPORT", -1, -1, 0 }
267
static RTFField fieldTable[] = {
268
// id type subtype default value
269
{ "AUTHOR", 8, 2, "NO AUTHOR" },
270
{ "FILENAME", 8, 0, "NO FILENAME" },
271
{ "TITLE", 8, 10, "NO TITLE" },
272
{ "NUMPAGES", 4, 1, 0 },
274
{ "TIME", -1, -1, 0 },
275
{ "DATE", -1, -1, 0 },
276
{ "HYPERLINK", 9, -1, 0 },
277
{ "SYMBOL", -1, -1, 0 },
278
{ "IMPORT", -1, -1, 0 }
284
282
// KWord attributes
285
static const char *alignN[4] = { "left", "right", "justify", "center" };
286
static const char *boolN[2] = { "false", "true" };
287
static const char *borderN[4] = { "LEFTBORDER", "RIGHTBORDER", "TOPBORDER", "BOTTOMBORDER" };
283
static const char *alignN[4] = { "left", "right", "justify", "center" };
284
static const char *boolN[2] = { "false", "true" };
285
static const char *borderN[4] = { "LEFTBORDER", "RIGHTBORDER", "TOPBORDER", "BOTTOMBORDER" };
289
RTFImport::RTFImport( QObject* parent, const QStringList& )
287
RTFImport::RTFImport(QObject* parent, const QStringList&)
294
for (uint i=0; i < sizeof(propertyTable) / sizeof(propertyTable[0]); i++)
296
properties.insert( propertyTable[i].name, &propertyTable[i] );
292
for (uint i = 0; i < sizeof(propertyTable) / sizeof(propertyTable[0]); i++) {
293
properties.insert(propertyTable[i].name, &propertyTable[i]);
298
for (uint i=0; i < sizeof(destinationPropertyTable) / sizeof(destinationPropertyTable[0]); i++)
300
destinationProperties.insert( destinationPropertyTable[i].name, &destinationPropertyTable[i] );
295
for (uint i = 0; i < sizeof(destinationPropertyTable) / sizeof(destinationPropertyTable[0]); i++) {
296
destinationProperties.insert(destinationPropertyTable[i].name, &destinationPropertyTable[i]);
303
299
// Check the hash size (see QDict doc)
304
kDebug(30515) << properties.count() <<" normal and" << destinationProperties.count() <<" destination keywords loaded";
300
kDebug(30515) << properties.count() << " normal and" << destinationProperties.count() << " destination keywords loaded";
305
301
if (properties.size() < properties.count())
306
302
kWarning(30515) << "Hash size of properties too small: " << properties.size() << ". It should be at least " << properties.count() << " and be a prime number";
307
303
if (destinationProperties.size() < destinationProperties.count())
308
304
kWarning(30515) << "Hash size of destinationProperties too small: " << destinationProperties.size() << ". It should be at least " << destinationProperties.count() << " and be a prime number";
313
KoFilter::ConversionStatus RTFImport::convert( const QByteArray& from, const QByteArray& to )
309
KoFilter::ConversionStatus RTFImport::convert(const QByteArray& from, const QByteArray& to)
315
311
// This filter only supports RTF to KWord conversion
316
312
if ((from != "application/rtf") || (to != "application/x-kword"))
365
if (token.type != RTFTokenizer::ControlWord)
357
if (token.type != RTFTokenizer::ControlWord) {
367
358
kError(30515) << "Wrong document type";
371
KMessageBox::error( 0L,
372
i18n("The document cannot be loaded, as it seems not to follow the RTF syntax."),
373
i18n("KWord's RTF Import Filter"), 0 );
361
KMessageBox::error(0L,
362
i18n("The document cannot be loaded, as it seems not to follow the RTF syntax."),
363
i18n("KWord's RTF Import Filter"), 0);
375
365
return KoFilter::WrongFormat;
378
368
bool force = false; // By default do not force, despite an unknown keyword or version
379
if ( !qstrcmp( token.text, "rtf" ) )
369
if (!qstrcmp(token.text, "rtf")) {
381
370
// RTF is normally version 1 but at least Ted uses 0 as version number
382
if ( token.value > 1 )
371
if (token.value > 1) {
384
372
kError(30515) << "Wrong RTF version (" << token.value << "); version 0 or 1 expected";
387
force = ( KMessageBox::warningYesNo( 0L,
388
i18n("The RTF (Rich Text Format) document has an unexpected version number: %1. Continuing might result in an erroneous conversion. Do you want to continue?", token.value ),
389
i18n("KWord's RTF Import Filter") ) == KMessageBox::Yes );
374
force = (KMessageBox::warningYesNo(0L,
375
i18n("The RTF (Rich Text Format) document has an unexpected version number: %1. Continuing might result in an erroneous conversion. Do you want to continue?", token.value),
376
i18n("KWord's RTF Import Filter")) == KMessageBox::Yes);
394
380
return KoFilter::WrongFormat;
398
else if ( !qstrcmp( token.text, "pwd" ) )
383
} else if (!qstrcmp(token.text, "pwd")) {
400
384
// PocketWord's PWD format is similar to RTF but has a version number of 2.
401
if ( token.value != 2 )
385
if (token.value != 2) {
403
386
kError(30515) << "Wrong PWD version (" << token.value << "); version 2 expected";
406
force = ( KMessageBox::warningYesNo( 0L,
407
i18n("The PWD (PocketWord's Rich Text Format) document has an unexpected version number: %1. Continuing might result in an erroneous conversion. Do you want to continue?", token.value ),
408
i18n("KWord's RTF Import Filter") ) == KMessageBox::Yes );
388
force = (KMessageBox::warningYesNo(0L,
389
i18n("The PWD (PocketWord's Rich Text Format) document has an unexpected version number: %1. Continuing might result in an erroneous conversion. Do you want to continue?", token.value),
390
i18n("KWord's RTF Import Filter")) == KMessageBox::Yes);
413
394
return KoFilter::WrongFormat;
417
else if ( !qstrcmp( token.text, "urtf" ) )
397
} else if (!qstrcmp(token.text, "urtf")) {
419
398
// URTF seems to have either no version or having version 1
420
if ( token.value > 1 )
399
if (token.value > 1) {
422
400
kError(30515) << "Wrong URTF version (" << token.value << "); version 0 or 1 expected";
425
force = ( KMessageBox::warningYesNo( 0L,
426
i18n("The URTF (\"Unicode Rich Text Format\") document has an unexpected version number: %1. Continuing might result in an erroneous conversion. Do you want to continue?", token.value ),
427
i18n("KWord's RTF Import Filter") ) == KMessageBox::Yes );
402
force = (KMessageBox::warningYesNo(0L,
403
i18n("The URTF (\"Unicode Rich Text Format\") document has an unexpected version number: %1. Continuing might result in an erroneous conversion. Do you want to continue?", token.value),
404
i18n("KWord's RTF Import Filter")) == KMessageBox::Yes);
432
408
return KoFilter::WrongFormat;
438
412
kError(30515) << "Wrong RTF document type (\\" << token.text << "); \\rtf, \\pwd or \\urtf expected";
442
KMessageBox::error( 0L,
443
i18n("The RTF document cannot be loaded, as it has an unexpected first keyword: \\%1.",token.text ),
444
i18n("KWord's RTF Import Filter"), 0 );
415
KMessageBox::error(0L,
416
i18n("The RTF document cannot be loaded, as it has an unexpected first keyword: \\%1.", token.text),
417
i18n("KWord's RTF Import Filter"), 0);
446
419
return KoFilter::WrongFormat;
452
425
// Document-formatting properties
464
437
// Create main document
465
frameSets.clear( 2 );
466
439
pictures.clear();
467
bodyText.node.clear( 3 );
468
firstPageHeader.node.clear( 3 );
469
oddPagesHeader.node.clear( 3 );
470
evenPagesHeader.node.clear( 3 );
471
firstPageFooter.node.clear( 3 );
472
oddPagesFooter.node.clear( 3 );
473
evenPagesFooter.node.clear( 3 );
440
bodyText.node.clear(3);
441
firstPageHeader.node.clear(3);
442
oddPagesHeader.node.clear(3);
443
evenPagesHeader.node.clear(3);
444
firstPageFooter.node.clear(3);
445
oddPagesFooter.node.clear(3);
446
evenPagesFooter.node.clear(3);
479
stateStack.push( state );
452
stateStack.push(state);
481
454
// Add a security item for the destination stack
482
455
destination.name = "!stackbottom";
484
changeDestination( destinationProperties["@rtf"] );
457
changeDestination(destinationProperties["@rtf"]);
487
460
emptyCell = state.tableCell;
489
462
state.ignoreGroup = false;
491
utf8TextCodec=QTextCodec::codecForName("UTF-8");
492
kDebug(30515) <<"UTF-8 asked, given:" << (utf8TextCodec?utf8TextCodec->name():QString("-none-"));
464
utf8TextCodec = QTextCodec::codecForName("UTF-8");
465
kDebug(30515) << "UTF-8 asked, given:" << (utf8TextCodec ? utf8TextCodec->name() : QString("-none-"));
494
467
// There is no default encoding in RTF, it must be always declared. (But beware of buggy files!)
495
textCodec=QTextCodec::codecForName("CP 1252"); // Or IBM 437 ?
496
kDebug(30515) <<"CP 1252 asked, given:" << (textCodec?textCodec->name():QString("-none-"));
468
textCodec = QTextCodec::codecForName("CP 1252"); // Or IBM 437 ?
469
kDebug(30515) << "CP 1252 asked, given:" << (textCodec ? textCodec->name() : QString("-none-"));
498
471
// Parse RTF document
501
473
bool firstToken = false;
502
474
bool ignoreUnknown = false;
506
while (token.type == RTFTokenizer::OpenGroup)
478
while (token.type == RTFTokenizer::OpenGroup) {
508
479
// Store the current state on the stack
509
stateStack.push( state );
480
stateStack.push(state);
510
481
state.brace0 = false;
511
482
firstToken = true;
512
483
ignoreUnknown = false;
516
if (token.type == RTFTokenizer::ControlWord && !qstrcmp( token.text, "*" ))
487
if (token.type == RTFTokenizer::ControlWord && !qstrcmp(token.text, "*")) {
518
488
// {\*\control ...} destination
519
489
ignoreUnknown = true;
523
if (token.type == RTFTokenizer::CloseGroup)
493
if (token.type == RTFTokenizer::CloseGroup) {
527
495
// Close the current destination
528
496
(this->*destination.destproc)(0L);
529
497
//kDebug(30515) <<"Closing destination..." << destinationStack.count();
530
if (destinationStack.isEmpty())
498
if (destinationStack.isEmpty()) {
532
499
kWarning(30515) << "Destination stack is empty! Document might be buggy!";
533
500
// Keep the destination to save what can still be saved!
537
502
destination = destinationStack.pop();
540
505
// ### TODO: why can this not be simplified to use QValueList::isEmpty()
541
if (stateStack.count() <= 1)
506
if (stateStack.count() <= 1) {
543
507
// End-of-document, keep formatting properties
544
508
stateStack.pop();
549
511
// Retrieve the current state from the stack
550
512
state = stateStack.pop();
553
else if (token.type == RTFTokenizer::ControlWord)
514
} else if (token.type == RTFTokenizer::ControlWord) {
555
515
RTFProperty *property = properties[token.text];
517
if (property != 0L) {
559
518
if (property->onlyValidIn == 0L ||
560
property->onlyValidIn == destination.name ||
561
property->onlyValidIn == destination.group)
563
(this->*property->cwproc)( property );
519
property->onlyValidIn == destination.name ||
520
property->onlyValidIn == destination.group) {
521
(this->*property->cwproc)(property);
523
} else if (firstToken) {
568
524
// Possible destination change
569
525
*(--token.text) = '@';
570
526
property = destinationProperties[token.text];
572
528
if ((property != 0L) &&
573
(property->onlyValidIn == 0L ||
574
property->onlyValidIn == destination.name ||
575
property->onlyValidIn == destination.group))
529
(property->onlyValidIn == 0L ||
530
property->onlyValidIn == destination.name ||
531
property->onlyValidIn == destination.group)) {
577
532
// Change destination
578
changeDestination( property );
580
else if (ignoreUnknown)
533
changeDestination(property);
534
} else if (ignoreUnknown) {
582
535
// Skip unknown {\* ...} destination
583
changeDestination( destinationProperties["@*"] );
536
changeDestination(destinationProperties["@*"]);
584
537
debugUnknownKeywords[token.text]++;
586
else if ( !property )
588
kWarning(30515) << "Unknown first non-ignorable token of a group: " << token.text; kDebug(30515) <<"Destination:" << ( (void*) destination.name ) <<" Destination stack depth:" << destinationStack.count();
538
} else if (!property) {
539
kWarning(30515) << "Unknown first non-ignorable token of a group: " << token.text; kDebug(30515) << "Destination:" << ((void*) destination.name) << " Destination stack depth:" << destinationStack.count();
589
540
// Put the second warning separately, as it can crash if destination.name is dangling
590
541
kWarning(30515) << " Assuming destination: " << destination.name;
591
542
debugUnknownKeywords[token.text]++;
596
545
debugUnknownKeywords[token.text]++;
599
else if (token.type == RTFTokenizer::PlainText || token.type == RTFTokenizer::BinaryData)
547
} else if (token.type == RTFTokenizer::PlainText || token.type == RTFTokenizer::BinaryData) {
601
548
(this->*destination.destproc)(0L);
605
552
// Determine header and footer type
606
553
const int hType = facingPages
607
? (state.section.titlePage ? 3 : 1) : (state.section.titlePage ? 2 : 0);
554
? (state.section.titlePage ? 3 : 1) : (state.section.titlePage ? 2 : 0);
609
556
const bool hasHeader = !oddPagesHeader.node.isEmpty() ||
610
(facingPages &&!evenPagesHeader.node.isEmpty()) ||
611
(state.section.titlePage && !firstPageHeader.node.isEmpty());
557
(facingPages && !evenPagesHeader.node.isEmpty()) ||
558
(state.section.titlePage && !firstPageHeader.node.isEmpty());
612
559
const bool hasFooter = !oddPagesFooter.node.isEmpty() ||
613
(facingPages && !evenPagesFooter.node.isEmpty()) ||
614
(state.section.titlePage && !firstPageFooter.node.isEmpty());
560
(facingPages && !evenPagesFooter.node.isEmpty()) ||
561
(state.section.titlePage && !firstPageFooter.node.isEmpty());
616
kDebug(30515) <<"hType" << hType <<" hasHeader" << hasHeader <<" hasFooter" << hasFooter;
563
kDebug(30515) << "hType" << hType << " hasHeader" << hasHeader << " hasFooter" << hasFooter;
618
565
// Create main document
619
DomNode mainDoc( "DOC" );
620
mainDoc.setAttribute( "mime", "application/x-kword" );
621
mainDoc.setAttribute( "syntaxVersion", "3" );
622
mainDoc.setAttribute( "editor", "KWord's RTF Import Filter" );
623
mainDoc.addNode( "PAPER" );
624
mainDoc.setAttribute( "format", 6 );
625
mainDoc.setAttribute( "columns", 1 );
626
mainDoc.setAttribute( "columnspacing", 2 );
627
mainDoc.setAttribute( "spHeadBody", 4 );
628
mainDoc.setAttribute( "spFootBody", 4 );
629
mainDoc.setAttribute( "zoom", 100 );
630
mainDoc.setAttribute( "width", .05*paperWidth );
631
mainDoc.setAttribute( "height", .05*paperHeight );
632
mainDoc.setAttribute( "orientation", landscape );
633
mainDoc.setAttribute( "hType", hType );
634
mainDoc.setAttribute( "fType", hType );
635
mainDoc.addNode( "PAPERBORDERS" );
636
mainDoc.addRect( leftMargin,
637
(hasHeader ? state.section.headerMargin : topMargin),
639
(hasFooter ? state.section.footerMargin : bottomMargin) );
640
mainDoc.closeNode( "PAPERBORDERS" );
641
mainDoc.closeNode( "PAPER" );
642
mainDoc.addNode( "ATTRIBUTES" );
643
mainDoc.setAttribute( "standardpage", 1 );
644
mainDoc.setAttribute( "processing", 0 );
645
//mainDoc.setAttribute( "unit", "pt" ); // use KWord default instead
646
mainDoc.setAttribute( "hasHeader", hasHeader );
647
mainDoc.setAttribute( "hasFooter", hasFooter );
648
mainDoc.closeNode( "ATTRIBUTES" );
649
mainDoc.addNode( "FRAMESETS" );
650
mainDoc.addFrameSet( "Frameset 1", 1, 0 );
651
mainDoc.addFrame( leftMargin, topMargin, (paperWidth - rightMargin),
652
(paperHeight - bottomMargin), 1, 0, 0 );
653
mainDoc.closeNode( "FRAME" );
654
mainDoc.appendNode( bodyText.node );
655
mainDoc.closeNode( "FRAMESET" );
659
mainDoc.addFrameSet( "First Page Header", 1, 1 );
660
mainDoc.addFrame( leftMargin, state.section.headerMargin,
661
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 0 );
662
mainDoc.closeNode( "FRAME" );
663
mainDoc.appendNode( firstPageHeader.node );
664
mainDoc.closeNode( "FRAMESET" );
665
mainDoc.addFrameSet( "Odd Pages Header", 1, 2 );
666
mainDoc.addFrame( leftMargin, state.section.headerMargin,
667
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 1 );
668
mainDoc.closeNode( "FRAME" );
669
mainDoc.appendNode( oddPagesHeader.node );
670
mainDoc.closeNode( "FRAMESET" );
671
mainDoc.addFrameSet( "Even Pages Header", 1, 3 );
672
mainDoc.addFrame( leftMargin, state.section.headerMargin,
673
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 2 );
674
mainDoc.closeNode( "FRAME" );
675
mainDoc.appendNode( evenPagesHeader.node );
676
mainDoc.closeNode( "FRAMESET" );
681
mainDoc.addFrameSet( "First Page Footer", 1, 4 );
682
mainDoc.addFrame( leftMargin, state.section.headerMargin,
683
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 0 );
684
mainDoc.closeNode( "FRAME" );
685
mainDoc.appendNode( firstPageFooter.node );
686
mainDoc.closeNode( "FRAMESET" );
687
mainDoc.addFrameSet( "Odd Pages Footer", 1, 5 );
688
mainDoc.addFrame( leftMargin, state.section.headerMargin,
689
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 1 );
690
mainDoc.closeNode( "FRAME" );
691
mainDoc.appendNode( oddPagesFooter.node );
692
mainDoc.closeNode( "FRAMESET" );
693
mainDoc.addFrameSet( "Even Pages Footer", 1, 6 );
694
mainDoc.addFrame( leftMargin, state.section.headerMargin,
695
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 2 );
696
mainDoc.closeNode( "FRAME" );
697
mainDoc.appendNode( evenPagesFooter.node );
698
mainDoc.closeNode( "FRAMESET" );
700
// Write out footnotes
702
foreach(RTFTextState* footnote, footnotes)
706
str.prepend("Footnote ");
708
mainDoc.addFrameSet( str, 1, 7 );
709
mainDoc.addFrame( leftMargin, paperHeight - bottomMargin-80,
710
(paperWidth - rightMargin), paperHeight-bottomMargin, 0, 2, 0 );
711
mainDoc.closeNode( "FRAME" );
712
mainDoc.appendNode( footnote->node );
713
mainDoc.closeNode( "FRAMESET" );
715
mainDoc.appendNode( frameSets );
716
mainDoc.closeNode( "FRAMESETS" );
717
mainDoc.addNode( "PICTURES" );
718
mainDoc.appendNode( pictures );
719
mainDoc.closeNode( "PICTURES" );
720
mainDoc.addNode( "STYLES" );
725
// Process all styles in the style sheet
726
const QVector<RTFStyle>::ConstIterator endStyleSheet=styleSheet.constEnd();
727
for (QVector<RTFStyle>::ConstIterator it=styleSheet.constBegin();it!=endStyleSheet;++it)
729
mainDoc.addNode( "STYLE" );
730
kwFormat.fmt = (*it).format;
732
// Search for 'following' style
733
for (QVector<RTFStyle>::ConstIterator it2=styleSheet.constBegin();it2!=endStyleSheet;++it2)
735
if ((*it2).layout.style == (*it).next)
737
mainDoc.addNode( "FOLLOWING" );
738
mainDoc.setAttribute( "name", CheckAndEscapeXmlText( (*it2).name ));
739
mainDoc.closeNode( "FOLLOWING");
566
DomNode mainDoc("DOC");
567
mainDoc.setAttribute("mime", "application/x-kword");
568
mainDoc.setAttribute("syntaxVersion", "3");
569
mainDoc.setAttribute("editor", "KWord's RTF Import Filter");
570
mainDoc.addNode("PAPER");
571
mainDoc.setAttribute("format", 6);
572
mainDoc.setAttribute("columns", 1);
573
mainDoc.setAttribute("columnspacing", 2);
574
mainDoc.setAttribute("spHeadBody", 4);
575
mainDoc.setAttribute("spFootBody", 4);
576
mainDoc.setAttribute("zoom", 100);
577
mainDoc.setAttribute("width", .05*paperWidth);
578
mainDoc.setAttribute("height", .05*paperHeight);
579
mainDoc.setAttribute("orientation", landscape);
580
mainDoc.setAttribute("hType", hType);
581
mainDoc.setAttribute("fType", hType);
582
mainDoc.addNode("PAPERBORDERS");
583
mainDoc.addRect(leftMargin,
584
(hasHeader ? state.section.headerMargin : topMargin),
586
(hasFooter ? state.section.footerMargin : bottomMargin));
587
mainDoc.closeNode("PAPERBORDERS");
588
mainDoc.closeNode("PAPER");
589
mainDoc.addNode("ATTRIBUTES");
590
mainDoc.setAttribute("standardpage", 1);
591
mainDoc.setAttribute("processing", 0);
592
//mainDoc.setAttribute( "unit", "pt" ); // use KWord default instead
593
mainDoc.setAttribute("hasHeader", hasHeader);
594
mainDoc.setAttribute("hasFooter", hasFooter);
595
mainDoc.closeNode("ATTRIBUTES");
596
mainDoc.addNode("FRAMESETS");
597
mainDoc.addFrameSet("Frameset 1", 1, 0);
598
mainDoc.addFrame(leftMargin, topMargin, (paperWidth - rightMargin),
599
(paperHeight - bottomMargin), 1, 0, 0);
600
mainDoc.closeNode("FRAME");
601
mainDoc.appendNode(bodyText.node);
602
mainDoc.closeNode("FRAMESET");
605
mainDoc.addFrameSet("First Page Header", 1, 1);
606
mainDoc.addFrame(leftMargin, state.section.headerMargin,
607
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 0);
608
mainDoc.closeNode("FRAME");
609
mainDoc.appendNode(firstPageHeader.node);
610
mainDoc.closeNode("FRAMESET");
611
mainDoc.addFrameSet("Odd Pages Header", 1, 2);
612
mainDoc.addFrame(leftMargin, state.section.headerMargin,
613
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 1);
614
mainDoc.closeNode("FRAME");
615
mainDoc.appendNode(oddPagesHeader.node);
616
mainDoc.closeNode("FRAMESET");
617
mainDoc.addFrameSet("Even Pages Header", 1, 3);
618
mainDoc.addFrame(leftMargin, state.section.headerMargin,
619
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 2);
620
mainDoc.closeNode("FRAME");
621
mainDoc.appendNode(evenPagesHeader.node);
622
mainDoc.closeNode("FRAMESET");
626
mainDoc.addFrameSet("First Page Footer", 1, 4);
627
mainDoc.addFrame(leftMargin, state.section.headerMargin,
628
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 0);
629
mainDoc.closeNode("FRAME");
630
mainDoc.appendNode(firstPageFooter.node);
631
mainDoc.closeNode("FRAMESET");
632
mainDoc.addFrameSet("Odd Pages Footer", 1, 5);
633
mainDoc.addFrame(leftMargin, state.section.headerMargin,
634
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 1);
635
mainDoc.closeNode("FRAME");
636
mainDoc.appendNode(oddPagesFooter.node);
637
mainDoc.closeNode("FRAMESET");
638
mainDoc.addFrameSet("Even Pages Footer", 1, 6);
639
mainDoc.addFrame(leftMargin, state.section.headerMargin,
640
(paperWidth - rightMargin), (topMargin - 80), 0, 2, 2);
641
mainDoc.closeNode("FRAME");
642
mainDoc.appendNode(evenPagesFooter.node);
643
mainDoc.closeNode("FRAMESET");
645
// Write out footnotes
647
foreach(RTFTextState* footnote, footnotes) {
650
str.prepend("Footnote ");
652
mainDoc.addFrameSet(str, 1, 7);
653
mainDoc.addFrame(leftMargin, paperHeight - bottomMargin - 80,
654
(paperWidth - rightMargin), paperHeight - bottomMargin, 0, 2, 0);
655
mainDoc.closeNode("FRAME");
656
mainDoc.appendNode(footnote->node);
657
mainDoc.closeNode("FRAMESET");
659
mainDoc.appendNode(frameSets);
660
mainDoc.closeNode("FRAMESETS");
661
mainDoc.addNode("PICTURES");
662
mainDoc.appendNode(pictures);
663
mainDoc.closeNode("PICTURES");
664
mainDoc.addNode("STYLES");
669
// Process all styles in the style sheet
670
const QVector<RTFStyle>::ConstIterator endStyleSheet = styleSheet.constEnd();
671
for (QVector<RTFStyle>::ConstIterator it = styleSheet.constBegin();it != endStyleSheet;++it) {
672
mainDoc.addNode("STYLE");
673
kwFormat.fmt = (*it).format;
675
// Search for 'following' style
676
for (QVector<RTFStyle>::ConstIterator it2 = styleSheet.constBegin();it2 != endStyleSheet;++it2) {
677
if ((*it2).layout.style == (*it).next) {
678
mainDoc.addNode("FOLLOWING");
679
mainDoc.setAttribute("name", CheckAndEscapeXmlText((*it2).name));
680
mainDoc.closeNode("FOLLOWING");
743
addLayout( mainDoc, (*it).name, (*it).layout, false );
744
addFormat( mainDoc, kwFormat, 0L );
745
mainDoc.closeNode( "STYLE" );
747
mainDoc.closeNode( "STYLES" );
748
mainDoc.closeNode( "DOC" );
684
addLayout(mainDoc, (*it).name, (*it).layout, false);
685
addFormat(mainDoc, kwFormat, 0L);
686
mainDoc.closeNode("STYLE");
688
mainDoc.closeNode("STYLES");
689
mainDoc.closeNode("DOC");
750
691
// Create document info
751
DomNode docInfo( "document-info" );
752
docInfo.addNode( "log" );
753
docInfo.addNode( "text" );
754
docInfo.closeNode( "text" );
755
docInfo.closeNode( "log" );
756
docInfo.addNode( "author" );
757
docInfo.addNode( "company" );
758
docInfo.appendNode( company );
759
docInfo.closeNode( "company" );
760
docInfo.addNode( "full-name" );
761
docInfo.appendNode( author );
762
docInfo.closeNode( "full-name" );
763
docInfo.addNode( "email" );
764
docInfo.closeNode( "email" );
765
docInfo.addNode( "telephone" );
766
docInfo.closeNode( "telephone" );
767
docInfo.addNode( "fax" );
768
docInfo.closeNode( "fax" );
769
docInfo.addNode( "country" );
770
docInfo.closeNode( "country" );
771
docInfo.addNode( "postal-code" );
772
docInfo.closeNode( "postal-code" );
773
docInfo.addNode( "city" );
774
docInfo.closeNode( "city" );
775
docInfo.addNode( "street" );
776
docInfo.closeNode( "street" );
777
docInfo.closeNode( "author" );
778
docInfo.addNode( "about" );
779
docInfo.addNode( "abstract" );
780
docInfo.appendNode( doccomm );
781
docInfo.closeNode( "abstract" );
782
docInfo.addNode( "title" );
783
docInfo.appendNode( title );
784
docInfo.closeNode( "title" );
785
docInfo.closeNode( "about" );
786
docInfo.closeNode( "document-info" );
692
DomNode docInfo("document-info");
693
docInfo.addNode("log");
694
docInfo.addNode("text");
695
docInfo.closeNode("text");
696
docInfo.closeNode("log");
697
docInfo.addNode("author");
698
docInfo.addNode("company");
699
docInfo.appendNode(company);
700
docInfo.closeNode("company");
701
docInfo.addNode("full-name");
702
docInfo.appendNode(author);
703
docInfo.closeNode("full-name");
704
docInfo.addNode("email");
705
docInfo.closeNode("email");
706
docInfo.addNode("telephone");
707
docInfo.closeNode("telephone");
708
docInfo.addNode("fax");
709
docInfo.closeNode("fax");
710
docInfo.addNode("country");
711
docInfo.closeNode("country");
712
docInfo.addNode("postal-code");
713
docInfo.closeNode("postal-code");
714
docInfo.addNode("city");
715
docInfo.closeNode("city");
716
docInfo.addNode("street");
717
docInfo.closeNode("street");
718
docInfo.closeNode("author");
719
docInfo.addNode("about");
720
docInfo.addNode("abstract");
721
docInfo.appendNode(doccomm);
722
docInfo.closeNode("abstract");
723
docInfo.addNode("title");
724
docInfo.appendNode(title);
725
docInfo.closeNode("title");
726
docInfo.closeNode("about");
727
docInfo.closeNode("document-info");
788
729
// Write out main document and document info
789
writeOutPart( "root", mainDoc );
790
writeOutPart( "documentinfo.xml", docInfo );
730
writeOutPart("root", mainDoc);
731
writeOutPart("documentinfo.xml", docInfo);
793
kDebug(30515) <<"RTF FILTER TIME:" << debugTime.elapsed();
734
kDebug(30515) << "RTF FILTER TIME:" << debugTime.elapsed();
795
for (QMap<QString,int>::ConstIterator it=debugUnknownKeywords.constBegin();
796
it!=debugUnknownKeywords.constEnd();it++)
797
kDebug(30515) <<"Unknown keyword:" << QString("%1" ).arg( it.value(), 4 ) <<" *" << it.key();
736
for (QMap<QString, int>::ConstIterator it = debugUnknownKeywords.constBegin();
737
it != debugUnknownKeywords.constEnd();it++)
738
kDebug(30515) << "Unknown keyword:" << QString("%1").arg(it.value(), 4) << " *" << it.key();
799
740
return KoFilter::OK;
802
void RTFImport::ignoreKeyword( RTFProperty * )
743
void RTFImport::ignoreKeyword(RTFProperty *)
806
void RTFImport::setCodepage( RTFProperty * )
747
void RTFImport::setCodepage(RTFProperty *)
808
749
QTextCodec* oldCodec = textCodec;
810
if ( token.value == 10000 )
751
if (token.value == 10000) {
812
752
cp = "Apple Roman"; // ### TODO: how to support the other ones (Qt does not know them!)
816
cp.setNum( token.value );
754
cp.setNum(token.value);
817
755
cp.prepend("CP");
819
textCodec=QTextCodec::codecForName(cp);
820
kDebug(30515) <<"\\ansicpg: codepage:" << token.value <<"asked:"<< cp <<" given:" << (textCodec?textCodec->name():QString("-none-"));
822
textCodec = oldCodec;
825
void RTFImport::setMacCodepage( RTFProperty * )
827
QTextCodec* oldCodec = textCodec;
828
textCodec=QTextCodec::codecForName("Apple Roman");
829
kDebug(30515) <<"\\mac" << (textCodec?textCodec->name():QString("-none-"));
831
textCodec = oldCodec;
834
void RTFImport::setAnsiCodepage( RTFProperty * )
836
QTextCodec* oldCodec = textCodec;
837
textCodec=QTextCodec::codecForName("CP1252");
838
kDebug(30515) <<"\\ansi" << (textCodec?textCodec->name():QString("-none-"));
840
textCodec = oldCodec;
843
void RTFImport::setPcaCodepage( RTFProperty * )
845
QTextCodec* oldCodec = textCodec;
846
textCodec=QTextCodec::codecForName("IBM 850"); // Qt writes the name with a space
847
kDebug(30515) <<"\\pca" << (textCodec?textCodec->name():QString("-none-"));
849
textCodec = oldCodec;
852
void RTFImport::setPcCodepage( RTFProperty * )
854
QTextCodec* oldCodec = textCodec;
855
textCodec=QTextCodec::codecForName("IBM 850"); // This is an approximation
856
kDebug(30515) <<"\\pc (approximation)" << (textCodec?textCodec->name():QString("-none-"));
858
textCodec = oldCodec;
861
void RTFImport::setToggleProperty( RTFProperty *property )
757
textCodec = QTextCodec::codecForName(cp);
758
kDebug(30515) << "\\ansicpg: codepage:" << token.value << "asked:" << cp << " given:" << (textCodec ? textCodec->name() : QString("-none-"));
760
textCodec = oldCodec;
763
void RTFImport::setMacCodepage(RTFProperty *)
765
QTextCodec* oldCodec = textCodec;
766
textCodec = QTextCodec::codecForName("Apple Roman");
767
kDebug(30515) << "\\mac" << (textCodec ? textCodec->name() : QString("-none-"));
769
textCodec = oldCodec;
772
void RTFImport::setAnsiCodepage(RTFProperty *)
774
QTextCodec* oldCodec = textCodec;
775
textCodec = QTextCodec::codecForName("CP1252");
776
kDebug(30515) << "\\ansi" << (textCodec ? textCodec->name() : QString("-none-"));
778
textCodec = oldCodec;
781
void RTFImport::setPcaCodepage(RTFProperty *)
783
QTextCodec* oldCodec = textCodec;
784
textCodec = QTextCodec::codecForName("IBM 850"); // Qt writes the name with a space
785
kDebug(30515) << "\\pca" << (textCodec ? textCodec->name() : QString("-none-"));
787
textCodec = oldCodec;
790
void RTFImport::setPcCodepage(RTFProperty *)
792
QTextCodec* oldCodec = textCodec;
793
textCodec = QTextCodec::codecForName("IBM 850"); // This is an approximation
794
kDebug(30515) << "\\pc (approximation)" << (textCodec ? textCodec->name() : QString("-none-"));
796
textCodec = oldCodec;
799
void RTFImport::setToggleProperty(RTFProperty *property)
863
801
((bool *)this)[property->offset] = (!token.hasParam || token.value != 0);
866
void RTFImport::setFlagProperty( RTFProperty *property )
804
void RTFImport::setFlagProperty(RTFProperty *property)
868
806
((bool *)this)[property->offset] = property->value;
871
void RTFImport::setCharset( RTFProperty *property )
809
void RTFImport::setCharset(RTFProperty *property)
874
switch(token.value) {
875
case 0: cp = "CP1252"; break; // ANSI_CHARSET
876
case 1: cp = "CP1252"; break; // DEFAULT_CHARSET
812
switch (token.value) {
813
case 0: cp = "CP1252"; break; // ANSI_CHARSET
814
case 1: cp = "CP1252"; break; // DEFAULT_CHARSET
877
815
//case 2: cp = ""; break; // SYMBOL_CHARSET not supported yet.
878
case 77: cp = "Apple Roman"; break; // MAC_CHARSET
879
case 128: cp = "Shift-JIS"; break; // SHIFTJIS_CHARSET "CP932"
880
case 129: cp = "eucKR"; break; // HANGUL_CHARSET "CP949"
881
case 130: cp = "CP1361"; break; // JOHAB_CHARSET doesn't really seem to be supported by Qt :-(
882
case 134: cp = "GB2312"; break; // GB2312_CHARSET "CP936"
883
case 136: cp = "Big5-HKSCS"; break; // CHINESEBIG5_CHARSET "CP950"
884
case 161: cp = "CP1253"; break; // GREEK_CHARSET
885
case 162: cp = "CP1254"; break; // TURKISH_CHARSET
886
case 163: cp = "CP1258"; break; // VIETNAMESE_CHARSET
887
case 177: cp = "CP1255"; break; // HEBREW_CHARSET
888
case 178: cp = "CP1256"; break; // ARABIC_CHARSET / ARABICSIMPLIFIED_CHARSET
889
case 186: cp = "CP1257"; break; // BALTIC_CHARSET
890
case 204: cp = "CP1251"; break; // RUSSIAN_CHARSET / CYRILLIC_CHARSET
891
case 222: cp = "CP874"; break; // THAI_CHARSET
892
case 238: cp = "CP1250"; break; // EASTEUROPE_CHARSET / EASTERNEUROPE_CHARSET
893
case 255: cp = "CP850"; break; // OEM_CHARSET "IBM 850"
816
case 77: cp = "Apple Roman"; break; // MAC_CHARSET
817
case 128: cp = "Shift-JIS"; break; // SHIFTJIS_CHARSET "CP932"
818
case 129: cp = "eucKR"; break; // HANGUL_CHARSET "CP949"
819
case 130: cp = "CP1361"; break; // JOHAB_CHARSET doesn't really seem to be supported by Qt :-(
820
case 134: cp = "GB2312"; break; // GB2312_CHARSET "CP936"
821
case 136: cp = "Big5-HKSCS"; break; // CHINESEBIG5_CHARSET "CP950"
822
case 161: cp = "CP1253"; break; // GREEK_CHARSET
823
case 162: cp = "CP1254"; break; // TURKISH_CHARSET
824
case 163: cp = "CP1258"; break; // VIETNAMESE_CHARSET
825
case 177: cp = "CP1255"; break; // HEBREW_CHARSET
826
case 178: cp = "CP1256"; break; // ARABIC_CHARSET / ARABICSIMPLIFIED_CHARSET
827
case 186: cp = "CP1257"; break; // BALTIC_CHARSET
828
case 204: cp = "CP1251"; break; // RUSSIAN_CHARSET / CYRILLIC_CHARSET
829
case 222: cp = "CP874"; break; // THAI_CHARSET
830
case 238: cp = "CP1250"; break; // EASTEUROPE_CHARSET / EASTERNEUROPE_CHARSET
831
case 255: cp = "CP850"; break; // OEM_CHARSET "IBM 850"
896
834
QTextCodec* oldCodec = textCodec;
897
textCodec=QTextCodec::codecForName(cp);
898
kDebug(30515) <<"\\fcharset: charset:" << token.value <<" codepage:"<< cp <<" given:" << (textCodec?textCodec->name():QString("-none-"));
835
textCodec = QTextCodec::codecForName(cp);
836
kDebug(30515) << "\\fcharset: charset:" << token.value << " codepage:" << cp << " given:" << (textCodec ? textCodec->name() : QString("-none-"));
900
838
textCodec = oldCodec;
903
void RTFImport::setNumericProperty( RTFProperty *property )
841
void RTFImport::setNumericProperty(RTFProperty *property)
905
843
*((int *)(((char *)this) + property->offset)) = token.hasParam ? token.value : property->value;
908
void RTFImport::setEnumProperty( RTFProperty *property )
846
void RTFImport::setEnumProperty(RTFProperty *property)
910
848
*((int *)(((char *)this) + property->offset)) = property->value;
913
void RTFImport::setFontStyleHint( RTFProperty* property )
915
font.styleHint = QFont::StyleHint( property->value );
918
void RTFImport::setPictureType( RTFProperty* property )
920
picture.type = RTFPicture::PictureType( property->value );
923
void RTFImport::setSimpleUnderlineProperty( RTFProperty* )
851
void RTFImport::setFontStyleHint(RTFProperty* property)
853
font.styleHint = QFont::StyleHint(property->value);
856
void RTFImport::setPictureType(RTFProperty* property)
858
picture.type = RTFPicture::PictureType(property->value);
861
void RTFImport::setSimpleUnderlineProperty(RTFProperty*)
925
863
state.format.underline
926
= (!token.hasParam || token.value != 0)
927
? RTFFormat::UnderlineSimple : RTFFormat::UnderlineNone;
930
void RTFImport::setUnderlineProperty( RTFProperty* property )
932
state.format.underline = RTFFormat::Underline( property->value );
935
void RTFImport::setBorderStyle( RTFProperty *property )
937
if (state.layout.border)
939
state.layout.border->style = static_cast <RTFBorder::BorderStyle> ( property->value );
943
for (uint i=0; i < 4; i++)
945
state.layout.borders[i].style = static_cast <RTFBorder::BorderStyle> ( property->value );
864
= (!token.hasParam || token.value != 0)
865
? RTFFormat::UnderlineSimple : RTFFormat::UnderlineNone;
868
void RTFImport::setUnderlineProperty(RTFProperty* property)
870
state.format.underline = RTFFormat::Underline(property->value);
873
void RTFImport::setBorderStyle(RTFProperty *property)
875
if (state.layout.border) {
876
state.layout.border->style = static_cast <RTFBorder::BorderStyle>(property->value);
878
for (uint i = 0; i < 4; i++) {
879
state.layout.borders[i].style = static_cast <RTFBorder::BorderStyle>(property->value);
950
void RTFImport::setBorderProperty( RTFProperty *property )
884
void RTFImport::setBorderProperty(RTFProperty *property)
952
886
//kDebug() <<"setBorderProperty:";
953
if (state.layout.border)
887
if (state.layout.border) {
955
888
state.layout.border->width = token.value;
959
for (uint i=0; i < 4; i++)
890
for (uint i = 0; i < 4; i++) {
961
891
state.layout.borders[i].width = token.value;
966
void RTFImport::setBorderColor( RTFProperty * )
896
void RTFImport::setBorderColor(RTFProperty *)
968
if (state.layout.border)
898
if (state.layout.border) {
970
899
state.layout.border->color = token.value;
974
for (uint i=0; i < 4; i++)
901
for (uint i = 0; i < 4; i++) {
976
902
state.layout.borders[i].color = token.value;
981
void RTFImport::setUpProperty( RTFProperty * )
907
void RTFImport::setUpProperty(RTFProperty *)
983
909
state.format.baseline = token.hasParam ? -token.value : -6;
986
void RTFImport::setPlainFormatting( RTFProperty * )
912
void RTFImport::setPlainFormatting(RTFProperty *)
988
914
RTFFormat &format = state.format;
990
format.font = defaultFont;
991
format.fontSize = 24;
995
format.underlinecolor = -1;
996
format.vertAlign = RTFFormat::Normal;
998
format.italic = false;
999
format.strike = false;
1000
format.striked = false;
1001
format.hidden = false;
1002
format.caps = false;
1003
format.smallCaps = false;
916
format.font = defaultFont;
917
format.fontSize = 24;
921
format.underlinecolor = -1;
922
format.vertAlign = RTFFormat::Normal;
924
format.italic = false;
925
format.strike = false;
926
format.striked = false;
927
format.hidden = false;
929
format.smallCaps = false;
1005
format.underline = RTFFormat::UnderlineNone;
931
format.underline = RTFFormat::UnderlineNone;
1007
933
// Do not reset format.uc !
1010
void RTFImport::setParagraphDefaults( RTFProperty * )
936
void RTFImport::setParagraphDefaults(RTFProperty *)
1012
938
RTFLayout &layout = state.layout;
1014
940
layout.tablist.clear();
1015
layout.tab.type = RTFTab::Left;
1016
layout.tab.leader = RTFTab::None;
941
layout.tab.type = RTFTab::Left;
942
layout.tab.leader = RTFTab::None;
1018
for (uint i=0; i < 4; i++)
944
for (uint i = 0; i < 4; i++) {
1020
945
RTFBorder &border = layout.borders[i];
1021
946
border.color = -1;
1022
947
border.width = 0;
1023
948
border.style = RTFBorder::None;
1025
layout.firstIndent = 0;
1026
layout.leftIndent = 0;
1027
layout.rightIndent = 0;
1028
layout.spaceBefore = 0;
1029
layout.spaceAfter = 0;
1030
layout.spaceBetween = 0;
950
layout.firstIndent = 0;
951
layout.leftIndent = 0;
952
layout.rightIndent = 0;
953
layout.spaceBefore = 0;
954
layout.spaceAfter = 0;
955
layout.spaceBetween = 0;
1031
956
layout.spaceBetweenMultiple = false;
1033
layout.alignment = RTFLayout::Left;
1035
layout.inTable = false;
1036
layout.keep = false;
1037
layout.keepNext = false;
1038
layout.pageBB = false;
1039
layout.pageBA = false;
958
layout.alignment = RTFLayout::Left;
960
layout.inTable = false;
962
layout.keepNext = false;
963
layout.pageBB = false;
964
layout.pageBA = false;
1042
void RTFImport::setSectionDefaults( RTFProperty * )
967
void RTFImport::setSectionDefaults(RTFProperty *)
1044
969
RTFSectionLayout §ion = state.section;
1046
section.headerMargin = 720;
1047
section.footerMargin = 720;
1048
section.titlePage = false;
971
section.headerMargin = 720;
972
section.footerMargin = 720;
973
section.titlePage = false;
1051
void RTFImport::setTableRowDefaults( RTFProperty * )
976
void RTFImport::setTableRowDefaults(RTFProperty *)
1053
978
RTFTableRow &tableRow = state.tableRow;
1054
979
RTFTableCell &tableCell = state.tableCell;
1056
tableRow.height = 0;
1058
tableRow.alignment = RTFLayout::Left;
983
tableRow.alignment = RTFLayout::Left;
1059
984
tableRow.cells.clear();
1060
tableCell.bgcolor = -1;
985
tableCell.bgcolor = -1;
1062
for (uint i=0; i < 4; i++)
987
for (uint i = 0; i < 4; i++) {
1064
988
RTFBorder &border = tableCell.borders[i];
1065
989
border.color = -1;
1066
990
border.width = 0;