1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/* TableStyle: Stores (and writes) table-based information that is
* needed at the head of an OO document.
*
* Copyright (C) 2002-2004 William Lachance (william.lachance@sympatico.ca)
* Copyright (C) 2004 Net Integration Technologies, Inc. (http://www.net-itech.com)
* Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For further information visit http://libwpd.sourceforge.net
*
*/
/* "This product is not manufactured, approved, or supported by
* Corel Corporation or Corel Corporation Limited."
*/
#include <math.h>
#include <string.h>
#include "FilterInternal.hxx"
#include "TableStyle.hxx"
#include "DocumentElement.hxx"
#ifdef _MSC_VER
#include <minmax.h>
#endif
TableCellStyle::TableCellStyle(const WPXPropertyList &xPropList, const char *psName) :
Style(psName),
mPropList(xPropList)
{
}
void TableCellStyle::write(DocumentHandler *pHandler) const
{
TagOpenElement styleOpen("style:style");
styleOpen.addAttribute("style:name", getName());
styleOpen.addAttribute("style:family", "table-cell");
styleOpen.write(pHandler);
// WLACH_REFACTORING: Only temporary.. a much better solution is to
// generalize this sort of thing into the "Style" superclass
WPXPropertyList stylePropList;
WPXPropertyList::Iter i(mPropList);
for (i.rewind(); i.next();)
{
if (strlen(i.key()) > 2 && strncmp(i.key(), "fo", 2) == 0)
stylePropList.insert(i.key(), i()->clone());
}
stylePropList.insert("fo:padding", "0.0382inch");
pHandler->startElement("style:properties", stylePropList);
pHandler->endElement("style:properties");
pHandler->endElement("style:style");
}
TableRowStyle::TableRowStyle(const WPXPropertyList &propList, const char *psName) :
Style(psName),
mPropList(propList)
{
}
void TableRowStyle::write(DocumentHandler *pHandler) const
{
TagOpenElement styleOpen("style:style");
styleOpen.addAttribute("style:name", getName());
styleOpen.addAttribute("style:family", "table-row");
styleOpen.write(pHandler);
TagOpenElement stylePropertiesOpen("style:properties");
if (mPropList["style:min-row-height"])
stylePropertiesOpen.addAttribute("style:min-row-height", mPropList["style:min-row-height"]->getStr());
else if (mPropList["style:row-height"])
stylePropertiesOpen.addAttribute("style:row-height", mPropList["style:row-height"]->getStr());
stylePropertiesOpen.write(pHandler);
pHandler->endElement("style:properties");
pHandler->endElement("style:style");
}
TableStyle::TableStyle(const WPXPropertyList &xPropList, const WPXPropertyListVector &columns, const char *psName) :
Style(psName),
mPropList(xPropList),
mColumns(columns)
{
}
TableStyle::~TableStyle()
{
typedef std::vector<TableCellStyle *>::iterator TCSVIter;
typedef std::vector<TableRowStyle *>::iterator TRSVIter;
for (TCSVIter iterTableCellStyles = mTableCellStyles.begin() ; iterTableCellStyles != mTableCellStyles.end(); iterTableCellStyles++)
delete(*iterTableCellStyles);
for (TRSVIter iterTableRowStyles = mTableRowStyles.begin() ; iterTableRowStyles != mTableRowStyles.end(); iterTableRowStyles++)
delete(*iterTableRowStyles);
}
void TableStyle::write(DocumentHandler *pHandler) const
{
TagOpenElement styleOpen("style:style");
styleOpen.addAttribute("style:name", getName());
styleOpen.addAttribute("style:family", "table");
if (getMasterPageName())
styleOpen.addAttribute("style:master-page-name", getMasterPageName()->cstr());
styleOpen.write(pHandler);
TagOpenElement stylePropertiesOpen("style:properties");
if (mPropList["table:align"])
stylePropertiesOpen.addAttribute("table:align", mPropList["table:align"]->getStr());
if (mPropList["fo:margin-left"])
stylePropertiesOpen.addAttribute("fo:margin-left", mPropList["fo:margin-left"]->getStr());
if (mPropList["fo:margin-right"])
stylePropertiesOpen.addAttribute("fo:margin-right", mPropList["fo:margin-right"]->getStr());
if (mPropList["style:width"])
stylePropertiesOpen.addAttribute("style:width", mPropList["style:width"]->getStr());
if (mPropList["fo:break-before"])
stylePropertiesOpen.addAttribute("fo:break-before", mPropList["fo:break-before"]->getStr());
stylePropertiesOpen.write(pHandler);
pHandler->endElement("style:properties");
pHandler->endElement("style:style");
int i=1;
WPXPropertyListVector::Iter j(mColumns);
for (j.rewind(); j.next();)
{
TagOpenElement styleNestedOpen("style:style");
WPXString sColumnName;
sColumnName.sprintf("%s.Column%i", getName().cstr(), i);
styleNestedOpen.addAttribute("style:name", sColumnName);
styleNestedOpen.addAttribute("style:family", "table-column");
styleNestedOpen.write(pHandler);
pHandler->startElement("style:properties", j());
pHandler->endElement("style:properties");
pHandler->endElement("style:style");
i++;
}
typedef std::vector<TableRowStyle *>::const_iterator TRSVIter;
for (TRSVIter iterTableRow = mTableRowStyles.begin() ; iterTableRow != mTableRowStyles.end(); iterTableRow++)
(*iterTableRow)->write(pHandler);
typedef std::vector<TableCellStyle *>::const_iterator TCSVIter;
for (TCSVIter iterTableCell = mTableCellStyles.begin() ; iterTableCell != mTableCellStyles.end(); iterTableCell++)
(*iterTableCell)->write(pHandler);
}
|