filters

textformat.cc

00001 /*
00002 ** A program to convert the XML rendered by KWord into LATEX.
00003 **
00004 ** Copyright (C) 2000, 2001, 2002 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 "fileheader.h"     /* for the use of FileHeader::instance() (color and underlined) */
00027 #include "textformat.h"
00028 
00029 /*******************************************/
00030 /* getColorXXXX                            */
00031 /*******************************************/
00032 int TextFormat::getColorBlue () const
00033 {
00034     if(_textcolor!= 0)
00035         return _textcolor->blue();
00036     else
00037         return 0;
00038 }
00039 
00040 int TextFormat::getColorGreen() const
00041 {
00042     if(_textcolor!= 0)
00043         return _textcolor->green();
00044     else
00045         return 0;
00046 }
00047 
00048 int TextFormat::getColorRed  () const
00049 {
00050     if(_textcolor!= 0)
00051         return _textcolor->red();
00052     else
00053         return 0;
00054 }
00055 
00056 /*******************************************/
00057 /* getBkColorXXX                           */
00058 /*******************************************/
00059 int TextFormat::getBkColorBlue () const
00060 {
00061     if(_backcolor!= 0)
00062         return _backcolor->blue();
00063     else
00064         return 0;
00065 }
00066 
00067 int TextFormat::getBkColorGreen() const
00068 {
00069     if(_backcolor!= 0)
00070         return _backcolor->green();
00071     else
00072         return 0;
00073 }
00074 
00075 int TextFormat::getBkColorRed  () const
00076 {
00077     if(_backcolor!= 0)
00078         return _backcolor->red();
00079     else
00080         return 0;
00081 }
00082 
00083 /*******************************************/
00084 /* setColor                                */
00085 /*******************************************/
00086 void TextFormat::setColor (const int r, const int g, const int b)
00087 {
00088     if(_textcolor == 0)
00089         _textcolor = new QColor(r, g, b);
00090     else
00091         _textcolor->setRgb(r, g, b);
00092 }
00093 
00094 /*******************************************/
00095 /* setBkColor                              */
00096 /*******************************************/
00097 void TextFormat::setBkColor (const int r, const int g, const int b)
00098 {
00099     if(_backcolor == 0)
00100         _backcolor = new QColor(r, g, b);
00101     else
00102         _backcolor->setRgb(r, g, b);
00103 }
00104 
00105 /*******************************************/
00106 /* analyseTextFormat                       */
00107 /*******************************************/
00108 /* Get the set of info. about a text format*/
00109 /*******************************************/
00110 void TextFormat::analyseFormat(const QDomNode balise)
00111 {
00112     /* MARKUPS FORMAT id="1" pos="0" len="17">...</FORMAT> */
00113     
00114     /* Parameters Analyse */
00115     analyseParam(balise);
00116     kdDebug(30522) << "ANALYSE A FORMAT" << endl;
00117     
00118     /* Children Markups Analyse */
00119     if(isChild(balise, "FONT"))
00120         analyseFont(getChild(balise, "FONT"));
00121     if(isChild(balise, "ITALIC"))
00122         analyseItalic(getChild(balise, "ITALIC"));
00123     if(isChild(balise, "UNDERLINE"))
00124         analyseUnderlined(getChild(balise, "UNDERLINE"));
00125     if(isChild(balise, "WEIGHT"))
00126         analyseWeight(getChild(balise, "WEIGHT"));
00127     if(isChild(balise, "VERTALIGN"))
00128         analyseAlign(getChild(balise, "VERTALIGN"));
00129     if(isChild(balise, "STRIKEOUT"))
00130         analyseStrikeout(getChild(balise, "STRIKEOUT"));
00131     if(isChild(balise, "COLOR"))
00132         analyseColor(getChild(balise, "COLOR"));
00133     if(isChild(balise, "SIZE"))
00134         analyseSize(getChild(balise, "SIZE"));
00135     if(isChild(balise, "TEXTBACKGROUNDCOLOR"))
00136         analyseBackgroundColor(getChild(balise, "TEXTBACKGROUNDCOLOR"));
00137 
00138     kdDebug(30522) << "END OF A FORMAT" << endl;
00139 }
00140 
00141 void TextFormat::analyseBackgroundColor(const QDomNode balise)
00142 {
00143     /* <TEXTBACKGROUNDCOLOR red="0" green="0" blue="0"/> */
00144     int  red   = 0, 
00145          blue  = 0,
00146          green = 0;
00147 
00148     red = getAttr(balise, "red").toInt();
00149     green = getAttr(balise, "green").toInt();
00150     blue = getAttr(balise, "blue").toInt();
00151 
00152     if(!(red == 255 && green == 255 && blue == 255))
00153     {
00154         kdDebug(30522) << "bk color = " << red << "," << green << "," << blue << endl;
00155         /* white color is default value */
00156         setBkColor(red, green, blue);
00157         FileHeader::instance()->useColor();
00158     }
00159 }
00160 
00161 /*******************************************/
00162 /* analyseParam                            */
00163 /*******************************************/
00164 /* Get the zone where the format is applied*/
00165 /*******************************************/
00166 void TextFormat::analyseParam(const QDomNode balise)
00167 {
00168     /* <FORMAT id="1" pos="0" len="17"> */
00169 
00170     //setId(getAttr(balise, "id").toInt());
00171     //setPos(getAttr(balise, "pos").toInt());
00172     //setLength(getAttr(balise, "len").toInt());
00173     Format::analyse(balise);
00174 }
00175 
00176 /*******************************************/
00177 /* analyseFont                             */
00178 /*******************************************/
00179 /* Get the text font!                      */
00180 /*******************************************/
00181 void TextFormat::analyseFont(const QDomNode balise)
00182 {
00183     /* <FONT name="times"> */
00184     setPolice(getAttr(balise, "name"));
00185 }
00186 
00187 /*******************************************/
00188 /* analyseItalic                           */
00189 /*******************************************/
00190 /* Verify if it's a italic text.           */
00191 /*******************************************/
00192 void TextFormat::analyseItalic(const QDomNode balise)
00193 {
00194     /* <ITALIC value="1"> */
00195     setItalic(getAttr(balise, "value").toInt());
00196 }
00197 
00198 /*******************************************/
00199 /* analyseUnderlined                       */
00200 /*******************************************/
00201 /* Verify if it's a underlined text.       */
00202 /*******************************************/
00203 void TextFormat::analyseUnderlined(const QDomNode balise)
00204 {
00205     /* <UNDERLINE value="1"> */
00206 
00207     setUnderlined(getAttr(balise, "value"));
00208     if(isUnderlined())
00209         FileHeader::instance()->useUnderline();
00210     kdDebug(30522) << "Underlined ? " << isUnderlined() << endl;
00211 }
00212 
00213 /*******************************************/
00214 /* analyseStrikeout                        */
00215 /*******************************************/
00216 /* Verify if it's a strikeout text.        */
00217 /*******************************************/
00218 void TextFormat::analyseStrikeout(const QDomNode balise)
00219 {
00220     /* <STRIKEOUT value="1" /> */
00221     setStrikeout(getAttr(balise, "value").toInt());
00222     if(isStrikeout())
00223         FileHeader::instance()->useUnderline();
00224     kdDebug(30522) << "Strikeout ? " << isUnderlined() << endl;
00225 }
00226 
00227 /*******************************************/
00228 /* analyseWeigth                           */
00229 /*******************************************/
00230 /* Get the text weigth.                    */
00231 /*******************************************/
00232 void TextFormat::analyseWeight(const QDomNode balise)
00233 {
00234     /* <WEIGHT value="75" /> */
00235     setWeight(getAttr(balise, "value").toInt());
00236     kdDebug(30522) << "Weight = " << getWeight() << endl;
00237 }
00238 
00239 /*******************************************/
00240 /* analyseAlign                            */
00241 /*******************************************/
00242 /* Get the text align.                     */
00243 /*******************************************/
00244 void TextFormat::analyseAlign(const QDomNode balise)
00245 {
00246     /* <VERTALIGN value="0"> */
00247 
00248     setAlign(getAttr(balise, "value").toInt());
00249 }
00250 
00251 /*******************************************/
00252 /* analyseColor                            */
00253 /*******************************************/
00254 /* Get the text color.                     */
00255 /*******************************************/
00256 void TextFormat::analyseColor(const QDomNode balise)
00257 {
00258     /* <COLOR red="0" green="0" blue="0"/> */
00259     int  red   = 0, 
00260          blue  = 0,
00261          green = 0;
00262 
00263     red = getAttr(balise, "red").toInt();
00264     green = getAttr(balise, "green").toInt();
00265     blue = getAttr(balise, "blue").toInt();
00266 
00267     if(!(red == 0 && green == 0 && blue == 0))
00268     {
00269         /* black color is default value */
00270         kdDebug(30522) << "color = " << red << "," << green << "," << blue << endl;
00271         setColor(red, green, blue);
00272         FileHeader::instance()->useColor();
00273     }
00274 }
00275 
00276 /*******************************************/
00277 /* analyseSize                             */
00278 /*******************************************/
00279 /* Get the text size.                      */
00280 /*******************************************/
00281 void TextFormat::analyseSize(const QDomNode balise)
00282 {
00283     /* <SIZE value="11"> */
00284     setSize(getAttr(balise, "value").toInt());
00285     kdDebug(30522) << "font size : " << getSize() << endl;
00286 }
KDE Home | KDE Accessibility Home | Description of Access Keys