| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
/* |
| 35 |
* Parser to WriteNow text document |
| 36 |
* |
| 37 |
*/ |
| 38 |
#ifndef WRITE_NOW_TEXT |
| 39 |
# define WRITE_NOW_TEXT |
| 40 |
|
| 41 |
#include <list> |
| 42 |
#include <string> |
| 43 |
#include <vector> |
| 44 |
|
| 45 |
#include "libmwaw_internal.hxx" |
| 46 |
|
| 47 |
#include "MWAWEntry.hxx" |
| 48 |
#include "MWAWSubDocument.hxx" |
| 49 |
|
| 50 |
#include "MWAWDebug.hxx" |
| 51 |
#include "MWAWInputStream.hxx" |
| 52 |
|
| 53 |
#include "MWAWParser.hxx" |
| 54 |
|
| 55 |
namespace WriteNowTextInternal |
| 56 |
{ |
| 57 |
struct ContentZone; |
| 58 |
struct ContentZones; |
| 59 |
|
| 60 |
struct Font; |
| 61 |
struct Paragraph; |
| 62 |
|
| 63 |
struct TableData; |
| 64 |
struct Token; |
| 65 |
|
| 66 |
struct Cell; |
| 67 |
|
| 68 |
struct State; |
| 69 |
} |
| 70 |
|
| 71 |
struct WriteNowEntry; |
| 72 |
struct WriteNowEntryManager; |
| 73 |
|
| 74 |
class WriteNowParser; |
| 75 |
|
| 76 |
/** \brief the main class to read the text part of writenow file |
| 77 |
* |
| 78 |
* |
| 79 |
* |
| 80 |
*/ |
| 81 |
class WriteNowText |
| 82 |
{ |
| 83 |
friend class WriteNowParser; |
| 84 |
friend struct WriteNowTextInternal::Cell; |
| 85 |
public: |
| 86 |
//! constructor |
| 87 |
explicit WriteNowText(WriteNowParser &parser); |
| 88 |
//! destructor |
| 89 |
virtual ~WriteNowText(); |
| 90 |
|
| 91 |
/** returns the file version */ |
| 92 |
int version() const; |
| 93 |
|
| 94 |
/** returns the number of pages */ |
| 95 |
int numPages() const; |
| 96 |
|
| 97 |
/** returns the header entry (if defined) */ |
| 98 |
WriteNowEntry getHeader() const; |
| 99 |
|
| 100 |
/** returns the footer entry (if defined) */ |
| 101 |
WriteNowEntry getFooter() const; |
| 102 |
|
| 103 |
protected: |
| 104 |
//! finds the different text zones |
| 105 |
bool createZones(); |
| 106 |
|
| 107 |
//! sends the data which have not yet been sent to the listener |
| 108 |
void flushExtra(); |
| 109 |
|
| 110 |
/** try to read the text zone ( list of entries ) |
| 111 |
and to create the text data zone */ |
| 112 |
bool parseZone(WriteNowEntry const &entry, std::vector<WriteNowEntry> &listData); |
| 113 |
|
| 114 |
//! parse a text data zone ( and create the associated structure ) |
| 115 |
std::shared_ptr<WriteNowTextInternal::ContentZones> parseContent(WriteNowEntry const &entry); |
| 116 |
|
| 117 |
/** send all the content zone of a zone defined by id |
| 118 |
0: main, 1 header/footer, 2: footnote |
| 119 |
*/ |
| 120 |
void sendZone(int id); |
| 121 |
|
| 122 |
//! send the text to the listener |
| 123 |
bool send(WriteNowEntry const &entry); |
| 124 |
|
| 125 |
//! send the text to the listener |
| 126 |
bool send(std::vector<WriteNowTextInternal::ContentZone> &listZones, |
| 127 |
std::vector<std::shared_ptr<WriteNowTextInternal::ContentZones> > &footnoteList, |
| 128 |
WriteNowTextInternal::Paragraph &ruler); |
| 129 |
|
| 130 |
/** sends a paragraph property to the listener */ |
| 131 |
void setProperty(WriteNowTextInternal::Paragraph const &ruler); |
| 132 |
|
| 133 |
// |
| 134 |
// low level |
| 135 |
// |
| 136 |
|
| 137 |
//! try to read the fonts zone |
| 138 |
bool readFontNames(WriteNowEntry const &entry); |
| 139 |
|
| 140 |
//! read a font |
| 141 |
bool readFont(MWAWInputStream &input, bool inStyle, WriteNowTextInternal::Font &font); |
| 142 |
|
| 143 |
//! read a paragraph format |
| 144 |
bool readParagraph(MWAWInputStream &input, WriteNowTextInternal::Paragraph &ruler); |
| 145 |
|
| 146 |
//! read a token |
| 147 |
bool readToken(MWAWInputStream &input, WriteNowTextInternal::Token &token); |
| 148 |
|
| 149 |
//! read a token (v2) |
| 150 |
bool readTokenV2(MWAWInputStream &input, WriteNowTextInternal::Token &token); |
| 151 |
|
| 152 |
//! read a table frame (checkme) |
| 153 |
bool readTable(MWAWInputStream &input, WriteNowTextInternal::TableData &table); |
| 154 |
|
| 155 |
//! try to read the styles zone |
| 156 |
bool readStyles(WriteNowEntry const &entry); |
| 157 |
|
| 158 |
private: |
| 159 |
WriteNowText(WriteNowText const &orig) = delete; |
| 160 |
WriteNowText &operator=(WriteNowText const &orig) = delete; |
| 161 |
|
| 162 |
protected: |
| 163 |
// |
| 164 |
// data |
| 165 |
// |
| 166 |
//! the parser state |
| 167 |
MWAWParserStatePtr m_parserState; |
| 168 |
|
| 169 |
//! the state |
| 170 |
std::shared_ptr<WriteNowTextInternal::State> m_state; |
| 171 |
|
| 172 |
//! the list of entry |
| 173 |
std::shared_ptr<WriteNowEntryManager> m_entryManager; |
| 174 |
|
| 175 |
//! the main parser; |
| 176 |
WriteNowParser *m_mainParser; |
| 177 |
}; |
| 178 |
#endif |
| 179 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |