~ubuntu-branches/ubuntu/gutsy/libwpd/gutsy

« back to all changes in this revision

Viewing changes to src/lib/WP1FixedLengthGroup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2006-10-24 12:14:42 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061024121442-z8c0itk65vgwmu3g
Tags: 0.8.7-4
update debian/copyright, mmh... 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libwpd
 
2
 * Copyright (C) 2003 William Lachance (wrlach@gmail.com)
 
3
 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
 
4
 * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
 
5
 *  
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
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 "WP1FixedLengthGroup.h"
 
28
#include "WP1SuppressPageCharacteristicsGroup.h"
 
29
#include "WP1UnsupportedFixedLengthGroup.h"
 
30
#include "WP1MarginResetGroup.h"
 
31
#include "WP1MarginReleaseGroup.h"
 
32
#include "WP1TopMarginGroup.h"
 
33
#include "WP1BottomMarginGroup.h"
 
34
#include "WP1ExtendedCharacterGroup.h"
 
35
#include "WP1PointSizeGroup.h"
 
36
#include "WP1LeftIndentGroup.h"
 
37
#include "WP1LeftRightIndentGroup.h"
 
38
#include "WP1JustificationGroup.h"
 
39
#include "WP1SpacingResetGroup.h"
 
40
#include "WP1CenterTextGroup.h"
 
41
#include "WP1FlushRightGroup.h"
 
42
#include "WP1FileStructure.h"
 
43
#include "libwpd_internal.h"
 
44
 
 
45
WP1FixedLengthGroup::WP1FixedLengthGroup(uint8_t group)
 
46
        : m_group(group)
 
47
{
 
48
}
 
49
 
 
50
WP1FixedLengthGroup * WP1FixedLengthGroup::constructFixedLengthGroup(WPXInputStream *input, uint8_t group)
 
51
{
 
52
        switch (group)
 
53
        {
 
54
                case WP1_MARGIN_RESET_GROUP:
 
55
                        return new WP1MarginResetGroup(input, group);
 
56
                case WP1_TOP_MARGIN_SET_GROUP:
 
57
                        return new WP1TopMarginGroup(input, group);
 
58
                case WP1_BOTTOM_MARGIN_SET_GROUP:
 
59
                        return new WP1BottomMarginGroup(input, group);
 
60
                case WP1_LEFT_INDENT_GROUP:
 
61
                        return new WP1LeftIndentGroup(input, group);
 
62
                case WP1_SUPPRESS_PAGE_CHARACTERISTICS_GROUP:
 
63
                        return new WP1SuppressPageCharacteristicsGroup(input, group);
 
64
                case WP1_LEFT_RIGHT_INDENT_GROUP:
 
65
                        return new WP1LeftRightIndentGroup(input, group);
 
66
                case WP1_MARGIN_RELEASE_GROUP:
 
67
                        return new WP1MarginReleaseGroup(input, group);
 
68
                case WP1_CENTER_TEXT_GROUP:
 
69
                        return new WP1CenterTextGroup(input, group);
 
70
                case WP1_FLUSH_RIGHT_GROUP:
 
71
                        return new WP1FlushRightGroup(input, group);
 
72
                case WP1_EXTENDED_CHARACTER_GROUP:
 
73
                        return new WP1ExtendedCharacterGroup(input, group);
 
74
                case WP1_POINT_SIZE_GROUP:
 
75
                        return new WP1PointSizeGroup(input, group);
 
76
                case WP1_JUSTIFICATION_GROUP:
 
77
                        return new WP1JustificationGroup(input, group);
 
78
                case WP1_SPACING_RESET_GROUP:
 
79
                        return new WP1SpacingResetGroup(input, group);
 
80
                default:
 
81
                        // this is an unhandled group, just skip it
 
82
                        return new WP1UnsupportedFixedLengthGroup(input, group);
 
83
        }
 
84
}
 
85
 
 
86
bool WP1FixedLengthGroup::isGroupConsistent(WPXInputStream *input, const uint8_t groupID)
 
87
{
 
88
        uint32_t startPosition = input->tell();
 
89
 
 
90
        try
 
91
        {
 
92
                int size = WP1_FUNCTION_GROUP_SIZE[groupID-0xC0];
 
93
                if (input->seek((startPosition + size - 2 - input->tell()), WPX_SEEK_CUR) || input->atEOS())
 
94
                {
 
95
                        input->seek(startPosition, WPX_SEEK_SET);
 
96
                        return false;
 
97
                }
 
98
                if (groupID != readU8(input))
 
99
                {
 
100
                        input->seek(startPosition, WPX_SEEK_SET);
 
101
                        return false;
 
102
                }
 
103
                
 
104
                input->seek(startPosition, WPX_SEEK_SET);
 
105
                return true;
 
106
        }
 
107
        catch(...)
 
108
        {
 
109
                input->seek(startPosition, WPX_SEEK_SET);
 
110
                return false;
 
111
        }
 
112
}
 
113
 
 
114
void WP1FixedLengthGroup::_read(WPXInputStream *input)
 
115
{
 
116
        uint32_t startPosition = input->tell();
 
117
        
 
118
        if (m_group >= 0xC0 && m_group <= 0xFE) // just an extra safety check
 
119
        {
 
120
                int size = WP1_FUNCTION_GROUP_SIZE[m_group-0xC0];
 
121
                if (size == -1)
 
122
                        return;
 
123
 
 
124
                _readContents(input);
 
125
 
 
126
                input->seek((startPosition + size - 2 - input->tell()), WPX_SEEK_CUR);
 
127
                if (m_group != readU8(input))
 
128
                {
 
129
                        WPD_DEBUG_MSG(("WordPerfect: Possible corruption detected. Bailing out!\n"));
 
130
                        throw FileException();
 
131
                }
 
132
        }
 
133
        else
 
134
                throw FileException();
 
135
}