filters

fileheader.cc

00001 /*
00002 ** A program to convert the XML rendered by KWord into LATEX.
00003 **
00004 ** Copyright (C) 2000, 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 "fileheader.h"
00027 #include "config.h"
00028 
00029 FileHeader* FileHeader::_instance = 0;
00030 
00031 /*******************************************/
00032 /* Constructor                             */
00033 /*******************************************/
00034 FileHeader::FileHeader()
00035 {
00036     _hasHeader    = false;
00037     _hasFooter    = false;
00038     _hasColor     = false;
00039     _hasUnderline = false;
00040     _hasEnumerate = false;
00041     _hasGraphics  = false;
00042     _hasTable     = false;
00043     _standardPage = 0;
00044     _processing   = TP_NORMAL;
00045     //setFileHeader(this);      /* for xmlParser class. */
00046 }
00047 
00048 /*******************************************/
00049 /* Destructor                              */
00050 /*******************************************/
00051 FileHeader::~FileHeader()
00052 {
00053     kdDebug(30522) << "FileHeader Destructor" << endl;
00054 }
00055 
00056 /*******************************************/
00057 /* AnalysePaperParam                       */
00058 /*******************************************/
00059 void FileHeader::analysePaperParam(const QDomNode balise)
00060 {
00061     setFormat(getAttr(balise, "format").toInt());
00062     _width = getAttr(balise, "width").toInt();
00063     _height = getAttr(balise, "height").toInt();
00064     setOrientation(getAttr(balise, "orientation").toInt());
00065     setColumns(getAttr(balise, "columns").toInt());
00066     _columnSpacing = getAttr(balise, "columnspacing").toInt();
00067     setHeadType(getAttr(balise, "hType").toInt());
00068     setFootType(getAttr(balise, "fType").toInt());
00069     _headBody = getAttr(balise, "spHeadBody").toInt();
00070     _footBody = getAttr(balise, "spFootBody").toInt();
00071     //getAttr(balise, "zoom").toInt();
00072 }
00073 
00074 /*******************************************/
00075 /* AnalysePaper                            */
00076 /*******************************************/
00077 void FileHeader::analysePaper(const QDomNode balise)
00078 {
00079     analysePaperParam(balise);
00080 
00081     //setTokenCurrent(balise_initiale->pContent);
00082     // Analyse children markups --> PAPERBORDERS
00083     QDomNode fils = getChild(balise, "PAPERSBORDERS");
00084     _leftBorder = getAttr(fils, "left").toInt();
00085     _rightBorder = getAttr(fils, "right").toInt();
00086     _bottomBorder = getAttr(fils, "bottom").toInt();
00087     _topBorder = getAttr(fils, "top").toInt();
00088 }
00089 
00090 /*******************************************/
00091 /* AnalyseAttributs                        */
00092 /*******************************************/
00093 void FileHeader::analyseAttributs(const QDomNode balise)
00094 {
00095     setProcessing(getAttr(balise, "processing").toInt());
00096     setStandardPge(getAttr(balise, "standardpage").toInt());
00097     setTOC(getAttr(balise, "hasTOC").toInt());
00098     _hasHeader = getAttr(balise, "hasHeader").toInt();
00099     _hasFooter = getAttr(balise, "hasFooter").toInt();
00100     setUnit(getAttr(balise, "unit").toInt());
00101 }
00102 
00103 /*******************************************/
00104 /* Generate                                */
00105 /*******************************************/
00106 void FileHeader::generate(QTextStream &out)
00107 {
00108     kdDebug(30522) << "GENERATION OF THE FILE HEADER" << endl;
00109     if(Config::instance()->mustUseLatin1())
00110         generateLatinPreambule(out);
00111     else if(Config::instance()->mustUseUnicode())
00112         generateUnicodePreambule(out);
00113 
00114     generatePackage(out);
00115     if(getFormat() == TF_CUSTOM)
00116         generatePaper(out);
00117     out << "%%%%%%%%%%%%%%%%%% END OF PREAMBLE %%%%%%%%%%%%%%%%%%" << endl << endl;
00118 }
00119 
00120 /*******************************************/
00121 /* GeneratePaper                           */
00122 /*******************************************/
00123 void FileHeader::generatePaper(QTextStream &out)
00124 {
00125     QString unit;
00126 
00127     out << "% Format of paper" << endl;
00128     kdDebug(30522) << "Generate custom size paper" << endl;
00129     /* paper size */
00130     out << "\\setlength{\\paperwidth}{"  << _width  << "pt}" << endl;
00131     out << "\\setlength{\\paperheight}{" << _height << "pt}" << endl;
00132     /* FileHeader and footer */
00133     out << "\\setlength{\\headsep}{" << _headBody << "pt}" << endl;
00134     out << "\\setlength{\\footskip}{" << _footBody + _bottomBorder << "pt}" << endl;
00135     /* Margin */
00136     out << "\\setlength{\\topmargin}{" << _topBorder << "pt}" << endl;
00137     out << "\\setlength{\\textwidth}{" << _width - _rightBorder - _leftBorder << "pt}" << endl;
00138     out << endl;
00139 }
00140 
00141 /*******************************************/
00142 /* GenerateLatinPreambule                  */
00143 /*******************************************/
00144 void FileHeader::generateLatinPreambule(QTextStream &out)
00145 {
00146     out << "%% Generated by KSpread. Don't modify this file but the file *.ksp." << endl;
00147     out << "%% Send an email to rjacolin@ifrance.com for bugs, wishes, .... Thank you." << endl;
00148     out << "%% Compile this file with : latex filename.tex" << endl;
00149     out << "%% a dvi file will be generated." << endl;
00150     out << "%% The file uses the latex style (not the kword style). " << endl;
00151     out << "\\documentclass[";
00152     switch(getFormat())
00153     {
00154         case TF_A3:
00155             out << "";
00156             break;
00157         case TF_A4:
00158             out << "a4paper, ";
00159             break;
00160         case TF_A5:
00161             out << "a5paper, ";
00162             break;
00163         case TF_USLETTER:
00164             out << "letterpaper, ";
00165             break;
00166         case TF_USLEGAL:
00167             out << "legalpaper, ";
00168             break;
00169         case TF_SCREEN:
00170             out << "";
00171             break;
00172         case TF_CUSTOM:
00173             out << "";
00174             break;
00175         case TF_B3:
00176             out << "";
00177             break;
00178         case TF_USEXECUTIVE:
00179             out << "executivepaper, ";
00180             break;
00181     }
00182     if(getOrientation() == TO_LANDSCAPE)
00183         out << "landscape, ";
00184     /* To change : will use a special latexcommand to able to
00185      * obtain more than one column :))
00186      */
00187     switch(getColumns())
00188     {
00189         case TC_1:
00190             //out << "onecolumn, ";
00191             break;
00192         case TC_2:
00193             out << "twocolumn, ";
00194             break;
00195         case TC_MORE:
00196             out << "";
00197     }
00198 
00199     out << Config::instance()->getDefaultFontSize() << "pt";
00200     if(Config::instance()->getQuality() == "draft")
00201         out << ", draft";
00202     out << "]{";
00203     out << Config::instance()->getClass() << "}" << endl;
00204     out << "\\usepackage[" << Config::instance()->getEncoding() << "]{inputenc}" << endl << endl;
00205 }
00206 
00207 /*******************************************/
00208 /* GenerateUnicodePreambule                */
00209 /*******************************************/
00210 void FileHeader::generateUnicodePreambule(QTextStream &out)
00211 {
00212     out << "%% Generated by KSpread. Don't modify this file but the file *.ksp." << endl;
00213     out << "%% Send an email to rjacolin@ifrance.com for bugs, wishes, .... Thank you." << endl;
00214     out << "%% Compile this file with : lambda filename.tex" << endl;
00215     out << "%% a dvi file will be generated." << endl;
00216     out << "%% Use odvips to convert it and to see it with gv" << endl;
00217     out << "%% The file uses the latex style (not the kword style). " << endl;
00218     out << "\\ocp\\TexUTF=inutf8" << endl;
00219     out << "\\InputTranslation currentfile \\TexUTF" << endl;
00220     out << "\\documentclass[";
00221     switch(getFormat())
00222     {
00223         case TF_A3:
00224             out << "";
00225             break;
00226         case TF_A4:
00227             out << "a4paper, ";
00228             break;
00229         case TF_A5:
00230             out << "a5paper, ";
00231             break;
00232         case TF_USLETTER:
00233             out << "letterpaper, ";
00234             break;
00235         case TF_USLEGAL:
00236             out << "legalpaper, ";
00237             break;
00238         case TF_SCREEN:
00239             out << "";
00240             break;
00241         case TF_CUSTOM:
00242             out << "";
00243             break;
00244         case TF_B3:
00245             out << "";
00246             break;
00247         case TF_USEXECUTIVE:
00248             out << "executivepaper, ";
00249             break;
00250     }
00251     if(getOrientation() == TO_LANDSCAPE)
00252         out << "landscape, ";
00253     /* To change : will use a special latexcommand to able to
00254      * obtain more than one column :))
00255      */
00256     switch(getColumns())
00257     {
00258         case TC_1:
00259             //out << "onecolumn, ";
00260             break;
00261         case TC_2:
00262             out << "twocolumn, ";
00263             break;
00264         case TC_MORE:
00265             out << "";
00266     }
00267 
00268     out << Config::instance()->getDefaultFontSize() << "pt";
00269     if(Config::instance()->getQuality() == "draft")
00270         out << ", draft";
00271     out << "]{";
00272     out << Config::instance()->getClass() << "}" << endl;
00273 }
00274 
00275 
00276 /*******************************************/
00277 /* GeneratePackage                         */
00278 /*******************************************/
00279 void FileHeader::generatePackage(QTextStream &out)
00280 {
00281     out << "% Package(s) to include" << endl;
00282     if(Config::instance()->mustUseUnicode())
00283         out << "\\usepackage{omega}" << endl;
00284     if(getFormat() == TF_A4)
00285         out << "\\usepackage[a4paper]{geometry}" << endl;
00286     if(hasFooter() || hasHeader())
00287         out << "\\usepackage{fancyhdr}" << endl;
00288     if(hasColor())
00289         out << "\\usepackage{colortbl}" << endl;
00290     if(hasUnderline())
00291         out << "\\usepackage{ulem}" << endl;
00292     if(hasEnumerate())
00293         out << "\\usepackage{enumerate}" << endl;
00294     if(hasGraphics())
00295         out << "\\usepackage{graphics}" << endl;
00296     out << "\\usepackage{array}" << endl;
00297     out << "\\usepackage{multirow}" << endl;
00298     out << "\\usepackage{textcomp}" << endl;
00299     out << "\\usepackage{rotating}" << endl;
00300     out << endl;
00301     QStringList langs = Config::instance()->getLanguagesList();
00302     if(langs.count() > 0)
00303     {
00304         out << "\\usepackage[" << langs.join( ", " ) << "]{babel}" << endl;
00305     }
00306     out << "\\usepackage{textcomp}" << endl;
00307     out << endl;
00308 
00309     if(langs.count() > 1)
00310         out <<"\\selectlanguage{" << Config::instance()->getDefaultLanguage()
00311             << "}" << endl << endl;
00312 }
00313 
00314 FileHeader* FileHeader::instance()
00315 {
00316     if(_instance == 0)
00317         _instance = new FileHeader();
00318     return _instance;
00319 }
00320 
KDE Home | KDE Accessibility Home | Description of Access Keys