CMXParser.h Source File documentation

CMXParser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libcdr project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef __CMXPARSER_H__
11 #define __CMXPARSER_H__
12
13 #include <stdio.h>
14 #include <iostream>
15 #include <vector>
16 #include <map>
17 #include <memory>
18 #include <librevenge-stream/librevenge-stream.h>
19 #include "CDRTypes.h"
20 #include "CommonParser.h"
21
22 #define CMX_MASTER_INDEX_TABLE 1
23 #define CMX_PAGE_INDEX_TABLE 2
24 #define CMX_MASTER_LAYER_TABLE 3
25 #define CMX_PROCEDURE_INDEX_TABLE 4
26 #define CMX_BITMAP_INDEX_TABLE 5
27 #define CMX_ARROW_INDEX_TABLE 6
28 #define CMX_FONT_INDEX_TABLE 7
29 #define CMX_EMBEDDED_FILE_INDEX_TABLE 8
30 #define CMX_THUMBNAIL_SECTION 10
31 #define CMX_OUTLINE_DESCRIPTION_SECTION 15
32 #define CMX_LINE_STYLE_DESCRIPTION_SECTION 16
33 #define CMX_ARROWHEADS_DESCRIPTION_SECTION 17
34 #define CMX_SCREEN_DESCRIPTION_SECTION 18
35 #define CMX_PEN_DESCRIPTION_SECTION 19
36 #define CMX_DOT_DASH_DESCRIPTION_SECTION 20
37 #define CMX_COLOR_DESCRIPTION_SECTION 21
38 #define CMX_COLOR_CORRECTION_SECTION 22
39 #define CMX_PREVIEW_BOX_SECTION 23
40
41 namespace libcdr
42 {
43
44 class CDRCollector;
45
46 struct CMXOutline
47 {
48 CMXOutline()
49 : m_lineStyle(0), m_screen(0), m_color(0),
50 m_arrowHeads(0), m_pen(0), m_dashArray(0) {}
51 unsigned short m_lineStyle;
52 unsigned short m_screen;
53 unsigned short m_color;
54 unsigned short m_arrowHeads;
55 unsigned short m_pen;
56 unsigned short m_dashArray;
57 };
58
59 struct CMXPen
60 {
61 CMXPen()
62 : m_width(0.0), m_aspect(1.0), m_angle(0.0), m_matrix() {}
63 double m_width;
64 double m_aspect;
65 double m_angle;
66 CDRTransform m_matrix;
67 };
68
69 struct CMXLineStyle
70 {
71 CMXLineStyle() : m_spec(0), m_capAndJoin(0) {}
72 unsigned char m_spec;
73 unsigned char m_capAndJoin;
74 };
75
76 struct CMXImageInfo
77 {
78 CMXImageInfo()
79 : m_type(0), m_compression(0), m_size(0), m_compressedSize(0) {}
80 unsigned short m_type;
81 unsigned short m_compression;
82 unsigned m_size;
83 unsigned m_compressedSize;
84 };
85
86 struct CMXParserState
87 {
88 CMXParserState()
89 : m_colorPalette(), m_dashArrays(), m_lineStyles(),
90 m_pens(), m_outlines(), m_bitmapOffsets(), m_patternOffsets(),
91 m_arrowOffsets(), m_embeddedOffsets(), m_embeddedOffsetTypes() {}
92 std::map<unsigned, CDRColor> m_colorPalette;
93 std::map<unsigned, std::vector<unsigned> > m_dashArrays;
94 std::map<unsigned, CMXLineStyle> m_lineStyles;
95 std::map<unsigned, CMXPen> m_pens;
96 std::map<unsigned, CMXOutline> m_outlines;
97 std::map<unsigned, unsigned> m_bitmapOffsets;
98 std::map<unsigned, unsigned> m_patternOffsets;
99 std::map<unsigned, unsigned> m_arrowOffsets;
100 std::map<unsigned, unsigned> m_embeddedOffsets;
101 std::map<unsigned, unsigned> m_embeddedOffsetTypes;
102 };
103
104 class CMXParser : protected CommonParser
105 {
106 public:
107 explicit CMXParser(CDRCollector *collector, CMXParserState &parserState);
108 ~CMXParser() override;
109 bool parseRecords(librevenge::RVNGInputStream *input, long size = -1, unsigned level = 0);
110
111 private:
112 CMXParser();
113 CMXParser(const CMXParser &);
114 CMXParser &operator=(const CMXParser &);
115 bool parseRecord(librevenge::RVNGInputStream *input, unsigned level = 0);
116 void readRecord(unsigned fourCC, unsigned &length, librevenge::RVNGInputStream *input);
117 void parseImage(librevenge::RVNGInputStream *input);
118
119 void readCMXHeader(librevenge::RVNGInputStream *input);
120 void readDisp(librevenge::RVNGInputStream *input);
121 void readPage(librevenge::RVNGInputStream *input);
122 void readProc(librevenge::RVNGInputStream *input);
123 void readRclr(librevenge::RVNGInputStream *input);
124 void readRotl(librevenge::RVNGInputStream *input);
125 void readRott(librevenge::RVNGInputStream *input);
126 void readRdot(librevenge::RVNGInputStream *input);
127 void readRpen(librevenge::RVNGInputStream *input);
128 void readIxtl(librevenge::RVNGInputStream *input);
129 void readIxef(librevenge::RVNGInputStream *input);
130 void readIxmr(librevenge::RVNGInputStream *input);
131 void readIxpg(librevenge::RVNGInputStream *input);
132 void readIxpc(librevenge::RVNGInputStream *input);
133 void readInfo(librevenge::RVNGInputStream *input);
134 void readData(librevenge::RVNGInputStream *input);
135
136 // Command readers
137 void readCommands(librevenge::RVNGInputStream *input, unsigned length);
138 void readBeginPage(librevenge::RVNGInputStream *input);
139 void readBeginLayer(librevenge::RVNGInputStream *input);
140 void readBeginGroup(librevenge::RVNGInputStream *input);
141 void readPolyCurve(librevenge::RVNGInputStream *input);
142 void readEllipse(librevenge::RVNGInputStream *input);
143 void readRectangle(librevenge::RVNGInputStream *input);
144 void readJumpAbsolute(librevenge::RVNGInputStream *input);
145 void readDrawImage(librevenge::RVNGInputStream *input);
146 void readBeginProcedure(librevenge::RVNGInputStream *input);
147
148 // Types readers
149 CDRTransform readMatrix(librevenge::RVNGInputStream *input);
150 CDRBox readBBox(librevenge::RVNGInputStream *input);
151 librevenge::RVNGString readString(librevenge::RVNGInputStream *input);
152 bool readFill(librevenge::RVNGInputStream *input);
153 bool readLens(librevenge::RVNGInputStream *input);
154
155 // Complex types readers
156 bool readRenderingAttributes(librevenge::RVNGInputStream *input);
157
158 // Helper Functions
159 CDRColor getPaletteColor(unsigned id);
160 CDRColor readColor(librevenge::RVNGInputStream *input, unsigned char colorModel);
161 CDRLineStyle getLineStyle(unsigned id);
162 const unsigned *_getOffsetByType(unsigned short type, const std::map<unsigned short, unsigned> &offsets);
163
164 bool m_bigEndian;
165 unsigned short m_unit;
166 double m_scale;
167 double m_xmin, m_xmax, m_ymin, m_ymax;
168 unsigned m_fillIndex;
169 unsigned m_nextInstructionOffset;
170 CMXParserState &m_parserState;
171 CMXImageInfo m_currentImageInfo;
172 std::unique_ptr<CDRPattern> m_currentPattern;
173 std::unique_ptr<CDRBitmap> m_currentBitmap;
174 };
175
176 } // namespace libcdr
177
178 #endif // __CMXPARSER_H__
179 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libcdr::CMXParser::readRotl
void readRotl(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1837
libcdr::CMXOutline::CMXOutline
CMXOutline()
Definition: CMXParser.h:48
libcdr::CMXParserState
Definition: CMXParser.h:86
libcdr::CommonParser
Definition: CommonParser.h:22
libcdr::CMXLineStyle::CMXLineStyle
CMXLineStyle()
Definition: CMXParser.h:71
libcdr::CMXImageInfo
Definition: CMXParser.h:76
libcdr::CMXParser::readBeginPage
void readBeginPage(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:489
libcdr::CMXParser::m_nextInstructionOffset
unsigned m_nextInstructionOffset
Definition: CMXParser.h:169
libcdr::CMXParser::readIxpg
void readIxpg(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:2030
libcdr::CMXParser::readRclr
void readRclr(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1682
libcdr::CMXParser::readData
void readData(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:2143
libcdr::CMXPen::m_aspect
double m_aspect
Definition: CMXParser.h:64
libcdr::CMXParser::~CMXParser
~CMXParser() override
Definition: CMXParser.cpp:77
libcdr::CMXParser::m_xmax
double m_xmax
Definition: CMXParser.h:167
libcdr::CMXParserState::CMXParserState
CMXParserState()
Definition: CMXParser.h:88
libcdr::CDRBox
Definition: CDRTypes.h:23
libcdr::CMXPen::CMXPen
CMXPen()
Definition: CMXParser.h:61
libcdr::CMXParser::m_currentBitmap
std::unique_ptr< CDRBitmap > m_currentBitmap
Definition: CMXParser.h:173
libcdr::CMXPen::m_matrix
CDRTransform m_matrix
Definition: CMXParser.h:66
libcdr::CMXImageInfo::m_compressedSize
unsigned m_compressedSize
Definition: CMXParser.h:83
libcdr::CMXPen
Definition: CMXParser.h:59
libcdr::CMXLineStyle::m_spec
unsigned char m_spec
Definition: CMXParser.h:72
libcdr::CMXParserState::m_embeddedOffsets
std::map< unsigned, unsigned > m_embeddedOffsets
Definition: CMXParser.h:100
libcdr::CMXParser::readRott
void readRott(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1788
libcdr::CMXParser::readPolyCurve
void readPolyCurve(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:588
libcdr::CMXParser::parseImage
void parseImage(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:149
libcdr::CMXLineStyle::m_capAndJoin
unsigned char m_capAndJoin
Definition: CMXParser.h:73
libcdr::CDRTransform
Definition: CDRTransforms.h:21
libcdr::CMXParser::operator=
CMXParser & operator=(const CMXParser &)
libcdr::CMXParser::readString
librevenge::RVNGString readString(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1005
libcdr::CMXParser::readRecord
void readRecord(unsigned fourCC, unsigned &length, librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:189
libcdr::CMXParser::readIxef
void readIxef(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1993
libcdr::CMXParserState::m_colorPalette
std::map< unsigned, CDRColor > m_colorPalette
Definition: CMXParser.h:92
libcdr::CMXOutline::m_arrowHeads
unsigned short m_arrowHeads
Definition: CMXParser.h:54
libcdr::CMXParser::m_unit
unsigned short m_unit
Definition: CMXParser.h:165
libcdr::CMXParser::m_currentPattern
std::unique_ptr< CDRPattern > m_currentPattern
Definition: CMXParser.h:172
libcdr::CMXParserState::m_patternOffsets
std::map< unsigned, unsigned > m_patternOffsets
Definition: CMXParser.h:98
libcdr::CMXParser
Definition: CMXParser.h:104
libcdr::CMXParser::readLens
bool readLens(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1016
libcdr::CMXPen::m_width
double m_width
Definition: CMXParser.h:63
libcdr::CMXParserState::m_outlines
std::map< unsigned, CMXOutline > m_outlines
Definition: CMXParser.h:96
libcdr::CMXParser::m_bigEndian
bool m_bigEndian
Definition: CMXParser.h:164
libcdr::CMXParser::m_parserState
CMXParserState & m_parserState
Definition: CMXParser.h:170
libcdr::CMXParserState::m_arrowOffsets
std::map< unsigned, unsigned > m_arrowOffsets
Definition: CMXParser.h:99
libcdr::CMXParser::m_currentImageInfo
CMXImageInfo m_currentImageInfo
Definition: CMXParser.h:171
libcdr
Definition: CDRCollector.h:29
libcdr::CMXOutline::m_dashArray
unsigned short m_dashArray
Definition: CMXParser.h:56
libcdr::CMXParser::readBeginProcedure
void readBeginProcedure(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:918
libcdr::CMXParser::readJumpAbsolute
void readJumpAbsolute(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1648
libcdr::CMXOutline
Definition: CMXParser.h:46
libcdr::CMXParser::m_ymin
double m_ymin
Definition: CMXParser.h:167
libcdr::CMXParser::readInfo
void readInfo(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:2102
libcdr::CMXParser::readRpen
void readRpen(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1894
libcdr::CMXParser::parseRecords
bool parseRecords(librevenge::RVNGInputStream *input, long size=-1, unsigned level=0)
Definition: CMXParser.cpp:81
libcdr::CMXOutline::m_pen
unsigned short m_pen
Definition: CMXParser.h:55
libcdr::CMXParser::readPage
void readPage(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:469
CommonParser.h
libcdr::CMXParser::readEllipse
void readEllipse(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:663
libcdr::CMXParserState::m_pens
std::map< unsigned, CMXPen > m_pens
Definition: CMXParser.h:95
libcdr::CMXParser::m_ymax
double m_ymax
Definition: CMXParser.h:167
libcdr::CMXOutline::m_lineStyle
unsigned short m_lineStyle
Definition: CMXParser.h:51
libcdr::CMXParserState::m_dashArrays
std::map< unsigned, std::vector< unsigned > > m_dashArrays
Definition: CMXParser.h:93
libcdr::CMXParser::readFill
bool readFill(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1060
libcdr::CMXParser::m_fillIndex
unsigned m_fillIndex
Definition: CMXParser.h:168
libcdr::CMXOutline::m_color
unsigned short m_color
Definition: CMXParser.h:53
libcdr::CMXParser::readProc
void readProc(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:479
libcdr::CMXParser::readMatrix
CDRTransform readMatrix(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:965
libcdr::CMXParser::_getOffsetByType
const unsigned * _getOffsetByType(unsigned short type, const std::map< unsigned short, unsigned > &offsets)
Definition: CMXParser.cpp:335
libcdr::CMXParser::readRectangle
void readRectangle(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:829
libcdr::CMXParser::readBeginGroup
void readBeginGroup(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:541
libcdr::CMXParser::readBBox
CDRBox readBBox(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:995
libcdr::CMXParser::readIxtl
void readIxtl(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1948
libcdr::CMXImageInfo::m_size
unsigned m_size
Definition: CMXParser.h:82
libcdr::CMXParser::CMXParser
CMXParser()
libcdr::CMXParserState::m_embeddedOffsetTypes
std::map< unsigned, unsigned > m_embeddedOffsetTypes
Definition: CMXParser.h:101
libcdr::CMXParser::parseRecord
bool parseRecord(librevenge::RVNGInputStream *input, unsigned level=0)
Definition: CMXParser.cpp:99
libcdr::CMXImageInfo::m_compression
unsigned short m_compression
Definition: CMXParser.h:81
libcdr::CMXParser::readBeginLayer
void readBeginLayer(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:538
libcdr::CMXParserState::m_lineStyles
std::map< unsigned, CMXLineStyle > m_lineStyles
Definition: CMXParser.h:94
libcdr::CMXParser::m_scale
double m_scale
Definition: CMXParser.h:166
libcdr::CMXImageInfo::CMXImageInfo
CMXImageInfo()
Definition: CMXParser.h:78
CDRTypes.h
libcdr::CDRLineStyle
Definition: CDRTypes.h:112
libcdr::CMXParser::m_xmin
double m_xmin
Definition: CMXParser.h:167
libcdr::CMXImageInfo::m_type
unsigned short m_type
Definition: CMXParser.h:80
libcdr::CMXParser::readDrawImage
void readDrawImage(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:768
libcdr::CMXParser::getLineStyle
CDRLineStyle getLineStyle(unsigned id)
Definition: CMXParser.cpp:2338
libcdr::CMXParser::readDisp
void readDisp(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:286
libcdr::CMXParser::readRdot
void readRdot(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1733
libcdr::CDRColor
Definition: CDRTypes.h:52
libcdr::CMXPen::m_angle
double m_angle
Definition: CMXParser.h:65
libcdr::CMXParser::readCMXHeader
void readCMXHeader(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:210
libcdr::CMXParser::readColor
CDRColor readColor(librevenge::RVNGInputStream *input, unsigned char colorModel)
Definition: CMXParser.cpp:2219
libcdr::CMXParser::readIxpc
void readIxpc(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:2065
libcdr::CMXParser::readCommands
void readCommands(librevenge::RVNGInputStream *input, unsigned length)
Definition: CMXParser.cpp:415
libcdr::CMXLineStyle
Definition: CMXParser.h:69
libcdr::CMXOutline::m_screen
unsigned short m_screen
Definition: CMXParser.h:52
libcdr::CMXParser::getPaletteColor
CDRColor getPaletteColor(unsigned id)
Definition: CMXParser.cpp:2211
libcdr::CDRCollector
Definition: CDRCollector.h:63
libcdr::CMXParser::readIxmr
void readIxmr(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:343
libcdr::CMXParser::readRenderingAttributes
bool readRenderingAttributes(librevenge::RVNGInputStream *input)
Definition: CMXParser.cpp:1475
libcdr::CMXParserState::m_bitmapOffsets
std::map< unsigned, unsigned > m_bitmapOffsets
Definition: CMXParser.h:97