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 <libwpd/libwpd.h>
39 #include <libwpg/libwpg.h>
40 
41 #include "MSPUBTypes.h"
42 #include "Fill.h"
43 #include "Shapes.h"
44 
45 class WPXInputStream;
46 
47 namespace libmspub
48 {
49 class MSPUBCollector;
51 {
52  unsigned seqNum;
53 public:
54  FindBySeqNum(unsigned sn) : seqNum(sn) { }
56  {
57  return ref.seqNum == seqNum;
58  }
59 };
60 
62 {
63  unsigned seqNum;
64 public:
65  FindByParentSeqNum(unsigned sn) : seqNum(sn) { }
67  {
68  return ref.parentSeqNum == seqNum;
69  }
70 };
71 
72 
74 {
75 public:
76  explicit MSPUBParser(WPXInputStream *input, MSPUBCollector *collector);
77  virtual ~MSPUBParser();
78  virtual bool parse();
79 protected:
80  virtual unsigned getColorIndexByQuillEntry(unsigned entry);
81 
83  {
84  TextSpanReference(unsigned short f, unsigned short l, CharacterStyle cs) : first(f), last(l), charStyle(cs) { }
85  unsigned short first;
86  unsigned short last;
88  };
89 
91  {
92  TextParagraphReference(unsigned short f, unsigned short l, ParagraphStyle ps) : first(f), last(l), paraStyle(ps) { }
93  unsigned short first;
94  unsigned short last;
96  };
97 
98  typedef std::vector<ContentChunkReference>::const_iterator ccr_iterator_t;
99 
100  MSPUBParser();
101  MSPUBParser(const MSPUBParser &);
103  virtual bool parseContents(WPXInputStream *input);
104  bool parseQuill(WPXInputStream *input);
105  bool parseEscher(WPXInputStream *input);
106  bool parseEscherDelay(WPXInputStream *input);
107 
108  MSPUBBlockInfo parseBlock(WPXInputStream *input, bool skipHierarchicalData = false);
109  EscherContainerInfo parseEscherContainer(WPXInputStream *input);
110 
111  ContentChunkReference *parseContentChunkReference(WPXInputStream *input, MSPUBBlockInfo block);
112  QuillChunkReference parseQuillChunkReference(WPXInputStream *input);
113  bool parseDocumentChunk(WPXInputStream *input, const ContentChunkReference &chunk);
114  bool parsePageChunk(WPXInputStream *input, const ContentChunkReference &chunk);
115  bool parsePaletteChunk(WPXInputStream *input, const ContentChunkReference &chunk);
116  bool parseShapes(WPXInputStream *input, MSPUBBlockInfo block, unsigned pageSeqNum);
117  bool parseShape(WPXInputStream *input, unsigned seqNum, unsigned pageSeqNum, bool parseWithoutDimensions, bool isGroup);
118  void parsePaletteEntry(WPXInputStream *input, MSPUBBlockInfo block);
119  void parseColors(WPXInputStream *input, const QuillChunkReference &chunk);
120  void parseFonts(WPXInputStream *input, const QuillChunkReference &chunk);
121  void parseDefaultStyle(WPXInputStream *input, const QuillChunkReference &chunk);
122  void parseShapeGroup(WPXInputStream *input, const EscherContainerInfo &spgr, bool topLevel, Coordinate &relativeTo, Coordinate &groupCoord);
123  void skipBlock(WPXInputStream *input, MSPUBBlockInfo block);
124  void parseEscherShape(WPXInputStream *input, const EscherContainerInfo &sp, bool topLevel, Coordinate &relativeTo, Coordinate &groupCoord);
125  bool findEscherContainer(WPXInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, unsigned short type);
126  bool findEscherContainerWithTypeInSet(WPXInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, std::set<unsigned short> types);
127  std::map<unsigned short, unsigned> extractEscherValues(WPXInputStream *input, const EscherContainerInfo &record);
128  std::vector<TextSpanReference> parseCharacterStyles(WPXInputStream *input, const QuillChunkReference &chunk);
129  std::vector<TextParagraphReference> parseParagraphStyles(WPXInputStream *input, const QuillChunkReference &chunk);
130  int getColorIndex(WPXInputStream *input, const MSPUBBlockInfo &info);
131  unsigned getFontIndex(WPXInputStream *input, const MSPUBBlockInfo &info);
132  CharacterStyle getCharacterStyle(WPXInputStream *input, bool inStsh = false);
133  ParagraphStyle getParagraphStyle(WPXInputStream *input);
134  Fill *getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg);
135 
136  WPXInputStream *m_input;
138  std::vector<MSPUBBlockInfo> m_blockInfo;
139  std::vector<ContentChunkReference> m_pageChunks;
140  std::vector<ContentChunkReference> m_shapeChunks;
141  std::vector<ContentChunkReference> m_paletteChunks;
142  std::vector<ContentChunkReference> m_unknownChunks;
147  std::vector<int> m_alternateShapeSeqNums;
148  std::vector<int> m_escherDelayIndices;
149 
150  static short getBlockDataLength(unsigned type);
151  static bool isBlockDataString(unsigned type);
152  static PageType getPageTypeBySeqNum(unsigned seqNum);
153  static unsigned getEscherElementTailLength(unsigned short type);
154  static unsigned getEscherElementAdditionalHeaderLength(unsigned short type);
155  static ImgType imgTypeByBlipType(unsigned short type);
156  static int getStartOffset(ImgType type, unsigned short initial);
157  static bool lineExistsByFlagPointer(unsigned *);
158 };
159 
160 } // namespace libmspub
161 
162 #endif // __MSPUBRAPHICS_H__
163 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.1.2