| 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 <map> |
| 39 |
#include <set> |
| 40 |
#include <sstream> |
| 41 |
#include <stack> |
| 42 |
|
| 43 |
#include <librevenge/librevenge.h> |
| 44 |
|
| 45 |
#include "MWAWFont.hxx" |
| 46 |
#include "MWAWFontConverter.hxx" |
| 47 |
#include "MWAWListener.hxx" |
| 48 |
#include "MWAWParagraph.hxx" |
| 49 |
#include "MWAWPosition.hxx" |
| 50 |
#include "MWAWSubDocument.hxx" |
| 51 |
|
| 52 |
#include "RagTime5ClusterManager.hxx" |
| 53 |
#include "RagTime5Document.hxx" |
| 54 |
#include "RagTime5StructManager.hxx" |
| 55 |
#include "RagTime5StyleManager.hxx" |
| 56 |
|
| 57 |
#include "RagTime5Layout.hxx" |
| 58 |
|
| 59 |
#include "libmwaw_internal.hxx" |
| 60 |
|
| 61 |
/** Internal: the structures of a RagTime5Layout */ |
| 62 |
namespace RagTime5LayoutInternal |
| 63 |
{ |
| 64 |
//! the layout cluster ( 4001 zone) |
| 65 |
struct ClusterLayout final : public RagTime5ClusterManager::Cluster { |
| 66 |
//! constructor |
| 67 |
ClusterLayout() |
| 68 |
: Cluster(C_Layout) |
| 69 |
, m_pageList() |
| 70 |
, m_pageNameLink() |
| 71 |
, m_pipelineLink() |
| 72 |
, m_pageDataLink() |
| 73 |
, m_childIdSet() |
| 74 |
, m_numChild(0) |
| 75 |
, m_numMasterChild(0) |
| 76 |
{ |
| 77 |
} |
| 78 |
//! destructor |
| 79 |
~ClusterLayout() final; |
| 80 |
|
| 81 |
//! a zone of in a layout |
| 82 |
struct Zone { |
| 83 |
//! constructor |
| 84 |
Zone() |
| 85 |
: m_mainId(0) |
| 86 |
, m_masterId(0) |
| 87 |
, m_dimension() |
| 88 |
{ |
| 89 |
} |
| 90 |
//! the main zone id |
| 91 |
int m_mainId; |
| 92 |
//! the master zone id or 0 |
| 93 |
int m_masterId; |
| 94 |
//! the dimension |
| 95 |
MWAWVec2f m_dimension; |
| 96 |
}; |
| 97 |
|
| 98 |
//! list of zone's |
| 99 |
std::vector<Zone> m_pageList; |
| 100 |
//! the name link for page? |
| 101 |
RagTime5ClusterManager::NameLink m_pageNameLink; |
| 102 |
//! link to a pipeline cluster list |
| 103 |
RagTime5ClusterManager::Link m_pipelineLink; |
| 104 |
//! link to a zone of fieldSize 8(unknown) |
| 105 |
RagTime5ClusterManager::Link m_pageDataLink; |
| 106 |
//! list of child id |
| 107 |
std::set<int> m_childIdSet; |
| 108 |
//! the number of classic child |
| 109 |
int m_numChild; |
| 110 |
//! the number of master child |
| 111 |
int m_numMasterChild; |
| 112 |
}; |
| 113 |
|
| 114 |
ClusterLayout::~ClusterLayout() |
| 115 |
{ |
| 116 |
} |
| 117 |
|
| 118 |
//////////////////////////////////////// |
| 119 |
//! Internal: the state of a RagTime5Layout |
| 120 |
struct State { |
| 121 |
//! constructor |
| 122 |
State() |
| 123 |
: m_numPages(-1) |
| 124 |
, m_idLayoutMap() |
| 125 |
, m_masterIdSet() |
| 126 |
, m_layoutIdToSendList() |
| 127 |
{ |
| 128 |
} |
| 129 |
//! the number of pages |
| 130 |
int m_numPages; |
| 131 |
//! map data id to text zone |
| 132 |
std::map<int, std::shared_ptr<ClusterLayout> > m_idLayoutMap; |
| 133 |
//! the list of master id |
| 134 |
std::set<int> m_masterIdSet; |
| 135 |
//! the list of layout to send |
| 136 |
std::vector<int> m_layoutIdToSendList; |
| 137 |
}; |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
//////////////////////////////////////////////////////////// |
| 142 |
// constructor/destructor, ... |
| 143 |
//////////////////////////////////////////////////////////// |
| 144 |
RagTime5Layout::RagTime5Layout(RagTime5Document &doc) |
| 145 |
: m_document(doc) |
| 146 |
, m_structManager(m_document.getStructManager()) |
| 147 |
, m_parserState(doc.getParserState()) |
| 148 |
, m_state(new RagTime5LayoutInternal::State) |
| 149 |
{ |
| 150 |
} |
| 151 |
|
| 152 |
RagTime5Layout::~RagTime5Layout() |
| 153 |
{ |
| 154 |
} |
| 155 |
|
| 156 |
int RagTime5Layout::version() const |
| 157 |
{ |
| 158 |
return m_parserState->m_version; |
| 159 |
} |
| 160 |
|
| 161 |
int RagTime5Layout::numPages() const |
| 162 |
{ |
| 163 |
if (m_state->m_numPages<0) |
| 164 |
const_cast<RagTime5Layout *>(this)->updateLayouts(); |
| 165 |
return m_state->m_numPages; |
| 166 |
} |
| 167 |
|
| 168 |
bool RagTime5Layout::sendPageContents() |
| 169 |
{ |
| 170 |
int page=0; |
| 171 |
for (size_t i=0; i<m_state->m_layoutIdToSendList.size(); ++i) { |
| 172 |
int lId=m_state->m_layoutIdToSendList[i]; |
| 173 |
if (m_state->m_idLayoutMap.find(lId)==m_state->m_idLayoutMap.end() || !m_state->m_idLayoutMap.find(lId)->second) { |
| 174 |
MWAW_DEBUG_MSG(("RagTime5Layout::sendPageContents: can not find layout %d\n", lId)); |
| 175 |
continue; |
| 176 |
} |
| 177 |
auto &layout=*m_state->m_idLayoutMap.find(lId)->second; |
| 178 |
layout.m_isSent=true; |
| 179 |
for (auto &zone : layout.m_pageList) { |
| 180 |
MWAWPosition position(MWAWVec2f(0,0), MWAWVec2f(100,100), librevenge::RVNG_POINT); |
| 181 |
position.m_anchorTo=MWAWPosition::Page; |
| 182 |
position.setPage(++page); |
| 183 |
if (zone.m_masterId) { |
| 184 |
if (m_state->m_idLayoutMap.find(zone.m_masterId)==m_state->m_idLayoutMap.end() || !m_state->m_idLayoutMap.find(zone.m_masterId)->second) { |
| 185 |
MWAW_DEBUG_MSG(("RagTime5Layout::sendPageContents: can not find layout %d\n", zone.m_masterId)); |
| 186 |
} |
| 187 |
else { |
| 188 |
auto &master=*m_state->m_idLayoutMap.find(zone.m_masterId)->second; |
| 189 |
int cId=0; |
| 190 |
size_t n=layout.m_pageList.size(); |
| 191 |
if (master.m_pageList.size()==1) |
| 192 |
cId=master.m_pageList[0].m_mainId; |
| 193 |
else if (n<master.m_pageList.size()) |
| 194 |
cId=master.m_pageList[n].m_mainId; |
| 195 |
if (cId) |
| 196 |
m_document.send(cId, MWAWListenerPtr(), position); |
| 197 |
} |
| 198 |
} |
| 199 |
if (zone.m_mainId) |
| 200 |
m_document.send(zone.m_mainId, MWAWListenerPtr(), position); |
| 201 |
} |
| 202 |
} |
| 203 |
return true; |
| 204 |
} |
| 205 |
|
| 206 |
//////////////////////////////////////////////////////////// |
| 207 |
// |
| 208 |
// Intermediate level |
| 209 |
// |
| 210 |
//////////////////////////////////////////////////////////// |
| 211 |
void RagTime5Layout::updateLayouts() |
| 212 |
{ |
| 213 |
for (auto const &it : m_state->m_idLayoutMap) { |
| 214 |
if (!it.second) continue; |
| 215 |
updateLayout(*it.second); |
| 216 |
} |
| 217 |
// look for no master layout |
| 218 |
int nPages=0; |
| 219 |
std::multimap<int,int> numZonesToLayout; |
| 220 |
for (auto const &it : m_state->m_idLayoutMap) { |
| 221 |
if (!it.second || it.second->m_pageList.empty() || m_state->m_masterIdSet.find(it.first)!=m_state->m_masterIdSet.end()) { |
| 222 |
if (it.second) |
| 223 |
it.second->m_isSent=true; |
| 224 |
continue; |
| 225 |
} |
| 226 |
numZonesToLayout.insert(std::multimap<int,int>::value_type(it.second->m_numChild,it.first)); |
| 227 |
nPages+=static_cast<int>(it.second->m_pageList.size()); |
| 228 |
} |
| 229 |
m_state->m_numPages=nPages; |
| 230 |
|
| 231 |
for (auto lIt=numZonesToLayout.rbegin(); lIt!=numZonesToLayout.rend(); ++lIt) |
| 232 |
m_state->m_layoutIdToSendList.push_back(lIt->second); |
| 233 |
} |
| 234 |
|
| 235 |
void RagTime5Layout::updateLayout(RagTime5LayoutInternal::ClusterLayout &layout) |
| 236 |
{ |
| 237 |
int numChild=0, numMasterChild=0; |
| 238 |
for (auto &zone : layout.m_pageList) { |
| 239 |
if (zone.m_mainId) { |
| 240 |
if (m_document.getClusterType(zone.m_mainId)==RagTime5ClusterManager::Cluster::C_GraphicZone) |
| 241 |
++numChild; |
| 242 |
else { |
| 243 |
MWAW_DEBUG_MSG(("RagTime5Layout::updateLayout: find unexpected type for cluster %d\n", zone.m_mainId)); |
| 244 |
zone.m_mainId=0; |
| 245 |
} |
| 246 |
} |
| 247 |
if (zone.m_masterId) { |
| 248 |
if (m_document.getClusterType(zone.m_masterId)==RagTime5ClusterManager::Cluster::C_Layout) { |
| 249 |
m_state->m_masterIdSet.insert(zone.m_masterId); |
| 250 |
++numMasterChild; |
| 251 |
} |
| 252 |
else { |
| 253 |
MWAW_DEBUG_MSG(("RagTime5Layout::updateLayout: find unexpected type for cluster %d\n", zone.m_masterId)); |
| 254 |
zone.m_masterId=0; |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
layout.m_numChild=numChild; |
| 259 |
layout.m_numMasterChild=numMasterChild; |
| 260 |
} |
| 261 |
|
| 262 |
|
| 263 |
//////////////////////////////////////////////////////////// |
| 264 |
// |
| 265 |
// Low level |
| 266 |
// |
| 267 |
//////////////////////////////////////////////////////////// |
| 268 |
|
| 269 |
//////////////////////////////////////////////////////////// |
| 270 |
// interface send function |
| 271 |
//////////////////////////////////////////////////////////// |
| 272 |
void RagTime5Layout::flushExtra() |
| 273 |
{ |
| 274 |
MWAW_DEBUG_MSG(("RagTime5Layout::flushExtra: not implemented\n")); |
| 275 |
} |
| 276 |
|
| 277 |
bool RagTime5Layout::send(RagTime5LayoutInternal::ClusterLayout &/*cluster*/, MWAWListenerPtr listener, int /*page*/) |
| 278 |
{ |
| 279 |
if (!listener) |
| 280 |
listener=m_parserState->getMainListener(); |
| 281 |
if (!listener) { |
| 282 |
MWAW_DEBUG_MSG(("RagTime5Layout::send: can not find the listener\n")); |
| 283 |
return false; |
| 284 |
} |
| 285 |
static bool first=true; |
| 286 |
if (first) { |
| 287 |
first=false; |
| 288 |
MWAW_DEBUG_MSG(("RagTime5Layout::send: sorry not implemented\n")); |
| 289 |
} |
| 290 |
return true; |
| 291 |
} |
| 292 |
|
| 293 |
//////////////////////////////////////////////////////////// |
| 294 |
// cluster parser |
| 295 |
//////////////////////////////////////////////////////////// |
| 296 |
|
| 297 |
namespace RagTime5LayoutInternal |
| 298 |
{ |
| 299 |
//! Internal: the helper to read a clustList |
| 300 |
struct ClustListParser final : public RagTime5StructManager::DataParser { |
| 301 |
//! constructor |
| 302 |
ClustListParser(RagTime5ClusterManager &clusterManager, int fieldSize, std::string const &zoneName) |
| 303 |
: RagTime5StructManager::DataParser(zoneName) |
| 304 |
, m_fieldSize(fieldSize) |
| 305 |
, m_linkList() |
| 306 |
, m_clusterManager(clusterManager) |
| 307 |
{ |
| 308 |
if (m_fieldSize<4) { |
| 309 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::ClustListParser: bad field size\n")); |
| 310 |
m_fieldSize=0; |
| 311 |
} |
| 312 |
} |
| 313 |
//! destructor |
| 314 |
~ClustListParser() final; |
| 315 |
//! returns the not null list dataId list |
| 316 |
std::vector<int> getIdList() const |
| 317 |
{ |
| 318 |
std::vector<int> res; |
| 319 |
for (auto const &lnk : m_linkList) { |
| 320 |
if (lnk.m_dataId>0) |
| 321 |
res.push_back(lnk.m_dataId); |
| 322 |
} |
| 323 |
return res; |
| 324 |
} |
| 325 |
//! return the cluster name |
| 326 |
std::string getClusterDebugName(int id) const |
| 327 |
{ |
| 328 |
return m_clusterManager.getClusterDebugName(id); |
| 329 |
} |
| 330 |
|
| 331 |
//! try to parse a data |
| 332 |
bool parseData(MWAWInputStreamPtr &input, long endPos, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f) final |
| 333 |
{ |
| 334 |
long pos=input->tell(); |
| 335 |
if (endPos-pos!=m_fieldSize) { |
| 336 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::ClustListParser::parse: bad data size\n")); |
| 337 |
return false; |
| 338 |
} |
| 339 |
std::vector<int> listIds; |
| 340 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 341 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::ClustListParser::parse: can not read an cluster id\n")); |
| 342 |
f << "##clusterIds,"; |
| 343 |
return false; |
| 344 |
} |
| 345 |
RagTime5StructManager::ZoneLink link; |
| 346 |
link.m_dataId=listIds[0]; |
| 347 |
if (listIds[0]) |
| 348 |
f << getClusterDebugName(listIds[0]) << ","; |
| 349 |
f << link; |
| 350 |
m_linkList.push_back(link); |
| 351 |
return true; |
| 352 |
} |
| 353 |
|
| 354 |
//! the field size |
| 355 |
int m_fieldSize; |
| 356 |
//! the list of read cluster |
| 357 |
std::vector<RagTime5StructManager::ZoneLink> m_linkList; |
| 358 |
private: |
| 359 |
//! the main zone manager |
| 360 |
RagTime5ClusterManager &m_clusterManager; |
| 361 |
//! copy constructor, not implemented |
| 362 |
ClustListParser(ClustListParser &orig) = delete; |
| 363 |
//! copy operator, not implemented |
| 364 |
ClustListParser &operator=(ClustListParser &orig) = delete; |
| 365 |
}; |
| 366 |
|
| 367 |
ClustListParser::~ClustListParser() |
| 368 |
{ |
| 369 |
} |
| 370 |
|
| 371 |
//! Internal: the helper to read a extra page data |
| 372 |
struct PageDataParser final : public RagTime5StructManager::DataParser { |
| 373 |
//! constructor |
| 374 |
PageDataParser(int fieldSize, std::string const &zoneName) |
| 375 |
: RagTime5StructManager::DataParser(zoneName) |
| 376 |
, m_fieldSize(fieldSize) |
| 377 |
{ |
| 378 |
if (m_fieldSize<8) { |
| 379 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::PageDataParser: bad field size\n")); |
| 380 |
m_fieldSize=0; |
| 381 |
} |
| 382 |
} |
| 383 |
//! destructor |
| 384 |
~PageDataParser() final; |
| 385 |
//! try to parse a data |
| 386 |
bool parseData(MWAWInputStreamPtr &input, long endPos, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f) final |
| 387 |
{ |
| 388 |
long pos=input->tell(); |
| 389 |
if (endPos-pos!=m_fieldSize) { |
| 390 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::PageDataParser::parse: bad data size\n")); |
| 391 |
return false; |
| 392 |
} |
| 393 |
auto val=input->readLong(4); |
| 394 |
f << "id1=" << val << ","; |
| 395 |
for (int i=0; i<2; ++i) { // f0=0|4|8|a, f1: the page number? |
| 396 |
val=input->readLong(2); |
| 397 |
if (val) f << "f" << i << "=" << val << ","; |
| 398 |
} |
| 399 |
return true; |
| 400 |
} |
| 401 |
|
| 402 |
//! the field size |
| 403 |
int m_fieldSize; |
| 404 |
private: |
| 405 |
//! copy constructor, not implemented |
| 406 |
PageDataParser(PageDataParser &orig) = delete; |
| 407 |
//! copy operator, not implemented |
| 408 |
PageDataParser &operator=(PageDataParser &orig) = delete; |
| 409 |
}; |
| 410 |
|
| 411 |
PageDataParser::~PageDataParser() |
| 412 |
{ |
| 413 |
} |
| 414 |
|
| 415 |
// |
| 416 |
//! low level: parser of layout cluster |
| 417 |
// |
| 418 |
struct LayoutCParser final : public RagTime5ClusterManager::ClusterParser { |
| 419 |
enum { F_page, F_pageData0, F_pageData1, F_pageData2, F_pipeline, F_name, F_nextId=F_name+3, F_settingsDef, F_settings}; |
| 420 |
//! constructor |
| 421 |
LayoutCParser(RagTime5ClusterManager &parser, int zoneType) |
| 422 |
: ClusterParser(parser, zoneType, "ClustLayout"), m_cluster(new ClusterLayout) |
| 423 |
, m_numPages(0) |
| 424 |
, m_what(-1) |
| 425 |
, m_linkId(-1) |
| 426 |
, m_fieldName("") |
| 427 |
|
| 428 |
, m_actualZone() |
| 429 |
|
| 430 |
, m_expectedIdToType() |
| 431 |
, m_idStack() |
| 432 |
{ |
| 433 |
} |
| 434 |
//! destructor |
| 435 |
~LayoutCParser() final; |
| 436 |
//! return the current cluster |
| 437 |
std::shared_ptr<RagTime5ClusterManager::Cluster> getCluster() final |
| 438 |
{ |
| 439 |
return m_cluster; |
| 440 |
} |
| 441 |
//! return the current layout cluster |
| 442 |
std::shared_ptr<ClusterLayout> getLayoutCluster() |
| 443 |
{ |
| 444 |
return m_cluster; |
| 445 |
} |
| 446 |
//! set a data id type |
| 447 |
void setExpectedType(int id, int type) |
| 448 |
{ |
| 449 |
m_expectedIdToType[id]=type; |
| 450 |
m_idStack.push(id); |
| 451 |
} |
| 452 |
/** returns to new zone to parse. -1: means no preference, 0: means first zone, ... */ |
| 453 |
int getNewZoneToParse() final |
| 454 |
{ |
| 455 |
if (m_idStack.empty()) |
| 456 |
return -1; |
| 457 |
int id=m_idStack.top(); |
| 458 |
m_idStack.pop(); |
| 459 |
return id; |
| 460 |
} |
| 461 |
//! start a new zone |
| 462 |
void startZone() final |
| 463 |
{ |
| 464 |
if (m_what<=0) |
| 465 |
++m_what; |
| 466 |
else if (m_what==1) { |
| 467 |
if (m_dataId>=m_numPages+1) |
| 468 |
++m_what; |
| 469 |
m_actualZone=ClusterLayout::Zone(); |
| 470 |
} |
| 471 |
} |
| 472 |
//! end of a start zone call |
| 473 |
void endZone() final |
| 474 |
{ |
| 475 |
if (m_link.empty()) |
| 476 |
return; |
| 477 |
switch (m_linkId) { |
| 478 |
case 0: |
| 479 |
m_cluster->m_pageDataLink=m_link; |
| 480 |
break; |
| 481 |
case 1: |
| 482 |
m_cluster->m_pipelineLink=m_link; |
| 483 |
break; |
| 484 |
case 2: |
| 485 |
m_cluster->m_settingLinks.push_back(m_link); |
| 486 |
break; |
| 487 |
case 3: |
| 488 |
if (m_cluster->m_pageNameLink.empty()) |
| 489 |
m_cluster->m_pageNameLink=RagTime5ClusterManager::NameLink(m_link); |
| 490 |
else { |
| 491 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::endZone: oops the name link is already set\n")); |
| 492 |
m_cluster->m_linksList.push_back(m_link); |
| 493 |
} |
| 494 |
break; |
| 495 |
default: |
| 496 |
m_cluster->m_linksList.push_back(m_link); |
| 497 |
break; |
| 498 |
} |
| 499 |
} |
| 500 |
//! parse a zone |
| 501 |
bool parseZone(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) final |
| 502 |
{ |
| 503 |
m_fieldName=""; |
| 504 |
m_linkId=-1; |
| 505 |
m_link.m_N=N; |
| 506 |
if (m_dataId==0) |
| 507 |
return parseHeaderZone(input,fSz,N,flag,f); |
| 508 |
auto const &it=m_expectedIdToType.find(m_dataId); |
| 509 |
int expected=(it!=m_expectedIdToType.end())?it->second : -1; |
| 510 |
if (expected!=-1) |
| 511 |
f << "[F" << m_dataId << "]"; |
| 512 |
int val; |
| 513 |
switch (expected) { |
| 514 |
case F_name: |
| 515 |
case F_name+1: |
| 516 |
case F_name+2: |
| 517 |
case F_pageData0: |
| 518 |
case F_pipeline: |
| 519 |
case F_settings: |
| 520 |
case F_settings+1: |
| 521 |
case F_settings+2: { |
| 522 |
std::string mess; |
| 523 |
long linkValues[4]; |
| 524 |
if (fSz<28 || !readLinkHeader(input, fSz, m_link, linkValues, mess)) { |
| 525 |
f << "###fType=" << RagTime5Layout::printType(m_link.m_fileType[0]) << ","; |
| 526 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 527 |
return true; |
| 528 |
} |
| 529 |
f << m_link << "," << mess; |
| 530 |
m_what=4; |
| 531 |
long expectedFileType1=0; |
| 532 |
if ((expected==F_name || expected==F_settings) && m_link.m_fileType[0]==0x3e800) |
| 533 |
m_link.m_name=expected==F_settings ? "settingsList0" : "unicodeList0"; |
| 534 |
else if ((expected==F_name+1 || expected==F_settings+1) && m_link.m_fileType[0]==0x35800) |
| 535 |
m_link.m_name=expected==F_settings+1 ? "settingsList1" : "unicodeList1"; |
| 536 |
else if (expected==F_name+2 && m_link.m_fileType[0]==0) { // fSz==32 |
| 537 |
expectedFileType1=0x200; |
| 538 |
m_linkId=3; |
| 539 |
m_link.m_name="unicodeNames"; |
| 540 |
} |
| 541 |
else if (expected==F_settings+2 && m_link.m_fileType[0]==0x47040) { |
| 542 |
m_linkId=2; |
| 543 |
m_link.m_name="settings"; |
| 544 |
} |
| 545 |
else if (expected==F_pageData0 && m_link.m_fileType[0]==0x14b9800) { // fSz=30 |
| 546 |
m_linkId=0; |
| 547 |
m_what=3; |
| 548 |
m_link.m_name="layoutPageData0"; |
| 549 |
expectedFileType1=0x10; |
| 550 |
} |
| 551 |
else if (expected==F_pipeline && m_link.m_fileType[0]==0) { // fSz=30 |
| 552 |
m_linkId=1; |
| 553 |
m_link.m_name="pipeline"; |
| 554 |
} |
| 555 |
else { |
| 556 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 557 |
f << "###"; |
| 558 |
} |
| 559 |
if (!m_link.m_name.empty()) { |
| 560 |
m_fieldName=m_link.m_name; |
| 561 |
f << m_link.m_name << ","; |
| 562 |
} |
| 563 |
if (expected==F_name||expected==F_name+1) |
| 564 |
m_cluster->m_pageNameLink.m_posToNamesLinks[expected-F_name]=m_link; |
| 565 |
if (expectedFileType1>0 && long(m_link.m_fileType[1]&0xFFD7)!=expectedFileType1) { |
| 566 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the expected field[%d] fileType1 seems odd\n", expected)); |
| 567 |
f << "###fileType1=" << std::hex << m_link.m_fileType[1] << std::dec << ","; |
| 568 |
} |
| 569 |
return true; |
| 570 |
} |
| 571 |
case F_page: |
| 572 |
return parsePageZone(input,fSz,N,flag,f); |
| 573 |
case F_pageData1: { |
| 574 |
if (fSz<54) { |
| 575 |
f << "###fSz,"; |
| 576 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 577 |
return true; |
| 578 |
} |
| 579 |
m_fieldName="layoutPageData1"; |
| 580 |
f << m_fieldName << ","; |
| 581 |
for (int i=0; i<2; ++i) { // always 0 |
| 582 |
val=static_cast<int>(input->readLong(2)); |
| 583 |
if (val) f << "f" << i << "=" << val << ","; |
| 584 |
} |
| 585 |
float dim[2]; |
| 586 |
for (auto &d : dim) d=float(input->readLong(4))/65536.f; |
| 587 |
f << "sz=" << MWAWVec2f(dim[0],dim[1]) << ","; |
| 588 |
|
| 589 |
std::vector<int> listIds; |
| 590 |
long actPos=input->tell(); |
| 591 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 592 |
f << "###cluster1,"; |
| 593 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: can not read cluster block[fSz=54]\n")); |
| 594 |
input->seek(actPos+4, librevenge::RVNG_SEEK_SET); |
| 595 |
} |
| 596 |
else if (listIds[0]) { // link to the new cluster e zone ? (can be also 0) |
| 597 |
m_cluster->m_clusterIdsList.push_back(listIds[0]); |
| 598 |
f << "cluster0=" << getClusterDebugName(listIds[0]) << ","; |
| 599 |
} |
| 600 |
for (int i=0; i<7; ++i) { // always 0 |
| 601 |
val=static_cast<int>(input->readLong(2)); |
| 602 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 603 |
} |
| 604 |
for (int i=0; i<9; ++i) { // g0=1, g1=1-7, g2=0-d, g3=0-1, g8=2-8 |
| 605 |
val=static_cast<int>(input->readLong(2)); |
| 606 |
if (val) f << "g" << i << "=" << val << ","; |
| 607 |
} |
| 608 |
return true; |
| 609 |
} |
| 610 |
case F_pageData2: { // unsure |
| 611 |
if (fSz<60) { |
| 612 |
f << "###fSz,"; |
| 613 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 614 |
return true; |
| 615 |
} |
| 616 |
m_fieldName="data2"; |
| 617 |
m_what=5; |
| 618 |
for (int i=0; i<4; ++i) { // f3=1 |
| 619 |
val=static_cast<int>(input->readLong(2)); |
| 620 |
if (val) f << "f" << i << "=" << val << ","; |
| 621 |
} |
| 622 |
val=static_cast<int>(input->readLong(4)); // 0/72cc/b840 |
| 623 |
if (val) f << "f4=" << std::hex << val << std::dec << ","; |
| 624 |
auto type=input->readULong(4); |
| 625 |
if (type!=0x14b6842) { |
| 626 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: find unexpected filetype[fSz=60]\n")); |
| 627 |
f << "#fileType1=" << RagTime5Layout::printType(type) << ","; |
| 628 |
} |
| 629 |
for (int i=0; i<7; ++i) { // g4=g6=1 |
| 630 |
val=static_cast<int>(input->readLong(2)); |
| 631 |
if (val) f << "g" << i << "=" << val << ","; |
| 632 |
} |
| 633 |
type=input->readULong(4); |
| 634 |
if (type!=0x35800) { // maybe a link here |
| 635 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: find unexpected filetype2[fSz=60]\n")); |
| 636 |
f << "#fileType2=" << RagTime5Layout::printType(type) << ","; |
| 637 |
} |
| 638 |
for (int i=0; i<4; ++i) { // 0 |
| 639 |
val=static_cast<int>(input->readLong(2)); |
| 640 |
if (val) f << "h" << i << "=" << val << ","; |
| 641 |
} |
| 642 |
type=input->readULong(4); |
| 643 |
if (type!=0x14b4817) { |
| 644 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: find unexpected filetype3[fSz=60]\n")); |
| 645 |
f << "#fileType3=" << RagTime5Layout::printType(type) << ","; |
| 646 |
} |
| 647 |
for (int i=0; i<4; ++i) { // h4=47 |
| 648 |
val=static_cast<int>(input->readLong(2)); |
| 649 |
if (val) f << "h" << i+4 << "=" << val << ","; |
| 650 |
} |
| 651 |
return true; |
| 652 |
} |
| 653 |
case F_settingsDef: // ok, but there are some that we do not find automatically |
| 654 |
if (fSz!=38) { |
| 655 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: unexpected settings def\n")); |
| 656 |
f << "###,"; |
| 657 |
} |
| 658 |
break; |
| 659 |
case F_nextId: |
| 660 |
default: |
| 661 |
break; |
| 662 |
} |
| 663 |
m_what=2; |
| 664 |
|
| 665 |
if (N<0) { |
| 666 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: N value seems bad\n")); |
| 667 |
f << "###N=" << N << ","; |
| 668 |
return true; |
| 669 |
} |
| 670 |
if (expected==-1) { |
| 671 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: unexpected field\n")); |
| 672 |
f << "###"; |
| 673 |
} |
| 674 |
switch (fSz) { |
| 675 |
case 29: { |
| 676 |
// checkme find where is stored next[id] |
| 677 |
std::string mess; |
| 678 |
long linkValues[4]; |
| 679 |
if (!readLinkHeader(input, fSz, m_link, linkValues, mess)) { |
| 680 |
f << "###fType=" << RagTime5Layout::printType(m_link.m_fileType[0]) << ","; |
| 681 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the field fSz28... type seems bad\n")); |
| 682 |
return true; |
| 683 |
} |
| 684 |
f << m_link << "," << mess; |
| 685 |
long expectedFileType1=0; |
| 686 |
if (m_link.m_fileType[0]==0x3c052) { |
| 687 |
m_what=6; |
| 688 |
m_fieldName="list:longs2"; |
| 689 |
expectedFileType1=0x50; |
| 690 |
// use 0cf042 to find data2 |
| 691 |
} |
| 692 |
else { |
| 693 |
f << "###fType=" << RagTime5Layout::printType(m_link.m_fileType[0]) << ","; |
| 694 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: the field fSz%d... type seems bad\n", int(fSz))); |
| 695 |
return true; |
| 696 |
} |
| 697 |
if (expectedFileType1>0 && long(m_link.m_fileType[1]&0xFFD7)!=expectedFileType1) { |
| 698 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: fileType1 seems odd[fSz=28...]\n")); |
| 699 |
f << "###fileType1=" << std::hex << m_link.m_fileType[1] << std::dec << ","; |
| 700 |
} |
| 701 |
break; |
| 702 |
} |
| 703 |
case 36: { // follow when it exists the fSz=30 zone, no auxilliar data |
| 704 |
m_fieldName="page[name]"; |
| 705 |
for (int i=0; i<2; ++i) { // always 0 |
| 706 |
val=static_cast<int>(input->readLong(2)); |
| 707 |
if (val) f << "f" << i << "=" << val << ","; |
| 708 |
} |
| 709 |
auto type=input->readULong(4); |
| 710 |
if (type!=0x7d01a) { |
| 711 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: find unexpected filetype[fSz=36]\n")); |
| 712 |
f << "###fileType=" << RagTime5Layout::printType(type) << ","; |
| 713 |
} |
| 714 |
val=static_cast<int>(input->readLong(4)); // 0 or small number |
| 715 |
if (val) { |
| 716 |
// TODO: find which expected type refers to next[id], can be list:longs2, settings[def], ... |
| 717 |
setExpectedType(val-1,F_nextId); |
| 718 |
f << "next[id]=F" << (val-1) << ","; |
| 719 |
} |
| 720 |
for (int i=0; i<3; ++i) { // f4=10 |
| 721 |
val=static_cast<int>(input->readLong(2)); |
| 722 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 723 |
} |
| 724 |
f << "ids=["; |
| 725 |
for (int i=0; i<3; ++i) { |
| 726 |
val=static_cast<int>(input->readLong(4)); |
| 727 |
if (!val) { |
| 728 |
f << "_,"; |
| 729 |
continue; |
| 730 |
} |
| 731 |
setExpectedType(val-1,F_name+i); |
| 732 |
f << "F" << val-1 << ","; |
| 733 |
} |
| 734 |
f << "],"; |
| 735 |
break; |
| 736 |
} |
| 737 |
case 38: { // in 1 or 2 exemplar, no auxilliar data |
| 738 |
m_fieldName="settings[Def]"; |
| 739 |
auto type=input->readULong(4); |
| 740 |
if (type!=0x47040) { |
| 741 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: find unexpected type[fSz=38]\n")); |
| 742 |
f << "##fileType=" << RagTime5Layout::printType(type) << ","; |
| 743 |
} |
| 744 |
type=input->readULong(4); // 0|1c07007|1492042 |
| 745 |
if (type) f << "fileType1=" << RagTime5Layout::printType(type) << ","; |
| 746 |
val=static_cast<int>(input->readLong(4)); |
| 747 |
if (val) { |
| 748 |
setExpectedType(val-1,F_nextId); |
| 749 |
f << "next[id]=F" << (val-1) << ","; |
| 750 |
} |
| 751 |
for (int i=0; i<3; ++i) { // f1=0|8, f4=10 |
| 752 |
val=static_cast<int>(input->readLong(2)); |
| 753 |
if (val) f << "f" << i << "=" << val << ","; |
| 754 |
} |
| 755 |
f << "ids=["; |
| 756 |
for (int i=0; i<3; ++i) { // small increasing sequence |
| 757 |
val=static_cast<int>(input->readLong(4)); |
| 758 |
if (!val) { |
| 759 |
f << "_,"; |
| 760 |
continue; |
| 761 |
} |
| 762 |
setExpectedType(val-1,F_settings+i); |
| 763 |
f << "F" << val-1 << ","; |
| 764 |
} |
| 765 |
f << "],"; |
| 766 |
val=static_cast<int>(input->readLong(2)); // always 0 |
| 767 |
if (val) f << "f5=" << val << ","; |
| 768 |
break; |
| 769 |
} |
| 770 |
default: |
| 771 |
f << "###fSz=" << fSz << ","; |
| 772 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseZone: find unexpected file size\n")); |
| 773 |
break; |
| 774 |
} |
| 775 |
if (!m_fieldName.empty()) |
| 776 |
f << m_fieldName << ","; |
| 777 |
return true; |
| 778 |
} |
| 779 |
//! parse a field |
| 780 |
bool parseField(RagTime5StructManager::Field const &field, int /*m*/, libmwaw::DebugStream &f) final |
| 781 |
{ |
| 782 |
if (!m_fieldName.empty()) |
| 783 |
f << m_fieldName << ","; |
| 784 |
auto const &it=m_expectedIdToType.find(m_dataId); |
| 785 |
switch (m_what) { |
| 786 |
case 0: // main |
| 787 |
if (field.m_type==RagTime5StructManager::Field::T_FieldList && field.m_fileType==0x14b5815) { |
| 788 |
for (auto const &child : field.m_fieldList) { |
| 789 |
if (child.m_type==RagTime5StructManager::Field::T_LongList && child.m_fileType==0xcf042) { |
| 790 |
f << "ids[page]=["; |
| 791 |
for (auto val : child.m_longList) { |
| 792 |
if (val==0) |
| 793 |
f << "_,"; |
| 794 |
else |
| 795 |
f << "F" << val-1 << ","; |
| 796 |
} |
| 797 |
// read the page in file order |
| 798 |
for (auto pIt=child.m_longList.rbegin(); pIt!=child.m_longList.rend(); ++pIt) { |
| 799 |
auto const &val=*pIt; |
| 800 |
if (val) |
| 801 |
setExpectedType(int(val-1),F_page); |
| 802 |
} |
| 803 |
continue; |
| 804 |
} |
| 805 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected main field\n")); |
| 806 |
f << "###[" << child << "],"; |
| 807 |
} |
| 808 |
break; |
| 809 |
} |
| 810 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected main field\n")); |
| 811 |
f << "###" << field; |
| 812 |
break; |
| 813 |
case 3: // page data |
| 814 |
if (field.m_type==RagTime5StructManager::Field::T_Unstructured && field.m_fileType==0xce017) { |
| 815 |
// rare, always 2 |
| 816 |
f << "unkn="<< field.m_extra << ","; |
| 817 |
break; |
| 818 |
} |
| 819 |
if (field.m_type==RagTime5StructManager::Field::T_Long && field.m_fileType==0xcf817) { |
| 820 |
// a small value between 2a and 61 |
| 821 |
f << "f0="<<field.m_longValue[0] << ","; |
| 822 |
break; |
| 823 |
} |
| 824 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected data0 field\n")); |
| 825 |
f << "###" << field; |
| 826 |
break; |
| 827 |
case 4: // list |
| 828 |
if (field.m_type==RagTime5StructManager::Field::T_LongList && field.m_fileType==0xce842) { |
| 829 |
f << "pos=["; |
| 830 |
for (auto val : field.m_longList) { |
| 831 |
if (val==0) |
| 832 |
f << "_,"; |
| 833 |
else if (val>1000) |
| 834 |
f << std::hex << val << std::dec << ","; |
| 835 |
else |
| 836 |
f << val << ","; |
| 837 |
} |
| 838 |
f << "],"; |
| 839 |
int expected=(it!=m_expectedIdToType.end())?it->second : -1; |
| 840 |
if (expected==F_name||expected==F_name+1) |
| 841 |
m_cluster->m_pageNameLink.m_posToNames[expected-F_name]=field.m_longList; |
| 842 |
else |
| 843 |
m_link.m_longList=field.m_longList; |
| 844 |
break; |
| 845 |
} |
| 846 |
if (field.m_type==RagTime5StructManager::Field::T_LongList && field.m_fileType==0xcf042) { // with 3c052 |
| 847 |
f << "unkn=["; |
| 848 |
for (auto val : field.m_longList) { |
| 849 |
if (val==0) |
| 850 |
f << "_,"; |
| 851 |
else |
| 852 |
f << val << ","; |
| 853 |
} |
| 854 |
break; |
| 855 |
} |
| 856 |
if (field.m_type==RagTime5StructManager::Field::T_Unstructured && field.m_fileType==0xce017) { |
| 857 |
// a small value 2|4|a|1c|40 |
| 858 |
f << "unkn="<<field.m_extra << ","; |
| 859 |
break; |
| 860 |
} |
| 861 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected list field\n")); |
| 862 |
f << "###" << field; |
| 863 |
break; |
| 864 |
case 5: // fSz=60 |
| 865 |
if (field.m_type==RagTime5StructManager::Field::T_FieldList && field.m_fileType==0x14b4815) { |
| 866 |
for (auto const &child : field.m_fieldList) { |
| 867 |
if (child.m_type==RagTime5StructManager::Field::T_LongList && child.m_fileType==0xce842) { |
| 868 |
f << "unkn=["; |
| 869 |
for (auto val : child.m_longList) { |
| 870 |
if (val==0) |
| 871 |
f << "_,"; |
| 872 |
else |
| 873 |
f << val << ","; |
| 874 |
} |
| 875 |
continue; |
| 876 |
} |
| 877 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected data2 field\n")); |
| 878 |
f << "###[" << child << "],"; |
| 879 |
} |
| 880 |
break; |
| 881 |
} |
| 882 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected data2 field\n")); |
| 883 |
f << "###" << field; |
| 884 |
break; |
| 885 |
case 6: // second list |
| 886 |
if (field.m_type==RagTime5StructManager::Field::T_LongList && field.m_fileType==0xcf042) { // with 3c052 |
| 887 |
f << "unkn=["; |
| 888 |
for (auto val : field.m_longList) { |
| 889 |
if (val==0) |
| 890 |
f << "_,"; |
| 891 |
else { |
| 892 |
setExpectedType(int(val-1),F_pageData2); |
| 893 |
f << "data2=F" << val-1 << ","; |
| 894 |
} |
| 895 |
} |
| 896 |
break; |
| 897 |
} |
| 898 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected list:long2 field\n")); |
| 899 |
f << "###" << field; |
| 900 |
break; |
| 901 |
default: |
| 902 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseField: find unexpected sub field\n")); |
| 903 |
f << "###" << field; |
| 904 |
break; |
| 905 |
} |
| 906 |
return true; |
| 907 |
} |
| 908 |
protected: |
| 909 |
//! parse a page |
| 910 |
bool parsePageZone(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) |
| 911 |
{ |
| 912 |
if (N<0 || m_dataId==0 || m_dataId>m_numPages || (fSz!=50 && fSz!=66)) { |
| 913 |
f << "###N=" << N << ",fSz=" << fSz << ","; |
| 914 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parsePageZone: find unexpected main field\n")); |
| 915 |
return false; |
| 916 |
} |
| 917 |
f << "page, fl=" << std::hex << flag << std::dec << ","; |
| 918 |
m_fieldName="page"; |
| 919 |
if (N!=1) { |
| 920 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parsePageZone: zone N seems badA\n")); |
| 921 |
f << "#N=" << N << ","; |
| 922 |
} |
| 923 |
int val; |
| 924 |
for (int i=0; i<2; ++i) { // always 0 |
| 925 |
val=static_cast<int>(input->readLong(2)); |
| 926 |
if (val) |
| 927 |
f << "f" << i << "=" << val << ","; |
| 928 |
} |
| 929 |
float dim[2]; |
| 930 |
for (auto &d : dim) d=float(input->readLong(4))/65536.f; |
| 931 |
m_actualZone.m_dimension=MWAWVec2f(dim[0],dim[1]); |
| 932 |
f << "sz=" << MWAWVec2f(dim[0],dim[1]) << ","; |
| 933 |
std::vector<int> listIds; |
| 934 |
long actPos=input->tell(); |
| 935 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 936 |
f << "###cluster0,"; |
| 937 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parsePageZone: can not read first cluster page\n")); |
| 938 |
input->seek(actPos+4, librevenge::RVNG_SEEK_SET); |
| 939 |
} |
| 940 |
else if (listIds[0]) { // link to a cluster main zone |
| 941 |
m_actualZone.m_mainId=listIds[0]; |
| 942 |
m_cluster->m_childIdSet.insert(listIds[0]); |
| 943 |
f << "cluster0=" << getClusterDebugName(listIds[0]) << ","; |
| 944 |
} |
| 945 |
for (int i=0; i<2; ++i) { // always 0: another item? |
| 946 |
val=static_cast<int>(input->readLong(2)); |
| 947 |
if (val) |
| 948 |
f << "f" << i+2 << "=" << val << ","; |
| 949 |
} |
| 950 |
listIds.clear(); |
| 951 |
actPos=input->tell(); |
| 952 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 953 |
f << "###cluster1,"; |
| 954 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parsePageZone: can not read second cluster page\n")); |
| 955 |
input->seek(actPos+4, librevenge::RVNG_SEEK_SET); |
| 956 |
} |
| 957 |
else if (listIds[0]) { // link to the master layout |
| 958 |
m_actualZone.m_masterId=listIds[0]; |
| 959 |
m_cluster->m_childIdSet.insert(listIds[0]); |
| 960 |
f << "cluster1=" << getClusterDebugName(listIds[0]) << ","; |
| 961 |
} |
| 962 |
for (int i=0; i<2; ++i) { // either 0,0 or 1,small number (but does not seems a data id ) |
| 963 |
val=static_cast<int>(input->readLong(2)); |
| 964 |
if (val) |
| 965 |
f << "f" << i+4 << "=" << val << ","; |
| 966 |
} |
| 967 |
val=static_cast<int>(input->readLong(4)); // alwas 1? |
| 968 |
if (val!=1) f << "f6=" << val << ","; |
| 969 |
f << "unkn=["; |
| 970 |
for (int i=0; i<4; ++i) { // small number: hasData0?, hasSetting?, hasPageName?, ? |
| 971 |
val=static_cast<int>(input->readLong(2)); |
| 972 |
if (val) |
| 973 |
f << val << ","; |
| 974 |
else |
| 975 |
f << "_,"; |
| 976 |
} |
| 977 |
f << "],"; |
| 978 |
val=static_cast<int>(input->readLong(4)); |
| 979 |
if (val) { |
| 980 |
setExpectedType(val-1,F_settingsDef); |
| 981 |
f << "settingsDef=F" << val-1 << ","; |
| 982 |
} |
| 983 |
if (fSz==66) { // master page |
| 984 |
f << "master,"; |
| 985 |
for (int i=0; i<2; ++i) { // 0: main, 1: master? |
| 986 |
val=static_cast<int>(input->readLong(4)); |
| 987 |
if (!val) continue; |
| 988 |
setExpectedType(val-1,F_pageData1); |
| 989 |
f << "pageData1[" << i << "]=F" << val-1 << ","; |
| 990 |
} |
| 991 |
for (int i=0; i<2; ++i) { // fl0=0|1 |
| 992 |
val=static_cast<int>(input->readLong(1)); |
| 993 |
if (!val) continue; |
| 994 |
if (i==0) // 1: specified number, 2:index counted from start, 3: from end, 4: formula |
| 995 |
f << "usage=" << val << ","; |
| 996 |
else |
| 997 |
f << "fl" << i << "=" << val << ","; |
| 998 |
} |
| 999 |
for (int i=0; i<3; ++i) { // g4=0|1, g6=g4 |
| 1000 |
val=static_cast<int>(input->readLong(2)); |
| 1001 |
if (!val) continue; |
| 1002 |
if (i==2) |
| 1003 |
f << "formula=f" << val << ","; |
| 1004 |
else |
| 1005 |
f << "g" << i+4 << "=" << val << ","; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
m_cluster->m_pageList.push_back(m_actualZone); |
| 1009 |
m_actualZone=ClusterLayout::Zone(); |
| 1010 |
return true; |
| 1011 |
} |
| 1012 |
|
| 1013 |
//! parse the header zone |
| 1014 |
bool parseHeaderZone(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) |
| 1015 |
{ |
| 1016 |
f << "header,fl=" << std::hex << flag << std::dec << ","; |
| 1017 |
m_fieldName="header"; |
| 1018 |
if (N!=-5 || m_dataId!=0 || (fSz!=123 && fSz!=127 && fSz!=128 && fSz!=132)) { |
| 1019 |
f << "###N=" << N << ",fSz=" << fSz << ","; |
| 1020 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseHeaderZone: find unexpected main field\n")); |
| 1021 |
return false; |
| 1022 |
} |
| 1023 |
int val; |
| 1024 |
for (int i=0; i<2; ++i) { |
| 1025 |
val=static_cast<int>(input->readLong(2)); |
| 1026 |
if (val) f << "f" << i << "=" << val << ","; |
| 1027 |
} |
| 1028 |
val=static_cast<int>(input->readLong(2)); // small number, unsure what it is |
| 1029 |
f << "id=" << val << ","; |
| 1030 |
val=static_cast<int>(input->readULong(2)); |
| 1031 |
if (val!=m_type) { |
| 1032 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseHeaderZone: unexpected zone type\n")); |
| 1033 |
f << "##zoneType=" << std::hex << val << std::dec << ","; |
| 1034 |
} |
| 1035 |
for (int i=0; i<2; ++i) { // f0=0, f1=4-6 |
| 1036 |
val=static_cast<int>(input->readLong(4)); |
| 1037 |
if (!val) continue; |
| 1038 |
if (i==1) { |
| 1039 |
setExpectedType(val-1,F_nextId); |
| 1040 |
f << "next[id]=F" << val-1 << ","; |
| 1041 |
} |
| 1042 |
else |
| 1043 |
f << "f" << i+2 << "=" << val << ","; |
| 1044 |
} |
| 1045 |
val=static_cast<int>(input->readLong(2)); // always 16 |
| 1046 |
if (val!=16) |
| 1047 |
f << "f4=" << val << ","; |
| 1048 |
m_numPages=static_cast<int>(input->readLong(4)); |
| 1049 |
if (m_numPages!=1) |
| 1050 |
f << "num[pages]=" << m_numPages << ","; |
| 1051 |
auto fileType=input->readULong(4); |
| 1052 |
if (fileType!=0x14b6052) { |
| 1053 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseHeaderZone: find unexpected filetype\n")); |
| 1054 |
f << "#fileType0=" << RagTime5Layout::printType(fileType) << ","; |
| 1055 |
} |
| 1056 |
for (int i=0; i<9; ++i) { // f11=0x60, |
| 1057 |
val=static_cast<int>(input->readLong(2)); |
| 1058 |
if (val) |
| 1059 |
f << "f" << i+5 << "=" << val << ","; |
| 1060 |
} |
| 1061 |
val=static_cast<int>(input->readLong(1)); |
| 1062 |
if (val!=1) f << "fl=" << val << ","; |
| 1063 |
if (fSz==128 || fSz==132) { |
| 1064 |
for (int i=0; i<5; ++i) { // unsure find only 0 here |
| 1065 |
val=static_cast<int>(input->readLong(1)); |
| 1066 |
if (val) |
| 1067 |
f << "flA" << i << "=" << val << ","; |
| 1068 |
} |
| 1069 |
} |
| 1070 |
val=static_cast<int>(input->readLong(4)); |
| 1071 |
if (val) { |
| 1072 |
setExpectedType(val-1,F_pageData0); |
| 1073 |
f << "pageData0=F" << val-1 << ","; |
| 1074 |
} |
| 1075 |
long actPos=input->tell(); |
| 1076 |
std::vector<int> listIds; |
| 1077 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 1078 |
MWAW_DEBUG_MSG(("RagTime5LayoutInternal::LayoutCParser::parseHeaderZone: can not read first cluster frame\n")); |
| 1079 |
f << "##badCluster,"; |
| 1080 |
input->seek(actPos+4, librevenge::RVNG_SEEK_SET); |
| 1081 |
} |
| 1082 |
else if (listIds[0]) { // find link to a named frame cluster |
| 1083 |
m_cluster->m_clusterIdsList.push_back(listIds[0]); |
| 1084 |
f << "clusterId1=" << getClusterDebugName(listIds[0]) << ","; |
| 1085 |
} |
| 1086 |
for (int i=0; i<2; ++i) { // always 0 |
| 1087 |
val=static_cast<int>(input->readLong(2)); |
| 1088 |
if (val) |
| 1089 |
f << "g" << i+1 << "=" << val << ","; |
| 1090 |
} |
| 1091 |
float dim[4]; |
| 1092 |
for (int i=0; i<2; ++i) dim[i]=float(input->readLong(4))/65536.f; |
| 1093 |
MWAWVec2f frameSize(dim[0],dim[1]); |
| 1094 |
f << "sz=" << frameSize << ","; |
| 1095 |
for (int i=0; i<2; ++i) dim[i]=float(input->readLong(4))/65536.f; |
| 1096 |
if (MWAWVec2f(dim[0],dim[1])!=frameSize) |
| 1097 |
f << "sz2=" << MWAWVec2f(dim[0],dim[1]) << ","; |
| 1098 |
auto fl=input->readULong(2); |
| 1099 |
// checkme, only ok for mac file ? |
| 1100 |
if (fl&1) f << "side[double],"; |
| 1101 |
if (fl&4) f << "show[grid],"; |
| 1102 |
if (fl&8) f << "tear[all,page],"; |
| 1103 |
fl &= 0xfff2; |
| 1104 |
if (fl) f << "flB=" << std::hex << fl << std::dec << ","; |
| 1105 |
for (int i=0; i<8; ++i) { |
| 1106 |
val=static_cast<int>(input->readLong(i==3 ? 4 : 2)); |
| 1107 |
int const expected[]= {0,0,0,0,1,0,1,1}; |
| 1108 |
if (val==expected[i]) continue; |
| 1109 |
if (i==0) |
| 1110 |
f << "first[page]=" << val+1 << ","; |
| 1111 |
else if (i==3) { |
| 1112 |
setExpectedType(val-1,F_pipeline); |
| 1113 |
f << "pipeline=F" << val-1 << ","; |
| 1114 |
} |
| 1115 |
else if (i==4) |
| 1116 |
f << "tear[from]=" << val << ","; |
| 1117 |
else if (i==6) |
| 1118 |
f << "tear[to]=" << val << ","; |
| 1119 |
else if (i==7) |
| 1120 |
f << "page[number,format]=" << val << ","; |
| 1121 |
else |
| 1122 |
f << "g" << i+2 << "=" << val << ","; |
| 1123 |
} |
| 1124 |
for (auto &d : dim) d=float(input->readLong(4))/65536.f; |
| 1125 |
f << "dim=" << MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[2],dim[3])) << ","; |
| 1126 |
for (int i=0; i<4; ++i) { // h3=0|1|3|6 |
| 1127 |
val=static_cast<int>(input->readLong(2)); |
| 1128 |
if (val) |
| 1129 |
f << "h" << i << "=" << val << ","; |
| 1130 |
} |
| 1131 |
if (fSz==127 || fSz==132) { |
| 1132 |
for (int i=0; i<2; ++i) { // always 0 |
| 1133 |
val=static_cast<int>(input->readLong(2)); |
| 1134 |
if (val) |
| 1135 |
f << "h" << i+3 << "=" << val << ","; |
| 1136 |
} |
| 1137 |
} |
| 1138 |
return true; |
| 1139 |
} |
| 1140 |
|
| 1141 |
//! the current cluster |
| 1142 |
std::shared_ptr<ClusterLayout> m_cluster; |
| 1143 |
//! the number of pages |
| 1144 |
int m_numPages; |
| 1145 |
//! a index to know which field is parsed : 0: main, 1:list of pages, 2: unknown, 3:data0, 4:list, 5: unknown, 6: list:longs2 |
| 1146 |
int m_what; |
| 1147 |
//! the link id : 0: listItem, 1: pipeline, 2: settinglinks, 3: namelink, |
| 1148 |
int m_linkId; |
| 1149 |
//! the actual field name |
| 1150 |
std::string m_fieldName; |
| 1151 |
|
| 1152 |
//! the actual zone |
| 1153 |
ClusterLayout::Zone m_actualZone; |
| 1154 |
|
| 1155 |
//! the expected id |
| 1156 |
std::map<int,int> m_expectedIdToType; |
| 1157 |
//! the id stack |
| 1158 |
std::stack<int> m_idStack; |
| 1159 |
}; |
| 1160 |
|
| 1161 |
LayoutCParser::~LayoutCParser() |
| 1162 |
{ |
| 1163 |
} |
| 1164 |
|
| 1165 |
} |
| 1166 |
|
| 1167 |
std::shared_ptr<RagTime5ClusterManager::Cluster> RagTime5Layout::readLayoutCluster(RagTime5Zone &zone, int zoneType) |
| 1168 |
{ |
| 1169 |
auto clusterManager=m_document.getClusterManager(); |
| 1170 |
if (!clusterManager) { |
| 1171 |
MWAW_DEBUG_MSG(("RagTime5Layout::readLayoutCluster: oops can not find the cluster manager\n")); |
| 1172 |
return std::shared_ptr<RagTime5ClusterManager::Cluster>(); |
| 1173 |
} |
| 1174 |
RagTime5LayoutInternal::LayoutCParser parser(*clusterManager, zoneType); |
| 1175 |
if (!clusterManager->readCluster(zone, parser) || !parser.getLayoutCluster()) { |
| 1176 |
MWAW_DEBUG_MSG(("RagTime5Layout::readLayoutCluster: oops can not find the cluster\n")); |
| 1177 |
return std::shared_ptr<RagTime5ClusterManager::Cluster>(); |
| 1178 |
} |
| 1179 |
|
| 1180 |
auto cluster=parser.getLayoutCluster(); |
| 1181 |
|
| 1182 |
std::map<int, librevenge::RVNGString> idToNameMap; |
| 1183 |
if (!cluster->m_pageNameLink.empty()) { |
| 1184 |
m_document.readUnicodeStringList(cluster->m_pageNameLink, idToNameMap); |
| 1185 |
// update the cluster name |
| 1186 |
for (size_t i=0; i<cluster->m_pageList.size(); ++i) { |
| 1187 |
auto it=idToNameMap.find(int(i+1)); |
| 1188 |
if (it==idToNameMap.end() || it->second.empty()) continue; |
| 1189 |
auto const &child=cluster->m_pageList[i]; |
| 1190 |
if (!child.m_mainId) continue; |
| 1191 |
clusterManager->setClusterName(child.m_mainId, it->second); |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
if (!cluster->m_pageDataLink.empty()) { // related to page |
| 1196 |
RagTime5LayoutInternal::PageDataParser pageParser(cluster->m_pageDataLink.m_fieldSize, "LayoutPage0"); |
| 1197 |
m_document.readFixedSizeZone(cluster->m_pageDataLink, pageParser); |
| 1198 |
} |
| 1199 |
if (!cluster->m_pipelineLink.empty() && cluster->m_pipelineLink.m_ids.size()==1) { |
| 1200 |
if (cluster->m_pipelineLink.m_fieldSize==4) { |
| 1201 |
RagTime5LayoutInternal::ClustListParser listParser(*clusterManager, 4, "LayoutPipeline"); |
| 1202 |
m_document.readFixedSizeZone(cluster->m_pipelineLink, listParser); |
| 1203 |
m_document.checkClusterList(listParser.getIdList()); |
| 1204 |
} |
| 1205 |
else { |
| 1206 |
MWAW_DEBUG_MSG(("RagTime5Layout::readClusterLayoutData: find unexpected field size for pipeline data\n")); |
| 1207 |
m_document.readFixedSizeZone(cluster->m_pipelineLink, "LayoutPipelineBAD"); |
| 1208 |
} |
| 1209 |
} |
| 1210 |
// can have some setting |
| 1211 |
for (auto const &lnk : cluster->m_settingLinks) { |
| 1212 |
if (lnk.empty()) continue; |
| 1213 |
RagTime5StructManager::FieldParser defaultParser("Settings"); |
| 1214 |
m_document.readStructZone(lnk, defaultParser, 0); |
| 1215 |
} |
| 1216 |
|
| 1217 |
for (auto const &lnk : cluster->m_linksList) { |
| 1218 |
if (lnk.m_type==RagTime5ClusterManager::Link::L_List) { |
| 1219 |
m_document.readListZone(lnk); |
| 1220 |
continue; |
| 1221 |
} |
| 1222 |
std::stringstream s; |
| 1223 |
s << "Layout_Data" << lnk.m_fieldSize; |
| 1224 |
RagTime5StructManager::DataParser defaultParser(s.str()); |
| 1225 |
m_document.readFixedSizeZone(lnk, defaultParser); |
| 1226 |
} |
| 1227 |
|
| 1228 |
if (m_state->m_idLayoutMap.find(zone.m_ids[0])!=m_state->m_idLayoutMap.end()) { |
| 1229 |
MWAW_DEBUG_MSG(("RagTime5Layout::readLayoutCluster: cluster %d already exists\n", zone.m_ids[0])); |
| 1230 |
} |
| 1231 |
else |
| 1232 |
m_state->m_idLayoutMap[zone.m_ids[0]]=cluster; |
| 1233 |
return cluster; |
| 1234 |
} |
| 1235 |
|
| 1236 |
|
| 1237 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |