filters

kspread/latex/export/format.cpp
1/*
2** A program to convert the XML rendered by KWord into LATEX.
3**
4** Copyright (C) 2002, 2003 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 "column.h"
27#include "fileheader.h" /* for the use of _header (color and underlined) */
28#include "format.h"
29#include "row.h"
30
32{
33 _multirow = -1;
34 _brushStyle = -1;
35 _isValidFormat = false;
36 _bottomBorder = NULL;
37 _topBorder = NULL;
38 _rightBorder = NULL;
39 _leftBorder = NULL;
40}
41
42Format::~Format()
43{
44 delete _bottomBorder;
45 delete _topBorder;
46 delete _leftBorder;
47 delete _rightBorder;
48}
49
50bool Format::hasTopBorder() const
51{
52 if(_topBorder == NULL)
53 return false;
54 else
55 return (_topBorder->getStyle() > 0);
56}
57
58bool Format::hasBottomBorder() const
59{
60 if(_bottomBorder == NULL)
61 return false;
62 else
63 return (_bottomBorder->getStyle() > 0);
64}
65
66bool Format::hasLeftBorder() const
67{
68 if(_leftBorder == NULL)
69 return false;
70 else
71 return (_leftBorder->getStyle() > 0);
72}
73
74bool Format::hasRightBorder() const
75{
76 if(_rightBorder == NULL)
77 return false;
78 else
79 return (_rightBorder->getStyle() > 0);
80}
81
82/* Get the set of info. about a text format */
83void Format::analyse(const TQDomNode balise)
84{
85 /* <format brushstyle="5" brushcolor="#a70bc3" bgcolor="#ffffff" alignY="2" align="4" > */
86 if( !getAttr(balise, "brushstyle").isEmpty() )
87 {
88 _isValidFormat = true;
89 setBrushStyle(getAttr(balise, "brushstyle").toInt());
90 FileHeader::instance()->useColor();
91 setBrushColor(getAttr(balise, "brushcolor"));
92 setBgColor(getAttr(balise, "bgcolor"));
93 setAlignY(getAttr(balise, "alignY").toLong());
94 setAlign(getAttr(balise, "align").toLong());
95 }
96 if(isChild(balise, "pen"))
97 analysePen(getChild(balise, "pen"));
98 if(isChild(balise, "bottom-border"))
99 {
100 kdDebug(30522) << "bottom-border" << endl;
101 _isValidFormat = true;
102 _bottomBorder = new Pen();
103 _bottomBorder->analyse(getChild(getChild(balise, "bottom-border"), "pen"));
104 }
105 if(isChild(balise, "top-border"))
106 {
107 kdDebug(30522) << "top-border" << endl;
108 _isValidFormat = true;
109 _topBorder = new Pen();
110 _topBorder->analyse(getChild(getChild(balise, "top-border"), "pen"));
111 }
112 if(isChild(balise, "left-border"))
113 {
114 kdDebug(30522) << "left-border" << endl;
115 _isValidFormat = true;
116 _leftBorder = new Pen();
117 _leftBorder->analyse(getChild(getChild(balise, "left-border"), "pen"));
118 }
119 if(isChild(balise, "right-border"))
120 {
121 kdDebug(30522) << "right-border" << endl;
122 _isValidFormat = true;
123 _rightBorder = new Pen();
124 _rightBorder->analyse(getChild(getChild(balise, "right-border"), "pen"));
125 }
126}
127
128void Format::analysePen(const TQDomNode balise)
129{
130 /* <pen width="0" style="1" color="#000000" /> */
131 _isValidFormat = true;
132 setPenWidth(getAttr(balise, "width").toDouble());
133 setPenStyle(getAttr(balise, "style").toInt());
134 setPenColor(getAttr(balise, "color"));
135}
136
137void Format::analyseFont(const TQDomNode balise)
138{
139 /* <font size="18" family="Helvetica" weight="50" /> */
140 setFontSize(getAttr(balise, "size").toInt());
141 setFontFamily(getAttr(balise, "family"));
142 setFontWeight(getAttr(balise, "weight").toInt());
143}
144
145void Format::generate(TQTextStream& out, Column* col, Row* row)
146{
147 if(hasLeftBorder())
148 out << "|";
149 if(isValidFormat() && getBrushStyle() >= 1)
150 {
151 out << ">{\\columncolor";
152 generateColor(out);
153 out << "}";
154 }
155 else if(col != NULL)
156 {
157 if(col->getBrushStyle() >= 1)
158 {
159 out << ">{\\columncolor";
160 col->generateColor(out);
161 out << "}";
162 }
163 }
164 else if(row != NULL)
165 {
166 if(row->getBrushStyle() >= 1)
167 {
168 out << ">{\\columncolor";
169 row->generateColor(out);
170 out << "}";
171 }
172 }
173 if ( col != NULL )
174 out << "m{" << col->getWidth() << "pt}";
175 if(hasRightBorder())
176 out << "|";
177}
178
179void Format::generateTextFormat(TQTextStream& out, TQString text)
180{
181 if(getPenStyle() > 0)
182 {
183 float red = ((float) getPenColor().red()) / 255;
184 float green = ((float) getPenColor().green()) / 255;
185 float blue = ((float) getPenColor().blue()) / 255;
186
187 out << "\\textcolor[rgb]{"<< red << ", " << green <<
188 ", " << blue << "}{" << text << "}" << endl;
189 }
190}
191
192void Format::generateColor(TQTextStream& out)
193{
194 if(getBrushStyle() >= 1)
195 {
196 float red = ((float) getBrushColor().red()) / 255;
197 float green = ((float) getBrushColor().green()) / 255;
198 float blue = ((float) getBrushColor().blue()) / 255;
199
200 out << "[rgb]{" << red << ", " << green <<
201 ", " << blue << "}%" << endl;
202 }
203}
This class hold a column.
Definition column.h:38
void generate(TQTextStream &out, Column *col=NULL, Row *row=NULL)
Generate the cell format inherited from the row or the colum format or use its own format.
void setAlign(long a)
setters
void generateColor(TQTextStream &out)
Generate the color format for a column or a row.
virtual void analyse(const TQDomNode)
Helpfull functions.
Format()
Constructors.
void generateTextFormat(TQTextStream &out, TQString text)
Generate the text cell format (color and font).
This class describe a pen which is used to draw borders.
Definition pen.h:39
This class hold a row.
Definition row.h:38