Line data Source code
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 : #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 : {
67 : class MSPUBCollector
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 :
131 : void addTextColor(ColorReference c);
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 : void setEncoding(Encoding encoding);
139 :
140 : void setNextTableCellTextEnds(const std::vector<unsigned> &ends);
141 : void setTextStringOffset(unsigned textId, unsigned offset);
142 :
143 : bool go();
144 :
145 : bool hasPage(unsigned seqNum) const;
146 : private:
147 :
148 0 : struct PageInfo
149 : {
150 : std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
151 0 : PageInfo() : m_shapeGroupsOrdered() { }
152 : };
153 :
154 : MSPUBCollector(const MSPUBCollector &);
155 : MSPUBCollector &operator=(const MSPUBCollector &);
156 :
157 : libwpg::WPGPaintInterface *m_painter;
158 : std::list<ContentChunkReference> m_contentChunkReferences;
159 : double m_width, m_height;
160 : bool m_widthSet, m_heightSet;
161 : unsigned short m_numPages;
162 : std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
163 : std::map<unsigned, PageInfo> m_pagesBySeqNum;
164 : std::vector<std::pair<ImgType, WPXBinaryData> > m_images;
165 : std::vector<BorderArtInfo> m_borderImages;
166 : std::vector<ColorReference> m_textColors;
167 : std::vector<std::vector<unsigned char> > m_fonts;
168 : std::vector<CharacterStyle> m_defaultCharStyles;
169 : std::vector<ParagraphStyle> m_defaultParaStyles;
170 : std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
171 : std::vector<Color> m_paletteColors;
172 : std::vector<unsigned> m_shapeSeqNumsOrdered;
173 : std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
174 : std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
175 : std::set<unsigned> m_skipIfNotBgSeqNums;
176 : ShapeGroupElement *m_currentShapeGroup;
177 : boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
178 : std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum;
179 : std::list<EmbeddedFontInfo> m_embeddedFonts;
180 : std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum;
181 : std::set<unsigned> m_masterPages;
182 : std::set<unsigned> m_shapesWithCoordinatesRotated90;
183 : std::map<unsigned, unsigned> m_masterPagesByPageSeqNum;
184 : boost::optional<Encoding> m_encoding;
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;
189 : // helper functions
190 : std::vector<int> getShapeAdjustValues(const ShapeInfo &info) const;
191 : boost::optional<unsigned> getMasterPageSeqNum(unsigned pageSeqNum) const;
192 : void setRectCoordProps(Coordinate, WPXPropertyList *) const;
193 : boost::optional<std::vector<libmspub::TextParagraph> > getShapeText(const ShapeInfo &info) const;
194 : void setupShapeStructures(ShapeGroupElement &elt);
195 : void addBlackToPaletteIfNecessary();
196 : void assignShapesToPages();
197 : void writePage(unsigned pageSeqNum) const;
198 : void writePageShapes(unsigned pageSeqNum) const;
199 : void writePageBackground(unsigned pageSeqNum) const;
200 : void writeImage(double x, double y, double height, double width,
201 : ImgType type, const WPXBinaryData &blob,
202 : boost::optional<Color> oneBitColor) const;
203 : bool pageIsMaster(unsigned pageSeqNum) const;
204 :
205 : boost::function<void(void)> paintShape(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform) const;
206 : double getCalculationValue(const ShapeInfo &info, unsigned index, bool recursiveEntry, const std::vector<int> &adjustValues) const;
207 :
208 : WPXPropertyList getCharStyleProps(const CharacterStyle &, boost::optional<unsigned> defaultCharStyleIndex) const;
209 : WPXPropertyList getParaStyleProps(const ParagraphStyle &, boost::optional<unsigned> defaultParaStyleIndex) const;
210 : double getSpecialValue(const ShapeInfo &info, const CustomShape &shape, int arg, const std::vector<int> &adjustValues) const;
211 : public:
212 : static WPXString getColorString(const Color &);
213 : };
214 : } // namespace libmspub
215 :
216 : #endif /* __MSPUBCOLLECTOR_H__ */
217 : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|