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

Generated for libmspub by doxygen 1.8.3.1