WPGXParser.cpp revision 91934be261c16d036521379306a74b0991720e67
273e421813f295d65aab512f508e8fb575d997d4gouldtj/* libwpg
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
273e421813f295d65aab512f508e8fb575d997d4gouldtj *
273e421813f295d65aab512f508e8fb575d997d4gouldtj * This library is free software; you can redistribute it and/or
273e421813f295d65aab512f508e8fb575d997d4gouldtj * modify it under the terms of the GNU Library General Public
273e421813f295d65aab512f508e8fb575d997d4gouldtj * License as published by the Free Software Foundation; either
273e421813f295d65aab512f508e8fb575d997d4gouldtj * version 2 of the License, or (at your option) any later version.
273e421813f295d65aab512f508e8fb575d997d4gouldtj *
273e421813f295d65aab512f508e8fb575d997d4gouldtj * This library is distributed in the hope that it will be useful,
273e421813f295d65aab512f508e8fb575d997d4gouldtj * but WITHOUT ANY WARRANTY; without even the implied warranty of
273e421813f295d65aab512f508e8fb575d997d4gouldtj * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Library General Public License for more details.
273e421813f295d65aab512f508e8fb575d997d4gouldtj *
273e421813f295d65aab512f508e8fb575d997d4gouldtj * You should have received a copy of the GNU Library General Public
273e421813f295d65aab512f508e8fb575d997d4gouldtj * License along with this library; if not, write to the
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Boston, MA 02111-1301 USA
273e421813f295d65aab512f508e8fb575d997d4gouldtj *
273e421813f295d65aab512f508e8fb575d997d4gouldtj * For further information visit http://libwpg.sourceforge.net
273e421813f295d65aab512f508e8fb575d997d4gouldtj */
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtj/* "This product is not manufactured, approved, or supported by
273e421813f295d65aab512f508e8fb575d997d4gouldtj * Corel Corporation or Corel Corporation Limited."
273e421813f295d65aab512f508e8fb575d997d4gouldtj */
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtj#include "WPGXParser.h"
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjusing namespace libwpg;
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjWPGXParser::WPGXParser(WPGInputStream *input, WPGPaintInterface* painter):
273e421813f295d65aab512f508e8fb575d997d4gouldtj m_input(input), m_painter(painter)
273e421813f295d65aab512f508e8fb575d997d4gouldtj{
273e421813f295d65aab512f508e8fb575d997d4gouldtj}
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjunsigned char WPGXParser::readU8()
273e421813f295d65aab512f508e8fb575d997d4gouldtj{
273e421813f295d65aab512f508e8fb575d997d4gouldtj return m_input->getc();
273e421813f295d65aab512f508e8fb575d997d4gouldtj}
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjunsigned short WPGXParser::readU16()
273e421813f295d65aab512f508e8fb575d997d4gouldtj{
273e421813f295d65aab512f508e8fb575d997d4gouldtj unsigned short p0 = (unsigned short)readU8();
273e421813f295d65aab512f508e8fb575d997d4gouldtj unsigned short p1 = (unsigned short)readU8();
273e421813f295d65aab512f508e8fb575d997d4gouldtj return p0|(p1<<8);
273e421813f295d65aab512f508e8fb575d997d4gouldtj}
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjunsigned long WPGXParser::readU32()
273e421813f295d65aab512f508e8fb575d997d4gouldtj{
273e421813f295d65aab512f508e8fb575d997d4gouldtj unsigned long p0 = (unsigned short)readU8();
273e421813f295d65aab512f508e8fb575d997d4gouldtj unsigned long p1 = (unsigned short)readU8();
273e421813f295d65aab512f508e8fb575d997d4gouldtj unsigned long p2 = (unsigned short)readU8();
273e421813f295d65aab512f508e8fb575d997d4gouldtj unsigned long p3 = (unsigned short)readU8();
273e421813f295d65aab512f508e8fb575d997d4gouldtj return p0|(p1<<8)|(p2<<16)|(p3<<24);
273e421813f295d65aab512f508e8fb575d997d4gouldtj}
273e421813f295d65aab512f508e8fb575d997d4gouldtj
273e421813f295d65aab512f508e8fb575d997d4gouldtjchar WPGXParser::readS8()
273e421813f295d65aab512f508e8fb575d997d4gouldtj{
273e421813f295d65aab512f508e8fb575d997d4gouldtj return (char)m_input->getc();
273e421813f295d65aab512f508e8fb575d997d4gouldtj}
short WPGXParser::readS16()
{
short p0 = readU8();
short p1 = readS8();
return p0|(p1<<8);
}
long WPGXParser::readS32()
{
long p0 = readU8();
long p1 = readU8();
long p2 = readU8();
long p3 = readS8();
return p0|(p1<<8)|(p2<<16)|(p3<<24);
}
unsigned int WPGXParser::readVariableLengthInteger()
{
// read a byte
unsigned char value8 = readU8();
// if it's in the range 0-0xFE, then we have a 8-bit value
if (value8<=0xFE) {
return (unsigned int)value8;
} else {
// now read a 16 bit value
unsigned short value16 = readU16();
// if the MSB is 1, we have a 32 bit value
if (value16>>15) {
// read the next 16 bit value (LSB part, in value16 resides the MSB part)
unsigned long lvalue16 = readU16();
unsigned long value32 = value16 & 0x7fff; // mask out the MSB
return (value32<<16)+lvalue16;
} else {
// we have a 16 bit value, return it
return (unsigned int)value16;
}
}
// unreachable
return 0;
}