2
** A program to convert the XML rendered by KWord into LATEX.
4
** Copyright (C) 2000 Robert JACOLIN
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.
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.
16
** To receive a copy of the GNU Library General Public License, write to the
17
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
** Boston, MA 02111-1307, USA.
22
#include <kdebug.h> /* for kdDebug stream */
23
#include <qbitarray.h>
29
/*******************************************/
31
/*******************************************/
38
/*******************************************/
40
/*******************************************/
45
void Table::setMaxColumn(int col)
47
if(_maxCol < col) _maxCol = col;
50
void Table::setMaxRow(int row)
52
if(_maxRow < row) _maxRow = row;
55
void Table::analyse(const QDomNode balise)
57
kdDebug() << "New table" << endl;
58
if(getAttr(balise, "columnnumber") == "1")
60
if(getAttr(balise, "borders") == "1")
62
if(getAttr(balise, "hide") == "1")
64
if(getAttr(balise, "hidezero") == "1")
66
if(getAttr(balise, "firstletterupper") == "1")
67
setFirstletterupper();
68
if(getAttr(balise, "grid") == "1")
70
if(getAttr(balise, "printgrid") == "1")
72
if(getAttr(balise, "printCommentIndicator") == "1")
73
setPrintCommentIndicator();
74
if(getAttr(balise, "printFormulaIndicator") == "1")
75
setPrintFormulaIndicator();
76
if(getAttr(balise, "showFormula") == "1")
78
if(getAttr(balise, "showFormulaIndicator") == "1")
79
setShowFormulaIndicator();
80
if(getAttr(balise, "lcmode") == "1")
82
setName(getAttr(balise, "name"));
84
analysePaper(getChild(balise, "paper"));
86
int max = getNbChild(balise);
87
for(int index = 0; index < max; index++)
89
QString name = getChildName(balise, index);
92
kdDebug() << "----- cell -----" << endl;
93
Cell* cell = new Cell();
94
cell->analyse(getChild(balise, index));
96
setMaxColumn(cell->getCol());
97
setMaxRow(cell->getRow());
99
else if(name == "column")
101
kdDebug() << "----- column -----" << endl;
102
Column* column = new Column();
103
column->analyse(getChild(balise, index));
104
_columns.append(column);
106
else if(name == "row")
108
kdDebug() << "----- row -----" << endl;
109
Row* row = new Row();
110
row->analyse(getChild(balise, index));
114
kdDebug() << "name : " << name << endl;
118
void Table::analysePaper(const QDomNode balise)
120
setFormat(getAttr(balise, "format"));
121
setOrientation(getAttr(balise, "orientation"));
124
QDomNode border = getChild(balise, "borders");
125
setBorderRight(getAttr(balise, "right").toLong());
126
setBorderLeft(getAttr(balise, "left").toLong());
127
setBorderBottom(getAttr(balise, "bottom").toLong());
128
setBorderTop(getAttr(balise, "top").toLong());
131
Cell* Table::searchCell(int col, int row)
133
QPtrListIterator<Cell> it(_cells);
135
kdDebug() << "search in list of " << _cells.count() << " cells" << endl;
137
while ( (cell = it.current()) != 0 )
140
kdDebug() << "cell: " << cell->getRow() << "-" << cell->getCol() << endl;
141
if(cell->getCol() == col && cell->getRow() == row)
147
Column* Table::searchColumn(int col)
149
QPtrListIterator<Column> it(_columns);
152
while ( (column = it.current()) != 0 )
155
if(column->getCol() == col)
161
Row* Table::searchRow(int rowNumber)
163
QPtrListIterator<Row> it(_rows);
166
while ( (row = it.current()) != 0 )
169
if(row->getRow() == rowNumber)
175
/*******************************************/
177
/*******************************************/
178
void Table::generate(QTextStream& out)
180
kdDebug() << "GENERATION OF A TABLE " << getMaxRow() << " - " << getMaxColumn()
182
out << endl << "%% " << getName() << endl;
183
if(getOrientation() == "Portrait")
185
out << "\\begin{sidewaystable}" << endl << endl;
190
out << "\\begin{tabular}";
191
generateTableHeader(out);
195
while(rowNumber <= getMaxRow())
197
generateTopLineBorder(out, rowNumber);
198
Row* row = searchRow(rowNumber);
202
for(int col = 1; col <= getMaxColumn(); col++)
205
generateCell(out, rowNumber, col);
207
if(col < getMaxColumn())
210
out << "\\\\" << endl;
213
generateBottomLineBorder(out, rowNumber - 1);
216
out << "\\end{tabular}" << endl << endl;
219
if(getOrientation() == "Portrait")
221
out << "\\end{sidewaystable}" << endl;
225
kdDebug() << "GENERATION OF A TABLE " << count() << endl;
226
out << endl << "\\begin{tabular}";
227
generateTableHeader(out);
232
while(row <= getMaxRow())
234
generateTopLineBorder(out, row);
235
for(int col= 0; col <= getMaxCol(); col++)
239
/* Search the cell in the list */
240
/* elt = searchCell(row, col);
242
out << "\\multicolumn{1}{";
243
if(elt->hasLeftBorder())
245
out << "m{" << getCellSize(col) << "pt}";
247
if(elt->hasRightBorder())
251
generateCell(out, row, col);
253
if(col < getMaxCol())
256
out << "\\\\" << endl;
260
generateBottomLineBorder(out, row - 1);
261
out << "\\end{tabular}" << endl << endl;
263
kdDebug() << "END OF GENERATINO OF A TABLE" << endl;
266
/*******************************************/
267
/* generateTopLineBorder */
268
/*******************************************/
269
void Table::generateTopLineBorder(QTextStream& out, int row)
273
QBitArray border( getMaxColumn() );
274
bool fullLine = true;
275
for(int index = 1; index <= getMaxColumn(); index++)
277
/* Search the cell in the list */
278
kdDebug() << "search " << row << ", " << index << endl;
279
cell = searchCell(index, row);
282
cell = new Cell(row, index);
284
/* If the element has a border display it here */
285
border[ index ] = cell->hasTopBorder();
286
if( ! cell->hasTopBorder() )
292
/* All column have a top border */
294
out << "\\hline" << endl;
299
while(index < getMaxColumn())
306
while(border[index] && index < getMaxColumn())
311
out << "\\cline{" << begin << "-" << end << "} " << endl;
318
row = searchRow(row);
320
row->generate(out);*/
323
/*******************************************/
324
/* generateBottomLineBorder */
325
/*******************************************/
326
void Table::generateBottomLineBorder(QTextStream& out, int row)
329
QBitArray border( getMaxColumn() );
330
bool fullLine = true;
332
for(int index = 1; index <= getMaxColumn(); index++)
334
/* Search the cell in the list */
335
cell = searchCell(index, row);
338
cell = new Cell(row, index);
340
/* If the element has a border display it here */
341
border[ index ] = cell->hasBottomBorder();
342
if( ! cell->hasBottomBorder() )
348
/* All column have a bottom border */
350
out << "\\hline" << endl;
355
while(index < getMaxColumn())
362
while(border[index] && index < getMaxColumn())
367
out << "\\cline{" << begin << "-" << end << "} " << endl;
374
/*******************************************/
376
/*******************************************/
377
void Table::generateCell(QTextStream& out, int row, int col)
379
kdDebug() << "GENERATE CELL : " << row << "," << col << endl;
381
/* Search the cell in the list */
382
Cell *cell = searchCell(col, row);
385
kdDebug() << "generate cell with text: " << cell->getText() << endl;
386
cell->generate(out, this);
389
kdDebug() << "END OF A CELL" << endl;
392
/*******************************************/
393
/* generateTableHeader */
394
/*******************************************/
395
void Table::generateTableHeader(QTextStream& out)
401
for(int col = 1; col <= getMaxColumn(); col++)
403
column = searchColumn(col);
405
column->generate(out);