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;
33 {
34  unsigned seqNum;
35 public:
36  FindBySeqNum(unsigned sn) : seqNum(sn) { }
38  {
39  return ref.seqNum == seqNum;
40  }
41 };
42 
44 {
45  unsigned seqNum;
46 public:
47  FindByParentSeqNum(unsigned sn) : seqNum(sn) { }
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;
59  {
60  }
61 };
62 
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 
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;
78  };
79 
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;
86  };
87 
88  typedef std::vector<ContentChunkReference>::const_iterator ccr_iterator_t;
89 
90  MSPUBParser();
91  MSPUBParser(const MSPUBParser &);
93  virtual bool parseContents(librevenge::RVNGInputStream *input);
94  bool parseQuill(librevenge::RVNGInputStream *input);
95  bool parseEscher(librevenge::RVNGInputStream *input);
96  bool parseEscherDelay(librevenge::RVNGInputStream *input);
97 
98  MSPUBBlockInfo parseBlock(librevenge::RVNGInputStream *input, bool skipHierarchicalData = false);
99  EscherContainerInfo parseEscherContainer(librevenge::RVNGInputStream *input);
100 
101  bool parseContentChunkReference(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
102  QuillChunkReference parseQuillChunkReference(librevenge::RVNGInputStream *input);
103  bool parseDocumentChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
104  bool parsePageChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
105  bool parsePaletteChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
106  bool parsePageShapeList(librevenge::RVNGInputStream *input, MSPUBBlockInfo block, unsigned pageSeqNum);
107  bool parseShape(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
108  bool parseBorderArtChunk(librevenge::RVNGInputStream *input,
109  const ContentChunkReference &chunk);
110  bool parseFontChunk(librevenge::RVNGInputStream *input,
111  const ContentChunkReference &chunk);
112  void parsePaletteEntry(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
113  void parseColors(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
114  void parseFonts(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
115  void parseDefaultStyle(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
116  void parseShapeGroup(librevenge::RVNGInputStream *input, const EscherContainerInfo &spgr, Coordinate parentCoordinateSystem, Coordinate parentGroupAbsoluteCoord);
117  void skipBlock(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
118  void parseEscherShape(librevenge::RVNGInputStream *input, const EscherContainerInfo &sp, Coordinate &parentCoordinateSystem, Coordinate &parentGroupAbsoluteCoord);
119  bool findEscherContainer(librevenge::RVNGInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, unsigned short type);
120  bool findEscherContainerWithTypeInSet(librevenge::RVNGInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, std::set<unsigned short> types);
121  std::map<unsigned short, unsigned> extractEscherValues(librevenge::RVNGInputStream *input, const EscherContainerInfo &record);
122  FOPTValues extractFOPTValues(librevenge::RVNGInputStream *input,
123  const libmspub::EscherContainerInfo &record);
124  std::vector<TextSpanReference> parseCharacterStyles(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
125  std::vector<TextParagraphReference> parseParagraphStyles(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
126  std::vector<Calculation> parseGuides(const std::vector<unsigned char>
127  &guideData);
128  std::vector<Vertex> parseVertices(const std::vector<unsigned char>
129  &vertexData);
130  std::vector<unsigned> parseTableCellDefinitions(librevenge::RVNGInputStream *input,
131  const QuillChunkReference &chunk);
132  std::vector<unsigned short> parseSegments(
133  const std::vector<unsigned char> &segmentData);
135  const std::vector<unsigned char> &vertexData,
136  const std::vector<unsigned char> &segmentData,
137  const std::vector<unsigned char> &guideData,
138  unsigned geoWidth, unsigned geoHeight);
139  int getColorIndex(librevenge::RVNGInputStream *input, const MSPUBBlockInfo &info);
140  unsigned getFontIndex(librevenge::RVNGInputStream *input, const MSPUBBlockInfo &info);
141  CharacterStyle getCharacterStyle(librevenge::RVNGInputStream *input);
142  ParagraphStyle getParagraphStyle(librevenge::RVNGInputStream *input);
143  boost::shared_ptr<Fill> getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg, std::map<unsigned short, std::vector<unsigned char> > &foptVal);
144 
145  librevenge::RVNGInputStream *m_input;
147  std::vector<MSPUBBlockInfo> m_blockInfo;
148  std::vector<ContentChunkReference> m_contentChunks;
149  std::vector<unsigned> m_cellsChunkIndices;
150  std::vector<unsigned> m_pageChunkIndices;
151  std::vector<unsigned> m_shapeChunkIndices;
152  std::vector<unsigned> m_paletteChunkIndices;
153  std::vector<unsigned> m_borderArtChunkIndices;
154  std::vector<unsigned> m_fontChunkIndices;
155  std::vector<unsigned> m_unknownChunkIndices;
156  boost::optional<unsigned> m_documentChunkIndex;
159  std::vector<int> m_alternateShapeSeqNums;
160  std::vector<int> m_escherDelayIndices;
161 
162  static short getBlockDataLength(unsigned type);
163  static bool isBlockDataString(unsigned type);
164  static PageType getPageTypeBySeqNum(unsigned seqNum);
165  static unsigned getEscherElementTailLength(unsigned short type);
166  static unsigned getEscherElementAdditionalHeaderLength(unsigned short type);
167  static ImgType imgTypeByBlipType(unsigned short type);
168  static int getStartOffset(ImgType type, unsigned short initial);
169  static bool lineExistsByFlagPointer(unsigned *flags,
170  unsigned *geomFlags = NULL);
171 };
172 
173 } // namespace libmspub
174 
175 #endif // __MSPUBRAPHICS_H__
176 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.4