~ubuntu-branches/ubuntu/edgy/libwpd/edgy-security

« back to all changes in this revision

Viewing changes to src/lib/WP3DefinitionGroup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2005-12-09 16:20:02 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20051209162002-6yx3aa0jrh06oocj
Tags: 0.8.4-2
* re-autogen to fix hppa build
* update automake builddep and add autoconf

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libwpd
 
2
 * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
17
 *
 
18
 * For further information visit http://libwpd.sourceforge.net
 
19
 */
 
20
 
 
21
/* "This product is not manufactured, approved, or supported by
 
22
 * Corel Corporation or Corel Corporation Limited."
 
23
 */
 
24
 
 
25
#include <math.h>
 
26
#include "WP3DefinitionGroup.h"
 
27
#include "WP3FileStructure.h"
 
28
#include "WPXFileStructure.h"
 
29
#include "libwpd_internal.h"
 
30
#include "libwpd_math.h"
 
31
 
 
32
WP3DefinitionGroup::WP3DefinitionGroup(WPXInputStream *input) :
 
33
        WP3VariableLengthGroup()
 
34
{
 
35
        _read(input);
 
36
}
 
37
 
 
38
WP3DefinitionGroup::~WP3DefinitionGroup()
 
39
{
 
40
        // fixme delete the font name
 
41
}
 
42
 
 
43
void WP3DefinitionGroup::_readContents(WPXInputStream *input)
 
44
{
 
45
        // this group can contain different kinds of data, thus we need to read
 
46
        // the contents accordingly
 
47
        switch (getSubGroup())
 
48
        {
 
49
        case WP3_DEFINITION_GROUP_SET_COLUMNS:
 
50
                {
 
51
                        uint8_t tmpColType = readU8(input);
 
52
                        if (tmpColType)
 
53
                        {
 
54
                                uint8_t tmpNumColumns = readU8(input);
 
55
                                if (tmpNumColumns)
 
56
                                        input->seek(((2*tmpNumColumns) - 1), WPX_SEEK_CUR);
 
57
                        }
 
58
 
 
59
                        m_colType = readU8(input);
 
60
                        if (!m_colType)
 
61
                        {
 
62
                                m_numColumns = 1;
 
63
                                m_isFixedWidth.clear();
 
64
                                m_columnWidth.clear();
 
65
                        }
 
66
                        else
 
67
                        {
 
68
                                m_numColumns = readU8(input);
 
69
                                if (m_numColumns > 1)
 
70
                                {
 
71
                                        for (int i=0; i<((2*m_numColumns)-1); i++)
 
72
                                        {
 
73
                                                if (i%2)
 
74
                                                {
 
75
                                                        uint32_t tmpSpaceBetweenColumns = readU32(input, true);
 
76
                                                        m_isFixedWidth.push_back(true);
 
77
                                                        m_columnWidth.push_back((float)((double)fixedPointToWPUs(tmpSpaceBetweenColumns)/(double)WPX_NUM_WPUS_PER_INCH));
 
78
                                                }
 
79
                                                else
 
80
                                                {
 
81
                                                        uint16_t tmpSizeOfColumn = readU16(input, true);
 
82
                                                        m_isFixedWidth.push_back(false);
 
83
                                                        m_columnWidth.push_back((float)((double)tmpSizeOfColumn/(double)0x10000));
 
84
                                                }
 
85
                                        }
 
86
                                }
 
87
                        }
 
88
                }
 
89
                break;
 
90
        default: /* something else we don't support, since it isn't in the docs */
 
91
                break;
 
92
        }
 
93
}
 
94
 
 
95
void WP3DefinitionGroup::parse(WP3Listener *listener)
 
96
{
 
97
        WPD_DEBUG_MSG(("WordPerfect: handling a Definition group\n"));
 
98
 
 
99
        switch (getSubGroup())
 
100
        {
 
101
        case WP3_DEFINITION_GROUP_SET_COLUMNS:
 
102
                // number of columns = {0,1} means columns off
 
103
                if ((m_numColumns <= 1))
 
104
                {
 
105
                        listener->columnChange(NEWSPAPER, 1, m_columnWidth, m_isFixedWidth); // the value "1" is bugus, the false bool gives you all the information you need here
 
106
                } 
 
107
                else
 
108
                {
 
109
                        switch (m_colType)
 
110
                        {
 
111
                                case WP3_COLUMN_TYPE_NEWSPAPER:
 
112
                                        listener->columnChange(NEWSPAPER, m_numColumns, m_columnWidth, m_isFixedWidth);
 
113
                                        break;
 
114
                                case WP3_COLUMN_TYPE_PARALLEL:
 
115
                                        listener->columnChange(PARALLEL, m_numColumns, m_columnWidth, m_isFixedWidth);
 
116
                                        break;
 
117
                                case WP3_COLUMN_TYPE_EXTENDED:
 
118
                                        listener->columnChange(PARALLEL_PROTECT, m_numColumns, m_columnWidth, m_isFixedWidth);
 
119
                                        break;
 
120
                                default: // something else we don't support, since it isn't in the docs
 
121
                                        break;
 
122
                        }
 
123
                }
 
124
                break;
 
125
        default: // something else we don't support, since it isn't in the docs
 
126
                break;
 
127
        }
 
128
}