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_vector.hpp>
00041 #include <boost/bind.hpp>
00042 #include <boost/function.hpp>
00043
00044 #include <libwpd/libwpd.h>
00045 #include <libwpg/libwpg.h>
00046
00047 #include "MSPUBTypes.h"
00048 #include "libmspub_utils.h"
00049 #include "MSPUBContentChunkType.h"
00050 #include "ShapeType.h"
00051 #include "Coordinate.h"
00052 #include "ShapeGroupElement.h"
00053 #include "Fill.h"
00054 #include "ColorReference.h"
00055 #include "PolygonUtils.h"
00056 #include "ShapeInfo.h"
00057 #include "BorderArtInfo.h"
00058 #include "Dash.h"
00059 #include "Arrow.h"
00060 #include "VerticalAlign.h"
00061 #include "EmbeddedFontInfo.h"
00062 #include "Shadow.h"
00063
00064 namespace libmspub
00065 {
00066 class MSPUBCollector
00067 {
00068 friend class Fill;
00069 friend class ImgFill;
00070 friend class SolidFill;
00071 friend class GradientFill;
00072 friend class PatternFill;
00073 public:
00074 typedef std::list<ContentChunkReference>::const_iterator ccr_iterator_t;
00075
00076 MSPUBCollector(::libwpg::WPGPaintInterface *painter);
00077 virtual ~MSPUBCollector();
00078
00079
00080 bool addPage(unsigned seqNum);
00081 bool addTextString(const std::vector<TextParagraph> &str, unsigned id);
00082 void addTextShape(unsigned stringId, unsigned seqNum);
00083 bool addImage(unsigned index, ImgType type, WPXBinaryData img);
00084 void setBorderImageOffset(unsigned index, unsigned offset);
00085 WPXBinaryData *addBorderImage(ImgType type, unsigned borderArtIndex);
00086 void setShapePage(unsigned seqNum, unsigned pageSeqNum);
00087
00088 void setNextPage(unsigned seqNum);
00089
00090 void setShapeType(unsigned seqNum, ShapeType type);
00091 void setShapeCropType(unsigned seqNum, ShapeType cropType);
00092 void setShapePictureRecolor(unsigned seqNum, const ColorReference &recolor);
00093 void setShapePictureBrightness(unsigned seqNum, int brightness);
00094 void setShapePictureContrast(unsigned seqNum, int contrast);
00095 void setShapeTableInfo(unsigned seqNum, const TableInfo &ti);
00096 void setShapeBorderImageId(unsigned seqNum, unsigned borderImageId);
00097 void setShapeCoordinatesInEmu(unsigned seqNum, int xs, int ys, int xe, int ye);
00098 void setShapeImgIndex(unsigned seqNum, unsigned index);
00099 void setShapeFill(unsigned seqNum, boost::shared_ptr<Fill> fill, bool skipIfNotBg);
00100 void setShapeDash(unsigned seqNum, const Dash &dash);
00101 void setAdjustValue(unsigned seqNum, unsigned index, int adjust);
00102 void setShapeRotation(unsigned seqNum, double rotation);
00103 void setShapeFlip(unsigned, bool, bool);
00104 void setShapeMargins(unsigned seqNum, unsigned left, unsigned top, unsigned right, unsigned bottom);
00105 void setShapeBorderPosition(unsigned seqNum, BorderPosition pos);
00106 void setShapeCoordinatesRotated90(unsigned seqNum);
00107 void setShapeCustomPath(unsigned seqNum,
00108 const DynamicCustomShape &shape);
00109 void setShapeClipPath(unsigned seqNum, const std::vector<libmspub::Vertex> &clip);
00110 void setShapeVerticalTextAlign(unsigned seqNum, VerticalAlign va);
00111 void designateMasterPage(unsigned seqNum);
00112 void setMasterPage(unsigned pageSeqNum, unsigned masterSeqNum);
00113 void setShapeStretchBorderArt(unsigned seqNum);
00114 void setShapeShadow(unsigned seqNum, const Shadow &shadow);
00115
00116
00117
00118 WPXBinaryData &addEOTFont(const WPXString &name);
00119
00120 void beginGroup();
00121 bool endGroup();
00122
00123 void setShapeLineBackColor(unsigned seqNum, ColorReference backColor);
00124 void addShapeLine(unsigned seqNum, Line line);
00125 void setShapeOrder(unsigned seqNum);
00126 void setPageBgShape(unsigned pageSeqNum, unsigned seqNum);
00127 void setWidthInEmu(unsigned long);
00128 void setHeightInEmu(unsigned long);
00129 void setShapeNumColumns(unsigned seqNum, unsigned numColumns);
00130 void setShapeColumnSpacing(unsigned seqNum, unsigned spacing);
00131 void setShapeBeginArrow(unsigned seqNum, const Arrow &arrow);
00132 void setShapeEndArrow(unsigned seqNum, const Arrow &arrow);
00133
00134 void addTextColor(ColorReference c);
00135 void addFont(std::vector<unsigned char> name);
00136
00137 void addDefaultCharacterStyle(const CharacterStyle &style);
00138 void addDefaultParagraphStyle(const ParagraphStyle &style);
00139 void addPaletteColor(Color);
00140 bool setCurrentGroupSeqNum(unsigned seqNum);
00141
00142 void useEncodingHeuristic();
00143
00144 void setNextTableCellTextEnds(const std::vector<unsigned> &ends);
00145 void setTextStringOffset(unsigned textId, unsigned offset);
00146
00147 bool go();
00148
00149 bool hasPage(unsigned seqNum) const;
00150 private:
00151
00152 struct PageInfo
00153 {
00154 std::vector<ShapeGroupElement *> m_shapeGroupsOrdered;
00155 PageInfo() : m_shapeGroupsOrdered() { }
00156 };
00157
00158 MSPUBCollector(const MSPUBCollector &);
00159 MSPUBCollector &operator=(const MSPUBCollector &);
00160
00161 libwpg::WPGPaintInterface *m_painter;
00162 std::list<ContentChunkReference> m_contentChunkReferences;
00163 double m_width, m_height;
00164 bool m_widthSet, m_heightSet;
00165 unsigned short m_numPages;
00166 std::map<unsigned, std::vector<TextParagraph> > m_textStringsById;
00167 std::map<unsigned, PageInfo> m_pagesBySeqNum;
00168 std::vector<std::pair<ImgType, WPXBinaryData> > m_images;
00169 std::vector<BorderArtInfo> m_borderImages;
00170 std::vector<ColorReference> m_textColors;
00171 std::vector<std::vector<unsigned char> > m_fonts;
00172 std::vector<CharacterStyle> m_defaultCharStyles;
00173 std::vector<ParagraphStyle> m_defaultParaStyles;
00174 std::map<unsigned, ShapeType> m_shapeTypesBySeqNum;
00175 std::vector<Color> m_paletteColors;
00176 std::vector<unsigned> m_shapeSeqNumsOrdered;
00177 std::map<unsigned, unsigned> m_pageSeqNumsByShapeSeqNum;
00178 std::map<unsigned, unsigned> m_bgShapeSeqNumsByPageSeqNum;
00179 std::set<unsigned> m_skipIfNotBgSeqNums;
00180 ShapeGroupElement *m_currentShapeGroup;
00181 boost::ptr_vector<ShapeGroupElement> m_topLevelShapes;
00182 std::map<unsigned, ShapeGroupElement *> m_groupsBySeqNum;
00183 std::list<EmbeddedFontInfo> m_embeddedFonts;
00184 std::map<unsigned, ShapeInfo> m_shapeInfosBySeqNum;
00185 std::set<unsigned> m_masterPages;
00186 std::set<unsigned> m_shapesWithCoordinatesRotated90;
00187 std::map<unsigned, unsigned> m_masterPagesByPageSeqNum;
00188 std::vector<std::vector<unsigned> > m_tableCellTextEndsVector;
00189 std::map<unsigned, unsigned> m_stringOffsetsByTextId;
00190 mutable std::vector<bool> m_calculationValuesSeen;
00191 std::vector<unsigned> m_pageSeqNumsOrdered;
00192 bool m_encodingHeuristic;
00193 std::vector<unsigned char> m_allText;
00194 mutable boost::optional<const char *> m_calculatedEncoding;
00195
00196 std::vector<int> getShapeAdjustValues(const ShapeInfo &info) const;
00197 boost::optional<unsigned> getMasterPageSeqNum(unsigned pageSeqNum) const;
00198 void setRectCoordProps(Coordinate, WPXPropertyList *) const;
00199 boost::optional<std::vector<libmspub::TextParagraph> > getShapeText(const ShapeInfo &info) const;
00200 void setupShapeStructures(ShapeGroupElement &elt);
00201 void addBlackToPaletteIfNecessary();
00202 void assignShapesToPages();
00203 void writePage(unsigned pageSeqNum) const;
00204 void writePageShapes(unsigned pageSeqNum) const;
00205 void writePageBackground(unsigned pageSeqNum) const;
00206 void writeImage(double x, double y, double height, double width,
00207 ImgType type, const WPXBinaryData &blob,
00208 boost::optional<Color> oneBitColor) const;
00209 bool pageIsMaster(unsigned pageSeqNum) const;
00210
00211 boost::function<void(void)> paintShape(const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform) const;
00212 double getCalculationValue(const ShapeInfo &info, unsigned index, bool recursiveEntry, const std::vector<int> &adjustValues) const;
00213
00214 WPXPropertyList getCharStyleProps(const CharacterStyle &, boost::optional<unsigned> defaultCharStyleIndex) const;
00215 WPXPropertyList getParaStyleProps(const ParagraphStyle &, boost::optional<unsigned> defaultParaStyleIndex) const;
00216 double getSpecialValue(const ShapeInfo &info, const CustomShape &shape, int arg, const std::vector<int> &adjustValues) const;
00217 void ponderStringEncoding(const std::vector<TextParagraph> &str);
00218 const char *getCalculatedEncoding() const;
00219 public:
00220 static WPXString getColorString(const Color &);
00221 };
00222 }
00223
00224 #endif
00225