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-2013 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 #include "BorderArtInfo.h"
59 #include "Dash.h"
60 #include "Arrow.h"
61 #include "VerticalAlign.h"
62 #include "EmbeddedFontInfo.h"
63 #include "Shadow.h"
64 
65 namespace libmspub
66 {
68 {
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  void addTextShape(unsigned stringId, unsigned seqNum);
84  bool addImage(unsigned index, ImgType type, WPXBinaryData img);
85  void setBorderImageOffset(unsigned index, unsigned offset);
86  WPXBinaryData *addBorderImage(ImgType type, unsigned borderArtIndex);
87  void setShapePage(unsigned seqNum, unsigned pageSeqNum);
88 
89  void setNextPage(unsigned seqNum);
90 
91  void setShapeType(unsigned seqNum, ShapeType type);
92  void setShapePictureRecolor(unsigned seqNum, const ColorReference &recolor);
93  void setShapeTableInfo(unsigned seqNum, const TableInfo &ti);
94  void setShapeBorderImageId(unsigned seqNum, unsigned borderImageId);
95  void setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
96  void setShapeImgIndex(unsigned seqNum, unsigned index);
97  void setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool skipIfNotBg);
98  void setShapeDash(unsigned seqNum, const Dash &dash);
99  void setAdjustValue(unsigned seqNum, unsigned index, int adjust);
100  void setShapeRotation(unsigned seqNum, double rotation);
101  void setShapeFlip(unsigned, bool, bool);
102  void setShapeMargins(unsigned seqNum, unsigned left, unsigned top, unsigned right, unsigned bottom);
103  void setShapeBorderPosition(unsigned seqNum, BorderPosition pos);
104  void setShapeCoordinatesRotated90(unsigned seqNum);
105  void setShapeCustomPath(unsigned seqNum,
106  const DynamicCustomShape &shape);
107  void setShapeVerticalTextAlign(unsigned seqNum, VerticalAlign va);
108  void designateMasterPage(unsigned seqNum);
109  void setMasterPage(unsigned pageSeqNum, unsigned masterSeqNum);
110  void setShapeStretchBorderArt(unsigned seqNum);
111  void setShapeShadow(unsigned seqNum, const Shadow &shadow);
112 
113  // Microsoft "Embedded OpenType" ... need to figure out how to convert
114  // this to a sane format and how to get LibreOffice to understand embedded fonts.
115  WPXBinaryData &addEOTFont(const WPXString &name);
116 
117  void beginGroup();
118  bool endGroup();
119 
120  void setShapeLineBackColor(unsigned seqNum, ColorReference backColor);
121  void addShapeLine(unsigned seqNum, Line line);
122  void setShapeOrder(unsigned seqNum);
123  void setPageBgShape(unsigned pageSeqNum, unsigned seqNum);
124  void setWidthInEmu(unsigned long);
125  void setHeightInEmu(unsigned long);
126  void setShapeNumColumns(unsigned seqNum, unsigned numColumns);
127  void setShapeColumnSpacing(unsigned seqNum, unsigned spacing);
128  void setShapeBeginArrow(unsigned seqNum, const Arrow &arrow);
129  void setShapeEndArrow(unsigned seqNum, const Arrow &arrow);
130 
132  void addFont(std::vector<unsigned char> name);
133 
134  void addDefaultCharacterStyle(const CharacterStyle &style);
135  void addDefaultParagraphStyle(const ParagraphStyle &style);
136  void addPaletteColor(Color);
137  bool setCurrentGroupSeqNum(unsigned seqNum);
138 
139  void useEncodingHeuristic();
140 
141  void setNextTableCellTextEnds(const std::vector<unsigned> &ends);
142  void setTextStringOffset(unsigned textId, unsigned offset);
143 
144  bool go();
145 
146  bool hasPage(unsigned seqNum) const;
147 private:
148 
149  struct PageInfo
150  {
151  std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
153  };
154 
157 
158  libwpg::WPGPaintInterface *m_painter;
159  std::list<ContentChunkReference> m_contentChunkReferences;
160  double m_width, m_height;
162  unsigned short m_numPages;
163  std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
164  std::map<unsigned, PageInfo> m_pagesBySeqNum;
165  std::vector<std::pair<ImgType, WPXBinaryData> > m_images;
166  std::vector<BorderArtInfo> m_borderImages;
167  std::vector<ColorReference> m_textColors;
168  std::vector<std::vector<unsigned char> > m_fonts;
169  std::vector<CharacterStyle> m_defaultCharStyles;
170  std::vector<ParagraphStyle> m_defaultParaStyles;
171  std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
172  std::vector<Color> m_paletteColors;
173  std::vector<unsigned> m_shapeSeqNumsOrdered;
174  std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
175  std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
176  std::set<unsigned> m_skipIfNotBgSeqNums;
178  boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
179  std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum;
180  std::list<EmbeddedFontInfo> m_embeddedFonts;
181  std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum;
182  std::set<unsigned> m_masterPages;
184  std::map<unsigned, unsigned> m_masterPagesByPageSeqNum;
185  std::vector<std::vector<unsigned> > m_tableCellTextEndsVector;
186  std::map<unsigned, unsigned> m_stringOffsetsByTextId;
187  mutable std::vector<bool> m_calculationValuesSeen;
188  std::vector<unsigned> m_pageSeqNumsOrdered;
190  std::vector<unsigned char> m_allText;
191  mutable boost::optional<const char *> m_calculatedEncoding;
192  // helper functions
193  std::vector<int> getShapeAdjustValues(const ShapeInfo &info) const;
194  boost::optional<unsigned> getMasterPageSeqNum(unsigned pageSeqNum) const;
195  void setRectCoordProps(Coordinate, WPXPropertyList *) const;
196  boost::optional<std::vector<libmspub::TextParagraph> > getShapeText(const ShapeInfo &info) const;
199  void assignShapesToPages();
200  void writePage(unsigned pageSeqNum) const;
201  void writePageShapes(unsigned pageSeqNum) const;
202  void writePageBackground(unsigned pageSeqNum) const;
203  void writeImage(double x, double y, double height, double width,
204  ImgType type, const WPXBinaryData &blob,
205  boost::optional<Color> oneBitColor) const;
206  bool pageIsMaster(unsigned pageSeqNum) const;
207 
208  boost::function<void(void)> paintShape(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform) const;
209  double getCalculationValue(const ShapeInfo &info, unsigned index, bool recursiveEntry, const std::vector<int> &adjustValues) const;
210 
211  WPXPropertyList getCharStyleProps(const CharacterStyle &, boost::optional<unsigned> defaultCharStyleIndex) const;
212  WPXPropertyList getParaStyleProps(const ParagraphStyle &, boost::optional<unsigned> defaultParaStyleIndex) const;
213  double getSpecialValue(const ShapeInfo &info, const CustomShape &shape, int arg, const std::vector<int> &adjustValues) const;
214  void ponderStringEncoding(const std::vector<TextParagraph> &str);
215  const char *getCalculatedEncoding() const;
216 public:
217  static WPXString getColorString(const Color &);
218 };
219 } // namespace libmspub
220 
221 #endif /* __MSPUBCOLLECTOR_H__ */
222 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.3