MWAWTextListener.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libmwaw
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00040 #ifndef MWAW_TEXT_LISTENER_H
00041 #define MWAW_TEXT_LISTENER_H
00042 
00043 #include <vector>
00044 
00045 #include <librevenge/librevenge.h>
00046 
00047 #include "libmwaw_internal.hxx"
00048 #include "MWAWGraphicStyle.hxx"
00049 
00050 #include "MWAWListener.hxx"
00051 
00052 class MWAWCell;
00053 class MWAWGraphicStyle;
00054 class MWAWGraphicShape;
00055 class MWAWTable;
00056 
00057 namespace MWAWTextListenerInternal
00058 {
00059 struct DocumentState;
00060 struct State;
00061 }
00062 
00064 class MWAWTextListener : public MWAWListener
00065 {
00066 public:
00068   MWAWTextListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGTextInterface *documentInterface);
00070   virtual ~MWAWTextListener();
00071 
00073   Type getType() const
00074   {
00075     return Text;
00076   }
00077 
00079   void setDocumentLanguage(std::string locale);
00080 
00082   void startDocument();
00084   void endDocument(bool sendDelayedSubDoc=true);
00086   bool isDocumentStarted() const;
00087 
00089   void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
00091   bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
00093   bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00095   void closeFrame();
00096 
00098   bool canWriteText() const
00099   {
00100     return MWAWTextListener::isDocumentStarted();
00101   }
00102 
00103   // ------ page --------
00105   bool isPageSpanOpened() const;
00109   MWAWPageSpan const &getPageSpan();
00110 
00111   // ------ header/footer --------
00113   bool insertHeader(MWAWSubDocumentPtr subDocument, librevenge::RVNGPropertyList const &extras);
00115   bool insertFooter(MWAWSubDocumentPtr subDocument, librevenge::RVNGPropertyList const &extras);
00117   bool isHeaderFooterOpened() const;
00118 
00119   // ------ text data -----------
00120 
00122   void insertChar(uint8_t character);
00125   void insertCharacter(unsigned char c);
00131   int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
00134   void insertUnicode(uint32_t character);
00136   void insertUnicodeString(librevenge::RVNGString const &str);
00137 
00139   void insertTab();
00141   void insertEOL(bool softBreak=false);
00142 
00143   // ------ text format -----------
00145   void setFont(MWAWFont const &font);
00147   MWAWFont const &getFont() const;
00148 
00149   // ------ paragraph format -----------
00151   bool isParagraphOpened() const;
00153   void setParagraph(MWAWParagraph const &paragraph);
00155   MWAWParagraph const &getParagraph() const;
00156 
00157   // ------- fields ----------------
00159   void insertField(MWAWField const &field);
00160 
00161   // ------- link ----------------
00163   void openLink(MWAWLink const &link);
00165   void closeLink();
00166 
00167   // ------- subdocument -----------------
00169   void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
00170 
00172   void insertComment(MWAWSubDocumentPtr &subDocument);
00173 
00175   void insertPicture(MWAWPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
00176                      std::string type="image/pict", MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00178   void insertPicture(MWAWPosition const &pos, MWAWGraphicShape const &shape,
00179                      MWAWGraphicStyle const &style);
00181   void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
00182                      MWAWGraphicStyle const &frameStyle=MWAWGraphicStyle::emptyStyle());
00183 
00184   // ------- table -----------------
00186   void openTable(MWAWTable const &table);
00188   void closeTable();
00190   void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
00192   void closeTableRow();
00194   void openTableCell(MWAWCell const &cell);
00196   void closeTableCell();
00198   void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1));
00199 
00200   // ------- section ---------------
00202   bool canOpenSectionAddBreak() const;
00204   bool isSectionOpened() const;
00206   MWAWSection const &getSection() const;
00208   bool openSection(MWAWSection const &section);
00210   bool closeSection();
00212   void insertBreak(BreakType breakType);
00213 
00214 protected:
00216   void _openSection();
00218   void _closeSection();
00220   void _openPageSpan(bool sendHeaderFooters=true);
00222   void _closePageSpan();
00223 
00224   void _startSubDocument();
00225   void _endSubDocument();
00226 
00227   void _handleFrameParameters(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos);
00228 
00229   void _openParagraph();
00230   void _closeParagraph();
00231   void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
00232   void _resetParagraphState(const bool isListElement=false);
00233 
00235   void _openListElement();
00237   void _closeListElement();
00239   void _changeList();
00244   int _getListId() const;
00245 
00247   void _openSpan();
00249   void _closeSpan();
00250 
00252   void _flushText();
00254   void _flushDeferredTabs();
00255 
00256   void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
00257 
00261   shared_ptr<MWAWTextListenerInternal::State> _pushParsingState();
00263   void _popParsingState();
00264 
00265 protected:
00267   shared_ptr<MWAWTextListenerInternal::DocumentState> m_ds;
00269   shared_ptr<MWAWTextListenerInternal::State> m_ps;
00271   std::vector<shared_ptr<MWAWTextListenerInternal::State> > m_psStack;
00273   MWAWParserState &m_parserState;
00275   librevenge::RVNGTextInterface *m_documentInterface;
00276 
00277 private:
00279   MWAWTextListener(const MWAWTextListener &);
00281   MWAWTextListener &operator=(const MWAWTextListener &);
00282 };
00283 
00284 #endif
00285 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: