00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __ABWCONTENTCOLLECTOR_H__
00011 #define __ABWCONTENTCOLLECTOR_H__
00012
00013 #include <vector>
00014 #include <stack>
00015 #include <set>
00016 #include <libwpd/libwpd.h>
00017 #include "ABWOutputElements.h"
00018 #include "ABWCollector.h"
00019
00020 namespace libabw
00021 {
00022
00023 enum ABWContext
00024 {
00025 ABW_SECTION,
00026 ABW_HEADER,
00027 ABW_FOOTER
00028 };
00029
00030 struct ABWStyle
00031 {
00032 ABWStyle() : basedon(), followedby(), properties() {}
00033 ~ABWStyle() {}
00034 std::string basedon;
00035 std::string followedby;
00036 std::map<std::string, std::string> properties;
00037 };
00038
00039 struct ABWContentTableState
00040 {
00041 ABWContentTableState();
00042 ABWContentTableState(const ABWContentTableState &ts);
00043 ~ABWContentTableState();
00044
00045 std::map<std::string, std::string> m_currentTableProperties;
00046 std::map<std::string, std::string> m_currentCellProperties;
00047
00048 int m_currentTableCol;
00049 int m_currentTableRow;
00050 int m_currentTableCellNumberInRow;
00051 int m_currentTableId;
00052 bool m_isTableRowOpened;
00053 bool m_isTableColumnOpened;
00054 bool m_isTableCellOpened;
00055 bool m_isCellWithoutParagraph;
00056 bool m_isRowWithoutCell;
00057 };
00058
00059 struct ABWContentParsingState
00060 {
00061 ABWContentParsingState();
00062 ABWContentParsingState(const ABWContentParsingState &ps);
00063 ~ABWContentParsingState();
00064
00065 bool m_isDocumentStarted;
00066 bool m_isPageSpanOpened;
00067 bool m_isSectionOpened;
00068 bool m_isHeaderOpened;
00069 bool m_isFooterOpened;
00070
00071 bool m_isSpanOpened;
00072 bool m_isParagraphOpened;
00073 bool m_isListElementOpened;
00074 bool m_inParagraphOrListElement;
00075
00076 std::map<std::string, std::string> m_currentSectionStyle;
00077 std::map<std::string, std::string> m_currentParagraphStyle;
00078 std::map<std::string, std::string> m_currentCharacterStyle;
00079
00080 double m_pageWidth;
00081 double m_pageHeight;
00082 double m_pageMarginTop;
00083 double m_pageMarginBottom;
00084 double m_pageMarginLeft;
00085 double m_pageMarginRight;
00086 int m_footerId;
00087 int m_footerLeftId;
00088 int m_footerFirstId;
00089 int m_footerLastId;
00090 int m_headerId;
00091 int m_headerLeftId;
00092 int m_headerFirstId;
00093 int m_headerLastId;
00094 int m_currentHeaderFooterId;
00095 WPXString m_currentHeaderFooterOccurrence;
00096 ABWContext m_parsingContext;
00097
00098 bool m_deferredPageBreak;
00099 bool m_deferredColumnBreak;
00100
00101 bool m_isNote;
00102
00103 int m_currentListLevel;
00104 int m_currentListId;
00105 bool m_isFirstTextInListElement;
00106
00107 std::stack<ABWContentTableState> m_tableStates;
00108 std::stack<std::pair<int, ABWListElement *> > m_listLevels;
00109 };
00110
00111 class ABWContentCollector : public ABWCollector
00112 {
00113 public:
00114 ABWContentCollector(WPXDocumentInterface *iface, const std::map<int, int> &tableSizes,
00115 const std::map<std::string, ABWData> &data,
00116 const std::map<int, ABWListElement *> &listElements);
00117 virtual ~ABWContentCollector();
00118
00119
00120
00121 void collectTextStyle(const char *name, const char *basedon, const char *followedby, const char *props);
00122 void collectParagraphProperties(const char *level, const char *listid, const char *parentid, const char *style, const char *props);
00123 void collectSectionProperties(const char *footer, const char *footerLeft, const char *footerFirst, const char *footerLast,
00124 const char *header, const char *headerLeft, const char *headerFirst, const char *headerLast,
00125 const char *props);
00126 void collectCharacterProperties(const char *style, const char *props);
00127 void collectPageSize(const char *width, const char *height, const char *units, const char *pageScale);
00128 void closeParagraphOrListElement();
00129 void closeSpan();
00130 void openLink(const char *href);
00131 void closeLink();
00132 void openFoot(const char *id);
00133 void closeFoot();
00134 void openEndnote(const char *id);
00135 void closeEndnote();
00136 void endSection();
00137 void startDocument();
00138 void endDocument();
00139 void insertLineBreak();
00140 void insertColumnBreak();
00141 void insertPageBreak();
00142 void insertText(const char *text);
00143 void insertImage(const char *dataid, const char *props);
00144 void collectList(const char *, const char *, const char *, const char *, const char *, const char *) {}
00145
00146 void collectData(const char *name, const char *mimeType, const WPXBinaryData &data);
00147 void collectHeaderFooter(const char *id, const char *type);
00148
00149 void openTable(const char *props);
00150 void closeTable();
00151 void openCell(const char *props);
00152 void closeCell();
00153
00154
00155 private:
00156 ABWContentCollector(const ABWContentCollector &);
00157 ABWContentCollector &operator=(const ABWContentCollector &);
00158
00159 void _openPageSpan();
00160 void _closePageSpan();
00161
00162 void _openSection();
00163 void _closeSection();
00164
00165 void _openParagraph();
00166 void _closeParagraph();
00167
00168 void _openListElement();
00169 void _closeListElement();
00170
00171 void _handleListChange();
00172 void _changeList();
00173 void _recurseListLevels(int oldLevel, int newLevel, int listId);
00174 void _writeOutDummyListLevels(int oldLevel, int newLevel);
00175
00176 void _openSpan();
00177 void _closeSpan();
00178
00179 void _openTable();
00180 void _closeTable();
00181 void _openTableRow();
00182 void _closeTableRow();
00183 void _openTableCell();
00184 void _closeTableCell();
00185
00186 void _openHeader();
00187 void _closeHeader();
00188 void _openFooter();
00189 void _closeFooter();
00190
00191 void _recurseTextProperties(const char *name, std::map<std::string, std::string> &styleProps);
00192 std::string _findParagraphProperty(const char *name);
00193 std::string _findCharacterProperty(const char *name);
00194 std::string _findTableProperty(const char *name);
00195 std::string _findCellProperty(const char *name);
00196 std::string _findSectionProperty(const char *name);
00197
00198 void _fillParagraphProperties(WPXPropertyList &propList, WPXPropertyListVector &tabStops, bool isListElement);
00199
00200 ABWContentParsingState *m_ps;
00201 WPXDocumentInterface *m_iface;
00202 std::stack<ABWContentParsingState *> m_parsingStates;
00203 std::set<std::string> m_dontLoop;
00204 std::map<std::string, ABWStyle> m_textStyles;
00205
00206 const std::map<std::string, ABWData> &m_data;
00207 const std::map<int, int> &m_tableSizes;
00208 int m_tableCounter;
00209 ABWOutputElements m_outputElements;
00210 const std::map<int, ABWListElement *> &m_listElements;
00211 std::vector<ABWListElement *> m_dummyListElements;
00212 };
00213
00214 }
00215
00216 #endif
00217