00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __MSPUBCOLLECTOR_H__
00031 #define __MSPUBCOLLECTOR_H__
00032
00033 #include <list>
00034 #include <vector>
00035 #include <map>
00036 #include <set>
00037 #include <string>
00038 #include <algorithm>
00039
00040 #include <boost/ptr_container/ptr_map.hpp>
00041 #include <boost/ptr_container/ptr_vector.hpp>
00042 #include <boost/bind.hpp>
00043 #include <boost/function.hpp>
00044
00045 #include <libwpd/libwpd.h>
00046 #include <libwpg/libwpg.h>
00047
00048 #include "MSPUBTypes.h"
00049 #include "libmspub_utils.h"
00050 #include "MSPUBContentChunkType.h"
00051 #include "ShapeType.h"
00052 #include "Coordinate.h"
00053 #include "ShapeGroupElement.h"
00054 #include "Fill.h"
00055 #include "ColorReference.h"
00056 #include "PolygonUtils.h"
00057 #include "ShapeInfo.h"
00058
00059 namespace libmspub
00060 {
00061 class MSPUBCollector
00062 {
00063 friend class Fill;
00064 friend class ImgFill;
00065 friend class SolidFill;
00066 friend class GradientFill;
00067 friend class PatternFill;
00068 public:
00069 typedef std::list<ContentChunkReference>::const_iterator ccr_iterator_t;
00070
00071 MSPUBCollector(::libwpg::WPGPaintInterface *painter);
00072 virtual ~MSPUBCollector();
00073
00074
00075 bool addPage(unsigned seqNum);
00076 bool addTextString(const std::vector<TextParagraph> &str, unsigned id);
00077 void addTextShape(unsigned stringId, unsigned seqNum, unsigned pageSeqNum);
00078 bool addImage(unsigned index, ImgType type, WPXBinaryData img);
00079 bool addShape(unsigned seqNum);
00080 void setShapePage(unsigned seqNum, unsigned pageSeqNum);
00081
00082 void setShapeType(unsigned seqNum, ShapeType type);
00083 void setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
00084 void setShapeImgIndex(unsigned seqNum, unsigned index);
00085 void setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool skipIfNotBg);
00086 void setAdjustValue(unsigned seqNum, unsigned index, int adjust);
00087 void setShapeRotation(unsigned seqNum, double rotation);
00088 void setShapeFlip(unsigned, bool, bool);
00089 void setShapeMargins(unsigned seqNum, unsigned left, unsigned top, unsigned right, unsigned bottom);
00090 void setShapeBorderPosition(unsigned seqNum, BorderPosition pos);
00091 void setShapeCoordinatesRotated90(unsigned seqNum);
00092
00093 void beginGroup();
00094 bool endGroup();
00095
00096 void addShapeLine(unsigned seqNum, Line line);
00097 void setShapeOrder(unsigned seqNum);
00098 void setPageBgShape(unsigned pageSeqNum, unsigned seqNum);
00099 void setWidthInEmu(unsigned long);
00100 void setHeightInEmu(unsigned long);
00101
00102 void addTextColor(ColorReference c);
00103 void addFont(std::vector<unsigned char> name);
00104
00105 void addDefaultCharacterStyle(const CharacterStyle &style);
00106 void addDefaultParagraphStyle(const ParagraphStyle &style);
00107 void addPaletteColor(Color);
00108 bool setCurrentGroupSeqNum(unsigned seqNum);
00109
00110 bool go();
00111
00112 bool hasPage(unsigned seqNum) const;
00113 private:
00114
00115 struct PageInfo
00116 {
00117 std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
00118 PageInfo() : m_shapeGroupsOrdered() { }
00119 };
00120
00121 MSPUBCollector(const MSPUBCollector &);
00122 MSPUBCollector &operator=(const MSPUBCollector &);
00123
00124 libwpg::WPGPaintInterface *m_painter;
00125 std::list<ContentChunkReference> m_contentChunkReferences;
00126 double m_width, m_height;
00127 bool m_widthSet, m_heightSet;
00128 unsigned short m_numPages;
00129 std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
00130 std::map<unsigned, PageInfo> m_pagesBySeqNum;
00131 std::vector<std::pair<ImgType, WPXBinaryData> > m_images;
00132 std::vector<ColorReference> m_textColors;
00133 std::vector<std::vector<unsigned char> > m_fonts;
00134 std::vector<CharacterStyle> m_defaultCharStyles;
00135 std::vector<ParagraphStyle> m_defaultParaStyles;
00136 std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
00137 std::vector<unsigned> m_possibleImageShapeSeqNums;
00138 std::vector<Color> m_paletteColors;
00139 std::vector<unsigned> m_shapeSeqNumsOrdered;
00140 std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
00141 std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
00142 std::set<unsigned> m_skipIfNotBgSeqNums;
00143 ShapeGroupElement *m_currentShapeGroup;
00144 boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
00145 std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum;
00146 std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum;
00147 std::set<unsigned> m_shapesWithCoordinatesRotated90;
00148 mutable std::vector<bool> m_calculationValuesSeen;
00149
00150 std::vector<int> getShapeAdjustValues(const ShapeInfo &info) const;
00151 void setRectCoordProps(Coordinate, WPXPropertyList *) const;
00152 boost::optional<std::vector<libmspub::TextParagraph> > getShapeText(const ShapeInfo &info) const;
00153 void setupShapeStructures(ShapeGroupElement &elt);
00154 void addBlackToPaletteIfNecessary();
00155 void assignShapesToPages();
00156 void writePage(unsigned pageSeqNum, const PageInfo &pageInfo) const;
00157 boost::function<void(void)> paintShape(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform) const;
00158 double getCalculationValue(const ShapeInfo &info, unsigned index, bool recursiveEntry, const std::vector<int> &adjustValues) const;
00159
00160 WPXPropertyList getCharStyleProps(const CharacterStyle &, unsigned defaultCharStyleIndex) const;
00161 WPXPropertyList getParaStyleProps(const ParagraphStyle &, unsigned defaultParaStyleIndex) const;
00162 double getSpecialValue(const ShapeInfo &info, const CustomShape &shape, int arg, const std::vector<int> &adjustValues) const;
00163 public:
00164 static WPXString getColorString(const Color &);
00165 };
00166 }
00167
00168 #endif
00169