Code

Cleaned up virtual destructor problem and compile warnings.
[inkscape.git] / src / extension / internal / libwpg / WPGXParser.cpp
1 /* libwpg\r
2  * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)\r
3  * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)\r
4  * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)\r
5  *\r
6  * This library is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU Library General Public\r
8  * License as published by the Free Software Foundation; either\r
9  * version 2 of the License, or (at your option) any later version.\r
10  *\r
11  * This library is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
14  * Library General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU Library General Public\r
17  * License along with this library; if not, write to the \r
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, \r
19  * Boston, MA  02111-1301 USA\r
20  *\r
21  * For further information visit http://libwpg.sourceforge.net\r
22  */\r
23  \r
24 /* "This product is not manufactured, approved, or supported by\r
25  * Corel Corporation or Corel Corporation Limited."\r
26  */\r
27 \r
28 #include "WPGXParser.h"\r
29 \r
30 using namespace libwpg;\r
31 \r
32 WPGXParser::WPGXParser(WPGInputStream *input, WPGPaintInterface* painter):\r
33   m_input(input), m_painter(painter)\r
34 {\r
35 }\r
36 \r
37 unsigned char WPGXParser::readU8()\r
38 {\r
39         return m_input->getc();\r
40 }\r
41 \r
42 unsigned short WPGXParser::readU16()\r
43 {\r
44         unsigned short p0 = (unsigned short)readU8();\r
45         unsigned short p1 = (unsigned short)readU8();\r
46         return p0|(p1<<8);\r
47 }\r
48 \r
49 unsigned long WPGXParser::readU32()\r
50 {\r
51         unsigned long p0 = (unsigned short)readU8();\r
52         unsigned long p1 = (unsigned short)readU8();\r
53         unsigned long p2 = (unsigned short)readU8();\r
54         unsigned long p3 = (unsigned short)readU8();\r
55         return p0|(p1<<8)|(p2<<16)|(p3<<24);\r
56 }\r
57 \r
58 char WPGXParser::readS8()\r
59 {\r
60         return (char)m_input->getc();\r
61 }\r
62 \r
63 short WPGXParser::readS16()\r
64 {\r
65         short p0 = readU8();\r
66         short p1 = readS8();\r
67         return p0|(p1<<8);\r
68 }\r
69 \r
70 long WPGXParser::readS32()\r
71 {\r
72         long p0 = readU8();\r
73         long p1 = readU8();\r
74         long p2 = readU8();\r
75         long p3 = readS8();\r
76         return p0|(p1<<8)|(p2<<16)|(p3<<24);\r
77 }\r
78 \r
79 unsigned int WPGXParser::readVariableLengthInteger()\r
80 {\r
81         // read a byte\r
82         unsigned char value8 = readU8();\r
83         // if it's in the range 0-0xFE, then we have a 8-bit value\r
84         if (value8<=0xFE) {\r
85                 return (unsigned int)value8;\r
86         } else {\r
87                 // now read a 16 bit value\r
88                 unsigned short value16 = readU16();\r
89                 // if the MSB is 1, we have a 32 bit value\r
90                 if (value16>>15) {\r
91                         // read the next 16 bit value (LSB part, in value16 resides the MSB part)\r
92                         unsigned long lvalue16 = readU16();\r
93                         unsigned long value32 = value16 & 0x7fff;  // mask out the MSB\r
94                         return (value32<<16)+lvalue16;\r
95                 } else {\r
96                         // we have a 16 bit value, return it\r
97                         return (unsigned int)value16;\r
98                 }\r
99         }\r
100         \r
101         // unreachable\r
102         return 0;\r
103 }\r