/src/libwpd/src/lib/WP3DefinitionGroup.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 "WP3DefinitionGroup.h" |
28 | | #include "WP3FileStructure.h" |
29 | | #include "WPXFileStructure.h" |
30 | | #include "libwpd_internal.h" |
31 | | #include "libwpd_math.h" |
32 | | #include "WP3Listener.h" |
33 | | |
34 | | WP3DefinitionGroup::WP3DefinitionGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption) : |
35 | 0 | WP3VariableLengthGroup(), |
36 | 0 | m_colType(0), |
37 | 0 | m_numColumns(0), |
38 | 0 | m_isFixedWidth(), |
39 | 0 | m_columnWidth() |
40 | 0 | { |
41 | 0 | _read(input, encryption); |
42 | 0 | } |
43 | | |
44 | | WP3DefinitionGroup::~WP3DefinitionGroup() |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | | void WP3DefinitionGroup::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption) |
49 | 0 | { |
50 | | // this group can contain different kinds of data, thus we need to read |
51 | | // the contents accordingly |
52 | 0 | switch (getSubGroup()) |
53 | 0 | { |
54 | 0 | case WP3_DEFINITION_GROUP_SET_COLUMNS: |
55 | 0 | { |
56 | 0 | unsigned char tmpColType = readU8(input, encryption); |
57 | 0 | if (tmpColType) |
58 | 0 | { |
59 | 0 | unsigned char tmpNumColumns = readU8(input, encryption); |
60 | 0 | if (tmpNumColumns) |
61 | 0 | input->seek(((2*tmpNumColumns) - 1), librevenge::RVNG_SEEK_CUR); |
62 | 0 | } |
63 | |
|
64 | 0 | m_colType = readU8(input, encryption); |
65 | 0 | if (!m_colType) |
66 | 0 | { |
67 | 0 | m_numColumns = 1; |
68 | 0 | m_isFixedWidth.clear(); |
69 | 0 | m_columnWidth.clear(); |
70 | 0 | } |
71 | 0 | else |
72 | 0 | { |
73 | 0 | m_numColumns = readU8(input, encryption); |
74 | 0 | if (m_numColumns > 1) |
75 | 0 | { |
76 | 0 | for (int i=0; i<((2*m_numColumns)-1); i++) |
77 | 0 | { |
78 | 0 | if (i%2) |
79 | 0 | { |
80 | 0 | unsigned tmpSpaceBetweenColumns = readU32(input, encryption, true); |
81 | 0 | m_isFixedWidth.push_back(true); |
82 | 0 | m_columnWidth.push_back((double)((double)fixedPointToWPUs(tmpSpaceBetweenColumns)/(double)WPX_NUM_WPUS_PER_INCH)); |
83 | 0 | } |
84 | 0 | else |
85 | 0 | { |
86 | 0 | unsigned short tmpSizeOfColumn = readU16(input, encryption, true); |
87 | 0 | m_isFixedWidth.push_back(false); |
88 | 0 | m_columnWidth.push_back((double)((double)tmpSizeOfColumn/(double)0x10000)); |
89 | 0 | } |
90 | 0 | } |
91 | 0 | } |
92 | 0 | } |
93 | 0 | } |
94 | 0 | break; |
95 | 0 | default: /* something else we don't support, since it isn't in the docs */ |
96 | 0 | break; |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | void WP3DefinitionGroup::parse(WP3Listener *listener) |
101 | 0 | { |
102 | 0 | WPD_DEBUG_MSG(("WordPerfect: handling a Definition group\n")); |
103 | |
|
104 | 0 | switch (getSubGroup()) |
105 | 0 | { |
106 | 0 | case WP3_DEFINITION_GROUP_SET_COLUMNS: |
107 | | // number of columns = {0,1} means columns off |
108 | 0 | if ((m_numColumns <= 1)) |
109 | 0 | { |
110 | 0 | listener->columnChange(NEWSPAPER, 1, m_columnWidth, m_isFixedWidth); // the value "1" is bugus, the false bool gives you all the information you need here |
111 | 0 | } |
112 | 0 | else |
113 | 0 | { |
114 | 0 | switch (m_colType) |
115 | 0 | { |
116 | 0 | case WP3_COLUMN_TYPE_NEWSPAPER: |
117 | 0 | listener->columnChange(NEWSPAPER, m_numColumns, m_columnWidth, m_isFixedWidth); |
118 | 0 | break; |
119 | 0 | case WP3_COLUMN_TYPE_PARALLEL: |
120 | 0 | listener->columnChange(PARALLEL, m_numColumns, m_columnWidth, m_isFixedWidth); |
121 | 0 | break; |
122 | 0 | case WP3_COLUMN_TYPE_EXTENDED: |
123 | 0 | listener->columnChange(PARALLEL_PROTECT, m_numColumns, m_columnWidth, m_isFixedWidth); |
124 | 0 | break; |
125 | 0 | default: // something else we don't support, since it isn't in the docs |
126 | 0 | break; |
127 | 0 | } |
128 | 0 | } |
129 | 0 | break; |
130 | 0 | default: // something else we don't support, since it isn't in the docs |
131 | 0 | break; |
132 | 0 | } |
133 | 0 | } |
134 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |