| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | /* libwps |
| 3 | * Version: MPL 2.0 / LGPLv2.1+ |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * Major Contributor(s): |
| 10 | * Copyright (C) 2009, 2011 Alonso Laurent ([email protected]) |
| 11 | * Copyright (C) 2006, 2007 Andrew Ziem |
| 12 | * Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 13 | * Copyright (C) 2004 Marc Maurer ([email protected]) |
| 14 | * Copyright (C) 2003-2005 William Lachance ([email protected]) |
| 15 | * |
| 16 | * For minor contributions see the git repository. |
| 17 | * |
| 18 | * Alternatively, the contents of this file may be used under the terms |
| 19 | * of the GNU Lesser General Public License Version 2.1 or later |
| 20 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 21 | * applicable instead of those above. |
| 22 | * |
| 23 | * For further information visit http://libwps.sourceforge.net |
| 24 | */ |
| 25 | |
| 26 | #ifndef WPS4_GRAPH |
| 27 | # define WPS4_GRAPH |
| 28 | |
| 29 | #include <map> |
| 30 | #include <vector> |
| 31 | |
| 32 | #include "libwps_internal.h" |
| 33 | |
| 34 | #include "WPSDebug.h" |
| 35 | |
| 36 | class WPS4Parser; |
| 37 | |
| 38 | namespace WPS4GraphInternal |
| 39 | { |
| 40 | struct State; |
| 41 | } |
| 42 | |
| 43 | //////////////////////////////////////////////////////////// |
| 44 | // |
| 45 | // class to parse the object |
| 46 | // |
| 47 | //////////////////////////////////////////////////////////// |
| 48 | |
| 49 | /** \brief the main class to read/store picture in a Pc MS Works document v1-4 |
| 50 | * |
| 51 | * This class must be associated with a WPS4Parser. |
| 52 | * \note As the pictures seems always be given with character' position, many functions |
| 53 | * which exists to maintain the same structures that exist(will) in WPS8TextGraph class |
| 54 | * do almost nothing. |
| 55 | */ |
| 56 | class WPS4Graph |
| 57 | { |
| 58 | friend class WPS4Parser; |
| 59 | public: |
| 60 | //! constructor given the main parser of the MN0 zone |
| 61 | explicit WPS4Graph(WPS4Parser &parser); |
| 62 | |
| 63 | //! destructor |
| 64 | ~WPS4Graph(); |
| 65 | |
| 66 | //! sets the listener |
| 67 | void setListener(WPSContentListenerPtr &listen) |
| 68 | { |
| 69 | m_listener = listen; |
| 70 | } |
| 71 | |
| 72 | /** computes the position of all found figures. |
| 73 | * |
| 74 | * In reality, as all the pictures seemed to be given with characters positions, |
| 75 | * it does almost nothing, ie it only updates some internal bool to know the picture which |
| 76 | * have been sent to the listener. |
| 77 | */ |
| 78 | void computePositions() const; |
| 79 | |
| 80 | //! returns the number page where we find a picture. In practice, 0/1 |
| 81 | int numPages() const; |
| 82 | |
| 83 | protected: |
| 84 | //! returns the file version |
| 85 | int version() const; |
| 86 | |
| 87 | //! store a list of object |
| 88 | void storeObjects(std::map<int,WPSEmbeddedObject> const &objectsMap); |
| 89 | |
| 90 | /** tries to find a picture in the zone pointed by \a entry |
| 91 | * \return the object id or -1 if find nothing |
| 92 | * \note the content of this zone is mainly unknown, |
| 93 | * so this function may failed to retrieved valid data |
| 94 | */ |
| 95 | int readObject(RVNGInputStreamPtr input, WPSEntry const &entry); |
| 96 | |
| 97 | //! sends an object with identificator \a id as a character to a given pposition |
| 98 | void sendObject(WPSPosition const &position, int id); |
| 99 | |
| 100 | /** send all the objects of a given page: |
| 101 | * \param page if page < 0, sends all the pictures which have not been used, |
| 102 | * |
| 103 | * As all the pictures seemed to be given with characters positions, this |
| 104 | * function only does something if page < 0. |
| 105 | */ |
| 106 | void sendObjects(int page); |
| 107 | |
| 108 | //! returns the debug file |
| 109 | libwps::DebugFile &ascii() |
| 110 | { |
| 111 | return m_asciiFile; |
| 112 | } |
| 113 | |
| 114 | private: |
| 115 | WPS4Graph(WPS4Graph const &orig) = delete; |
| 116 | WPS4Graph &operator=(WPS4Graph const &orig) = delete; |
| 117 | protected: |
| 118 | //! the listener |
| 119 | WPSContentListenerPtr m_listener; |
| 120 | |
| 121 | //! the main parser |
| 122 | WPS4Parser &m_mainParser; |
| 123 | |
| 124 | //! the state |
| 125 | mutable std::shared_ptr<WPS4GraphInternal::State> m_state; |
| 126 | |
| 127 | //! the ascii file |
| 128 | libwps::DebugFile &m_asciiFile; |
| 129 | }; |
| 130 | |
| 131 | #endif |
| 132 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |
| 133 |