/src/libwpd/src/lib/WP6ColumnGroup.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) 2002 William Lachance (wrlach@gmail.com) |
11 | | * Copyright (C) 2002 Marc Maurer (uwog@uwog.net) |
12 | | * |
13 | | * For minor contributions see the git repository. |
14 | | * |
15 | | * Alternatively, the contents of this file may be used under the terms |
16 | | * of the GNU Lesser General Public License Version 2.1 or later |
17 | | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
18 | | * applicable instead of those above. |
19 | | * |
20 | | * For further information visit http://libwpd.sourceforge.net |
21 | | */ |
22 | | |
23 | | /* "This product is not manufactured, approved, or supported by |
24 | | * Corel Corporation or Corel Corporation Limited." |
25 | | */ |
26 | | |
27 | | #include "WP6ColumnGroup.h" |
28 | | #include "WP6Listener.h" |
29 | | #include "libwpd_internal.h" |
30 | | #include "WP6FileStructure.h" |
31 | | #include "WPXFileStructure.h" |
32 | | |
33 | | WP6ColumnGroup::WP6ColumnGroup(librevenge::RVNGInputStream *input, WPXEncryption *encryption) : |
34 | 0 | WP6VariableLengthGroup(), |
35 | 0 | m_margin(0), |
36 | 0 | m_colType(0), |
37 | 0 | m_numColumns(0), |
38 | 0 | m_rowSpacing(0.0), |
39 | 0 | m_isFixedWidth(), |
40 | 0 | m_columnWidth() |
41 | 0 | { |
42 | 0 | _read(input, encryption); |
43 | 0 | } |
44 | | |
45 | | void WP6ColumnGroup::_readContents(librevenge::RVNGInputStream *input, WPXEncryption *encryption) |
46 | 0 | { |
47 | | // this group can contain different kinds of data, thus we need to read |
48 | | // the contents accordingly |
49 | 0 | switch (getSubGroup()) |
50 | 0 | { |
51 | 0 | case 0: // Left Margin Set |
52 | 0 | case 1: // Right Margin Set |
53 | 0 | { |
54 | 0 | m_margin = readU16(input, encryption); |
55 | 0 | WPD_DEBUG_MSG(("WordPerfect: Read column group margin size (margin: %i)\n", m_margin)); |
56 | 0 | } |
57 | 0 | break; |
58 | 0 | case 2: |
59 | 0 | { |
60 | 0 | m_colType = readU8(input, encryption); |
61 | 0 | unsigned tmpRowSpacing = readU32(input, encryption); |
62 | 0 | auto tmpRowSpacingIntegerPart = (signed short)((tmpRowSpacing & 0xffff0000) >> 16); |
63 | 0 | auto tmpRowSpacingFractionalPart = (double)((double)(tmpRowSpacing & 0xffff)/(double)0x10000); |
64 | 0 | m_rowSpacing = (double)tmpRowSpacingIntegerPart + tmpRowSpacingFractionalPart; |
65 | 0 | m_numColumns = readU8(input, encryption); |
66 | 0 | if (m_numColumns > 1) |
67 | 0 | { |
68 | 0 | unsigned short tmpWidth; |
69 | 0 | unsigned char tmpDefinition; |
70 | 0 | for (int i=0; i<((2*m_numColumns)-1); i++) |
71 | 0 | { |
72 | 0 | tmpDefinition = readU8(input, encryption); |
73 | 0 | tmpWidth = readU16(input, encryption); |
74 | 0 | if ((tmpDefinition & 0x01) == 0x01) |
75 | 0 | { |
76 | 0 | m_isFixedWidth.push_back(true); |
77 | 0 | m_columnWidth.push_back((double)((double)tmpWidth/(double)WPX_NUM_WPUS_PER_INCH)); |
78 | 0 | } |
79 | 0 | else |
80 | 0 | { |
81 | 0 | m_isFixedWidth.push_back(false); |
82 | 0 | m_columnWidth.push_back((double)((double)tmpWidth/(double)0x10000)); |
83 | 0 | } |
84 | |
|
85 | 0 | } |
86 | 0 | } |
87 | 0 | WPD_DEBUG_MSG(("WordPerfect: Column type: %d\n", m_colType & 0x03)); |
88 | 0 | WPD_DEBUG_MSG(("WordPerfect: Numer of columns: %d\n", m_numColumns)); |
89 | 0 | } |
90 | 0 | break; |
91 | 0 | case 3: /* TODO: Column Border */ |
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 WP6ColumnGroup::parse(WP6Listener *listener) |
101 | 0 | { |
102 | 0 | WPD_DEBUG_MSG(("WordPerfect: handling a Column group\n")); |
103 | |
|
104 | 0 | if (getFlags() & 0x40) // Ignore function flag |
105 | 0 | return; |
106 | | |
107 | 0 | switch (getSubGroup()) |
108 | 0 | { |
109 | 0 | case 0: // Left Margin Set |
110 | 0 | { |
111 | 0 | listener->marginChange(WPX_LEFT, m_margin); |
112 | 0 | } |
113 | 0 | break; |
114 | 0 | case 1: // Right Margin Set |
115 | 0 | { |
116 | 0 | listener->marginChange(WPX_RIGHT, m_margin); |
117 | 0 | } |
118 | 0 | break; |
119 | 0 | case 2: // Define Text Columns |
120 | 0 | { |
121 | | // number of columns = {0,1} means columns off |
122 | 0 | if ((m_numColumns == 0) || (m_numColumns == 1)) |
123 | 0 | { |
124 | 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 |
125 | 0 | } |
126 | 0 | else |
127 | 0 | { |
128 | 0 | switch (m_colType & 0x03) |
129 | 0 | { |
130 | 0 | case WP6_COLUMN_TYPE_NEWSPAPER: |
131 | 0 | listener->columnChange(NEWSPAPER, m_numColumns, m_columnWidth, m_isFixedWidth); |
132 | 0 | break; |
133 | 0 | case WP6_COLUMN_TYPE_NEWSPAPER_VERTICAL_BALANCE: |
134 | 0 | listener->columnChange(NEWSPAPER_VERTICAL_BALANCE, m_numColumns, m_columnWidth, m_isFixedWidth); |
135 | 0 | break; |
136 | 0 | case WP6_COLUMN_TYPE_PARALLEL: |
137 | 0 | listener->columnChange(PARALLEL, m_numColumns, m_columnWidth, m_isFixedWidth); |
138 | 0 | break; |
139 | 0 | case WP6_COLUMN_TYPE_PARALLEL_PROTECT: |
140 | 0 | listener->columnChange(PARALLEL_PROTECT, m_numColumns, m_columnWidth, m_isFixedWidth); |
141 | 0 | break; |
142 | 0 | default: // something else we don't support, since it isn't in the docs |
143 | 0 | break; |
144 | 0 | } |
145 | 0 | } |
146 | 0 | } |
147 | 0 | break; |
148 | 0 | case 3: // TODO: Column Border |
149 | 0 | { |
150 | 0 | } |
151 | 0 | break; |
152 | 0 | default: // something else we don't support, since it isn't in the docs |
153 | 0 | break; |
154 | 0 | } |
155 | 0 | } |
156 | | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |