blob: 63d11f834e013077e9cb12687c723338a0c3b1b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// bigEndianByteReader.cpp
//
// Part of KDVI - A DVI previewer for the KDE desktop environemt
//
// (C) 2003 Stefan Kebekus
// Distributed under the GPL
#include <config.h>
#include <kdebug.h>
#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;
}
|