MSPUBCollector.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 __MSPUBCOLLECTOR_H__
31 #define __MSPUBCOLLECTOR_H__
32 
33 #include <list>
34 #include <vector>
35 #include <map>
36 #include <set>
37 #include <string>
38 #include <algorithm>
39 #include <cmath>
40 
41 #include <boost/ptr_container/ptr_map.hpp>
42 #include <boost/ptr_container/ptr_vector.hpp>
43 
44 #include <libwpd/libwpd.h>
45 #include <libwpg/libwpg.h>
46 
47 #include "MSPUBTypes.h"
48 #include "libmspub_utils.h"
49 #include "MSPUBContentChunkType.h"
50 #include "ShapeType.h"
51 #include "Fill.h"
52 #include "ColorReference.h"
53 #include "PolygonUtils.h"
54 #include "Shapes.h"
55 #include "ShapeGroupPainter.h"
56 #include "ShapeGroup.h"
57 
58 #define PI 3.14159265
59 
60 namespace libmspub
61 {
63 {
64  //TODO Refactor this class to avoid relying on a list of friend declarations
65  friend struct Shape;
66  friend struct GeometricShape;
67  friend struct FillableShape;
68  friend class ShapeGroupPainter;
69  friend class Fill;
70  friend class ImgFill;
71  friend class SolidFill;
72  friend class GradientFill;
73  friend class PatternFill;
74 public:
75  typedef std::list<ContentChunkReference>::const_iterator ccr_iterator_t;
76 
77  MSPUBCollector(::libwpg::WPGPaintInterface *painter);
78  virtual ~MSPUBCollector();
79 
80  // collector functions
81  bool addPage(unsigned seqNum);
82  bool addTextString(const std::vector<TextParagraph> &str, unsigned id);
83  bool addTextShape(unsigned stringId, unsigned seqNum, unsigned pageSeqNum);
84  bool addImage(unsigned index, ImgType type, WPXBinaryData img);
85  bool addShape(unsigned seqNum);
86  bool setShapePage(unsigned seqNum, unsigned pageSeqNum);
87 
88  bool setShapeType(unsigned seqNum, ShapeType type);
89  bool setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
90  bool setShapeImgIndex(unsigned seqNum, unsigned index);
91  bool setShapeFill(unsigned seqNum, Fill *fill, bool skipIfNotBg);
92  bool setAdjustValue(unsigned seqNum, unsigned index, int adjust);
93  bool setShapeRotation(unsigned seqNum, double rotation);
94  bool setShapeFlip(unsigned, bool, bool);
95  bool setShapeMargins(unsigned seqNum, unsigned left, unsigned top, unsigned right, unsigned bottom);
96  bool setShapeBorderPosition(unsigned seqNum, BorderPosition pos);
97 
98  void beginGroup();
99  bool endGroup();
100 
101  void addShapeLine(unsigned seqNum, Line line);
102  void setShapeOrder(unsigned seqNum);
103  void setPageBgShape(unsigned pageSeqNum, unsigned seqNum);
104  void setWidthInEmu(unsigned long);
105  void setHeightInEmu(unsigned long);
106 
108  void addFont(std::vector<unsigned char> name);
109 
110  void addDefaultCharacterStyle(const CharacterStyle &style);
111  void addDefaultParagraphStyle(const ParagraphStyle &style);
112  void addPaletteColor(Color);
113  bool setCurrentGroupSeqNum(unsigned seqNum);
114 
115  bool go();
116 
117  bool hasPage(unsigned seqNum) const;
118 private:
119 
120  struct PageInfo
121  {
122  std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
124  };
125 
126  struct Margins
127  {
128  Margins(unsigned left, unsigned top, unsigned right, unsigned bottom) :
129  m_left(left), m_top(top), m_right(right), m_bottom(bottom) { }
131  };
132 
135 
136  libwpg::WPGPaintInterface *m_painter;
137  std::list<ContentChunkReference> m_contentChunkReferences;
138  double m_width, m_height;
140  unsigned short m_numPages;
141  std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
142  std::map<unsigned, PageInfo> m_pagesBySeqNum;
143  boost::ptr_map<unsigned, Shape> m_shapesBySeqNum; // boost::ptr_map is used instead of std::map to support Shape polymorphism
144  std::vector<std::pair<ImgType, WPXBinaryData> > m_images;
145  std::vector<ColorReference> m_textColors;
146  std::vector<std::vector<unsigned char> > m_fonts;
147  std::vector<CharacterStyle> m_defaultCharStyles;
148  std::vector<ParagraphStyle> m_defaultParaStyles;
149  std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
150  std::vector<unsigned> m_possibleImageShapeSeqNums;
151  std::map<unsigned, unsigned> m_shapeImgIndicesBySeqNum;
152  std::map<unsigned, Coordinate> m_shapeCoordinatesBySeqNum;
153  std::map<unsigned, std::vector<Line> > m_shapeLinesBySeqNum;
154  boost::ptr_map<unsigned, Fill> m_shapeFillsBySeqNum;
155  std::vector<Color> m_paletteColors;
156  std::vector<unsigned> m_shapeSeqNumsOrdered;
157  std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
158  std::map<unsigned, std::pair<unsigned, unsigned> > m_textInfoBySeqNum;
159  std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
160  std::set<unsigned> m_skipIfNotBgSeqNums;
161  std::map<unsigned, std::map<unsigned, int> > m_adjustValuesByIndexBySeqNum;
162  std::map<unsigned, double> m_shapeRotationsBySeqNum;
163  std::map<unsigned, std::pair<bool, bool> > m_shapeFlipsBySeqNum;
164  std::map<unsigned, Margins> m_shapeMarginsBySeqNum;
165  // BorderPositions are irrelevant except for rectangular shapes.
166  std::map<unsigned, BorderPosition> m_shapeBorderPositionsBySeqNum;
168  boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
169  std::map<unsigned, ShapeGroup *> m_groupsBySeqNum;
170 
171  // helper functions
172  void assignImages();
173  void assignGroups();
174  void setRectCoordProps(Coordinate, WPXPropertyList *);
175  WPXPropertyList getCharStyleProps(const CharacterStyle &, unsigned defaultCharStyleIndex);
176  WPXPropertyList getParaStyleProps(const ParagraphStyle &, unsigned defaultParaStyleIndex);
177 public:
178  static WPXString getColorString(const Color &);
179 };
180 } // namespace libmspub
181 
182 #endif /* __MSPUBCOLLECTOR_H__ */
183 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.1.2