filters

format.cc

00001 /*
00002 ** A program to convert the XML rendered by KWord into LATEX.
00003 **
00004 ** Copyright (C) 2002, 2003 Robert JACOLIN
00005 **
00006 ** This library is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU Library General Public
00008 ** License as published by the Free Software Foundation; either
00009 ** version 2 of the License, or (at your option) any later version.
00010 **
00011 ** This library is distributed in the hope that it will be useful,
00012 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 ** Library General Public License for more details.
00015 **
00016 ** To receive a copy of the GNU Library General Public License, write to the
00017 ** Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 **
00020 */
00021 
00022 #include <stdlib.h>
00023 
00024 #include <kdebug.h>
00025 
00026 #include "column.h"
00027 #include "fileheader.h" /* for the use of _header (color and underlined) */
00028 #include "format.h"
00029 #include "row.h"
00030 
00031 Format::Format()
00032 {
00033     _multirow = -1;
00034     _brushStyle = -1;
00035     _isValidFormat = false;
00036     _bottomBorder = NULL;
00037     _topBorder = NULL;
00038     _rightBorder = NULL;
00039     _leftBorder = NULL;
00040 }
00041 
00042 Format::~Format()
00043 {
00044     delete _bottomBorder;
00045     delete _topBorder;
00046     delete _leftBorder;
00047     delete _rightBorder;
00048 }
00049 
00050 bool Format::hasTopBorder() const
00051 {
00052     if(_topBorder == NULL)
00053         return false;
00054     else
00055         return (_topBorder->getStyle() > 0);
00056 }
00057 
00058 bool Format::hasBottomBorder() const
00059 {
00060     if(_bottomBorder == NULL)
00061         return false;
00062     else
00063         return (_bottomBorder->getStyle() > 0);
00064 }
00065 
00066 bool Format::hasLeftBorder() const
00067 {
00068     if(_leftBorder == NULL)
00069         return false;
00070     else
00071         return (_leftBorder->getStyle() > 0);
00072 }
00073 
00074 bool Format::hasRightBorder() const
00075 {
00076     if(_rightBorder == NULL)
00077         return false;
00078     else
00079         return (_rightBorder->getStyle() > 0);
00080 }
00081 
00082 /* Get the set of info. about a text format */
00083 void Format::analyse(const QDomNode balise)
00084 {
00085     /* <format brushstyle="5" brushcolor="#a70bc3" bgcolor="#ffffff" alignY="2" align="4" > */
00086     if( !getAttr(balise, "brushstyle").isEmpty() )
00087     {
00088         _isValidFormat = true;
00089         setBrushStyle(getAttr(balise, "brushstyle").toInt());
00090         FileHeader::instance()->useColor();
00091         setBrushColor(getAttr(balise, "brushcolor"));
00092         setBgColor(getAttr(balise, "bgcolor"));
00093         setAlignY(getAttr(balise, "alignY").toLong());
00094         setAlign(getAttr(balise, "align").toLong());
00095     }
00096     if(isChild(balise, "pen"))
00097         analysePen(getChild(balise, "pen"));
00098     if(isChild(balise, "bottom-border"))
00099     {
00100         kdDebug(30522) << "bottom-border" << endl;
00101         _isValidFormat = true;
00102         _bottomBorder = new Pen();
00103         _bottomBorder->analyse(getChild(getChild(balise, "bottom-border"), "pen"));
00104     }
00105     if(isChild(balise, "top-border"))
00106     {
00107         kdDebug(30522) << "top-border" << endl;
00108         _isValidFormat = true;
00109         _topBorder = new Pen();
00110         _topBorder->analyse(getChild(getChild(balise, "top-border"), "pen"));
00111     }
00112     if(isChild(balise, "left-border"))
00113     {
00114         kdDebug(30522) << "left-border" << endl;
00115         _isValidFormat = true;
00116         _leftBorder = new Pen();
00117         _leftBorder->analyse(getChild(getChild(balise, "left-border"), "pen"));
00118     }
00119     if(isChild(balise, "right-border"))
00120     {
00121         kdDebug(30522) << "right-border" << endl;
00122         _isValidFormat = true;
00123         _rightBorder = new Pen();
00124         _rightBorder->analyse(getChild(getChild(balise, "right-border"), "pen"));
00125     }
00126 }
00127 
00128 void Format::analysePen(const QDomNode balise)
00129 {
00130     /* <pen width="0" style="1" color="#000000" /> */
00131     _isValidFormat = true;
00132     setPenWidth(getAttr(balise, "width").toDouble());
00133     setPenStyle(getAttr(balise, "style").toInt());
00134     setPenColor(getAttr(balise, "color"));
00135 }
00136 
00137 void Format::analyseFont(const QDomNode balise)
00138 {
00139     /* <font size="18" family="Helvetica" weight="50" /> */
00140     setFontSize(getAttr(balise, "size").toInt());
00141     setFontFamily(getAttr(balise, "family"));
00142     setFontWeight(getAttr(balise, "weight").toInt());
00143 }
00144 
00145 void Format::generate(QTextStream& out, Column* col, Row* row)
00146 {
00147     if(hasLeftBorder())
00148         out << "|";
00149     if(isValidFormat() && getBrushStyle() >= 1)
00150     {
00151         out << ">{\\columncolor";
00152         generateColor(out);
00153         out << "}";
00154     }
00155     else if(col != NULL)
00156     {
00157         if(col->getBrushStyle() >= 1)
00158         {
00159             out << ">{\\columncolor";
00160             col->generateColor(out);
00161             out << "}";
00162         }
00163     }
00164     else if(row != NULL)
00165     {
00166         if(row->getBrushStyle() >= 1)
00167         {
00168             out << ">{\\columncolor";
00169             row->generateColor(out);
00170             out << "}";
00171         }
00172     }
00173         if ( col != NULL )
00174             out << "m{" << col->getWidth() << "pt}";
00175     if(hasRightBorder())
00176         out << "|";
00177 }
00178 
00179 void Format::generateTextFormat(QTextStream& out, QString text)
00180 {
00181     if(getPenStyle() > 0)
00182     {
00183         float red   = ((float) getPenColor().red()) / 255;
00184         float green = ((float) getPenColor().green()) / 255;
00185         float blue  = ((float) getPenColor().blue()) / 255;
00186 
00187         out << "\\textcolor[rgb]{"<< red << ", " << green <<
00188                 ", " << blue << "}{" << text << "}" << endl;
00189     }
00190 }
00191 
00192 void Format::generateColor(QTextStream& out)
00193 {
00194     if(getBrushStyle() >= 1)
00195     {
00196         float red   = ((float) getBrushColor().red()) / 255;
00197         float green = ((float) getBrushColor().green()) / 255;
00198         float blue  = ((float) getBrushColor().blue()) / 255;
00199 
00200         out << "[rgb]{" << red << ", " << green <<
00201                 ", " << blue << "}%" << endl;
00202     }
00203 }
KDE Home | KDE Accessibility Home | Description of Access Keys