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 <librevenge/librevenge.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 ABWPropertyMap properties;
00037 };
00038
00039 struct ABWContentTableState
00040 {
00041 ABWContentTableState();
00042 ABWContentTableState(const ABWContentTableState &ts);
00043 ~ABWContentTableState();
00044
00045 ABWPropertyMap m_currentTableProperties;
00046 ABWPropertyMap 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 ABWPropertyMap m_currentSectionStyle;
00077 ABWPropertyMap m_currentParagraphStyle;
00078 ABWPropertyMap 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 librevenge::RVNGString 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(librevenge::RVNGTextInterface *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 collectDocumentProperties(const char *props);
00123 void collectParagraphProperties(const char *level, const char *listid, const char *parentid, const char *style, const char *props);
00124 void collectSectionProperties(const char *footer, const char *footerLeft, const char *footerFirst, const char *footerLast,
00125 const char *header, const char *headerLeft, const char *headerFirst, const char *headerLast,
00126 const char *props);
00127 void collectCharacterProperties(const char *style, const char *props);
00128 void collectPageSize(const char *width, const char *height, const char *units, const char *pageScale);
00129 void closeParagraphOrListElement();
00130 void closeSpan();
00131 void openLink(const char *href);
00132 void closeLink();
00133 void openFoot(const char *id);
00134 void closeFoot();
00135 void openEndnote(const char *id);
00136 void closeEndnote();
00137 void endSection();
00138 void startDocument();
00139 void endDocument();
00140 void insertLineBreak();
00141 void insertColumnBreak();
00142 void insertPageBreak();
00143 void insertText(const char *text);
00144 void insertImage(const char *dataid, const char *props);
00145 void collectList(const char *, const char *, const char *, const char *, const char *, const char *) {}
00146
00147 void collectData(const char *name, const char *mimeType, const librevenge::RVNGBinaryData &data);
00148 void collectHeaderFooter(const char *id, const char *type);
00149
00150 void openTable(const char *props);
00151 void closeTable();
00152 void openCell(const char *props);
00153 void closeCell();
00154
00155 void addMetadataEntry(const char *name, const char *value);
00156
00157 private:
00158 ABWContentCollector(const ABWContentCollector &);
00159 ABWContentCollector &operator=(const ABWContentCollector &);
00160
00161 void _setMetadata();
00162
00163 void _openPageSpan();
00164 void _closePageSpan();
00165
00166 void _openSection();
00167 void _closeSection();
00168
00169 void _openParagraph();
00170 void _closeParagraph();
00171
00172 void _openListElement();
00173 void _closeListElement();
00174
00175 void _handleListChange();
00176 void _changeList();
00177 void _recurseListLevels(int oldLevel, int newLevel, int listId);
00178 void _writeOutDummyListLevels(int oldLevel, int newLevel);
00179
00180 void _openSpan();
00181 void _closeSpan();
00182
00183 void _openTable();
00184 void _closeTable();
00185 void _openTableRow();
00186 void _closeTableRow();
00187 void _openTableCell();
00188 void _closeTableCell();
00189
00190 void _openHeader();
00191 void _closeHeader();
00192 void _openFooter();
00193 void _closeFooter();
00194
00195 void _recurseTextProperties(const char *name, ABWPropertyMap &styleProps);
00196 std::string _findDocumentProperty(const char *name);
00197 std::string _findParagraphProperty(const char *name);
00198 std::string _findCharacterProperty(const char *name);
00199 std::string _findTableProperty(const char *name);
00200 std::string _findCellProperty(const char *name);
00201 std::string _findSectionProperty(const char *name);
00202 std::string _findMetadataEntry(const char *name);
00203
00204 void _fillParagraphProperties(librevenge::RVNGPropertyList &propList, bool isListElement);
00205
00206 ABWContentParsingState *m_ps;
00207 librevenge::RVNGTextInterface *m_iface;
00208 std::stack<ABWContentParsingState *> m_parsingStates;
00209 std::set<std::string> m_dontLoop;
00210 std::map<std::string, ABWStyle> m_textStyles;
00211
00212 ABWPropertyMap m_documentStyle;
00213 ABWPropertyMap m_metadata;
00214
00215 const std::map<std::string, ABWData> &m_data;
00216 const std::map<int, int> &m_tableSizes;
00217 int m_tableCounter;
00218 ABWOutputElements m_outputElements;
00219 const std::map<int, ABWListElement *> &m_listElements;
00220 std::vector<ABWListElement *> m_dummyListElements;
00221 };
00222
00223 }
00224
00225 #endif
00226