/src/libwpd/src/lib/WP3TablesGroup.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | | /* libwpd |
3 | | * Version: MPL 2.0 / LGPLv2.1+ |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * Major Contributor(s): |
10 | | * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch) |
11 | | * |
12 | | * For minor contributions see the git repository. |
13 | | * |
14 | | * Alternatively, the contents of this file may be used under the terms |
15 | | * of the GNU Lesser General Public License Version 2.1 or later |
16 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
17 | | * applicable instead of those above. |
18 | | * |
19 | | * For further information visit http://libwpd.sourceforge.net |
20 | | */ |
21 | | |
22 | | /* "This product is not manufactured, approved, or supported by |
23 | | * Corel Corporation or Corel Corporation Limited." |
24 | | */ |
25 | | |
26 | | #include <math.h> |
27 | | #include "WP3TablesGroup.h" |
28 | | #include "WP3FileStructure.h" |
29 | | #include "WP3Listener.h" |
30 | | #include "WPXFileStructure.h" |
31 | | #include "libwpd_internal.h" |
32 | | #include "libwpd_math.h" |
33 | | |
34 | | WP3TablesGroup::WP3TablesGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption) : |
35 | 0 | m_tableMode(0), |
36 | 0 | m_offsetFromLeftEdge(0), |
37 | 0 | m_topGutterSpacing(0), |
38 | 0 | m_leftGutterSpacing(0), |
39 | 0 | m_bottomGutterSpacing(0), |
40 | 0 | m_rightGutterSpacing(0), |
41 | 0 | m_numColumns(0), |
42 | 0 | m_columnMode(32), |
43 | 0 | m_numberFormat(32), |
44 | 0 | m_columnWidth(32), |
45 | 0 | m_rightOffsetForDecimalAlign(32), |
46 | 0 | m_colSpan(0), |
47 | 0 | m_rowSpan(0), |
48 | 0 | m_cellFillColor(RGBSColor(0xff, 0xff, 0xff)) |
49 | 0 | { |
50 | 0 | _read(input, encryption); |
51 | 0 | } |
52 | | |
53 | | WP3TablesGroup::~WP3TablesGroup() |
54 | 0 | { |
55 | 0 | } |
56 | | |
57 | | void WP3TablesGroup::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption) |
58 | 0 | { |
59 | | // this group can contain different kinds of data, thus we need to read |
60 | | // the contents accordingly |
61 | 0 | unsigned char i; |
62 | 0 | long startPosition = 0; |
63 | 0 | switch (getSubGroup()) |
64 | 0 | { |
65 | 0 | case WP3_TABLES_GROUP_TABLE_FUNCTION: |
66 | 0 | startPosition = input->tell(); |
67 | 0 | input->seek(71, librevenge::RVNG_SEEK_CUR); |
68 | 0 | m_tableMode = readU8(input, encryption); |
69 | 0 | m_offsetFromLeftEdge = readU32(input, encryption, true); |
70 | 0 | m_topGutterSpacing = readU32(input, encryption, true); |
71 | 0 | m_leftGutterSpacing = readU32(input, encryption, true); |
72 | 0 | m_bottomGutterSpacing = readU32(input, encryption, true); |
73 | 0 | m_rightGutterSpacing = readU32(input, encryption, true); |
74 | 0 | input->seek(3, librevenge::RVNG_SEEK_CUR); |
75 | 0 | m_numColumns = readU8(input, encryption); |
76 | 0 | if ((m_numColumns > 32) || ((input->tell() - startPosition + m_numColumns*10) > (getSize() - 4))) |
77 | 0 | throw FileException(); |
78 | 0 | for (i=0; i<m_numColumns; i++) |
79 | 0 | { |
80 | 0 | if (input->isEnd()) |
81 | 0 | throw FileException(); |
82 | 0 | m_columnMode[i] = readU8(input, encryption); |
83 | 0 | m_numberFormat[i] = readU8(input, encryption); |
84 | 0 | m_columnWidth[i] = readU32(input, encryption, true); |
85 | 0 | m_rightOffsetForDecimalAlign[i] = readU32(input, encryption, true); |
86 | 0 | } |
87 | 0 | break; |
88 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_SPAN: |
89 | 0 | m_colSpan = readU16(input, encryption, true); |
90 | 0 | m_rowSpan = readU16(input, encryption, true); |
91 | 0 | m_colSpan++; |
92 | 0 | m_rowSpan++; |
93 | 0 | break; |
94 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_TOP_LINE: |
95 | 0 | break; |
96 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_LEFT_LINE: |
97 | 0 | break; |
98 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_BOTTOM_LINE: |
99 | 0 | break; |
100 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_RIGHT_LINE: |
101 | 0 | break; |
102 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_TOP_LINE_COLOR: |
103 | 0 | break; |
104 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_LEFT_LINE_COLOR: |
105 | 0 | break; |
106 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_BOTTOM_LINE_COLOR: |
107 | 0 | break; |
108 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_RIGHT_LINE_COLOR: |
109 | 0 | break; |
110 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_FILL_COLOR_PATTERN: |
111 | 0 | { |
112 | 0 | unsigned short tmpRed = readU16(input, encryption, true); |
113 | 0 | unsigned short tmpGreen = readU16(input, encryption, true); |
114 | 0 | unsigned short tmpBlue = readU16(input, encryption, true); |
115 | 0 | m_cellFillColor = RGBSColor(tmpRed, tmpGreen, tmpBlue); |
116 | 0 | } |
117 | 0 | break; |
118 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_VERTICAL_ALIGNMENT: |
119 | 0 | break; |
120 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_MODE: |
121 | 0 | break; |
122 | 0 | case WP3_TABLES_GROUP_SET_TABLE_ROW_MODE: |
123 | 0 | break; |
124 | 0 | default: /* something else we don't support, since it isn't in the docs */ |
125 | 0 | break; |
126 | 0 | } |
127 | 0 | } |
128 | | |
129 | | void WP3TablesGroup::parse(WP3Listener *listener) |
130 | 0 | { |
131 | 0 | WPD_DEBUG_MSG(("WordPerfect: handling a Tables group\n")); |
132 | |
|
133 | 0 | unsigned char i; |
134 | 0 | switch (getSubGroup()) |
135 | 0 | { |
136 | 0 | case WP3_TABLES_GROUP_TABLE_FUNCTION: |
137 | 0 | listener->defineTable(m_tableMode, fixedPointToWPUs(m_offsetFromLeftEdge)); |
138 | 0 | for (i=0; i<m_numColumns && i < 32; i++) |
139 | 0 | listener->addTableColumnDefinition(fixedPointToWPUs(m_columnWidth[i]), fixedPointToWPUs(m_leftGutterSpacing), |
140 | 0 | fixedPointToWPUs(m_rightGutterSpacing), 0, LEFT); |
141 | 0 | listener->startTable(); |
142 | 0 | break; |
143 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_SPAN: |
144 | 0 | listener->setTableCellSpan(m_colSpan, m_rowSpan); |
145 | 0 | break; |
146 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_TOP_LINE: |
147 | 0 | break; |
148 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_LEFT_LINE: |
149 | 0 | break; |
150 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_BOTTOM_LINE: |
151 | 0 | break; |
152 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_RIGHT_LINE: |
153 | 0 | break; |
154 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_TOP_LINE_COLOR: |
155 | 0 | break; |
156 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_LEFT_LINE_COLOR: |
157 | 0 | break; |
158 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_BOTTOM_LINE_COLOR: |
159 | 0 | break; |
160 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_RIGHT_LINE_COLOR: |
161 | 0 | break; |
162 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_FILL_COLOR_PATTERN: |
163 | 0 | listener->setTableCellFillColor(&m_cellFillColor); |
164 | 0 | break; |
165 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_VERTICAL_ALIGNMENT: |
166 | 0 | break; |
167 | 0 | case WP3_TABLES_GROUP_SET_TABLE_CELL_MODE: |
168 | 0 | break; |
169 | 0 | case WP3_TABLES_GROUP_SET_TABLE_ROW_MODE: |
170 | 0 | break; |
171 | 0 | default: // something else we don't support, since it isn't in the docs |
172 | 0 | break; |
173 | 0 | } |
174 | 0 | } |
175 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |