WPSContentListener.h
Go to the documentation of this file.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* libwps
* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Major Contributor(s):
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
* Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Lesser General Public License Version 2.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
*
* For further information visit http://libwps.sourceforge.net
*/
#ifndef WPSCONTENTLISTENER_H
#define WPSCONTENTLISTENER_H
#include <vector>
#include <libwpd/libwpd.h>
#include "libwps_internal.h"
class WPXBinaryData;
class WPXDocumentInterface;
class WPXString;
class WPXPropertyListVector;
class WPSCell;
class WPSList;
class WPSPageSpan;
class WPSPosition;
class WPSSubDocument;
struct WPSTabStop;
typedef shared_ptr<WPSSubDocument> WPSSubDocumentPtr;
struct WPSDocumentParsingState
{
WPSDocumentParsingState(std::vector<WPSPageSpan> const &pageList);
~WPSDocumentParsingState();
std::vector<WPSPageSpan> m_pageList;
WPXPropertyList m_metaData;
int m_footNoteNumber , m_endNoteNumber ;
int m_newListId; // a new free id
bool m_isDocumentStarted, m_isHeaderFooterStarted;
std::vector<WPSSubDocumentPtr> m_subDocuments;
private:
WPSDocumentParsingState(const WPSDocumentParsingState &);
WPSDocumentParsingState &operator=(const WPSDocumentParsingState &);
};
struct WPSContentParsingState
{
WPSContentParsingState();
~WPSContentParsingState();
WPXString m_textBuffer;
int m_numDeferredTabs;
uint32_t m_textAttributeBits;
double m_fontSize;
WPXString m_fontName;
uint32_t m_fontColor;
int m_textLanguage;
bool m_isParagraphColumnBreak;
bool m_isParagraphPageBreak;
libwps::Justification m_paragraphJustification;
double m_paragraphLineSpacing;
WPXUnit m_paragraphLineSpacingUnit;
uint32_t m_paragraphBackgroundColor;
int m_paragraphBorders;
WPSBorder m_paragraphBordersStyle;
shared_ptr<WPSList> m_list;
uint8_t m_currentListLevel;
bool m_isPageSpanOpened;
bool m_isSectionOpened;
bool m_isFrameOpened;
bool m_isPageSpanBreakDeferred;
bool m_isHeaderFooterWithoutParagraph;
bool m_isSpanOpened;
bool m_isParagraphOpened;
bool m_isListElementOpened;
bool m_firstParagraphInPageSpan;
std::vector<unsigned int> m_numRowsToSkip;
bool m_isTableOpened;
bool m_isTableRowOpened;
bool m_isTableColumnOpened;
bool m_isTableCellOpened;
unsigned m_currentPage;
int m_numPagesRemainingInSpan;
int m_currentPageNumber;
bool m_sectionAttributesChanged;
int m_numColumns;
std::vector < WPSColumnDefinition > m_textColumns;
bool m_isTextColumnWithoutParagraph;
double m_pageFormLength;
double m_pageFormWidth;
bool m_pageFormOrientationIsPortrait;
double m_pageMarginLeft;
double m_pageMarginRight;
double m_pageMarginTop;
double m_pageMarginBottom;
double m_sectionMarginLeft; // In multicolumn sections, the above two will be rather interpreted
double m_sectionMarginRight; // as section margin change
double m_sectionMarginTop;
double m_sectionMarginBottom;
double m_paragraphMarginLeft; // resulting paragraph margin that is one of the paragraph
double m_paragraphMarginRight; // properties
double m_paragraphMarginTop;
WPXUnit m_paragraphMarginTopUnit;
double m_paragraphMarginBottom;
WPXUnit m_paragraphMarginBottomUnit;
double m_leftMarginByPageMarginChange; // part of the margin due to the PAGE margin change
double m_rightMarginByPageMarginChange; // inside a page that already has content.
double m_leftMarginByParagraphMarginChange; // part of the margin due to the PARAGRAPH
double m_rightMarginByParagraphMarginChange; // margin change (in WP6)
double m_leftMarginByTabs; // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
double m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
double m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
double m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
double m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
double m_listReferencePosition; // position from the left page margin of the list number/bullet
double m_listBeginPosition; // position from the left page margin of the beginning of the list
std::vector<bool> m_listOrderedLevels;
uint16_t m_alignmentCharacter;
std::vector<WPSTabStop> m_tabStops;
bool m_isTabPositionRelative;
bool m_inSubDocument;
bool m_isNote;
libwps::SubDocumentType m_subDocumentType;
private:
WPSContentParsingState(const WPSContentParsingState &);
WPSContentParsingState &operator=(const WPSContentParsingState &);
};
class WPSContentListener
{
public:
WPSContentListener(std::vector<WPSPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
virtual ~WPSContentListener();
void setDocumentLanguage(int lcid);
void startDocument();
void endDocument();
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
bool isHeaderFooterOpened() const;
// ------ text data -----------
void insertCharacter(uint8_t character);
void insertUnicode(uint32_t character);
void insertUnicodeString(WPXString const &str);
static void appendUnicode(uint32_t val, WPXString &buffer);
void insertTab();
void insertEOL(bool softBreak=false);
void insertBreak(const uint8_t breakType);
// ------ text format -----------
void setTextFont(const WPXString &fontName);
void setFontSize(const uint16_t fontSize);
void setFontAttributes(const uint32_t fontAttributes);
void setTextLanguage(int lcid);
void setTextColor(const uint32_t rgb);
void setFont(const WPSFont &font);
// ------ paragraph format -----------
bool isParagraphOpened() const;
void setParagraphLineSpacing(const double lineSpacing, WPXUnit unit=WPX_PERCENT);
void setParagraphJustification(libwps::Justification justification, bool force=false);
void setParagraphTextIndent(double margin);
void setParagraphMargin(double margin, int pos);
void setTabs(const std::vector<WPSTabStop> &tabStops);
void setParagraphBackgroundColor(uint32_t color=0xFFFFFF);
void setParagraphBorders(int which, WPSBorder style=WPSBorder());
// ------ list format -----------
void setCurrentList(shared_ptr<WPSList> list);
shared_ptr<WPSList> getCurrentList() const;
void setCurrentListLevel(int level);
// ------- fields ----------------
enum FieldType { None, PageNumber, Date, Time, Title, Link, Database };
void insertField(FieldType type);
void insertDateTimeField(char const *format);
// ------- subdocument -----------------
enum NoteType { FOOTNOTE, ENDNOTE };
void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
void insertLabelNote(const NoteType noteType, WPXString const &label, WPSSubDocumentPtr &subDocument);
void insertComment(WPSSubDocumentPtr &subDocument);
void insertPicture(WPSPosition const &pos, const WPXBinaryData &binaryData,
std::string type="image/pict",
WPXPropertyList frameExtras=WPXPropertyList());
void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
WPXPropertyList frameExtras=WPXPropertyList());
// ------- table -----------------
void openTable(std::vector<float> const &colWidth, WPXUnit unit);
void closeTable();
void openTableRow(float h, WPXUnit unit, bool headerRow=false);
void closeTableRow();
void openTableCell(WPSCell const &cell, WPXPropertyList const &extras);
void closeTableCell();
void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
// ------- section ---------------
bool isSectionOpened() const;
int getSectionNumColumns() const;
bool openSection(std::vector<int> colsWidth=std::vector<int>(), WPXUnit unit=WPX_INCH);
bool closeSection();
protected:
void _openSection();
void _closeSection();
void _openPageSpan();
void _closePageSpan();
void _updatePageSpanDependent(bool set);
void _recomputeParagraphPositions();
void _startSubDocument();
void _endSubDocument();
void _handleFrameParameters( WPXPropertyList &propList, WPSPosition const &pos);
bool _openFrame(WPSPosition const &pos, WPXPropertyList extras=WPXPropertyList());
void _closeFrame();
void _openParagraph();
void _closeParagraph();
void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
void _getTabStops(WPXPropertyListVector &tabStops);
void _appendJustification(WPXPropertyList &propList, libwps::Justification justification);
void _resetParagraphState(const bool isListElement=false);
void _openListElement();
void _closeListElement();
void _changeList();
void _openSpan();
void _closeSpan();
void _flushText();
void _flushDeferredTabs();
void _insertBreakIfNecessary(WPXPropertyList &propList);
static void _addLanguage(int lcid, WPXPropertyList &propList);
shared_ptr<WPSContentParsingState> _pushParsingState();
void _popParsingState();
protected:
shared_ptr<WPSDocumentParsingState> m_ds; // main parse state
shared_ptr<WPSContentParsingState> m_ps; // parse state
std::vector<shared_ptr<WPSContentParsingState> > m_psStack;
WPXDocumentInterface *m_documentInterface;
private:
WPSContentListener(const WPSContentListener &);
WPSContentListener &operator=(const WPSContentListener &);
};
typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
#endif
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */