STOFFTextListener.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 /* libstoff
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 
00034 #ifndef STOFF_TEXT_LISTENER_H
00035 #define STOFF_TEXT_LISTENER_H
00036 
00037 #include <vector>
00038 
00039 #include <librevenge/librevenge.h>
00040 
00041 #include "libstaroffice_internal.hxx"
00042 
00043 #include "STOFFGraphicStyle.hxx"
00044 
00045 #include "STOFFListener.hxx"
00046 
00047 class STOFFTextShape;
00048 
00049 namespace STOFFTextListenerInternal
00050 {
00051 struct TextState;
00052 struct State;
00053 }
00054 
00059 class STOFFTextListener : public STOFFListener
00060 {
00061 public:
00063   STOFFTextListener(STOFFListManagerPtr listManager, std::vector<STOFFPageSpan> const &pageList, librevenge::RVNGTextInterface *documentInterface);
00065   virtual ~STOFFTextListener();
00066 
00068   Type getType() const
00069   {
00070     return Text;
00071   }
00072 
00074   void setDocumentLanguage(std::string locale);
00076   void setDocumentMetaData(const librevenge::RVNGPropertyList &list);
00078   void startDocument();
00080   void endDocument(bool sendDelayedSubDoc=true);
00081 
00082   // ------ general information --------
00084   bool canWriteText() const
00085   {
00086     return STOFFTextListener::isDocumentStarted();
00087   }
00088 
00090   bool isDocumentStarted() const;
00091 
00093   void handleSubDocument(STOFFSubDocumentPtr subDocument, libstoff::SubDocumentType subDocumentType);
00095   bool isSubDocumentOpened(libstoff::SubDocumentType &subdocType) const;
00097   bool openFrame(STOFFPosition const &pos, STOFFGraphicStyle const &style=STOFFGraphicStyle());
00099   void closeFrame();
00101   bool openGroup(STOFFPosition const &pos);
00103   void closeGroup();
00105   bool openLayer(librevenge::RVNGString const &name);
00107   void closeLayer();
00108 
00109   // ------ page --------
00111   bool openMasterPage(STOFFPageSpan &/*masterPage*/);
00113   void closeMasterPage()
00114   {
00115   }
00117   bool isPageSpanOpened() const;
00121   STOFFPageSpan const &getPageSpan();
00122 
00123   // ------ header/footer --------
00125   bool openHeader(librevenge::RVNGPropertyList const &extras);
00127   bool openFooter(librevenge::RVNGPropertyList const &extras);
00129   bool closeHeader();
00131   bool closeFooter();
00133   bool insertHeaderRegion(STOFFSubDocumentPtr subDocument, librevenge::RVNGString const &which);
00135   bool insertFooterRegion(STOFFSubDocumentPtr subDocument, librevenge::RVNGString const &which);
00137   bool isHeaderFooterOpened() const;
00138 
00139   // ------ text data -----------
00141   void insertChar(uint8_t character);
00146   void insertUnicode(uint32_t character);
00148   void insertUnicodeString(librevenge::RVNGString const &str);
00149 
00151   void insertTab();
00153   void insertEOL(bool softBreak=false);
00154 
00155   // ------ text format -----------
00157   void setFont(STOFFFont const &font);
00159   STOFFFont const &getFont() const;
00160 
00161   // ------ paragraph format -----------
00163   bool isParagraphOpened() const;
00165   void setParagraph(STOFFParagraph const &paragraph);
00167   STOFFParagraph const &getParagraph() const;
00168 
00169   // ------ style definition -----------
00171   void defineStyle(STOFFFont const &style);
00173   bool isFontStyleDefined(librevenge::RVNGString const &name) const;
00175   void defineStyle(STOFFGraphicStyle const &style);
00177   bool isGraphicStyleDefined(librevenge::RVNGString const &name) const;
00179   void defineStyle(STOFFParagraph const &style);
00181   bool isParagraphStyleDefined(librevenge::RVNGString const &name) const;
00182 
00183   // ------- fields ----------------
00185   void insertField(STOFFField const &field);
00186 
00187   // ------- link ----------------
00189   void openLink(STOFFLink const &link);
00191   void closeLink();
00192 
00193   // ------- subdocument -----------------
00195   void insertShape(STOFFGraphicShape const &shape, STOFFGraphicStyle const &style, STOFFPosition const &pos);
00197   void insertTextBox(STOFFPosition const &pos, STOFFSubDocumentPtr subDocument, STOFFGraphicStyle const &style=STOFFGraphicStyle());
00199   void insertPicture(STOFFPosition const &pos, STOFFEmbeddedObject const &picture,
00200                      STOFFGraphicStyle const &style=STOFFGraphicStyle());
00202   void insertNote(STOFFNote const &note, STOFFSubDocumentPtr &subDocument);
00204   void insertComment(STOFFSubDocumentPtr &subDocument, librevenge::RVNGString const &creator="", librevenge::RVNGString const &date="");
00205 
00206   // ------- table -----------------
00207 
00209   void insertTable(STOFFPosition const &pos, STOFFTable &table, STOFFGraphicStyle const &style=STOFFGraphicStyle());
00211   void openTable(STOFFTable const &table);
00213   void openTable(STOFFPosition const &pos, STOFFTable const &table);
00215   void closeTable();
00217   void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
00219   void closeTableRow();
00221   void openTableCell(STOFFCell const &cell);
00223   void closeTableCell();
00225   void addEmptyTableCell(STOFFVec2i const &pos, STOFFVec2i span=STOFFVec2i(1,1));
00226 
00227   // ------- section ---------------
00228 
00230   bool canOpenSectionAddBreak() const;
00232   bool isSectionOpened() const;
00234   STOFFSection const &getSection() const;
00236   bool openSection(STOFFSection const &section);
00238   bool closeSection();
00240   void insertBreak(BreakType breakType);
00241 
00242 protected:
00244   void _openSection();
00246   void _closeSection();
00248   void _openPageSpan(bool sendHeaderFooters=true);
00250   void _closePageSpan();
00251 
00252   void _startSubDocument();
00253   void _endSubDocument();
00254 
00258   void _handleFrameParameters(librevenge::RVNGPropertyList &propList, STOFFPosition const &pos, STOFFGraphicStyle const &style);
00259 
00260   void _openParagraph();
00261   void _closeParagraph();
00262   void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
00263   void _resetParagraphState(const bool isListElement=false);
00264 
00266   void _openListElement();
00268   void _closeListElement();
00270   void _changeList();
00275   int _getListId() const;
00276 
00278   void _openSpan();
00280   void _closeSpan();
00281 
00283   void _flushText();
00285   void _flushDeferredTabs();
00286 
00287   void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
00288 
00292   shared_ptr<STOFFTextListenerInternal::State> _pushParsingState();
00294   void _popParsingState();
00295 
00296 protected:
00298   shared_ptr<STOFFTextListenerInternal::TextState> m_ds;
00300   shared_ptr<STOFFTextListenerInternal::State> m_ps;
00302   std::vector<shared_ptr<STOFFTextListenerInternal::State> > m_psStack;
00304   librevenge::RVNGTextInterface *m_documentInterface;
00305 
00306 private:
00307   STOFFTextListener(const STOFFTextListener &);
00308   STOFFTextListener &operator=(const STOFFTextListener &);
00309 };
00310 
00311 #endif
00312 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: