filters

kspread/latex/export/fileheader.cpp
1/*
2** A program to convert the XML rendered by KWord into LATEX.
3**
4** Copyright (C) 2000, 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 "fileheader.h"
27#include "config.h"
28
29FileHeader* FileHeader::_instance = 0;
30
31/*******************************************/
32/* Constructor */
33/*******************************************/
35{
36 _hasHeader = false;
37 _hasFooter = false;
38 _hasColor = false;
39 _hasUnderline = false;
40 _hasEnumerate = false;
41 _hasGraphics = false;
42 _hasTable = false;
43 _standardPage = 0;
44 _processing = TP_NORMAL;
45 //setFileHeader(this); /* for xmlParser class. */
46}
47
48/*******************************************/
49/* Destructor */
50/*******************************************/
52{
53 kdDebug(30522) << "FileHeader Destructor" << endl;
54}
55
56/*******************************************/
57/* AnalysePaperParam */
58/*******************************************/
59void FileHeader::analysePaperParam(const TQDomNode balise)
60{
61 setFormat(getAttr(balise, "format").toInt());
62 _width = getAttr(balise, "width").toInt();
63 _height = getAttr(balise, "height").toInt();
64 setOrientation(getAttr(balise, "orientation").toInt());
65 setColumns(getAttr(balise, "columns").toInt());
66 _columnSpacing = getAttr(balise, "columnspacing").toInt();
67 setHeadType(getAttr(balise, "hType").toInt());
68 setFootType(getAttr(balise, "fType").toInt());
69 _headBody = getAttr(balise, "spHeadBody").toInt();
70 _footBody = getAttr(balise, "spFootBody").toInt();
71 //getAttr(balise, "zoom").toInt();
72}
73
74/*******************************************/
75/* AnalysePaper */
76/*******************************************/
77void FileHeader::analysePaper(const TQDomNode balise)
78{
79 analysePaperParam(balise);
80
81 //setTokenCurrent(balise_initiale->pContent);
82 // Analyse children markups --> PAPERBORDERS
83 TQDomNode fils = getChild(balise, "PAPERSBORDERS");
84 _leftBorder = getAttr(fils, "left").toInt();
85 _rightBorder = getAttr(fils, "right").toInt();
86 _bottomBorder = getAttr(fils, "bottom").toInt();
87 _topBorder = getAttr(fils, "top").toInt();
88}
89
90/*******************************************/
91/* AnalyseAttributs */
92/*******************************************/
93void FileHeader::analyseAttributs(const TQDomNode balise)
94{
95 setProcessing(getAttr(balise, "processing").toInt());
96 setStandardPge(getAttr(balise, "standardpage").toInt());
97 setTOC(getAttr(balise, "hasTOC").toInt());
98 _hasHeader = getAttr(balise, "hasHeader").toInt();
99 _hasFooter = getAttr(balise, "hasFooter").toInt();
100 setUnit(getAttr(balise, "unit").toInt());
101}
102
103/*******************************************/
104/* Generate */
105/*******************************************/
106void FileHeader::generate(TQTextStream &out)
107{
108 kdDebug(30522) << "GENERATION OF THE FILE HEADER" << endl;
109 if(Config::instance()->mustUseLatin1())
110 generateLatinPreambule(out);
111 else if(Config::instance()->mustUseUnicode())
112 generateUnicodePreambule(out);
113
114 generatePackage(out);
115 if(getFormat() == TF_CUSTOM)
116 generatePaper(out);
117 out << "%%%%%%%%%%%%%%%%%% END OF PREAMBLE %%%%%%%%%%%%%%%%%%" << endl << endl;
118}
119
120/*******************************************/
121/* GeneratePaper */
122/*******************************************/
123void FileHeader::generatePaper(TQTextStream &out)
124{
125 TQString unit;
126
127 out << "% Format of paper" << endl;
128 kdDebug(30522) << "Generate custom size paper" << endl;
129 /* paper size */
130 out << "\\setlength{\\paperwidth}{" << _width << "pt}" << endl;
131 out << "\\setlength{\\paperheight}{" << _height << "pt}" << endl;
132 /* FileHeader and footer */
133 out << "\\setlength{\\headsep}{" << _headBody << "pt}" << endl;
134 out << "\\setlength{\\footskip}{" << _footBody + _bottomBorder << "pt}" << endl;
135 /* Margin */
136 out << "\\setlength{\\topmargin}{" << _topBorder << "pt}" << endl;
137 out << "\\setlength{\\textwidth}{" << _width - _rightBorder - _leftBorder << "pt}" << endl;
138 out << endl;
139}
140
141/*******************************************/
142/* GenerateLatinPreambule */
143/*******************************************/
144void FileHeader::generateLatinPreambule(TQTextStream &out)
145{
146 out << "%% Generated by KSpread. Don't modify this file but the file *.ksp." << endl;
147 out << "%% Send an email to rjacolin@ifrance.com for bugs, wishes, .... Thank you." << endl;
148 out << "%% Compile this file with : latex filename.tex" << endl;
149 out << "%% a dvi file will be generated." << endl;
150 out << "%% The file uses the latex style (not the kword style). " << endl;
151 out << "\\documentclass[";
152 switch(getFormat())
153 {
154 case TF_A3:
155 out << "";
156 break;
157 case TF_A4:
158 out << "a4paper, ";
159 break;
160 case TF_A5:
161 out << "a5paper, ";
162 break;
163 case TF_USLETTER:
164 out << "letterpaper, ";
165 break;
166 case TF_USLEGAL:
167 out << "legalpaper, ";
168 break;
169 case TF_SCREEN:
170 out << "";
171 break;
172 case TF_CUSTOM:
173 out << "";
174 break;
175 case TF_B3:
176 out << "";
177 break;
178 case TF_USEXECUTIVE:
179 out << "executivepaper, ";
180 break;
181 }
182 if(getOrientation() == TO_LANDSCAPE)
183 out << "landscape, ";
184 /* To change : will use a special latexcommand to able to
185 * obtain more than one column :))
186 */
187 switch(getColumns())
188 {
189 case TC_1:
190 //out << "onecolumn, ";
191 break;
192 case TC_2:
193 out << "twocolumn, ";
194 break;
195 case TC_MORE:
196 out << "";
197 }
198
199 out << Config::instance()->getDefaultFontSize() << "pt";
200 if(Config::instance()->getQuality() == "draft")
201 out << ", draft";
202 out << "]{";
203 out << Config::instance()->getClass() << "}" << endl;
204 out << "\\usepackage[" << Config::instance()->getEncoding() << "]{inputenc}" << endl << endl;
205}
206
207/*******************************************/
208/* GenerateUnicodePreambule */
209/*******************************************/
210void FileHeader::generateUnicodePreambule(TQTextStream &out)
211{
212 out << "%% Generated by KSpread. Don't modify this file but the file *.ksp." << endl;
213 out << "%% Send an email to rjacolin@ifrance.com for bugs, wishes, .... Thank you." << endl;
214 out << "%% Compile this file with : lambda filename.tex" << endl;
215 out << "%% a dvi file will be generated." << endl;
216 out << "%% Use odvips to convert it and to see it with gv" << endl;
217 out << "%% The file uses the latex style (not the kword style). " << endl;
218 out << "\\ocp\\TexUTF=inutf8" << endl;
219 out << "\\InputTranslation currentfile \\TexUTF" << endl;
220 out << "\\documentclass[";
221 switch(getFormat())
222 {
223 case TF_A3:
224 out << "";
225 break;
226 case TF_A4:
227 out << "a4paper, ";
228 break;
229 case TF_A5:
230 out << "a5paper, ";
231 break;
232 case TF_USLETTER:
233 out << "letterpaper, ";
234 break;
235 case TF_USLEGAL:
236 out << "legalpaper, ";
237 break;
238 case TF_SCREEN:
239 out << "";
240 break;
241 case TF_CUSTOM:
242 out << "";
243 break;
244 case TF_B3:
245 out << "";
246 break;
247 case TF_USEXECUTIVE:
248 out << "executivepaper, ";
249 break;
250 }
251 if(getOrientation() == TO_LANDSCAPE)
252 out << "landscape, ";
253 /* To change : will use a special latexcommand to able to
254 * obtain more than one column :))
255 */
256 switch(getColumns())
257 {
258 case TC_1:
259 //out << "onecolumn, ";
260 break;
261 case TC_2:
262 out << "twocolumn, ";
263 break;
264 case TC_MORE:
265 out << "";
266 }
267
268 out << Config::instance()->getDefaultFontSize() << "pt";
269 if(Config::instance()->getQuality() == "draft")
270 out << ", draft";
271 out << "]{";
272 out << Config::instance()->getClass() << "}" << endl;
273}
274
275
276/*******************************************/
277/* GeneratePackage */
278/*******************************************/
279void FileHeader::generatePackage(TQTextStream &out)
280{
281 out << "% Package(s) to include" << endl;
282 if(Config::instance()->mustUseUnicode())
283 out << "\\usepackage{omega}" << endl;
284 if(getFormat() == TF_A4)
285 out << "\\usepackage[a4paper]{geometry}" << endl;
286 if(hasFooter() || hasHeader())
287 out << "\\usepackage{fancyhdr}" << endl;
288 if(hasColor())
289 out << "\\usepackage{colortbl}" << endl;
290 if(hasUnderline())
291 out << "\\usepackage{ulem}" << endl;
292 if(hasEnumerate())
293 out << "\\usepackage{enumerate}" << endl;
294 if(hasGraphics())
295 out << "\\usepackage{graphics}" << endl;
296 out << "\\usepackage{array}" << endl;
297 out << "\\usepackage{multirow}" << endl;
298 out << "\\usepackage{textcomp}" << endl;
299 out << "\\usepackage{rotating}" << endl;
300 out << endl;
301 TQStringList langs = Config::instance()->getLanguagesList();
302 if(langs.count() > 0)
303 {
304 out << "\\usepackage[" << langs.join( ", " ) << "]{babel}" << endl;
305 }
306 out << "\\usepackage{textcomp}" << endl;
307 out << endl;
308
309 if(langs.count() > 1)
310 out <<"\\selectlanguage{" << Config::instance()->getDefaultLanguage()
311 << "}" << endl << endl;
312}
313
314FileHeader* FileHeader::instance()
315{
316 if(_instance == 0)
317 _instance = new FileHeader();
318 return _instance;
319}
320
This class hold all general information about the doc : does it use a color markup,...
void setFormat(TFormat f)
Modifiors.
virtual ~FileHeader()
Destructor.
TFormat getFormat() const
Accessors.