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

Generated for libmspub by doxygen 1.8.3.1