File indexing completed on 2024-05-12 16:06:35
0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*- 0002 // bigEndianByteReader.cpp 0003 // 0004 // Part of KDVI - A DVI previewer for the KDE desktop environment 0005 // 0006 // SPDX-FileCopyrightText: 2003 Stefan Kebekus 0007 // SPDX-License-Identifier: GPL-2.0-or-later 0008 0009 #include <config.h> 0010 0011 #include "bigEndianByteReader.h" 0012 #include "debug_dvi.h" 0013 #include "dvi.h" 0014 0015 //#define DEBUG_ENDIANREADER 0016 0017 quint8 bigEndianByteReader::readUINT8() 0018 { 0019 // This check saveguards us against segmentation fault. It is also 0020 // necessary for virtual fonts, which do not end with EOP. 0021 if (command_pointer >= end_pointer) { 0022 #ifdef DEBUG_ENDIANREADER 0023 qCCritical(OkularDviDebug) << "bigEndianByteReader::readUINT8() tried to read past end of data chunk"; 0024 qCCritical(OkularDviDebug) << "end_pointer = " << end_pointer; 0025 qCCritical(OkularDviDebug) << "command_pointer = " << command_pointer; 0026 #endif 0027 return EOP; 0028 } 0029 0030 return *(command_pointer++); 0031 } 0032 0033 quint16 bigEndianByteReader::readUINT16() 0034 { 0035 // This check saveguards us against segmentation fault. It is also 0036 // necessary for virtual fonts, which do not end with EOP. 0037 if (command_pointer >= end_pointer) { 0038 return EOP; 0039 } 0040 0041 quint16 a; 0042 a = *(command_pointer++); 0043 a = (a << 8) | *(command_pointer++); 0044 return a; 0045 } 0046 0047 quint32 bigEndianByteReader::readUINT32() 0048 { 0049 // This check saveguards us against segmentation fault. It is also 0050 // necessary for virtual fonts, which do not end with EOP. 0051 if (command_pointer >= end_pointer) { 0052 return EOP; 0053 } 0054 0055 quint32 a; 0056 a = *(command_pointer++); 0057 a = (a << 8) | *(command_pointer++); 0058 a = (a << 8) | *(command_pointer++); 0059 a = (a << 8) | *(command_pointer++); 0060 return a; 0061 } 0062 0063 void bigEndianByteReader::writeUINT32(quint32 a) 0064 { 0065 // This check saveguards us against segmentation fault. It is also 0066 // necessary for virtual fonts, which do not end with EOP. 0067 if (command_pointer >= end_pointer) { 0068 return; 0069 } 0070 0071 command_pointer[3] = (quint8)(a & 0xFF); 0072 a = a >> 8; 0073 command_pointer[2] = (quint8)(a & 0xFF); 0074 a = a >> 8; 0075 command_pointer[1] = (quint8)(a & 0xFF); 0076 a = a >> 8; 0077 command_pointer[0] = (quint8)(a & 0xFF); 0078 0079 command_pointer += 4; 0080 return; 0081 } 0082 0083 quint32 bigEndianByteReader::readUINT(quint8 size) 0084 { 0085 // This check saveguards us against segmentation fault. It is also 0086 // necessary for virtual fonts, which do not end with EOP. 0087 if (command_pointer >= end_pointer) { 0088 return EOP; 0089 } 0090 0091 quint32 a = 0; 0092 while (size > 0) { 0093 a = (a << 8) + *(command_pointer++); 0094 size--; 0095 } 0096 return a; 0097 } 0098 0099 qint32 bigEndianByteReader::readINT(quint8 length) 0100 { 0101 // This check saveguards us against segmentation fault. It is also 0102 // necessary for virtual fonts, which do not end with EOP. 0103 if (command_pointer >= end_pointer) { 0104 return EOP; 0105 } 0106 0107 qint32 a = *(command_pointer++); 0108 0109 if (a & 0x80) { 0110 a -= 0x100; 0111 } 0112 0113 while ((--length) > 0) { 0114 a = (a << 8) | *(command_pointer++); 0115 } 0116 0117 return a; 0118 }