filters

textformat.cpp
1/*
2** A program to convert the XML rendered by KWord into LATEX.
3**
4** Copyright (C) 2000, 2001, 2002 Robert JACOLIN
5**
6** This library is free software; you can redistribute it and/or
7** modify it under the terms of the GNU Library General Public
8** License as published by the Free Software Foundation; either
9** version 2 of the License, or (at your option) any later version.
10**
11** This library is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14** Library General Public License for more details.
15**
16** To receive a copy of the GNU Library General Public License, write to the
17** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19**
20*/
21
22#include <stdlib.h>
23
24#include <kdebug.h>
25
26#include "fileheader.h" /* for the use of FileHeader::instance() (color and underlined) */
27#include "textformat.h"
28
29/*******************************************/
30/* getColorXXXX */
31/*******************************************/
32int TextFormat::getColorBlue () const
33{
34 if(_textcolor!= 0)
35 return _textcolor->blue();
36 else
37 return 0;
38}
39
40int TextFormat::getColorGreen() const
41{
42 if(_textcolor!= 0)
43 return _textcolor->green();
44 else
45 return 0;
46}
47
48int TextFormat::getColorRed () const
49{
50 if(_textcolor!= 0)
51 return _textcolor->red();
52 else
53 return 0;
54}
55
56/*******************************************/
57/* getBkColorXXX */
58/*******************************************/
59int TextFormat::getBkColorBlue () const
60{
61 if(_backcolor!= 0)
62 return _backcolor->blue();
63 else
64 return 0;
65}
66
67int TextFormat::getBkColorGreen() const
68{
69 if(_backcolor!= 0)
70 return _backcolor->green();
71 else
72 return 0;
73}
74
75int TextFormat::getBkColorRed () const
76{
77 if(_backcolor!= 0)
78 return _backcolor->red();
79 else
80 return 0;
81}
82
83/*******************************************/
84/* setColor */
85/*******************************************/
86void TextFormat::setColor (const int r, const int g, const int b)
87{
88 if(_textcolor == 0)
89 _textcolor = new TQColor(r, g, b);
90 else
91 _textcolor->setRgb(r, g, b);
92}
93
94/*******************************************/
95/* setBkColor */
96/*******************************************/
97void TextFormat::setBkColor (const int r, const int g, const int b)
98{
99 if(_backcolor == 0)
100 _backcolor = new TQColor(r, g, b);
101 else
102 _backcolor->setRgb(r, g, b);
103}
104
105/*******************************************/
106/* analyseTextFormat */
107/*******************************************/
108/* Get the set of info. about a text format*/
109/*******************************************/
110void TextFormat::analyseFormat(const TQDomNode balise)
111{
112 /* MARKUPS FORMAT id="1" pos="0" len="17">...</FORMAT> */
113
114 /* Parameters Analyse */
115 analyseParam(balise);
116 kdDebug(30522) << "ANALYSE A FORMAT" << endl;
117
118 /* Children Markups Analyse */
119 if(isChild(balise, "FONT"))
120 analyseFont(getChild(balise, "FONT"));
121 if(isChild(balise, "ITALIC"))
122 analyseItalic(getChild(balise, "ITALIC"));
123 if(isChild(balise, "UNDERLINE"))
124 analyseUnderlined(getChild(balise, "UNDERLINE"));
125 if(isChild(balise, "WEIGHT"))
126 analyseWeight(getChild(balise, "WEIGHT"));
127 if(isChild(balise, "VERTALIGN"))
128 analyseAlign(getChild(balise, "VERTALIGN"));
129 if(isChild(balise, "STRIKEOUT"))
130 analyseStrikeout(getChild(balise, "STRIKEOUT"));
131 if(isChild(balise, "COLOR"))
132 analyseColor(getChild(balise, "COLOR"));
133 if(isChild(balise, "SIZE"))
134 analyseSize(getChild(balise, "SIZE"));
135 if(isChild(balise, "TEXTBACKGROUNDCOLOR"))
136 analyseBackgroundColor(getChild(balise, "TEXTBACKGROUNDCOLOR"));
137
138 kdDebug(30522) << "END OF A FORMAT" << endl;
139}
140
141void TextFormat::analyseBackgroundColor(const TQDomNode balise)
142{
143 /* <TEXTBACKGROUNDCOLOR red="0" green="0" blue="0"/> */
144 int red = 0,
145 blue = 0,
146 green = 0;
147
148 red = getAttr(balise, "red").toInt();
149 green = getAttr(balise, "green").toInt();
150 blue = getAttr(balise, "blue").toInt();
151
152 if(!(red == 255 && green == 255 && blue == 255))
153 {
154 kdDebug(30522) << "bk color = " << red << "," << green << "," << blue << endl;
155 /* white color is default value */
156 setBkColor(red, green, blue);
157 FileHeader::instance()->useColor();
158 }
159}
160
161/*******************************************/
162/* analyseParam */
163/*******************************************/
164/* Get the zone where the format is applied*/
165/*******************************************/
166void TextFormat::analyseParam(const TQDomNode balise)
167{
168 /* <FORMAT id="1" pos="0" len="17"> */
169
170 //setId(getAttr(balise, "id").toInt());
171 //setPos(getAttr(balise, "pos").toInt());
172 //setLength(getAttr(balise, "len").toInt());
173 Format::analyse(balise);
174}
175
176/*******************************************/
177/* analyseFont */
178/*******************************************/
179/* Get the text font! */
180/*******************************************/
181void TextFormat::analyseFont(const TQDomNode balise)
182{
183 /* <FONT name="times"> */
184 setPolice(getAttr(balise, "name"));
185}
186
187/*******************************************/
188/* analyseItalic */
189/*******************************************/
190/* Verify if it's a italic text. */
191/*******************************************/
192void TextFormat::analyseItalic(const TQDomNode balise)
193{
194 /* <ITALIC value="1"> */
195 setItalic(getAttr(balise, "value").toInt());
196}
197
198/*******************************************/
199/* analyseUnderlined */
200/*******************************************/
201/* Verify if it's a underlined text. */
202/*******************************************/
203void TextFormat::analyseUnderlined(const TQDomNode balise)
204{
205 /* <UNDERLINE value="1"> */
206
207 setUnderlined(getAttr(balise, "value"));
208 if(isUnderlined())
209 FileHeader::instance()->useUnderline();
210 kdDebug(30522) << "Underlined ? " << isUnderlined() << endl;
211}
212
213/*******************************************/
214/* analyseStrikeout */
215/*******************************************/
216/* Verify if it's a strikeout text. */
217/*******************************************/
218void TextFormat::analyseStrikeout(const TQDomNode balise)
219{
220 /* <STRIKEOUT value="1" /> */
221 setStrikeout(getAttr(balise, "value").toInt());
222 if(isStrikeout())
223 FileHeader::instance()->useUnderline();
224 kdDebug(30522) << "Strikeout ? " << isUnderlined() << endl;
225}
226
227/*******************************************/
228/* analyseWeigth */
229/*******************************************/
230/* Get the text weigth. */
231/*******************************************/
232void TextFormat::analyseWeight(const TQDomNode balise)
233{
234 /* <WEIGHT value="75" /> */
235 setWeight(getAttr(balise, "value").toInt());
236 kdDebug(30522) << "Weight = " << getWeight() << endl;
237}
238
239/*******************************************/
240/* analyseAlign */
241/*******************************************/
242/* Get the text align. */
243/*******************************************/
244void TextFormat::analyseAlign(const TQDomNode balise)
245{
246 /* <VERTALIGN value="0"> */
247
248 setAlign(getAttr(balise, "value").toInt());
249}
250
251/*******************************************/
252/* analyseColor */
253/*******************************************/
254/* Get the text color. */
255/*******************************************/
256void TextFormat::analyseColor(const TQDomNode balise)
257{
258 /* <COLOR red="0" green="0" blue="0"/> */
259 int red = 0,
260 blue = 0,
261 green = 0;
262
263 red = getAttr(balise, "red").toInt();
264 green = getAttr(balise, "green").toInt();
265 blue = getAttr(balise, "blue").toInt();
266
267 if(!(red == 0 && green == 0 && blue == 0))
268 {
269 /* black color is default value */
270 kdDebug(30522) << "color = " << red << "," << green << "," << blue << endl;
271 setColor(red, green, blue);
272 FileHeader::instance()->useColor();
273 }
274}
275
276/*******************************************/
277/* analyseSize */
278/*******************************************/
279/* Get the text size. */
280/*******************************************/
281void TextFormat::analyseSize(const TQDomNode balise)
282{
283 /* <SIZE value="11"> */
284 setSize(getAttr(balise, "value").toInt());
285 kdDebug(30522) << "font size : " << getSize() << endl;
286}
virtual void analyse(const TQDomNode)
Helpfull functions.