| 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 <cmath> |
| 35 |
#include <iomanip> |
| 36 |
#include <iostream> |
| 37 |
#include <limits> |
| 38 |
#include <sstream> |
| 39 |
|
| 40 |
#include <librevenge/librevenge.h> |
| 41 |
|
| 42 |
#include "MWAWFontConverter.hxx" |
| 43 |
#include "MWAWGraphicListener.hxx" |
| 44 |
#include "MWAWGraphicShape.hxx" |
| 45 |
#include "MWAWGraphicStyle.hxx" |
| 46 |
#include "MWAWHeader.hxx" |
| 47 |
#include "MWAWParagraph.hxx" |
| 48 |
#include "MWAWPictBitmap.hxx" |
| 49 |
#include "MWAWPictData.hxx" |
| 50 |
#include "MWAWPrinter.hxx" |
| 51 |
#include "MWAWPosition.hxx" |
| 52 |
#include "MWAWSubDocument.hxx" |
| 53 |
|
| 54 |
#include "ClarisDrawStyleManager.hxx" |
| 55 |
#include "ClarisDrawGraph.hxx" |
| 56 |
#include "ClarisDrawText.hxx" |
| 57 |
#include "ClarisWksStruct.hxx" |
| 58 |
|
| 59 |
#include "ClarisDrawParser.hxx" |
| 60 |
|
| 61 |
/** Internal: the structures of a ClarisDrawParser */ |
| 62 |
namespace ClarisDrawParserInternal |
| 63 |
{ |
| 64 |
// generic class used to defined a layer |
| 65 |
struct Layer { |
| 66 |
//! constructor |
| 67 |
Layer() |
| 68 |
: m_groupId(0) |
| 69 |
, m_isHidden(false) |
| 70 |
, m_name("") |
| 71 |
{ |
| 72 |
} |
| 73 |
//! the first group id |
| 74 |
int m_groupId; |
| 75 |
//! true if the layer is hidden |
| 76 |
bool m_isHidden; |
| 77 |
//! the layer name |
| 78 |
librevenge::RVNGString m_name; |
| 79 |
}; |
| 80 |
|
| 81 |
//////////////////////////////////////////// |
| 82 |
//! Internal: the state of a ClarisDrawParser |
| 83 |
struct State { |
| 84 |
//! constructor |
| 85 |
State() |
| 86 |
: m_version(0) |
| 87 |
, m_isLibrary(false) |
| 88 |
, m_numDSET(0) |
| 89 |
, m_EOF(-1) |
| 90 |
, m_actualLayer(1) |
| 91 |
, m_numLayers(1) |
| 92 |
, m_createMasterPage(false) |
| 93 |
, m_displayAsSlide(false) |
| 94 |
, m_layerList() |
| 95 |
, m_pageSpanSet(false) |
| 96 |
, m_headerId(0) |
| 97 |
, m_footerId(0) |
| 98 |
, m_pages(1,1) |
| 99 |
, m_zonesMap() |
| 100 |
, m_zoneIdToFileTypeMap() |
| 101 |
{ |
| 102 |
} |
| 103 |
//! the file version |
| 104 |
int m_version; |
| 105 |
//! flag to know if the file is a library or not |
| 106 |
bool m_isLibrary; |
| 107 |
//! the number of DSET+FNTM |
| 108 |
int m_numDSET; |
| 109 |
//! the last data zone size |
| 110 |
long m_EOF; |
| 111 |
//! the actual layer |
| 112 |
int m_actualLayer; |
| 113 |
//! the number of layer |
| 114 |
int m_numLayers; |
| 115 |
//! flag to know if we need or not to create a master |
| 116 |
bool m_createMasterPage; |
| 117 |
//! flag to know if we need to display data as slide |
| 118 |
bool m_displayAsSlide; |
| 119 |
//! the layer list |
| 120 |
std::vector<Layer> m_layerList; |
| 121 |
//! flag to know if the page has been set |
| 122 |
bool m_pageSpanSet; |
| 123 |
//! header id |
| 124 |
int m_headerId; |
| 125 |
//! footer id |
| 126 |
int m_footerId; |
| 127 |
//! the number of pages |
| 128 |
MWAWVec2i m_pages; |
| 129 |
/** the map of zone*/ |
| 130 |
std::map<int, std::shared_ptr<ClarisWksStruct::DSET> > m_zonesMap; |
| 131 |
/** map zone id to file type */ |
| 132 |
std::map<int, int> m_zoneIdToFileTypeMap; |
| 133 |
}; |
| 134 |
} |
| 135 |
|
| 136 |
//////////////////////////////////////////////////////////// |
| 137 |
// constructor/destructor, ... |
| 138 |
//////////////////////////////////////////////////////////// |
| 139 |
ClarisDrawParser::ClarisDrawParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 140 |
: MWAWGraphicParser(input, rsrcParser, header) |
| 141 |
, m_state() |
| 142 |
, m_styleManager() |
| 143 |
, m_graphParser() |
| 144 |
, m_textParser() |
| 145 |
{ |
| 146 |
init(); |
| 147 |
} |
| 148 |
|
| 149 |
ClarisDrawParser::~ClarisDrawParser() |
| 150 |
{ |
| 151 |
} |
| 152 |
|
| 153 |
void ClarisDrawParser::init() |
| 154 |
{ |
| 155 |
resetGraphicListener(); |
| 156 |
setAsciiName("main-1"); |
| 157 |
m_state.reset(new ClarisDrawParserInternal::State); |
| 158 |
m_styleManager.reset(new ClarisDrawStyleManager(*this)); |
| 159 |
|
| 160 |
m_graphParser.reset(new ClarisDrawGraph(*this)); |
| 161 |
m_textParser.reset(new ClarisDrawText(*this)); |
| 162 |
|
| 163 |
getPageSpan().setMargins(0.1); |
| 164 |
} |
| 165 |
|
| 166 |
int ClarisDrawParser::getFileType(int zoneId) const |
| 167 |
{ |
| 168 |
if (m_state->m_zoneIdToFileTypeMap.find(zoneId) == m_state->m_zoneIdToFileTypeMap.end()) { |
| 169 |
MWAW_DEBUG_MSG(("ClarisDrawParser::getFileType: zone %d does not exists!!!!\n", zoneId)); |
| 170 |
return -1; |
| 171 |
} |
| 172 |
return m_state->m_zoneIdToFileTypeMap.find(zoneId)->second; |
| 173 |
} |
| 174 |
|
| 175 |
bool ClarisDrawParser::sendTextZone(int number, int subZone) |
| 176 |
{ |
| 177 |
return m_textParser->sendZone(number, subZone); |
| 178 |
} |
| 179 |
|
| 180 |
MWAWVec2f ClarisDrawParser::getPageLeftTop() |
| 181 |
{ |
| 182 |
return MWAWVec2f(float(getParserState()->m_pageSpan.getMarginLeft()), |
| 183 |
float(getParserState()->m_pageSpan.getMarginTop())); |
| 184 |
} |
| 185 |
|
| 186 |
//////////////////////////////////////////////////////////// |
| 187 |
// the parser |
| 188 |
//////////////////////////////////////////////////////////// |
| 189 |
void ClarisDrawParser::parse(librevenge::RVNGDrawingInterface *docInterface) |
| 190 |
{ |
| 191 |
if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
| 192 |
bool ok = false; |
| 193 |
try { |
| 194 |
// create the asciiFile |
| 195 |
ascii().setStream(getInput()); |
| 196 |
ascii().open(asciiName()); |
| 197 |
checkHeader(nullptr); |
| 198 |
ok = createZones(); |
| 199 |
if (ok) { |
| 200 |
createDocument(docInterface); |
| 201 |
MWAWVec2f leftTop=72.0f*getPageLeftTop(); |
| 202 |
MWAWPosition pos(leftTop,MWAWVec2f(0,0),librevenge::RVNG_POINT); |
| 203 |
pos.setRelativePosition(MWAWPosition::Page); |
| 204 |
MWAWGraphicListenerPtr listener=getGraphicListener(); |
| 205 |
|
| 206 |
if (m_state->m_isLibrary) { |
| 207 |
for (size_t i=0; i<m_state->m_layerList.size(); ++i) { |
| 208 |
if (i>0) |
| 209 |
listener->insertBreak(MWAWListener::PageBreak); |
| 210 |
m_graphParser->sendMainGroupChild(int(i), pos); |
| 211 |
} |
| 212 |
} |
| 213 |
else if (m_state->m_displayAsSlide) { |
| 214 |
bool first=true; |
| 215 |
for (size_t i=1; i< m_state->m_layerList.size(); ++i) { |
| 216 |
if (m_graphParser->isEmptyGroup(m_state->m_layerList[i].m_groupId)) |
| 217 |
continue; |
| 218 |
if (!first) |
| 219 |
listener->insertBreak(MWAWListener::PageBreak); |
| 220 |
first=false; |
| 221 |
m_graphParser->sendGroup(m_state->m_layerList[i].m_groupId, pos); |
| 222 |
} |
| 223 |
} |
| 224 |
else { |
| 225 |
for (size_t i=1; i< m_state->m_layerList.size(); ++i) { |
| 226 |
if (m_graphParser->isEmptyGroup(m_state->m_layerList[i].m_groupId)) |
| 227 |
continue; |
| 228 |
bool openLayer=false; |
| 229 |
if (!m_state->m_layerList[i].m_name.empty()) |
| 230 |
openLayer=listener->openLayer(m_state->m_layerList[i].m_name); |
| 231 |
m_graphParser->sendGroup(m_state->m_layerList[i].m_groupId, pos); |
| 232 |
if (openLayer) |
| 233 |
listener->closeLayer(); |
| 234 |
} |
| 235 |
} |
| 236 |
#ifdef DEBUG |
| 237 |
m_graphParser->flushExtra(); |
| 238 |
#endif |
| 239 |
} |
| 240 |
ascii().reset(); |
| 241 |
} |
| 242 |
catch (...) { |
| 243 |
MWAW_DEBUG_MSG(("ClarisDrawParser::parse: exception catched when parsing\n")); |
| 244 |
ok = false; |
| 245 |
} |
| 246 |
|
| 247 |
resetGraphicListener(); |
| 248 |
if (!ok) throw(libmwaw::ParseException()); |
| 249 |
} |
| 250 |
|
| 251 |
//////////////////////////////////////////////////////////// |
| 252 |
// create the document |
| 253 |
//////////////////////////////////////////////////////////// |
| 254 |
void ClarisDrawParser::createDocument(librevenge::RVNGDrawingInterface *documentInterface) |
| 255 |
{ |
| 256 |
if (!documentInterface) return; |
| 257 |
if (getGraphicListener()) { |
| 258 |
MWAW_DEBUG_MSG(("ClarisDrawParser::createDocument: listener already exist\n")); |
| 259 |
return; |
| 260 |
} |
| 261 |
|
| 262 |
m_graphParser->updateGroup(m_state->m_isLibrary); |
| 263 |
|
| 264 |
|
| 265 |
// create the page list |
| 266 |
int numPages=1; |
| 267 |
MWAWPageSpan ps(getPageSpan()); |
| 268 |
ps.setPageSpan(1); |
| 269 |
std::vector<librevenge::RVNGString> listNames; |
| 270 |
if (m_state->m_isLibrary) { |
| 271 |
numPages=static_cast<int>(m_state->m_layerList.size()); |
| 272 |
if (numPages<1) numPages=1; |
| 273 |
} |
| 274 |
else { |
| 275 |
m_state->m_createMasterPage=!m_state->m_layerList.empty() && |
| 276 |
!m_graphParser->isEmptyGroup(m_state->m_layerList[0].m_groupId); |
| 277 |
if (m_state->m_createMasterPage) |
| 278 |
ps.setMasterPageName(librevenge::RVNGString("Master")); |
| 279 |
for (size_t i=1; i<m_state->m_layerList.size(); ++i) { |
| 280 |
if (!m_graphParser->isEmptyGroup(m_state->m_layerList[i].m_groupId)) |
| 281 |
listNames.push_back(m_state->m_layerList[i].m_name); |
| 282 |
} |
| 283 |
if (m_state->m_displayAsSlide && !listNames.empty()) |
| 284 |
numPages=static_cast<int>(listNames.size()); |
| 285 |
} |
| 286 |
std::vector<MWAWPageSpan> pageList; |
| 287 |
for (int i=0; i<numPages; ++i) { |
| 288 |
MWAWPageSpan page(ps); |
| 289 |
if (m_state->m_isLibrary && i<static_cast<int>(m_state->m_layerList.size())) |
| 290 |
page.setPageName(m_state->m_layerList[size_t(i)].m_name); |
| 291 |
else if (m_state->m_displayAsSlide && i<static_cast<int>(listNames.size())) |
| 292 |
page.setPageName(listNames[size_t(i)]); |
| 293 |
pageList.push_back(page); |
| 294 |
} |
| 295 |
MWAWGraphicListenerPtr listen(new MWAWGraphicListener(*getParserState(), pageList, documentInterface)); |
| 296 |
setGraphicListener(listen); |
| 297 |
listen->startDocument(); |
| 298 |
|
| 299 |
|
| 300 |
if (!m_state->m_createMasterPage) |
| 301 |
return; |
| 302 |
|
| 303 |
// we need to send the master page |
| 304 |
if (!listen->openMasterPage(ps)) { |
| 305 |
MWAW_DEBUG_MSG(("ClarisDrawParser::createDocument: can not create the master page\n")); |
| 306 |
m_state->m_createMasterPage=false; |
| 307 |
return; |
| 308 |
} |
| 309 |
MWAWVec2f leftTop=72.0f*getPageLeftTop(); |
| 310 |
MWAWPosition pos(leftTop,MWAWVec2f(0,0),librevenge::RVNG_POINT); |
| 311 |
pos.setRelativePosition(MWAWPosition::Page); |
| 312 |
m_graphParser->sendGroup(m_state->m_layerList[0].m_groupId, pos); |
| 313 |
listen->closeMasterPage(); |
| 314 |
} |
| 315 |
|
| 316 |
//////////////////////////////////////////////////////////// |
| 317 |
// |
| 318 |
// Intermediate level |
| 319 |
// |
| 320 |
//////////////////////////////////////////////////////////// |
| 321 |
bool ClarisDrawParser::createZones() |
| 322 |
{ |
| 323 |
MWAWInputStreamPtr input = getInput(); |
| 324 |
if ((m_state->m_isLibrary && !readLibraryHeader()) || |
| 325 |
(!m_state->m_isLibrary && !readDocHeader())) |
| 326 |
return false; |
| 327 |
|
| 328 |
if (m_state->m_EOF>0) |
| 329 |
input->pushLimit(m_state->m_EOF); |
| 330 |
while (readZone()); |
| 331 |
if (!input->isEnd()) { |
| 332 |
ascii().addPos(input->tell()); |
| 333 |
ascii().addNote("Entries(BAD)"); |
| 334 |
} |
| 335 |
while (!input->isEnd()) { |
| 336 |
long pos=input->tell(); |
| 337 |
if (input->readULong(4)!=0x44534554) { |
| 338 |
input->seek(pos+1, librevenge::RVNG_SEEK_SET); |
| 339 |
continue; |
| 340 |
} |
| 341 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 342 |
long actPos=input->tell(); |
| 343 |
while (readZone()) |
| 344 |
actPos=input->tell(); |
| 345 |
if (actPos==pos) { |
| 346 |
input->seek(actPos+4, librevenge::RVNG_SEEK_SET); |
| 347 |
continue; |
| 348 |
} |
| 349 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 350 |
if (input->isEnd()) break; |
| 351 |
MWAW_DEBUG_MSG(("ClarisDrawParser::createZones: oops loose tracks of zones\n")); |
| 352 |
ascii().addPos(input->tell()); |
| 353 |
ascii().addNote("Entries(BAD):###"); |
| 354 |
} |
| 355 |
if (m_state->m_EOF>0) |
| 356 |
input->popLimit(); |
| 357 |
return true; |
| 358 |
} |
| 359 |
|
| 360 |
bool ClarisDrawParser::readZone() |
| 361 |
{ |
| 362 |
MWAWInputStreamPtr input = getInput(); |
| 363 |
long pos=input->tell(); |
| 364 |
if (!input->checkPosition(pos+4)) |
| 365 |
return false; |
| 366 |
auto zoneSz=long(input->readULong(4)); |
| 367 |
if (zoneSz==0x44534554) { |
| 368 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 369 |
return readDSET().get()!=nullptr; |
| 370 |
} |
| 371 |
else if (zoneSz==0x464e544d) { |
| 372 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 373 |
return m_styleManager->readFontNames(); |
| 374 |
} |
| 375 |
else if ((zoneSz>>16)>16) { |
| 376 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 377 |
return false; |
| 378 |
} |
| 379 |
else if ((zoneSz>>16)!=0) { |
| 380 |
ascii().addPos(pos); |
| 381 |
ascii().addNote("Entries(Short)"); |
| 382 |
input->seek(pos+2, librevenge::RVNG_SEEK_SET); |
| 383 |
return true; |
| 384 |
} |
| 385 |
long endPos=input->tell()+zoneSz; |
| 386 |
if (zoneSz<0 || ((zoneSz&1) && (zoneSz==0x4453 || zoneSz==0x464e)) || !input->checkPosition(endPos)) { |
| 387 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 388 |
return false; |
| 389 |
} |
| 390 |
libmwaw::DebugStream f; |
| 391 |
if (zoneSz==0) |
| 392 |
f << "_"; |
| 393 |
else |
| 394 |
f << "Entries(Unknown)"; |
| 395 |
ascii().addPos(pos); |
| 396 |
ascii().addNote(f.str().c_str()); |
| 397 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 398 |
return true; |
| 399 |
} |
| 400 |
|
| 401 |
bool ClarisDrawParser::readDocHeader() |
| 402 |
{ |
| 403 |
MWAWInputStreamPtr input = getInput(); |
| 404 |
if (!input->checkPosition(0x80A)) return false; |
| 405 |
|
| 406 |
input->seek(8, librevenge::RVNG_SEEK_SET); |
| 407 |
libmwaw::DebugStream f; |
| 408 |
f << "Entries(DocHeader):"; |
| 409 |
auto val = static_cast<int>(input->readLong(2)); // always find 1 |
| 410 |
if (val != 1) |
| 411 |
f << "#unkn=" << std::hex << val << std::dec << ","; |
| 412 |
for (int i = 0; i < 4; i++) { |
| 413 |
val = static_cast<int>(input->readULong(2)); |
| 414 |
if (val) |
| 415 |
f << std::hex << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 416 |
} |
| 417 |
int dim[2]; |
| 418 |
for (int &i : dim) i= static_cast<int>(input->readLong(2)); |
| 419 |
f << "dim?=" << dim[1] << "x" << dim[0] << ","; |
| 420 |
int margin[6]; |
| 421 |
f << "margin?=["; |
| 422 |
for (int &i : margin) { |
| 423 |
i = static_cast<int>(input->readLong(2)); |
| 424 |
if (i) |
| 425 |
f << i << ","; |
| 426 |
else |
| 427 |
f << "_,"; |
| 428 |
} |
| 429 |
f << "],"; |
| 430 |
// seems a good indication that slide mode is choosen |
| 431 |
if (dim[0] > 0 && dim[1] > 0 && |
| 432 |
margin[0] >= 0 && margin[1] >= 0 && margin[2] >= 0 && margin[3] >= 0 && |
| 433 |
dim[0] > margin[0]+margin[2] && dim[1] > margin[1]+margin[3]) { |
| 434 |
|
| 435 |
MWAWVec2i paperSize(dim[1],dim[0]); |
| 436 |
MWAWVec2i lTopMargin(margin[1], margin[0]); |
| 437 |
MWAWVec2i rBotMargin(margin[3], margin[2]); |
| 438 |
|
| 439 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 440 |
getPageSpan().setMarginBottom(rBotMargin.y()/72.0); |
| 441 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 442 |
getPageSpan().setMarginRight(rBotMargin.x()/72.0); |
| 443 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 444 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 445 |
m_state->m_pageSpanSet = true; |
| 446 |
} |
| 447 |
int dim2[2]; |
| 448 |
for (int &i : dim2) i = static_cast<int>(input->readLong(2)); |
| 449 |
f << "dim2?=" << dim2[1] << "x" << dim2[0] << ","; |
| 450 |
int fl[4]; |
| 451 |
f << "fl?=["; |
| 452 |
for (int &i : fl) { |
| 453 |
i = static_cast<int>(input->readULong(1)); |
| 454 |
if (i) |
| 455 |
f << i << ","; |
| 456 |
else |
| 457 |
f << "_,"; |
| 458 |
} |
| 459 |
f << "],"; |
| 460 |
for (int i = 0; i < 9; i++) { |
| 461 |
val = static_cast<int>(input->readLong(2)); |
| 462 |
if (val) |
| 463 |
f << "g" << i << "=" << val << ","; |
| 464 |
} |
| 465 |
|
| 466 |
ascii().addDelimiter(input->tell(), '|'); |
| 467 |
ascii().addPos(8); |
| 468 |
ascii().addNote(f.str().c_str()); |
| 469 |
|
| 470 |
input->seek(8+132, librevenge::RVNG_SEEK_SET); |
| 471 |
|
| 472 |
/* zone 1 actual font, actul pos, .. */ |
| 473 |
if (!m_textParser->readParagraph()) |
| 474 |
return false; |
| 475 |
long pos = input->tell(); |
| 476 |
f.str(""); |
| 477 |
f << "DocHeader:zone?=" << input->readULong(2) << ","; |
| 478 |
ascii().addPos(pos); |
| 479 |
ascii().addNote(f.str().c_str()); |
| 480 |
MWAWFont font; |
| 481 |
int posChar; |
| 482 |
if (!m_textParser->readFont(-1, posChar, font)) |
| 483 |
return false; |
| 484 |
|
| 485 |
/* zone 2, type, unknown */ |
| 486 |
pos = input->tell(); |
| 487 |
f.str(""); |
| 488 |
f << "DocHeader-1:"; |
| 489 |
for (int i = 0; i < 6; i++) { |
| 490 |
val = static_cast<int>(input->readULong(2)); |
| 491 |
if (val) f << "f" << i << "=" << val << ","; |
| 492 |
} |
| 493 |
ascii().addDelimiter(input->tell(), '|'); |
| 494 |
input->seek(pos+20, librevenge::RVNG_SEEK_SET); |
| 495 |
ascii().addPos(pos); |
| 496 |
ascii().addNote(f.str().c_str()); |
| 497 |
|
| 498 |
// the document font ? |
| 499 |
if (!m_textParser->readFont(-1, posChar, font)) |
| 500 |
return false; |
| 501 |
|
| 502 |
pos=input->tell(); |
| 503 |
f.str(""); |
| 504 |
f << "DocHeader-2:"; |
| 505 |
for (int i=0; i<5; ++i) { |
| 506 |
val=static_cast<int>(input->readULong(2)); |
| 507 |
static int const expected[] = {0,1,2,2,0}; |
| 508 |
if (val!=expected[i]) |
| 509 |
f << "f" << i << "=" << val << ","; |
| 510 |
} |
| 511 |
for (int i=0; i<8; ++i) { |
| 512 |
val=static_cast<int>(input->readULong(1)); |
| 513 |
static int const expected[] = {1/*or 16*/,0,0,0,0,1,1, 0}; |
| 514 |
if (val!=expected[i]) |
| 515 |
f << "f" << i+5 << "=" << val << ","; |
| 516 |
} |
| 517 |
for (int i=0; i<4; ++i) { |
| 518 |
val=static_cast<int>(input->readULong(2)); |
| 519 |
static int const expected[] = {1,1,0x2d,0}; |
| 520 |
if (val!=expected[i]) |
| 521 |
f << "f" << i+13 << "=" << val << ","; |
| 522 |
} |
| 523 |
f << "fl=["; |
| 524 |
for (int i=0; i<13; ++i) { |
| 525 |
val=static_cast<int>(input->readULong(1)); |
| 526 |
if (val==1) f << "*,"; |
| 527 |
else if (val) f << val << ","; |
| 528 |
else f << "_,"; |
| 529 |
} |
| 530 |
f << "],"; |
| 531 |
for (int i=0; i<16; ++i) { // always 0 |
| 532 |
val=static_cast<int>(input->readULong(2)); |
| 533 |
if (val) |
| 534 |
f << "g" << i << "=" << val << ","; |
| 535 |
} |
| 536 |
for (int i=0; i<5; ++i) { |
| 537 |
val=static_cast<int>(input->readULong(2)); |
| 538 |
static int const expected[] = {0,1,0,0x600,0x504}; |
| 539 |
if (val!=expected[i]) |
| 540 |
f << "h" << i << "=" << std::hex << val << std::dec << ","; |
| 541 |
} |
| 542 |
val=static_cast<int>(input->readULong(1)); // always 0 |
| 543 |
if (val) f << "h5=" << val << ","; |
| 544 |
int num[3]; |
| 545 |
for (int i=0; i<3; ++i) { |
| 546 |
num[i]=static_cast<int>(input->readULong(2)); |
| 547 |
if (!num[i]) |
| 548 |
continue; |
| 549 |
static char const *wh[]= {"color", "unkn1", "gradient"}; |
| 550 |
f << "num[" << wh[i] << "]=" << num[i] << ","; |
| 551 |
} |
| 552 |
m_styleManager->setDefaultNumbers(num[0], num[2]); |
| 553 |
|
| 554 |
ascii().addDelimiter(input->tell(),'|'); |
| 555 |
ascii().addPos(pos); |
| 556 |
ascii().addNote(f.str().c_str()); |
| 557 |
input->seek(pos+124, librevenge::RVNG_SEEK_SET); |
| 558 |
|
| 559 |
pos=input->tell(); |
| 560 |
f.str(""); |
| 561 |
f << "DocHeader(Col):"; |
| 562 |
auto numCols = static_cast<int>(input->readLong(2)); |
| 563 |
if (numCols < 1 || numCols > 9) { |
| 564 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDocHeader: pb reading number of columns\n")); |
| 565 |
f << "###numCols=" << numCols; |
| 566 |
numCols = 1; |
| 567 |
} |
| 568 |
if (numCols != 1) |
| 569 |
f << "numCols=" << numCols << ","; |
| 570 |
f << "colsW=["; |
| 571 |
for (int i = 0; i < numCols; i++) { |
| 572 |
val = static_cast<int>(input->readULong(2)); |
| 573 |
f << val << ","; |
| 574 |
} |
| 575 |
f << "],"; |
| 576 |
input->seek(pos+20, librevenge::RVNG_SEEK_SET); |
| 577 |
if (numCols > 1) { |
| 578 |
f << "colsS=["; |
| 579 |
for (int i = 0; i < numCols-1; i++) { |
| 580 |
val = static_cast<int>(input->readULong(2)); |
| 581 |
f << input->readULong(2); |
| 582 |
if (val) f << ":" << val << ","; |
| 583 |
} |
| 584 |
f << "],"; |
| 585 |
} |
| 586 |
input->seek(pos+36, librevenge::RVNG_SEEK_SET); |
| 587 |
val = static_cast<int>(input->readLong(2)); |
| 588 |
if (val) f << "unkn=" << val << ","; |
| 589 |
ascii().addPos(pos); |
| 590 |
ascii().addNote(f.str().c_str()); |
| 591 |
|
| 592 |
pos=input->tell(); |
| 593 |
input->seek(pos+214, librevenge::RVNG_SEEK_SET); |
| 594 |
ascii().addPos(pos); |
| 595 |
ascii().addNote("DocHeader-3"); |
| 596 |
|
| 597 |
pos=input->tell(); // only 0? |
| 598 |
input->seek(pos+256, librevenge::RVNG_SEEK_SET); |
| 599 |
ascii().addPos(pos); |
| 600 |
ascii().addNote("DocHeader-4"); |
| 601 |
|
| 602 |
pos=input->tell(); |
| 603 |
input->seek(pos+190, librevenge::RVNG_SEEK_SET); |
| 604 |
ascii().addPos(pos); |
| 605 |
ascii().addNote("DocHeader-5"); |
| 606 |
|
| 607 |
pos=input->tell(); // only 0? |
| 608 |
input->seek(pos+256, librevenge::RVNG_SEEK_SET); |
| 609 |
ascii().addPos(pos); |
| 610 |
ascii().addNote("DocHeader-6"); |
| 611 |
|
| 612 |
pos=input->tell(); |
| 613 |
input->seek(pos+256+96, librevenge::RVNG_SEEK_SET); |
| 614 |
ascii().addPos(pos); |
| 615 |
ascii().addNote("DocHeader-7"); |
| 616 |
|
| 617 |
pos=input->tell(); |
| 618 |
f.str(""); |
| 619 |
f << "DocHeader-8:"; |
| 620 |
input->seek(pos+111, librevenge::RVNG_SEEK_SET); |
| 621 |
val=static_cast<int>(input->readLong(1)); |
| 622 |
if (val==1) { |
| 623 |
f << "slide,"; |
| 624 |
m_state->m_displayAsSlide=true; |
| 625 |
} |
| 626 |
else if (val) { |
| 627 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDocHeader: pb reading the viewer style\n")); |
| 628 |
f << "###slide=" << val << ","; |
| 629 |
} |
| 630 |
input->seek(pos+150, librevenge::RVNG_SEEK_SET); |
| 631 |
ascii().addPos(pos); |
| 632 |
ascii().addNote(f.str().c_str()); |
| 633 |
|
| 634 |
pos=input->tell(); |
| 635 |
input->seek(pos+130, librevenge::RVNG_SEEK_SET); |
| 636 |
ascii().addPos(pos); |
| 637 |
ascii().addNote("DocHeader-9"); |
| 638 |
|
| 639 |
pos=input->tell(); |
| 640 |
ascii().addPos(pos); |
| 641 |
ascii().addNote("DocHeader-A"); |
| 642 |
|
| 643 |
input->seek(0x80A, librevenge::RVNG_SEEK_SET); |
| 644 |
// now 25 zones |
| 645 |
for (int i=0; i<25; ++i) { |
| 646 |
if (input->isEnd()) |
| 647 |
return false; |
| 648 |
pos=input->tell(); |
| 649 |
auto zoneSz=long(input->readULong(4)); |
| 650 |
if (!zoneSz) { |
| 651 |
ascii().addPos(pos); |
| 652 |
ascii().addNote("_"); |
| 653 |
continue; |
| 654 |
} |
| 655 |
if (!input->checkPosition(pos+4+zoneSz)) { |
| 656 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDocHeader: can not find zone %d\n", i+1)); |
| 657 |
ascii().addPos(pos); |
| 658 |
ascii().addNote("###"); |
| 659 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 660 |
return true; |
| 661 |
} |
| 662 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 663 |
bool done=false; |
| 664 |
switch (i+1) { |
| 665 |
case 1: |
| 666 |
done=m_textParser->readParagraphs(); |
| 667 |
break; |
| 668 |
case 2: |
| 669 |
done=readPrintInfo(); |
| 670 |
break; |
| 671 |
case 3: |
| 672 |
done=m_styleManager->readPatternList(); |
| 673 |
break; |
| 674 |
case 4: |
| 675 |
done=m_styleManager->readGradientList(); |
| 676 |
break; |
| 677 |
case 6: |
| 678 |
done=m_styleManager->readFontStyles(); |
| 679 |
break; |
| 680 |
case 8: // never seens data: fieldData=4, headerSize=14 (always 1,5,0,100,101,0,101,0,1,12710?) |
| 681 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Zone8A", false); |
| 682 |
break; |
| 683 |
case 9: // never seens data: fieldData=12, headerSize=4 (1,id) |
| 684 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Zone9A", false); |
| 685 |
break; |
| 686 |
case 10: // never seens data: fieldData=4, headerSize=4 (1,id) |
| 687 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Zone10A", false); |
| 688 |
break; |
| 689 |
// CHECKME |
| 690 |
case 16: // Arrow |
| 691 |
done=m_styleManager->readArrows(); |
| 692 |
break; |
| 693 |
case 17: // Dash |
| 694 |
done=m_styleManager->readDashs(); |
| 695 |
break; |
| 696 |
case 18: // Ruler style |
| 697 |
done=m_styleManager->readRulers(); |
| 698 |
break; |
| 699 |
case 20: |
| 700 |
done = m_graphParser->readTransformations(); |
| 701 |
break; |
| 702 |
case 21: // fieldData=36 |
| 703 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Zone21A", false); |
| 704 |
break; |
| 705 |
case 22: // fieldData=4, headerSize=4 (1, consecutive id) |
| 706 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Zone22A", false); |
| 707 |
break; |
| 708 |
default: |
| 709 |
break; |
| 710 |
} |
| 711 |
if (done) continue; |
| 712 |
f.str(""); |
| 713 |
f << "Entries(Zone" << i+1 << "A):"; |
| 714 |
ascii().addPos(pos); |
| 715 |
ascii().addNote(f.str().c_str()); |
| 716 |
input->seek(pos+4+zoneSz, librevenge::RVNG_SEEK_SET); |
| 717 |
} |
| 718 |
|
| 719 |
pos=input->tell(); |
| 720 |
if (!readDocInfo()) { |
| 721 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 722 |
return true; |
| 723 |
} |
| 724 |
pos=input->tell(); |
| 725 |
if (!readLayouts()) { |
| 726 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDocHeader: can not find layout zone\n")); |
| 727 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 728 |
return true; |
| 729 |
} |
| 730 |
pos=input->tell(); |
| 731 |
input->seek(pos+4, librevenge::RVNG_SEEK_SET); |
| 732 |
if (input->readULong(2)!=0x100) { |
| 733 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDocHeader: can not find UnknZone zone\n")); |
| 734 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 735 |
return true; |
| 736 |
} |
| 737 |
ascii().addPos(pos); |
| 738 |
ascii().addNote("Entries(UnknZone0)"); |
| 739 |
input->seek(pos+832, librevenge::RVNG_SEEK_SET); |
| 740 |
|
| 741 |
// now 12 zones |
| 742 |
for (int i=0; i<12; ++i) { |
| 743 |
if (input->isEnd()) |
| 744 |
return false; |
| 745 |
pos=input->tell(); |
| 746 |
auto zoneSz=long(input->readULong(4)); |
| 747 |
if (!zoneSz) { |
| 748 |
ascii().addPos(pos); |
| 749 |
ascii().addNote("_"); |
| 750 |
continue; |
| 751 |
} |
| 752 |
if (!input->checkPosition(pos+4+zoneSz)) { |
| 753 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDocHeader: can not find zone %d\n", i+1)); |
| 754 |
ascii().addPos(pos); |
| 755 |
ascii().addNote("###"); |
| 756 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 757 |
return true; |
| 758 |
} |
| 759 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 760 |
bool done=false; |
| 761 |
switch (i+1) { |
| 762 |
case 1: // never seens data: fieldData=4, headerSize=4 (1,id) |
| 763 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB1A", false); |
| 764 |
break; |
| 765 |
case 3: // never seens data: fieldData=6, headerSize=0 |
| 766 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB3A", false); |
| 767 |
break; |
| 768 |
case 4:// never seens data: fieldData=14, headerSize=0 |
| 769 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB4A", false); |
| 770 |
break; |
| 771 |
case 5:// never seens data: fieldData=14, headerSize=0 |
| 772 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB5A", false); |
| 773 |
break; |
| 774 |
case 6:// never seens data: fieldData=8, headerSize=80 |
| 775 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB6A", false); |
| 776 |
break; |
| 777 |
case 7:// never seens data: fieldData=28, headerSize=80 |
| 778 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB7A", false); |
| 779 |
break; |
| 780 |
case 8:// never seens data: fieldData=1e, headerSize=0 |
| 781 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB8A", false); |
| 782 |
break; |
| 783 |
case 9:// TODO: fieldData=1c (2*double+), headerSize=0 |
| 784 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB9A", false); |
| 785 |
break; |
| 786 |
case 10: |
| 787 |
done = m_styleManager->readColorList(); |
| 788 |
break; |
| 789 |
case 11:// never seens data: fieldData=c, headerSize=0 |
| 790 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB11A", false); |
| 791 |
break; |
| 792 |
case 12:// never seens data: fieldData=32, headerSize=0 |
| 793 |
done = ClarisWksStruct::readStructZone(*getParserState(), "ZoneB12A", false); |
| 794 |
break; |
| 795 |
default: |
| 796 |
break; |
| 797 |
} |
| 798 |
if (done) continue; |
| 799 |
f.str(""); |
| 800 |
f << "Entries(ZoneB" << i+1 << "A):"; |
| 801 |
ascii().addPos(pos); |
| 802 |
ascii().addNote(f.str().c_str()); |
| 803 |
input->seek(pos+4+zoneSz, librevenge::RVNG_SEEK_SET); |
| 804 |
} |
| 805 |
pos=input->tell(); |
| 806 |
f.str(""); |
| 807 |
f << "Entries(NDSET):"; |
| 808 |
m_state->m_numDSET=static_cast<int>(input->readLong(2)); |
| 809 |
if (m_state->m_numDSET) f << "num=" << m_state->m_numDSET << ","; |
| 810 |
ascii().addPos(pos); |
| 811 |
ascii().addNote(f.str().c_str()); |
| 812 |
|
| 813 |
return true; |
| 814 |
} |
| 815 |
|
| 816 |
bool ClarisDrawParser::readLibraryHeader() |
| 817 |
{ |
| 818 |
MWAWInputStreamPtr input = getInput(); |
| 819 |
libmwaw::DebugStream f; |
| 820 |
f << "Entries(LibHeader):"; |
| 821 |
if (!input->checkPosition(846)) return false; |
| 822 |
input->seek(8, librevenge::RVNG_SEEK_SET); |
| 823 |
long val=input->readLong(4); // always 0 |
| 824 |
if (val) f << "f0=" << val << ","; |
| 825 |
f << "ID=" << std::hex << input->readULong(4) << std::dec << ","; // a big number |
| 826 |
val=input->readLong(2); // always 0x100 |
| 827 |
if (val!=0x100) f << "f1=" << val << ","; |
| 828 |
for (int i=0; i<5; ++i) { // always 0 |
| 829 |
val=input->readLong(2); |
| 830 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 831 |
} |
| 832 |
auto N=static_cast<int>(input->readLong(2)); // checkme: the number of graphics ? |
| 833 |
if (N) f << "N=" << N << ","; |
| 834 |
for (long i=0; i<2; ++i) { // always 0,1 |
| 835 |
val=input->readLong(2); |
| 836 |
if (val!=i) f << "f" << i+7 << "=" << val << ","; |
| 837 |
} |
| 838 |
f << "ID1=["; |
| 839 |
for (int i=0; i<2; ++i) { // two big number |
| 840 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 841 |
} |
| 842 |
f << "],"; |
| 843 |
val=input->readLong(2); // always 0x100 |
| 844 |
if (val!=0x100) f << "f9=" << val << ","; |
| 845 |
val=input->readLong(2); // always 0 |
| 846 |
if (val) f << "f10=" << val << ","; |
| 847 |
f << "ID2=" << std::hex << input->readULong(4) << std::dec << ","; // another big number |
| 848 |
for (int i=0; i<56; ++i) { // always 0 |
| 849 |
val=input->readLong(2); |
| 850 |
if (val) f << "g" << i << "=" << val << ","; |
| 851 |
} |
| 852 |
ascii().addPos(8); |
| 853 |
ascii().addNote(f.str().c_str()); |
| 854 |
|
| 855 |
long pos=input->tell(); |
| 856 |
f.str(""); |
| 857 |
f << "LibHeader-A:"; |
| 858 |
for (int i=0; i<2; ++i) { // f1=54,5c|5d |
| 859 |
val=input->readLong(2); |
| 860 |
if (val) f << "f" << i << "=" << val << ","; |
| 861 |
} |
| 862 |
f << "IDs=["; |
| 863 |
for (int i=0; i<9; ++i) { // 7 or 9 big number |
| 864 |
val=long(input->readULong(4)); |
| 865 |
if (val) |
| 866 |
f << std::hex << val << std::dec << ","; |
| 867 |
else |
| 868 |
f << "_,"; |
| 869 |
} |
| 870 |
f << "],"; |
| 871 |
for (int i=0; i<6; ++i) { // always 0 |
| 872 |
val=input->readLong(2); |
| 873 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 874 |
} |
| 875 |
for (int i=0; i<2; ++i) { |
| 876 |
f << "unkn" << i << "=["; |
| 877 |
for (int j=0; j<2; ++j) { // _, small number |
| 878 |
val=input->readLong(2); |
| 879 |
if (val) |
| 880 |
f << val << ","; |
| 881 |
else |
| 882 |
f << "_,"; |
| 883 |
} |
| 884 |
f << std::hex << input->readULong(4) << std::dec << ","; // big number or 0 |
| 885 |
f << "],"; |
| 886 |
} |
| 887 |
for (int i=0; i<26; ++i) { // always 0 |
| 888 |
val=input->readLong(2); |
| 889 |
if (val) f << "g" << i << "=" << val << ","; |
| 890 |
} |
| 891 |
ascii().addPos(pos); |
| 892 |
ascii().addNote(f.str().c_str()); |
| 893 |
|
| 894 |
pos=input->tell(); |
| 895 |
f.str(""); |
| 896 |
f << "LibHeader-B:"; |
| 897 |
auto fSz=static_cast<int>(input->readULong(1)); |
| 898 |
if (fSz>63) { |
| 899 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryHeader: string size seems bad\n")); |
| 900 |
f << "##fSz=" << fSz << ","; |
| 901 |
fSz=0; |
| 902 |
} |
| 903 |
std::string text(""); |
| 904 |
for (int i=0; i<fSz; ++i) text+=char(input->readULong(1)); |
| 905 |
f << "filename=" << text << ","; |
| 906 |
input->seek(pos+64, librevenge::RVNG_SEEK_SET); |
| 907 |
for (int i=0; i<96; ++i) { // always 0 |
| 908 |
val=input->readLong(2); |
| 909 |
if (val) f << "f" << i << "=" << val << ","; |
| 910 |
} |
| 911 |
val=static_cast<int>(input->readULong(1)); // always filename size ? |
| 912 |
if (val!=fSz) f << "#fSz1=" << fSz << ","; |
| 913 |
val=static_cast<int>(input->readULong(1)); // always 0? |
| 914 |
if (val) f << "f96=" << val << ","; |
| 915 |
f << "ID=" << std::hex << input->readULong(4) << std::dec << ","; // big number |
| 916 |
val=static_cast<int>(input->readLong(2)); // 0 | 0fcc |
| 917 |
if (val) f << "g0=" << val << ","; |
| 918 |
val=static_cast<int>(input->readULong(2)); // 80[89]3 |
| 919 |
if (val) f << "fl=" << std::hex << val << std::dec << ","; |
| 920 |
val=static_cast<int>(input->readLong(2)); // 0 |
| 921 |
if (val) f << "g1=" << val << ","; |
| 922 |
val=static_cast<int>(input->readULong(1)); // always filename size ? |
| 923 |
if (val!=fSz) f << "#fSz2=" << fSz << ","; |
| 924 |
val=static_cast<int>(input->readULong(1)); // always 0? |
| 925 |
if (val) f << "g2=" << val << ","; |
| 926 |
ascii().addPos(pos); |
| 927 |
ascii().addNote(f.str().c_str()); |
| 928 |
|
| 929 |
pos=input->tell(); |
| 930 |
f.str(""); |
| 931 |
f << "LibHeader-C:"; |
| 932 |
fSz=static_cast<int>(input->readULong(1)); |
| 933 |
if (fSz>63) { |
| 934 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryHeader: string size seems bad\n")); |
| 935 |
f << "##fSz=" << fSz << ","; |
| 936 |
fSz=0; |
| 937 |
} |
| 938 |
text=""; |
| 939 |
for (int i=0; i<fSz; ++i) text+=char(input->readULong(1)); |
| 940 |
f << "author?=" << text << ","; |
| 941 |
input->seek(pos+64, librevenge::RVNG_SEEK_SET); |
| 942 |
for (int i=0; i<96; ++i) { // always 0 |
| 943 |
val=input->readLong(2); |
| 944 |
if (val) f << "f" << i << "=" << val << ","; |
| 945 |
} |
| 946 |
ascii().addPos(pos); |
| 947 |
ascii().addNote(f.str().c_str()); |
| 948 |
|
| 949 |
pos=input->tell(); |
| 950 |
f.str(""); |
| 951 |
f << "LibHeader-D:"; |
| 952 |
for (int i=0; i<16; ++i) { |
| 953 |
val=static_cast<int>(input->readLong(2)); |
| 954 |
static int const expected[]= {4,2,0/*35 or 3f*/,48, 9, 0/*78 or 8x*/, 0x42, 18, |
| 955 |
3, 0xd4, 0/*7b or 8e*/, 0x57, 3, 0xc4, 0/*7b or 8f*/, 0 |
| 956 |
}; |
| 957 |
if (val!=expected[i]) |
| 958 |
f << "f" << i << "=" << val << ","; |
| 959 |
} |
| 960 |
int dim[2]; |
| 961 |
for (auto &i : dim) i=static_cast<int>(input->readLong(2)); |
| 962 |
f << "dim=" << MWAWVec2i(dim[0],dim[1]) << ","; // 64x64 or 72x72 |
| 963 |
m_state->m_numDSET=static_cast<int>(input->readLong(2)); |
| 964 |
if (m_state->m_numDSET) f << "num[DSET]=" << m_state->m_numDSET << ","; |
| 965 |
ascii().addPos(pos); |
| 966 |
ascii().addNote(f.str().c_str()); |
| 967 |
|
| 968 |
input->seek(846, librevenge::RVNG_SEEK_SET); |
| 969 |
// the style are coded after the DSET zones, let try to find them |
| 970 |
input->seek(-44, librevenge::RVNG_SEEK_END); |
| 971 |
while (input->tell()>=846) { |
| 972 |
pos=input->tell(); |
| 973 |
auto c=static_cast<int>(input->readULong(1)); |
| 974 |
bool find=false; |
| 975 |
switch (c) { |
| 976 |
case 0x44: |
| 977 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 978 |
if (readDSET(pos==846)) |
| 979 |
find=true; |
| 980 |
else |
| 981 |
input->seek(pos-4, librevenge::RVNG_SEEK_SET); |
| 982 |
break; |
| 983 |
case 0x53: |
| 984 |
input->seek(pos-1, librevenge::RVNG_SEEK_SET); |
| 985 |
break; |
| 986 |
case 0x45: |
| 987 |
input->seek(pos-2, librevenge::RVNG_SEEK_SET); |
| 988 |
break; |
| 989 |
case 0x54: |
| 990 |
input->seek(pos-3, librevenge::RVNG_SEEK_SET); |
| 991 |
break; |
| 992 |
default: |
| 993 |
input->seek(pos-4, librevenge::RVNG_SEEK_SET); |
| 994 |
break; |
| 995 |
} |
| 996 |
if (!find) |
| 997 |
continue; |
| 998 |
m_state->m_EOF=input->tell(); |
| 999 |
// clean storage |
| 1000 |
m_graphParser->resetState(); |
| 1001 |
m_textParser->resetState(); |
| 1002 |
m_state->m_zonesMap.clear(); |
| 1003 |
m_state->m_zoneIdToFileTypeMap.clear(); |
| 1004 |
while (!input->isEnd()) { |
| 1005 |
pos=input->tell(); |
| 1006 |
if (input->readULong(4)) { |
| 1007 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1008 |
break; |
| 1009 |
} |
| 1010 |
ascii().addPos(pos); |
| 1011 |
ascii().addNote("_"); |
| 1012 |
} |
| 1013 |
pos=input->tell(); |
| 1014 |
bool ok=true; |
| 1015 |
if (!m_textParser->readParagraphs()) { |
| 1016 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryHeader: can not read the paragraph style\n")); |
| 1017 |
ascii().addPos(pos); |
| 1018 |
ascii().addNote("Entries(RULR):###"); |
| 1019 |
ok=false; |
| 1020 |
} |
| 1021 |
for (int i=0; ok && i<20; ++i) { |
| 1022 |
pos=input->tell(); |
| 1023 |
auto dSz=long(input->readULong(4)); |
| 1024 |
if (!dSz) { |
| 1025 |
ascii().addPos(pos); |
| 1026 |
ascii().addNote("_"); |
| 1027 |
continue; |
| 1028 |
} |
| 1029 |
if (!input->checkPosition(pos+4+dSz)) { |
| 1030 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryHeader: can not find style zone %d\n", i+1)); |
| 1031 |
ascii().addPos(pos); |
| 1032 |
ascii().addNote("###"); |
| 1033 |
break; |
| 1034 |
} |
| 1035 |
bool done=false; |
| 1036 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1037 |
switch (i+1) { |
| 1038 |
case 1: |
| 1039 |
done=m_styleManager->readArrows(); |
| 1040 |
break; |
| 1041 |
case 2: |
| 1042 |
done=m_styleManager->readDashs(); |
| 1043 |
break; |
| 1044 |
case 3: |
| 1045 |
done=m_styleManager->readPatternList(); |
| 1046 |
break; |
| 1047 |
case 4: |
| 1048 |
done=m_styleManager->readGradientList(); |
| 1049 |
break; |
| 1050 |
case 5: |
| 1051 |
done = m_graphParser->readTransformations(); |
| 1052 |
break; |
| 1053 |
case 6: |
| 1054 |
done = m_styleManager->readRulers(); |
| 1055 |
break; |
| 1056 |
case 7: // two zones: pos and names |
| 1057 |
done = readLibraryNames(); |
| 1058 |
break; |
| 1059 |
case 8: |
| 1060 |
done = m_styleManager->readColorList(); |
| 1061 |
break; |
| 1062 |
case 9: // maybe zone 24 |
| 1063 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Style10A", false); |
| 1064 |
break; |
| 1065 |
case 10: // maybe zone 25 |
| 1066 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Style11A", false); |
| 1067 |
break; |
| 1068 |
case 11: // maybe readfontnames without header |
| 1069 |
done = ClarisWksStruct::readStructZone(*getParserState(), "Style12A", false); |
| 1070 |
break; |
| 1071 |
default: |
| 1072 |
break; |
| 1073 |
} |
| 1074 |
if (done) continue; |
| 1075 |
f.str(""); |
| 1076 |
f << "Entries(Style" << i+1 << "A):"; |
| 1077 |
ascii().addPos(pos); |
| 1078 |
ascii().addNote(f.str().c_str()); |
| 1079 |
input->seek(pos+4+dSz, librevenge::RVNG_SEEK_SET); |
| 1080 |
} |
| 1081 |
break; |
| 1082 |
} |
| 1083 |
input->seek(846, librevenge::RVNG_SEEK_SET); |
| 1084 |
if (!readDSET(true)) { |
| 1085 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryHeader:can not read main group\n")); |
| 1086 |
input->seek(846, librevenge::RVNG_SEEK_SET); |
| 1087 |
} |
| 1088 |
return true; |
| 1089 |
} |
| 1090 |
|
| 1091 |
//////////////////////////////////////////////////////////// |
| 1092 |
// read the header |
| 1093 |
//////////////////////////////////////////////////////////// |
| 1094 |
bool ClarisDrawParser::checkHeader(MWAWHeader *header, bool /*strict*/) |
| 1095 |
{ |
| 1096 |
*m_state = ClarisDrawParserInternal::State(); |
| 1097 |
MWAWInputStreamPtr input = getInput(); |
| 1098 |
if (!input || !input->hasDataFork() || !input->checkPosition(846)) |
| 1099 |
return false; |
| 1100 |
|
| 1101 |
libmwaw::DebugStream f; |
| 1102 |
f << "FileHeader:"; |
| 1103 |
input->seek(0, librevenge::RVNG_SEEK_SET); |
| 1104 |
auto val=static_cast<int>(input->readULong(1)); |
| 1105 |
if (val==0x2) { |
| 1106 |
m_state->m_isLibrary=true; |
| 1107 |
f << "lib,"; |
| 1108 |
} |
| 1109 |
else if (val==0x1) { |
| 1110 |
if (!input->checkPosition(0x80A)) |
| 1111 |
return false; |
| 1112 |
} |
| 1113 |
else |
| 1114 |
return false; |
| 1115 |
val=static_cast<int>(input->readULong(2)); // a3-b1 |
| 1116 |
if (val) f << "f0=" << std::hex << val << std::dec << ","; |
| 1117 |
if (input->readULong(1) || input->readULong(4) != 0x45585057) return false; |
| 1118 |
int vers=1; |
| 1119 |
setVersion(vers); |
| 1120 |
m_state->m_version=vers; |
| 1121 |
if (header) |
| 1122 |
header->reset(MWAWDocument::MWAW_T_CLARISDRAW, vers, MWAWDocument::MWAW_K_DRAW); |
| 1123 |
input->seek(8,librevenge::RVNG_SEEK_SET); |
| 1124 |
ascii().addPos(0); |
| 1125 |
ascii().addNote(f.str().c_str()); |
| 1126 |
|
| 1127 |
return true; |
| 1128 |
} |
| 1129 |
|
| 1130 |
//////////////////////////////////////////////////////////// |
| 1131 |
// read the layout |
| 1132 |
//////////////////////////////////////////////////////////// |
| 1133 |
bool ClarisDrawParser::readLayouts() |
| 1134 |
{ |
| 1135 |
MWAWInputStreamPtr input = getInput(); |
| 1136 |
long pos=input->tell(); |
| 1137 |
libmwaw::DebugFile &ascFile = ascii(); |
| 1138 |
libmwaw::DebugStream f; |
| 1139 |
f << "Entries(Layout):"; |
| 1140 |
ClarisWksStruct::Struct header; |
| 1141 |
if (!header.readHeader(input,true)) { |
| 1142 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLayouts: the data size seems bad\n")); |
| 1143 |
f << "###"; |
| 1144 |
ascFile.addPos(pos); |
| 1145 |
ascFile.addNote(f.str().c_str()); |
| 1146 |
return false; |
| 1147 |
} |
| 1148 |
if (header.m_size==0) { |
| 1149 |
ascFile.addPos(pos); |
| 1150 |
ascFile.addNote("_"); |
| 1151 |
return true; |
| 1152 |
} |
| 1153 |
long endPos = pos+4+header.m_size; |
| 1154 |
f << header; |
| 1155 |
if (header.m_headerSize) { |
| 1156 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1157 |
input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR); |
| 1158 |
} |
| 1159 |
ascFile.addPos(pos); |
| 1160 |
ascFile.addNote(f.str().c_str()); |
| 1161 |
|
| 1162 |
pos=input->tell(); |
| 1163 |
if (header.m_dataSize!=336) { |
| 1164 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1165 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLayouts: no sure how to read the data\n")); |
| 1166 |
ascFile.addPos(pos); |
| 1167 |
ascFile.addNote("Layout:###"); |
| 1168 |
return true; |
| 1169 |
} |
| 1170 |
for (long i=0; i<header.m_numData; ++i) { |
| 1171 |
pos=input->tell(); |
| 1172 |
ClarisDrawParserInternal::Layer layer; |
| 1173 |
f.str(""); |
| 1174 |
f << "Layout-A" << i << ":"; |
| 1175 |
auto cSz=static_cast<int>(input->readULong(1)); |
| 1176 |
librevenge::RVNGString name(""); |
| 1177 |
for (int c=0; c<cSz; ++c) { |
| 1178 |
auto ch=char(input->readULong(1)); |
| 1179 |
if (!ch) continue; |
| 1180 |
f << ch; |
| 1181 |
int unicode= getParserState()->m_fontConverter->unicode(3, static_cast<unsigned char>(ch)); |
| 1182 |
if (unicode==-1) |
| 1183 |
name.append(ch); |
| 1184 |
else |
| 1185 |
libmwaw::appendUnicode(static_cast<uint32_t>(unicode), name); |
| 1186 |
} |
| 1187 |
f << ","; |
| 1188 |
layer.m_name=name; |
| 1189 |
ascFile.addPos(pos); |
| 1190 |
ascFile.addNote(f.str().c_str()); |
| 1191 |
|
| 1192 |
input->seek(pos+256, librevenge::RVNG_SEEK_SET); |
| 1193 |
pos=input->tell(); |
| 1194 |
f.str(""); |
| 1195 |
f << "Layout-B" << i << ":"; |
| 1196 |
auto val=static_cast<int>(input->readULong(1)); // always 40|80 |
| 1197 |
if (val&0x80) { |
| 1198 |
f << "hidden,"; |
| 1199 |
layer.m_isHidden=true; |
| 1200 |
} |
| 1201 |
val &=0x7F; |
| 1202 |
if (val!=0x40) f << "fl0=" << std::hex << val << std::dec << ","; |
| 1203 |
val=static_cast<int>(input->readULong(1)); // 0|1|2|6c|d8|fc|ff |
| 1204 |
if (val) f << "fl1=" << std::hex << val << std::dec << ","; |
| 1205 |
for (int j=0; j<2; ++j) { // always 0 |
| 1206 |
val=static_cast<int>(input->readULong(2)); |
| 1207 |
if (val) f << "f" << j << "=" << val << ","; |
| 1208 |
} |
| 1209 |
layer.m_groupId=static_cast<int>(input->readULong(2)); |
| 1210 |
f << "id[group]=" << layer.m_groupId << ","; |
| 1211 |
val=static_cast<int>(input->readLong(4)); |
| 1212 |
if (val==-1) |
| 1213 |
f << "locked,"; |
| 1214 |
else if (val) |
| 1215 |
f << "#lock=" << val << ","; |
| 1216 |
for (int j=0; j<16; ++j) { // always 0 |
| 1217 |
val=static_cast<int>(input->readULong(4)); |
| 1218 |
if (val) f << "g" << j << "=" << val << ","; |
| 1219 |
} |
| 1220 |
val=static_cast<int>(input->readULong(4)); |
| 1221 |
if (val) f << "ID=" << std::hex << val << std::dec << ","; |
| 1222 |
ascFile.addPos(pos); |
| 1223 |
ascFile.addNote(f.str().c_str()); |
| 1224 |
input->seek(pos+80, librevenge::RVNG_SEEK_SET); |
| 1225 |
m_state->m_layerList.push_back(layer); |
| 1226 |
} |
| 1227 |
return true; |
| 1228 |
} |
| 1229 |
|
| 1230 |
bool ClarisDrawParser::readLibraryNames() |
| 1231 |
{ |
| 1232 |
MWAWInputStreamPtr input = getInput(); |
| 1233 |
long pos=input->tell(); |
| 1234 |
if (!input->checkPosition(pos+8)) return false; |
| 1235 |
libmwaw::DebugFile &ascFile = ascii(); |
| 1236 |
libmwaw::DebugStream f; |
| 1237 |
f << "Entries(LibraryName):"; |
| 1238 |
ClarisWksStruct::Struct header; |
| 1239 |
if (!header.readHeader(input,true)) { |
| 1240 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryNames: the data size seems bad\n")); |
| 1241 |
f << "###"; |
| 1242 |
ascFile.addPos(pos); |
| 1243 |
ascFile.addNote(f.str().c_str()); |
| 1244 |
return false; |
| 1245 |
} |
| 1246 |
if (header.m_size==0) { |
| 1247 |
ascFile.addPos(pos); |
| 1248 |
ascFile.addNote("_"); |
| 1249 |
pos=input->tell(); |
| 1250 |
auto sz = long(input->readULong(4)); |
| 1251 |
if (!input->checkPosition(pos+4+sz)) { |
| 1252 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryNames: the name size seems bad\n")); |
| 1253 |
f << "###"; |
| 1254 |
ascFile.addPos(pos); |
| 1255 |
ascFile.addNote(f.str().c_str()); |
| 1256 |
return false; |
| 1257 |
} |
| 1258 |
if (!sz) { |
| 1259 |
ascFile.addPos(pos); |
| 1260 |
ascFile.addNote("_"); |
| 1261 |
return true; |
| 1262 |
} |
| 1263 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryNames: find a string but no position\n")); |
| 1264 |
f << "###"; |
| 1265 |
ascFile.addPos(pos); |
| 1266 |
ascFile.addNote(f.str().c_str()); |
| 1267 |
input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET); |
| 1268 |
return true; |
| 1269 |
} |
| 1270 |
|
| 1271 |
long endPos=pos+4+header.m_size; |
| 1272 |
f << header; |
| 1273 |
if (header.m_headerSize) { |
| 1274 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1275 |
input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR); |
| 1276 |
} |
| 1277 |
ascFile.addPos(pos); |
| 1278 |
ascFile.addNote(f.str().c_str()); |
| 1279 |
|
| 1280 |
pos=input->tell(); |
| 1281 |
if (header.m_dataSize!=4) { |
| 1282 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1283 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryNames: no sure how to read the position\n")); |
| 1284 |
ascFile.addPos(pos); |
| 1285 |
ascFile.addNote("LibraryName:###"); |
| 1286 |
return true; |
| 1287 |
} |
| 1288 |
|
| 1289 |
pos=input->tell(); |
| 1290 |
f.str(""); |
| 1291 |
f << "LibraryName-pos:"; |
| 1292 |
std::vector<int> positions, lengths; |
| 1293 |
for (long i=0; i<header.m_numData; ++i) { |
| 1294 |
auto sSz=static_cast<int>(input->readULong(2)); |
| 1295 |
auto position=static_cast<int>(input->readULong(2)); |
| 1296 |
f << position << ":" << sSz << ","; |
| 1297 |
positions.push_back(position); |
| 1298 |
lengths.push_back(sSz); |
| 1299 |
} |
| 1300 |
ascFile.addPos(pos); |
| 1301 |
ascFile.addNote(f.str().c_str()); |
| 1302 |
|
| 1303 |
pos=input->tell(); |
| 1304 |
f.str(""); |
| 1305 |
f << "LibraryName-name:"; |
| 1306 |
auto sz = long(input->readULong(4)); |
| 1307 |
if (sz==0 || !input->checkPosition(pos+4+sz)) { |
| 1308 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryNames: can not find the name\n")); |
| 1309 |
f << "###"; |
| 1310 |
ascFile.addPos(pos); |
| 1311 |
ascFile.addNote(f.str().c_str()); |
| 1312 |
return false; |
| 1313 |
} |
| 1314 |
|
| 1315 |
for (size_t i=0; i<positions.size(); ++i) { |
| 1316 |
ClarisDrawParserInternal::Layer layer; |
| 1317 |
if (positions[i]+lengths[i]>sz) { |
| 1318 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readLibraryNames: the name %d seems bad\n", int(i))); |
| 1319 |
f << "###,"; |
| 1320 |
m_state->m_layerList.push_back(layer); |
| 1321 |
continue; |
| 1322 |
} |
| 1323 |
input->seek(pos+4+positions[i], librevenge::RVNG_SEEK_SET); |
| 1324 |
librevenge::RVNGString name(""); |
| 1325 |
for (int c=0; c<lengths[i]; ++c) { |
| 1326 |
auto ch=char(input->readULong(1)); |
| 1327 |
if (!ch) continue; |
| 1328 |
f << ch; |
| 1329 |
int unicode= getParserState()->m_fontConverter->unicode(3, static_cast<unsigned char>(ch)); |
| 1330 |
if (unicode==-1) |
| 1331 |
name.append(ch); |
| 1332 |
else |
| 1333 |
libmwaw::appendUnicode(static_cast<uint32_t>(unicode), name); |
| 1334 |
} |
| 1335 |
f << ","; |
| 1336 |
layer.m_name = name; |
| 1337 |
m_state->m_layerList.push_back(layer); |
| 1338 |
} |
| 1339 |
ascFile.addPos(pos); |
| 1340 |
ascFile.addNote(f.str().c_str()); |
| 1341 |
input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET); |
| 1342 |
return true; |
| 1343 |
} |
| 1344 |
//////////////////////////////////////////////////////////// |
| 1345 |
// read the document information |
| 1346 |
//////////////////////////////////////////////////////////// |
| 1347 |
bool ClarisDrawParser::readDocInfo() |
| 1348 |
{ |
| 1349 |
MWAWInputStreamPtr input = getInput(); |
| 1350 |
libmwaw::DebugStream f; |
| 1351 |
f << "Entries(DocInfo):"; |
| 1352 |
long pos = input->tell(); |
| 1353 |
long endPos=pos+428; |
| 1354 |
if (!input->checkPosition(endPos)) return false; |
| 1355 |
f << "ptr=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1356 |
int val; |
| 1357 |
for (int i = 0; i < 6; i++) { |
| 1358 |
val = static_cast<int>(input->readULong(2)); |
| 1359 |
if (val) f << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 1360 |
} |
| 1361 |
m_state->m_headerId = static_cast<int>(input->readLong(2)); |
| 1362 |
if (m_state->m_headerId) f << "headerId=" << m_state->m_headerId << ","; |
| 1363 |
val = static_cast<int>(input->readLong(2)); |
| 1364 |
if (val) f << "unkn=" << val << ","; |
| 1365 |
m_state->m_footerId = static_cast<int>(input->readLong(2)); |
| 1366 |
if (m_state->m_footerId) f << "footerId=" << m_state->m_footerId << ","; |
| 1367 |
for (int i=0; i < 4; ++i) { |
| 1368 |
val = static_cast<int>(input->readLong(2)); |
| 1369 |
if (val) f << "g" << i << "=" << val << ","; |
| 1370 |
} |
| 1371 |
int pages[2]; |
| 1372 |
for (auto &page : pages) page=static_cast<int>(input->readLong(2)); |
| 1373 |
if (pages[1]>=1 && pages[1] < 1000 && pages[0]>=1 && pages[0]<100) |
| 1374 |
m_state->m_pages=MWAWVec2i(pages[0],pages[1]); |
| 1375 |
if (pages[0]!=1 || pages[1]!=1) |
| 1376 |
f << "pages[num]=" << pages[0] << "x" << pages[1] << ","; |
| 1377 |
ascii().addDelimiter(input->tell(), '|'); |
| 1378 |
ascii().addPos(pos); |
| 1379 |
ascii().addNote(f.str().c_str()); |
| 1380 |
ascii().addPos(pos+100); |
| 1381 |
ascii().addNote("DocInfo-2"); |
| 1382 |
ascii().addPos(pos+200); |
| 1383 |
ascii().addNote("DocInfo-3"); |
| 1384 |
ascii().addPos(pos+300); |
| 1385 |
ascii().addNote("DocInfo-4"); |
| 1386 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1387 |
return true; |
| 1388 |
} |
| 1389 |
|
| 1390 |
//////////////////////////////////////////////////////////// |
| 1391 |
// try to read the print info zone |
| 1392 |
//////////////////////////////////////////////////////////// |
| 1393 |
bool ClarisDrawParser::readPrintInfo() |
| 1394 |
{ |
| 1395 |
MWAWInputStreamPtr input = getInput(); |
| 1396 |
long pos=input->tell(); |
| 1397 |
long endPos=pos+124; |
| 1398 |
if (input->readULong(4)!=120 || !input->checkPosition(endPos)) { |
| 1399 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readPrintInfo: file seems too short\n")); |
| 1400 |
return false; |
| 1401 |
} |
| 1402 |
libmwaw::DebugStream f; |
| 1403 |
f << "Entries(PrintInfo):"; |
| 1404 |
libmwaw::PrinterInfo info; |
| 1405 |
if (!info.read(input)) { |
| 1406 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readPrintInfo: can not read print info\n")); |
| 1407 |
return false; |
| 1408 |
} |
| 1409 |
f << info; |
| 1410 |
MWAWVec2i paperSize = info.paper().size(); |
| 1411 |
MWAWVec2i pageSize = info.page().size(); |
| 1412 |
if (pageSize.x() <= 0 || pageSize.y() <= 0 || |
| 1413 |
paperSize.x() <= 0 || paperSize.y() <= 0) { |
| 1414 |
ascii().addPos(pos); |
| 1415 |
ascii().addNote(f.str().c_str()); |
| 1416 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1417 |
return true; |
| 1418 |
} |
| 1419 |
|
| 1420 |
// define margin from print info |
| 1421 |
MWAWVec2i lTopMargin= -1 * info.paper().pos(0); |
| 1422 |
MWAWVec2i rBotMargin=info.paper().size() - info.page().size(); |
| 1423 |
|
| 1424 |
// move margin left | top |
| 1425 |
int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0; |
| 1426 |
int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0; |
| 1427 |
lTopMargin -= MWAWVec2i(decalX, decalY); |
| 1428 |
rBotMargin += MWAWVec2i(decalX, decalY); |
| 1429 |
|
| 1430 |
// decrease right | bottom |
| 1431 |
int rightMarg = rBotMargin.x() -50; |
| 1432 |
if (rightMarg < 0) rightMarg=0; |
| 1433 |
int botMarg = rBotMargin.y() -50; |
| 1434 |
if (botMarg < 0) botMarg=0; |
| 1435 |
|
| 1436 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 1437 |
getPageSpan().setMarginBottom(botMarg/72.0); |
| 1438 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 1439 |
getPageSpan().setMarginRight(rightMarg/72.0); |
| 1440 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 1441 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 1442 |
|
| 1443 |
ascii().addPos(pos); |
| 1444 |
ascii().addNote(f.str().c_str()); |
| 1445 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1446 |
return true; |
| 1447 |
} |
| 1448 |
|
| 1449 |
//////////////////////////////////////////////////////////// |
| 1450 |
// read the document main part |
| 1451 |
//////////////////////////////////////////////////////////// |
| 1452 |
std::shared_ptr<ClarisWksStruct::DSET> ClarisDrawParser::readDSET(bool isLibHeader) |
| 1453 |
{ |
| 1454 |
MWAWInputStreamPtr input = getInput(); |
| 1455 |
long pos = input->tell(); |
| 1456 |
libmwaw::DebugStream f; |
| 1457 |
libmwaw::DebugFile &ascFile=ascii(); |
| 1458 |
if (input->readULong(4) != 0x44534554L) |
| 1459 |
return std::shared_ptr<ClarisWksStruct::DSET>(); |
| 1460 |
auto sz = long(input->readULong(4)); |
| 1461 |
MWAWEntry entry; |
| 1462 |
entry.setBegin(pos); |
| 1463 |
entry.setLength(sz+8); |
| 1464 |
|
| 1465 |
long endPos = entry.end(); |
| 1466 |
if (sz<16 || !input->checkPosition(entry.end())) { |
| 1467 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDSET: file is too short\n")); |
| 1468 |
return std::shared_ptr<ClarisWksStruct::DSET>(); |
| 1469 |
} |
| 1470 |
|
| 1471 |
ClarisWksStruct::DSET dset; |
| 1472 |
dset.m_size = sz; |
| 1473 |
dset.m_numData = static_cast<int>(input->readULong(2)); |
| 1474 |
|
| 1475 |
input->seek(10, librevenge::RVNG_SEEK_CUR); |
| 1476 |
dset.m_fileType = static_cast<int>(input->readULong(1)); |
| 1477 |
input->seek(-11, librevenge::RVNG_SEEK_CUR); |
| 1478 |
int nFlags = 0; |
| 1479 |
switch (dset.m_fileType) { |
| 1480 |
case 1: // text |
| 1481 |
dset.m_beginSelection = static_cast<int>(input->readLong(4)); |
| 1482 |
dset.m_endSelection = static_cast<int>(input->readLong(4)); |
| 1483 |
dset.m_textType = static_cast<int>(input->readULong(1)); |
| 1484 |
dset.m_flags[nFlags++] = static_cast<int>(input->readLong(1)); |
| 1485 |
dset.m_headerSz = 44; |
| 1486 |
dset.m_dataSz = 28; |
| 1487 |
break; |
| 1488 |
default: |
| 1489 |
dset.m_flags[nFlags++] = static_cast<int>(input->readLong(2)); // normally -1 |
| 1490 |
dset.m_flags[nFlags++] = static_cast<int>(input->readLong(2)); // the 0 |
| 1491 |
dset.m_dataSz = static_cast<int>(input->readULong(2)); |
| 1492 |
dset.m_headerSz = static_cast<int>(input->readULong(2)); |
| 1493 |
dset.m_flags[nFlags++] = static_cast<int>(input->readLong(2)); |
| 1494 |
break; |
| 1495 |
} |
| 1496 |
dset.m_flags[nFlags++] = static_cast<int>(input->readLong(2)); |
| 1497 |
dset.m_id = static_cast<int>(input->readULong(2)); |
| 1498 |
std::shared_ptr<ClarisWksStruct::DSET> zone; |
| 1499 |
switch (dset.m_fileType) { |
| 1500 |
case 0: |
| 1501 |
zone=m_graphParser->readGroupZone(dset, entry, isLibHeader); |
| 1502 |
break; |
| 1503 |
case 1: |
| 1504 |
zone=m_textParser->readDSETZone(dset, entry); |
| 1505 |
break; |
| 1506 |
case 4: |
| 1507 |
zone=m_graphParser->readBitmapZone(dset, entry); |
| 1508 |
break; |
| 1509 |
default: |
| 1510 |
break; |
| 1511 |
} |
| 1512 |
if (!zone) { |
| 1513 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDSET: find unexpected type\n")); |
| 1514 |
zone.reset(new ClarisWksStruct::DSET(dset)); |
| 1515 |
f << "Entries(DSETU): " << *zone; |
| 1516 |
|
| 1517 |
auto data0Length = static_cast<int>(zone->m_dataSz); |
| 1518 |
auto N = static_cast<int>(zone->m_numData); |
| 1519 |
|
| 1520 |
ascFile.addDelimiter(input->tell(), '|'); |
| 1521 |
ascFile.addPos(pos); |
| 1522 |
ascFile.addNote(f.str().c_str()); |
| 1523 |
|
| 1524 |
const long dataSz = sz-12-zone->m_headerSz; |
| 1525 |
if ((dataSz && (data0Length<=0 || (dataSz/data0Length)!=N || (dataSz%data0Length)!=0)) || (!dataSz && N)) { |
| 1526 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDSET: unexpected size for zone definition, try to continue\n")); |
| 1527 |
ascFile.addPos(pos); |
| 1528 |
ascFile.addNote("###"); |
| 1529 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1530 |
return zone; |
| 1531 |
} |
| 1532 |
|
| 1533 |
long debPos = endPos-N*data0Length; |
| 1534 |
for (long i = 0; i < zone->m_numData; i++) { |
| 1535 |
input->seek(debPos, librevenge::RVNG_SEEK_SET); |
| 1536 |
f.str(""); |
| 1537 |
f << "DSETU-" << i << ":"; |
| 1538 |
|
| 1539 |
long actPos = input->tell(); |
| 1540 |
if (actPos != debPos && actPos != debPos+data0Length) |
| 1541 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1542 |
ascFile.addPos(debPos); |
| 1543 |
ascFile.addNote(f.str().c_str()); |
| 1544 |
debPos += data0Length; |
| 1545 |
} |
| 1546 |
|
| 1547 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1548 |
} |
| 1549 |
|
| 1550 |
if (m_state->m_zonesMap.find(zone->m_id) != m_state->m_zonesMap.end()) { |
| 1551 |
MWAW_DEBUG_MSG(("ClarisDrawParser::readDSET: zone %d already exists!!!!\n", |
| 1552 |
zone->m_id)); |
| 1553 |
} |
| 1554 |
else { |
| 1555 |
m_state->m_zonesMap[zone->m_id] = zone; |
| 1556 |
m_state->m_zoneIdToFileTypeMap[zone->m_id] = dset.m_fileType; |
| 1557 |
} |
| 1558 |
return zone; |
| 1559 |
} |
| 1560 |
|
| 1561 |
//////////////////////////////////////////////////////////// |
| 1562 |
// |
| 1563 |
// send data |
| 1564 |
// |
| 1565 |
//////////////////////////////////////////////////////////// |
| 1566 |
|
| 1567 |
|
| 1568 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |