| 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 <algorithm> |
| 35 |
#include <cmath> |
| 36 |
#include <iomanip> |
| 37 |
#include <iostream> |
| 38 |
#include <limits> |
| 39 |
#include <map> |
| 40 |
#include <set> |
| 41 |
#include <sstream> |
| 42 |
|
| 43 |
#include <librevenge/librevenge.h> |
| 44 |
|
| 45 |
#include "MWAWFontConverter.hxx" |
| 46 |
#include "MWAWGraphicListener.hxx" |
| 47 |
#include "MWAWGraphicShape.hxx" |
| 48 |
#include "MWAWGraphicStyle.hxx" |
| 49 |
#include "MWAWHeader.hxx" |
| 50 |
#include "MWAWParagraph.hxx" |
| 51 |
#include "MWAWPictBitmap.hxx" |
| 52 |
#include "MWAWPictData.hxx" |
| 53 |
#include "MWAWPrinter.hxx" |
| 54 |
#include "MWAWPosition.hxx" |
| 55 |
#include "MWAWSubDocument.hxx" |
| 56 |
|
| 57 |
#include "ReadySetGoParser.hxx" |
| 58 |
|
| 59 |
#include "ReadySetGoGraph.hxx" |
| 60 |
#include "ReadySetGoStyleManager.hxx" |
| 61 |
|
| 62 |
/** Internal: the structures of a ReadySetGoParser */ |
| 63 |
namespace ReadySetGoParserInternal |
| 64 |
{ |
| 65 |
|
| 66 |
//////////////////////////////////////// |
| 67 |
//! Internal: the state of a ReadySetGoParser |
| 68 |
struct State { |
| 69 |
//! constructor |
| 70 |
State() |
| 71 |
: m_designStudio(false) |
| 72 |
, m_numLayouts(1) |
| 73 |
, m_numGlossary(0) |
| 74 |
, m_numObjectGlossary(0) |
| 75 |
, m_numStyles(0) |
| 76 |
, m_hasCustomColors(false) |
| 77 |
, m_hasFontsBlock2(false) |
| 78 |
{ |
| 79 |
} |
| 80 |
//! a flag to descriminate between ReadySetGo and Design Studio |
| 81 |
bool m_designStudio; |
| 82 |
//! the number of layouts: used for v3 |
| 83 |
int m_numLayouts; |
| 84 |
//! the number of glossary: used for v4 |
| 85 |
int m_numGlossary; |
| 86 |
//! the number of object glossary: used for v6 |
| 87 |
int m_numObjectGlossary; |
| 88 |
//! the number of styles: v4 |
| 89 |
int m_numStyles; |
| 90 |
//! a flag to know if the document has custom colors: v5 |
| 91 |
bool m_hasCustomColors; |
| 92 |
//! a unknown zone : v6 |
| 93 |
bool m_hasFontsBlock2; |
| 94 |
}; |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
//////////////////////////////////////////////////////////// |
| 99 |
// constructor/destructor, ... |
| 100 |
//////////////////////////////////////////////////////////// |
| 101 |
ReadySetGoParser::ReadySetGoParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 102 |
: MWAWGraphicParser(input, rsrcParser, header) |
| 103 |
, m_graphParser() |
| 104 |
, m_styleManager() |
| 105 |
, m_state(new ReadySetGoParserInternal::State) |
| 106 |
{ |
| 107 |
m_styleManager.reset(new ReadySetGoStyleManager(*this)); |
| 108 |
m_graphParser.reset(new ReadySetGoGraph(*this)); |
| 109 |
setAsciiName("main-1"); |
| 110 |
getPageSpan().setMargins(0.1); |
| 111 |
} |
| 112 |
|
| 113 |
ReadySetGoParser::~ReadySetGoParser() |
| 114 |
{ |
| 115 |
} |
| 116 |
|
| 117 |
bool ReadySetGoParser::isDesignStudioFile() const |
| 118 |
{ |
| 119 |
return m_state->m_designStudio; |
| 120 |
} |
| 121 |
|
| 122 |
//////////////////////////////////////////////////////////// |
| 123 |
// the parser |
| 124 |
//////////////////////////////////////////////////////////// |
| 125 |
void ReadySetGoParser::parse(librevenge::RVNGDrawingInterface *docInterface) |
| 126 |
{ |
| 127 |
if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
| 128 |
bool ok = false; |
| 129 |
try { |
| 130 |
// create the asciiFile |
| 131 |
ascii().setStream(getInput()); |
| 132 |
ascii().open(asciiName()); |
| 133 |
checkHeader(nullptr); |
| 134 |
|
| 135 |
// update the style manager, ... |
| 136 |
ok = createZones(); |
| 137 |
if (ok) { |
| 138 |
createDocument(docInterface); |
| 139 |
ok=getGraphicListener() && m_graphParser->sendPages(); |
| 140 |
} |
| 141 |
ascii().reset(); |
| 142 |
} |
| 143 |
catch (...) { |
| 144 |
MWAW_DEBUG_MSG(("ReadySetGoParser::parse: exception catched when parsing\n")); |
| 145 |
ok = false; |
| 146 |
} |
| 147 |
|
| 148 |
resetGraphicListener(); |
| 149 |
if (!ok) throw(libmwaw::ParseException()); |
| 150 |
} |
| 151 |
|
| 152 |
//////////////////////////////////////////////////////////// |
| 153 |
// create the document |
| 154 |
//////////////////////////////////////////////////////////// |
| 155 |
void ReadySetGoParser::createDocument(librevenge::RVNGDrawingInterface *documentInterface) |
| 156 |
{ |
| 157 |
if (!documentInterface) return; |
| 158 |
if (getGraphicListener()) { |
| 159 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createDocument: listener already exist\n")); |
| 160 |
return; |
| 161 |
} |
| 162 |
|
| 163 |
// create the page list |
| 164 |
std::vector<MWAWPageSpan> pageList; |
| 165 |
m_graphParser->updatePageSpanList(pageList); |
| 166 |
MWAWGraphicListenerPtr listen(new MWAWGraphicListener(*getParserState(), pageList, documentInterface)); |
| 167 |
setGraphicListener(listen); |
| 168 |
listen->startDocument(); |
| 169 |
m_graphParser->sendMasterPages(); |
| 170 |
} |
| 171 |
|
| 172 |
//////////////////////////////////////////////////////////// |
| 173 |
// |
| 174 |
// Intermediate level |
| 175 |
// |
| 176 |
//////////////////////////////////////////////////////////// |
| 177 |
bool ReadySetGoParser::createZones() |
| 178 |
{ |
| 179 |
auto input=getInput(); |
| 180 |
int const vers=version(); |
| 181 |
bool const designStudio=isDesignStudioFile(); |
| 182 |
if (!input) { |
| 183 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: no input\n")); |
| 184 |
return false; |
| 185 |
} |
| 186 |
libmwaw::DebugStream f; |
| 187 |
if (vers<3) |
| 188 |
input->seek(0, librevenge::RVNG_SEEK_SET); |
| 189 |
else if (vers==3) { |
| 190 |
input->seek(2, librevenge::RVNG_SEEK_SET); |
| 191 |
if (!readDocument()) |
| 192 |
return false; |
| 193 |
} |
| 194 |
else { |
| 195 |
if (!input->checkPosition(vers<=5 ? 100 : 200)) { |
| 196 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: the file seems too short\n")); |
| 197 |
return false; |
| 198 |
} |
| 199 |
input->seek(2, librevenge::RVNG_SEEK_SET); |
| 200 |
f.str(""); |
| 201 |
f << "Entries(ZonePos):"; |
| 202 |
std::map<long,int> posToId; |
| 203 |
f << "pos=["; |
| 204 |
for (int i=0; i<(vers==4 ? 2 : vers==5 ? 5 : 12); ++i) { // Style, ???? |
| 205 |
long posi=input->readLong(4); |
| 206 |
f << std::hex << posi << std::dec << ","; |
| 207 |
if (posi<(vers==4 ? 0x100 : 0x300) || !input->checkPosition(posi)) { |
| 208 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: the %d th positions seems bad\n", i)); |
| 209 |
f << "###"; |
| 210 |
ascii().addPos(2); |
| 211 |
ascii().addNote(f.str().c_str()); |
| 212 |
return false; |
| 213 |
} |
| 214 |
posToId[posi]=i; |
| 215 |
} |
| 216 |
f << "],"; |
| 217 |
for (int i=0; i<(vers==4 ? 45 : vers==5 ? 39 : 75); ++i) { |
| 218 |
int val=int(input->readLong(2)); |
| 219 |
if (val) |
| 220 |
f << "f" << i << "=" << val << ","; |
| 221 |
} |
| 222 |
ascii().addPos(2); |
| 223 |
ascii().addNote(f.str().c_str()); |
| 224 |
|
| 225 |
// first zone |
| 226 |
if (!readDocument() || !readPrintInfo() || !m_graphParser->readLayoutsList(m_state->m_numLayouts)) |
| 227 |
return false; |
| 228 |
// 26 master possible A to Z times 2 (left or right) |
| 229 |
if (vers>=6 && !designStudio && !m_graphParser->readLayoutsList(52, true)) |
| 230 |
return false; |
| 231 |
if (!readIdsList() || input->tell()>posToId.begin()->first) |
| 232 |
return false; |
| 233 |
if (input->tell()<posToId.begin()->first) { |
| 234 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: find extra data for the beginning zone\n")); |
| 235 |
ascii().addPos(input->tell()); |
| 236 |
ascii().addNote("ZonePos:extra###"); |
| 237 |
} |
| 238 |
for (auto posIdIt=posToId.begin(); posIdIt!=posToId.end();) { |
| 239 |
long pos=posIdIt->first; |
| 240 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 241 |
int id=posIdIt->second, origId=id; |
| 242 |
if (vers>=6) { |
| 243 |
if (id<3 || (id>=7 && id<=9) || id==11) |
| 244 |
; |
| 245 |
// 2: color list?, 3: color name? |
| 246 |
else if (id>=4 && id<=5) |
| 247 |
--id; |
| 248 |
// 6: N, -1, -256 + Nx[8 bytes?] |
| 249 |
else |
| 250 |
id=-1; |
| 251 |
} |
| 252 |
++posIdIt; |
| 253 |
long endPos=posIdIt==posToId.end() ? -1 : posIdIt->first; |
| 254 |
if (endPos>0) |
| 255 |
input->pushLimit(endPos); |
| 256 |
bool ok=true; |
| 257 |
switch (id) { |
| 258 |
case 0: |
| 259 |
ok=m_styleManager->readStyles(m_state->m_numStyles); |
| 260 |
break; |
| 261 |
case 1: |
| 262 |
ok=readGlossary(); |
| 263 |
break; |
| 264 |
case 2: |
| 265 |
if (!m_state->m_hasCustomColors) { |
| 266 |
if (!input->checkPosition(pos+4)) { |
| 267 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones[color]: can not find the data\n")); |
| 268 |
ok=false; |
| 269 |
break; |
| 270 |
} |
| 271 |
// normally followed by 0 |
| 272 |
ascii().addPos(pos); |
| 273 |
ascii().addNote("_"); |
| 274 |
break; |
| 275 |
} |
| 276 |
ok=m_styleManager->readColors(); |
| 277 |
break; |
| 278 |
case 3: |
| 279 |
ok=m_styleManager->readColorNames(); |
| 280 |
break; |
| 281 |
case 4: |
| 282 |
ok=m_styleManager->readFontsBlock(); |
| 283 |
break; |
| 284 |
case 7: |
| 285 |
ok=m_styleManager->readFontsName(); |
| 286 |
break; |
| 287 |
case 8: |
| 288 |
ok=readFontsUnknown(); |
| 289 |
break; |
| 290 |
case 9: |
| 291 |
ok=readObjectGlossary(); |
| 292 |
break; |
| 293 |
case 11: |
| 294 |
ok=readZone11(); |
| 295 |
break; |
| 296 |
// 9: N?x40char, then ? maybe link to templates data |
| 297 |
// 10: find len=4c, 2 IDS + 6 small values b,b,c,d,a,a |
| 298 |
default: |
| 299 |
if (vers>=6) { |
| 300 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 301 |
f.str(""); |
| 302 |
f << "Entries(Zone" << origId << "A):"; |
| 303 |
long len=long(input->readLong(4)); |
| 304 |
long zEndPos=pos+4+len; |
| 305 |
if (zEndPos<pos+4 || (endPos>0 && zEndPos>endPos) || (endPos<=0 && !input->checkPosition(zEndPos))) { |
| 306 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones[unknown, last]: can not find the data\n")); |
| 307 |
ok=false; |
| 308 |
break; |
| 309 |
} |
| 310 |
ascii().addPos(pos); |
| 311 |
ascii().addNote(f.str().c_str()); |
| 312 |
input->seek(zEndPos, librevenge::RVNG_SEEK_SET); |
| 313 |
break; |
| 314 |
} |
| 315 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: find unexpected zone=%d\n", id)); |
| 316 |
ok=false; |
| 317 |
break; |
| 318 |
} |
| 319 |
if (endPos>0) |
| 320 |
input->popLimit(); |
| 321 |
if (ok) { |
| 322 |
input->popLimit(); |
| 323 |
if (endPos>0) |
| 324 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 325 |
continue; |
| 326 |
} |
| 327 |
ascii().addPos(pos); |
| 328 |
ascii().addNote("Entries(Bad):###"); |
| 329 |
if (endPos==-1) // no way to continue |
| 330 |
return false; |
| 331 |
} |
| 332 |
if (m_state->m_hasFontsBlock2 && !m_styleManager->readFontsBlock2()) |
| 333 |
return false; |
| 334 |
return m_graphParser->readShapes(); |
| 335 |
} |
| 336 |
|
| 337 |
if (!readPrintInfo()) |
| 338 |
return false; |
| 339 |
|
| 340 |
if (vers==3) { |
| 341 |
if (!m_graphParser->readLayoutsList(m_state->m_numLayouts) || !readIdsList()) |
| 342 |
return false; |
| 343 |
// always empty |
| 344 |
long pos=input->tell(); |
| 345 |
long len=long(input->readLong(4)); |
| 346 |
f.str(""); |
| 347 |
f << "Entries(Zone0):"; |
| 348 |
if ((long)((unsigned long)pos+4+(unsigned long)len)<pos+4 || !input->checkPosition(pos+4+len)) { |
| 349 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: can not find a initial zone0\n")); |
| 350 |
f << "###"; |
| 351 |
ascii().addPos(pos); |
| 352 |
ascii().addNote(f.str().c_str()); |
| 353 |
return false; |
| 354 |
} |
| 355 |
if (len==0) { |
| 356 |
ascii().addPos(pos); |
| 357 |
ascii().addNote("_"); |
| 358 |
} |
| 359 |
else { |
| 360 |
ascii().addPos(pos); |
| 361 |
ascii().addNote(f.str().c_str()); |
| 362 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 363 |
} |
| 364 |
} |
| 365 |
if (!m_graphParser->readShapes()) |
| 366 |
return false; |
| 367 |
|
| 368 |
if (!input->isEnd()) { |
| 369 |
MWAW_DEBUG_MSG(("ReadySetGoParser::createZones: find extra data\n")); |
| 370 |
ascii().addPos(input->tell()); |
| 371 |
ascii().addNote("Entries(Extra):###"); |
| 372 |
} |
| 373 |
return true; |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
//////////////////////////////////////////////////////////// |
| 378 |
// read the header |
| 379 |
//////////////////////////////////////////////////////////// |
| 380 |
bool ReadySetGoParser::checkHeader(MWAWHeader *header, bool strict) |
| 381 |
{ |
| 382 |
*m_state = ReadySetGoParserInternal::State(); |
| 383 |
MWAWInputStreamPtr input = getInput(); |
| 384 |
if (!input || !input->hasDataFork() || !input->checkPosition(126)) |
| 385 |
return false; |
| 386 |
|
| 387 |
libmwaw::DebugStream f; |
| 388 |
f << "FileHeader:"; |
| 389 |
input->seek(0, librevenge::RVNG_SEEK_SET); |
| 390 |
int val=int(input->readULong(2)); |
| 391 |
f << "vers=" << val << ","; |
| 392 |
int vers=1; |
| 393 |
m_state->m_designStudio=false; |
| 394 |
if (val==0x1e) { // 30 |
| 395 |
if (input->readULong(2) || input->readULong(2)!=0x86) |
| 396 |
return false; |
| 397 |
vers=3; |
| 398 |
} |
| 399 |
else if (val>=400 && val<=402) // I only see 400 |
| 400 |
vers=4; |
| 401 |
else if (val>=5000 && val<=5005) // I only see 5003 v4.5 |
| 402 |
vers=5; |
| 403 |
else if (val>=6000 && val<=6003) //I only see 6000 |
| 404 |
vers=6; |
| 405 |
// I only find some demo files, these files look very simillar to v6 files |
| 406 |
// I try to modified the parser to parse them, but there remains some |
| 407 |
// problems at least colors' problems |
| 408 |
else if (val==7100) // 7100 v7.1 |
| 409 |
vers=7; |
| 410 |
else if (val==0x13e4) { // Design Studio, visibly was forked between RSG 4.5 and RSG 6 |
| 411 |
f << "designStudio,"; |
| 412 |
m_state->m_designStudio=true; |
| 413 |
vers=6; |
| 414 |
} |
| 415 |
else if (val!=0x78) |
| 416 |
return false; |
| 417 |
ascii().addPos(0); |
| 418 |
ascii().addNote(f.str().c_str()); |
| 419 |
|
| 420 |
if (vers<3) { |
| 421 |
// we need to retrieve the version v1 or v2 |
| 422 |
input->seek(2+120, librevenge::RVNG_SEEK_SET); |
| 423 |
int n=int(input->readULong(2)); |
| 424 |
if (n<=0) |
| 425 |
return false; |
| 426 |
|
| 427 |
// |
| 428 |
// first test for version 2, the more structured |
| 429 |
// |
| 430 |
bool ok=true; |
| 431 |
vers=2; |
| 432 |
int nShapes=0; |
| 433 |
for (int p=0; p<n; ++p) { |
| 434 |
long pos=input->tell(); |
| 435 |
if (!input->checkPosition(pos+2)) { |
| 436 |
ok=false; |
| 437 |
break; |
| 438 |
} |
| 439 |
val=int(input->readLong(2)); |
| 440 |
if (val<0) { |
| 441 |
ok=false; |
| 442 |
break; |
| 443 |
} |
| 444 |
nShapes+=val; |
| 445 |
} |
| 446 |
for (int s=0; s<nShapes; ++s) { |
| 447 |
long pos=input->tell(); |
| 448 |
if (!ok || !input->checkPosition(pos+4)) { |
| 449 |
ok=false; |
| 450 |
break; |
| 451 |
} |
| 452 |
int type=int(input->readULong(2)); |
| 453 |
if (type<0 || type>6) { |
| 454 |
ok=false; |
| 455 |
break; |
| 456 |
} |
| 457 |
input->seek(2, librevenge::RVNG_SEEK_CUR); |
| 458 |
for (int i=0; i<2; ++i) { |
| 459 |
pos=input->tell(); |
| 460 |
int len=int(input->readULong(2)); |
| 461 |
if ((i==0 && len!=0x1c) || !input->checkPosition(pos+2+len)) { |
| 462 |
ok=false; |
| 463 |
break; |
| 464 |
} |
| 465 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 466 |
} |
| 467 |
if (!ok) |
| 468 |
break; |
| 469 |
if (type==3 && !input->isEnd()) { |
| 470 |
// we must check if there is a picture |
| 471 |
pos=input->tell(); |
| 472 |
int len=int(input->readULong(2)); |
| 473 |
if (len<10) |
| 474 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 475 |
else { |
| 476 |
if (!input->checkPosition(pos+2+len)) { |
| 477 |
ok=false; |
| 478 |
break; |
| 479 |
} |
| 480 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 481 |
} |
| 482 |
} |
| 483 |
if (type!=4) |
| 484 |
continue; |
| 485 |
for (int st=0; st<2; ++st) { // zone1=[text, style], zone2=[para] |
| 486 |
pos=input->tell(); |
| 487 |
int len=int(input->readULong(2)); |
| 488 |
if (!input->checkPosition(pos+2+len)) { |
| 489 |
ok=false; |
| 490 |
break; |
| 491 |
} |
| 492 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 493 |
} |
| 494 |
} |
| 495 |
if (ok && nShapes<=10 && !input->isEnd()) |
| 496 |
ok=false; |
| 497 |
|
| 498 |
if (!ok) { |
| 499 |
// test for version 1 |
| 500 |
ok=true; |
| 501 |
vers=1; |
| 502 |
input->seek(2+120+2, librevenge::RVNG_SEEK_SET); |
| 503 |
for (int i=0; i<std::min(10,n); ++i) { |
| 504 |
long pos=input->tell(); |
| 505 |
if (!input->checkPosition(pos+26)) { |
| 506 |
ok=false; |
| 507 |
break; |
| 508 |
} |
| 509 |
int type=int(input->readLong(2)); |
| 510 |
if (type<0 || type>5 || type==2) { |
| 511 |
ok=false; |
| 512 |
break; |
| 513 |
} |
| 514 |
int const expectedSize[]= {26, 74, 0, 30, 28, 28}; |
| 515 |
if (expectedSize[type]<=0 || !input->checkPosition(pos+expectedSize[type])) { |
| 516 |
ok=false; |
| 517 |
break; |
| 518 |
} |
| 519 |
input->seek(pos+expectedSize[type], librevenge::RVNG_SEEK_SET); |
| 520 |
if (type==0 && i+1!=n) { |
| 521 |
ok=false; |
| 522 |
break; |
| 523 |
} |
| 524 |
if (type==5 && !input->isEnd()) { |
| 525 |
// we must check if there is a picture |
| 526 |
pos=input->tell(); |
| 527 |
int len=int(input->readULong(2)); |
| 528 |
if (len<10) |
| 529 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 530 |
else { |
| 531 |
if (!input->checkPosition(pos+2+len)) { |
| 532 |
ok=false; |
| 533 |
break; |
| 534 |
} |
| 535 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 536 |
} |
| 537 |
} |
| 538 |
if (type!=1) |
| 539 |
continue; |
| 540 |
for (int st=0; st<2; ++st) { |
| 541 |
pos=input->tell(); |
| 542 |
int len=int(input->readULong(2)); |
| 543 |
if (!input->checkPosition(pos+2+len)) { |
| 544 |
ok=false; |
| 545 |
break; |
| 546 |
} |
| 547 |
input->seek(pos+2+len, librevenge::RVNG_SEEK_SET); |
| 548 |
} |
| 549 |
} |
| 550 |
if (ok && n<=10 && !input->isEnd()) |
| 551 |
ok=false; |
| 552 |
} |
| 553 |
if (!ok) |
| 554 |
return false; |
| 555 |
} |
| 556 |
else if (vers==3) { |
| 557 |
if (strict) { |
| 558 |
input->seek(2, librevenge::RVNG_SEEK_SET); |
| 559 |
for (int i=0; i<3; ++i) { |
| 560 |
long pos=input->tell(); |
| 561 |
long len=long(input->readLong(4)); |
| 562 |
if ((long)((unsigned long)pos+4+(unsigned long)len)<pos+4 || !input->checkPosition(pos+4+len)) |
| 563 |
return false; |
| 564 |
if (len==0 && i<2) |
| 565 |
return false; |
| 566 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
else { // vers>3 |
| 571 |
if (vers>=6 && !input->checkPosition(200+20)) |
| 572 |
return false; |
| 573 |
|
| 574 |
input->seek(2, librevenge::RVNG_SEEK_SET); |
| 575 |
// first check the initial list of pointers |
| 576 |
int emptyZone=0; |
| 577 |
for (int i=0; i<(vers==4 ? 2 : vers==5 ? 5 : 12); ++i) { |
| 578 |
long pos=long(input->readLong(4)); |
| 579 |
if (pos==0) |
| 580 |
++emptyZone; |
| 581 |
else if (pos<(vers==4 ? 0x100 : 0x300) || !input->checkPosition(pos)) |
| 582 |
return false; |
| 583 |
} |
| 584 |
if (emptyZone>1) |
| 585 |
return false; |
| 586 |
if (strict) { |
| 587 |
input->seek(vers<=5 ? 100 : 200, librevenge::RVNG_SEEK_SET); |
| 588 |
for (int step=0; step<4; ++step) { |
| 589 |
long pos=input->tell(); |
| 590 |
long len=long(input->readLong(4)); |
| 591 |
if (pos+4+len<pos+len || !input->checkPosition(pos+4+len)) |
| 592 |
return false; |
| 593 |
if (step==0 && len<(vers==4 ? 0xcc : vers==5 ? 0x188 : vers==6 ? (m_state->m_designStudio ? 0x2be : 0x58c) : 0x5a0)) |
| 594 |
return false; |
| 595 |
if (step==1 && len!=0x78) |
| 596 |
return false; |
| 597 |
input->seek(pos+4+len, librevenge::RVNG_SEEK_SET); |
| 598 |
} |
| 599 |
} |
| 600 |
} |
| 601 |
setVersion(vers); |
| 602 |
if (header) |
| 603 |
header->reset(MWAWDocument::MWAW_T_READYSETGO, vers, MWAWDocument::MWAW_K_DRAW); |
| 604 |
|
| 605 |
return true; |
| 606 |
} |
| 607 |
|
| 608 |
//////////////////////////////////////////////////////////// |
| 609 |
// try to read the main zone |
| 610 |
//////////////////////////////////////////////////////////// |
| 611 |
bool ReadySetGoParser::readDocument() |
| 612 |
{ |
| 613 |
int const vers=version(); |
| 614 |
if (vers<3) { |
| 615 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: unexpected version\n")); |
| 616 |
return false; |
| 617 |
} |
| 618 |
MWAWInputStreamPtr input = getInput(); |
| 619 |
if (!input) |
| 620 |
return false; |
| 621 |
long pos=input->tell(); |
| 622 |
if (!input->checkPosition(pos+4)) { |
| 623 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: can not read the zone length\n")); |
| 624 |
return false; |
| 625 |
} |
| 626 |
libmwaw::DebugStream f; |
| 627 |
f << "Entries(Document):"; |
| 628 |
long len=long(input->readLong(4)); |
| 629 |
long endPos=pos+4+len; |
| 630 |
if (len<0 || !input->checkPosition(endPos)) { |
| 631 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: can not read the zone length\n")); |
| 632 |
f << "###"; |
| 633 |
ascii().addPos(pos); |
| 634 |
ascii().addNote(f.str().c_str()); |
| 635 |
return false; |
| 636 |
} |
| 637 |
bool const designStudio=isDesignStudioFile(); |
| 638 |
long const expectedLength=vers==3 ? 0x86 : vers==4 ? 0xcc : vers==5 ? 0x188 : vers== 6 ? (designStudio ? 0x2be : 0x58c) : 0x5a0; // v7.1: I find len=5a0 or len=211b |
| 639 |
if (len<expectedLength) { |
| 640 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: unexpected zone length\n")); |
| 641 |
f << "###"; |
| 642 |
ascii().addPos(pos); |
| 643 |
ascii().addNote(f.str().c_str()); |
| 644 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 645 |
return true; |
| 646 |
} |
| 647 |
if (len>expectedLength) { |
| 648 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: find extra data\n")); |
| 649 |
ascii().addPos(pos+4+expectedLength); |
| 650 |
ascii().addNote("Document-extra:###"); |
| 651 |
} |
| 652 |
f << "ID=" << std::hex << input->readULong(4) << std::dec << ","; |
| 653 |
if (vers>=6) { |
| 654 |
int cLen=int(input->readULong(1)); |
| 655 |
if (cLen>63) { |
| 656 |
f << "###"; |
| 657 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: unexpected file name len\n")); |
| 658 |
cLen=0; |
| 659 |
} |
| 660 |
std::string name; |
| 661 |
for (int i=0; i<cLen; ++i) { |
| 662 |
char c=char(input->readLong(1)); |
| 663 |
if (c==0) |
| 664 |
break; |
| 665 |
name+=c; |
| 666 |
} |
| 667 |
f << "printer=" << name << ","; |
| 668 |
input->seek(pos+4+4+64, librevenge::RVNG_SEEK_SET); |
| 669 |
for (int i=0; i<8; ++i) { // f2=0|6|8 |
| 670 |
int val=int(input->readLong(2)); |
| 671 |
int const expected[]= {0,0,0,100,0,256,2,0}; |
| 672 |
if (val!=expected[i]) |
| 673 |
f << "f" << i << "=" << val << ","; |
| 674 |
} |
| 675 |
for (int i=0; i<12; ++i) { |
| 676 |
int val=int(input->readLong(2)); |
| 677 |
if (val) |
| 678 |
f << "g" << i << "=" << val << ","; |
| 679 |
} |
| 680 |
ascii().addPos(pos); |
| 681 |
ascii().addNote(f.str().c_str()); |
| 682 |
input->seek(pos+4+108, librevenge::RVNG_SEEK_SET); |
| 683 |
|
| 684 |
pos=input->tell(); |
| 685 |
f.str(""); |
| 686 |
f << "Document-0:"; |
| 687 |
} |
| 688 |
int val=int(input->readLong(2)); |
| 689 |
if (val!=1) |
| 690 |
f << "first[page]=" << val << ","; |
| 691 |
m_state->m_numLayouts=int(input->readLong(2)); |
| 692 |
if (m_state->m_numLayouts) |
| 693 |
f << "num[layout]=" << m_state->m_numLayouts << ","; |
| 694 |
val=int(input->readLong(2)); |
| 695 |
if (val+1!=m_state->m_numLayouts) |
| 696 |
f << "act[layout]=" << val << ","; |
| 697 |
if (vers>=6 && !designStudio) { |
| 698 |
f << "IDS=["; |
| 699 |
for (int i=0; i<2; ++i) |
| 700 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 701 |
f << "],"; |
| 702 |
val=int(input->readLong(2)); |
| 703 |
if (val) |
| 704 |
f << "num[unkn]=" << val << ","; |
| 705 |
f << "ID0=["; |
| 706 |
for (int i=0; i<2; ++i) |
| 707 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 708 |
f << "],"; |
| 709 |
} |
| 710 |
else { |
| 711 |
f << "IDS=["; |
| 712 |
for (int i=0; i<3; ++i) |
| 713 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 714 |
f << "],"; |
| 715 |
} |
| 716 |
val=int(input->readLong(2)); |
| 717 |
if (val) { |
| 718 |
m_state->m_numGlossary=val; |
| 719 |
f << "num[glossary]=" << val << ","; |
| 720 |
} |
| 721 |
f << "ID1=" << std::hex << input->readULong(4) << std::dec << ","; |
| 722 |
if (vers>3) { |
| 723 |
m_state->m_numStyles=int(input->readLong(2)); |
| 724 |
if (m_state->m_numStyles) |
| 725 |
f << "num[styles]=" << m_state->m_numStyles << ","; |
| 726 |
f << "ID2=" << std::hex << input->readULong(4) << std::dec << ","; |
| 727 |
} |
| 728 |
f << "margins=["; |
| 729 |
for (int i=0; i<4; ++i) f << float(input->readLong(4))/65536 << ","; |
| 730 |
f << "],"; |
| 731 |
f << "unkns=["; |
| 732 |
for (int i=0; i<2; ++i) f << float(input->readLong(4))/65536 << ","; |
| 733 |
f << "],"; |
| 734 |
for (int i=0; i<2; ++i) { |
| 735 |
val=int(input->readLong(2)); |
| 736 |
int const expected[]= {4,2}; |
| 737 |
if (val!=expected[i]) |
| 738 |
f << "f" << i+3 << "=" << val << ","; |
| 739 |
} |
| 740 |
if (vers>3) { |
| 741 |
for (int i=0; i<2; ++i) { |
| 742 |
val=int(input->readLong(1)); |
| 743 |
if (val==-1) |
| 744 |
f << "fl" << i << ","; |
| 745 |
else if (val) |
| 746 |
f << "fl" << i << "=" << val << ","; |
| 747 |
} |
| 748 |
} |
| 749 |
f << "ID3=" << std::hex << input->readULong(4) << std::dec << ","; |
| 750 |
val=int(input->readLong(2)); |
| 751 |
if (val) |
| 752 |
f << "f4=" << val << ","; |
| 753 |
ascii().addPos(pos); |
| 754 |
ascii().addNote(f.str().c_str()); |
| 755 |
|
| 756 |
pos=input->tell(); |
| 757 |
f.str(""); |
| 758 |
f << "Document-A:"; |
| 759 |
if (vers>3) { |
| 760 |
int cLen=int(input->readULong(1)); |
| 761 |
if (cLen>61) { |
| 762 |
f << "###"; |
| 763 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readDocument: unexpected file name len\n")); |
| 764 |
cLen=0; |
| 765 |
} |
| 766 |
std::string name; |
| 767 |
for (int i=0; i<cLen; ++i) { |
| 768 |
char c=char(input->readLong(1)); |
| 769 |
if (c==0) |
| 770 |
break; |
| 771 |
name+=c; |
| 772 |
} |
| 773 |
f << "file=" << name << ","; |
| 774 |
input->seek(pos+62, librevenge::RVNG_SEEK_SET); |
| 775 |
ascii().addDelimiter(input->tell(),'|'); |
| 776 |
if (vers>=6) { |
| 777 |
input->seek(pos+62+12, librevenge::RVNG_SEEK_SET); |
| 778 |
ascii().addDelimiter(input->tell(),'|'); |
| 779 |
input->seek(pos+62+12+25*6, librevenge::RVNG_SEEK_SET); |
| 780 |
ascii().addDelimiter(input->tell(),'|'); |
| 781 |
// then something like 0009206000088000000b00000001000000020003 |
| 782 |
} |
| 783 |
ascii().addPos(pos); |
| 784 |
ascii().addNote(f.str().c_str()); |
| 785 |
|
| 786 |
if (vers>=5) { |
| 787 |
input->seek(pos+(vers<=5 ? 134 : 244), librevenge::RVNG_SEEK_SET); |
| 788 |
pos=input->tell(); |
| 789 |
f.str(""); |
| 790 |
f << "Document-B:"; |
| 791 |
f << "IDS=["; |
| 792 |
for (int i=0; i<4; ++i) |
| 793 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 794 |
f << "],"; |
| 795 |
ascii().addDelimiter(input->tell(),'|'); |
| 796 |
input->seek(pos+24, librevenge::RVNG_SEEK_SET); |
| 797 |
ascii().addDelimiter(input->tell(),'|'); |
| 798 |
val=int(input->readULong(4)); |
| 799 |
if (val) { |
| 800 |
m_state->m_hasCustomColors=true; |
| 801 |
f << "color[IDS]=" << std::hex << val << std::dec << ","; |
| 802 |
} |
| 803 |
if (vers>=6) { |
| 804 |
val=int(input->readULong(4)); |
| 805 |
if (val) |
| 806 |
f << "color[IDS,unkn]=" << std::hex << val << std::dec << ","; |
| 807 |
} |
| 808 |
val=int(input->readULong(4)); |
| 809 |
if (val) |
| 810 |
f << "color[IDS,name]=" << std::hex << val << std::dec << ","; |
| 811 |
ascii().addDelimiter(input->tell(),'|'); |
| 812 |
ascii().addPos(pos); |
| 813 |
ascii().addNote(f.str().c_str()); |
| 814 |
} |
| 815 |
if (vers>=6) { |
| 816 |
input->seek(pos+188, librevenge::RVNG_SEEK_SET); |
| 817 |
pos=input->tell(); |
| 818 |
f.str(""); |
| 819 |
f << "Document-C:"; |
| 820 |
f << "IDS=["; |
| 821 |
for (int i=0; i<4; ++i) |
| 822 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 823 |
f << "],"; |
| 824 |
for (int i=0; i<2; ++i) { // f0=0|2bc |
| 825 |
val=int(input->readULong(2)); |
| 826 |
int const expected[]= { 0, 0x1f21}; |
| 827 |
if (val!=expected[i]) |
| 828 |
f << "f" << i << "=" << val << ","; |
| 829 |
} |
| 830 |
int dim[2]; |
| 831 |
for (auto &d : dim) d=int(input->readULong(2)); |
| 832 |
f << "dim=" << MWAWVec2i(dim[1],dim[0]) << ","; |
| 833 |
f << "margins?=["; |
| 834 |
for (int i=0; i<4; ++i) f << input->readLong(2) << ","; |
| 835 |
f << "],"; |
| 836 |
for (int i=0; i<4; ++i) { |
| 837 |
val=int(input->readULong(2)); |
| 838 |
if (val!=(i==2 ? 90 : 0)) |
| 839 |
f << "f" << i+2 << "=" << val << ","; |
| 840 |
} |
| 841 |
if (designStudio) |
| 842 |
ascii().addDelimiter(input->tell(),'|'); |
| 843 |
ascii().addPos(pos); |
| 844 |
ascii().addNote(f.str().c_str()); |
| 845 |
} |
| 846 |
if (vers>=6 && !designStudio) { |
| 847 |
for (int i=0; i<26; ++i) { |
| 848 |
pos=input->tell(); |
| 849 |
f.str(""); |
| 850 |
f << "Document-D" << i << ":"; |
| 851 |
// 000600008000000080000000800000008000000040000002ff8[01] |
| 852 |
input->seek(pos+26, librevenge::RVNG_SEEK_SET); |
| 853 |
ascii().addPos(pos); |
| 854 |
ascii().addNote(f.str().c_str()); |
| 855 |
} |
| 856 |
pos=input->tell(); |
| 857 |
f.str(""); |
| 858 |
f << "Document-E:"; |
| 859 |
m_state->m_numObjectGlossary=int(input->readLong(2)); |
| 860 |
if (m_state->m_numObjectGlossary) f << "num[object,glossary]=" << m_state->m_numObjectGlossary << ","; |
| 861 |
f << "ID0=" << std::hex << input->readULong(4) << std::dec << ","; |
| 862 |
for (int i=0; i<3; ++i) { |
| 863 |
val=int(input->readLong(2)); |
| 864 |
if (val) f << "f" << i << "=" << val << ","; |
| 865 |
} |
| 866 |
f << "ID1=" << std::hex << input->readULong(4) << std::dec << ","; |
| 867 |
for (int i=0; i<7; ++i) { // f4=0|256 |
| 868 |
val=int(input->readLong(2)); |
| 869 |
if (val) f << "f" << i+4 << "=" << val << ","; |
| 870 |
} |
| 871 |
for (int i=0; i<7; ++i) { |
| 872 |
val=int(input->readLong(2)); |
| 873 |
int const expected[]= {-1, 45, 0, 60, 0, 0, 300}; |
| 874 |
if (val!=expected[i]) f << "f" << i+11 << "=" << val << ","; |
| 875 |
} |
| 876 |
val=int(input->readULong(4)); |
| 877 |
if (val) { // checkme |
| 878 |
f << "ID2[font]=" << std::hex << val << std::dec << ","; |
| 879 |
m_state->m_hasFontsBlock2=true; |
| 880 |
} |
| 881 |
|
| 882 |
ascii().addDelimiter(input->tell(),'|'); |
| 883 |
// endPos-4: int16: ragzone percent, a flag:0,1 related to ragged method? |
| 884 |
ascii().addPos(pos); |
| 885 |
ascii().addNote(f.str().c_str()); |
| 886 |
} |
| 887 |
|
| 888 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 889 |
return true; |
| 890 |
} |
| 891 |
// vers <= 3 |
| 892 |
std::string name; |
| 893 |
for (int i=0; i<62; ++i) { // checkme, maybe a string of size 32, followed by... |
| 894 |
char c=char(input->readLong(1)); |
| 895 |
if (c==0) |
| 896 |
break; |
| 897 |
name+=c; |
| 898 |
} |
| 899 |
f << "file=" << name << ","; |
| 900 |
input->seek(pos+62, librevenge::RVNG_SEEK_SET); |
| 901 |
int dim[2]; |
| 902 |
for (auto &d : dim) d=int(input->readLong(2)); |
| 903 |
f << "dim=" << MWAWVec2i(dim[0],dim[1]) << ","; |
| 904 |
val=int(input->readLong(2)); |
| 905 |
if (val!=1) f << "unit=" << val << ","; // inch, centimeters, pica |
| 906 |
for (int i=0; i<4; ++i) { |
| 907 |
val=int(input->readLong(1)); |
| 908 |
if (val==-1) |
| 909 |
continue; |
| 910 |
if (i==0) |
| 911 |
f << "hide[ruler]"; |
| 912 |
else if (i==1) |
| 913 |
f << "hide[grid]"; |
| 914 |
else |
| 915 |
f << "fl" << i; |
| 916 |
if (val!=0) |
| 917 |
f << "=" << val << ","; |
| 918 |
else |
| 919 |
f << ","; |
| 920 |
} |
| 921 |
ascii().addPos(pos); |
| 922 |
ascii().addNote(f.str().c_str()); |
| 923 |
|
| 924 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 925 |
return true; |
| 926 |
} |
| 927 |
|
| 928 |
bool ReadySetGoParser::readIdsList() |
| 929 |
{ |
| 930 |
if (version()<3) { |
| 931 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readIdsList: unexpected version\n")); |
| 932 |
return false; |
| 933 |
} |
| 934 |
MWAWInputStreamPtr input = getInput(); |
| 935 |
if (!input) |
| 936 |
return false; |
| 937 |
long pos=input->tell(); |
| 938 |
if (!input->checkPosition(pos+4)) { |
| 939 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readIdsList: can not read the zone length\n")); |
| 940 |
return false; |
| 941 |
} |
| 942 |
libmwaw::DebugStream f; |
| 943 |
f << "Entries(IDLists):"; |
| 944 |
long len=long(input->readLong(4)); |
| 945 |
long endPos=pos+4+len; |
| 946 |
if (len<0 || endPos<pos+4 || !input->checkPosition(endPos)) { |
| 947 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readIdsList: can not read the zone length\n")); |
| 948 |
f << "###"; |
| 949 |
ascii().addPos(pos); |
| 950 |
ascii().addNote(f.str().c_str()); |
| 951 |
return false; |
| 952 |
} |
| 953 |
if (len==0) { |
| 954 |
ascii().addPos(pos); |
| 955 |
ascii().addNote("_"); |
| 956 |
return true; |
| 957 |
} |
| 958 |
if (len%4) { |
| 959 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readIdsList: can not determine the number of IDS\n")); |
| 960 |
f << "###"; |
| 961 |
ascii().addPos(pos); |
| 962 |
ascii().addNote(f.str().c_str()); |
| 963 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 964 |
return true; |
| 965 |
} |
| 966 |
f << "ids=["; |
| 967 |
for (int i=0; i<len/4; ++i) { |
| 968 |
auto val=input->readULong(4); |
| 969 |
if (val) |
| 970 |
f << std::hex << val << std::dec << ","; |
| 971 |
else |
| 972 |
f << "_,"; |
| 973 |
} |
| 974 |
f << "],"; |
| 975 |
ascii().addPos(pos); |
| 976 |
ascii().addNote(f.str().c_str()); |
| 977 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 978 |
|
| 979 |
return true; |
| 980 |
} |
| 981 |
|
| 982 |
//////////////////////////////////////////////////////////// |
| 983 |
// try to read the shapes zone |
| 984 |
//////////////////////////////////////////////////////////// |
| 985 |
bool ReadySetGoParser::readGlossary() |
| 986 |
{ |
| 987 |
MWAWInputStreamPtr input = getInput(); |
| 988 |
if (!input) |
| 989 |
return false; |
| 990 |
int const vers=version(); |
| 991 |
long pos=input->tell(); |
| 992 |
libmwaw::DebugStream f; |
| 993 |
f << "Entries(Glossary):"; |
| 994 |
if (vers<4) { |
| 995 |
f << "###"; |
| 996 |
ascii().addPos(pos); |
| 997 |
ascii().addNote(f.str().c_str()); |
| 998 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary: unexpected version\n")); |
| 999 |
return false; |
| 1000 |
} |
| 1001 |
long len=long(input->readLong(4)); |
| 1002 |
long endPos=pos+4+len; |
| 1003 |
if (m_state->m_numGlossary<0 || len<52*m_state->m_numGlossary || endPos<pos+4 || !input->checkPosition(endPos)) { |
| 1004 |
f << "###"; |
| 1005 |
ascii().addPos(pos); |
| 1006 |
ascii().addNote(f.str().c_str()); |
| 1007 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary: the zone's length seems bad\n")); |
| 1008 |
return false; |
| 1009 |
} |
| 1010 |
|
| 1011 |
if (len==0) { |
| 1012 |
ascii().addPos(pos); |
| 1013 |
ascii().addNote("_"); |
| 1014 |
return true; |
| 1015 |
} |
| 1016 |
ascii().addPos(pos); |
| 1017 |
ascii().addNote(f.str().c_str()); |
| 1018 |
std::vector<bool> hasTabs; |
| 1019 |
for (int i=0; i<m_state->m_numGlossary; ++i) { |
| 1020 |
pos=input->tell(); |
| 1021 |
f.str(""); |
| 1022 |
f << "Glossary-" << i << ":"; |
| 1023 |
int cLen=int(input->readULong(1)); |
| 1024 |
if (cLen>35) { |
| 1025 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary: the name's length seems bad\n")); |
| 1026 |
f << "###"; |
| 1027 |
cLen=0; |
| 1028 |
} |
| 1029 |
std::string name; |
| 1030 |
for (int c=0; c<cLen; ++c) { |
| 1031 |
char ch=char(input->readLong(1)); |
| 1032 |
if (!ch) |
| 1033 |
break; |
| 1034 |
name+=ch; |
| 1035 |
} |
| 1036 |
f << name << ","; |
| 1037 |
input->seek(pos+36, librevenge::RVNG_SEEK_SET); |
| 1038 |
f << "IDS=["; |
| 1039 |
for (int j=0; j<4; ++j) { |
| 1040 |
auto id=input->readULong(4); |
| 1041 |
if (j==2) |
| 1042 |
hasTabs.push_back(id!=0); |
| 1043 |
if (!id) |
| 1044 |
f << "_,"; |
| 1045 |
else |
| 1046 |
f << std::hex << id << std::dec << ","; |
| 1047 |
} |
| 1048 |
f << "],"; |
| 1049 |
input->seek(pos+52, librevenge::RVNG_SEEK_SET); |
| 1050 |
ascii().addPos(pos); |
| 1051 |
ascii().addNote(f.str().c_str()); |
| 1052 |
} |
| 1053 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1054 |
|
| 1055 |
for (size_t i=0; i<size_t(m_state->m_numGlossary); ++i) { |
| 1056 |
for (int step=0; step<(hasTabs[i] ? 3 : 2); ++step) { |
| 1057 |
pos=input->tell(); |
| 1058 |
len=long(input->readLong(4)); |
| 1059 |
f.str(""); |
| 1060 |
f << "Glossary-" << (step==0 ? "text" : step==1 ? "style" : "tabs") << "[" << i << "]:"; |
| 1061 |
endPos=pos+4+len; |
| 1062 |
if (endPos<pos+4 || !input->checkPosition(endPos)) { |
| 1063 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary: can not find a data block\n")); |
| 1064 |
f << "###"; |
| 1065 |
ascii().addPos(pos); |
| 1066 |
ascii().addNote(f.str().c_str()); |
| 1067 |
return false; |
| 1068 |
} |
| 1069 |
switch (step) { |
| 1070 |
case 0: { |
| 1071 |
int const begTextPos=vers<6 ? 18 : 58; |
| 1072 |
if (len<begTextPos+2) { |
| 1073 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary[text]: the zone length seems bad\n")); |
| 1074 |
f << "###"; |
| 1075 |
break; |
| 1076 |
} |
| 1077 |
int cLen=int(input->readULong(4)); |
| 1078 |
f << "N=" << cLen << ","; |
| 1079 |
if (cLen+begTextPos>len || (long)((unsigned long)cLen+(unsigned long)begTextPos)<begTextPos) { |
| 1080 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary: can not read the number of caracters\n")); |
| 1081 |
f << "###"; |
| 1082 |
cLen=0; |
| 1083 |
} |
| 1084 |
for (int j=0; j<2; ++j) { // maybe last change font/para |
| 1085 |
int val=int(input->readLong(4)); |
| 1086 |
if (val!=cLen) |
| 1087 |
f << "N" << j+1 << "=" << val << ","; |
| 1088 |
} |
| 1089 |
f << "IDS=["; |
| 1090 |
for (int j=0; j<2; ++j) { |
| 1091 |
auto val=input->readULong(4); |
| 1092 |
if (val) |
| 1093 |
f << std::hex << val << std::dec << ","; |
| 1094 |
else |
| 1095 |
f << "_,"; |
| 1096 |
} |
| 1097 |
f << "],"; |
| 1098 |
if (vers>=6) { |
| 1099 |
ascii().addDelimiter(input->tell(),'|'); |
| 1100 |
input->seek(38, librevenge::RVNG_SEEK_CUR); |
| 1101 |
ascii().addDelimiter(input->tell(),'|'); |
| 1102 |
} |
| 1103 |
for (int c=0; c<cLen; ++c) { |
| 1104 |
unsigned char ch=(unsigned char)input->readULong(1); |
| 1105 |
if (ch<0x1f && ch!=0x9) |
| 1106 |
f << "[#" << std::hex << int(ch) << std::dec << "]"; |
| 1107 |
else |
| 1108 |
f << ch; |
| 1109 |
} |
| 1110 |
break; |
| 1111 |
} |
| 1112 |
case 1: { |
| 1113 |
if (len<4) { |
| 1114 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary[style]: the zone length seems bad\n")); |
| 1115 |
f << "###"; |
| 1116 |
break; |
| 1117 |
} |
| 1118 |
int N=int(input->readULong(4)); |
| 1119 |
f << "N=" << N << ","; |
| 1120 |
if (N<0 || (len-4)/(vers==4 ? 30 : vers==5 ? 38 : 48)<N) { |
| 1121 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary[style]: can not detect the number of styles\n")); |
| 1122 |
f << "###"; |
| 1123 |
break; |
| 1124 |
} |
| 1125 |
for (int j=0; j<N; ++j) { |
| 1126 |
int cPos; |
| 1127 |
MWAWFont font; |
| 1128 |
MWAWParagraph para; |
| 1129 |
if (!m_styleManager->readStyle(font, para, &cPos)) |
| 1130 |
break; |
| 1131 |
} |
| 1132 |
break; |
| 1133 |
} |
| 1134 |
case 2: { |
| 1135 |
if (len<2) { |
| 1136 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary[tab]: the zone length seems bad\n")); |
| 1137 |
f << "###"; |
| 1138 |
break; |
| 1139 |
} |
| 1140 |
int N=int(input->readULong(2)); |
| 1141 |
f << "N=" << N << ","; |
| 1142 |
if (N<0 || (len-2)/148<N) { |
| 1143 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readGlossary[tab]: can not detect the number of tabulations\n")); |
| 1144 |
f << "###"; |
| 1145 |
break; |
| 1146 |
} |
| 1147 |
for (int j=0; j<N; ++j) { |
| 1148 |
int cPos; |
| 1149 |
std::vector<MWAWTabStop> tabs; |
| 1150 |
if (!m_styleManager->readTabulations(tabs, 148, &cPos)) |
| 1151 |
break; |
| 1152 |
} |
| 1153 |
break; |
| 1154 |
} |
| 1155 |
default: |
| 1156 |
break; |
| 1157 |
} |
| 1158 |
ascii().addPos(pos); |
| 1159 |
ascii().addNote(f.str().c_str()); |
| 1160 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
return true; |
| 1165 |
} |
| 1166 |
|
| 1167 |
bool ReadySetGoParser::readObjectGlossary() |
| 1168 |
{ |
| 1169 |
MWAWInputStreamPtr input = getInput(); |
| 1170 |
if (!input) |
| 1171 |
return false; |
| 1172 |
int const vers=version(); |
| 1173 |
long pos=input->tell(); |
| 1174 |
libmwaw::DebugStream f; |
| 1175 |
f << "Entries(ObjGloss):"; |
| 1176 |
if (vers<6) { |
| 1177 |
f << "###"; |
| 1178 |
ascii().addPos(pos); |
| 1179 |
ascii().addNote(f.str().c_str()); |
| 1180 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readObjectGlossary: unexpected version\n")); |
| 1181 |
return false; |
| 1182 |
} |
| 1183 |
long len=long(input->readLong(4)); |
| 1184 |
long endPos=pos+4+len; |
| 1185 |
if (m_state->m_numObjectGlossary<0 || len<40*m_state->m_numObjectGlossary || endPos<pos+4 || !input->checkPosition(endPos)) { |
| 1186 |
f << "###"; |
| 1187 |
ascii().addPos(pos); |
| 1188 |
ascii().addNote(f.str().c_str()); |
| 1189 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readObjectGlossary: the zone's length seems bad\n")); |
| 1190 |
return false; |
| 1191 |
} |
| 1192 |
|
| 1193 |
if (len==0) { |
| 1194 |
ascii().addPos(pos); |
| 1195 |
ascii().addNote("_"); |
| 1196 |
return true; |
| 1197 |
} |
| 1198 |
ascii().addPos(pos); |
| 1199 |
ascii().addNote(f.str().c_str()); |
| 1200 |
for (int i=0; i<m_state->m_numObjectGlossary; ++i) { |
| 1201 |
pos=input->tell(); |
| 1202 |
f.str(""); |
| 1203 |
f << "ObjGloss-" << i << ":"; |
| 1204 |
int cLen=int(input->readULong(1)); |
| 1205 |
if (cLen>35) { |
| 1206 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readObjectGlossary: the name's length seems bad\n")); |
| 1207 |
f << "###"; |
| 1208 |
cLen=0; |
| 1209 |
} |
| 1210 |
std::string name; |
| 1211 |
for (int c=0; c<cLen; ++c) { |
| 1212 |
char ch=char(input->readLong(1)); |
| 1213 |
if (!ch) |
| 1214 |
break; |
| 1215 |
name+=ch; |
| 1216 |
} |
| 1217 |
f << name << ","; |
| 1218 |
input->seek(pos+36, librevenge::RVNG_SEEK_SET); |
| 1219 |
f << "IDS=["; |
| 1220 |
for (int j=0; j<1; ++j) { |
| 1221 |
auto id=input->readULong(4); |
| 1222 |
if (!id) |
| 1223 |
f << "_,"; |
| 1224 |
else |
| 1225 |
f << std::hex << id << std::dec << ","; |
| 1226 |
} |
| 1227 |
f << "],"; |
| 1228 |
input->seek(pos+40, librevenge::RVNG_SEEK_SET); |
| 1229 |
ascii().addPos(pos); |
| 1230 |
ascii().addNote(f.str().c_str()); |
| 1231 |
} |
| 1232 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1233 |
for (int i=0; i<m_state->m_numObjectGlossary; ++i) { |
| 1234 |
if (!m_graphParser->readShapesInObject()) |
| 1235 |
return false; |
| 1236 |
} |
| 1237 |
|
| 1238 |
return true; |
| 1239 |
} |
| 1240 |
|
| 1241 |
bool ReadySetGoParser::readFontsUnknown() |
| 1242 |
{ |
| 1243 |
MWAWInputStreamPtr input = getInput(); |
| 1244 |
if (!input) |
| 1245 |
return false; |
| 1246 |
int const vers=version(); |
| 1247 |
long pos=input->tell(); |
| 1248 |
libmwaw::DebugStream f; |
| 1249 |
f << "Entries(FontUnkn):"; |
| 1250 |
if (vers<6) { |
| 1251 |
f << "###"; |
| 1252 |
ascii().addPos(pos); |
| 1253 |
ascii().addNote(f.str().c_str()); |
| 1254 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readFontsUnknown: unexpected version\n")); |
| 1255 |
return false; |
| 1256 |
} |
| 1257 |
long len=long(input->readLong(4)); |
| 1258 |
long endPos=pos+4+len; |
| 1259 |
if ((len && (len%8)!=2) || endPos<pos+4 || !input->checkPosition(endPos)) { |
| 1260 |
f << "###"; |
| 1261 |
ascii().addPos(pos); |
| 1262 |
ascii().addNote(f.str().c_str()); |
| 1263 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readFontsUnknown: the zone's length seems bad\n")); |
| 1264 |
return false; |
| 1265 |
} |
| 1266 |
|
| 1267 |
if (len==0) { |
| 1268 |
ascii().addPos(pos); |
| 1269 |
ascii().addNote("_"); |
| 1270 |
return true; |
| 1271 |
} |
| 1272 |
|
| 1273 |
int N=int(input->readULong(2)); |
| 1274 |
f << "N=" << N << ","; |
| 1275 |
if (8*N+2 != len) { |
| 1276 |
f << "###"; |
| 1277 |
ascii().addPos(pos); |
| 1278 |
ascii().addNote(f.str().c_str()); |
| 1279 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readFontsUnknown: can not read the number of elements\n")); |
| 1280 |
return false; |
| 1281 |
} |
| 1282 |
f << "fonts=["; |
| 1283 |
for (int i=0; i<N; ++i) { |
| 1284 |
f << "["; |
| 1285 |
f << "fId=" << input->readULong(2) << ","; |
| 1286 |
int val=int(input->readULong(1)); |
| 1287 |
if (val) f << "fFlags=" << std::hex << val << std::dec << ","; |
| 1288 |
val=int(input->readULong(1)); |
| 1289 |
if (val) |
| 1290 |
f << "fl=" << val << ","; |
| 1291 |
val=int(input->readULong(4)); |
| 1292 |
if (val) |
| 1293 |
f << "ID=" << std::hex << val << std::dec << ","; |
| 1294 |
f << "],"; |
| 1295 |
} |
| 1296 |
f << "],"; |
| 1297 |
ascii().addPos(pos); |
| 1298 |
ascii().addNote(f.str().c_str()); |
| 1299 |
for (int i=0; i<N; ++i) { |
| 1300 |
pos=input->tell(); |
| 1301 |
f.str(""); |
| 1302 |
f << "FontUnkn-" << i << ":"; |
| 1303 |
len=long(input->readLong(4)); |
| 1304 |
endPos=pos+4+len; |
| 1305 |
if (endPos<pos+4 || len<2 || !input->checkPosition(endPos)) { |
| 1306 |
f << "###"; |
| 1307 |
ascii().addPos(pos); |
| 1308 |
ascii().addNote(f.str().c_str()); |
| 1309 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readFontsUnknown: can not find a sub zone\n")); |
| 1310 |
return false; |
| 1311 |
} |
| 1312 |
int N1=int(input->readULong(2)); |
| 1313 |
f << "N=" << N1 << ","; |
| 1314 |
if (2+4*N1>len) { |
| 1315 |
f << "###"; |
| 1316 |
ascii().addPos(pos); |
| 1317 |
ascii().addNote(f.str().c_str()); |
| 1318 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readFontsUnknown: can not find the number of data\n")); |
| 1319 |
return false; |
| 1320 |
} |
| 1321 |
ascii().addDelimiter(input->tell(),'|'); |
| 1322 |
ascii().addPos(pos); |
| 1323 |
ascii().addNote(f.str().c_str()); |
| 1324 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1325 |
} |
| 1326 |
return true; |
| 1327 |
} |
| 1328 |
|
| 1329 |
bool ReadySetGoParser::readZone11() |
| 1330 |
{ |
| 1331 |
MWAWInputStreamPtr input = getInput(); |
| 1332 |
if (!input) |
| 1333 |
return false; |
| 1334 |
int const vers=version(); |
| 1335 |
long pos=input->tell(); |
| 1336 |
libmwaw::DebugStream f; |
| 1337 |
f << "Entries(Zone11A):"; |
| 1338 |
if (vers<6) { |
| 1339 |
f << "###"; |
| 1340 |
ascii().addPos(pos); |
| 1341 |
ascii().addNote(f.str().c_str()); |
| 1342 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readZone11: unexpected version\n")); |
| 1343 |
return false; |
| 1344 |
} |
| 1345 |
long len=long(input->readLong(4)); |
| 1346 |
long endPos=pos+4+len; |
| 1347 |
if ((len && len<0x138) || endPos<pos+4 || !input->checkPosition(endPos)) { |
| 1348 |
f << "###"; |
| 1349 |
ascii().addPos(pos); |
| 1350 |
ascii().addNote(f.str().c_str()); |
| 1351 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readZone11: the zone's length seems bad\n")); |
| 1352 |
return false; |
| 1353 |
} |
| 1354 |
|
| 1355 |
if (len==0) { |
| 1356 |
ascii().addPos(pos); |
| 1357 |
ascii().addNote("_"); |
| 1358 |
return true; |
| 1359 |
} |
| 1360 |
|
| 1361 |
input->seek(pos+300, librevenge::RVNG_SEEK_SET); |
| 1362 |
ascii().addDelimiter(input->tell(), '|'); |
| 1363 |
int N=int(input->readULong(2)); |
| 1364 |
f << "N=" << N << ","; |
| 1365 |
if (len<0x138+28*N) { |
| 1366 |
f << "###"; |
| 1367 |
ascii().addPos(pos); |
| 1368 |
ascii().addNote(f.str().c_str()); |
| 1369 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readZone11: can not read the number of data\n")); |
| 1370 |
return false; |
| 1371 |
} |
| 1372 |
ascii().addPos(pos); |
| 1373 |
ascii().addNote(f.str().c_str()); |
| 1374 |
|
| 1375 |
input->seek(pos+4+0x138, librevenge::RVNG_SEEK_SET); |
| 1376 |
for (int i=0; i<N; ++i) { |
| 1377 |
pos=input->tell(); |
| 1378 |
f.str(""); |
| 1379 |
f << "Zone11A-" << i << ":"; |
| 1380 |
input->seek(pos+28, librevenge::RVNG_SEEK_SET); |
| 1381 |
ascii().addPos(pos); |
| 1382 |
ascii().addNote(f.str().c_str()); |
| 1383 |
} |
| 1384 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1385 |
return true; |
| 1386 |
} |
| 1387 |
|
| 1388 |
//////////////////////////////////////////////////////////// |
| 1389 |
// try to read the print info zone |
| 1390 |
//////////////////////////////////////////////////////////// |
| 1391 |
bool ReadySetGoParser::readPrintInfo() |
| 1392 |
{ |
| 1393 |
MWAWInputStreamPtr input = getInput(); |
| 1394 |
int const vers=version(); |
| 1395 |
long pos=input->tell(); |
| 1396 |
long endPos=pos+120+(vers<3 ? 2 : 4); |
| 1397 |
if (!input->checkPosition(endPos) || input->readULong((vers<3 ? 2 : 4))!=0x78) { |
| 1398 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readPrintInfo: file seems too short\n")); |
| 1399 |
return false; |
| 1400 |
} |
| 1401 |
libmwaw::DebugStream f; |
| 1402 |
f << "Entries(PrintInfo):"; |
| 1403 |
libmwaw::PrinterInfo info; |
| 1404 |
if (!info.read(input)) { |
| 1405 |
MWAW_DEBUG_MSG(("ReadySetGoParser::readPrintInfo: can not read print info\n")); |
| 1406 |
return false; |
| 1407 |
} |
| 1408 |
f << info; |
| 1409 |
MWAWVec2i paperSize = info.paper().size(); |
| 1410 |
MWAWVec2i pageSize = info.page().size(); |
| 1411 |
if (pageSize.x() <= 0 || pageSize.y() <= 0 || |
| 1412 |
paperSize.x() <= 0 || paperSize.y() <= 0) { |
| 1413 |
ascii().addPos(pos); |
| 1414 |
ascii().addNote(f.str().c_str()); |
| 1415 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1416 |
return true; |
| 1417 |
} |
| 1418 |
|
| 1419 |
// define margin from print info |
| 1420 |
MWAWVec2i lTopMargin= -1 * info.paper().pos(0); |
| 1421 |
MWAWVec2i rBotMargin=info.paper().size() - info.page().size(); |
| 1422 |
|
| 1423 |
// move margin left | top |
| 1424 |
int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0; |
| 1425 |
int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0; |
| 1426 |
lTopMargin -= MWAWVec2i(decalX, decalY); |
| 1427 |
rBotMargin += MWAWVec2i(decalX, decalY); |
| 1428 |
|
| 1429 |
// decrease right | bottom |
| 1430 |
int rightMarg = rBotMargin.x() -50; |
| 1431 |
if (rightMarg < 0) rightMarg=0; |
| 1432 |
int botMarg = rBotMargin.y() -50; |
| 1433 |
if (botMarg < 0) botMarg=0; |
| 1434 |
|
| 1435 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 1436 |
getPageSpan().setMarginBottom(botMarg/72.0); |
| 1437 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 1438 |
getPageSpan().setMarginRight(rightMarg/72.0); |
| 1439 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 1440 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 1441 |
|
| 1442 |
ascii().addPos(pos); |
| 1443 |
ascii().addNote(f.str().c_str()); |
| 1444 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1445 |
return true; |
| 1446 |
} |
| 1447 |
|
| 1448 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |