| 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_TEXT_H |
| 27 | #define WPS4_TEXT_H |
| 28 | |
| 29 | #include <vector> |
| 30 | |
| 31 | #include "libwps_internal.h" |
| 32 | #include "libwps_tools_win.h" |
| 33 | |
| 34 | #include "WPSEntry.h" |
| 35 | #include "WPSDebug.h" |
| 36 | #include "WPSTextParser.h" |
| 37 | |
| 38 | class WPS4Parser; |
| 39 | namespace WPS4TextInternal |
| 40 | { |
| 41 | struct Font; |
| 42 | struct State; |
| 43 | } |
| 44 | |
| 45 | /** The class which parses text zones in a pc MS Works document v1-4 |
| 46 | * |
| 47 | * This class must be associated with a WPS4Parser. It finds and reads: |
| 48 | * - TEXT[3] : the text limits ( header, footer, main text with notes) |
| 49 | * - SHdr, SFtr : a string to store header/footer in v1-2 (?) |
| 50 | * - BTEC : the fonts properties |
| 51 | * - BTEP : the paragraph properties |
| 52 | * - FONT : the font names |
| 53 | * - FTNp, FTNd : the footnote positions (text position and text of notes) |
| 54 | * - BKMK : a comment field ( contain a string ) |
| 55 | * - CHRT : a chart ( unknown format ) |
| 56 | * It reads: |
| 57 | * - DTTM : field contents ( only parsed) |
| 58 | * - EOBJ : the text position with the position and size of an object |
| 59 | * |
| 60 | * \note It also reads the size of the document because this size is stored |
| 61 | * between the "entries" which defines the text positions and the BTEC |
| 62 | * positions... |
| 63 | */ |
| 64 | class WPS4Text : public WPSTextParser |
| 65 | { |
| 66 | friend class WPS4Parser; |
| 67 | |
| 68 | public: |
| 69 | //! contructor |
| 70 | WPS4Text(WPS4Parser &parser, RVNGInputStreamPtr &input); |
| 71 | |
| 72 | //! destructor |
| 73 | ~WPS4Text() override; |
| 74 | |
| 75 | //! sets the listener |
| 76 | void setListener(WPSContentListenerPtr &listen) |
| 77 | { |
| 78 | m_listener = listen; |
| 79 | } |
| 80 | |
| 81 | //! returns the number of pages |
| 82 | int numPages() const; |
| 83 | |
| 84 | //! sends the data which have not yet been sent to the listener |
| 85 | void flushExtra(); |
| 86 | |
| 87 | /** send all the objects with page anchor corresponding given page |
| 88 | * \param page if page < 0, sends all the pictures which have a page anchor, |
| 89 | */ |
| 90 | void sendObjects(int page); |
| 91 | protected: |
| 92 | //! return the main parser |
| 93 | WPS4Parser &mainParser() |
| 94 | { |
| 95 | return reinterpret_cast<WPS4Parser &>(m_mainParser); |
| 96 | } |
| 97 | //! return the main parser |
| 98 | WPS4Parser const &mainParser() const |
| 99 | { |
| 100 | return reinterpret_cast<WPS4Parser const &>(m_mainParser); |
| 101 | } |
| 102 | |
| 103 | //! returns the default font to use for the document |
| 104 | WPS4TextInternal::Font getDefaultFont() const; |
| 105 | |
| 106 | //! returns the header entry (if such entry exists, if not returns an invalid entry) |
| 107 | WPSEntry getHeaderEntry() const; |
| 108 | |
| 109 | //! returns the footer entry (if such entry exists, if not returns an invalid entry) |
| 110 | WPSEntry getFooterEntry() const; |
| 111 | |
| 112 | //! returns the main text entry (if such entry exists, if not returns an invalid entry) |
| 113 | WPSEntry getMainTextEntry() const; |
| 114 | |
| 115 | //! reads a text section and sends it to a listener |
| 116 | bool readText(WPSEntry const &entry); |
| 117 | |
| 118 | //! finds all text entries (TEXT, SHdr, SFtr, BTEC, BTEP, FTNp, FTNp, BKMK, FONT, CHRT) |
| 119 | bool readEntries(); |
| 120 | //! parsed all the text entries |
| 121 | bool readStructures(); |
| 122 | |
| 123 | protected: |
| 124 | //---------------------------------------- |
| 125 | // FDP parsing |
| 126 | //---------------------------------------- |
| 127 | |
| 128 | //! finds the FDPC/FDPP structure using the BTEC/BTEP entries |
| 129 | //! \param which == 0 means FDPP |
| 130 | bool findFDPStructures(int which); |
| 131 | //! finds the FDPC/FDPP structure by searching after the text zone |
| 132 | //! \param which == 0 means FDPP |
| 133 | bool findFDPStructuresByHand(int which); |
| 134 | |
| 135 | //---------------------------------------- |
| 136 | // PLC parsing, setting |
| 137 | //---------------------------------------- |
| 138 | |
| 139 | /** definition of the plc data parser (low level) |
| 140 | * |
| 141 | * \param endPos the end of the properties' definition, |
| 142 | * \param bot defines the begin of the text's zone |
| 143 | * \param eot defines the end of the text's zone |
| 144 | * \param id the number of this properties |
| 145 | * \param mess a string which can be filled to indicate unparsed data */ |
| 146 | typedef bool (WPS4Text::* DataParser) |
| 147 | (long bot, long eot, int id, long endPos, std::string &mess); |
| 148 | |
| 149 | /** reads a PLC (Pointer List Composant ?) in zone entry |
| 150 | * |
| 151 | * \param zone the zone of the data in the file, |
| 152 | * \param textPtrs lists of offset in text zones where properties changes |
| 153 | * \param listValues lists of properties values (filled only if values are simple types: int, ..) |
| 154 | * \param parser the parser to use to read the values */ |
| 155 | bool readPLC(WPSEntry const &zone, |
| 156 | std::vector<long> &textPtrs, std::vector<long> &listValues, |
| 157 | DataParser parser = nullptr); |
| 158 | |
| 159 | //! default plc reader |
| 160 | bool defDataParser(long bot, long eot, int id, long endPos, std::string &mess); |
| 161 | |
| 162 | //! reads the font names |
| 163 | bool readFontNames(WPSEntry const &entry); |
| 164 | |
| 165 | //! reads a font properties |
| 166 | bool readFont(long endPos, int &id, std::string &mess); |
| 167 | |
| 168 | //! reads a paragraph properties |
| 169 | bool readParagraph(long endPos, int &id, std::string &mess); |
| 170 | |
| 171 | /** reads the ZZDLink ( a list of filename ) */ |
| 172 | bool readDosLink(WPSEntry const &entry); |
| 173 | |
| 174 | //! reads a object properties ( position in text, size and definition in file) |
| 175 | bool objectDataParser(long bot, long eot, int id, |
| 176 | long endPos, std::string &mess); |
| 177 | |
| 178 | //! reads the footnotes positions and definitions ( zones FTNd and FTNp) |
| 179 | bool readFootNotes(WPSEntry const &ftnD, WPSEntry const &ftnP); |
| 180 | |
| 181 | //! reads a book mark property ( string) |
| 182 | bool footNotesDataParser(long bot, long eot, int id, long endPos, std::string &mess); |
| 183 | |
| 184 | //! reads a book mark property ( string) |
| 185 | bool bkmkDataParser(long bot, long eot, int id, long endPos, std::string &mess); |
| 186 | |
| 187 | //! reads a date time property |
| 188 | bool dttmDataParser(long bot, long eot, int id, long endPos, std::string &mess); |
| 189 | |
| 190 | protected: |
| 191 | //! the listener |
| 192 | WPSContentListenerPtr m_listener; |
| 193 | |
| 194 | //! the internal state |
| 195 | mutable std::shared_ptr<WPS4TextInternal::State> m_state; |
| 196 | }; |
| 197 | #endif |
| 198 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |