filters

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