From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdvi/bigEndianByteReader.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 kdvi/bigEndianByteReader.cpp (limited to 'kdvi/bigEndianByteReader.cpp') diff --git a/kdvi/bigEndianByteReader.cpp b/kdvi/bigEndianByteReader.cpp new file mode 100644 index 00000000..63d11f83 --- /dev/null +++ b/kdvi/bigEndianByteReader.cpp @@ -0,0 +1,111 @@ +// bigEndianByteReader.cpp +// +// Part of KDVI - A DVI previewer for the KDE desktop environemt +// +// (C) 2003 Stefan Kebekus +// Distributed under the GPL + +#include + +#include + +#include "bigEndianByteReader.h" +#include "dvi.h" + +//#define DEBUG_ENDIANREADER + +Q_UINT8 bigEndianByteReader::readUINT8() +{ + // This check saveguards us against segmentation fault. It is also + // necessary for virtual fonts, which do not end whith EOP. + if (command_pointer >= end_pointer) { +#ifdef DEBUG_ENDIANREADER + kdError(4300) << "bigEndianByteReader::readUINT8() tried to read past end of data chunk" << endl; + kdError(4300) << "end_pointer = " << end_pointer << endl; + kdError(4300) << "command_pointer = " << command_pointer << endl; +#endif + return EOP; + } + + return *(command_pointer++); +} + +Q_UINT16 bigEndianByteReader::readUINT16() +{ + // This check saveguards us against segmentation fault. It is also + // necessary for virtual fonts, which do not end whith EOP. + if (command_pointer >= end_pointer) + return EOP; + + Q_UINT16 a; + a = *(command_pointer++); + a = (a << 8) | *(command_pointer++); + return a; +} + +Q_UINT32 bigEndianByteReader::readUINT32() +{ + // This check saveguards us against segmentation fault. It is also + // necessary for virtual fonts, which do not end whith EOP. + if (command_pointer >= end_pointer) + return EOP; + + Q_UINT32 a; + a = *(command_pointer++); + a = (a << 8) | *(command_pointer++); + a = (a << 8) | *(command_pointer++); + a = (a << 8) | *(command_pointer++); + return a; +} + +void bigEndianByteReader::writeUINT32(Q_UINT32 a) +{ + // This check saveguards us against segmentation fault. It is also + // necessary for virtual fonts, which do not end whith EOP. + if (command_pointer >= end_pointer) + return; + + command_pointer[3] = (Q_UINT8)(a & 0xFF); + a = a >> 8; + command_pointer[2] = (Q_UINT8)(a & 0xFF); + a = a >> 8; + command_pointer[1] = (Q_UINT8)(a & 0xFF); + a = a >> 8; + command_pointer[0] = (Q_UINT8)(a & 0xFF); + + command_pointer += 4; + return; +} + +Q_UINT32 bigEndianByteReader::readUINT(Q_UINT8 size) +{ + // This check saveguards us against segmentation fault. It is also + // necessary for virtual fonts, which do not end whith EOP. + if (command_pointer >= end_pointer) + return EOP; + + Q_UINT32 a = 0; + while (size > 0) { + a = (a << 8) + *(command_pointer++); + size--; + } + return a; +} + +Q_INT32 bigEndianByteReader::readINT(Q_UINT8 length) +{ + // This check saveguards us against segmentation fault. It is also + // necessary for virtual fonts, which do not end whith EOP. + if (command_pointer >= end_pointer) + return EOP; + + Q_INT32 a = *(command_pointer++); + + if (a & 0x80) + a -= 0x100; + + while ((--length) > 0) + a = (a << 8) | *(command_pointer++); + + return a; +} -- cgit v1.2.1