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 
40 #include <boost/ptr_container/ptr_map.hpp>
41 #include <boost/ptr_container/ptr_vector.hpp>
42 #include <boost/bind.hpp>
43 #include <boost/function.hpp>
44 
45 #include <libwpd/libwpd.h>
46 #include <libwpg/libwpg.h>
47 
48 #include "MSPUBTypes.h"
49 #include "libmspub_utils.h"
50 #include "MSPUBContentChunkType.h"
51 #include "ShapeType.h"
52 #include "Coordinate.h"
53 #include "ShapeGroupElement.h"
54 #include "Fill.h"
55 #include "ColorReference.h"
56 #include "PolygonUtils.h"
57 #include "ShapeInfo.h"
58 
59 namespace libmspub
60 {
62 {
63  friend class Fill;
64  friend class ImgFill;
65  friend class SolidFill;
66  friend class GradientFill;
67  friend class PatternFill;
68 public:
69  typedef std::list<ContentChunkReference>::const_iterator ccr_iterator_t;
70 
71  MSPUBCollector(::libwpg::WPGPaintInterface *painter);
72  virtual ~MSPUBCollector();
73 
74  // collector functions
75  bool addPage(unsigned seqNum);
76  bool addTextString(const std::vector<TextParagraph> &str, unsigned id);
77  void addTextShape(unsigned stringId, unsigned seqNum, unsigned pageSeqNum);
78  bool addImage(unsigned index, ImgType type, WPXBinaryData img);
79  bool addShape(unsigned seqNum);
80  void setShapePage(unsigned seqNum, unsigned pageSeqNum);
81 
82  void setShapeType(unsigned seqNum, ShapeType type);
83  void setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
84  void setShapeImgIndex(unsigned seqNum, unsigned index);
85  void setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool skipIfNotBg);
86  void setAdjustValue(unsigned seqNum, unsigned index, int adjust);
87  void setShapeRotation(unsigned seqNum, double rotation);
88  void setShapeFlip(unsigned, bool, bool);
89  void setShapeMargins(unsigned seqNum, unsigned left, unsigned top, unsigned right, unsigned bottom);
90  void setShapeBorderPosition(unsigned seqNum, BorderPosition pos);
91  void setShapeCoordinatesRotated90(unsigned seqNum);
92 
93  void beginGroup();
94  bool endGroup();
95 
96  void addShapeLine(unsigned seqNum, Line line);
97  void setShapeOrder(unsigned seqNum);
98  void setPageBgShape(unsigned pageSeqNum, unsigned seqNum);
99  void setWidthInEmu(unsigned long);
100  void setHeightInEmu(unsigned long);
101 
103  void addFont(std::vector<unsigned char> name);
104 
105  void addDefaultCharacterStyle(const CharacterStyle &style);
106  void addDefaultParagraphStyle(const ParagraphStyle &style);
107  void addPaletteColor(Color);
108  bool setCurrentGroupSeqNum(unsigned seqNum);
109 
110  bool go();
111 
112  bool hasPage(unsigned seqNum) const;
113 private:
114 
115  struct PageInfo
116  {
117  std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
119  };
120 
123 
124  libwpg::WPGPaintInterface *m_painter;
125  std::list<ContentChunkReference> m_contentChunkReferences;
126  double m_width, m_height;
128  unsigned short m_numPages;
129  std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
130  std::map<unsigned, PageInfo> m_pagesBySeqNum;
131  std::vector<std::pair<ImgType, WPXBinaryData> > m_images;
132  std::vector<ColorReference> m_textColors;
133  std::vector<std::vector<unsigned char> > m_fonts;
134  std::vector<CharacterStyle> m_defaultCharStyles;
135  std::vector<ParagraphStyle> m_defaultParaStyles;
136  std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
137  std::vector<unsigned> m_possibleImageShapeSeqNums;
138  std::vector<Color> m_paletteColors;
139  std::vector<unsigned> m_shapeSeqNumsOrdered;
140  std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
141  std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
142  std::set<unsigned> m_skipIfNotBgSeqNums;
144  boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
145  std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum;
146  std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum;
148  mutable std::vector<bool> m_calculationValuesSeen;
149  // helper functions
150  std::vector<int> getShapeAdjustValues(const ShapeInfo &info) const;
151  void setRectCoordProps(Coordinate, WPXPropertyList *) const;
152  boost::optional<std::vector<libmspub::TextParagraph> > getShapeText(const ShapeInfo &info) const;
155  void assignShapesToPages();
156  void writePage(unsigned pageSeqNum, const PageInfo &pageInfo) const;
157  boost::function<void(void)> paintShape(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform) const;
158  double getCalculationValue(const ShapeInfo &info, unsigned index, bool recursiveEntry, const std::vector<int> &adjustValues) const;
159 
160  WPXPropertyList getCharStyleProps(const CharacterStyle &, unsigned defaultCharStyleIndex) const;
161  WPXPropertyList getParaStyleProps(const ParagraphStyle &, unsigned defaultParaStyleIndex) const;
162  double getSpecialValue(const ShapeInfo &info, const CustomShape &shape, int arg, const std::vector<int> &adjustValues) const;
163 public:
164  static WPXString getColorString(const Color &);
165 };
166 } // namespace libmspub
167 
168 #endif /* __MSPUBCOLLECTOR_H__ */
169 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.1.2