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 <libwpd/libwpd.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 
00060 class MWAWGraphicListener : public MWAWListener
00061 {
00062 public:
00064   MWAWGraphicListener(MWAWParserState &parserState);
00066   virtual ~MWAWGraphicListener();
00067 
00069   void startGraphic(Box2f const &bdbox);
00071   bool endGraphic(WPXBinaryData &data, std::string &mimeType);
00073   bool isDocumentStarted() const;
00074 
00076   void handleSubDocument(Vec2f const &orig, MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
00078   bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
00079 
00080   // ------ general information --------
00082   bool canWriteText() const;
00084   Box2f const &getGraphicBdBox();
00085 
00086   // ------ text data -----------
00088   void insertChar(uint8_t character);
00091   void insertCharacter(unsigned char c);
00097   int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
00100   void insertUnicode(uint32_t character);
00102   void insertUnicodeString(WPXString const &str);
00103 
00105   void insertTab();
00107   void insertEOL(bool softBreak=false);
00108 
00109   // ------ text format -----------
00111   void setFont(MWAWFont const &font);
00113   MWAWFont const &getFont() const;
00114 
00115   // ------ paragraph format -----------
00117   bool isParagraphOpened() const;
00119   void setParagraph(MWAWParagraph const &paragraph);
00121   MWAWParagraph const &getParagraph() const;
00122 
00123   // ------- fields ----------------
00125   void insertField(MWAWField const &field);
00126 
00127   // ------- subdocument -----------------
00129   void insertPicture(Box2f const &bdbox, MWAWGraphicStyle const &style,
00130                      const WPXBinaryData &binaryData, std::string type="image/pict");
00132   void insertPicture(Box2f const &bdbox, MWAWGraphicShape const &shape,
00133                      MWAWGraphicStyle const &style);
00135   void insertTextBox(Box2f const &bdbox, MWAWSubDocumentPtr subDocument, MWAWGraphicStyle const &style);
00137   void insertGroup(Box2f const &bdbox, MWAWSubDocumentPtr subDocument);
00138   // ------- section ---------------
00140   bool canOpenSectionAddBreak() const {
00141     return false;
00142   }
00144   bool isSectionOpened() const {
00145     return false;
00146   }
00148   MWAWSection const &getSection() const;
00150   bool openSection(MWAWSection const &section);
00152   bool closeSection() {
00153     return false;
00154   }
00156   void insertBreak(BreakType breakType);
00157 
00158 protected:
00159   void _startSubDocument();
00160   void _endSubDocument();
00161 
00162   void _handleFrameParameters(WPXPropertyList &propList, Box2f const &pos, MWAWGraphicStyle const &style);
00163   bool openFrame();
00164   void closeFrame();
00165 
00166 
00167   void _openParagraph();
00168   void _closeParagraph();
00169   void _resetParagraphState(const bool isListElement=false);
00170 
00172   void _openListElement();
00174   void _closeListElement();
00176   void _changeList();
00181   int _getListId() const;
00182 
00183   void _openSpan();
00184   void _closeSpan();
00185 
00186   void _flushText();
00187 
00191   shared_ptr<MWAWGraphicListenerInternal::State> _pushParsingState();
00193   void _popParsingState();
00194 
00195 protected:
00197   shared_ptr<MWAWGraphicListenerInternal::GraphicState> m_gs;
00199   shared_ptr<MWAWGraphicListenerInternal::State> m_ps;
00201   std::vector<shared_ptr<MWAWGraphicListenerInternal::State> > m_psStack;
00203   MWAWParserState &m_parserState;
00204 
00205 private:
00206   MWAWGraphicListener(const MWAWGraphicListener &);
00207   MWAWGraphicListener &operator=(const MWAWGraphicListener &);
00208 };
00209 
00210 #endif
00211 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: