| 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) 2006, 2007 Andrew Ziem |
| 11 | * Copyright (C) 2003-2005 William Lachance ([email protected]) |
| 12 | * Copyright (C) 2003 Marc Maurer ([email protected]) |
| 13 | * |
| 14 | * For minor contributions see the git repository. |
| 15 | * |
| 16 | * Alternatively, the contents of this file may be used under the terms |
| 17 | * of the GNU Lesser General Public License Version 2.1 or later |
| 18 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 19 | * applicable instead of those above. |
| 20 | */ |
| 21 | |
| 22 | #ifndef WPS8_H |
| 23 | #define WPS8_H |
| 24 | |
| 25 | #include <deque> |
| 26 | #include <vector> |
| 27 | |
| 28 | #include <librevenge/librevenge.h> |
| 29 | |
| 30 | #include "libwps_internal.h" |
| 31 | #include "WPSParser.h" |
| 32 | |
| 33 | class WPSPageSpan; |
| 34 | |
| 35 | namespace WPS8ParserInternal |
| 36 | { |
| 37 | class SubDocument; |
| 38 | struct State; |
| 39 | } |
| 40 | |
| 41 | class WPS8Graph; |
| 42 | class WPS8Table; |
| 43 | class WPS8Text; |
| 44 | |
| 45 | /** |
| 46 | * This class parses Works version 2000 through 8. |
| 47 | * |
| 48 | */ |
| 49 | class WPS8Parser final : public WPSParser |
| 50 | { |
| 51 | friend class WPS8ParserInternal::SubDocument; |
| 52 | friend class WPS8Graph; |
| 53 | friend class WPS8Table; |
| 54 | friend class WPS8Text; |
| 55 | |
| 56 | public: |
| 57 | //! constructor |
| 58 | WPS8Parser(RVNGInputStreamPtr &input, WPSHeaderPtr &header); |
| 59 | //! destructor |
| 60 | ~WPS8Parser() final; |
| 61 | //! called by WPSDocument to parse the file |
| 62 | void parse(librevenge::RVNGTextInterface *documentInterface) final; |
| 63 | protected: |
| 64 | //! return true if the pos is in the file, update the file size if need |
| 65 | bool checkInFile(long pos); |
| 66 | |
| 67 | //! adds a new page |
| 68 | void newPage(int number); |
| 69 | //! set the listener |
| 70 | void setListener(std::shared_ptr<WPSContentListener> const &listener); |
| 71 | /** creates the main listener */ |
| 72 | std::shared_ptr<WPSContentListener> createListener(librevenge::RVNGTextInterface *interface); |
| 73 | |
| 74 | /** tries to parse the main zone, ... */ |
| 75 | bool createStructures(); |
| 76 | /** tries to parse the different OLE zones ( except the main zone ) */ |
| 77 | bool createOLEStructures(); |
| 78 | |
| 79 | //! returns the page height, ie. paper size less margin (in inches) |
| 80 | float pageHeight() const; |
| 81 | //! returns the page width, ie. paper size less margin (in inches) |
| 82 | float pageWidth() const; |
| 83 | //! returns the number of columns |
| 84 | int numColumns() const; |
| 85 | |
| 86 | //! send the frames which corresponds to a given page to the listener |
| 87 | void sendPageFrames(); |
| 88 | // interface with text parser |
| 89 | |
| 90 | //! creates a subdocument to send a textbox which correspond to the strsid text zone |
| 91 | void sendTextBox(WPSPosition const &pos, int strsid, |
| 92 | librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList()); |
| 93 | |
| 94 | //! sends text corresponding to the entry to the listener (via WPS8Text) |
| 95 | void send(WPSEntry const &entry); |
| 96 | //! sends text corresponding to the strsId to the listener (via WPS8Text) |
| 97 | void send(int strsId); |
| 98 | |
| 99 | //! send the text of a cell to a listener (via WPS8Text) |
| 100 | void sendTextInCell(int strsId, int cellId); |
| 101 | |
| 102 | // interface with table parser |
| 103 | |
| 104 | //! sends a table as a character with given size ( via its WPS8Table ) |
| 105 | bool sendTable(Vec2f const &size, int objectId); |
| 106 | //! retrieve the strsId corresponding to a table ( mainly for debug) |
| 107 | int getTableSTRSId(int tableId) const; |
| 108 | |
| 109 | // interface with graph parser |
| 110 | |
| 111 | /** sends an object as a character with given size (via its WPS8Graph ) |
| 112 | * |
| 113 | * \param size the size of the object in the document pages |
| 114 | * \param objectId the object identificator |
| 115 | * \param ole indicated if we look for objects coming from a ole zone or objects coming from a Pict zone */ |
| 116 | bool sendObject(Vec2f const &size, int objectId, bool ole); |
| 117 | |
| 118 | // |
| 119 | // low level |
| 120 | // |
| 121 | |
| 122 | //! parses an index entry |
| 123 | bool parseHeaderIndexEntry(); |
| 124 | /** function which is called, if some data remains after the basic content |
| 125 | of an entry: by default does nothing */ |
| 126 | bool parseHeaderIndexEntryEnd(long endPos, WPSEntry &hie,std::string &mess); |
| 127 | |
| 128 | /** tries to find the beginning of the list of indices, |
| 129 | * then try to find all entries in this list. |
| 130 | * |
| 131 | * Stores result in nameTable, offsetTable */ |
| 132 | bool parseHeaderIndex(); |
| 133 | |
| 134 | /** \brief reads the DOP zone: the document properties |
| 135 | * |
| 136 | * Contains the page dimension, the background picture, ... */ |
| 137 | bool readDocProperties(WPSEntry const &entry, WPSPageSpan &page); |
| 138 | |
| 139 | /** \brief reads the FRAM zone: ie a zone which can contains textbox, picture, ... |
| 140 | and have some borders */ |
| 141 | bool readFRAM(WPSEntry const &entry); |
| 142 | /** \brief reads the FRCD zone: ie a zone which can contains mailmerge data ? */ |
| 143 | bool readFRCD(WPSEntry const &entry); |
| 144 | |
| 145 | /** \brief parses a SYID zone |
| 146 | * |
| 147 | * an unknown zone which seems to have the same number of entries |
| 148 | * than the text zones (STRS) */ |
| 149 | bool readSYID(WPSEntry const &entry, std::vector<int> &listId); |
| 150 | |
| 151 | /** \brief parses the WNPR zone : a zone which seems to contain the printer preferences. |
| 152 | * |
| 153 | * \warning: read data are not used */ |
| 154 | bool readWNPR(WPSEntry const &entry); |
| 155 | |
| 156 | //! finds the structures of the Ole zone "SPELLING" |
| 157 | static bool readSPELLING(RVNGInputStreamPtr input, std::string const &oleName); |
| 158 | |
| 159 | std::shared_ptr<WPSContentListener> m_listener; /* the listener (if set)*/ |
| 160 | //! the graph parser |
| 161 | std::shared_ptr<WPS8Graph> m_graphParser; |
| 162 | //! the table parser |
| 163 | std::shared_ptr<WPS8Table> m_tableParser; |
| 164 | //! the text parser |
| 165 | std::shared_ptr<WPS8Text> m_textParser; |
| 166 | //! the internal state |
| 167 | std::shared_ptr<WPS8ParserInternal::State> m_state; |
| 168 | |
| 169 | private: |
| 170 | std::deque<int> m_sendingTables; |
| 171 | }; |
| 172 | |
| 173 | #endif /* WPS8_H */ |
| 174 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |