| 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 |
#include <iomanip> |
| 35 |
#include <iostream> |
| 36 |
#include <limits> |
| 37 |
#include <set> |
| 38 |
#include <sstream> |
| 39 |
|
| 40 |
#include <librevenge/librevenge.h> |
| 41 |
|
| 42 |
#include "MWAWTextListener.hxx" |
| 43 |
#include "MWAWFontConverter.hxx" |
| 44 |
#include "MWAWHeader.hxx" |
| 45 |
#include "MWAWPosition.hxx" |
| 46 |
#include "MWAWPrinter.hxx" |
| 47 |
#include "MWAWRSRCParser.hxx" |
| 48 |
#include "MWAWSubDocument.hxx" |
| 49 |
|
| 50 |
#include "NisusWrtGraph.hxx" |
| 51 |
#include "NisusWrtStruct.hxx" |
| 52 |
#include "NisusWrtText.hxx" |
| 53 |
|
| 54 |
#include "NisusWrtParser.hxx" |
| 55 |
|
| 56 |
/** Internal: the structures of a NisusWrtParser */ |
| 57 |
namespace NisusWrtParserInternal |
| 58 |
{ |
| 59 |
/** Internal structure: use to store a numbering, a variable or a version */ |
| 60 |
struct Variable { |
| 61 |
//! Constructor |
| 62 |
explicit Variable(NisusWrtStruct::VariableType type = NisusWrtStruct::V_None) |
| 63 |
: m_type(0) |
| 64 |
, m_containerType(type) |
| 65 |
, m_fieldType(-1) |
| 66 |
, m_refId(-1) |
| 67 |
, m_numberingType(libmwaw::NONE) |
| 68 |
, m_startNumber(1) |
| 69 |
, m_increment(1) |
| 70 |
, m_prefix("") |
| 71 |
, m_suffix("") |
| 72 |
, m_dateFormat(0) |
| 73 |
, m_sample("") |
| 74 |
, m_extra("") |
| 75 |
{ |
| 76 |
} |
| 77 |
//! operator<< |
| 78 |
friend std::ostream &operator<<(std::ostream &o, Variable const &num); |
| 79 |
//! returns true if this is a date |
| 80 |
bool isDate() const |
| 81 |
{ |
| 82 |
return m_fieldType == 1 || m_fieldType == 0xf; |
| 83 |
} |
| 84 |
//! returns the date format |
| 85 |
std::string getDateFormat() const |
| 86 |
{ |
| 87 |
if (!isDate()) return ""; |
| 88 |
switch (m_dateFormat) { |
| 89 |
case 0: |
| 90 |
case 0x20: |
| 91 |
return "%m/%d/%Y"; |
| 92 |
case 0x40: |
| 93 |
return "%d/%m/%Y"; |
| 94 |
case 1: |
| 95 |
case 0x21: |
| 96 |
case 2: |
| 97 |
case 0x22: // normally DDD, MMM d Y |
| 98 |
return "%A, %B %d %Y"; |
| 99 |
case 0x41: |
| 100 |
case 0x42: |
| 101 |
return "%A, %d %B, %Y"; |
| 102 |
case 0x81: |
| 103 |
case 0xa1: |
| 104 |
case 0x82: |
| 105 |
case 0xa2: // normally DDD, MMM d Y |
| 106 |
return "%B %d, %Y"; |
| 107 |
case 0xc1: |
| 108 |
case 0xc2: |
| 109 |
return "%d %B, %Y"; |
| 110 |
default: |
| 111 |
break; |
| 112 |
} |
| 113 |
return ""; |
| 114 |
} |
| 115 |
//! the main type |
| 116 |
int m_type; |
| 117 |
//! the container type |
| 118 |
NisusWrtStruct::VariableType m_containerType; |
| 119 |
//! the variable type |
| 120 |
long m_fieldType; |
| 121 |
//! the reference id |
| 122 |
int m_refId; |
| 123 |
//! the numbering type |
| 124 |
libmwaw::NumberingType m_numberingType; |
| 125 |
//! the start number |
| 126 |
int m_startNumber; |
| 127 |
//! the increment |
| 128 |
int m_increment; |
| 129 |
//! the prefix |
| 130 |
std::string m_prefix; |
| 131 |
//! the suffix |
| 132 |
std::string m_suffix; |
| 133 |
//! the date format |
| 134 |
int m_dateFormat; |
| 135 |
//! a sample used in a dialog ? |
| 136 |
std::string m_sample; |
| 137 |
//! some extra debuging information |
| 138 |
std::string m_extra; |
| 139 |
}; |
| 140 |
|
| 141 |
std::ostream &operator<<(std::ostream &o, Variable const &num) |
| 142 |
{ |
| 143 |
switch (num.m_type) { |
| 144 |
case 1: |
| 145 |
o << "numbering,"; |
| 146 |
break; |
| 147 |
case 2: |
| 148 |
o << "numbering[count],"; |
| 149 |
break; |
| 150 |
case 3: |
| 151 |
o << "version,"; |
| 152 |
break; |
| 153 |
case 4: |
| 154 |
o << "version[small],"; |
| 155 |
break; |
| 156 |
case 5: |
| 157 |
o << "date/time,"; |
| 158 |
break; |
| 159 |
case 6: |
| 160 |
o << "docTitle,"; |
| 161 |
break; |
| 162 |
default: |
| 163 |
o << "#type=" << num.m_type << ","; |
| 164 |
break; |
| 165 |
} |
| 166 |
switch (num.m_containerType) { |
| 167 |
case NisusWrtStruct::V_Numbering: |
| 168 |
o << "number,"; |
| 169 |
break; |
| 170 |
case NisusWrtStruct::V_Variable: |
| 171 |
o << "variable,"; |
| 172 |
break; |
| 173 |
case NisusWrtStruct::V_Version: |
| 174 |
o << "version,"; |
| 175 |
break; |
| 176 |
case NisusWrtStruct::V_None: |
| 177 |
break; |
| 178 |
#if !defined(__clang__) |
| 179 |
default: |
| 180 |
o << "#type[container]=" << int(num.m_containerType) << ","; |
| 181 |
return o; |
| 182 |
#endif |
| 183 |
} |
| 184 |
if (num.m_refId >= 0) |
| 185 |
o << "refId=" << num.m_refId << ","; |
| 186 |
switch (num.m_fieldType) { |
| 187 |
case -1: |
| 188 |
break; |
| 189 |
case 0x1: |
| 190 |
o << "date2,"; |
| 191 |
break; |
| 192 |
case 0xe: |
| 193 |
o << "version,"; |
| 194 |
break; |
| 195 |
case 0xf: |
| 196 |
o << "date,"; |
| 197 |
break; |
| 198 |
case 0x10: |
| 199 |
o << "time,"; |
| 200 |
break; |
| 201 |
case 0x11: |
| 202 |
o << "docTitle,"; |
| 203 |
break; |
| 204 |
case 0x1c: |
| 205 |
o << "footnote,"; |
| 206 |
break; |
| 207 |
case 0x1d: |
| 208 |
o << "reference?,"; |
| 209 |
break; |
| 210 |
// alway in version variable ? |
| 211 |
case 0x7FFFFFFF: |
| 212 |
o << "none,"; |
| 213 |
break; |
| 214 |
// in a variable find also 0xFFFF8014 |
| 215 |
default: |
| 216 |
if ((num.m_fieldType>>16)==0x7FFF) |
| 217 |
o << "#fieldType=" << num.m_fieldType -0x7FFFFFFF-1 << ","; |
| 218 |
else if ((num.m_fieldType>>16)==0xFFFF) |
| 219 |
o << "#fieldType=X" << std::hex << num.m_fieldType << std::dec << ","; |
| 220 |
else |
| 221 |
o << "#fieldType=" << num.m_fieldType << ","; |
| 222 |
break; |
| 223 |
} |
| 224 |
std::string type = libmwaw::numberingTypeToString(num.m_numberingType); |
| 225 |
if (type.length()) |
| 226 |
o << "type=" << type << ","; |
| 227 |
if (num.m_startNumber != 1) o << "start=" << num.m_startNumber << ","; |
| 228 |
if (num.m_increment != 1) o << "increment=" << num.m_increment << ","; |
| 229 |
if (num.m_prefix.length()) { |
| 230 |
static char const *wh0[] = { "unkn0", "prefix", "name", "comments" }; |
| 231 |
o << wh0[num.m_containerType] << "=\"" << num.m_prefix << "\","; |
| 232 |
} |
| 233 |
if (num.m_suffix.length()) { |
| 234 |
static char const *wh2[] = { "unkn2", "suffix", "suffix", "unkn2" }; |
| 235 |
o << wh2[num.m_containerType] << "=\"" << num.m_suffix << "\","; |
| 236 |
} |
| 237 |
if (num.m_sample.length()) { |
| 238 |
static char const *wh1[] = { "unkn1", "sample", "sample", "author?" }; |
| 239 |
o << wh1[num.m_containerType] << "=\"" << num.m_sample << "\","; |
| 240 |
} |
| 241 |
if (num.m_dateFormat) { |
| 242 |
switch (num.m_dateFormat & 0x9F) { |
| 243 |
case 1: |
| 244 |
o << "format=Day, Month D YYYY,"; |
| 245 |
break; |
| 246 |
case 2: |
| 247 |
o << "format=Day, Mon D YYYY,"; |
| 248 |
break; |
| 249 |
case 0x81: |
| 250 |
o << "format=Month D, YYYY,"; |
| 251 |
break; |
| 252 |
case 0x82: |
| 253 |
o << "format=Mon D, YYYY,"; |
| 254 |
break; |
| 255 |
default: |
| 256 |
o << "#format=" << std::hex << (num.m_dateFormat&0x9F) << std::dec << ","; |
| 257 |
break; |
| 258 |
} |
| 259 |
if (num.m_dateFormat & 0x20) o << "[english]"; |
| 260 |
if (num.m_dateFormat & 0x40) o << "[european]"; |
| 261 |
o << ","; |
| 262 |
} |
| 263 |
if (num.m_extra.length()) |
| 264 |
o << num.m_extra; |
| 265 |
return o; |
| 266 |
} |
| 267 |
|
| 268 |
/** Internal structure: use to store a mark (reference) */ |
| 269 |
struct Reference { |
| 270 |
//! constructor |
| 271 |
Reference() |
| 272 |
: m_id(-1) |
| 273 |
, m_textPosition() |
| 274 |
, m_text("") |
| 275 |
{ |
| 276 |
} |
| 277 |
|
| 278 |
// the mark id ? |
| 279 |
int m_id; |
| 280 |
// the text position |
| 281 |
MWAWEntry m_textPosition; |
| 282 |
// the mark text |
| 283 |
std::string m_text; |
| 284 |
}; |
| 285 |
|
| 286 |
//! internal structure used to stored some zone data |
| 287 |
struct Zone { |
| 288 |
//! constructor |
| 289 |
Zone() |
| 290 |
: m_referenceList() |
| 291 |
, m_numberingResetList() |
| 292 |
, m_variableList() |
| 293 |
, m_versionList() |
| 294 |
{ |
| 295 |
} |
| 296 |
/** the list of reference */ |
| 297 |
std::vector<Reference> m_referenceList; |
| 298 |
//! the list of numbering reset id |
| 299 |
std::vector<int> m_numberingResetList; |
| 300 |
/** the list of variable */ |
| 301 |
std::vector<Variable> m_variableList; |
| 302 |
/** the list of versions */ |
| 303 |
std::vector<Variable> m_versionList; |
| 304 |
}; |
| 305 |
|
| 306 |
//////////////////////////////////////// |
| 307 |
//! Internal: the state of a NisusWrtParser |
| 308 |
struct State { |
| 309 |
//! constructor |
| 310 |
State() |
| 311 |
: m_numberingList() |
| 312 |
, m_actPage(0) |
| 313 |
, m_numPages(0) |
| 314 |
, m_numColumns(1) |
| 315 |
, m_columnSep(0.5f) |
| 316 |
, m_footnoteInfo() |
| 317 |
, m_isTextDocument() |
| 318 |
{ |
| 319 |
} |
| 320 |
|
| 321 |
/** the list of numbering */ |
| 322 |
std::vector<Variable> m_numberingList; |
| 323 |
/** the main zones : Main, Footnote, HeaderFooter */ |
| 324 |
Zone m_zones[3]; |
| 325 |
int m_actPage /** the actual page */, m_numPages /** the number of page of the final document */; |
| 326 |
|
| 327 |
int m_numColumns /** the number of columns */; |
| 328 |
float m_columnSep /** the columns separator */; |
| 329 |
/** the footnote placement */ |
| 330 |
NisusWrtStruct::FootnoteInfo m_footnoteInfo; |
| 331 |
/** a bool to know if we examine a text document or another thing glossary ... */ |
| 332 |
bool m_isTextDocument; |
| 333 |
}; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
//////////////////////////////////////////////////////////// |
| 338 |
// constructor/destructor, ... |
| 339 |
//////////////////////////////////////////////////////////// |
| 340 |
NisusWrtParser::NisusWrtParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 341 |
: MWAWTextParser(input, rsrcParser, header) |
| 342 |
, m_state() |
| 343 |
, m_graphParser() |
| 344 |
, m_textParser() |
| 345 |
{ |
| 346 |
init(); |
| 347 |
} |
| 348 |
|
| 349 |
NisusWrtParser::~NisusWrtParser() |
| 350 |
{ |
| 351 |
} |
| 352 |
|
| 353 |
void NisusWrtParser::init() |
| 354 |
{ |
| 355 |
resetTextListener(); |
| 356 |
setAsciiName("main-1"); |
| 357 |
|
| 358 |
m_state.reset(new NisusWrtParserInternal::State); |
| 359 |
|
| 360 |
// reduce the margin (in case, the page is not defined) |
| 361 |
getPageSpan().setMargins(0.1); |
| 362 |
|
| 363 |
m_graphParser.reset(new NisusWrtGraph(*this)); |
| 364 |
m_textParser.reset(new NisusWrtText(*this)); |
| 365 |
} |
| 366 |
|
| 367 |
MWAWInputStreamPtr NisusWrtParser::rsrcInput() |
| 368 |
{ |
| 369 |
return getRSRCParser()->getInput(); |
| 370 |
} |
| 371 |
|
| 372 |
libmwaw::DebugFile &NisusWrtParser::rsrcAscii() |
| 373 |
{ |
| 374 |
return getRSRCParser()->ascii(); |
| 375 |
} |
| 376 |
|
| 377 |
//////////////////////////////////////////////////////////// |
| 378 |
// position and height |
| 379 |
//////////////////////////////////////////////////////////// |
| 380 |
MWAWVec2f NisusWrtParser::getPageLeftTop() const |
| 381 |
{ |
| 382 |
return MWAWVec2f(float(getPageSpan().getMarginLeft()), |
| 383 |
float(getPageSpan().getMarginTop())); |
| 384 |
} |
| 385 |
|
| 386 |
void NisusWrtParser::getColumnInfo(int &numColumns, float &colSep) const |
| 387 |
{ |
| 388 |
numColumns = m_state->m_numColumns; |
| 389 |
colSep = m_state->m_columnSep; |
| 390 |
} |
| 391 |
|
| 392 |
void NisusWrtParser::getFootnoteInfo(NisusWrtStruct::FootnoteInfo &fInfo) const |
| 393 |
{ |
| 394 |
fInfo = m_state->m_footnoteInfo; |
| 395 |
} |
| 396 |
|
| 397 |
//////////////////////////////////////////////////////////// |
| 398 |
// interface with the graph parser |
| 399 |
//////////////////////////////////////////////////////////// |
| 400 |
bool NisusWrtParser::sendPicture(int pictId, MWAWPosition const &pictPos) |
| 401 |
{ |
| 402 |
if (!rsrcInput()) return false; |
| 403 |
long pos = rsrcInput()->tell(); |
| 404 |
bool ok=m_graphParser->sendPicture(pictId, true, pictPos); |
| 405 |
rsrcInput()->seek(pos, librevenge::RVNG_SEEK_SET); |
| 406 |
return ok; |
| 407 |
} |
| 408 |
|
| 409 |
//////////////////////////////////////////////////////////// |
| 410 |
// access to variable date |
| 411 |
//////////////////////////////////////////////////////////// |
| 412 |
std::string NisusWrtParser::getDateFormat(NisusWrtStruct::ZoneType zoneId, int vId) const |
| 413 |
{ |
| 414 |
if (zoneId >= 3) { |
| 415 |
MWAW_DEBUG_MSG(("NisusWrtParser::getDateFormat: bad zone %d\n", zoneId)); |
| 416 |
return ""; |
| 417 |
} |
| 418 |
NisusWrtParserInternal::Zone const &zone = m_state->m_zones[zoneId]; |
| 419 |
if (vId < 0 || vId >= int(zone.m_variableList.size()) || |
| 420 |
!zone.m_variableList[size_t(vId)].isDate()) { |
| 421 |
// some version 3 files do not contain any variables, so returns the default value... |
| 422 |
if (version()==3 && zone.m_variableList.size()==0) |
| 423 |
return "%m/%d/%Y"; |
| 424 |
MWAW_DEBUG_MSG(("NisusWrtParser::getDateFormat: can not find the variable %d\n", vId)); |
| 425 |
return ""; |
| 426 |
} |
| 427 |
return zone.m_variableList[size_t(vId)].getDateFormat(); |
| 428 |
} |
| 429 |
|
| 430 |
bool NisusWrtParser::getReferenceData |
| 431 |
(NisusWrtStruct::ZoneType zoneId, int vId, |
| 432 |
MWAWField::Type &fType, std::string &content, std::vector<int> &values) const |
| 433 |
{ |
| 434 |
fType = MWAWField::None; |
| 435 |
content = ""; |
| 436 |
if (zoneId >= 3) { |
| 437 |
MWAW_DEBUG_MSG(("NisusWrtParser::getReferenceData: bad zone %d\n", zoneId)); |
| 438 |
return false; |
| 439 |
} |
| 440 |
auto const &zone = m_state->m_zones[zoneId]; |
| 441 |
if (vId < 0 || vId >= int(zone.m_variableList.size())) { |
| 442 |
MWAW_DEBUG_MSG(("NisusWrtParser::getReferenceData: can not find the variable %d\n", vId)); |
| 443 |
return false; |
| 444 |
} |
| 445 |
auto const &var=zone.m_variableList[size_t(vId)]; |
| 446 |
if ((var.m_type != 1 && var.m_type != 2) || var.m_refId<=0) { |
| 447 |
MWAW_DEBUG_MSG(("NisusWrtParser::getReferenceData: find a variable with bad type %d\n", vId)); |
| 448 |
return false; |
| 449 |
} |
| 450 |
// first special case |
| 451 |
if (var.m_type == 1 && var.m_refId == 14) { |
| 452 |
fType = MWAWField::PageNumber; |
| 453 |
return true; |
| 454 |
} |
| 455 |
if (var.m_type == 2 && var.m_refId == 15) { |
| 456 |
fType = MWAWField::PageCount; |
| 457 |
return true; |
| 458 |
} |
| 459 |
size_t numVar = m_state->m_numberingList.size(); |
| 460 |
if (var.m_refId-1 >= int(numVar)) { |
| 461 |
MWAW_DEBUG_MSG(("NisusWrtParser::getReferenceData: can not find numbering variable for %d\n", vId)); |
| 462 |
return false; |
| 463 |
} |
| 464 |
// resize values if needed |
| 465 |
for (size_t p = values.size(); p < numVar; p++) |
| 466 |
values.push_back(m_state->m_numberingList[p].m_startNumber |
| 467 |
-m_state->m_numberingList[p].m_increment); |
| 468 |
auto const &ref=m_state->m_numberingList[size_t(var.m_refId-1)]; |
| 469 |
values[size_t(var.m_refId-1)] += ref.m_increment; |
| 470 |
|
| 471 |
size_t numReset = zone.m_numberingResetList.size(); |
| 472 |
if (numReset < numVar+1) |
| 473 |
numReset = numVar+1; |
| 474 |
if (size_t(var.m_refId) < numReset) { |
| 475 |
std::vector<bool> doneValues; |
| 476 |
std::vector<int> toDoValues; |
| 477 |
doneValues.resize(numReset, false); |
| 478 |
doneValues[size_t(var.m_refId)]=true; |
| 479 |
toDoValues.push_back(int(var.m_refId)); |
| 480 |
while (toDoValues.size()) { |
| 481 |
auto modId = static_cast<int>(toDoValues.back()); |
| 482 |
toDoValues.pop_back(); |
| 483 |
for (size_t r = 0; r < numReset; r++) { |
| 484 |
if (zone.m_numberingResetList[r] != modId) |
| 485 |
continue; |
| 486 |
if (r == 0 || doneValues[r]) continue; |
| 487 |
doneValues[r] = true; |
| 488 |
values[r-1] = m_state->m_numberingList[r-1].m_startNumber |
| 489 |
-m_state->m_numberingList[r-1].m_increment; |
| 490 |
toDoValues.push_back(int(r)); |
| 491 |
} |
| 492 |
} |
| 493 |
} |
| 494 |
std::stringstream s; |
| 495 |
std::string str = ref.m_prefix + ref.m_suffix; |
| 496 |
for (char p : str) { |
| 497 |
auto c = static_cast<unsigned char>(p); |
| 498 |
if (c==0 || (c < 0x20 && c > numVar)) { |
| 499 |
MWAW_DEBUG_MSG(("NisusWrtParser::getReferenceData: find unknown variable\n")); |
| 500 |
#ifdef DEBUG |
| 501 |
s << "###[" << int(c) << "]"; |
| 502 |
#endif |
| 503 |
} |
| 504 |
else if (c < 0x20) |
| 505 |
s << libmwaw::numberingValueToString |
| 506 |
(m_state->m_numberingList[size_t(c-1)].m_numberingType, |
| 507 |
values[size_t(c-1)]); |
| 508 |
else s << char(c); |
| 509 |
} |
| 510 |
content=s.str(); |
| 511 |
return true; |
| 512 |
} |
| 513 |
|
| 514 |
//////////////////////////////////////////////////////////// |
| 515 |
// new page |
| 516 |
//////////////////////////////////////////////////////////// |
| 517 |
void NisusWrtParser::newPage(int number) |
| 518 |
{ |
| 519 |
if (number <= m_state->m_actPage || number > m_state->m_numPages) |
| 520 |
return; |
| 521 |
|
| 522 |
while (m_state->m_actPage < number) { |
| 523 |
m_state->m_actPage++; |
| 524 |
if (!getTextListener() || m_state->m_actPage == 1) |
| 525 |
continue; |
| 526 |
getTextListener()->insertBreak(MWAWTextListener::PageBreak); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
//////////////////////////////////////////////////////////// |
| 531 |
// the parser |
| 532 |
//////////////////////////////////////////////////////////// |
| 533 |
void NisusWrtParser::parse(librevenge::RVNGTextInterface *docInterface) |
| 534 |
{ |
| 535 |
if (!getInput().get() || !getRSRCParser() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
| 536 |
bool ok = false; |
| 537 |
try { |
| 538 |
// create the asciiFile |
| 539 |
ascii().setStream(getInput()); |
| 540 |
ascii().open(asciiName()); |
| 541 |
checkHeader(nullptr); |
| 542 |
ok = createZones(); |
| 543 |
if (ok) { |
| 544 |
createDocument(docInterface); |
| 545 |
m_graphParser->sendPageGraphics(); |
| 546 |
m_textParser->sendMainText(); |
| 547 |
#ifdef DEBUG |
| 548 |
m_graphParser->flushExtra(); |
| 549 |
m_textParser->flushExtra(); |
| 550 |
#endif |
| 551 |
} |
| 552 |
ascii().reset(); |
| 553 |
} |
| 554 |
catch (...) { |
| 555 |
MWAW_DEBUG_MSG(("NisusWrtParser::parse: exception catched when parsing\n")); |
| 556 |
ok = false; |
| 557 |
} |
| 558 |
|
| 559 |
resetTextListener(); |
| 560 |
if (!ok) throw(libmwaw::ParseException()); |
| 561 |
} |
| 562 |
|
| 563 |
//////////////////////////////////////////////////////////// |
| 564 |
// create the document |
| 565 |
//////////////////////////////////////////////////////////// |
| 566 |
void NisusWrtParser::createDocument(librevenge::RVNGTextInterface *documentInterface) |
| 567 |
{ |
| 568 |
if (!documentInterface) return; |
| 569 |
if (getTextListener()) { |
| 570 |
MWAW_DEBUG_MSG(("NisusWrtParser::createDocument: listener already exist\n")); |
| 571 |
return; |
| 572 |
} |
| 573 |
|
| 574 |
// update the page |
| 575 |
m_state->m_actPage = 0; |
| 576 |
|
| 577 |
// create the page list |
| 578 |
int numPages = 1; |
| 579 |
if (m_graphParser->numPages() > numPages) |
| 580 |
numPages = m_graphParser->numPages(); |
| 581 |
if (m_textParser->numPages() > numPages) |
| 582 |
numPages = m_textParser->numPages(); |
| 583 |
m_state->m_numPages = numPages; |
| 584 |
|
| 585 |
std::vector<MWAWPageSpan> pageList; |
| 586 |
std::shared_ptr<MWAWSubDocument> subDoc; |
| 587 |
for (int i = 0; i <= numPages;) { |
| 588 |
MWAWPageSpan ps(getPageSpan()); |
| 589 |
int numSim[2]= {1,1}; |
| 590 |
subDoc = m_textParser->getHeader(i+1, numSim[0]); |
| 591 |
if (subDoc) { |
| 592 |
MWAWHeaderFooter header(MWAWHeaderFooter::HEADER, MWAWHeaderFooter::ALL); |
| 593 |
header.m_subDocument=subDoc; |
| 594 |
ps.setHeaderFooter(header); |
| 595 |
} |
| 596 |
subDoc = m_textParser->getFooter(i+1, numSim[1]); |
| 597 |
if (subDoc) { |
| 598 |
MWAWHeaderFooter footer(MWAWHeaderFooter::FOOTER, MWAWHeaderFooter::ALL); |
| 599 |
footer.m_subDocument=subDoc; |
| 600 |
ps.setHeaderFooter(footer); |
| 601 |
} |
| 602 |
if (numSim[1] < numSim[0]) numSim[0]=numSim[1]; |
| 603 |
if (numSim[0] < 1) numSim[0]=1; |
| 604 |
ps.setPageSpan(numSim[0]); |
| 605 |
i+=numSim[0]; |
| 606 |
pageList.push_back(ps); |
| 607 |
} |
| 608 |
|
| 609 |
// |
| 610 |
MWAWTextListenerPtr listen(new MWAWTextListener(*getParserState(), pageList, documentInterface)); |
| 611 |
setTextListener(listen); |
| 612 |
listen->startDocument(); |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
//////////////////////////////////////////////////////////// |
| 617 |
// |
| 618 |
// Intermediate level |
| 619 |
// |
| 620 |
//////////////////////////////////////////////////////////// |
| 621 |
bool NisusWrtParser::createZones() |
| 622 |
{ |
| 623 |
MWAWInputStreamPtr input = getInput(); |
| 624 |
std::string type, creator; |
| 625 |
if (input && input->getFinderInfo(type, creator) && type != "TEXT") |
| 626 |
m_state->m_isTextDocument = false; |
| 627 |
auto &entryMap = getRSRCParser()->getEntriesMap(); |
| 628 |
|
| 629 |
// the 128 id |
| 630 |
auto it = entryMap.lower_bound("PREC"); |
| 631 |
while (it != entryMap.end()) { |
| 632 |
if (it->first != "PREC") |
| 633 |
break; |
| 634 |
MWAWEntry const &entry = it++->second; |
| 635 |
readPrintInfo(entry); |
| 636 |
} |
| 637 |
it = entryMap.lower_bound("CPRC"); |
| 638 |
while (it != entryMap.end()) { |
| 639 |
if (it->first != "CPRC") |
| 640 |
break; |
| 641 |
MWAWEntry const &entry = it++->second; |
| 642 |
readCPRC(entry); |
| 643 |
} |
| 644 |
it = entryMap.lower_bound("PGLY"); |
| 645 |
while (it != entryMap.end()) { |
| 646 |
if (it->first != "PGLY") |
| 647 |
break; |
| 648 |
MWAWEntry const &entry = it++->second; |
| 649 |
readPageLimit(entry); |
| 650 |
} |
| 651 |
it = entryMap.lower_bound("INFO"); |
| 652 |
while (it != entryMap.end()) { |
| 653 |
if (it->first != "INFO") |
| 654 |
break; |
| 655 |
MWAWEntry const &entry = it++->second; |
| 656 |
readINFO(entry); |
| 657 |
} |
| 658 |
it = entryMap.lower_bound("ABBR"); |
| 659 |
while (it != entryMap.end()) { |
| 660 |
if (it->first != "ABBR") |
| 661 |
break; |
| 662 |
MWAWEntry const &entry = it++->second; |
| 663 |
readABBR(entry); |
| 664 |
} |
| 665 |
it = entryMap.lower_bound("FTA2"); |
| 666 |
while (it != entryMap.end()) { |
| 667 |
if (it->first != "FTA2") |
| 668 |
break; |
| 669 |
MWAWEntry const &entry = it++->second; |
| 670 |
readFTA2(entry); |
| 671 |
} |
| 672 |
it = entryMap.lower_bound("FnSc"); |
| 673 |
while (it != entryMap.end()) { |
| 674 |
if (it->first != "FnSc") |
| 675 |
break; |
| 676 |
MWAWEntry const &entry = it++->second; |
| 677 |
readFnSc(entry); |
| 678 |
} |
| 679 |
/** find also the resources : |
| 680 |
- alis: seems to contains data and some strings |
| 681 |
- OPEN: seems to contains one string: author? (size 0x20) |
| 682 |
- INF2: seems to contain some colors and some data (size 0x222) |
| 683 |
- sect: in two files: 010[1|a]0000acc0015f0000000[1|6]000... (size 0x24) |
| 684 |
*/ |
| 685 |
|
| 686 |
if (!m_textParser->createZones()) |
| 687 |
return false; |
| 688 |
m_graphParser->createZones(); |
| 689 |
|
| 690 |
// numbering, mark, variable, version, ... |
| 691 |
it = entryMap.lower_bound("CNAM"); // numbering name added in v5, v6 |
| 692 |
while (it != entryMap.end()) { |
| 693 |
if (it->first != "CNAM") |
| 694 |
break; |
| 695 |
MWAWEntry const &entry = it++->second; |
| 696 |
std::vector<std::string> list; |
| 697 |
readStringsList(entry, list, true); |
| 698 |
} |
| 699 |
|
| 700 |
it = entryMap.lower_bound("DSPL"); |
| 701 |
while (it != entryMap.end()) { |
| 702 |
if (it->first != "DSPL") |
| 703 |
break; |
| 704 |
MWAWEntry &entry = it++->second; |
| 705 |
entry.setName("NumberingDef"); |
| 706 |
NisusWrtStruct::RecursifData data(NisusWrtStruct::Z_Main, NisusWrtStruct::V_Numbering); |
| 707 |
data.read(*this, entry); |
| 708 |
readVariable(data); |
| 709 |
} |
| 710 |
char const *variableNames[] = { "VARI", "FVAR", "HVAR" }; |
| 711 |
for (int z = 0; z < 3; z++) { |
| 712 |
it = entryMap.lower_bound(variableNames[z]); |
| 713 |
while (it != entryMap.end()) { |
| 714 |
if (it->first != variableNames[z]) |
| 715 |
break; |
| 716 |
MWAWEntry &entry = it++->second; |
| 717 |
entry.setName("Variable"); |
| 718 |
NisusWrtStruct::RecursifData data(NisusWrtStruct::ZoneType(z), NisusWrtStruct::V_Variable); |
| 719 |
data.read(*this, entry); |
| 720 |
readVariable(data); |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
char const *cntrNames[] = { "CNTR", "FCNT", "HCNT" }; |
| 725 |
for (int z = 0; z < 3; z++) { |
| 726 |
it = entryMap.lower_bound(cntrNames[z]); |
| 727 |
while (it != entryMap.end()) { |
| 728 |
if (it->first != cntrNames[z]) |
| 729 |
break; |
| 730 |
MWAWEntry const &entry = it++->second; |
| 731 |
readCNTR(entry, int(NisusWrtStruct::ZoneType(z))); |
| 732 |
} |
| 733 |
} |
| 734 |
char const *numbResetNames[] = { "DPND", "FDPN", "HDPN" }; |
| 735 |
for (int z = 0; z < 3; z++) { |
| 736 |
it = entryMap.lower_bound(numbResetNames[z]); |
| 737 |
while (it != entryMap.end()) { |
| 738 |
if (it->first != numbResetNames[z]) |
| 739 |
break; |
| 740 |
MWAWEntry const &entry = it++->second; |
| 741 |
readNumberingReset(entry, int(NisusWrtStruct::ZoneType(z))); |
| 742 |
} |
| 743 |
} |
| 744 |
char const *versionNames[] = { "VRS ", "FVRS", "HVRS" }; |
| 745 |
for (int z = 0; z < 3; z++) { |
| 746 |
it = entryMap.lower_bound(versionNames[z]); |
| 747 |
while (it != entryMap.end()) { |
| 748 |
if (it->first != versionNames[z]) |
| 749 |
break; |
| 750 |
MWAWEntry &entry = it++->second; |
| 751 |
entry.setName("VariabS"); |
| 752 |
NisusWrtStruct::RecursifData data(NisusWrtStruct::ZoneType(z), NisusWrtStruct::V_Version); |
| 753 |
data.read(*this, entry); |
| 754 |
readVariable(data); |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
char const *markNames[] = { "MRK7", "FMRK", "HMRK" }; |
| 759 |
for (int z = 0; z < 3; z++) { |
| 760 |
it = entryMap.lower_bound(markNames[z]); |
| 761 |
while (it != entryMap.end()) { |
| 762 |
if (it->first != markNames[z]) |
| 763 |
break; |
| 764 |
MWAWEntry &entry = it++->second; |
| 765 |
entry.setName("Reference"); |
| 766 |
NisusWrtStruct::RecursifData data = NisusWrtStruct::RecursifData(NisusWrtStruct::ZoneType(z)); |
| 767 |
data.read(*this, entry); |
| 768 |
readReference(data); |
| 769 |
} |
| 770 |
} |
| 771 |
it = entryMap.lower_bound("XMRK"); // related to mark7 ? |
| 772 |
while (it != entryMap.end()) { |
| 773 |
if (it->first != "XMRK") |
| 774 |
break; |
| 775 |
MWAWEntry &entry = it++->second; |
| 776 |
entry.setName("XMRK"); |
| 777 |
NisusWrtStruct::RecursifData data(NisusWrtStruct::Z_Main); |
| 778 |
data.read(*this, entry); |
| 779 |
} |
| 780 |
// unknown ? |
| 781 |
it = entryMap.lower_bound("SGP1"); |
| 782 |
while (it != entryMap.end()) { |
| 783 |
if (it->first != "SGP1") |
| 784 |
break; |
| 785 |
MWAWEntry &entry = it++->second; |
| 786 |
entry.setName("SGP1"); |
| 787 |
NisusWrtStruct::RecursifData data(NisusWrtStruct::Z_Main); |
| 788 |
data.read(*this, entry); |
| 789 |
readSGP1(data); |
| 790 |
} |
| 791 |
return true; |
| 792 |
} |
| 793 |
|
| 794 |
//////////////////////////////////////////////////////////// |
| 795 |
// |
| 796 |
// Low level |
| 797 |
// |
| 798 |
//////////////////////////////////////////////////////////// |
| 799 |
|
| 800 |
//////////////////////////////////////////////////////////// |
| 801 |
// read the header |
| 802 |
//////////////////////////////////////////////////////////// |
| 803 |
bool NisusWrtParser::checkHeader(MWAWHeader *header, bool /*strict*/) |
| 804 |
{ |
| 805 |
*m_state = NisusWrtParserInternal::State(); |
| 806 |
/** no data fork, may be ok, but this means |
| 807 |
that the file contains no text and no picture, so... */ |
| 808 |
MWAWInputStreamPtr input = getInput(); |
| 809 |
if (!input || !input->hasDataFork() || !getRSRCParser()) |
| 810 |
return false; |
| 811 |
MWAWRSRCParser::Version applVersion, docVersion; |
| 812 |
// read the Nisus version |
| 813 |
MWAWEntry entry = getRSRCParser()->getEntry("vers", 2002); |
| 814 |
if (!entry.valid()) entry = getRSRCParser()->getEntry("vers", 2); |
| 815 |
// read the application format version |
| 816 |
if (!entry.valid() || !getRSRCParser()->parseVers(entry, applVersion)) { |
| 817 |
MWAW_DEBUG_MSG(("NisusWrtParser::checkHeader: can not find the Nisus version\n")); |
| 818 |
} |
| 819 |
// read the file format version |
| 820 |
entry = getRSRCParser()->getEntry("vers", 1); |
| 821 |
if (!entry.valid() || !getRSRCParser()->parseVers(entry, docVersion)) { |
| 822 |
MWAW_DEBUG_MSG(("NisusWrtParser::checkHeader: can not find the Nisus file format version\n")); |
| 823 |
return false; |
| 824 |
} |
| 825 |
switch (docVersion.m_majorVersion) { |
| 826 |
case 3: |
| 827 |
case 4: |
| 828 |
MWAW_DEBUG_MSG(("NisusWrtParser::checkHeader: find Nisus %d file with file format version %d\n", applVersion.m_majorVersion, docVersion.m_majorVersion)); |
| 829 |
break; |
| 830 |
default: |
| 831 |
MWAW_DEBUG_MSG(("NisusWrtParser::checkHeader: find Nisus %d file with unknown file format version %d\n", applVersion.m_majorVersion, docVersion.m_majorVersion)); |
| 832 |
return false; |
| 833 |
} |
| 834 |
|
| 835 |
setVersion(docVersion.m_majorVersion); |
| 836 |
if (header) |
| 837 |
header->reset(MWAWDocument::MWAW_T_NISUSWRITER, version()); |
| 838 |
|
| 839 |
return true; |
| 840 |
} |
| 841 |
|
| 842 |
//////////////////////////////////////////////////////////// |
| 843 |
// read a list of string |
| 844 |
//////////////////////////////////////////////////////////// |
| 845 |
bool NisusWrtParser::readStringsList(MWAWEntry const &entry, std::vector<std::string> &list, bool simpleList) |
| 846 |
{ |
| 847 |
list.resize(0); |
| 848 |
if (!entry.valid() && entry.length()!=0) { |
| 849 |
MWAW_DEBUG_MSG(("NisusWrtParser::readStringsList: the entry is bad\n")); |
| 850 |
return false; |
| 851 |
} |
| 852 |
entry.setParsed(true); |
| 853 |
MWAWInputStreamPtr input = rsrcInput(); |
| 854 |
long pos = entry.begin(); |
| 855 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 856 |
|
| 857 |
libmwaw::DebugStream f; |
| 858 |
f << "Entries(" << entry.type() << ")[" << entry.id() << "]:"; |
| 859 |
rsrcAscii().addPos(pos-4); |
| 860 |
rsrcAscii().addNote(f.str().c_str()); |
| 861 |
|
| 862 |
while (!input->isEnd()) { |
| 863 |
pos = input->tell(); |
| 864 |
if (pos == entry.end()) break; |
| 865 |
long endPos = entry.end(); |
| 866 |
f.str(""); |
| 867 |
f << entry.type() << list.size() << ":"; |
| 868 |
|
| 869 |
if (!simpleList) { |
| 870 |
if (pos+2 > entry.end()) { |
| 871 |
f << "###"; |
| 872 |
rsrcAscii().addPos(pos); |
| 873 |
rsrcAscii().addNote(f.str().c_str()); |
| 874 |
|
| 875 |
MWAW_DEBUG_MSG(("NisusWrtParser::readStringsList: can not read strings\n")); |
| 876 |
return false; |
| 877 |
} |
| 878 |
auto sz = static_cast<int>(input->readULong(2)); |
| 879 |
endPos = pos+2+sz; |
| 880 |
if (pos+2+sz > entry.end()) { |
| 881 |
f.str(""); |
| 882 |
f << "###"; |
| 883 |
rsrcAscii().addPos(pos); |
| 884 |
rsrcAscii().addNote(f.str().c_str()); |
| 885 |
|
| 886 |
MWAW_DEBUG_MSG(("NisusWrtParser::readStringsList: zone size is bad\n")); |
| 887 |
return false; |
| 888 |
} |
| 889 |
} |
| 890 |
|
| 891 |
/* checkme: in STNM we can have a list of string, it is general or |
| 892 |
do we need to create a new function NisusWrtParser::readStringsListList |
| 893 |
*/ |
| 894 |
std::string str(""); |
| 895 |
while (input->tell() < endPos-1) { |
| 896 |
auto pSz = static_cast<int>(input->readULong(1)); |
| 897 |
if (pSz == 0xFF) { |
| 898 |
f << "_"; |
| 899 |
pSz = 0; |
| 900 |
} |
| 901 |
if (input->tell()+pSz > endPos || input->isEnd()) { |
| 902 |
f << "###"; |
| 903 |
rsrcAscii().addPos(pos); |
| 904 |
rsrcAscii().addNote(f.str().c_str()); |
| 905 |
MWAW_DEBUG_MSG(("NisusWrtParser::readStringsList: string size is too big\n")); |
| 906 |
return false; |
| 907 |
} |
| 908 |
std::string str1(""); |
| 909 |
for (int c=0; c < pSz; c++) |
| 910 |
str1 += char(input->readULong(1)); |
| 911 |
f << str1 << ","; |
| 912 |
str += str1; |
| 913 |
if (simpleList) continue; |
| 914 |
if ((pSz%2)==0) input->seek(1,librevenge::RVNG_SEEK_CUR); |
| 915 |
} |
| 916 |
list.push_back(str); |
| 917 |
rsrcAscii().addPos(pos); |
| 918 |
rsrcAscii().addNote(f.str().c_str()); |
| 919 |
if (simpleList) break; |
| 920 |
} |
| 921 |
return true; |
| 922 |
} |
| 923 |
|
| 924 |
//////////////////////////////////////////////////////////// |
| 925 |
// read DSPL or the VRS zone: numbering definition or version |
| 926 |
//////////////////////////////////////////////////////////// |
| 927 |
bool NisusWrtParser::readVariable(NisusWrtStruct::RecursifData const &data) |
| 928 |
{ |
| 929 |
if (!data.m_info || data.m_info->m_zoneType >= 3) { |
| 930 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: find unexpected zoneType\n")); |
| 931 |
return false; |
| 932 |
} |
| 933 |
if (!data.m_childList.size()) |
| 934 |
return true; |
| 935 |
|
| 936 |
if (data.m_childList.size() > 1) { |
| 937 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: level 0 node contains more than 1 node\n")); |
| 938 |
} |
| 939 |
if (data.m_childList[0].isLeaf()) { |
| 940 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: level 1 node is a leaf\n")); |
| 941 |
return false; |
| 942 |
} |
| 943 |
auto const &mainData = *data.m_childList[0].m_data; |
| 944 |
auto &zone = m_state->m_zones[int(data.m_info->m_zoneType)]; |
| 945 |
MWAWInputStreamPtr input = rsrcInput(); |
| 946 |
libmwaw::DebugStream f; |
| 947 |
long val; |
| 948 |
|
| 949 |
std::vector<NisusWrtParserInternal::Variable> *result = nullptr; |
| 950 |
int lastMaxId = 0; |
| 951 |
switch (data.m_info->m_variableType) { |
| 952 |
case NisusWrtStruct::V_Numbering: |
| 953 |
lastMaxId = 11; |
| 954 |
result = &m_state->m_numberingList; |
| 955 |
break; |
| 956 |
case NisusWrtStruct::V_Version: |
| 957 |
lastMaxId = 8; |
| 958 |
result = &zone.m_versionList; |
| 959 |
break; |
| 960 |
case NisusWrtStruct::V_Variable: |
| 961 |
lastMaxId = 12; |
| 962 |
result = &zone.m_variableList; |
| 963 |
break; |
| 964 |
case NisusWrtStruct::V_None: |
| 965 |
#if !defined(__clang__) |
| 966 |
default: |
| 967 |
#endif |
| 968 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: find unexpected dataType\n")); |
| 969 |
return false; |
| 970 |
} |
| 971 |
for (auto const &node : mainData.m_childList) { |
| 972 |
static int const minExpectedSz[] = { 1, 4, 1, 2, 2, 2, 4, 4, 1, 4, 1 }; |
| 973 |
NisusWrtParserInternal::Variable num(data.m_info->m_variableType); |
| 974 |
num.m_type = node.m_type; |
| 975 |
|
| 976 |
if (node.isLeaf()) { |
| 977 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: level 2 node is a leaf\n")); |
| 978 |
continue; |
| 979 |
} |
| 980 |
auto const &dt = *node.m_data; |
| 981 |
f.str(""); |
| 982 |
int lastId = lastMaxId; |
| 983 |
switch (num.m_type) { |
| 984 |
case 1: // [2..12] with v12 is a string |
| 985 |
lastId = 12; |
| 986 |
f << "numbering,"; |
| 987 |
break; |
| 988 |
case 2: // idem |
| 989 |
lastId = 12; |
| 990 |
f << "numbering[count],"; |
| 991 |
break; |
| 992 |
case 3: // type = [2, 3.. 8] |
| 993 |
lastId = 8; |
| 994 |
f << "version,"; |
| 995 |
break; |
| 996 |
case 4: // type = [2,3,4] |
| 997 |
lastId = 4; |
| 998 |
f << "version[small],"; |
| 999 |
break; |
| 1000 |
case 5: //type=[2,3,4,4] second id=4: a small int : Date format/time |
| 1001 |
lastId = 4; |
| 1002 |
f << "date/time,"; |
| 1003 |
break; |
| 1004 |
case 6: // type=[2,3,4] |
| 1005 |
lastId = 4; |
| 1006 |
f << "docTitle,"; |
| 1007 |
break; |
| 1008 |
default: |
| 1009 |
f << "#"; |
| 1010 |
break; |
| 1011 |
} |
| 1012 |
rsrcAscii().addPos(node.m_entry.begin()-16); |
| 1013 |
rsrcAscii().addNote(f.str().c_str()); |
| 1014 |
|
| 1015 |
for (size_t nDt = 0; nDt < dt.m_childList.size(); nDt++) { |
| 1016 |
if (!dt.m_childList[nDt].isLeaf()) { |
| 1017 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: level 3 node is not a leaf\n")); |
| 1018 |
continue; |
| 1019 |
} |
| 1020 |
MWAWEntry const &entry = dt.m_childList[nDt].m_entry; |
| 1021 |
f.str(""); |
| 1022 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1023 |
int id = dt.m_childList[nDt].m_type; |
| 1024 |
bool checkId = false; |
| 1025 |
if (id != int(nDt)+2) { |
| 1026 |
if (id == 4 && node.m_type == 5 && entry.length() >= 2) { |
| 1027 |
checkId = true; |
| 1028 |
id = -4; |
| 1029 |
} |
| 1030 |
else |
| 1031 |
f << "#id=" << id << ","; |
| 1032 |
} |
| 1033 |
|
| 1034 |
if (!checkId && (id < 2 || id > lastId || entry.length() < minExpectedSz[id-2])) { |
| 1035 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: find unexpected size for data %d\n", int(nDt))); |
| 1036 |
f << "###"; |
| 1037 |
rsrcAscii().addPos(entry.begin()-12); |
| 1038 |
rsrcAscii().addNote(f.str().c_str()); |
| 1039 |
continue; |
| 1040 |
} |
| 1041 |
switch (id) { |
| 1042 |
case 2: |
| 1043 |
case 4: // display example |
| 1044 |
case 10: |
| 1045 |
case 12: { // postfix : list of fields |
| 1046 |
auto mSz = static_cast<int>(input->readULong(1)); |
| 1047 |
if (mSz+1 > entry.length()) { |
| 1048 |
MWAW_DEBUG_MSG(("NisusWrtParser::readVariable: the dpsl seems to short\n")); |
| 1049 |
f << "###Text"; |
| 1050 |
break; |
| 1051 |
} |
| 1052 |
std::string text(""); |
| 1053 |
for (int i = 0; i < mSz; i++) |
| 1054 |
text+= char(input->readULong(1)); |
| 1055 |
static char const *wh0[] = { "unkn0", "prefix", "name", "comments" }; |
| 1056 |
static char const *wh1[] = { "unkn1", "sample", "sample", "author?" }; |
| 1057 |
static char const *wh2[] = { "unkn2", "suffix", "suffix", "unkn2" }; |
| 1058 |
switch (id) { |
| 1059 |
case 2: |
| 1060 |
num.m_prefix = text; |
| 1061 |
f << wh0[num.m_containerType]; |
| 1062 |
break; |
| 1063 |
case 4: |
| 1064 |
num.m_sample = text; |
| 1065 |
f << wh1[num.m_containerType]; |
| 1066 |
break; |
| 1067 |
case 10: |
| 1068 |
num.m_suffix = text; |
| 1069 |
f << wh2[num.m_containerType]; |
| 1070 |
break; |
| 1071 |
case 12: |
| 1072 |
f << "f12"; |
| 1073 |
break; |
| 1074 |
default: |
| 1075 |
f << "###id[" << id << "]"; |
| 1076 |
} |
| 1077 |
f << "=\"" << text << "\""; |
| 1078 |
break; |
| 1079 |
} |
| 1080 |
case -4: { // date format |
| 1081 |
num.m_dateFormat = static_cast<int>(input->readULong(2)); |
| 1082 |
if (!num.m_dateFormat) break; // default |
| 1083 |
std::string format(""); |
| 1084 |
format = num.getDateFormat(); |
| 1085 |
if (format.length()) f << "format=" << format << ","; |
| 1086 |
else f << "#format=" << std::hex << (num.m_dateFormat&0x9F) << std::dec << ","; |
| 1087 |
break; |
| 1088 |
} |
| 1089 |
case 5: // style : 0=arabic, 1=roman, upperroman, abgadhawaz(arabic), alpha, upperalpha, hebrew |
| 1090 |
val = long(input->readULong(2)); |
| 1091 |
f << "type="; |
| 1092 |
num.m_numberingType = libmwaw::ARABIC; |
| 1093 |
switch (val) { |
| 1094 |
case 0: |
| 1095 |
f << "arabic,"; |
| 1096 |
break; |
| 1097 |
case 1: |
| 1098 |
num.m_numberingType = libmwaw::LOWERCASE_ROMAN; |
| 1099 |
f << "roman,"; |
| 1100 |
break; |
| 1101 |
case 2: |
| 1102 |
num.m_numberingType = libmwaw::UPPERCASE_ROMAN; |
| 1103 |
f << "upperroman,"; |
| 1104 |
break; |
| 1105 |
case 3: |
| 1106 |
f << "abgadhawaz,"; |
| 1107 |
break; |
| 1108 |
case 4: |
| 1109 |
num.m_numberingType = libmwaw::LOWERCASE; |
| 1110 |
f << "alpha,"; |
| 1111 |
break; |
| 1112 |
case 5: |
| 1113 |
num.m_numberingType = libmwaw::UPPERCASE; |
| 1114 |
f << "upperalpha,"; |
| 1115 |
break; |
| 1116 |
case 6: |
| 1117 |
f << "hebrew,"; |
| 1118 |
break; |
| 1119 |
default: |
| 1120 |
f << "#" << val << ","; |
| 1121 |
} |
| 1122 |
break; |
| 1123 |
case 6: // start number |
| 1124 |
num.m_startNumber = static_cast<int>(input->readLong(2)); |
| 1125 |
f << "start=" << num.m_startNumber <<","; |
| 1126 |
break; |
| 1127 |
case 7: // increment |
| 1128 |
num.m_increment = static_cast<int>(input->readLong(2)); |
| 1129 |
f << "increment=" << num.m_increment <<","; |
| 1130 |
break; |
| 1131 |
case 9: // id ? |
| 1132 |
num.m_refId = static_cast<int>(input->readULong(4)); |
| 1133 |
f << "refId=" << num.m_refId << ","; |
| 1134 |
break; |
| 1135 |
case 3: |
| 1136 |
num.m_fieldType = long(input->readULong(4)); |
| 1137 |
switch (num.m_fieldType) { |
| 1138 |
// 1(type 5) date ? |
| 1139 |
case 0xe: |
| 1140 |
f << "version,"; |
| 1141 |
break; |
| 1142 |
case 0xf: |
| 1143 |
f << "date,"; |
| 1144 |
break; |
| 1145 |
case 0x10: |
| 1146 |
f << "time,"; |
| 1147 |
break; |
| 1148 |
case 0x11: |
| 1149 |
f << "docTitle,"; |
| 1150 |
break; |
| 1151 |
case 0x14: // find with 0xFFFF8014 |
| 1152 |
f << "mark,"; |
| 1153 |
break; |
| 1154 |
case 0x1c: |
| 1155 |
f << "footnote,"; |
| 1156 |
break; |
| 1157 |
case 0x1d: |
| 1158 |
f << "reference?,"; |
| 1159 |
break; |
| 1160 |
// alway in version variable ? |
| 1161 |
case 0x7FFFFFFF: |
| 1162 |
f << "none,"; |
| 1163 |
break; |
| 1164 |
default: |
| 1165 |
if ((num.m_fieldType>>16)==0x7FFF) |
| 1166 |
f << "#fieldType=" << num.m_fieldType -0x7FFFFFFF-1 << ","; |
| 1167 |
else if ((num.m_fieldType>>16)==0xFFFF) |
| 1168 |
f << "#fieldType=X" << std::hex << num.m_fieldType << std::dec << ","; |
| 1169 |
else |
| 1170 |
f << "#fieldType=" << num.m_fieldType << ","; |
| 1171 |
break; |
| 1172 |
} |
| 1173 |
break; |
| 1174 |
case 8: // always 0 ? |
| 1175 |
val = long(input->readULong(4)); |
| 1176 |
f << "g8=" << val << ","; |
| 1177 |
break; |
| 1178 |
case 11: // find 0-2: if numbering g11=0 means add default data, if not num data? |
| 1179 |
val = long(input->readULong(4)); |
| 1180 |
if (val==0) { |
| 1181 |
f << "auto,"; |
| 1182 |
if (num.m_suffix.length()) |
| 1183 |
f << "###"; |
| 1184 |
else |
| 1185 |
num.m_suffix += char(num.m_refId); |
| 1186 |
} |
| 1187 |
else |
| 1188 |
f << "numVar?=" << val << ","; |
| 1189 |
break; |
| 1190 |
default: |
| 1191 |
break; |
| 1192 |
} |
| 1193 |
|
| 1194 |
if (f.str().length()) { |
| 1195 |
rsrcAscii().addPos(entry.begin()-12); |
| 1196 |
rsrcAscii().addNote(f.str().c_str()); |
| 1197 |
} |
| 1198 |
} |
| 1199 |
result->push_back(num); |
| 1200 |
} |
| 1201 |
return true; |
| 1202 |
} |
| 1203 |
|
| 1204 |
//////////////////////////////////////////////////////////// |
| 1205 |
// read the DPND zone ( the numbering reset zone ) |
| 1206 |
//////////////////////////////////////////////////////////// |
| 1207 |
bool NisusWrtParser::readNumberingReset(MWAWEntry const &entry, int zoneId) |
| 1208 |
{ |
| 1209 |
// find to 2 times with entry.length()=0x22 |
| 1210 |
if (!entry.valid()) { |
| 1211 |
MWAW_DEBUG_MSG(("NisusWrtParser::readNumberingReset: the entry is bad\n")); |
| 1212 |
return false; |
| 1213 |
} |
| 1214 |
if (zoneId < 0 || zoneId >= 3) { |
| 1215 |
MWAW_DEBUG_MSG(("NisusWrtParser::readNumberingReset: find unexpected zoneId: %d\n", zoneId)); |
| 1216 |
return false; |
| 1217 |
} |
| 1218 |
auto &zone = m_state->m_zones[zoneId]; |
| 1219 |
entry.setParsed(true); |
| 1220 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1221 |
long pos = entry.begin(); |
| 1222 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1223 |
auto sz = static_cast<int>(input->readULong(2)); |
| 1224 |
if (sz+2 != entry.length() || sz%2) { |
| 1225 |
MWAW_DEBUG_MSG(("NisusWrtParser::readNumberingReset: entry size seems odd\n")); |
| 1226 |
return false; |
| 1227 |
} |
| 1228 |
libmwaw::DebugStream f; |
| 1229 |
f << "Entries(NumberingReset)[" << zoneId << "]:"; |
| 1230 |
auto numElt = size_t(sz/2); |
| 1231 |
zone.m_numberingResetList.resize(numElt, 0); |
| 1232 |
for (size_t i = 0; i < numElt; i++) { |
| 1233 |
auto val = int(input->readULong(2)); |
| 1234 |
zone.m_numberingResetList[i] = val; |
| 1235 |
if (val) f << "reset" << int(i) << "=" << val << ","; |
| 1236 |
} |
| 1237 |
rsrcAscii().addPos(pos-4); |
| 1238 |
rsrcAscii().addNote(f.str().c_str()); |
| 1239 |
return true; |
| 1240 |
} |
| 1241 |
|
| 1242 |
//////////////////////////////////////////////////////////// |
| 1243 |
// read mark zone ( ie the reference structure ) |
| 1244 |
//////////////////////////////////////////////////////////// |
| 1245 |
bool NisusWrtParser::readReference(NisusWrtStruct::RecursifData const &data) |
| 1246 |
{ |
| 1247 |
if (!data.m_info || data.m_info->m_zoneType >= 3) { |
| 1248 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: find unexpected zoneType\n")); |
| 1249 |
return false; |
| 1250 |
} |
| 1251 |
|
| 1252 |
if (!data.m_childList.size()) |
| 1253 |
return true; |
| 1254 |
|
| 1255 |
if (data.m_childList.size() > 1) { |
| 1256 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: level 0 node contains more than 1 node\n")); |
| 1257 |
} |
| 1258 |
if (data.m_childList[0].isLeaf()) { |
| 1259 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: level 1 node is a leaf\n")); |
| 1260 |
return false; |
| 1261 |
} |
| 1262 |
auto const &mainData = *data.m_childList[0].m_data; |
| 1263 |
auto &zone = m_state->m_zones[static_cast<int>(data.m_info->m_zoneType)]; |
| 1264 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1265 |
libmwaw::DebugStream f, f2; |
| 1266 |
|
| 1267 |
size_t n = 0; |
| 1268 |
bool pbFound = false; |
| 1269 |
size_t numData = mainData.m_childList.size(); |
| 1270 |
while (n < numData) { |
| 1271 |
if (n+1 >= numData) { |
| 1272 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: find an odd number of data\n")); |
| 1273 |
break; |
| 1274 |
} |
| 1275 |
|
| 1276 |
// ----- First the position ----- |
| 1277 |
auto const &nd=mainData.m_childList[n++]; |
| 1278 |
if (nd.isLeaf() || nd.m_type != 0x7FFFFFFF) { |
| 1279 |
if (!pbFound) { |
| 1280 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: oops find bad type for the filePos node\n")); |
| 1281 |
pbFound = true; |
| 1282 |
} |
| 1283 |
continue; |
| 1284 |
} |
| 1285 |
NisusWrtParserInternal::Reference ref; |
| 1286 |
auto const &dt=*nd.m_data; |
| 1287 |
if (dt.m_childList.size() != 1 || !dt.m_childList[0].isLeaf()) { |
| 1288 |
if (!pbFound) { |
| 1289 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: the filePos node contain unexpected data\n")); |
| 1290 |
pbFound = true; |
| 1291 |
} |
| 1292 |
zone.m_referenceList.push_back(ref); |
| 1293 |
continue; |
| 1294 |
} |
| 1295 |
MWAWEntry entry = dt.m_childList[0].m_entry; |
| 1296 |
if (entry.length() < 8) { |
| 1297 |
if (!pbFound) { |
| 1298 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: the filePos size seem bad\n")); |
| 1299 |
pbFound = true; |
| 1300 |
} |
| 1301 |
zone.m_referenceList.push_back(ref); |
| 1302 |
rsrcAscii().addPos(entry.begin()-12); |
| 1303 |
rsrcAscii().addNote("###"); |
| 1304 |
continue; |
| 1305 |
} |
| 1306 |
|
| 1307 |
// the file position in the text part |
| 1308 |
long pos = entry.begin(); |
| 1309 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1310 |
f.str(""); |
| 1311 |
f << "Position:"; |
| 1312 |
ref.m_textPosition.setBegin(long(input->readULong(4))); |
| 1313 |
ref.m_textPosition.setEnd(long(input->readULong(4))); |
| 1314 |
f << "filePos=" << std::hex |
| 1315 |
<< ref.m_textPosition.begin() << "<->" << ref.m_textPosition.end() << std::dec << ","; |
| 1316 |
rsrcAscii().addPos(pos-12); |
| 1317 |
rsrcAscii().addNote(f.str().c_str()); |
| 1318 |
|
| 1319 |
// ----- Second the data node ----- |
| 1320 |
auto const &nd1=mainData.m_childList[n++]; |
| 1321 |
|
| 1322 |
if (nd1.isLeaf() || nd1.m_type == 0x7FFFFFFF) { |
| 1323 |
if (!pbFound) { |
| 1324 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: the date node contain unexpected data\n")); |
| 1325 |
pbFound = true; |
| 1326 |
} |
| 1327 |
zone.m_referenceList.push_back(ref); |
| 1328 |
n--; |
| 1329 |
continue; |
| 1330 |
} |
| 1331 |
|
| 1332 |
f.str(""); |
| 1333 |
switch (nd1.m_type) { |
| 1334 |
case 1: |
| 1335 |
break; // type=1:id, type=100:text |
| 1336 |
case 2: |
| 1337 |
f << "unknown,"; |
| 1338 |
break; // type=1:id, type=-4:?, type=220: ?, type=300: list of chain? |
| 1339 |
default: |
| 1340 |
f << "#type=" << nd1.m_type << ","; |
| 1341 |
break; |
| 1342 |
} |
| 1343 |
if (f.str().length()) { |
| 1344 |
rsrcAscii().addPos(nd1.m_entry.begin()-16); |
| 1345 |
rsrcAscii().addNote(f.str().c_str()); |
| 1346 |
} |
| 1347 |
long val; |
| 1348 |
auto const &dt1=*nd1.m_data; |
| 1349 |
for (auto const &dt1Child : dt1.m_childList) { |
| 1350 |
if (!dt1Child.isLeaf()) { |
| 1351 |
if (!pbFound) { |
| 1352 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: find some level 2 data array nodes\n")); |
| 1353 |
pbFound = true; |
| 1354 |
} |
| 1355 |
continue; |
| 1356 |
} |
| 1357 |
NisusWrtStruct::RecursifData::Node const &childNode = dt1Child; |
| 1358 |
entry = childNode.m_entry; |
| 1359 |
pos = entry.begin(); |
| 1360 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1361 |
f.str(""); |
| 1362 |
switch (childNode.m_type) { |
| 1363 |
case 1: |
| 1364 |
f << "II:"; |
| 1365 |
if (entry.length() < 4) { |
| 1366 |
f << "###"; |
| 1367 |
break; |
| 1368 |
} |
| 1369 |
ref.m_id = static_cast<int>(input->readLong(4)); // some kind of id ? |
| 1370 |
f << "id?=" << ref.m_id << ","; |
| 1371 |
break; |
| 1372 |
case 0x7ffffffc: // find one time with 0 |
| 1373 |
f << "III:"; |
| 1374 |
if (entry.length() < 4) { |
| 1375 |
f << "###"; |
| 1376 |
break; |
| 1377 |
} |
| 1378 |
val = input->readLong(4); |
| 1379 |
f << "unkn=" << val << ","; |
| 1380 |
break; |
| 1381 |
case 100: { |
| 1382 |
f << "Text:"; |
| 1383 |
if (entry.length() < 1) { |
| 1384 |
f << "###"; |
| 1385 |
break; |
| 1386 |
} |
| 1387 |
auto mSz = static_cast<int>(input->readULong(1)); |
| 1388 |
if (mSz+1 > entry.length()) { |
| 1389 |
f << "###"; |
| 1390 |
break; |
| 1391 |
} |
| 1392 |
std::string mark(""); |
| 1393 |
for (int i = 0; i < mSz; i++) |
| 1394 |
mark+=char(input->readULong(1)); |
| 1395 |
ref.m_text = mark; |
| 1396 |
f << mark; |
| 1397 |
break; |
| 1398 |
} |
| 1399 |
case 220: { |
| 1400 |
if (entry.length()==0) break; |
| 1401 |
if (entry.length()%12) { |
| 1402 |
MWAW_DEBUG_MSG(("NisusWrtParser::readReference: unexpected length for type 220\n")); |
| 1403 |
f << "###sz"; |
| 1404 |
break; |
| 1405 |
} |
| 1406 |
auto N=int(entry.length()/12); |
| 1407 |
for (int j = 0; j < N ; j++) { |
| 1408 |
long actPos = input->tell(); |
| 1409 |
f2.str(""); |
| 1410 |
f2 << "Reference2[" << j << "]:type=220,"; |
| 1411 |
val = long(input->readULong(4)); // always 0? |
| 1412 |
if (val) f << "unkn=" << val << ","; |
| 1413 |
// unknown, maybe some dim... |
| 1414 |
f2 << "dim?=" << float(input->readLong(4))/65536.f << "<->"; |
| 1415 |
f2 << float(input->readLong(4))/65536.f << ","; |
| 1416 |
rsrcAscii().addPos(actPos); |
| 1417 |
rsrcAscii().addNote(f2.str().c_str()); |
| 1418 |
input->seek(actPos+12, librevenge::RVNG_SEEK_SET); |
| 1419 |
} |
| 1420 |
break; |
| 1421 |
} |
| 1422 |
case 300: // find with size 0x28 |
| 1423 |
break; |
| 1424 |
default: |
| 1425 |
f << "#type"; |
| 1426 |
break; |
| 1427 |
} |
| 1428 |
if (f.str().length()) { |
| 1429 |
rsrcAscii().addPos(pos-12); |
| 1430 |
rsrcAscii().addNote(f.str().c_str()); |
| 1431 |
} |
| 1432 |
} |
| 1433 |
zone.m_referenceList.push_back(ref); |
| 1434 |
} |
| 1435 |
return true; |
| 1436 |
} |
| 1437 |
|
| 1438 |
//////////////////////////////////////////////////////////// |
| 1439 |
// read SGP1 zone: a unknown zone (a type, an id/anchor type? and a bdbox ) |
| 1440 |
//////////////////////////////////////////////////////////// |
| 1441 |
bool NisusWrtParser::readSGP1(NisusWrtStruct::RecursifData const &data) |
| 1442 |
{ |
| 1443 |
if (!data.m_info || data.m_info->m_zoneType >= 3) { |
| 1444 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: find unexpected zoneType\n")); |
| 1445 |
return false; |
| 1446 |
} |
| 1447 |
|
| 1448 |
if (!data.m_childList.size()) |
| 1449 |
return true; |
| 1450 |
|
| 1451 |
if (data.m_childList.size() > 1) { |
| 1452 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: level 0 node contains more than 1 node\n")); |
| 1453 |
} |
| 1454 |
if (data.m_childList[0].isLeaf()) { |
| 1455 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: level 1 node is a leaf\n")); |
| 1456 |
return false; |
| 1457 |
} |
| 1458 |
auto const &mainData = *data.m_childList[0].m_data; |
| 1459 |
// NisusWrtParserInternal::Zone &zone = m_state->m_zones[static_cast<int>(data.m_info->m_zoneType)]; |
| 1460 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1461 |
libmwaw::DebugStream f; |
| 1462 |
|
| 1463 |
long val; |
| 1464 |
for (auto const &mChild : mainData.m_childList) { |
| 1465 |
if (mChild.isLeaf()) { |
| 1466 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: oops some level 2 node are leaf\n")); |
| 1467 |
continue; |
| 1468 |
} |
| 1469 |
auto const &dt=*mChild.m_data; |
| 1470 |
for (auto const &child : dt.m_childList) { |
| 1471 |
if (!child.isLeaf()) { |
| 1472 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: find an odd level 3 leaf\n")); |
| 1473 |
continue; |
| 1474 |
} |
| 1475 |
|
| 1476 |
long pos = child.m_entry.begin(); |
| 1477 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1478 |
f.str(""); |
| 1479 |
switch (child.m_type) { |
| 1480 |
case 110: { |
| 1481 |
if (child.m_entry.length()==0) break; |
| 1482 |
if (child.m_entry.length()%4) { |
| 1483 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: unexpected length for type 110\n")); |
| 1484 |
f << "###sz"; |
| 1485 |
break; |
| 1486 |
} |
| 1487 |
// find some increasing sequence here |
| 1488 |
auto N=int(child.m_entry.length()/4); |
| 1489 |
f << "unkn=["; |
| 1490 |
for (int j = 0; j < N; j++) { |
| 1491 |
val = input->readLong(4); |
| 1492 |
f << val << ","; |
| 1493 |
} |
| 1494 |
f << "]"; |
| 1495 |
break; |
| 1496 |
} |
| 1497 |
case 120: |
| 1498 |
case 200: { /* checkme: always find mSz=0 here */ |
| 1499 |
if (child.m_entry.length()==0) { |
| 1500 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: unexpected length for type %d\n", child.m_type)); |
| 1501 |
f << "###sz"; |
| 1502 |
break; |
| 1503 |
} |
| 1504 |
auto mSz = static_cast<int>(input->readULong(1)); |
| 1505 |
if (mSz+1 > child.m_entry.length()) { |
| 1506 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: the %d text seems to short\n", child.m_type)); |
| 1507 |
f << "###sz"; |
| 1508 |
break; |
| 1509 |
} |
| 1510 |
std::string text(""); |
| 1511 |
for (int c = 0; c < mSz; c++) |
| 1512 |
text+=char(input->readULong(1)); |
| 1513 |
f << "text=" << text << ","; |
| 1514 |
break; |
| 1515 |
} |
| 1516 |
case 100: { |
| 1517 |
if (child.m_entry.length()!=0x24) { |
| 1518 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: unexpected length for type 100\n")); |
| 1519 |
f << "###sz"; |
| 1520 |
break; |
| 1521 |
} |
| 1522 |
// find f1=1, f3=[0|1], f5=0x28, other always 0... |
| 1523 |
for (int j = 0; j < 18; j++) { |
| 1524 |
val = input->readLong(2); |
| 1525 |
if (val) f << "f" << j << "=" << val << ","; |
| 1526 |
} |
| 1527 |
break; |
| 1528 |
} |
| 1529 |
case 300: { |
| 1530 |
if (child.m_entry.length()!=0x5c) { |
| 1531 |
MWAW_DEBUG_MSG(("NisusWrtParser::readSGP1: unexpected length for type 300\n")); |
| 1532 |
f << "###sz"; |
| 1533 |
break; |
| 1534 |
} |
| 1535 |
val = long(input->readULong(2)); // always 0x8000 ? |
| 1536 |
if (val != 0x8000) f << "f0=" << std::hex << val << std::dec << ","; |
| 1537 |
for (int j = 0; j < 2; j++) { // find [0,-2]|0 |
| 1538 |
val = input->readLong(2); |
| 1539 |
if (val) f << "f" << j+1 << "=" << val << ","; |
| 1540 |
} |
| 1541 |
val = long(input->readULong(2)); // find 0 and 1 time 0x7101 |
| 1542 |
if (val) f << "f3=" << std::hex << val << std::dec << ","; |
| 1543 |
auto mSz = static_cast<int>(input->readULong(1)); |
| 1544 |
if (mSz >= 32) { |
| 1545 |
f << "###textSz=" << mSz << ","; |
| 1546 |
mSz = 0; |
| 1547 |
} |
| 1548 |
std::string text(""); |
| 1549 |
for (int j = 0; j < mSz; j++) |
| 1550 |
text += char(input->readULong(1)); |
| 1551 |
if (text.length()) f << "\"" << text << "\","; |
| 1552 |
// checkme: where does the data begins again |
| 1553 |
input->seek(child.m_entry.begin()+40, librevenge::RVNG_SEEK_SET); |
| 1554 |
for (int j = 0; j < 17; j++) { // find always 0 here |
| 1555 |
val = input->readLong(2); |
| 1556 |
if (val) f << "g" << j << "=" << val << ","; |
| 1557 |
} |
| 1558 |
val = long(input->readULong(2)); // 1|b |
| 1559 |
f << "unkn=" << val << ","; |
| 1560 |
for (int j = 0; j < 8; j++) { // find always 0 here |
| 1561 |
val = input->readLong(2); |
| 1562 |
if (val) f << "h" << j << "=" << val << ","; |
| 1563 |
} |
| 1564 |
break; |
| 1565 |
} |
| 1566 |
default: |
| 1567 |
f << "type=" << child.m_type << ","; |
| 1568 |
break; |
| 1569 |
} |
| 1570 |
rsrcAscii().addPos(pos-12); |
| 1571 |
rsrcAscii().addNote(f.str().c_str()); |
| 1572 |
} |
| 1573 |
} |
| 1574 |
return true; |
| 1575 |
} |
| 1576 |
|
| 1577 |
//////////////////////////////////////////////////////////// |
| 1578 |
// read the print info |
| 1579 |
//////////////////////////////////////////////////////////// |
| 1580 |
bool NisusWrtParser::readPrintInfo(MWAWEntry const &entry) |
| 1581 |
{ |
| 1582 |
if (!entry.valid() || entry.length() < 0x78) { |
| 1583 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPrintInfo: the entry is bad\n")); |
| 1584 |
return false; |
| 1585 |
} |
| 1586 |
if (entry.id() != 128) { |
| 1587 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPrintInfo: the entry id %d is odd\n", entry.id())); |
| 1588 |
} |
| 1589 |
entry.setParsed(true); |
| 1590 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1591 |
long pos = entry.begin(); |
| 1592 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1593 |
|
| 1594 |
libmwaw::DebugStream f; |
| 1595 |
// print info |
| 1596 |
libmwaw::PrinterInfo info; |
| 1597 |
if (!info.read(input)) return false; |
| 1598 |
if (entry.id() != 128) |
| 1599 |
f << "Entries(PrintInfo)[#" << entry.id() << "]:" << info; |
| 1600 |
else |
| 1601 |
f << "Entries(PrintInfo):" << info; |
| 1602 |
|
| 1603 |
MWAWVec2i paperSize = info.paper().size(); |
| 1604 |
MWAWVec2i pageSize = info.page().size(); |
| 1605 |
if (pageSize.x() <= 0 || pageSize.y() <= 0 || |
| 1606 |
paperSize.x() <= 0 || paperSize.y() <= 0) return false; |
| 1607 |
|
| 1608 |
// define margin from print info |
| 1609 |
MWAWVec2i lTopMargin= -1 * info.paper().pos(0); |
| 1610 |
MWAWVec2i rBotMargin=info.paper().pos(1) - info.page().pos(1); |
| 1611 |
|
| 1612 |
// move margin left | top |
| 1613 |
int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0; |
| 1614 |
int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0; |
| 1615 |
lTopMargin -= MWAWVec2i(decalX, decalY); |
| 1616 |
rBotMargin += MWAWVec2i(decalX, decalY); |
| 1617 |
|
| 1618 |
// decrease right | bottom |
| 1619 |
int rightMarg = rBotMargin.x() -10; |
| 1620 |
if (rightMarg < 0) rightMarg=0; |
| 1621 |
int botMarg = rBotMargin.y() -50; |
| 1622 |
if (botMarg < 0) botMarg=0; |
| 1623 |
|
| 1624 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 1625 |
getPageSpan().setMarginBottom(botMarg/72.0); |
| 1626 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 1627 |
getPageSpan().setMarginRight(rightMarg/72.0); |
| 1628 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 1629 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 1630 |
|
| 1631 |
if (entry.length() != 0x78) |
| 1632 |
f << "###size=" << entry.length() << ","; |
| 1633 |
rsrcAscii().addPos(pos-4); |
| 1634 |
rsrcAscii().addNote(f.str().c_str()); |
| 1635 |
input->seek(pos+0x78, librevenge::RVNG_SEEK_SET); |
| 1636 |
if (long(input->tell()) != pos+0x78) { |
| 1637 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPrintInfo: file is too short\n")); |
| 1638 |
return false; |
| 1639 |
} |
| 1640 |
|
| 1641 |
return true; |
| 1642 |
} |
| 1643 |
|
| 1644 |
//////////////////////////////////////////////////////////// |
| 1645 |
// read the PGLY zone ( page limit ) |
| 1646 |
//////////////////////////////////////////////////////////// |
| 1647 |
bool NisusWrtParser::readPageLimit(MWAWEntry const &entry) |
| 1648 |
{ |
| 1649 |
if (!entry.valid() || entry.length() < 0xa2) { |
| 1650 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPageLimit: the entry is bad\n")); |
| 1651 |
return false; |
| 1652 |
} |
| 1653 |
if (entry.id() != 128) { |
| 1654 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPageLimit: the entry id %d is odd\n", entry.id())); |
| 1655 |
} |
| 1656 |
entry.setParsed(true); |
| 1657 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1658 |
long pos = entry.begin(); |
| 1659 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1660 |
|
| 1661 |
libmwaw::DebugStream f; |
| 1662 |
if (entry.id() != 128) |
| 1663 |
f << "Entries(Page)[#" << entry.id() << "]:"; |
| 1664 |
else |
| 1665 |
f << "Entries(Page):"; |
| 1666 |
|
| 1667 |
long val = input->readLong(2); // always 0x88 ? |
| 1668 |
if (val != 0x88) f << "f0=" << val << ","; |
| 1669 |
val = input->readLong(2); // always 0x901 or two flags ? |
| 1670 |
if (val != 0x901) f << "f1=" << val << ","; |
| 1671 |
val = input->readLong(2); // always 0x0 |
| 1672 |
if (val) f << "f2=" << val << ","; |
| 1673 |
|
| 1674 |
MWAWBox2i boxes[3]; |
| 1675 |
for (auto &box : boxes) { |
| 1676 |
int dim[4]; |
| 1677 |
for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
| 1678 |
box = MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])); |
| 1679 |
} |
| 1680 |
f << "page=" << boxes[0] << ","; |
| 1681 |
f << "page[text]=" << boxes[1] << ","; |
| 1682 |
f << "page[columns]=" << boxes[2] << ","; |
| 1683 |
MWAWVec2i pageDim = boxes[0].size(); |
| 1684 |
MWAWVec2i LT=boxes[1][0]-boxes[0][0]; |
| 1685 |
MWAWVec2i RB=boxes[0][1]-boxes[1][1]; |
| 1686 |
bool dimOk=pageDim[0] > 0 && pageDim[1] > 0 && |
| 1687 |
LT[0] >= 0 && LT[1] >= 0 && RB[0] >= 0 && RB[1] >= 0; |
| 1688 |
if (!dimOk && m_state->m_isTextDocument) { |
| 1689 |
// can be ok in a glossary: in this case, all values can be 0 |
| 1690 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPageLimit: the page margins seems odd\n")); |
| 1691 |
f << "###dim,"; |
| 1692 |
} |
| 1693 |
// all zero expected some time g0=2 |
| 1694 |
for (int i = 0; i < 3; i++) { |
| 1695 |
val = input->readLong(2); |
| 1696 |
if (val) f << "g" << i << "=" << val << ","; |
| 1697 |
} |
| 1698 |
int numColumns = static_cast<int>(input->readLong(2))+1; |
| 1699 |
auto colSeps = static_cast<int>(input->readLong(2)); |
| 1700 |
if (!dimOk) ; |
| 1701 |
else if (numColumns <= 0 || numColumns > 8 || colSeps < 0 || colSeps *numColumns >= pageDim[0]) { |
| 1702 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPageLimit: the columns definition seems odd\n")); |
| 1703 |
f << "###"; |
| 1704 |
} |
| 1705 |
else { |
| 1706 |
m_state->m_numColumns = numColumns; |
| 1707 |
m_state->m_columnSep = float(colSeps)/72.f; |
| 1708 |
} |
| 1709 |
if (numColumns != 1) f << "nCols=" << numColumns << ","; |
| 1710 |
if (colSeps != 36) f << "colSeps=" << colSeps << "pt,"; |
| 1711 |
static int const expectedValues[]= { 0, 3, 1}; |
| 1712 |
// find also, g3=0x10, g4=g5=0 (in v3 file) |
| 1713 |
for (int i = 0; i < 3; i++) { |
| 1714 |
val = input->readLong(2); |
| 1715 |
if (int(val) != expectedValues[i]) |
| 1716 |
f << "g" << i+3 << "=" << val << ","; |
| 1717 |
} |
| 1718 |
// find only 0 expected h2=[0|1], h6=[0|-1] |
| 1719 |
for (int i = 0; i < 7; i++) { |
| 1720 |
val = input->readLong(2); |
| 1721 |
if (val) |
| 1722 |
f << "h" << i << "=" << val << ","; |
| 1723 |
} |
| 1724 |
// a series of flags 0 or 1, find frequently fl0=1, and sometimes fl4=fl5=1 |
| 1725 |
for (int i = 0; i < 8; i++) { |
| 1726 |
val = input->readLong(1); |
| 1727 |
if (val) |
| 1728 |
f << "fl" << i << "=" << val << ","; |
| 1729 |
} |
| 1730 |
// always 0 |
| 1731 |
for (int i = 0; i < 3; i++) { |
| 1732 |
val = input->readLong(2); |
| 1733 |
if (val) |
| 1734 |
f << "l" << i << "=" << val << ","; |
| 1735 |
} |
| 1736 |
rsrcAscii().addPos(pos-4); |
| 1737 |
rsrcAscii().addNote(f.str().c_str()); |
| 1738 |
|
| 1739 |
pos = input->tell(); |
| 1740 |
f.str(""); |
| 1741 |
f << "Page[A]:"; |
| 1742 |
// find 0,3ea0f83e|3ea19dbd|3ea2433b|3ec00000|3ec0a57f |
| 1743 |
val = long(input->readULong(4)); |
| 1744 |
if (val) f << "f0=" << std::hex << val << std::dec << ","; |
| 1745 |
// find f3=[0|1|-1] |
| 1746 |
for (int i = 1; i < 4; i++) { |
| 1747 |
val = input->readLong(2); |
| 1748 |
if (val) |
| 1749 |
f << "f" << i << "=" << val << ","; |
| 1750 |
} |
| 1751 |
// 2 times 0x48 ? |
| 1752 |
for (int i = 4; i < 6; i++) { |
| 1753 |
val = input->readLong(2); |
| 1754 |
if (val != 0x48) |
| 1755 |
f << "f" << i << "=" << val << ","; |
| 1756 |
} |
| 1757 |
int dim[4]; |
| 1758 |
for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
| 1759 |
MWAWBox2i realPage = MWAWBox2i(MWAWVec2i(dim[1],dim[0]), MWAWVec2i(dim[3],dim[2])); |
| 1760 |
if (dimOk && realPage.size()[0] >= pageDim[0] && realPage.size()[1] >= pageDim[1]) { |
| 1761 |
LT -= realPage[0]; |
| 1762 |
RB += (realPage[1]-boxes[0][1]); |
| 1763 |
pageDim = realPage.size(); |
| 1764 |
} |
| 1765 |
else if (dimOk) { |
| 1766 |
MWAW_DEBUG_MSG(("NisusWrtParser::readPageLimit: realPage is smaller than page\n")); |
| 1767 |
f << "###"; |
| 1768 |
dimOk = false; |
| 1769 |
} |
| 1770 |
f << "page[complete]=" << realPage << ","; |
| 1771 |
val = input->readLong(1); |
| 1772 |
bool portrait = true; |
| 1773 |
switch (val) { |
| 1774 |
case 0: |
| 1775 |
break; |
| 1776 |
case 1: |
| 1777 |
portrait = false; |
| 1778 |
f << "landscape,"; |
| 1779 |
break; |
| 1780 |
default: |
| 1781 |
f << "#pageOrientation=" << val << ","; |
| 1782 |
break; |
| 1783 |
} |
| 1784 |
for (int i = 0; i < 5; i++) { |
| 1785 |
val = input->readLong(1); |
| 1786 |
if (val) |
| 1787 |
f << "fl" << i << "=" << val << ","; |
| 1788 |
} |
| 1789 |
// a size ? often 114,16d |
| 1790 |
int sz[2]; |
| 1791 |
for (auto &s : sz) s=static_cast<int>(input->readLong(2)); |
| 1792 |
if (sz[0]||sz[1]) |
| 1793 |
f << "sz=" << sz[1] << "x" << sz[0] << ","; |
| 1794 |
// v3: 0,0 or v4: 0x29 0x3 ? |
| 1795 |
for (int i = 0; i < 2; i++) { |
| 1796 |
val = input->readLong(2); |
| 1797 |
if (val) |
| 1798 |
f << "g" << i << "=" << val << ","; |
| 1799 |
} |
| 1800 |
// another sz ? ~153,~1fc |
| 1801 |
for (int &i : sz) |
| 1802 |
i=static_cast<int>(input->readLong(2)); |
| 1803 |
if (sz[0]||sz[1]) |
| 1804 |
f << "sz2=" << sz[1] << "x" << sz[0] << ","; |
| 1805 |
// 0|-1, find also g4=0xa |
| 1806 |
for (int i = 2; i < 8; i++) { |
| 1807 |
val = input->readLong(2); |
| 1808 |
if (val) |
| 1809 |
f << "g" << i << "=" << val << ","; |
| 1810 |
} |
| 1811 |
// 0 expect h0=[0|1|22], h1=[0|1|22], h0=h1 ( almost always ? ) |
| 1812 |
for (int i = 0; i < 7; i++) { |
| 1813 |
val = input->readLong(2); |
| 1814 |
if (val) |
| 1815 |
f << "h" << i << "=" << val << ","; |
| 1816 |
} |
| 1817 |
// a dim |
| 1818 |
for (auto &s : sz) s=static_cast<int>(input->readLong(2)); |
| 1819 |
if (sz[0]||sz[1]) |
| 1820 |
f << "dim=" << sz[1] << "x" << sz[0] << ","; |
| 1821 |
// all 0 expected k1=[0|1], k2=[0|1] k4=1 |
| 1822 |
for (int i = 0; i < 9; i++) { |
| 1823 |
val = input->readLong(2); |
| 1824 |
if (val) |
| 1825 |
f << "k" << i << "=" << val << ","; |
| 1826 |
} |
| 1827 |
if (entry.length()!=0xa2) |
| 1828 |
f << "###size=" << entry.length() << ","; |
| 1829 |
rsrcAscii().addPos(pos); |
| 1830 |
rsrcAscii().addNote(f.str().c_str()); |
| 1831 |
|
| 1832 |
if (!dimOk) return true; |
| 1833 |
getPageSpan().setMarginTop(double(LT[1])/72.0); |
| 1834 |
getPageSpan().setMarginBottom(double(RB[1])/72.0); |
| 1835 |
getPageSpan().setMarginLeft(double(LT[0])/72.0); |
| 1836 |
getPageSpan().setMarginRight(double(RB[0])/72.0); |
| 1837 |
getPageSpan().setFormLength(double(pageDim[1])/72.); |
| 1838 |
getPageSpan().setFormWidth(double(pageDim[0])/72.); |
| 1839 |
if (!portrait) |
| 1840 |
getPageSpan().setFormOrientation(MWAWPageSpan::LANDSCAPE); |
| 1841 |
|
| 1842 |
return true; |
| 1843 |
} |
| 1844 |
|
| 1845 |
//////////////////////////////////////////////////////////// |
| 1846 |
// read the CPRC zone ( unknown ) |
| 1847 |
//////////////////////////////////////////////////////////// |
| 1848 |
bool NisusWrtParser::readCPRC(MWAWEntry const &entry) |
| 1849 |
{ |
| 1850 |
if (!entry.valid() || entry.length() < 0xe) { |
| 1851 |
MWAW_DEBUG_MSG(("NisusWrtParser::readCPRC: the entry is bad\n")); |
| 1852 |
return false; |
| 1853 |
} |
| 1854 |
if (entry.id() != 128) { |
| 1855 |
MWAW_DEBUG_MSG(("NisusWrtParser::readCPRC: the entry id %d is odd\n", entry.id())); |
| 1856 |
} |
| 1857 |
entry.setParsed(true); |
| 1858 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1859 |
long pos = entry.begin(); |
| 1860 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1861 |
|
| 1862 |
libmwaw::DebugStream f; |
| 1863 |
if (entry.id() != 128) |
| 1864 |
f << "Entries(CPRC)[#" << entry.id() << "]:"; |
| 1865 |
else |
| 1866 |
f << "Entries(CPRC):"; |
| 1867 |
|
| 1868 |
/** find only 0... |
| 1869 |
except one time f0=1[id?], f4=1900 f6=206c [2pos?] |
| 1870 |
*/ |
| 1871 |
for (int i = 0; i < int(entry.length())/2; i++) { |
| 1872 |
auto val = static_cast<int>(input->readULong(2)); |
| 1873 |
if (val) f << "#f" << i << "=" << std::hex << val << std::dec << ","; |
| 1874 |
} |
| 1875 |
|
| 1876 |
if (entry.length()!=0xe) |
| 1877 |
f << "###size=" << entry.length() << ","; |
| 1878 |
rsrcAscii().addPos(pos-4); |
| 1879 |
rsrcAscii().addNote(f.str().c_str()); |
| 1880 |
return true; |
| 1881 |
} |
| 1882 |
|
| 1883 |
//////////////////////////////////////////////////////////// |
| 1884 |
// read the CNTR zone ( a list of related to VRS ? ) |
| 1885 |
//////////////////////////////////////////////////////////// |
| 1886 |
bool NisusWrtParser::readCNTR(MWAWEntry const &entry, int zoneId) |
| 1887 |
{ |
| 1888 |
if (!entry.valid() || entry.length()<20 || (entry.length()%12) != 8) { |
| 1889 |
MWAW_DEBUG_MSG(("NisusWrtParser::readCNTR: the entry is bad\n")); |
| 1890 |
return false; |
| 1891 |
} |
| 1892 |
if (zoneId < 0 || zoneId >= 3) { |
| 1893 |
MWAW_DEBUG_MSG(("NisusWrtParser::readCNTR: find unexpected zoneId: %d\n", zoneId)); |
| 1894 |
return false; |
| 1895 |
} |
| 1896 |
// NisusWrtParserInternal::Zone &zone = m_state->m_zones[zoneId]; |
| 1897 |
entry.setParsed(true); |
| 1898 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1899 |
long pos = entry.begin(); |
| 1900 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1901 |
|
| 1902 |
int numElt = int(entry.length()/12)-1; |
| 1903 |
libmwaw::DebugStream f; |
| 1904 |
f << "Entries(VariabCntr)[" << zoneId << "]:N=" << numElt; |
| 1905 |
rsrcAscii().addPos(pos-4); |
| 1906 |
rsrcAscii().addNote(f.str().c_str()); |
| 1907 |
for (int i = 0; i < numElt; i++) { |
| 1908 |
// unkn[16] * 3, 0[16], refId, 0[16], unkn[16] |
| 1909 |
pos = input->tell(); |
| 1910 |
f.str(""); |
| 1911 |
f << "VariabCntr" << i << ":"; |
| 1912 |
rsrcAscii().addPos(pos); |
| 1913 |
rsrcAscii().addNote(f.str().c_str()); |
| 1914 |
input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
| 1915 |
} |
| 1916 |
|
| 1917 |
f.str(""); |
| 1918 |
f << "VariabCntr(II)"; |
| 1919 |
rsrcAscii().addPos(input->tell()); |
| 1920 |
rsrcAscii().addNote(f.str().c_str()); |
| 1921 |
|
| 1922 |
return true; |
| 1923 |
} |
| 1924 |
|
| 1925 |
//////////////////////////////////////////////////////////// |
| 1926 |
//! read the ABBR resource: a list of abreviation ? |
| 1927 |
//////////////////////////////////////////////////////////// |
| 1928 |
bool NisusWrtParser::readABBR(MWAWEntry const &entry) |
| 1929 |
{ |
| 1930 |
if (!entry.valid() || entry.length()%32) { |
| 1931 |
MWAW_DEBUG_MSG(("NisusWrtParser::readABBR: the entry is bad\n")); |
| 1932 |
return false; |
| 1933 |
} |
| 1934 |
if (entry.id() != 1003) { |
| 1935 |
MWAW_DEBUG_MSG(("NisusWrtParser::readABBR: the entry id %d is odd\n", entry.id())); |
| 1936 |
} |
| 1937 |
entry.setParsed(true); |
| 1938 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1939 |
long pos = entry.begin(); |
| 1940 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1941 |
|
| 1942 |
libmwaw::DebugStream f; |
| 1943 |
auto numElt = int(entry.length()/32); |
| 1944 |
for (int n = 0; n < numElt; n++) { |
| 1945 |
pos = input->tell(); |
| 1946 |
f.str(""); |
| 1947 |
if (n==0) { |
| 1948 |
if (entry.id() != 1003) |
| 1949 |
f << "Entries(ABBR)[#" << entry.id() << "]"; |
| 1950 |
else |
| 1951 |
f << "Entries(ABBR)"; |
| 1952 |
} |
| 1953 |
else |
| 1954 |
f << "ABBR"; |
| 1955 |
f << "[" << n << "]:"; |
| 1956 |
long id = input->readLong(4); |
| 1957 |
if (id != long(n)) |
| 1958 |
f << "#id=" << id << ","; |
| 1959 |
auto sSz = int(input->readULong(1)); |
| 1960 |
if (sSz > 27) { |
| 1961 |
MWAW_DEBUG_MSG(("NisusWrtParser::readABBR: the string size is bad\n")); |
| 1962 |
f << "##"; |
| 1963 |
} |
| 1964 |
else { |
| 1965 |
std::string str(""); |
| 1966 |
for (int i = 0; i < sSz; i++) |
| 1967 |
str += char(input->readULong(1)); |
| 1968 |
f << "\"" << str << "\","; |
| 1969 |
} |
| 1970 |
rsrcAscii().addPos(n==0 ? pos-4 : pos); |
| 1971 |
rsrcAscii().addNote(f.str().c_str()); |
| 1972 |
input->seek(pos+32, librevenge::RVNG_SEEK_SET); |
| 1973 |
} |
| 1974 |
|
| 1975 |
return true; |
| 1976 |
} |
| 1977 |
|
| 1978 |
//////////////////////////////////////////////////////////// |
| 1979 |
//! read the FTA2 resource: a list of ? |
| 1980 |
//////////////////////////////////////////////////////////// |
| 1981 |
bool NisusWrtParser::readFTA2(MWAWEntry const &entry) |
| 1982 |
{ |
| 1983 |
if (!entry.valid() || entry.length()%12) { |
| 1984 |
MWAW_DEBUG_MSG(("NisusWrtParser::readFTA2: the entry is bad\n")); |
| 1985 |
return false; |
| 1986 |
} |
| 1987 |
if (entry.id() != 1003) { |
| 1988 |
MWAW_DEBUG_MSG(("NisusWrtParser::readFTA2: the entry id %d is odd\n", entry.id())); |
| 1989 |
} |
| 1990 |
entry.setParsed(true); |
| 1991 |
MWAWInputStreamPtr input = rsrcInput(); |
| 1992 |
long pos = entry.begin(); |
| 1993 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1994 |
|
| 1995 |
libmwaw::DebugStream f; |
| 1996 |
auto numElt = int(entry.length()/12); |
| 1997 |
for (int n = 0; n < numElt; n++) { |
| 1998 |
pos = input->tell(); |
| 1999 |
f.str(""); |
| 2000 |
if (n==0) { |
| 2001 |
if (entry.id() != 1003) |
| 2002 |
f << "Entries(FTA2)[#" << entry.id() << "]"; |
| 2003 |
else |
| 2004 |
f << "Entries(FTA2)"; |
| 2005 |
} |
| 2006 |
else |
| 2007 |
f << "FTA2"; |
| 2008 |
f << "[" << n << "]:"; |
| 2009 |
auto val = int(input->readLong(1)); // 0|ff |
| 2010 |
if (val==-1) f << "f0,"; |
| 2011 |
else if (val) f << "f0=" << val << ","; |
| 2012 |
val = int(input->readLong(1)); // 0|6|7|f ( maybe f1=0 if f0=ff ) |
| 2013 |
if (val) |
| 2014 |
f << "f1=" << std::hex << val << std::dec << ","; |
| 2015 |
// always 0 excepted f3=0|ff9f|ffc1 |
| 2016 |
for (int i = 0; i < 5; i++) { |
| 2017 |
val = int(input->readLong(2)); |
| 2018 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 2019 |
} |
| 2020 |
rsrcAscii().addPos(n==0 ? pos-4 : pos); |
| 2021 |
rsrcAscii().addNote(f.str().c_str()); |
| 2022 |
input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
| 2023 |
} |
| 2024 |
|
| 2025 |
return true; |
| 2026 |
} |
| 2027 |
|
| 2028 |
//////////////////////////////////////////////////////////// |
| 2029 |
//! read the FnSc resource: a list of ? |
| 2030 |
//////////////////////////////////////////////////////////// |
| 2031 |
bool NisusWrtParser::readFnSc(MWAWEntry const &entry) |
| 2032 |
{ |
| 2033 |
if (!entry.valid() || entry.length() != 0x42) { |
| 2034 |
MWAW_DEBUG_MSG(("NisusWrtParser::readFnSc: the entry is bad\n")); |
| 2035 |
return false; |
| 2036 |
} |
| 2037 |
if (entry.id() != 1003) { |
| 2038 |
MWAW_DEBUG_MSG(("NisusWrtParser::readFnSc: the entry id %d is odd\n", entry.id())); |
| 2039 |
} |
| 2040 |
entry.setParsed(true); |
| 2041 |
MWAWInputStreamPtr input = rsrcInput(); |
| 2042 |
long pos = entry.begin(); |
| 2043 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2044 |
|
| 2045 |
libmwaw::DebugStream f; |
| 2046 |
if (entry.id() != 1003) |
| 2047 |
f << "Entries(FnSc)[#" << entry.id() << "]:"; |
| 2048 |
else |
| 2049 |
f << "Entries(FnSc):"; |
| 2050 |
long val; |
| 2051 |
val = input->readLong(2); // find 0|3|10|14 |
| 2052 |
if (val) f << "f0=" << val << ","; |
| 2053 |
val = long(input->readULong(2)); // find 0|4000|4034 |
| 2054 |
if (val) f << "f1=" << std::hex << val << std::dec << ","; |
| 2055 |
for (int i = 0; i < 31; i++) { // always 0? |
| 2056 |
val = input->readLong(2); |
| 2057 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 2058 |
} |
| 2059 |
rsrcAscii().addPos(pos-4); |
| 2060 |
rsrcAscii().addNote(f.str().c_str()); |
| 2061 |
|
| 2062 |
return true; |
| 2063 |
} |
| 2064 |
|
| 2065 |
//////////////////////////////////////////////////////////// |
| 2066 |
//! read the INFO resource: a unknown zone |
| 2067 |
//////////////////////////////////////////////////////////// |
| 2068 |
bool NisusWrtParser::readINFO(MWAWEntry const &entry) |
| 2069 |
{ |
| 2070 |
if (!entry.valid() || entry.length() < 0x23a) { |
| 2071 |
MWAW_DEBUG_MSG(("NisusWrtParser::readINFO: the entry is bad\n")); |
| 2072 |
return false; |
| 2073 |
} |
| 2074 |
if (entry.id() != 1003) { |
| 2075 |
MWAW_DEBUG_MSG(("NisusWrtParser::readINFO: the entry id %d is odd\n", entry.id())); |
| 2076 |
} |
| 2077 |
entry.setParsed(true); |
| 2078 |
MWAWInputStreamPtr input = rsrcInput(); |
| 2079 |
long pos = entry.begin(); |
| 2080 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2081 |
|
| 2082 |
libmwaw::DebugStream f; |
| 2083 |
if (entry.id() != 1003) |
| 2084 |
f << "Entries(INFO)[#" << entry.id() << "]:"; |
| 2085 |
else |
| 2086 |
f << "Entries(INFO):"; |
| 2087 |
long val = input->readLong(2); |
| 2088 |
if (val != 1) f << "f0=" << val << ","; |
| 2089 |
int select[2]; // checkme |
| 2090 |
for (auto &sel : select) sel = static_cast<int>(input->readLong(4)); |
| 2091 |
if (select[0] || select[1]) { |
| 2092 |
f << "select=" << select[0]; |
| 2093 |
if (select[1] != select[0]) f << "x" << select[1]; |
| 2094 |
f << ","; |
| 2095 |
} |
| 2096 |
val = input->readLong(2); |
| 2097 |
if (val) f << "f1=" << val << ","; |
| 2098 |
// a dim or 2 position ? |
| 2099 |
int dim[4]; |
| 2100 |
for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
| 2101 |
if (dim[0] || dim[1] || dim[2] || dim[3]) |
| 2102 |
f << "dim|pos?=" << dim[0] << "x" << dim[1] |
| 2103 |
<< "<->" << dim[2] << "x" << dim[3] << ","; |
| 2104 |
int sz[2]; |
| 2105 |
for (auto &s : sz) s = static_cast<int>(input->readLong(2)); |
| 2106 |
if (sz[0] || sz[1]) |
| 2107 |
f << "sz=" << sz[0] << "x" << sz[1] << ","; |
| 2108 |
for (int i = 0; i < 2; i++) { // always 1|1 |
| 2109 |
val = input->readLong(1); |
| 2110 |
if (val) f << "fl" << i << "=" << val << ","; |
| 2111 |
} |
| 2112 |
for (int i = 0; i < 8; i++) { // always 0 |
| 2113 |
val = input->readLong(2); |
| 2114 |
if (val) f << "g" << i << "=" << val << ","; |
| 2115 |
} |
| 2116 |
rsrcAscii().addPos(pos-4); |
| 2117 |
rsrcAscii().addNote(f.str().c_str()); |
| 2118 |
|
| 2119 |
pos = input->tell(); |
| 2120 |
f.str(""); |
| 2121 |
f << "INFOA0:"; |
| 2122 |
for (int i = 0; i < 4; i++) { // find 0-0-0-0 or 1-1-1-1 or 1-1-1-4 |
| 2123 |
val = input->readLong(2); |
| 2124 |
if (val) f << "f" << i << "=" << val << ","; |
| 2125 |
} |
| 2126 |
// 4 times the same val: 0, aa55, ffff |
| 2127 |
auto unkn = static_cast<int>(input->readULong(2)); |
| 2128 |
if (unkn) f << "unknA0=" << std::hex << unkn << std::dec << ","; |
| 2129 |
for (int i = 1; i < 4; i++) { |
| 2130 |
val = long(input->readULong(2)); |
| 2131 |
if (val != unkn) |
| 2132 |
f << "unknA" << i << "=" << std::hex << val << std::dec << ","; |
| 2133 |
} |
| 2134 |
// 4 times the same val: 0, ffff |
| 2135 |
unkn = static_cast<int>(input->readULong(2)); |
| 2136 |
if (unkn) f << "unknB0=" << std::hex << unkn << std::dec << ","; |
| 2137 |
for (int i = 1; i < 4; i++) { |
| 2138 |
val = long(input->readULong(2)); |
| 2139 |
if (val != unkn) |
| 2140 |
f << "unknB" << i << "=" << std::hex << val << std::dec << ","; |
| 2141 |
} |
| 2142 |
rsrcAscii().addDelimiter(input->tell(),'|'); |
| 2143 |
rsrcAscii().addPos(pos); |
| 2144 |
rsrcAscii().addNote(f.str().c_str()); |
| 2145 |
|
| 2146 |
input->seek(pos+0x2c, librevenge::RVNG_SEEK_SET); |
| 2147 |
pos = input->tell(); |
| 2148 |
f.str(""); |
| 2149 |
f << "INFOB:"; |
| 2150 |
rsrcAscii().addPos(pos); |
| 2151 |
rsrcAscii().addNote(f.str().c_str()); |
| 2152 |
|
| 2153 |
input->seek(pos+0x112, librevenge::RVNG_SEEK_SET); |
| 2154 |
pos = input->tell(); |
| 2155 |
f.str(""); |
| 2156 |
f << "INFOA1:"; |
| 2157 |
rsrcAscii().addPos(pos); |
| 2158 |
rsrcAscii().addNote(f.str().c_str()); |
| 2159 |
|
| 2160 |
input->seek(entry.begin() + 0x194, librevenge::RVNG_SEEK_SET); |
| 2161 |
pos = input->tell(); |
| 2162 |
f.str(""); |
| 2163 |
f << "INFOC:"; |
| 2164 |
|
| 2165 |
auto &ftInfo = m_state->m_footnoteInfo; |
| 2166 |
ftInfo.m_flags = static_cast<int>(input->readULong(2)); |
| 2167 |
ftInfo.m_unknown = static_cast<int>(input->readLong(2)); |
| 2168 |
ftInfo.m_distToDocument = static_cast<int>(input->readLong(2)); |
| 2169 |
ftInfo.m_distSeparator = static_cast<int>(input->readLong(2)); |
| 2170 |
ftInfo.m_separatorLength = static_cast<int>(input->readLong(2)); |
| 2171 |
f << "footnote=[" << ftInfo << "],"; |
| 2172 |
rsrcAscii().addDelimiter(input->tell(), '|'); |
| 2173 |
rsrcAscii().addPos(pos); |
| 2174 |
rsrcAscii().addNote(f.str().c_str()); |
| 2175 |
|
| 2176 |
return true; |
| 2177 |
} |
| 2178 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |