| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 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 |
|
| 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> §ionTypes); |
| 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 |
| 180 |
|
| 181 |
|