Go to the documentation of this file.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 #ifndef WPSCONTENTLISTENER_H
00030 #define WPSCONTENTLISTENER_H
00031
00032 #include <vector>
00033
00034 #include <libwpd/WPXPropertyList.h>
00035
00036 #include "libwps_internal.h"
00037
00038 class WPXBinaryData;
00039 class WPXDocumentInterface;
00040 class WPXString;
00041 class WPXPropertyListVector;
00042
00043 class WPSCell;
00044 class WPSList;
00045 class WPSPageSpan;
00046 class WPSPosition;
00047 class WPSSubDocument;
00048 struct WPSTabStop;
00049
00050 typedef shared_ptr<WPSSubDocument> WPSSubDocumentPtr;
00051
00052 struct WPSDocumentParsingState
00053 {
00054 WPSDocumentParsingState(std::vector<WPSPageSpan> const &pageList);
00055 ~WPSDocumentParsingState();
00056
00057 std::vector<WPSPageSpan> m_pageList;
00058 WPXPropertyList m_metaData;
00059
00060 int m_footNoteNumber , m_endNoteNumber ;
00061 int m_newListId;
00062
00063 bool m_isDocumentStarted, m_isHeaderFooterStarted;
00064 std::vector<WPSSubDocumentPtr> m_subDocuments;
00066 private:
00067 WPSDocumentParsingState(const WPSDocumentParsingState &);
00068 WPSDocumentParsingState &operator=(const WPSDocumentParsingState &);
00069 };
00070
00071 struct WPSContentParsingState
00072 {
00073 WPSContentParsingState();
00074 ~WPSContentParsingState();
00075
00076 WPXString m_textBuffer;
00077 int m_numDeferredTabs;
00078
00079 uint32_t m_textAttributeBits;
00080 double m_fontSize;
00081 WPXString m_fontName;
00082 uint32_t m_fontColor;
00083 int m_textLanguage;
00084
00085 bool m_isParagraphColumnBreak;
00086 bool m_isParagraphPageBreak;
00087 libwps::Justification m_paragraphJustification;
00088 double m_paragraphLineSpacing;
00089 WPXUnit m_paragraphLineSpacingUnit;
00090 int m_paragraphBorders;
00091 libwps::BorderStyle m_paragraphBordersStyle;
00092 int m_paragraphBordersWidth;
00093 uint32_t m_paragraphBordersColor;
00094
00095 shared_ptr<WPSList> m_list;
00096 uint8_t m_currentListLevel;
00097
00098 bool m_isPageSpanOpened;
00099 bool m_isSectionOpened;
00100 bool m_isFrameOpened;
00101 bool m_isPageSpanBreakDeferred;
00102 bool m_isHeaderFooterWithoutParagraph;
00103
00104 bool m_isSpanOpened;
00105 bool m_isParagraphOpened;
00106 bool m_isListElementOpened;
00107
00108 bool m_firstParagraphInPageSpan;
00109
00110 std::vector<unsigned int> m_numRowsToSkip;
00111 bool m_isTableOpened;
00112 bool m_isTableRowOpened;
00113 bool m_isTableColumnOpened;
00114 bool m_isTableCellOpened;
00115
00116 unsigned m_currentPage;
00117 int m_numPagesRemainingInSpan;
00118 int m_currentPageNumber;
00119
00120 bool m_sectionAttributesChanged;
00121 int m_numColumns;
00122 std::vector < WPSColumnDefinition > m_textColumns;
00123 bool m_isTextColumnWithoutParagraph;
00124
00125 double m_pageFormLength;
00126 double m_pageFormWidth;
00127 bool m_pageFormOrientationIsPortrait;
00128
00129 double m_pageMarginLeft;
00130 double m_pageMarginRight;
00131 double m_pageMarginTop;
00132 double m_pageMarginBottom;
00133
00134 double m_sectionMarginLeft;
00135 double m_sectionMarginRight;
00136 double m_sectionMarginTop;
00137 double m_sectionMarginBottom;
00138 double m_paragraphMarginLeft;
00139 double m_paragraphMarginRight;
00140 double m_paragraphMarginTop;
00141 WPXUnit m_paragraphMarginTopUnit;
00142 double m_paragraphMarginBottom;
00143 WPXUnit m_paragraphMarginBottomUnit;
00144 double m_leftMarginByPageMarginChange;
00145 double m_rightMarginByPageMarginChange;
00146 double m_leftMarginByParagraphMarginChange;
00147 double m_rightMarginByParagraphMarginChange;
00148 double m_leftMarginByTabs;
00149 double m_rightMarginByTabs;
00150
00151 double m_paragraphTextIndent;
00152 double m_textIndentByParagraphIndentChange;
00153 double m_textIndentByTabs;
00154
00155 double m_listReferencePosition;
00156 double m_listBeginPosition;
00157 std::vector<bool> m_listOrderedLevels;
00158
00159 uint16_t m_alignmentCharacter;
00160 std::vector<WPSTabStop> m_tabStops;
00161 bool m_isTabPositionRelative;
00162
00163 bool m_inSubDocument;
00164
00165 bool m_isNote;
00166 libwps::SubDocumentType m_subDocumentType;
00167
00168 private:
00169 WPSContentParsingState(const WPSContentParsingState &);
00170 WPSContentParsingState &operator=(const WPSContentParsingState &);
00171 };
00172
00173 class WPSContentListener
00174 {
00175 public:
00176 WPSContentListener(std::vector<WPSPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
00177 virtual ~WPSContentListener();
00178
00179 void setDocumentLanguage(int lcid);
00180
00181 void startDocument();
00182 void endDocument();
00183 void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
00184 bool isHeaderFooterOpened() const;
00185
00186
00187
00189 void insertCharacter(uint8_t character);
00193 void insertUnicode(uint32_t character);
00195 void insertUnicodeString(WPXString const &str);
00197 static void appendUnicode(uint32_t val, WPXString &buffer);
00198
00199 void insertTab();
00200 void insertEOL(bool softBreak=false);
00201 void insertBreak(const uint8_t breakType);
00202
00203
00204 void setTextFont(const WPXString &fontName);
00205 void setFontSize(const uint16_t fontSize);
00206 void setFontAttributes(const uint32_t fontAttributes);
00207 void setTextLanguage(int lcid);
00208 void setTextColor(const uint32_t rgb);
00209 void setFont(const WPSFont &font);
00210
00211
00213 bool isParagraphOpened() const;
00214 void setParagraphLineSpacing(const double lineSpacing, WPXUnit unit=WPX_PERCENT);
00217 void setParagraphJustification(libwps::Justification justification, bool force=false);
00219 void setParagraphTextIndent(double margin);
00224 void setParagraphMargin(double margin, int pos);
00228 void setTabs(const std::vector<WPSTabStop> &tabStops);
00235 void setParagraphBorders(int which, libwps::BorderStyle style=libwps::BorderSingle, int width=1, uint32_t color=0);
00236
00237
00239 void setCurrentList(shared_ptr<WPSList> list);
00241 shared_ptr<WPSList> getCurrentList() const;
00244 void setCurrentListLevel(int level);
00245
00246
00248 enum FieldType { None, PageNumber, Date, Time, Title, Link, Database };
00250 void insertField(FieldType type);
00252 void insertDateTimeField(char const *format);
00253
00254
00256 enum NoteType { FOOTNOTE, ENDNOTE };
00258 void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
00260 void insertLabelNote(const NoteType noteType, WPXString const &label, WPSSubDocumentPtr &subDocument);
00262 void insertComment(WPSSubDocumentPtr &subDocument);
00263
00265 void insertPicture(WPSPosition const &pos, const WPXBinaryData &binaryData,
00266 std::string type="image/pict",
00267 WPXPropertyList frameExtras=WPXPropertyList());
00269 void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
00270 WPXPropertyList frameExtras=WPXPropertyList());
00271
00272
00273
00275 void openTable(std::vector<float> const &colWidth, WPXUnit unit);
00277 void closeTable();
00279 void openTableRow(float h, WPXUnit unit, bool headerRow=false);
00281 void closeTableRow();
00285 void openTableCell(WPSCell const &cell, WPXPropertyList const &extras);
00287 void closeTableCell();
00288
00289
00291 bool isSectionOpened() const;
00293 bool openSection(std::vector<int> colsWidth=std::vector<int>(), WPXUnit unit=WPX_INCH);
00295 bool closeSection();
00296
00297 protected:
00298 void _openSection();
00299 void _closeSection();
00300
00301 void _openPageSpan();
00302 void _closePageSpan();
00303 void _updatePageSpanDependent(bool set);
00304 void _recomputeParagraphPositions();
00305
00306 void _startSubDocument();
00307 void _endSubDocument();
00308
00309 void _handleFrameParameters( WPXPropertyList &propList, WPSPosition const &pos);
00310 bool _openFrame(WPSPosition const &pos, WPXPropertyList extras=WPXPropertyList());
00311 void _closeFrame();
00312
00313 void _openParagraph();
00314 void _closeParagraph();
00315 void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
00316 void _getTabStops(WPXPropertyListVector &tabStops);
00317 void _appendJustification(WPXPropertyList &propList, libwps::Justification justification);
00318 void _resetParagraphState(const bool isListElement=false);
00319
00320 void _openListElement();
00321 void _closeListElement();
00322 void _changeList();
00323
00324 void _openSpan();
00325 void _closeSpan();
00326
00327 void _flushText();
00328 void _flushDeferredTabs();
00329
00330 void _insertBreakIfNecessary(WPXPropertyList &propList);
00331
00332 static void _addLanguage(int lcid, WPXPropertyList &propList);
00333
00337 shared_ptr<WPSContentParsingState> _pushParsingState();
00339 void _popParsingState();
00340
00341 protected:
00342 shared_ptr<WPSDocumentParsingState> m_ds;
00343 shared_ptr<WPSContentParsingState> m_ps;
00344 std::vector<shared_ptr<WPSContentParsingState> > m_psStack;
00345 WPXDocumentInterface *m_documentInterface;
00346
00347 private:
00348 WPSContentListener(const WPSContentListener &);
00349 WPSContentListener &operator=(const WPSContentListener &);
00350 };
00351
00352 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
00353
00354 #endif
00355