MWAWGraphicListener.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 
00034 #ifndef MWAW_GRAPHIC_LISTENER_H
00035 #define MWAW_GRAPHIC_LISTENER_H
00036 
00037 #include <vector>
00038 
00039 #include <librevenge/librevenge.h>
00040 
00041 #include "libmwaw_internal.hxx"
00042 
00043 #include "MWAWGraphicStyle.hxx"
00044 
00045 #include "MWAWListener.hxx"
00046 
00047 class MWAWGraphicShape;
00048 
00049 namespace MWAWGraphicListenerInternal
00050 {
00051 struct GraphicState;
00052 struct State;
00053 }
00054 
00059 class MWAWGraphicListener : public MWAWListener
00060 {
00061 public:
00063   MWAWGraphicListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGDrawingInterface *documentInterface);
00067   MWAWGraphicListener(MWAWParserState &parserState, MWAWBox2f const &box, librevenge::RVNGDrawingInterface *documentInterface);
00069   virtual ~MWAWGraphicListener();
00070 
00072   Type getType() const
00073   {
00074     return Graphic;
00075   }
00076 
00078   void setDocumentLanguage(std::string locale);
00080   void startDocument();
00082   void endDocument(bool delayed=true);
00083 
00084   // ------ general information --------
00086   bool canWriteText() const;
00088   bool isDocumentStarted() const;
00089 
00091   void handleSubDocument(MWAWVec2f const &orig, MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
00093   void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType)
00094   {
00095     handleSubDocument(MWAWVec2f(0,0), subDocument, subDocumentType);
00096   }
00098   bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
00100   bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00102   void closeFrame();
00104   bool openGroup(MWAWPosition const &pos);
00106   void closeGroup();
00108   bool openLayer(librevenge::RVNGString const &name);
00110   void closeLayer();
00111 
00112   // ------ page --------
00114   bool openMasterPage(MWAWPageSpan &masterPage);
00116   void closeMasterPage()
00117   {
00118     _closePageSpan(true);
00119   }
00121   bool isPageSpanOpened() const;
00125   MWAWPageSpan const &getPageSpan();
00126 
00127   // ------ header/footer --------
00129   bool insertHeader(MWAWSubDocumentPtr subDocument, librevenge::RVNGPropertyList const &extras);
00131   bool insertFooter(MWAWSubDocumentPtr subDocument, librevenge::RVNGPropertyList const &extras);
00133   bool isHeaderFooterOpened() const;
00134 
00135   // ------ text data -----------
00137   void insertChar(uint8_t character);
00140   void insertCharacter(unsigned char c);
00146   int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
00149   void insertUnicode(uint32_t character);
00151   void insertUnicodeString(librevenge::RVNGString const &str);
00152 
00154   void insertTab();
00156   void insertEOL(bool softBreak=false);
00157 
00158   // ------ text format -----------
00160   void setFont(MWAWFont const &font);
00162   MWAWFont const &getFont() const;
00163 
00164   // ------ paragraph format -----------
00166   bool isParagraphOpened() const;
00168   void setParagraph(MWAWParagraph const &paragraph);
00170   MWAWParagraph const &getParagraph() const;
00171 
00172   // ------- fields ----------------
00174   void insertField(MWAWField const &field);
00175 
00176   // ------- link ----------------
00178   void openLink(MWAWLink const &link);
00180   void closeLink();
00181 
00182   // ------- subdocument -----------------
00184   void insertPicture(MWAWPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
00185                      std::string type="image/pict", MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00187   void insertPicture(MWAWPosition const &pos, MWAWGraphicShape const &shape, MWAWGraphicStyle const &style);
00189   void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument, MWAWGraphicStyle const &style);
00191   void insertGroup(MWAWBox2f const &bdbox, MWAWSubDocumentPtr subDocument);
00195   void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
00199   void insertComment(MWAWSubDocumentPtr &subDocument);
00200 
00201   // ------- table -----------------
00202 
00204   void insertTable(MWAWPosition const &pos, MWAWTable &table, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle());
00206   void openTable(MWAWTable const &table);
00208   void openTable(MWAWPosition const &pos, MWAWTable const &table, MWAWGraphicStyle const &style);
00210   void closeTable();
00212   void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
00214   void closeTableRow();
00216   void openTableCell(MWAWCell const &cell);
00218   void closeTableCell();
00220   void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1));
00221 
00222   // ------- section ---------------
00223 
00225   bool canOpenSectionAddBreak() const
00226   {
00227     return false;
00228   }
00230   bool isSectionOpened() const
00231   {
00232     return false;
00233   }
00235   MWAWSection const &getSection() const;
00237   bool openSection(MWAWSection const &section);
00239   bool closeSection()
00240   {
00241     return false;
00242   }
00244   void insertBreak(BreakType breakType);
00245 
00246 protected:
00248   void _openPageSpan(bool sendHeaderFooters=true);
00250   void _closePageSpan(bool masterPage=false);
00251 
00252   void _startSubDocument();
00253   void _endSubDocument();
00254 
00258   void _handleFrameParameters(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos, MWAWGraphicStyle const &style);
00259 
00260   void _openParagraph();
00261   void _closeParagraph();
00262   void _resetParagraphState(const bool isListElement=false);
00263 
00265   void _openListElement();
00267   void _closeListElement();
00269   void _changeList();
00274   int _getListId() const;
00275 
00276   void _openSpan();
00277   void _closeSpan();
00278 
00279   void _flushText();
00280 
00284   shared_ptr<MWAWGraphicListenerInternal::State> _pushParsingState();
00286   void _popParsingState();
00287 
00288 protected:
00290   shared_ptr<MWAWGraphicListenerInternal::GraphicState> m_ds;
00292   shared_ptr<MWAWGraphicListenerInternal::State> m_ps;
00294   std::vector<shared_ptr<MWAWGraphicListenerInternal::State> > m_psStack;
00296   MWAWParserState &m_parserState;
00298   librevenge::RVNGDrawingInterface *m_documentInterface;
00299 
00300 private:
00301   MWAWGraphicListener(const MWAWGraphicListener &);
00302   MWAWGraphicListener &operator=(const MWAWGraphicListener &);
00303 };
00304 
00305 #endif
00306 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: