Code

Cleaned up virtual destructor problem and compile warnings.
[inkscape.git] / src / extension / internal / libwpg / WPGHeader.cpp
1 /* libwpg
2  * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
3  * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the 
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
18  * Boston, MA  02111-1301 USA
19  *
20  * For further information visit http://libwpg.sourceforge.net
21  */
23 /* "This product is not manufactured, approved, or supported by
24  * Corel Corporation or Corel Corporation Limited."
25  */
27 #include "WPGHeader.h"
28 #include "libwpg_utils.h"
30 namespace
31 {
32 static inline unsigned short readU16( const void* p )
33 {
34         const unsigned char* ptr = (const unsigned char*) p;
35         return ptr[0]+(ptr[1]<<8);
36 }
38 static inline unsigned long readU32( const void* p )
39 {
40         const unsigned char* ptr = (const unsigned char*) p;
41         return ptr[0]+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
42 }
43 }
45 using namespace libwpg;
47 WPGHeader::WPGHeader()
48 {
49                 // create a sensible default header
50                 m_identifier[0] = 0xff;
51                 m_identifier[1] = 'W'; 
52                 m_identifier[2] = 'P'; 
53                 m_identifier[3] = 'C'; 
54                 m_productType = 0x01;
55                 m_fileType = 0x16;
56                 m_encryptionKey = 0x00;
57                 m_majorVersion = 0x02;
58                 m_minorVersion = 0x00;
59                 m_encryptionKey = 0;
60                 m_startOfPacketData = 0;
61                 m_entryCount = 0;
62                 m_resourceComplete = 0;
63                 m_encryptionBlockOffset = 0;
64                 m_fileSize = 0;
65                 m_encryptVersion = 0;
66 }
68 bool WPGHeader::load(WPGInputStream *input)
69 {
70         input->seek(0);
71         
72         unsigned char prefix[26];
73         long n = input->read(26, (char*)prefix);
74         if(n < 26)
75                 return false;
76         
77         m_identifier[0] = prefix[0];  
78         m_identifier[1] = prefix[1];  
79         m_identifier[2] = prefix[2];  
80         m_identifier[3] = prefix[3];  
81         m_startOfDocument = readU32(prefix+4);
82         m_productType = prefix[8];
83         m_fileType = prefix[9];
84         m_majorVersion = prefix[10];
85         m_minorVersion = prefix[11];
86         m_encryptionKey = readU16(prefix+12);
87         m_startOfPacketData = readU16(prefix+14);
88         
89         WPG_DEBUG_MSG(("Header Identifier  = %c%c%c\n", m_identifier[1], 
90         m_identifier[2], m_identifier[3]));
91         WPG_DEBUG_MSG(("Product type       = 0x%x\n",  m_productType));
92         WPG_DEBUG_MSG(("File type          = 0x%x\n",  m_fileType));
93         WPG_DEBUG_MSG(("Major version      = 0x%x\n",  m_majorVersion));
94         WPG_DEBUG_MSG(("Minor version      = 0x%x\n",  m_minorVersion));
95         WPG_DEBUG_MSG(("Encryption key     = 0x%x\n",  m_encryptionKey));
96         
97         return true;
98 }
100 bool WPGHeader::isSupported() const
102         return (
103                 (m_identifier[0] == 0xFF) &&
104                 (m_identifier[1] == 'W') &&
105                 (m_identifier[2] == 'P') &&
106                 (m_identifier[3] == 'C') &&
107                 (m_productType == 0x01) &&
108                 (m_fileType == 0x16) &&
109                 (m_encryptionKey == 0x00) &&     // we don't support encryption
110                 ((m_majorVersion == 0x02) || (m_majorVersion == 0x01)) &&
111                 (m_minorVersion == 0x00) 
112 );
115 unsigned long WPGHeader::startOfDocument() const
117         return m_startOfDocument;
120 int WPGHeader::majorVersion() const
122         return m_majorVersion;