MSPUBParser.h Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

MSPUBParser.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 libmspub 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 __MSPUBPARSER_H__
11 #define __MSPUBPARSER_H__
12
13 #include <map>
14 #include <set>
15 #include <vector>
16 #include <memory>
17
18 #include <boost/shared_ptr.hpp>
19 #include <boost/optional.hpp>
20
21 #include <librevenge/librevenge.h>
22 #include <librevenge/librevenge.h>
23
24 #include "MSPUBTypes.h"
25 #include "Fill.h"
26 #include "Coordinate.h"
27 #include "PolygonUtils.h"
28
29 namespace libmspub
30 {
31 class MSPUBCollector;
32 class FindBySeqNum
33 {
34 unsigned seqNum;
35 public:
36 FindBySeqNum(unsigned sn) : seqNum(sn) { }
37 bool operator()(const libmspub::ContentChunkReference &ref)
38 {
39 return ref.seqNum == seqNum;
40 }
41 };
42
43 class FindByParentSeqNum
44 {
45 unsigned seqNum;
46 public:
47 FindByParentSeqNum(unsigned sn) : seqNum(sn) { }
48 bool operator()(const libmspub::ContentChunkReference &ref)
49 {
50 return ref.parentSeqNum == seqNum;
51 }
52 };
53
54 struct FOPTValues
55 {
56 std::map<unsigned short, unsigned> m_scalarValues;
57 std::map<unsigned short, std::vector<unsigned char> > m_complexValues;
58 FOPTValues() : m_scalarValues(), m_complexValues()
59 {
60 }
61 };
62
63 class MSPUBParser
64 {
65 public:
66 explicit MSPUBParser(librevenge::RVNGInputStream *input, MSPUBCollector *collector);
67 virtual ~MSPUBParser();
68 virtual bool parse();
69 protected:
70 virtual unsigned getColorIndexByQuillEntry(unsigned entry);
71
72 struct TextSpanReference
73 {
74 TextSpanReference(unsigned short f, unsigned short l, const CharacterStyle &cs) : first(f), last(l), charStyle(cs) { }
75 unsigned short first;
76 unsigned short last;
77 CharacterStyle charStyle;
78 };
79
80 struct TextParagraphReference
81 {
82 TextParagraphReference(unsigned short f, unsigned short l, const ParagraphStyle &ps) : first(f), last(l), paraStyle(ps) { }
83 unsigned short first;
84 unsigned short last;
85 ParagraphStyle paraStyle;
86 };
87
88 typedef std::vector<ContentChunkReference>::const_iterator ccr_iterator_t;
89
90 MSPUBParser();
91 MSPUBParser(const MSPUBParser &);
92 MSPUBParser &operator=(const MSPUBParser &);
93 virtual bool parseContents(librevenge::RVNGInputStream *input);
94 bool parseMetaData(librevenge::RVNGInputStream *input);
95 bool parseQuill(librevenge::RVNGInputStream *input);
96 bool parseEscher(librevenge::RVNGInputStream *input);
97 bool parseEscherDelay(librevenge::RVNGInputStream *input);
98
99 MSPUBBlockInfo parseBlock(librevenge::RVNGInputStream *input, bool skipHierarchicalData = false);
100 EscherContainerInfo parseEscherContainer(librevenge::RVNGInputStream *input);
101
102 bool parseContentChunkReference(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
103 QuillChunkReference parseQuillChunkReference(librevenge::RVNGInputStream *input);
104 bool parseDocumentChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
105 bool parsePageChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
106 bool parsePaletteChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
107 bool parsePageShapeList(librevenge::RVNGInputStream *input, MSPUBBlockInfo block, unsigned pageSeqNum);
108 bool parseShape(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
109 bool parseBorderArtChunk(librevenge::RVNGInputStream *input,
110 const ContentChunkReference &chunk);
111 bool parseFontChunk(librevenge::RVNGInputStream *input,
112 const ContentChunkReference &chunk);
113 void parsePaletteEntry(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
114 void parseColors(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
115 void parseFonts(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
116 void parseDefaultStyle(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
117 void parseShapeGroup(librevenge::RVNGInputStream *input, const EscherContainerInfo &spgr, Coordinate parentCoordinateSystem, Coordinate parentGroupAbsoluteCoord);
118 void skipBlock(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
119 void parseEscherShape(librevenge::RVNGInputStream *input, const EscherContainerInfo &sp, Coordinate &parentCoordinateSystem, Coordinate &parentGroupAbsoluteCoord);
120 bool findEscherContainer(librevenge::RVNGInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, unsigned short type);
121 bool findEscherContainerWithTypeInSet(librevenge::RVNGInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, std::set<unsigned short> types);
122 std::map<unsigned short, unsigned> extractEscherValues(librevenge::RVNGInputStream *input, const EscherContainerInfo &record);
123 FOPTValues extractFOPTValues(librevenge::RVNGInputStream *input,
124 const libmspub::EscherContainerInfo &record);
125 std::vector<TextSpanReference> parseCharacterStyles(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
126 std::vector<TextParagraphReference> parseParagraphStyles(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
127 std::vector<Calculation> parseGuides(const std::vector<unsigned char>
128 &guideData);
129 std::vector<Vertex> parseVertices(const std::vector<unsigned char>
130 &vertexData);
131 std::vector<unsigned> parseTableCellDefinitions(librevenge::RVNGInputStream *input,
132 const QuillChunkReference &chunk);
133 std::vector<unsigned short> parseSegments(
134 const std::vector<unsigned char> &segmentData);
135 DynamicCustomShape getDynamicCustomShape(
136 const std::vector<unsigned char> &vertexData,
137 const std::vector<unsigned char> &segmentData,
138 const std::vector<unsigned char> &guideData,
139 unsigned geoWidth, unsigned geoHeight);
140 int getColorIndex(librevenge::RVNGInputStream *input, const MSPUBBlockInfo &info);
141 unsigned getFontIndex(librevenge::RVNGInputStream *input, const MSPUBBlockInfo &info);
142 CharacterStyle getCharacterStyle(librevenge::RVNGInputStream *input);
143 ParagraphStyle getParagraphStyle(librevenge::RVNGInputStream *input);
144 boost::shared_ptr<Fill> getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg, std::map<unsigned short, std::vector<unsigned char> > &foptVal);
145
146 librevenge::RVNGInputStream *m_input;
147 MSPUBCollector *m_collector;
148 std::vector<MSPUBBlockInfo> m_blockInfo;
149 std::vector<ContentChunkReference> m_contentChunks;
150 std::vector<unsigned> m_cellsChunkIndices;
151 std::vector<unsigned> m_pageChunkIndices;
152 std::vector<unsigned> m_shapeChunkIndices;
153 std::vector<unsigned> m_paletteChunkIndices;
154 std::vector<unsigned> m_borderArtChunkIndices;
155 std::vector<unsigned> m_fontChunkIndices;
156 std::vector<unsigned> m_unknownChunkIndices;
157 boost::optional<unsigned> m_documentChunkIndex;
158 int m_lastSeenSeqNum;
159 unsigned m_lastAddedImage;
160 std::vector<int> m_alternateShapeSeqNums;
161 std::vector<int> m_escherDelayIndices;
162
163 static short getBlockDataLength(unsigned type);
164 static bool isBlockDataString(unsigned type);
165 static PageType getPageTypeBySeqNum(unsigned seqNum);
166 static unsigned getEscherElementTailLength(unsigned short type);
167 static unsigned getEscherElementAdditionalHeaderLength(unsigned short type);
168 static ImgType imgTypeByBlipType(unsigned short type);
169 static int getStartOffset(ImgType type, unsigned short initial);
170 static bool lineExistsByFlagPointer(unsigned *flags,
171 unsigned *geomFlags = NULL);
172 };
173
174 } // namespace libmspub
175
176 #endif // __MSPUBRAPHICS_H__
177 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libmspub::ContentChunkReference::seqNum
unsigned seqNum
Definition: MSPUBTypes.h:74
libmspub::MSPUBParser::m_escherDelayIndices
std::vector< int > m_escherDelayIndices
Definition: MSPUBParser.h:161
Fill.h
PolygonUtils.h
libmspub::DynamicCustomShape
Definition: PolygonUtils.h:91
libmspub::FindByParentSeqNum::operator()
bool operator()(const libmspub::ContentChunkReference &ref)
Definition: MSPUBParser.h:48
libmspub::MSPUBParser::m_borderArtChunkIndices
std::vector< unsigned > m_borderArtChunkIndices
Definition: MSPUBParser.h:154
libmspub::MSPUBBlockInfo
Definition: MSPUBTypes.h:54
libmspub::FOPTValues::FOPTValues
FOPTValues()
Definition: MSPUBParser.h:58
libmspub::MSPUBParser::TextParagraphReference::first
unsigned short first
Definition: MSPUBParser.h:83
libmspub::MSPUBParser::m_collector
MSPUBCollector * m_collector
Definition: MSPUBParser.h:147
libmspub::MSPUBParser::m_fontChunkIndices
std::vector< unsigned > m_fontChunkIndices
Definition: MSPUBParser.h:155
libmspub::MSPUBParser::m_alternateShapeSeqNums
std::vector< int > m_alternateShapeSeqNums
Definition: MSPUBParser.h:160
libmspub::MSPUBParser::m_lastAddedImage
unsigned m_lastAddedImage
Definition: MSPUBParser.h:159
libmspub::MSPUBParser::TextParagraphReference::paraStyle
ParagraphStyle paraStyle
Definition: MSPUBParser.h:85
libmspub::ContentChunkReference
Definition: MSPUBTypes.h:66
libmspub::MSPUBParser::ccr_iterator_t
std::vector< ContentChunkReference >::const_iterator ccr_iterator_t
Definition: MSPUBParser.h:88
libmspub::MSPUBParser::TextParagraphReference::TextParagraphReference
TextParagraphReference(unsigned short f, unsigned short l, const ParagraphStyle &ps)
Definition: MSPUBParser.h:82
libmspub::MSPUBParser::TextSpanReference::charStyle
CharacterStyle charStyle
Definition: MSPUBParser.h:77
libmspub::Coordinate
Definition: Coordinate.h:15
libmspub::MSPUBParser::m_shapeChunkIndices
std::vector< unsigned > m_shapeChunkIndices
Definition: MSPUBParser.h:152
libmspub::ContentChunkReference::parentSeqNum
unsigned parentSeqNum
Definition: MSPUBTypes.h:75
libmspub::MSPUBParser::TextSpanReference::last
unsigned short last
Definition: MSPUBParser.h:76
libmspub::PageType
PageType
Definition: MSPUBTypes.h:172
libmspub::MSPUBParser::TextSpanReference::first
unsigned short first
Definition: MSPUBParser.h:75
libmspub::ImgType
ImgType
Definition: MSPUBTypes.h:179
libmspub::FindBySeqNum
Definition: MSPUBParser.h:32
libmspub::FindBySeqNum::FindBySeqNum
FindBySeqNum(unsigned sn)
Definition: MSPUBParser.h:36
libmspub::MSPUBParser::TextParagraphReference::last
unsigned short last
Definition: MSPUBParser.h:84
libmspub::EscherContainerInfo
Definition: MSPUBTypes.h:46
libmspub::MSPUBParser::TextParagraphReference
Definition: MSPUBParser.h:80
libmspub::FOPTValues::m_scalarValues
std::map< unsigned short, unsigned > m_scalarValues
Definition: MSPUBParser.h:56
libmspub::FOPTValues::m_complexValues
std::map< unsigned short, std::vector< unsigned char > > m_complexValues
Definition: MSPUBParser.h:57
libmspub::ParagraphStyle
Definition: MSPUBTypes.h:129
libmspub
Definition: Arrow.h:13
libmspub::MSPUBParser::m_input
librevenge::RVNGInputStream * m_input
Definition: MSPUBParser.h:146
libmspub::FOPTValues
Definition: MSPUBParser.h:54
libmspub::FindBySeqNum::operator()
bool operator()(const libmspub::ContentChunkReference &ref)
Definition: MSPUBParser.h:37
libmspub::QuillChunkReference
Definition: MSPUBTypes.h:78
libmspub::MSPUBParser::TextSpanReference::TextSpanReference
TextSpanReference(unsigned short f, unsigned short l, const CharacterStyle &cs)
Definition: MSPUBParser.h:74
libmspub::FindByParentSeqNum::FindByParentSeqNum
FindByParentSeqNum(unsigned sn)
Definition: MSPUBParser.h:47
Coordinate.h
libmspub::MSPUBParser::m_cellsChunkIndices
std::vector< unsigned > m_cellsChunkIndices
Definition: MSPUBParser.h:150
libmspub::FindByParentSeqNum::seqNum
unsigned seqNum
Definition: MSPUBParser.h:45
libmspub::CharacterStyle
Definition: MSPUBTypes.h:88
MSPUBTypes.h
libmspub::MSPUBParser::m_documentChunkIndex
boost::optional< unsigned > m_documentChunkIndex
Definition: MSPUBParser.h:157
libmspub::MSPUBCollector
Definition: MSPUBCollector.h:46
libmspub::MSPUBParser
Definition: MSPUBParser.h:63
libmspub::MSPUBParser::m_contentChunks
std::vector< ContentChunkReference > m_contentChunks
Definition: MSPUBParser.h:149
libmspub::MSPUBParser::m_pageChunkIndices
std::vector< unsigned > m_pageChunkIndices
Definition: MSPUBParser.h:151
libmspub::MSPUBParser::m_paletteChunkIndices
std::vector< unsigned > m_paletteChunkIndices
Definition: MSPUBParser.h:153
libmspub::MSPUBParser::TextSpanReference
Definition: MSPUBParser.h:72
libmspub::MSPUBParser::m_lastSeenSeqNum
int m_lastSeenSeqNum
Definition: MSPUBParser.h:158
libmspub::MSPUBParser::m_blockInfo
std::vector< MSPUBBlockInfo > m_blockInfo
Definition: MSPUBParser.h:148
libmspub::MSPUBParser::m_unknownChunkIndices
std::vector< unsigned > m_unknownChunkIndices
Definition: MSPUBParser.h:156
libmspub::FindBySeqNum::seqNum
unsigned seqNum
Definition: MSPUBParser.h:34
libmspub::FindByParentSeqNum
Definition: MSPUBParser.h:43