/src/libwpd/src/lib/WP5DefinitionGroup.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 "WP5DefinitionGroup.h" |
27 | | #include "WP5Listener.h" |
28 | | #include "libwpd_internal.h" |
29 | | |
30 | | WP5DefinitionGroup_DefineTablesSubGroup::WP5DefinitionGroup_DefineTablesSubGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption, unsigned short subGroupSize) : |
31 | 0 | WP5VariableLengthGroup_SubGroup(), |
32 | 0 | m_position(0), |
33 | 0 | m_numColumns(0), |
34 | 0 | m_leftOffset(0), |
35 | 0 | m_leftGutter(0), |
36 | 0 | m_rightGutter(0) |
37 | 0 | { |
38 | 0 | long startPosition = input->tell(); |
39 | | // Skip useless old values to read the old column number |
40 | 0 | input->seek(2, librevenge::RVNG_SEEK_CUR); |
41 | 0 | m_numColumns = readU16(input, encryption); |
42 | | // Skip to new values |
43 | 0 | input->seek(20+(5*m_numColumns), librevenge::RVNG_SEEK_CUR); |
44 | | // Read the new values |
45 | 0 | unsigned char tmpFlags = readU8(input, encryption); |
46 | 0 | m_position = tmpFlags & 0x07; |
47 | 0 | input->seek(1, librevenge::RVNG_SEEK_CUR); |
48 | 0 | m_numColumns = readU16(input, encryption); |
49 | 0 | input->seek(4, librevenge::RVNG_SEEK_CUR); |
50 | 0 | m_leftGutter = readU16(input, encryption); |
51 | 0 | m_rightGutter = readU16(input, encryption); |
52 | 0 | input->seek(10, librevenge::RVNG_SEEK_CUR); |
53 | 0 | m_leftOffset = readU16(input, encryption); |
54 | 0 | int i; |
55 | 0 | if ((m_numColumns > 32) || ((input->tell() - startPosition + m_numColumns*5) > (subGroupSize - 4))) |
56 | 0 | throw FileException(); |
57 | 0 | for (i=0; i < m_numColumns; i++) |
58 | 0 | { |
59 | 0 | if (input->isEnd()) |
60 | 0 | throw FileException(); |
61 | 0 | m_columnWidth[i] = readU16(input, encryption); |
62 | 0 | } |
63 | 0 | for (i=0; i < m_numColumns; i++) |
64 | 0 | { |
65 | 0 | if (input->isEnd()) |
66 | 0 | throw FileException(); |
67 | 0 | m_attributeBits[i] = readU16(input, encryption); |
68 | 0 | } |
69 | 0 | for (i=0; i < m_numColumns; i++) |
70 | 0 | { |
71 | 0 | if (input->isEnd()) |
72 | 0 | throw FileException(); |
73 | 0 | m_columnAlignment[i] = readU8(input, encryption); |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | | void WP5DefinitionGroup_DefineTablesSubGroup::parse(WP5Listener *listener) |
78 | 0 | { |
79 | | // Since there are no nested tables in WP5, a new table definition automatically closes previous table |
80 | 0 | listener->endTable(); |
81 | |
|
82 | 0 | listener->defineTable(m_position, m_leftOffset); |
83 | 0 | for (int i=0; i < m_numColumns && i < 32; i++) |
84 | 0 | listener->addTableColumnDefinition(m_columnWidth[i], m_leftGutter, m_rightGutter, m_attributeBits[i], m_columnAlignment[i]); |
85 | 0 | listener->startTable(); |
86 | 0 | } |
87 | | |
88 | | |
89 | | WP5DefinitionGroup::WP5DefinitionGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption) : |
90 | 0 | WP5VariableLengthGroup(), |
91 | 0 | m_subGroupData() |
92 | 0 | { |
93 | 0 | _read(input, encryption); |
94 | 0 | } |
95 | | |
96 | | WP5DefinitionGroup::~WP5DefinitionGroup() |
97 | 0 | { |
98 | 0 | } |
99 | | |
100 | | void WP5DefinitionGroup::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption) |
101 | 0 | { |
102 | 0 | switch (getSubGroup()) |
103 | 0 | { |
104 | 0 | case WP5_TOP_DEFINITION_GROUP_DEFINE_TABLES: |
105 | 0 | m_subGroupData.reset(new WP5DefinitionGroup_DefineTablesSubGroup(input, encryption, getSize())); |
106 | 0 | break; |
107 | 0 | default: |
108 | 0 | break; |
109 | 0 | } |
110 | 0 | } |
111 | | |
112 | | void WP5DefinitionGroup::parse(WP5Listener *listener) |
113 | 0 | { |
114 | 0 | WPD_DEBUG_MSG(("WordPerfect: handling a Definition group\n")); |
115 | |
|
116 | 0 | switch (getSubGroup()) |
117 | 0 | { |
118 | 0 | case WP5_TOP_DEFINITION_GROUP_DEFINE_TABLES: |
119 | 0 | m_subGroupData->parse(listener); |
120 | 0 | break; |
121 | 0 | default: |
122 | 0 | break; |
123 | 0 | } |
124 | 0 | } |
125 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |