summaryrefslogtreecommitdiffstats
path: root/fbreader/src/formats/doc/DocFloatImageReader.h
blob: d2d6c2e94819b75e60b1ed825fb765f210010b73 (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
/*
 * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

#ifndef __DOCFLOATIMAGEREADER_H__
#define __DOCFLOATIMAGEREADER_H__

#include <ZLFileImage.h>

class DocFloatImageReader {

public:
	struct BlipStoreEntry { // see p.68 [MS-ODRAW]
		unsigned int size; // size of blip in stream
		unsigned int referenceCount; // (cRef) reference count for the the blip
		unsigned int offsetInDelay; // foDelay, file offset in the delay stream
	};

	struct Blip { //see p.59, p63-66 [MS-ODRAW]
		BlipStoreEntry storeEntry;
		unsigned int type;
		ZLFileImage::Blocks blocks;
	};

	struct FSP { //see p.76-77 [MS-ODRAW]
		unsigned int shapeId; //spid
	};

	struct FOPTE { //see p.98 and p.32 [MS-ODRAW]
		unsigned int pId; //pid
		bool isBlipId; //fBid
		bool isComplex; //fComplex
		unsigned int value; //op
	};

	struct FSPContainer { //see p.53-55 [MS-ODRAW]
		FSP fsp;
		std::vector<FOPTE> fopte;
	};

	struct OfficeArtContent { //see p.405-406 [MS-DOC]
		std::vector<Blip> blips; //retrieved from OfficeArtDggContainer
		std::vector<FSPContainer> FSPs; //retrieved from OfficeArtDgContainer
	};

	struct RecordHeader { //see p.26 [MS-ODRAW]
		unsigned int version;
		unsigned int instance;
		unsigned int type;
		unsigned int length;
	};

public:
	DocFloatImageReader(unsigned int off, unsigned int len, shared_ptr<OleStream> tableStream, shared_ptr<OleStream> mainStream);

public:
	void readAll();

	ZLFileImage::Blocks getBlocksForShapeId(unsigned int shapeId) const;

private:
	static unsigned int readRecordHeader(RecordHeader &header, shared_ptr<OleStream> stream);
	static unsigned int readDggContainer(OfficeArtContent &item, unsigned int length, shared_ptr<OleStream> stream, shared_ptr<OleStream> mainStream);

	static unsigned int readBStoreContainer(OfficeArtContent &item, unsigned int length, shared_ptr<OleStream> stream, shared_ptr<OleStream> mainStream);
	static unsigned int readBStoreContainerFileBlock(Blip &blip, shared_ptr<OleStream> stream, shared_ptr<OleStream> mainStream);
	static unsigned int readBlip(Blip &blip, const RecordHeader &header, shared_ptr<OleStream> stream);
	static unsigned int readFBSE(BlipStoreEntry &fbse, shared_ptr<OleStream> stream);

	static unsigned int readFOPTE(FOPTE &fopte, shared_ptr<OleStream> stream);
	static unsigned int readArrayFOPTE(std::vector<FOPTE> &fopte, unsigned int length, shared_ptr<OleStream> stream);
	static unsigned int readFSP(FSP &fsp, shared_ptr<OleStream> stream);
	static unsigned int readSpContainter(FSPContainer &item, unsigned int length, shared_ptr<OleStream> stream);
	static unsigned int readSpgrContainer(OfficeArtContent &item, unsigned int length, shared_ptr<OleStream> stream);
	static unsigned int readDgContainer(OfficeArtContent &item,  unsigned int length, shared_ptr<OleStream> stream);

	static unsigned int skipRecord(const RecordHeader &header, shared_ptr<OleStream> stream);

	static unsigned int read1Byte(shared_ptr<OleStream> stream);
	static unsigned int read2Bytes(shared_ptr<OleStream> stream);
	static unsigned int read4Bytes(shared_ptr<OleStream> stream);

private:
	shared_ptr<OleStream> myTableStream;
	shared_ptr<OleStream> myMainStream;
	unsigned int myOffset;
	unsigned int myLength;

	OfficeArtContent myItem;
};

#endif /* __DOCFLOATIMAGEREADER_H__ */