ZMF4Parser.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 a part of the libzmf 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 ZMF4PARSER_H_INCLUDED
11#define ZMF4PARSER_H_INCLUDED
12
13#include <librevenge/librevenge.h>
14#include "libzmf_utils.h"
15#include "ZMF4Header.h"
16#include "ZMFCollector.h"
17#include "ZMFTypes.h"
18#include <functional>
19#include <vector>
20#include <map>
21#include <boost/optional.hpp>
22
23 namespace libzmf
24{
25
26 class ZMF4Parser
27{
28 // disable copying
29 ZMF4Parser(const ZMF4Parser &other) = delete;
30 ZMF4Parser &operator=(const ZMF4Parser &other) = delete;
31
32 public:
33 ZMF4Parser(const RVNGInputStreamPtr &input, librevenge::RVNGDrawingInterface *painter);
34 bool parse();
35
36 private:
37 enum class ObjectType
38 {
39 UNKNOWN,
40 FILL,
41 TRANSPARENCY,
42 PEN,
43 SHADOW,
44 ARROW,
45 FONT,
46 PARAGRAPH,
47 TEXT,
48 BITMAP,
49 PAGE_START,
50 GUIDELINES,
51 PAGE_END,
52 LAYER_START,
53 LAYER_END,
54 DOCUMENT_SETTINGS,
55 COLOR_PALETTE,
56 RECTANGLE,
57 ELLIPSE,
58 POLYGON,
59 CURVE,
60 IMAGE,
61 TEXT_FRAME,
62 TABLE,
63 GROUP_START,
64 GROUP_END
65 };
66
67 struct ObjectHeader
68 {
69 ObjectType type;
70 uint32_t size;
71 uint32_t nextObjectOffset;
72 boost::optional<uint32_t> id;
73 uint32_t refObjCount;
74 uint32_t refListStartOffset;
75
76 ObjectHeader()
77 : type()
78 , size(0)
79 , nextObjectOffset(0)
80 , id()
81 , refObjCount(0)
82 , refListStartOffset(0)
83 { }
84 };
85
86 struct ObjectRef
87 {
88 uint32_t id;
89 uint32_t tag;
90 };
91
92 static ObjectType parseObjectType(uint8_t type);
93
94 ObjectHeader readObjectHeader();
95
96 std::vector<ObjectRef> readObjectRefs();
97
98 boost::optional<Fill> getFillByRefId(uint32_t id);
99 boost::optional<Pen> getPenByRefId(uint32_t id);
100 boost::optional<Shadow> getShadowByRefId(uint32_t id);
101 boost::optional<Transparency> getTransparencyByRefId(uint32_t id);
102 boost::optional<Font> getFontByRefId(uint32_t id);
103 boost::optional<ParagraphStyle> getParagraphStyleByRefId(uint32_t id);
104 boost::optional<Text> getTextByRefId(uint32_t id);
105 boost::optional<Image> getImageByRefId(uint32_t id);
106 ArrowPtr getArrowByRefId(uint32_t id);
107
108 Style readStyle();
109
110 Point readPoint();
111 Point readUnscaledPoint();
112
113 BoundingBox readBoundingBox();
114
115 void readCurveSectionTypes(std::vector<CurveType> &sectionTypes);
116 std::vector<Curve> readCurveComponents(std::function<Point()> readPointFunc);
117
118 Color readColor();
119 Gradient readGradient(uint32_t type);
120
121 void readPreviewBitmap();
122
123 void readDocumentSettings();
124 void readPage();
125 void readLayer(const ObjectHeader &layerStartObjHeader);
126
127 void readPen();
128 void readFill();
129 void readTransparency();
130 void readShadow();
131
132 void readArrow();
133
134 void readBitmap();
135
136 void readImage();
137
138 void readFont();
139 void readParagraphStyle();
140 void readText();
141
142 void readTextFrame();
143
144 void readCurve();
145 void readRectangle();
146 void readEllipse();
147 void readPolygon();
148
149 void readTable();
150
151 const RVNGInputStreamPtr m_input;
152 uint32_t m_inputLength;
153
154 ZMFCollector m_collector;
155
156 ZMF4Header m_header;
157
158 ZMFPageSettings m_pageSettings;
159
160 int m_pageNumber;
161
162 ObjectHeader m_currentObjectHeader;
163
164 std::map<uint32_t, Pen> m_pens;
165 std::map<uint32_t, Fill> m_fills;
166 std::map<uint32_t, Transparency> m_transparencies;
167 std::map<uint32_t, Shadow> m_shadows;
168 std::map<uint32_t, ArrowPtr> m_arrows;
169
170 std::map<uint32_t, Image> m_images;
171
172 std::map<uint32_t, Font> m_fonts;
173 std::map<uint32_t, ParagraphStyle> m_paragraphStyles;
174 std::map<uint32_t, Text> m_texts;
175};
176
177}
178
179#endif // ZMF4PARSER_H_INCLUDED
180
181/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
ZMF4Header.h
ZMFCollector.h
ZMFTypes.h
libzmf::ZMF4Header
Definition: ZMF4Header.h:19
libzmf::ZMF4Parser
Definition: ZMF4Parser.h:27
libzmf::ZMF4Parser::readUnscaledPoint
Point readUnscaledPoint()
Definition: ZMF4Parser.cpp:320
libzmf::ZMF4Parser::m_collector
ZMFCollector m_collector
Definition: ZMF4Parser.h:154
libzmf::ZMF4Parser::readArrow
void readArrow()
Definition: ZMF4Parser.cpp:940
libzmf::ZMF4Parser::readEllipse
void readEllipse()
Definition: ZMF4Parser.cpp:1256
libzmf::ZMF4Parser::readPreviewBitmap
void readPreviewBitmap()
Definition: ZMF4Parser.cpp:498
libzmf::ZMF4Parser::m_transparencies
std::map< uint32_t, Transparency > m_transparencies
Definition: ZMF4Parser.h:166
libzmf::ZMF4Parser::readFont
void readFont()
Definition: ZMF4Parser.cpp:1028
libzmf::ZMF4Parser::getFillByRefId
boost::optional< Fill > getFillByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:237
libzmf::ZMF4Parser::readCurveComponents
std::vector< Curve > readCurveComponents(std::function< Point()> readPointFunc)
Definition: ZMF4Parser.cpp:379
libzmf::ZMF4Parser::getImageByRefId
boost::optional< Image > getImageByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:272
libzmf::ZMF4Parser::m_pageNumber
int m_pageNumber
Definition: ZMF4Parser.h:160
libzmf::ZMF4Parser::readCurveSectionTypes
void readCurveSectionTypes(std::vector< CurveType > &sectionTypes)
Definition: ZMF4Parser.cpp:356
libzmf::ZMF4Parser::m_fonts
std::map< uint32_t, Font > m_fonts
Definition: ZMF4Parser.h:172
libzmf::ZMF4Parser::readBoundingBox
BoundingBox readBoundingBox()
Definition: ZMF4Parser.cpp:327
libzmf::ZMF4Parser::m_fills
std::map< uint32_t, Fill > m_fills
Definition: ZMF4Parser.h:165
libzmf::ZMF4Parser::readPoint
Point readPoint()
Definition: ZMF4Parser.cpp:313
libzmf::ZMF4Parser::parseObjectType
static ObjectType parseObjectType(uint8_t type)
Definition: ZMF4Parser.cpp:104
libzmf::ZMF4Parser::m_header
ZMF4Header m_header
Definition: ZMF4Parser.h:156
libzmf::ZMF4Parser::readFill
void readFill()
Definition: ZMF4Parser.cpp:678
libzmf::ZMF4Parser::ObjectType
ObjectType
Definition: ZMF4Parser.h:38
libzmf::ZMF4Parser::ObjectType::CURVE
@ CURVE
libzmf::ZMF4Parser::ObjectType::PAGE_END
@ PAGE_END
libzmf::ZMF4Parser::ObjectType::PARAGRAPH
@ PARAGRAPH
libzmf::ZMF4Parser::ObjectType::DOCUMENT_SETTINGS
@ DOCUMENT_SETTINGS
libzmf::ZMF4Parser::ObjectType::IMAGE
@ IMAGE
libzmf::ZMF4Parser::ObjectType::LAYER_END
@ LAYER_END
libzmf::ZMF4Parser::ObjectType::LAYER_START
@ LAYER_START
libzmf::ZMF4Parser::ObjectType::TABLE
@ TABLE
libzmf::ZMF4Parser::ObjectType::ELLIPSE
@ ELLIPSE
libzmf::ZMF4Parser::ObjectType::FONT
@ FONT
libzmf::ZMF4Parser::ObjectType::GROUP_START
@ GROUP_START
libzmf::ZMF4Parser::ObjectType::GROUP_END
@ GROUP_END
libzmf::ZMF4Parser::ObjectType::TEXT
@ TEXT
libzmf::ZMF4Parser::ObjectType::UNKNOWN
@ UNKNOWN
libzmf::ZMF4Parser::ObjectType::BITMAP
@ BITMAP
libzmf::ZMF4Parser::ObjectType::PAGE_START
@ PAGE_START
libzmf::ZMF4Parser::ObjectType::SHADOW
@ SHADOW
libzmf::ZMF4Parser::ObjectType::COLOR_PALETTE
@ COLOR_PALETTE
libzmf::ZMF4Parser::ObjectType::RECTANGLE
@ RECTANGLE
libzmf::ZMF4Parser::ObjectType::TEXT_FRAME
@ TEXT_FRAME
libzmf::ZMF4Parser::ObjectType::TRANSPARENCY
@ TRANSPARENCY
libzmf::ZMF4Parser::ObjectType::ARROW
@ ARROW
libzmf::ZMF4Parser::ObjectType::PEN
@ PEN
libzmf::ZMF4Parser::ObjectType::GUIDELINES
@ GUIDELINES
libzmf::ZMF4Parser::ObjectType::FILL
@ FILL
libzmf::ZMF4Parser::ObjectType::POLYGON
@ POLYGON
libzmf::ZMF4Parser::readPage
void readPage()
Definition: ZMF4Parser.cpp:533
libzmf::ZMF4Parser::getParagraphStyleByRefId
boost::optional< ParagraphStyle > getParagraphStyleByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:262
libzmf::ZMF4Parser::m_paragraphStyles
std::map< uint32_t, ParagraphStyle > m_paragraphStyles
Definition: ZMF4Parser.h:173
libzmf::ZMF4Parser::readObjectRefs
std::vector< ObjectRef > readObjectRefs()
Definition: ZMF4Parser.cpp:201
libzmf::ZMF4Parser::readPolygon
void readPolygon()
Definition: ZMF4Parser.cpp:1280
libzmf::ZMF4Parser::parse
bool parse()
Definition: ZMF4Parser.cpp:72
libzmf::ZMF4Parser::readStyle
Style readStyle()
Definition: ZMF4Parser.cpp:283
libzmf::ZMF4Parser::readParagraphStyle
void readParagraphStyle()
Definition: ZMF4Parser.cpp:1061
libzmf::ZMF4Parser::getTransparencyByRefId
boost::optional< Transparency > getTransparencyByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:252
libzmf::ZMF4Parser::readGradient
Gradient readGradient(uint32_t type)
Definition: ZMF4Parser.cpp:432
libzmf::ZMF4Parser::m_input
const RVNGInputStreamPtr m_input
Definition: ZMF4Parser.h:151
libzmf::ZMF4Parser::readTable
void readTable()
Definition: ZMF4Parser.cpp:1323
libzmf::ZMF4Parser::readLayer
void readLayer(const ObjectHeader &layerStartObjHeader)
Definition: ZMF4Parser.cpp:594
libzmf::ZMF4Parser::operator=
ZMF4Parser & operator=(const ZMF4Parser &other)=delete
libzmf::ZMF4Parser::readBitmap
void readBitmap()
Definition: ZMF4Parser.cpp:961
libzmf::ZMF4Parser::ZMF4Parser
ZMF4Parser(const ZMF4Parser &other)=delete
libzmf::ZMF4Parser::m_inputLength
uint32_t m_inputLength
Definition: ZMF4Parser.h:152
libzmf::ZMF4Parser::m_arrows
std::map< uint32_t, ArrowPtr > m_arrows
Definition: ZMF4Parser.h:168
libzmf::ZMF4Parser::readCurve
void readCurve()
Definition: ZMF4Parser.cpp:1233
libzmf::ZMF4Parser::getTextByRefId
boost::optional< Text > getTextByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:267
libzmf::ZMF4Parser::m_shadows
std::map< uint32_t, Shadow > m_shadows
Definition: ZMF4Parser.h:167
libzmf::ZMF4Parser::readColor
Color readColor()
Definition: ZMF4Parser.cpp:423
libzmf::ZMF4Parser::getShadowByRefId
boost::optional< Shadow > getShadowByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:247
libzmf::ZMF4Parser::m_texts
std::map< uint32_t, Text > m_texts
Definition: ZMF4Parser.h:174
libzmf::ZMF4Parser::getFontByRefId
boost::optional< Font > getFontByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:257
libzmf::ZMF4Parser::getPenByRefId
boost::optional< Pen > getPenByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:242
libzmf::ZMF4Parser::m_images
std::map< uint32_t, Image > m_images
Definition: ZMF4Parser.h:170
libzmf::ZMF4Parser::readObjectHeader
ObjectHeader readObjectHeader()
Definition: ZMF4Parser.cpp:164
libzmf::ZMF4Parser::getArrowByRefId
ArrowPtr getArrowByRefId(uint32_t id)
Definition: ZMF4Parser.cpp:277
libzmf::ZMF4Parser::readTransparency
void readTransparency()
Definition: ZMF4Parser.cpp:749
libzmf::ZMF4Parser::readPen
void readPen()
Definition: ZMF4Parser.cpp:772
libzmf::ZMF4Parser::m_pageSettings
ZMFPageSettings m_pageSettings
Definition: ZMF4Parser.h:158
libzmf::ZMF4Parser::readShadow
void readShadow()
Definition: ZMF4Parser.cpp:888
libzmf::ZMF4Parser::m_pens
std::map< uint32_t, Pen > m_pens
Definition: ZMF4Parser.h:164
libzmf::ZMF4Parser::readRectangle
void readRectangle()
Definition: ZMF4Parser.cpp:1244
libzmf::ZMF4Parser::m_currentObjectHeader
ObjectHeader m_currentObjectHeader
Definition: ZMF4Parser.h:162
libzmf::ZMF4Parser::readText
void readText()
Definition: ZMF4Parser.cpp:1123
libzmf::ZMF4Parser::readDocumentSettings
void readDocumentSettings()
Definition: ZMF4Parser.cpp:507
libzmf::ZMF4Parser::readTextFrame
void readTextFrame()
Definition: ZMF4Parser.cpp:1196
libzmf::ZMF4Parser::readImage
void readImage()
Definition: ZMF4Parser.cpp:997
libzmf::ZMFCollector
Definition: ZMFCollector.h:22
libzmf_utils.h
libzmf
Definition: BMIHeader.cpp:14
libzmf::ArrowPtr
std::shared_ptr< Arrow > ArrowPtr
Definition: ZMFTypes.h:139
libzmf::RVNGInputStreamPtr
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
Definition: libzmf_utils.h:80
libzmf::BoundingBox
Definition: ZMFTypes.h:47
libzmf::Color
Definition: ZMFTypes.h:98
libzmf::Gradient
Definition: ZMFTypes.h:192
libzmf::Point
Definition: ZMFTypes.h:25
libzmf::Style
Definition: ZMFTypes.h:259
libzmf::ZMF4Parser::ObjectHeader
Definition: ZMF4Parser.h:68
libzmf::ZMF4Parser::ObjectHeader::size
uint32_t size
Definition: ZMF4Parser.h:70
libzmf::ZMF4Parser::ObjectHeader::type
ObjectType type
Definition: ZMF4Parser.h:69
libzmf::ZMF4Parser::ObjectHeader::nextObjectOffset
uint32_t nextObjectOffset
Definition: ZMF4Parser.h:71
libzmf::ZMF4Parser::ObjectHeader::refListStartOffset
uint32_t refListStartOffset
Definition: ZMF4Parser.h:74
libzmf::ZMF4Parser::ObjectHeader::ObjectHeader
ObjectHeader()
Definition: ZMF4Parser.h:76
libzmf::ZMF4Parser::ObjectHeader::id
boost::optional< uint32_t > id
Definition: ZMF4Parser.h:72
libzmf::ZMF4Parser::ObjectHeader::refObjCount
uint32_t refObjCount
Definition: ZMF4Parser.h:73
libzmf::ZMF4Parser::ObjectRef
Definition: ZMF4Parser.h:87
libzmf::ZMF4Parser::ObjectRef::id
uint32_t id
Definition: ZMF4Parser.h:88
libzmf::ZMF4Parser::ObjectRef::tag
uint32_t tag
Definition: ZMF4Parser.h:89
libzmf::ZMFPageSettings
Definition: ZMFTypes.h:390