filters

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