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