00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __MSPUBPARSER_H__
00011 #define __MSPUBPARSER_H__
00012
00013 #include <map>
00014 #include <set>
00015 #include <vector>
00016 #include <memory>
00017
00018 #include <boost/shared_ptr.hpp>
00019 #include <boost/optional.hpp>
00020
00021 #include <librevenge/librevenge.h>
00022 #include <librevenge/librevenge.h>
00023
00024 #include "MSPUBTypes.h"
00025 #include "Fill.h"
00026 #include "Coordinate.h"
00027 #include "PolygonUtils.h"
00028
00029 namespace libmspub
00030 {
00031 class MSPUBCollector;
00032 class FindBySeqNum
00033 {
00034 unsigned seqNum;
00035 public:
00036 FindBySeqNum(unsigned sn) : seqNum(sn) { }
00037 bool operator()(const libmspub::ContentChunkReference &ref)
00038 {
00039 return ref.seqNum == seqNum;
00040 }
00041 };
00042
00043 class FindByParentSeqNum
00044 {
00045 unsigned seqNum;
00046 public:
00047 FindByParentSeqNum(unsigned sn) : seqNum(sn) { }
00048 bool operator()(const libmspub::ContentChunkReference &ref)
00049 {
00050 return ref.parentSeqNum == seqNum;
00051 }
00052 };
00053
00054 struct FOPTValues
00055 {
00056 std::map<unsigned short, unsigned> m_scalarValues;
00057 std::map<unsigned short, std::vector<unsigned char> > m_complexValues;
00058 FOPTValues() : m_scalarValues(), m_complexValues()
00059 {
00060 }
00061 };
00062
00063 class MSPUBParser
00064 {
00065 public:
00066 explicit MSPUBParser(librevenge::RVNGInputStream *input, MSPUBCollector *collector);
00067 virtual ~MSPUBParser();
00068 virtual bool parse();
00069 protected:
00070 virtual unsigned getColorIndexByQuillEntry(unsigned entry);
00071
00072 struct TextSpanReference
00073 {
00074 TextSpanReference(unsigned short f, unsigned short l, const CharacterStyle &cs) : first(f), last(l), charStyle(cs) { }
00075 unsigned short first;
00076 unsigned short last;
00077 CharacterStyle charStyle;
00078 };
00079
00080 struct TextParagraphReference
00081 {
00082 TextParagraphReference(unsigned short f, unsigned short l, const ParagraphStyle &ps) : first(f), last(l), paraStyle(ps) { }
00083 unsigned short first;
00084 unsigned short last;
00085 ParagraphStyle paraStyle;
00086 };
00087
00088 typedef std::vector<ContentChunkReference>::const_iterator ccr_iterator_t;
00089
00090 MSPUBParser();
00091 MSPUBParser(const MSPUBParser &);
00092 MSPUBParser &operator=(const MSPUBParser &);
00093 virtual bool parseContents(librevenge::RVNGInputStream *input);
00094 bool parseMetaData(librevenge::RVNGInputStream *input);
00095 bool parseQuill(librevenge::RVNGInputStream *input);
00096 bool parseEscher(librevenge::RVNGInputStream *input);
00097 bool parseEscherDelay(librevenge::RVNGInputStream *input);
00098
00099 MSPUBBlockInfo parseBlock(librevenge::RVNGInputStream *input, bool skipHierarchicalData = false);
00100 EscherContainerInfo parseEscherContainer(librevenge::RVNGInputStream *input);
00101
00102 bool parseContentChunkReference(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
00103 QuillChunkReference parseQuillChunkReference(librevenge::RVNGInputStream *input);
00104 bool parseDocumentChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
00105 bool parsePageChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
00106 bool parsePaletteChunk(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
00107 bool parsePageShapeList(librevenge::RVNGInputStream *input, MSPUBBlockInfo block, unsigned pageSeqNum);
00108 bool parseShape(librevenge::RVNGInputStream *input, const ContentChunkReference &chunk);
00109 bool parseBorderArtChunk(librevenge::RVNGInputStream *input,
00110 const ContentChunkReference &chunk);
00111 bool parseFontChunk(librevenge::RVNGInputStream *input,
00112 const ContentChunkReference &chunk);
00113 void parsePaletteEntry(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
00114 void parseColors(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
00115 void parseFonts(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
00116 void parseDefaultStyle(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
00117 void parseShapeGroup(librevenge::RVNGInputStream *input, const EscherContainerInfo &spgr, Coordinate parentCoordinateSystem, Coordinate parentGroupAbsoluteCoord);
00118 void skipBlock(librevenge::RVNGInputStream *input, MSPUBBlockInfo block);
00119 void parseEscherShape(librevenge::RVNGInputStream *input, const EscherContainerInfo &sp, Coordinate &parentCoordinateSystem, Coordinate &parentGroupAbsoluteCoord);
00120 bool findEscherContainer(librevenge::RVNGInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, unsigned short type);
00121 bool findEscherContainerWithTypeInSet(librevenge::RVNGInputStream *input, const EscherContainerInfo &parent, EscherContainerInfo &out, std::set<unsigned short> types);
00122 std::map<unsigned short, unsigned> extractEscherValues(librevenge::RVNGInputStream *input, const EscherContainerInfo &record);
00123 FOPTValues extractFOPTValues(librevenge::RVNGInputStream *input,
00124 const libmspub::EscherContainerInfo &record);
00125 std::vector<TextSpanReference> parseCharacterStyles(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
00126 std::vector<TextParagraphReference> parseParagraphStyles(librevenge::RVNGInputStream *input, const QuillChunkReference &chunk);
00127 std::vector<Calculation> parseGuides(const std::vector<unsigned char>
00128 &guideData);
00129 std::vector<Vertex> parseVertices(const std::vector<unsigned char>
00130 &vertexData);
00131 std::vector<unsigned> parseTableCellDefinitions(librevenge::RVNGInputStream *input,
00132 const QuillChunkReference &chunk);
00133 std::vector<unsigned short> parseSegments(
00134 const std::vector<unsigned char> &segmentData);
00135 DynamicCustomShape getDynamicCustomShape(
00136 const std::vector<unsigned char> &vertexData,
00137 const std::vector<unsigned char> &segmentData,
00138 const std::vector<unsigned char> &guideData,
00139 unsigned geoWidth, unsigned geoHeight);
00140 int getColorIndex(librevenge::RVNGInputStream *input, const MSPUBBlockInfo &info);
00141 unsigned getFontIndex(librevenge::RVNGInputStream *input, const MSPUBBlockInfo &info);
00142 CharacterStyle getCharacterStyle(librevenge::RVNGInputStream *input);
00143 ParagraphStyle getParagraphStyle(librevenge::RVNGInputStream *input);
00144 boost::shared_ptr<Fill> getNewFill(const std::map<unsigned short, unsigned> &foptValues, bool &skipIfNotBg, std::map<unsigned short, std::vector<unsigned char> > &foptVal);
00145
00146 librevenge::RVNGInputStream *m_input;
00147 MSPUBCollector *m_collector;
00148 std::vector<MSPUBBlockInfo> m_blockInfo;
00149 std::vector<ContentChunkReference> m_contentChunks;
00150 std::vector<unsigned> m_cellsChunkIndices;
00151 std::vector<unsigned> m_pageChunkIndices;
00152 std::vector<unsigned> m_shapeChunkIndices;
00153 std::vector<unsigned> m_paletteChunkIndices;
00154 std::vector<unsigned> m_borderArtChunkIndices;
00155 std::vector<unsigned> m_fontChunkIndices;
00156 std::vector<unsigned> m_unknownChunkIndices;
00157 boost::optional<unsigned> m_documentChunkIndex;
00158 int m_lastSeenSeqNum;
00159 unsigned m_lastAddedImage;
00160 std::vector<int> m_alternateShapeSeqNums;
00161 std::vector<int> m_escherDelayIndices;
00162
00163 static short getBlockDataLength(unsigned type);
00164 static bool isBlockDataString(unsigned type);
00165 static PageType getPageTypeBySeqNum(unsigned seqNum);
00166 static unsigned getEscherElementTailLength(unsigned short type);
00167 static unsigned getEscherElementAdditionalHeaderLength(unsigned short type);
00168 static ImgType imgTypeByBlipType(unsigned short type);
00169 static int getStartOffset(ImgType type, unsigned short initial);
00170 static bool lineExistsByFlagPointer(unsigned *flags,
00171 unsigned *geomFlags = NULL);
00172 };
00173
00174 }
00175
00176 #endif // __MSPUBRAPHICS_H__
00177