MSPUBCollector.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libmspub project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef __MSPUBCOLLECTOR_H__
11 #define __MSPUBCOLLECTOR_H__
12 
13 #include <list>
14 #include <vector>
15 #include <map>
16 #include <set>
17 #include <string>
18 #include <algorithm>
19 
20 #include <boost/ptr_container/ptr_vector.hpp>
21 #include <boost/bind.hpp>
22 #include <boost/function.hpp>
23 
24 #include <librevenge/librevenge.h>
25 #include <librevenge/librevenge.h>
26 
27 #include "MSPUBTypes.h"
28 #include "libmspub_utils.h"
29 #include "MSPUBContentChunkType.h"
30 #include "ShapeType.h"
31 #include "Coordinate.h"
32 #include "ShapeGroupElement.h"
33 #include "Fill.h"
34 #include "ColorReference.h"
35 #include "PolygonUtils.h"
36 #include "ShapeInfo.h"
37 #include "BorderArtInfo.h"
38 #include "Dash.h"
39 #include "Arrow.h"
40 #include "VerticalAlign.h"
41 #include "EmbeddedFontInfo.h"
42 #include "Shadow.h"
43 
44 namespace libmspub
45 {
47 {
48  friend class Fill;
49  friend class ImgFill;
50  friend class SolidFill;
51  friend class GradientFill;
52  friend class PatternFill;
53 public:
54  typedef std::list<ContentChunkReference>::const_iterator ccr_iterator_t;
55 
56  MSPUBCollector(::librevenge::RVNGDrawingInterface *painter);
57  virtual ~MSPUBCollector();
58 
59  // collector functions
60  bool addPage(unsigned seqNum);
61  bool addTextString(const std::vector<TextParagraph> &str, unsigned id);
62  void addTextShape(unsigned stringId, unsigned seqNum);
63  bool addImage(unsigned index, ImgType type, librevenge::RVNGBinaryData img);
64  void setBorderImageOffset(unsigned index, unsigned offset);
65  librevenge::RVNGBinaryData *addBorderImage(ImgType type, unsigned borderArtIndex);
66  void setShapePage(unsigned seqNum, unsigned pageSeqNum);
67 
68  void setNextPage(unsigned seqNum);
69 
70  void setShapeType(unsigned seqNum, ShapeType type);
71  void setShapeCropType(unsigned seqNum, ShapeType cropType);
72  void setShapePictureRecolor(unsigned seqNum, const ColorReference &recolor);
73  void setShapePictureBrightness(unsigned seqNum, int brightness);
74  void setShapePictureContrast(unsigned seqNum, int contrast);
75  void setShapeTableInfo(unsigned seqNum, const TableInfo &ti);
76  void setShapeBorderImageId(unsigned seqNum, unsigned borderImageId);
77  void setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
78  void setShapeImgIndex(unsigned seqNum, unsigned index);
79  void setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool skipIfNotBg);
80  void setShapeDash(unsigned seqNum, const Dash &dash);
81  void setAdjustValue(unsigned seqNum, unsigned index, int adjust);
82  void setShapeRotation(unsigned seqNum, double rotation);
83  void setShapeFlip(unsigned, bool, bool);
84  void setShapeMargins(unsigned seqNum, unsigned left, unsigned top, unsigned right, unsigned bottom);
85  void setShapeBorderPosition(unsigned seqNum, BorderPosition pos);
86  void setShapeCoordinatesRotated90(unsigned seqNum);
87  void setShapeCustomPath(unsigned seqNum,
88  const DynamicCustomShape &shape);
89  void setShapeClipPath(unsigned seqNum, const std::vector<libmspub::Vertex> &clip);
90  void setShapeVerticalTextAlign(unsigned seqNum, VerticalAlign va);
91  void designateMasterPage(unsigned seqNum);
92  void setMasterPage(unsigned pageSeqNum, unsigned masterSeqNum);
93  void setShapeStretchBorderArt(unsigned seqNum);
94  void setShapeShadow(unsigned seqNum, const Shadow &shadow);
95 
96  // Microsoft "Embedded OpenType" ... need to figure out how to convert
97  // this to a sane format and how to get LibreOffice to understand embedded fonts.
98  librevenge::RVNGBinaryData &addEOTFont(const librevenge::RVNGString &name);
99 
100  void beginGroup();
101  bool endGroup();
102 
103  void setShapeLineBackColor(unsigned seqNum, ColorReference backColor);
104  void addShapeLine(unsigned seqNum, Line line);
105  void setShapeOrder(unsigned seqNum);
106  void setPageBgShape(unsigned pageSeqNum, unsigned seqNum);
107  void setWidthInEmu(unsigned long);
108  void setHeightInEmu(unsigned long);
109  void setShapeNumColumns(unsigned seqNum, unsigned numColumns);
110  void setShapeColumnSpacing(unsigned seqNum, unsigned spacing);
111  void setShapeBeginArrow(unsigned seqNum, const Arrow &arrow);
112  void setShapeEndArrow(unsigned seqNum, const Arrow &arrow);
113 
115  void addFont(std::vector<unsigned char> name);
116 
117  void addDefaultCharacterStyle(const CharacterStyle &style);
118  void addDefaultParagraphStyle(const ParagraphStyle &style);
119  void addPaletteColor(Color);
120  bool setCurrentGroupSeqNum(unsigned seqNum);
121 
122  void useEncodingHeuristic();
123 
124  void setNextTableCellTextEnds(const std::vector<unsigned> &ends);
125  void setTextStringOffset(unsigned textId, unsigned offset);
126 
127  bool go();
128 
129  bool hasPage(unsigned seqNum) const;
130 private:
131 
132  struct PageInfo
133  {
134  std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
136  };
137 
140 
141  librevenge::RVNGDrawingInterface *m_painter;
142  std::list<ContentChunkReference> m_contentChunkReferences;
143  double m_width, m_height;
145  unsigned short m_numPages;
146  std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
147  std::map<unsigned, PageInfo> m_pagesBySeqNum;
148  std::vector<std::pair<ImgType, librevenge::RVNGBinaryData> > m_images;
149  std::vector<BorderArtInfo> m_borderImages;
150  std::vector<ColorReference> m_textColors;
151  std::vector<std::vector<unsigned char> > m_fonts;
152  std::vector<CharacterStyle> m_defaultCharStyles;
153  std::vector<ParagraphStyle> m_defaultParaStyles;
154  std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
155  std::vector<Color> m_paletteColors;
156  std::vector<unsigned> m_shapeSeqNumsOrdered;
157  std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
158  std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
159  std::set<unsigned> m_skipIfNotBgSeqNums;
161  boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
162  std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum;
163  std::list<EmbeddedFontInfo> m_embeddedFonts;
164  std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum;
165  std::set<unsigned> m_masterPages;
167  std::map<unsigned, unsigned> m_masterPagesByPageSeqNum;
168  std::vector<std::vector<unsigned> > m_tableCellTextEndsVector;
169  std::map<unsigned, unsigned> m_stringOffsetsByTextId;
170  mutable std::vector<bool> m_calculationValuesSeen;
171  std::vector<unsigned> m_pageSeqNumsOrdered;
173  std::vector<unsigned char> m_allText;
174  mutable boost::optional<const char *> m_calculatedEncoding;
175  // helper functions
176  std::vector<int> getShapeAdjustValues(const ShapeInfo &info) const;
177  boost::optional<unsigned> getMasterPageSeqNum(unsigned pageSeqNum) const;
178  void setRectCoordProps(Coordinate, librevenge::RVNGPropertyList *) const;
179  boost::optional<std::vector<libmspub::TextParagraph> > getShapeText(const ShapeInfo &info) const;
182  void assignShapesToPages();
183  void writePage(unsigned pageSeqNum) const;
184  void writePageShapes(unsigned pageSeqNum) const;
185  void writePageBackground(unsigned pageSeqNum) const;
186  void writeImage(double x, double y, double height, double width,
187  ImgType type, const librevenge::RVNGBinaryData &blob,
188  boost::optional<Color> oneBitColor) const;
189  bool pageIsMaster(unsigned pageSeqNum) const;
190 
191  boost::function<void(void)> paintShape(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform) const;
192  double getCalculationValue(const ShapeInfo &info, unsigned index, bool recursiveEntry, const std::vector<int> &adjustValues) const;
193 
194  librevenge::RVNGPropertyList getCharStyleProps(const CharacterStyle &, boost::optional<unsigned> defaultCharStyleIndex) const;
195  librevenge::RVNGPropertyList getParaStyleProps(const ParagraphStyle &, boost::optional<unsigned> defaultParaStyleIndex) const;
196  double getSpecialValue(const ShapeInfo &info, const CustomShape &shape, int arg, const std::vector<int> &adjustValues) const;
197  void ponderStringEncoding(const std::vector<TextParagraph> &str);
198  const char *getCalculatedEncoding() const;
199 public:
200  static librevenge::RVNGString getColorString(const Color &);
201 };
202 } // namespace libmspub
203 
204 #endif /* __MSPUBCOLLECTOR_H__ */
205 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libmspub by doxygen 1.8.4