MSPUBParser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* libmspub
3  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License or as specified alternatively below. You may obtain a copy of
8  * the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * Major Contributor(s):
16  * Copyright (C) 2012 Brennan Vincent <brennanv@email.arizona.edu>
17  * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
18  *
19  * All Rights Reserved.
20  *
21  * For minor contributions see the git repository.
22  *
23  * Alternatively, the contents of this file may be used under the terms of
24  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
25  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
26  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
27  * instead of those above.
28  */
29 
30 #ifndef __MSPUBPARSER_H__
31 #define __MSPUBPARSER_H__
32 
33 #include <map>
34 #include <set>
35 #include <vector>
36 #include <memory>
37 
38 #include <boost/shared_ptr.hpp>
39 #include <boost/optional.hpp>
40 
41 #include <libwpd/libwpd.h>
42 #include <libwpg/libwpg.h>
43 
44 #include "MSPUBTypes.h"
45 #include "Fill.h"
46 #include "Coordinate.h"
47 
48 class WPXInputStream;
49 
50 namespace libmspub
51 {
52 class MSPUBCollector;
54 {
55  unsigned seqNum;
56 public:
57  FindBySeqNum(unsigned sn) : seqNum(sn) { }
59  {
60  return ref.seqNum == seqNum;
61  }
62 };
63 
65 {
66  unsigned seqNum;
67 public:
68  FindByParentSeqNum(unsigned sn) : seqNum(sn) { }
70  {
71  return ref.parentSeqNum == seqNum;
72  }
73 };
74 
75 
77 {
78 public:
79  explicit MSPUBParser(WPXInputStream *input, MSPUBCollector *collector);
80  virtual ~MSPUBParser();
81  virtual bool parse();
82 protected:
83  virtual unsigned getColorIndexByQuillEntry(unsigned entry);
84 
86  {
87  TextSpanReference(unsigned short f, unsigned short l, CharacterStyle cs) : first(f), last(l), charStyle(cs) { }
88  unsigned short first;
89  unsigned short last;
91  };
92 
94  {
95  TextParagraphReference(unsigned short f, unsigned short l, ParagraphStyle ps) : first(f), last(l), paraStyle(ps) { }
96  unsigned short first;
97  unsigned short last;
99  };
100 
101  typedef std::vector<ContentChunkReference>::const_iterator ccr_iterator_t;
102 
103  MSPUBParser();
104  MSPUBParser(const MSPUBParser &);
106  virtual bool parseContents(WPXInputStream *input);
107  bool parseQuill(WPXInputStream *input);
108  bool parseEscher(WPXInputStream *input);
109  bool parseEscherDelay(WPXInputStream *input);
110 
111  MSPUBBlockInfo parseBlock(WPXInputStream *input, bool skipHierarchicalData = false);
112  EscherContainerInfo parseEscherContainer(WPXInputStream *input);
113 
114  bool parseContentChunkReference(WPXInputStream *input, MSPUBBlockInfo block);
115  QuillChunkReference parseQuillChunkReference(WPXInputStream *input);
116  bool parseDocumentChunk(WPXInputStream *input, const ContentChunkReference &chunk);
117  bool parsePageChunk(WPXInputStream *input, const ContentChunkReference &chunk);
118  bool parsePaletteChunk(WPXInputStream *input, const ContentChunkReference &chunk);
119  bool parseShapes(WPXInputStream *input, MSPUBBlockInfo block, unsigned pageSeqNum);
120  bool parseShape(WPXInputStream *input, unsigned seqNum, unsigned pageSeqNum, bool parseWithoutDimensions, bool isGroup);
121  void parsePaletteEntry(WPXInputStream *input, MSPUBBlockInfo block);
122  void parseColors(WPXInputStream *input, const QuillChunkReference &chunk);
123  void parseFonts(WPXInputStream *input, const QuillChunkReference &chunk);
124  void parseDefaultStyle(WPXInputStream *input, const QuillChunkReference &chunk);
125  void parseShapeGroup(WPXInputStream *input, const EscherContainerInfo &spgr, bool topLevel, Coordinate parentCoordinateSystem, Coordinate parentGroupAbsoluteCoord);
126  void skipBlock(WPXInputStream *input, MSPUBBlockInfo block);
127  void parseEscherShape(WPXInputStream *input, const EscherContainerInfo &sp, bool topLevel, Coordinate &parentCoordinateSystem, Coordinate &parentGroupAbsoluteCoord);
128  bool findEscherContainer(WPXInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, unsigned short type);
129  bool findEscherContainerWithTypeInSet(WPXInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, std::set<unsigned short> types);
130  std::map<unsigned short, unsigned> extractEscherValues(WPXInputStream *input, const EscherContainerInfo &record);
131  std::vector<TextSpanReference> parseCharacterStyles(WPXInputStream *input, const QuillChunkReference &chunk);
132  std::vector<TextParagraphReference> parseParagraphStyles(WPXInputStream *input, const QuillChunkReference &chunk);
133  int getColorIndex(WPXInputStream *input, const MSPUBBlockInfo &info);
134  unsigned getFontIndex(WPXInputStream *input, const MSPUBBlockInfo &info);
135  CharacterStyle getCharacterStyle(WPXInputStream *input, bool inStsh = false);
136  ParagraphStyle getParagraphStyle(WPXInputStream *input);
137  boost::shared_ptr<Fill> getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg);
138 
139  WPXInputStream *m_input;
141  std::vector<MSPUBBlockInfo> m_blockInfo;
142  std::vector<ContentChunkReference> m_contentChunks;
143  std::vector<unsigned> m_pageChunkIndices;
144  std::vector<unsigned> m_shapeChunkIndices;
145  std::vector<unsigned> m_paletteChunkIndices;
146  std::vector<unsigned> m_unknownChunkIndices;
147  boost::optional<unsigned> m_documentChunkIndex;
150  std::vector<int> m_alternateShapeSeqNums;
151  std::vector<int> m_escherDelayIndices;
152 
153  static short getBlockDataLength(unsigned type);
154  static bool isBlockDataString(unsigned type);
155  static PageType getPageTypeBySeqNum(unsigned seqNum);
156  static unsigned getEscherElementTailLength(unsigned short type);
157  static unsigned getEscherElementAdditionalHeaderLength(unsigned short type);
158  static ImgType imgTypeByBlipType(unsigned short type);
159  static int getStartOffset(ImgType type, unsigned short initial);
160  static bool lineExistsByFlagPointer(unsigned *);
161 };
162 
163 } // namespace libmspub
164 
165 #endif // __MSPUBRAPHICS_H__
166 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.1.1