| 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 convert Mariner Write document |
| 36 |
*/ |
| 37 |
#ifndef MARINER_WRT_PARSER |
| 38 |
# define MARINER_WRT_PARSER |
| 39 |
|
| 40 |
#include <iostream> |
| 41 |
#include <string> |
| 42 |
#include <vector> |
| 43 |
|
| 44 |
#include <librevenge/librevenge.h> |
| 45 |
|
| 46 |
#include "MWAWDebug.hxx" |
| 47 |
#include "MWAWEntry.hxx" |
| 48 |
#include "MWAWInputStream.hxx" |
| 49 |
|
| 50 |
#include "MWAWParser.hxx" |
| 51 |
|
| 52 |
namespace MarinerWrtParserInternal |
| 53 |
{ |
| 54 |
struct State; |
| 55 |
class SubDocument; |
| 56 |
} |
| 57 |
|
| 58 |
class MarinerWrtGraph; |
| 59 |
class MarinerWrtText; |
| 60 |
|
| 61 |
//! a entry to store a zone structure |
| 62 |
struct MarinerWrtEntry final : public MWAWEntry { |
| 63 |
//! constructor |
| 64 |
MarinerWrtEntry() |
| 65 |
: MWAWEntry() |
| 66 |
, m_fileType(0) |
| 67 |
, m_N(0) |
| 68 |
, m_value(0) |
| 69 |
{ |
| 70 |
} |
| 71 |
//! destructor |
| 72 |
~MarinerWrtEntry() final; |
| 73 |
//! returns the entry name; |
| 74 |
std::string name() const; |
| 75 |
//! operator<< |
| 76 |
friend std::ostream &operator<< (std::ostream &o, MarinerWrtEntry const &ent) |
| 77 |
{ |
| 78 |
if (ent.m_N || ent.m_value || ent.m_extra.length()) { |
| 79 |
o << "["; |
| 80 |
if (ent.m_N) o << "N=" << ent.m_N << ","; |
| 81 |
if (ent.m_value) o << "unkn=" << ent.m_value << ","; |
| 82 |
if (ent.m_extra.length()) o << ent.m_extra; |
| 83 |
o << "],"; |
| 84 |
} |
| 85 |
return o; |
| 86 |
} |
| 87 |
//! the entry type |
| 88 |
int m_fileType; |
| 89 |
//! the number of value |
| 90 |
int m_N; |
| 91 |
//! a unknown value |
| 92 |
int m_value; |
| 93 |
}; |
| 94 |
|
| 95 |
//! Internal: a struct used to read some field |
| 96 |
struct MarinerWrtStruct { |
| 97 |
//! constructor |
| 98 |
MarinerWrtStruct() |
| 99 |
: m_filePos(-1) |
| 100 |
, m_pos() |
| 101 |
, m_type(-1) |
| 102 |
, m_data() |
| 103 |
{ |
| 104 |
} |
| 105 |
//! operator<< |
| 106 |
friend std::ostream &operator<<(std::ostream &o, MarinerWrtStruct const &dt); |
| 107 |
//! returns the number of values |
| 108 |
int numValues() const |
| 109 |
{ |
| 110 |
return int(m_data.size()); |
| 111 |
} |
| 112 |
//! returns true if this corresponds to a simple container |
| 113 |
bool isBasic() const |
| 114 |
{ |
| 115 |
return (m_type==1 || m_type==2) && m_data.size()<=1; |
| 116 |
} |
| 117 |
//! returns the ith value (or 0 if it does not exists ) |
| 118 |
long value(int i) const; |
| 119 |
//! the file position where the field description begin |
| 120 |
long m_filePos; |
| 121 |
//! the file data position (for type=0 data ) |
| 122 |
MWAWEntry m_pos; |
| 123 |
//! the data type |
| 124 |
int m_type; |
| 125 |
//! the data block |
| 126 |
std::vector<long> m_data; |
| 127 |
}; |
| 128 |
|
| 129 |
/** \brief the main class to read a Mariner Write file |
| 130 |
* |
| 131 |
* |
| 132 |
* |
| 133 |
*/ |
| 134 |
class MarinerWrtParser final : public MWAWTextParser |
| 135 |
{ |
| 136 |
friend class MarinerWrtGraph; |
| 137 |
friend class MarinerWrtText; |
| 138 |
friend class MarinerWrtParserInternal::SubDocument; |
| 139 |
|
| 140 |
public: |
| 141 |
//! constructor |
| 142 |
MarinerWrtParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 143 |
//! destructor |
| 144 |
~MarinerWrtParser() final; |
| 145 |
|
| 146 |
//! checks if the document header is correct (or not) |
| 147 |
bool checkHeader(MWAWHeader *header, bool strict=false) final; |
| 148 |
|
| 149 |
// the main parse function |
| 150 |
void parse(librevenge::RVNGTextInterface *documentInterface) final; |
| 151 |
|
| 152 |
protected: |
| 153 |
//! inits all internal variables |
| 154 |
void init(); |
| 155 |
|
| 156 |
//! creates the listener which will be associated to the document |
| 157 |
void createDocument(librevenge::RVNGTextInterface *documentInterface); |
| 158 |
|
| 159 |
//! finds the different objects zones |
| 160 |
bool createZones(); |
| 161 |
/** try to read a zone */ |
| 162 |
bool readZone(int &actZone, bool onlyTest=false); |
| 163 |
|
| 164 |
//! returns the page left top point ( in inches) |
| 165 |
MWAWVec2f getPageLeftTop() const; |
| 166 |
//! returns the section information corresponding to a zone |
| 167 |
MWAWSection getSection(int zoneId) const; |
| 168 |
|
| 169 |
//! adds a new page |
| 170 |
void newPage(int number); |
| 171 |
|
| 172 |
// interface with the text parser |
| 173 |
|
| 174 |
//! return a zoneid corresponding to a fileId (or -1) and set the endnote flag |
| 175 |
int getZoneId(uint32_t fileId, bool &endNote); |
| 176 |
//! ask the text parser to send a zone |
| 177 |
void sendText(int zoneId); |
| 178 |
|
| 179 |
// interface with the graph parser |
| 180 |
//! return the pattern percent which corresponds to an id (or -1) |
| 181 |
float getPatternPercent(int id) const; |
| 182 |
//! ask the graph parser to send a token |
| 183 |
void sendToken(int zoneId, long tokenId); |
| 184 |
|
| 185 |
// |
| 186 |
// low level |
| 187 |
// |
| 188 |
|
| 189 |
/** try to read an entry header */ |
| 190 |
bool readEntryHeader(MarinerWrtEntry &entry); |
| 191 |
/** try to decode a zone */ |
| 192 |
bool decodeZone(std::vector<MarinerWrtStruct> &dataList, long numData=999999); |
| 193 |
|
| 194 |
/** try to read the separator of differents part */ |
| 195 |
bool readSeparator(MarinerWrtEntry const &entry); |
| 196 |
/** try to read the zone dimension ( normal and with margin ) */ |
| 197 |
bool readZoneDim(MarinerWrtEntry const &entry, int zoneId); |
| 198 |
/** try to read the zone header */ |
| 199 |
bool readZoneHeader(MarinerWrtEntry const &entry, int zoneId, bool onlyTest); |
| 200 |
/** try to read a unknown zone : one by separator?, borderdim? */ |
| 201 |
bool readZoneb(MarinerWrtEntry const &entry, int zoneId); |
| 202 |
/** try to read a unknown zone of 9 int*/ |
| 203 |
bool readZonec(MarinerWrtEntry const &entry, int zoneId); |
| 204 |
/** try to read a unknown zone of 23 int*/ |
| 205 |
bool readZone13(MarinerWrtEntry const &entry, int zoneId); |
| 206 |
/** try to read the doc info zone */ |
| 207 |
bool readDocInfo(MarinerWrtEntry const &entry, int zoneId); |
| 208 |
/** try to read a printinfo zone */ |
| 209 |
bool readPrintInfo(MarinerWrtEntry const &entry); |
| 210 |
/** try to read a xml printinfo zone */ |
| 211 |
bool readCPRT(MarinerWrtEntry const &entry); |
| 212 |
|
| 213 |
/** try to read a number or a list of number entries */ |
| 214 |
bool readNumbersString(int num, std::vector<long> &res); |
| 215 |
|
| 216 |
protected: |
| 217 |
// |
| 218 |
// data |
| 219 |
// |
| 220 |
//! the state |
| 221 |
std::shared_ptr<MarinerWrtParserInternal::State> m_state; |
| 222 |
|
| 223 |
//! a flag to know if page margins span are set |
| 224 |
bool m_pageMarginsSpanSet; |
| 225 |
|
| 226 |
//! the graph parser |
| 227 |
std::shared_ptr<MarinerWrtGraph> m_graphParser; |
| 228 |
|
| 229 |
//! the text parser |
| 230 |
std::shared_ptr<MarinerWrtText> m_textParser; |
| 231 |
}; |
| 232 |
#endif |
| 233 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |