summaryrefslogtreecommitdiff
path: root/Build/source/libs/graphite/src/segment/FileInput.h
blob: f8c32b762ebf262d58c62f68289a8d83bcd32bfc (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
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: FileInput.h
Responsibility: Sharon Correll
Last reviewed: not yet

Description:
    Defines utility functions for reading from a font file.
----------------------------------------------------------------------------------------------*/

#ifdef _MSC_VER
#pragma once
#endif
#ifndef FILEINPUT_INCLUDED
#define FILEINPUT_INCLUDED

//:End Ignore

namespace gr
{

int swapb(int nArg);
unsigned int swapb(unsigned int nArg);
utf16 swapb(utf16 chwArg);
short swapb(short snArg);

//	Most significant byte first (converting from least-sig-first):
inline int msbf(int nArg)					{ return swapb(nArg); }
inline unsigned int msbf(unsigned int nArg)	{ return swapb(nArg); }
inline utf16 msbf(utf16 chwArg)				{ return swapb(chwArg); }
inline short msbf(short chwArg)				{ return swapb(chwArg); }

//	Least significant byte first (converting from most-sig first):
inline int lsbf(int nArg)					{ return swapb(nArg); }
inline unsigned int lsbf(unsigned int nArg)	{ return swapb(nArg); };
inline utf16 lsbf(utf16 chwArg)				{ return swapb(chwArg); }
inline short lsbf(short chwArg)				{ return swapb(chwArg); }

class GrIStream
{
public:
	virtual void Close() = 0;

	virtual byte ReadByteFromFont() = 0;
	virtual short ReadShortFromFont() = 0;
	virtual utf16 ReadUShortFromFont() = 0;
	virtual int ReadIntFromFont() = 0;
	virtual void ReadBlockFromFont(void * pvInput, int cb) = 0;

	virtual void GetPositionInFont(long * plPos) = 0;
	virtual void SetPositionInFont(long lPos) = 0;

	virtual bool OpenBuffer(byte * pbBuffer, int cb) = 0;
	virtual void CloseBuffer() = 0;

protected:
    virtual ~GrIStream() {}
};


/*----------------------------------------------------------------------------------------------
	A stream that reads from a buffer rather than a file.
----------------------------------------------------------------------------------------------*/
class GrBufferIStream : public GrIStream
{
public:
	GrBufferIStream();
	~GrBufferIStream();

	#ifdef GR_FW
	virtual bool Open(std::wstring stuFileName, std::ios::openmode kMode);
	#else
	virtual bool Open(const char * pcFileName, std::ios::openmode kMode);
	#endif
	virtual void Close();

	virtual byte ReadByteFromFont();
	virtual short ReadShortFromFont();
	virtual utf16 ReadUShortFromFont();
	virtual int ReadIntFromFont();
	virtual void ReadBlockFromFont(void * pvInput, int cb);

	virtual void GetPositionInFont(long * plPos);
	virtual void SetPositionInFont(long lPos);

	virtual bool OpenBuffer(byte * pbBuffer, int cb);
	virtual void CloseBuffer()
	{
		Close();
	}

protected:
	byte * m_pbStart;
	byte * m_pbNext;
	byte * m_pbLim;
};

} // namespace gr

#endif // !FILEINPUT_INCLUDED