| 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 WPS4_H |
| 23 | #define WPS4_H |
| 24 | |
| 25 | #include <vector> |
| 26 | |
| 27 | #include <librevenge-stream/librevenge-stream.h> |
| 28 | #include "libwps_internal.h" |
| 29 | #include "libwps_tools_win.h" |
| 30 | |
| 31 | #include "WPSParser.h" |
| 32 | |
| 33 | class WPSPageSpan; |
| 34 | |
| 35 | namespace WPS4ParserInternal |
| 36 | { |
| 37 | class SubDocument; |
| 38 | struct State; |
| 39 | } |
| 40 | |
| 41 | class WPS4Graph; |
| 42 | class WPS4Text; |
| 43 | |
| 44 | /** |
| 45 | * This class parses Works version 2 through 4. |
| 46 | * |
| 47 | */ |
| 48 | class WPS4Parser final : public WPSParser |
| 49 | { |
| 50 | friend class WPS4ParserInternal::SubDocument; |
| 51 | friend class WPS4Graph; |
| 52 | friend class WPS4Text; |
| 53 | |
| 54 | public: |
| 55 | //! constructor |
| 56 | WPS4Parser(RVNGInputStreamPtr &input, WPSHeaderPtr &header, |
| 57 | libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::UNKNOWN); |
| 58 | //! destructor |
| 59 | ~WPS4Parser() final; |
| 60 | //! called by WPSDocument to parse the file |
| 61 | void parse(librevenge::RVNGTextInterface *documentInterface) final; |
| 62 | //! checks if the document header is correct (or not) |
| 63 | bool checkHeader(WPSHeader *header, bool strict=false); |
| 64 | protected: |
| 65 | //! color |
| 66 | bool getColor(int id, WPSColor &color) const; |
| 67 | |
| 68 | //! sets the file size ( filled by WPS4Text ) |
| 69 | void setSizeFile(long sz); |
| 70 | //! return true if the pos is in the file, update the file size if need |
| 71 | bool checkFilePosition(long pos); |
| 72 | |
| 73 | //! adds a new page |
| 74 | void newPage(int number); |
| 75 | //! set the listener |
| 76 | void setListener(std::shared_ptr<WPSContentListener> const &listener); |
| 77 | |
| 78 | /** tries to parse the main zone, ... */ |
| 79 | bool createStructures(); |
| 80 | /** tries to parse the different OLE zones ( except the main zone ) */ |
| 81 | bool createOLEStructures(); |
| 82 | /** creates the main listener */ |
| 83 | std::shared_ptr<WPSContentListener> createListener(librevenge::RVNGTextInterface *interface); |
| 84 | |
| 85 | // interface with text parser |
| 86 | |
| 87 | //! returns the page height, ie. paper size less margin (in inches) |
| 88 | float pageHeight() const; |
| 89 | //! returns the page width, ie. paper size less margin (in inches) |
| 90 | float pageWidth() const; |
| 91 | //! returns the number of columns |
| 92 | int numColumns() const; |
| 93 | /** returns the default font type, ie. the encoding given by the constructor if given |
| 94 | or the encoding deduiced from the version. |
| 95 | */ |
| 96 | libwps_tools_win::Font::Type getDefaultFontType() const; |
| 97 | //! returns the document codepage ( given from the file OEM field ) |
| 98 | libwps_tools_win::Font::Type getOEMFontType() const; |
| 99 | |
| 100 | /** creates a document for a comment entry and then send the data |
| 101 | * |
| 102 | * \note actually all bookmarks (comments) are empty */ |
| 103 | void createDocument(WPSEntry const &entry, libwps::SubDocumentType type); |
| 104 | /** creates a document for a footnote entry with label and then send the data*/ |
| 105 | void createNote(WPSEntry const &entry, librevenge::RVNGString const &label); |
| 106 | //! creates a textbox and then send the data |
| 107 | void createTextBox(WPSEntry const &entry, WPSPosition const &pos, librevenge::RVNGPropertyList const &extras); |
| 108 | //! sends text corresponding to the entry to the listener (via WPS4Text) |
| 109 | void send(WPSEntry const &entry, libwps::SubDocumentType type); |
| 110 | |
| 111 | // interface with graph parser |
| 112 | |
| 113 | /** tries to read a picture ( via its WPS4Graph ) |
| 114 | * |
| 115 | * \note returns the object id or -1 if find nothing */ |
| 116 | int readObject(RVNGInputStreamPtr input, WPSEntry const &entry); |
| 117 | |
| 118 | /** sends an object with given id ( via its WPS4Graph ) |
| 119 | * |
| 120 | * The object is sent as a character with given size \a position */ |
| 121 | void sendObject(WPSPosition const &position, int id); |
| 122 | |
| 123 | // |
| 124 | // low level |
| 125 | // |
| 126 | |
| 127 | /** finds the different zones (text, print, ...) and updates nameMultiMap */ |
| 128 | bool findZones(); |
| 129 | |
| 130 | /** parses an entry |
| 131 | * |
| 132 | * reads a zone offset and a zone size and checks if this entry is valid */ |
| 133 | bool parseEntry(std::string const &name); |
| 134 | |
| 135 | /** tries to read the document dimension */ |
| 136 | bool readDocDim(); |
| 137 | |
| 138 | /// tries to read the printer information |
| 139 | bool readPrnt(WPSEntry const &entry); |
| 140 | |
| 141 | /** reads the additional windows info |
| 142 | |
| 143 | \note this zone contains many unknown data |
| 144 | */ |
| 145 | bool readDocWindowsInfo(WPSEntry const &entry); |
| 146 | |
| 147 | std::shared_ptr<WPSContentListener> m_listener; /* the listener (if set)*/ |
| 148 | //! the graph parser |
| 149 | std::shared_ptr<WPS4Graph> m_graphParser; |
| 150 | //! the text parser |
| 151 | std::shared_ptr<WPS4Text> m_textParser; |
| 152 | //! the internal state |
| 153 | std::shared_ptr<WPS4ParserInternal::State> m_state; |
| 154 | }; |
| 155 | |
| 156 | #endif /* WPS4_H */ |
| 157 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |