| 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 "MWAWGraphicEncoder.hxx" |
| 49 |
#include "MWAWGraphicListener.hxx" |
| 50 |
#include "MWAWParagraph.hxx" |
| 51 |
#include "MWAWPosition.hxx" |
| 52 |
#include "MWAWSection.hxx" |
| 53 |
#include "MWAWSpreadsheetEncoder.hxx" |
| 54 |
#include "MWAWSpreadsheetListener.hxx" |
| 55 |
#include "MWAWSubDocument.hxx" |
| 56 |
|
| 57 |
#include "RagTime5ClusterManager.hxx" |
| 58 |
#include "RagTime5Document.hxx" |
| 59 |
#include "RagTime5StructManager.hxx" |
| 60 |
#include "RagTime5StyleManager.hxx" |
| 61 |
|
| 62 |
#include "RagTime5Text.hxx" |
| 63 |
|
| 64 |
#include "libmwaw_internal.hxx" |
| 65 |
|
| 66 |
/** Internal: the structures of a RagTime5Text */ |
| 67 |
namespace RagTime5TextInternal |
| 68 |
{ |
| 69 |
//! a PLC of a RagTime5Text |
| 70 |
struct PLC { |
| 71 |
//! constructor |
| 72 |
PLC() |
| 73 |
: m_position(-1) |
| 74 |
, m_fileType(0) |
| 75 |
, m_value(-1) |
| 76 |
{ |
| 77 |
} |
| 78 |
//! operator<< |
| 79 |
friend std::ostream &operator<<(std::ostream &o, PLC const &plc) |
| 80 |
{ |
| 81 |
if (plc.m_fileType==0) { |
| 82 |
o << "free[next]"; |
| 83 |
if (plc.m_position>0) |
| 84 |
o << "=PLC" << plc.m_position; |
| 85 |
o << ","; |
| 86 |
return o; |
| 87 |
} |
| 88 |
if (plc.m_position>=0) o << "pos=" << plc.m_position << ","; |
| 89 |
switch (plc.m_fileType) { |
| 90 |
case 0: |
| 91 |
break; |
| 92 |
case 0x1001: |
| 93 |
o << "para,"; |
| 94 |
break; |
| 95 |
case 0x1801: // soft? |
| 96 |
o << "line[beg],"; |
| 97 |
break; |
| 98 |
case 0x3001: |
| 99 |
o << "index[end],"; |
| 100 |
break; |
| 101 |
// 0x4001: related to footnote? |
| 102 |
case 0x5001: |
| 103 |
o << "char,"; |
| 104 |
break; |
| 105 |
case 0x7001: |
| 106 |
o << "index[beg],"; |
| 107 |
break; |
| 108 |
default: |
| 109 |
if (plc.m_fileType&0xfe) o << "#"; |
| 110 |
o << "type=" << std::hex << plc.m_fileType << std::dec << ","; |
| 111 |
} |
| 112 |
if (plc.m_value!=-1) o << "f0=" << plc.m_value << ","; |
| 113 |
return o; |
| 114 |
} |
| 115 |
//! the position in the text |
| 116 |
int m_position; |
| 117 |
//! the file type |
| 118 |
int m_fileType; |
| 119 |
//! an unknown value |
| 120 |
int m_value; |
| 121 |
}; |
| 122 |
|
| 123 |
//! a small struct use to define a block of a RagTime5Text |
| 124 |
struct Block { |
| 125 |
//! constructor |
| 126 |
Block() |
| 127 |
: m_id(0) |
| 128 |
, m_subId(0) |
| 129 |
, m_dimension() |
| 130 |
, m_extra("") |
| 131 |
{ |
| 132 |
for (auto &plc : m_plc) plc=0; |
| 133 |
} |
| 134 |
//! operator<< |
| 135 |
friend std::ostream &operator<<(std::ostream &o, Block const &block) |
| 136 |
{ |
| 137 |
o << "id=" << block.m_id << ","; |
| 138 |
if (block.m_subId) o << "id[sub]=" << block.m_subId << ","; |
| 139 |
o << "PLC" << block.m_plc[0] << "<->" << block.m_plc[1] << ","; |
| 140 |
o << block.m_dimension << ","; |
| 141 |
o << block.m_extra; |
| 142 |
return o; |
| 143 |
} |
| 144 |
//! the block id |
| 145 |
int m_id; |
| 146 |
//! the block sub id |
| 147 |
int m_subId; |
| 148 |
//! the block dimension |
| 149 |
MWAWBox2f m_dimension; |
| 150 |
//! the list of zone plc (first-end) |
| 151 |
int m_plc[2]; |
| 152 |
//! extra data |
| 153 |
std::string m_extra; |
| 154 |
}; |
| 155 |
|
| 156 |
//! a small struct used to store link plc data: footnote, index, ... |
| 157 |
struct LinkPLC { |
| 158 |
//! constructor |
| 159 |
LinkPLC() |
| 160 |
: m_what(0) |
| 161 |
, m_type(0) |
| 162 |
, m_positions(-1,-1) |
| 163 |
, m_id(0) |
| 164 |
, m_dimensions() |
| 165 |
, m_footnotePositions() |
| 166 |
{ |
| 167 |
} |
| 168 |
//! the plc type 0:attachment, 1:item(list item), 2:unknown, 3:index, 4:formula(page number, ...), 5:footnote |
| 169 |
int m_what; |
| 170 |
//! the file type |
| 171 |
int m_type; |
| 172 |
//! the position in the text |
| 173 |
MWAWVec2i m_positions; |
| 174 |
//! an identifier |
| 175 |
int m_id; |
| 176 |
//! the attachment box |
| 177 |
MWAWVec2f m_dimensions; |
| 178 |
//! the footnote data |
| 179 |
MWAWVec2i m_footnotePositions; |
| 180 |
}; |
| 181 |
|
| 182 |
//! low level: the text cluster of a RagTime5Text |
| 183 |
struct ClusterText final : public RagTime5ClusterManager::Cluster { |
| 184 |
//! constructor |
| 185 |
ClusterText() |
| 186 |
: RagTime5ClusterManager::Cluster(C_TextZone) |
| 187 |
, m_contentLink() |
| 188 |
, m_plcDefLink() |
| 189 |
, m_plcDefFreeBegin(0) |
| 190 |
, m_plcDefNumFree(-1) |
| 191 |
, m_plcToStyleLink() |
| 192 |
, m_blockCellToPlcLink() |
| 193 |
, m_separatorLink() |
| 194 |
, m_footnoteLink() |
| 195 |
, m_indexLink() |
| 196 |
, m_textIntListLink() |
| 197 |
, m_unknownLinks1() |
| 198 |
|
| 199 |
, m_blockList() |
| 200 |
, m_blockCellList() |
| 201 |
, m_childList() |
| 202 |
, m_PLCList() |
| 203 |
, m_separators() |
| 204 |
, m_posToStyleIdMap() |
| 205 |
, m_linkPLCList() |
| 206 |
, m_posToLinkIdMap() |
| 207 |
{ |
| 208 |
} |
| 209 |
//! destructor |
| 210 |
~ClusterText() final; |
| 211 |
//! the main content |
| 212 |
RagTime5ClusterManager::Link m_contentLink; |
| 213 |
//! the plc definition link |
| 214 |
RagTime5ClusterManager::Link m_plcDefLink; |
| 215 |
//! the plc first free block in the plc definition list |
| 216 |
int m_plcDefFreeBegin; |
| 217 |
//! the number of free block in the plc definition list |
| 218 |
int m_plcDefNumFree; |
| 219 |
//! the plc to text style link |
| 220 |
RagTime5ClusterManager::Link m_plcToStyleLink; |
| 221 |
//! the blockCell to plc link |
| 222 |
RagTime5ClusterManager::Link m_blockCellToPlcLink; |
| 223 |
//! the word/separator link |
| 224 |
RagTime5ClusterManager::Link m_separatorLink; |
| 225 |
//! the footnote link |
| 226 |
RagTime5ClusterManager::Link m_footnoteLink; |
| 227 |
//! the index link |
| 228 |
RagTime5ClusterManager::Link m_indexLink; |
| 229 |
//! the list of link zone |
| 230 |
RagTime5ClusterManager::Link m_linkDefs[5]; |
| 231 |
//! list of a int link with size 2(only v6.6) |
| 232 |
RagTime5ClusterManager::Link m_textIntListLink; |
| 233 |
//! list of unkndata1 links |
| 234 |
std::vector<RagTime5ClusterManager::Link> m_unknownLinks1; |
| 235 |
//! list of unknown link: the three unkndata+2-3 links and the header link3 link |
| 236 |
RagTime5ClusterManager::Link m_unknownLink[3]; |
| 237 |
|
| 238 |
// final data |
| 239 |
|
| 240 |
//! list of block (defined in header) |
| 241 |
std::vector<std::vector<Block> > m_blockList; |
| 242 |
//! list of block (defined in blockCell list) |
| 243 |
std::vector<Block> m_blockCellList; |
| 244 |
//! list of child |
| 245 |
std::vector<RagTime5StructManager::ZoneLink> m_childList; |
| 246 |
//! the PLC list |
| 247 |
std::vector<PLC> m_PLCList; |
| 248 |
//! the separators |
| 249 |
std::vector<int> m_separators; |
| 250 |
//! position to plc map |
| 251 |
std::multimap<int, int> m_posToStyleIdMap; |
| 252 |
//! the link plc list |
| 253 |
std::vector<LinkPLC> m_linkPLCList; |
| 254 |
//! position to link data map |
| 255 |
std::multimap<int, size_t> m_posToLinkIdMap; |
| 256 |
}; |
| 257 |
|
| 258 |
ClusterText::~ClusterText() |
| 259 |
{ |
| 260 |
} |
| 261 |
|
| 262 |
//////////////////////////////////////// |
| 263 |
//! Internal: the state of a RagTime5Text |
| 264 |
struct State { |
| 265 |
//! constructor |
| 266 |
State() |
| 267 |
: m_numPages(0) |
| 268 |
, m_idTextMap() |
| 269 |
, m_uniqueIndexId(0) |
| 270 |
{ |
| 271 |
} |
| 272 |
//! the number of pages |
| 273 |
int m_numPages; |
| 274 |
//! map data id to text zone |
| 275 |
std::map<int, std::shared_ptr<ClusterText> > m_idTextMap; |
| 276 |
//! an int used to create unique index id |
| 277 |
int m_uniqueIndexId; |
| 278 |
}; |
| 279 |
|
| 280 |
//! Internal: the subdocument of a RagTime5Text |
| 281 |
class SubDocument final : public MWAWSubDocument |
| 282 |
{ |
| 283 |
public: |
| 284 |
// constructor |
| 285 |
SubDocument(RagTime5Text &parser, MWAWInputStreamPtr const &input, |
| 286 |
RagTime5TextInternal::ClusterText &cluster, RagTime5Zone &dataZone, size_t firstChar, size_t lastChar) |
| 287 |
: MWAWSubDocument(&parser.m_document.getMainParser(), input, MWAWEntry()) |
| 288 |
, m_ragtimeParser(parser) |
| 289 |
, m_cluster(cluster) |
| 290 |
, m_dataZone(dataZone) |
| 291 |
, m_firstChar(firstChar) |
| 292 |
, m_lastChar(lastChar) |
| 293 |
{ |
| 294 |
} |
| 295 |
|
| 296 |
//! destructor |
| 297 |
~SubDocument() final {} |
| 298 |
|
| 299 |
//! operator!= |
| 300 |
bool operator!=(MWAWSubDocument const &doc) const final; |
| 301 |
|
| 302 |
//! the parser function |
| 303 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 304 |
|
| 305 |
protected: |
| 306 |
//! the main parser |
| 307 |
RagTime5Text &m_ragtimeParser; |
| 308 |
//! the cluster |
| 309 |
ClusterText &m_cluster; |
| 310 |
//! the data zone |
| 311 |
RagTime5Zone &m_dataZone; |
| 312 |
//! the first char |
| 313 |
size_t m_firstChar; |
| 314 |
//! the last char |
| 315 |
size_t m_lastChar; |
| 316 |
}; |
| 317 |
|
| 318 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/) |
| 319 |
{ |
| 320 |
if (!listener.get()) { |
| 321 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::SubDocument::parse: no listener\n")); |
| 322 |
return; |
| 323 |
} |
| 324 |
|
| 325 |
long pos = m_input->tell(); |
| 326 |
m_ragtimeParser.send(m_cluster, m_dataZone, listener, m_firstChar, m_lastChar, true, -1); |
| 327 |
m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 328 |
} |
| 329 |
|
| 330 |
bool SubDocument::operator!=(MWAWSubDocument const &doc) const |
| 331 |
{ |
| 332 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 333 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 334 |
if (!sDoc) return true; |
| 335 |
if (&m_ragtimeParser != &sDoc->m_ragtimeParser) return true; |
| 336 |
if (&m_cluster != &sDoc->m_cluster) return true; |
| 337 |
if (&m_dataZone != &sDoc->m_dataZone) return true; |
| 338 |
if (m_firstChar != sDoc->m_firstChar) return true; |
| 339 |
if (m_lastChar != sDoc->m_lastChar) return true; |
| 340 |
return false; |
| 341 |
} |
| 342 |
|
| 343 |
} |
| 344 |
|
| 345 |
//////////////////////////////////////////////////////////// |
| 346 |
// constructor/destructor, ... |
| 347 |
//////////////////////////////////////////////////////////// |
| 348 |
RagTime5Text::RagTime5Text(RagTime5Document &doc) |
| 349 |
: m_document(doc) |
| 350 |
, m_structManager(m_document.getStructManager()) |
| 351 |
, m_styleManager(m_document.getStyleManager()) |
| 352 |
, m_parserState(doc.getParserState()) |
| 353 |
, m_state(new RagTime5TextInternal::State) |
| 354 |
{ |
| 355 |
} |
| 356 |
|
| 357 |
RagTime5Text::~RagTime5Text() |
| 358 |
{ } |
| 359 |
|
| 360 |
int RagTime5Text::version() const |
| 361 |
{ |
| 362 |
return m_parserState->m_version; |
| 363 |
} |
| 364 |
|
| 365 |
int RagTime5Text::numPages() const |
| 366 |
{ |
| 367 |
// TODO IMPLEMENT ME |
| 368 |
MWAW_DEBUG_MSG(("RagTime5Text::numPages: is not implemented\n")); |
| 369 |
return 0; |
| 370 |
} |
| 371 |
|
| 372 |
bool RagTime5Text::send(int zoneId, MWAWListenerPtr listener, int partId, int cellId, double totalWidth) |
| 373 |
{ |
| 374 |
auto it=m_state->m_idTextMap.find(zoneId); |
| 375 |
if (it==m_state->m_idTextMap.end() || !it->second) { |
| 376 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find zone %d\n", zoneId)); |
| 377 |
return false; |
| 378 |
} |
| 379 |
return send(*it->second, listener, partId, cellId, totalWidth); |
| 380 |
} |
| 381 |
|
| 382 |
//////////////////////////////////////////////////////////// |
| 383 |
// |
| 384 |
// Intermediate level |
| 385 |
// |
| 386 |
//////////////////////////////////////////////////////////// |
| 387 |
|
| 388 |
//////////////////////////////////////////////////////////// |
| 389 |
// text separator position |
| 390 |
//////////////////////////////////////////////////////////// |
| 391 |
bool RagTime5Text::readTextSeparators(RagTime5Zone &zone, std::vector<int> &separators) |
| 392 |
{ |
| 393 |
if (!zone.m_entry.valid() || zone.getKindLastPart(zone.m_kinds[1].empty())!="ItemData") { |
| 394 |
MWAW_DEBUG_MSG(("RagTime5Text::readTextSeparators: can not find the text position zone\n")); |
| 395 |
return false; |
| 396 |
} |
| 397 |
|
| 398 |
zone.m_isParsed=true; |
| 399 |
MWAWEntry entry=zone.m_entry; |
| 400 |
MWAWInputStreamPtr input=zone.getInput(); |
| 401 |
libmwaw::DebugFile &ascFile=zone.ascii(); |
| 402 |
libmwaw::DebugStream f; |
| 403 |
f << "Entries(TextSep)[" << zone << "]:"; |
| 404 |
|
| 405 |
input->seek(zone.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 406 |
separators.resize(size_t(2*entry.length())); |
| 407 |
|
| 408 |
int lastSeen=0, numSeen=0; |
| 409 |
for (long i=0; i<entry.length(); ++i) { |
| 410 |
auto c=static_cast<int>(input->readULong(1)); |
| 411 |
for (int j=0; j<2; ++j) { |
| 412 |
int v=(j==0 ? (c>>4) : c)&0xf; |
| 413 |
if (v!=lastSeen) { |
| 414 |
if (numSeen==1) f << lastSeen << ","; |
| 415 |
else if (numSeen) f << lastSeen << "x" << numSeen << ","; |
| 416 |
numSeen=0; |
| 417 |
lastSeen=v; |
| 418 |
} |
| 419 |
++numSeen; |
| 420 |
separators[size_t(2*i+j)]=v; |
| 421 |
} |
| 422 |
} |
| 423 |
if (numSeen==1) f << lastSeen << ","; |
| 424 |
else if (numSeen) f << lastSeen << "x" << numSeen << ","; |
| 425 |
|
| 426 |
ascFile.addPos(entry.end()); |
| 427 |
ascFile.addNote("_"); |
| 428 |
ascFile.addPos(entry.begin()); |
| 429 |
ascFile.addNote(f.str().c_str()); |
| 430 |
return true; |
| 431 |
} |
| 432 |
|
| 433 |
//////////////////////////////////////////////////////////// |
| 434 |
// link/list definition |
| 435 |
//////////////////////////////////////////////////////////// |
| 436 |
bool RagTime5Text::readLinkZones(RagTime5TextInternal::ClusterText &cluster, RagTime5ClusterManager::Link const &link, int what) |
| 437 |
{ |
| 438 |
if (link.m_ids.empty()) { |
| 439 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: can not find the first zone id\n")); |
| 440 |
return false; |
| 441 |
} |
| 442 |
if (what!=1 && link.m_ids.size()>=3 && link.m_ids[2]) { |
| 443 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: find unexpected link2\n")); |
| 444 |
} |
| 445 |
else if (link.m_ids.size()>=3 && link.m_ids[2]) { |
| 446 |
std::vector<long> decal; |
| 447 |
if (link.m_ids[1]) |
| 448 |
m_document.readPositions(link.m_ids[1], decal); |
| 449 |
if (decal.empty()) |
| 450 |
decal=link.m_longList; |
| 451 |
int const dataId=link.m_ids[2]; |
| 452 |
auto dataZone=m_document.getDataZone(dataId); |
| 453 |
if (!dataZone) { |
| 454 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: can not find the data zone %d\n", dataId)); |
| 455 |
return false; |
| 456 |
} |
| 457 |
else if (!dataZone->m_entry.valid() || dataZone->getKindLastPart(dataZone->m_kinds[1].empty())!="ItemData") { |
| 458 |
if (decal.size()==1) { |
| 459 |
// a graphic zone with 0 zone is ok... |
| 460 |
dataZone->m_isParsed=true; |
| 461 |
} |
| 462 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: the data zone %d seems bad\n", dataId)); |
| 463 |
} |
| 464 |
else { |
| 465 |
MWAWEntry entry=dataZone->m_entry; |
| 466 |
dataZone->m_isParsed=true; |
| 467 |
|
| 468 |
libmwaw::DebugFile &ascFile=dataZone->ascii(); |
| 469 |
libmwaw::DebugStream f; |
| 470 |
f << "Entries(" << link.m_name << "Def)[" << *dataZone << "]:"; |
| 471 |
ascFile.addPos(entry.end()); |
| 472 |
ascFile.addNote("_"); |
| 473 |
|
| 474 |
if (decal.size() <= 1) { |
| 475 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: can not find position for the data zone %d\n", dataId)); |
| 476 |
f << "###"; |
| 477 |
ascFile.addPos(entry.begin()); |
| 478 |
ascFile.addNote(f.str().c_str()); |
| 479 |
} |
| 480 |
else { |
| 481 |
auto N=int(decal.size()); |
| 482 |
MWAWInputStreamPtr input=dataZone->getInput(); |
| 483 |
input->setReadInverted(!cluster.m_hiLoEndian); // checkme maybe zone |
| 484 |
|
| 485 |
ascFile.addPos(entry.begin()); |
| 486 |
ascFile.addNote(f.str().c_str()); |
| 487 |
|
| 488 |
for (int i=0; i<N-1; ++i) { |
| 489 |
long pos=decal[size_t(i)], nextPos=decal[size_t(i+1)]; |
| 490 |
if (pos==nextPos) continue; |
| 491 |
if (pos<0 || pos>entry.length()) { |
| 492 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: can not read the data zone %d-%d seems bad\n", dataId, i)); |
| 493 |
continue; |
| 494 |
} |
| 495 |
f.str(""); |
| 496 |
f << link.m_name << "Def-" << i+1 << ":"; |
| 497 |
librevenge::RVNGString string; |
| 498 |
input->seek(pos+entry.begin(), librevenge::RVNG_SEEK_SET); |
| 499 |
if (nextPos>entry.length() || !m_structManager->readUnicodeString(input, entry.begin()+nextPos, string)) { |
| 500 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: can not read a string\n")); |
| 501 |
f << "###"; |
| 502 |
} |
| 503 |
else if (!string.empty() && string.cstr()[0]=='\0') |
| 504 |
f << "\"" << string.cstr()+1 << "\","; |
| 505 |
else |
| 506 |
f << "\"" << string.cstr() << "\","; |
| 507 |
ascFile.addPos(entry.begin()+pos); |
| 508 |
ascFile.addNote(f.str().c_str()); |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
// ok no list |
| 514 |
if (!link.m_ids[0]) |
| 515 |
return true; |
| 516 |
auto dataZone=m_document.getDataZone(link.m_ids[0]); |
| 517 |
if (!dataZone || dataZone->getKindLastPart()!="ItemData") { |
| 518 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: can not find the first zone %d\n", link.m_ids[0])); |
| 519 |
return false; |
| 520 |
} |
| 521 |
|
| 522 |
// ok no list |
| 523 |
if (!dataZone->m_entry.valid()) |
| 524 |
return true; |
| 525 |
|
| 526 |
MWAWInputStreamPtr input=dataZone->getInput(); |
| 527 |
bool const hiLo=dataZone->m_hiLoEndian; |
| 528 |
input->setReadInverted(!hiLo); |
| 529 |
input->seek(dataZone->m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 530 |
dataZone->m_isParsed=true; |
| 531 |
|
| 532 |
libmwaw::DebugFile &ascFile=dataZone->ascii(); |
| 533 |
libmwaw::DebugStream f; |
| 534 |
ascFile.addPos(dataZone->m_entry.end()); |
| 535 |
ascFile.addNote("_"); |
| 536 |
int const expectedSize[]= {32, 14/* or 24 in 6.5*/, 16, 12, 16, 24}; |
| 537 |
// CHANGEME: find where the version is stored and use it to decide if the fieldSize is ok or not |
| 538 |
if (what<0 || what>=6 || (link.m_fieldSize!=expectedSize[what] && (what!=1 || link.m_fieldSize!=24))) { |
| 539 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: find unexpected size for zone %d\n", link.m_ids[0])); |
| 540 |
f << "###"; |
| 541 |
ascFile.addPos(dataZone->m_entry.begin()); |
| 542 |
ascFile.addNote(f.str().c_str()); |
| 543 |
return false; |
| 544 |
} |
| 545 |
if (link.m_fieldSize<12 || dataZone->m_entry.length()/link.m_fieldSize<link.m_N || link.m_N<=0) { |
| 546 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: the position zone %d seems bad\n", dataZone->m_ids[0])); |
| 547 |
f << "Entries(" << link.m_name << ")[" << *dataZone << "]:" << link << "###,"; |
| 548 |
ascFile.addPos(dataZone->m_entry.begin()); |
| 549 |
ascFile.addNote(f.str().c_str()); |
| 550 |
return false; |
| 551 |
} |
| 552 |
size_t numPLC=cluster.m_PLCList.size(); |
| 553 |
for (int i=0; i<link.m_N; ++i) { |
| 554 |
long pos=input->tell(); |
| 555 |
f.str(""); |
| 556 |
if (i==0) |
| 557 |
f << "Entries(" << link.m_name << "Pos)[" << *dataZone << "]:"; |
| 558 |
else |
| 559 |
f << link.m_name << "Pos-" << i << ":"; |
| 560 |
size_t ids[2]; |
| 561 |
for (auto &id : ids) id=size_t(input->readULong(4)); |
| 562 |
if (ids[0] && ids[1]) { |
| 563 |
bool ok=true; |
| 564 |
RagTime5TextInternal::LinkPLC linkPLC; |
| 565 |
linkPLC.m_what=what; |
| 566 |
for (int j=0; j<2; ++j) { |
| 567 |
if (ids[j]>numPLC) { |
| 568 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: a plc position in zone %d seems bad\n", dataZone->m_ids[0])); |
| 569 |
f << "###PLC" << ids[j]; |
| 570 |
ok=false; |
| 571 |
continue; |
| 572 |
} |
| 573 |
linkPLC.m_positions[j]=cluster.m_PLCList[ids[j]-1].m_position; |
| 574 |
f << linkPLC.m_positions[j]; |
| 575 |
if (j==0) |
| 576 |
f << "<->"; |
| 577 |
else |
| 578 |
f << ","; |
| 579 |
} |
| 580 |
if (ok && linkPLC.m_positions[0]>linkPLC.m_positions[1]) { |
| 581 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: the plc orders in zone %d seems bad\n", dataZone->m_ids[0])); |
| 582 |
f << "###"; |
| 583 |
ok=false; |
| 584 |
} |
| 585 |
int val=int(input->readLong(2)); // always 0? |
| 586 |
if (val) f << "f0=" << val << ","; |
| 587 |
linkPLC.m_type=int(input->readLong(2)); |
| 588 |
f << "type=" << linkPLC.m_type << ","; // 8: graph/footnote/index, 10: ref1 and ref4, 14: ref3 |
| 589 |
if (link.m_fieldSize==16) { |
| 590 |
linkPLC.m_id=int(input->readLong(4)); |
| 591 |
if (what==4) |
| 592 |
f << "FD" << linkPLC.m_id << ","; |
| 593 |
else |
| 594 |
f << "id=" << linkPLC.m_id << ","; |
| 595 |
} |
| 596 |
else if (what==3) // index |
| 597 |
linkPLC.m_id=++m_state->m_uniqueIndexId; |
| 598 |
else if (what==5) { // footnote |
| 599 |
for (auto &id : ids) id=size_t(input->readULong(4)); |
| 600 |
for (int j=0; j<2; ++j) { |
| 601 |
if (ids[j]>numPLC) { |
| 602 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: a plc position in zone %d seems bad\n", dataZone->m_ids[0])); |
| 603 |
f << "###PLC" << ids[j]; |
| 604 |
ok=false; |
| 605 |
continue; |
| 606 |
} |
| 607 |
linkPLC.m_footnotePositions[j]=cluster.m_PLCList[ids[j]-1].m_position; |
| 608 |
f << linkPLC.m_footnotePositions[j]; |
| 609 |
if (j==0) |
| 610 |
f << "<->"; |
| 611 |
else |
| 612 |
f << ","; |
| 613 |
} |
| 614 |
if (ok && linkPLC.m_footnotePositions[0]>linkPLC.m_footnotePositions[1]) { |
| 615 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: the plc orders in zone %d seems bad\n", dataZone->m_ids[0])); |
| 616 |
f << "###"; |
| 617 |
ok=false; |
| 618 |
} |
| 619 |
linkPLC.m_id=int(input->readLong(4)); |
| 620 |
f << "id=" << linkPLC.m_id << ","; |
| 621 |
} |
| 622 |
else if (what==0) { // attachment |
| 623 |
float dim[2]; |
| 624 |
for (auto &d : dim) d=float(input->readLong(4))/65536.f; |
| 625 |
linkPLC.m_dimensions=MWAWVec2f(dim[0],dim[1]); |
| 626 |
f << "dim=" << linkPLC.m_dimensions << ","; |
| 627 |
linkPLC.m_id=int(input->readLong(4)); |
| 628 |
f << "id=" << linkPLC.m_id << ","; |
| 629 |
} |
| 630 |
if (input->tell()!=pos+link.m_fieldSize) |
| 631 |
ascFile.addDelimiter(input->tell(),'|'); |
| 632 |
if (ok) { |
| 633 |
size_t id=cluster.m_linkPLCList.size(); |
| 634 |
cluster.m_linkPLCList.push_back(linkPLC); |
| 635 |
cluster.m_posToLinkIdMap.insert(std::pair<int,size_t>(linkPLC.m_positions[0],id)); |
| 636 |
if (linkPLC.m_positions[0]!=linkPLC.m_positions[1]) |
| 637 |
cluster.m_posToLinkIdMap.insert(std::pair<int,size_t>(linkPLC.m_positions[1],id)); |
| 638 |
} |
| 639 |
} |
| 640 |
ascFile.addPos(pos); |
| 641 |
ascFile.addNote(f.str().c_str()); |
| 642 |
input->seek(pos+link.m_fieldSize, librevenge::RVNG_SEEK_SET); |
| 643 |
} |
| 644 |
if (input->tell()<dataZone->m_entry.end()) { |
| 645 |
f.str(""); |
| 646 |
f << link.m_name << "Pos-:end"; |
| 647 |
// check me: the size seems always a multiple of 16, so maybe reserved data... |
| 648 |
if (dataZone->m_entry.length()%link.m_fieldSize) { |
| 649 |
f << "###"; |
| 650 |
static bool first=true; |
| 651 |
if (first) { |
| 652 |
MWAW_DEBUG_MSG(("RagTime5Text::readLinkZones: find some extra data\n")); |
| 653 |
first=false; |
| 654 |
} |
| 655 |
} |
| 656 |
ascFile.addPos(input->tell()); |
| 657 |
ascFile.addNote(f.str().c_str()); |
| 658 |
} |
| 659 |
return true; |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
//////////////////////////////////////////////////////////// |
| 664 |
// PLC |
| 665 |
//////////////////////////////////////////////////////////// |
| 666 |
bool RagTime5Text::readPLC(RagTime5TextInternal::ClusterText &cluster, int zoneId) |
| 667 |
{ |
| 668 |
auto zone=m_document.getDataZone(zoneId); |
| 669 |
if (!zone || !zone->m_entry.valid() || (zone->m_entry.length()%6) || |
| 670 |
zone->getKindLastPart(zone->m_kinds[1].empty())!="ItemData") { |
| 671 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLC: the entry of zone %d seems bad\n", zoneId)); |
| 672 |
return false; |
| 673 |
} |
| 674 |
MWAWEntry entry=zone->m_entry; |
| 675 |
MWAWInputStreamPtr input=zone->getInput(); |
| 676 |
bool const hiLo=cluster.m_hiLoEndian; |
| 677 |
input->setReadInverted(!hiLo); |
| 678 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 679 |
|
| 680 |
libmwaw::DebugFile &ascFile=zone->ascii(); |
| 681 |
libmwaw::DebugStream f; |
| 682 |
zone->m_isParsed=true; |
| 683 |
ascFile.addPos(entry.end()); |
| 684 |
ascFile.addNote("_"); |
| 685 |
|
| 686 |
auto N=size_t(entry.length()/6); |
| 687 |
f << "Entries(TextPLCDef)[" << *zone << "]:"; |
| 688 |
// first check the free list |
| 689 |
int freeId=cluster.m_plcDefFreeBegin; |
| 690 |
std::set<int> listFreeIds; |
| 691 |
bool ok=true; |
| 692 |
for (int i=0; i<cluster.m_plcDefNumFree; ++i) { |
| 693 |
if (freeId<=0 || freeId>int(N) || listFreeIds.find(freeId)!=listFreeIds.end()) { |
| 694 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLC: find a bad freeId=%d\n", freeId)); |
| 695 |
ok=false; |
| 696 |
break; |
| 697 |
} |
| 698 |
listFreeIds.insert(freeId); |
| 699 |
input->seek(entry.begin()+(freeId-1)*6, librevenge::RVNG_SEEK_SET); |
| 700 |
freeId=static_cast<int>(input->readLong(4)); |
| 701 |
} |
| 702 |
if (ok && freeId) { |
| 703 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLC: last free Id=%d seems bad\n", freeId)); |
| 704 |
} |
| 705 |
if (!ok) { |
| 706 |
listFreeIds.clear(); |
| 707 |
f << "###badFreeList,"; |
| 708 |
} |
| 709 |
ascFile.addPos(entry.begin()); |
| 710 |
ascFile.addNote(f.str().c_str()); |
| 711 |
|
| 712 |
cluster.m_PLCList.resize(N); |
| 713 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 714 |
for (size_t i=0; i<N; ++i) { |
| 715 |
long pos=input->tell(); |
| 716 |
if (listFreeIds.find(int(i+1))!=listFreeIds.end()) { |
| 717 |
ascFile.addPos(pos); |
| 718 |
ascFile.addNote("_"); |
| 719 |
input->seek(6, librevenge::RVNG_SEEK_CUR); |
| 720 |
continue; |
| 721 |
} |
| 722 |
f.str(""); |
| 723 |
f << "TextPLCDef-PLC" << i+1 << ":"; |
| 724 |
RagTime5TextInternal::PLC plc; |
| 725 |
if (hiLo) { |
| 726 |
plc.m_fileType=static_cast<int>(input->readULong(2)); |
| 727 |
plc.m_position=static_cast<int>(input->readULong(2)); |
| 728 |
plc.m_value=static_cast<int>(input->readLong(2)); |
| 729 |
} |
| 730 |
else { |
| 731 |
plc.m_value=static_cast<int>(input->readLong(2)); |
| 732 |
plc.m_position=static_cast<int>(input->readULong(2)); |
| 733 |
plc.m_fileType=static_cast<int>(input->readULong(2)); |
| 734 |
} |
| 735 |
|
| 736 |
f << plc; |
| 737 |
cluster.m_PLCList[i]=plc; |
| 738 |
ascFile.addPos(pos); |
| 739 |
ascFile.addNote(f.str().c_str()); |
| 740 |
} |
| 741 |
input->setReadInverted(false); |
| 742 |
return true; |
| 743 |
} |
| 744 |
|
| 745 |
bool RagTime5Text::readPLCToCharStyle(RagTime5TextInternal::ClusterText &cluster) |
| 746 |
{ |
| 747 |
if (cluster.m_plcToStyleLink.m_ids.empty()) |
| 748 |
return true; |
| 749 |
int const zoneId=cluster.m_plcToStyleLink.m_ids[0]; |
| 750 |
if (!zoneId) |
| 751 |
return false; |
| 752 |
|
| 753 |
auto zone=m_document.getDataZone(zoneId); |
| 754 |
if (!zone || !zone->m_entry.valid() || (zone->m_entry.length()%6) || |
| 755 |
zone->getKindLastPart(zone->m_kinds[1].empty())!="ItemData") { |
| 756 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLCToCharStyle: the entry of zone %d seems bad\n", zoneId)); |
| 757 |
return false; |
| 758 |
} |
| 759 |
MWAWEntry entry=zone->m_entry; |
| 760 |
MWAWInputStreamPtr input=zone->getInput(); |
| 761 |
input->setReadInverted(!cluster.m_hiLoEndian); // checkme: can also be zone->m_hiLoEndian |
| 762 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 763 |
|
| 764 |
libmwaw::DebugFile &ascFile=zone->ascii(); |
| 765 |
libmwaw::DebugStream f; |
| 766 |
zone->m_isParsed=true; |
| 767 |
ascFile.addPos(entry.end()); |
| 768 |
ascFile.addNote("_"); |
| 769 |
|
| 770 |
f << "Entries(TextPLCToCStyle)[" << *zone << "]:"; |
| 771 |
|
| 772 |
auto N=int(entry.length()/6); |
| 773 |
if (N>cluster.m_plcToStyleLink.m_N) // rare but can happens |
| 774 |
N=cluster.m_plcToStyleLink.m_N; |
| 775 |
else if (N<cluster.m_plcToStyleLink.m_N) { |
| 776 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLCToCharStyle: N value seems too short\n")); |
| 777 |
f << "##N=" << N << ","; |
| 778 |
} |
| 779 |
ascFile.addPos(entry.begin()); |
| 780 |
ascFile.addNote(f.str().c_str()); |
| 781 |
size_t numPLC=cluster.m_PLCList.size(); |
| 782 |
long lastFindPos=-1; |
| 783 |
for (int i=0; i<N; ++i) { |
| 784 |
long pos=input->tell(); |
| 785 |
f.str(""); |
| 786 |
f << "TextPLCToCStyle-" << i << ":"; |
| 787 |
auto id=size_t(input->readULong(4)); |
| 788 |
auto styleId=static_cast<int>(input->readULong(2)); |
| 789 |
f << "PLC" << id; |
| 790 |
if (id==0 || id>numPLC) { |
| 791 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLCToCharStyle: find bad PLC id\n")); |
| 792 |
f << "###"; |
| 793 |
} |
| 794 |
else { |
| 795 |
auto const plc=cluster.m_PLCList[size_t(id-1)]; |
| 796 |
if ((i==0 && plc.m_position!=0) || (i && plc.m_position<lastFindPos)) { |
| 797 |
MWAW_DEBUG_MSG(("RagTime5Text::readPLCToCharStyle: the PLC position seems bad\n")); |
| 798 |
f << "###"; |
| 799 |
} |
| 800 |
else |
| 801 |
cluster.m_posToStyleIdMap.insert(std::multimap<int, int>::value_type(plc.m_position, styleId)); |
| 802 |
lastFindPos=plc.m_position; |
| 803 |
f << "[" << plc << "]"; |
| 804 |
} |
| 805 |
f << "->TS" << styleId << ","; |
| 806 |
ascFile.addPos(pos); |
| 807 |
ascFile.addNote(f.str().c_str()); |
| 808 |
} |
| 809 |
if (input->tell()!=entry.end()) { |
| 810 |
ascFile.addPos(input->tell()); |
| 811 |
ascFile.addNote("TextPLCToCStyle:#extra"); |
| 812 |
} |
| 813 |
input->setReadInverted(false); |
| 814 |
return true; |
| 815 |
} |
| 816 |
|
| 817 |
//////////////////////////////////////////////////////////// |
| 818 |
// |
| 819 |
// Low level |
| 820 |
// |
| 821 |
//////////////////////////////////////////////////////////// |
| 822 |
|
| 823 |
//////////////////////////////////////////////////////////// |
| 824 |
// interface send function |
| 825 |
//////////////////////////////////////////////////////////// |
| 826 |
|
| 827 |
void RagTime5Text::flushExtra(bool onlyCheck) |
| 828 |
{ |
| 829 |
for (auto const &it : m_state->m_idTextMap) { |
| 830 |
if (!it.second || it.second->m_isSent) |
| 831 |
continue; |
| 832 |
static bool first=true; |
| 833 |
if (first) { |
| 834 |
MWAW_DEBUG_MSG(("RagTime5Text::flushExtra: find some unsent zones: %d...\n", it.first)); |
| 835 |
first=false; |
| 836 |
} |
| 837 |
if (!onlyCheck) |
| 838 |
send(*it.second, MWAWListenerPtr()); |
| 839 |
} |
| 840 |
} |
| 841 |
|
| 842 |
bool RagTime5Text::send(RagTime5TextInternal::ClusterText &cluster, RagTime5Zone &dataZone, MWAWListenerPtr listener, size_t firstChar, size_t lastChar, |
| 843 |
bool isLastZone, double totalWidth) |
| 844 |
{ |
| 845 |
if (!listener) |
| 846 |
listener=m_parserState->getMainListener(); |
| 847 |
if (!listener) { |
| 848 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the listener\n")); |
| 849 |
return false; |
| 850 |
} |
| 851 |
if (cluster.m_separators.empty()) { |
| 852 |
std::shared_ptr<RagTime5Zone> sepZone; |
| 853 |
int cId=!cluster.m_separatorLink.m_ids.empty() ? cluster.m_separatorLink.m_ids[0] : -1; |
| 854 |
if (cId>0) |
| 855 |
sepZone=m_document.getDataZone(cId); |
| 856 |
std::vector<int> separators; |
| 857 |
if (!sepZone) { |
| 858 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the text separator zone %d\n", cId)); |
| 859 |
} |
| 860 |
else |
| 861 |
readTextSeparators(*sepZone, cluster.m_separators); |
| 862 |
} |
| 863 |
auto input=dataZone.getInput(); |
| 864 |
auto const &entry=dataZone.m_entry; |
| 865 |
auto &ascFile=dataZone.ascii(); |
| 866 |
if (!input || long(firstChar)>=entry.length()/2 || firstChar>=cluster.m_separators.size()) { |
| 867 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the text\n")); |
| 868 |
return false; |
| 869 |
} |
| 870 |
if (long(lastChar)>entry.length()/2 || lastChar>cluster.m_separators.size()) { |
| 871 |
MWAW_DEBUG_MSG(("RagTime5Text::send: last char seems to big\n")); |
| 872 |
lastChar=std::min<size_t>(size_t(entry.length()/2),cluster.m_separators.size()); |
| 873 |
} |
| 874 |
input->seek(entry.begin()+2*long(firstChar), librevenge::RVNG_SEEK_SET); |
| 875 |
long pos=input->tell(); |
| 876 |
libmwaw::DebugStream f; |
| 877 |
f << "TextUnicode:"; |
| 878 |
bool newLine=true; |
| 879 |
auto numLinks=cluster.m_linkPLCList.size(); |
| 880 |
for (size_t i=firstChar; i<lastChar; ++i) { |
| 881 |
auto plcIt=cluster.m_posToStyleIdMap.lower_bound(int(i)); |
| 882 |
while (plcIt!=cluster.m_posToStyleIdMap.end() && plcIt->first==static_cast<int>(i)) { |
| 883 |
int const styleId=plcIt++->second; |
| 884 |
f << "[TS" << styleId << "]"; |
| 885 |
MWAWFont font; |
| 886 |
MWAWParagraph para; |
| 887 |
MWAWSection section; |
| 888 |
if (!m_styleManager->updateTextStyles(styleId, font, para, section, totalWidth)) { |
| 889 |
MWAW_DEBUG_MSG(("RagTime5Text::send: the style seems bad\n")); |
| 890 |
f << "###"; |
| 891 |
} |
| 892 |
else { |
| 893 |
if (newLine && listener->canOpenSectionAddBreak() && section!=listener->getSection()) { |
| 894 |
if (listener->isSectionOpened()) |
| 895 |
listener->closeSection(); |
| 896 |
listener->openSection(section); |
| 897 |
} |
| 898 |
listener->setParagraph(para); |
| 899 |
listener->setFont(font); |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
switch (cluster.m_separators[i]) { |
| 904 |
case 0: // none |
| 905 |
case 2: // sign separator: .,/-(x) |
| 906 |
case 3: // word separator |
| 907 |
case 4: // potential hyphenate |
| 908 |
break; |
| 909 |
default: // find also 1 and 7:link?, 8, 12 |
| 910 |
f << "[m" << cluster.m_separators[i] << "]"; |
| 911 |
} |
| 912 |
newLine=false; |
| 913 |
auto linkIt=cluster.m_posToLinkIdMap.find(int(i)); |
| 914 |
while (linkIt!=cluster.m_posToLinkIdMap.end() && linkIt->first==int(i)) { |
| 915 |
if (linkIt->second>=numLinks) { |
| 916 |
MWAW_DEBUG_MSG(("RagTime5Text::send: find a bad link\n")); |
| 917 |
++linkIt; |
| 918 |
continue; |
| 919 |
} |
| 920 |
auto const &plc=cluster.m_linkPLCList[linkIt++->second]; |
| 921 |
if (plc.m_what==3 && plc.m_positions[0]!=plc.m_positions[1]) { // index |
| 922 |
MWAWField field(int(i)==plc.m_positions[0] ? MWAWField::BookmarkStart : MWAWField::BookmarkEnd); |
| 923 |
std::stringstream s; |
| 924 |
s << "Index" << plc.m_id; |
| 925 |
field.m_data=s.str(); |
| 926 |
listener->insertField(field); |
| 927 |
} |
| 928 |
// TODO when m_what==4, check if we can retrieve the formula, to decide if this is a pagenumber, ... |
| 929 |
} |
| 930 |
auto unicode=uint32_t(input->readULong(2)); |
| 931 |
switch (unicode) { |
| 932 |
case 0: |
| 933 |
f << "###[0]"; |
| 934 |
break; |
| 935 |
case 9: |
| 936 |
listener->insertTab(); |
| 937 |
f << "\t"; |
| 938 |
break; |
| 939 |
case 0xb: |
| 940 |
case 0xd: |
| 941 |
if (i+1==lastChar && !isLastZone && unicode==0xd) |
| 942 |
break; |
| 943 |
newLine=unicode==0xd; |
| 944 |
listener->insertEOL(unicode==0xb); |
| 945 |
ascFile.addPos(pos); |
| 946 |
ascFile.addNote(f.str().c_str()); |
| 947 |
pos=input->tell(); |
| 948 |
f.str(""); |
| 949 |
f << "TextUnicode:"; |
| 950 |
break; |
| 951 |
case 0xe820: // attachment |
| 952 |
case 0xe824: { // footnote |
| 953 |
linkIt=cluster.m_posToLinkIdMap.find(int(i)); |
| 954 |
bool find=false; |
| 955 |
int expectedType=unicode==0xe820 ? 0 : 5; |
| 956 |
while (linkIt!=cluster.m_posToLinkIdMap.end() && linkIt->first==int(i)) { |
| 957 |
if (linkIt->second>=numLinks) { |
| 958 |
MWAW_DEBUG_MSG(("RagTime5Text::send: find a bad link\n")); |
| 959 |
++linkIt; |
| 960 |
continue; |
| 961 |
} |
| 962 |
auto const &plc=cluster.m_linkPLCList[linkIt++->second]; |
| 963 |
if (plc.m_what!=expectedType) continue; |
| 964 |
find=true; |
| 965 |
if (unicode==0xe824) { |
| 966 |
if (plc.m_footnotePositions[0]>0 && plc.m_footnotePositions[0]<plc.m_footnotePositions[1]) { |
| 967 |
// add a note as comment (we are in a textbox) |
| 968 |
std::shared_ptr<MWAWSubDocument> doc=std::make_shared<RagTime5TextInternal::SubDocument>(*this, input, cluster, dataZone, plc.m_footnotePositions[0], plc.m_footnotePositions[1]); |
| 969 |
listener->insertComment(doc); |
| 970 |
} |
| 971 |
} |
| 972 |
else { |
| 973 |
if (plc.m_id<0 || plc.m_id>=int(cluster.m_childList.size())) { |
| 974 |
MWAW_DEBUG_MSG(("RagTime5Text::send: oops, unknown child %d\n", plc.m_id)); |
| 975 |
} |
| 976 |
else { |
| 977 |
auto lnk=cluster.m_childList[size_t(plc.m_id)]; |
| 978 |
auto lnkType=m_document.getClusterManager()->getClusterType(lnk.m_dataId); |
| 979 |
|
| 980 |
MWAWPosition position(MWAWVec2f(0,0), plc.m_dimensions, librevenge::RVNG_POINT); |
| 981 |
position.setRelativePosition(MWAWPosition::CharBaseLine, MWAWPosition::XLeft, MWAWPosition::YCenter); |
| 982 |
if (lnkType==RagTime5ClusterManager::Cluster::C_Unknown) { |
| 983 |
MWAW_DEBUG_MSG(("RagTime5Text::send: oops, child has no dataId\n")); |
| 984 |
} |
| 985 |
else if (lnkType==RagTime5ClusterManager::Cluster::C_PictureZone) |
| 986 |
m_document.send(lnk.m_dataId, listener, position); |
| 987 |
else if (lnkType==RagTime5ClusterManager::Cluster::C_SpreadsheetZone) { |
| 988 |
// let try to create a graphic object to represent the content |
| 989 |
MWAWBox2f box(MWAWVec2f(0,0), position.size()); |
| 990 |
MWAWSpreadsheetEncoder spreadsheetEncoder; |
| 991 |
MWAWSpreadsheetListenerPtr spreadsheetListener(new MWAWSpreadsheetListener(*m_parserState, box, &spreadsheetEncoder)); |
| 992 |
spreadsheetListener->startDocument(); |
| 993 |
MWAWPosition spreadsheetPos; |
| 994 |
spreadsheetPos.m_anchorTo = MWAWPosition::Page; |
| 995 |
m_document.send(lnk.m_dataId, spreadsheetListener, spreadsheetPos); |
| 996 |
spreadsheetListener->endDocument(); |
| 997 |
|
| 998 |
MWAWEmbeddedObject picture; |
| 999 |
if (spreadsheetEncoder.getBinaryResult(picture)) |
| 1000 |
listener->insertPicture(position, picture); |
| 1001 |
} |
| 1002 |
else { |
| 1003 |
// let try to create a graphic object to represent the content |
| 1004 |
MWAWBox2f box(MWAWVec2f(0,0), position.size()); |
| 1005 |
MWAWGraphicEncoder graphicEncoder; |
| 1006 |
MWAWGraphicListenerPtr graphicListener(new MWAWGraphicListener(*m_parserState, box, &graphicEncoder)); |
| 1007 |
graphicListener->startDocument(); |
| 1008 |
MWAWPosition graphicPos; |
| 1009 |
graphicPos.m_anchorTo = MWAWPosition::Page; |
| 1010 |
m_document.send(lnk.m_dataId, graphicListener, graphicPos); |
| 1011 |
graphicListener->endDocument(); |
| 1012 |
|
| 1013 |
MWAWEmbeddedObject picture; |
| 1014 |
if (graphicEncoder.getBinaryResult(picture)) |
| 1015 |
listener->insertPicture(position, picture); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
} |
| 1019 |
break; |
| 1020 |
} |
| 1021 |
|
| 1022 |
if (!find) { |
| 1023 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the corresponding link\n")); |
| 1024 |
} |
| 1025 |
f << "[" << std::hex << unicode << std::dec << "]"; |
| 1026 |
break; |
| 1027 |
} |
| 1028 |
case 0xe834: // end sub zone< |
| 1029 |
case 0xe835: // end zone |
| 1030 |
f << "[" << std::hex << unicode << std::dec << "]"; |
| 1031 |
break; |
| 1032 |
default: |
| 1033 |
if (unicode<=0x1f) { |
| 1034 |
MWAW_DEBUG_MSG(("RagTime5Text::send: find an odd char %x\n", static_cast<unsigned int>(unicode))); |
| 1035 |
f << "[#" << std::hex << unicode << std::dec << "]"; |
| 1036 |
break; |
| 1037 |
} |
| 1038 |
listener->insertUnicode(unicode); |
| 1039 |
if (unicode<0x80) |
| 1040 |
f << char(unicode); |
| 1041 |
else |
| 1042 |
f << "[" << std::hex << unicode << std::dec << "]"; |
| 1043 |
break; |
| 1044 |
} |
| 1045 |
} |
| 1046 |
if (pos!=input->tell()||firstChar==lastChar) { |
| 1047 |
ascFile.addPos(pos); |
| 1048 |
ascFile.addNote(f.str().c_str()); |
| 1049 |
} |
| 1050 |
return true; |
| 1051 |
} |
| 1052 |
|
| 1053 |
bool RagTime5Text::send(RagTime5TextInternal::ClusterText &cluster, MWAWListenerPtr listener, int blockId, int cellId, double totalWidth) |
| 1054 |
{ |
| 1055 |
if (!listener) |
| 1056 |
listener=m_parserState->getMainListener(); |
| 1057 |
if (!listener) { |
| 1058 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the listener\n")); |
| 1059 |
return false; |
| 1060 |
} |
| 1061 |
cluster.m_isSent=true; |
| 1062 |
std::vector<RagTime5TextInternal::Block> const *blockZones=nullptr; |
| 1063 |
std::vector<RagTime5TextInternal::Block> blockCell; |
| 1064 |
if (cellId>0 && cellId<=static_cast<int>(cluster.m_blockCellList.size())) { |
| 1065 |
blockCell.push_back(cluster.m_blockCellList[size_t(cellId-1)]); |
| 1066 |
blockZones=&blockCell; |
| 1067 |
} |
| 1068 |
else if (cellId>0) { |
| 1069 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the block %d in zone %d\n", cellId, cluster.m_zoneId)); |
| 1070 |
} |
| 1071 |
else if (blockId>0 && blockId<=static_cast<int>(cluster.m_blockList.size()) && !cluster.m_blockList[size_t(blockId-1)].empty()) |
| 1072 |
blockZones=&cluster.m_blockList[size_t(blockId-1)]; |
| 1073 |
else if (blockId>0) { |
| 1074 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the block %d in zone %d\n", blockId, cluster.m_zoneId)); |
| 1075 |
} |
| 1076 |
|
| 1077 |
std::shared_ptr<RagTime5Zone> dataZone; |
| 1078 |
int cId=!cluster.m_contentLink.m_ids.empty() ? cluster.m_contentLink.m_ids[0] : -1; |
| 1079 |
if (cId>0) |
| 1080 |
dataZone=m_document.getDataZone(cId); |
| 1081 |
else |
| 1082 |
dataZone.reset(); |
| 1083 |
if (!dataZone || !dataZone->m_entry.valid() || |
| 1084 |
dataZone->getKindLastPart(dataZone->m_kinds[1].empty())!="Unicode") { |
| 1085 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find the text contents zone %d\n", cId)); |
| 1086 |
return false; |
| 1087 |
} |
| 1088 |
|
| 1089 |
dataZone->m_isParsed=true; |
| 1090 |
if (dataZone->m_entry.length()==0) return true; |
| 1091 |
|
| 1092 |
MWAWInputStreamPtr input=dataZone->getInput(); |
| 1093 |
libmwaw::DebugFile &ascFile=dataZone->ascii(); |
| 1094 |
libmwaw::DebugStream f; |
| 1095 |
f << "Entries(TextUnicode)[" << *dataZone << "]:"; |
| 1096 |
if (dataZone->m_entry.length()%2) { |
| 1097 |
MWAW_DEBUG_MSG(("RagTime5Text::send: bad length for zone %d\n", cId)); |
| 1098 |
f << "###"; |
| 1099 |
ascFile.addPos(dataZone->m_entry.begin()); |
| 1100 |
ascFile.addNote(f.str().c_str()); |
| 1101 |
ascFile.addPos(dataZone->m_entry.end()); |
| 1102 |
ascFile.addNote("_"); |
| 1103 |
return false; |
| 1104 |
} |
| 1105 |
input->setReadInverted(!cluster.m_hiLoEndian); |
| 1106 |
input->seek(dataZone->m_entry.end()-2, librevenge::RVNG_SEEK_SET); |
| 1107 |
if (input->readULong(2)==0xd00) { |
| 1108 |
static bool first=true; |
| 1109 |
if (first) { |
| 1110 |
MWAW_DEBUG_MSG(("RagTime5Text::send: must change some hiLo\n")); |
| 1111 |
first=false; |
| 1112 |
} |
| 1113 |
f << "###hiLo,"; |
| 1114 |
input->setReadInverted(cluster.m_hiLoEndian); |
| 1115 |
} |
| 1116 |
|
| 1117 |
auto N=size_t(dataZone->m_entry.length()/2); |
| 1118 |
size_t numZones=blockZones ? blockZones->size() : 1; |
| 1119 |
ascFile.addPos(dataZone->m_entry.begin()); |
| 1120 |
ascFile.addNote(f.str().c_str()); |
| 1121 |
ascFile.addPos(dataZone->m_entry.end()); |
| 1122 |
ascFile.addNote("_"); |
| 1123 |
for (size_t z=0; z<numZones; ++z) { |
| 1124 |
RagTime5TextInternal::Block block; |
| 1125 |
bool checkBlock=false; |
| 1126 |
if (blockZones) { |
| 1127 |
block=(*blockZones)[z]; |
| 1128 |
checkBlock=true; |
| 1129 |
} |
| 1130 |
else if (blockId<0) { |
| 1131 |
if (-blockId>static_cast<int>(cluster.m_blockCellList.size())) { |
| 1132 |
MWAW_DEBUG_MSG(("RagTime5Text::send: can not find blockCell %d zone\n", -blockId)); |
| 1133 |
return true; |
| 1134 |
} |
| 1135 |
block=cluster.m_blockCellList[size_t(-blockId-1)]; |
| 1136 |
if (block.m_plc[0]==0 && block.m_plc[1]==0) |
| 1137 |
return true; |
| 1138 |
checkBlock=true; |
| 1139 |
} |
| 1140 |
|
| 1141 |
size_t firstChar=0, lastChar=N; |
| 1142 |
if (checkBlock) { |
| 1143 |
bool ok=true; |
| 1144 |
for (int i=0; i<2; ++i) { |
| 1145 |
if (block.m_plc[i]==0) continue; |
| 1146 |
if (block.m_plc[i]<0 || block.m_plc[i]>static_cast<int>(cluster.m_PLCList.size())) { |
| 1147 |
MWAW_DEBUG_MSG(("RagTime5Text::send: find bad plc id for block %d\n", cluster.m_zoneId)); |
| 1148 |
ok=false; |
| 1149 |
continue; |
| 1150 |
} |
| 1151 |
if (i==0) |
| 1152 |
firstChar=size_t(cluster.m_PLCList[size_t(block.m_plc[i]-1)].m_position); |
| 1153 |
else |
| 1154 |
lastChar=size_t(cluster.m_PLCList[size_t(block.m_plc[i]-1)].m_position); |
| 1155 |
} |
| 1156 |
if (lastChar<firstChar) { |
| 1157 |
MWAW_DEBUG_MSG(("RagTime5Text::send: find bad plc positions for block %d\n", cluster.m_zoneId)); |
| 1158 |
continue; |
| 1159 |
} |
| 1160 |
if (!ok) continue; |
| 1161 |
if (lastChar>N) { |
| 1162 |
MWAW_DEBUG_MSG(("RagTime5Text::send: last char seems too big for block %d\n", cluster.m_zoneId)); |
| 1163 |
lastChar=N; |
| 1164 |
} |
| 1165 |
|
| 1166 |
auto plcIt=cluster.m_posToStyleIdMap.upper_bound(int(firstChar)); |
| 1167 |
MWAWFont font; |
| 1168 |
MWAWParagraph para; |
| 1169 |
MWAWSection section; |
| 1170 |
if ((plcIt==cluster.m_posToStyleIdMap.end() || plcIt->first>static_cast<int>(firstChar)) && |
| 1171 |
plcIt !=cluster.m_posToStyleIdMap.begin() && m_styleManager->updateTextStyles((--plcIt)->second, font, para, section, totalWidth)) { |
| 1172 |
if (listener->canOpenSectionAddBreak() && section!=listener->getSection()) { |
| 1173 |
if (listener->isSectionOpened()) |
| 1174 |
listener->closeSection(); |
| 1175 |
listener->openSection(section); |
| 1176 |
} |
| 1177 |
listener->setParagraph(para); |
| 1178 |
listener->setFont(font); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
send(cluster, *dataZone, listener, firstChar, lastChar, z+1==numZones, totalWidth); |
| 1183 |
} |
| 1184 |
ascFile.addPos(dataZone->m_entry.end()); |
| 1185 |
ascFile.addNote("_"); |
| 1186 |
input->setReadInverted(false); |
| 1187 |
return true; |
| 1188 |
} |
| 1189 |
|
| 1190 |
//////////////////////////////////////////////////////////// |
| 1191 |
// cluster parser |
| 1192 |
//////////////////////////////////////////////////////////// |
| 1193 |
|
| 1194 |
namespace RagTime5TextInternal |
| 1195 |
{ |
| 1196 |
|
| 1197 |
|
| 1198 |
//! Internal: the helper to read a clustList |
| 1199 |
struct ClustListParser final : public RagTime5StructManager::DataParser { |
| 1200 |
//! constructor |
| 1201 |
ClustListParser(RagTime5ClusterManager &clusterManager, std::string const &zoneName) |
| 1202 |
: RagTime5StructManager::DataParser(zoneName) |
| 1203 |
, m_clusterList() |
| 1204 |
, m_clusterManager(clusterManager) |
| 1205 |
{ |
| 1206 |
} |
| 1207 |
//! destructor |
| 1208 |
~ClustListParser() final; |
| 1209 |
//! returns a name which can be used to debugging |
| 1210 |
std::string getClusterDebugName(int id) const |
| 1211 |
{ |
| 1212 |
return m_clusterManager.getClusterDebugName(id); |
| 1213 |
} |
| 1214 |
|
| 1215 |
//! try to parse a data |
| 1216 |
bool parseData(MWAWInputStreamPtr &input, long endPos, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f) final |
| 1217 |
{ |
| 1218 |
long pos=input->tell(); |
| 1219 |
long fSz=endPos-pos; |
| 1220 |
if (fSz!=10 && fSz!=12 && fSz!=14) { |
| 1221 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::ClustListParser::parse: bad data size\n")); |
| 1222 |
return false; |
| 1223 |
} |
| 1224 |
|
| 1225 |
std::vector<int> listIds; |
| 1226 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 1227 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::ClustListParser::parse: can not read an cluster id\n")); |
| 1228 |
f << "##clusterIds,"; |
| 1229 |
return false; |
| 1230 |
} |
| 1231 |
if (listIds[0]) { |
| 1232 |
m_clusterList.push_back(listIds[0]); |
| 1233 |
f << getClusterDebugName(listIds[0]) << ","; |
| 1234 |
} |
| 1235 |
if (fSz==12 || fSz==14) { |
| 1236 |
unsigned long lVal=input->readULong(4); // c00..small number |
| 1237 |
f << "f0=" << (lVal&0x3fffffff); |
| 1238 |
if ((lVal&0xc0000000)==0xc0000000) f << "*"; |
| 1239 |
else if (lVal&0xc0000000) f << ":" << (lVal>>30); |
| 1240 |
f << ","; |
| 1241 |
} |
| 1242 |
int num=fSz==12 ? 2 : 3; |
| 1243 |
for (int i=0; i<num; ++i) { // f3=1 if fSz==14, f1=0x200, f2=1 if fSz==12 |
| 1244 |
auto val=static_cast<int>(input->readLong(2)); |
| 1245 |
if (val) f << "f" << i+1 << "=" << val << ","; |
| 1246 |
} |
| 1247 |
return true; |
| 1248 |
} |
| 1249 |
|
| 1250 |
//! the list of read cluster |
| 1251 |
std::vector<int> m_clusterList; |
| 1252 |
private: |
| 1253 |
//! the main zone manager |
| 1254 |
RagTime5ClusterManager &m_clusterManager; |
| 1255 |
//! copy constructor, not implemented |
| 1256 |
ClustListParser(ClustListParser &orig) = delete; |
| 1257 |
//! copy operator, not implemented |
| 1258 |
ClustListParser &operator=(ClustListParser &orig) = delete; |
| 1259 |
}; |
| 1260 |
|
| 1261 |
ClustListParser::~ClustListParser() |
| 1262 |
{ |
| 1263 |
} |
| 1264 |
|
| 1265 |
//! Internal: the helper to read a block 2 list |
| 1266 |
struct BlockCellListParser final : public RagTime5StructManager::DataParser { |
| 1267 |
//! constructor |
| 1268 |
BlockCellListParser() |
| 1269 |
: RagTime5StructManager::DataParser("TextBlockCell") |
| 1270 |
, m_blockList() |
| 1271 |
{ |
| 1272 |
} |
| 1273 |
//! destructor |
| 1274 |
~BlockCellListParser() final; |
| 1275 |
//! try to parse a data |
| 1276 |
bool parseData(MWAWInputStreamPtr &input, long endPos, RagTime5Zone &/*zone*/, int /*n*/, libmwaw::DebugStream &f) final |
| 1277 |
{ |
| 1278 |
long pos=input->tell(); |
| 1279 |
long fSz=endPos-pos; |
| 1280 |
if (fSz!=20) { |
| 1281 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::BlockCellListParser::parse: bad data size\n")); |
| 1282 |
return false; |
| 1283 |
} |
| 1284 |
|
| 1285 |
Block block; |
| 1286 |
for (int &i : block.m_plc) i=static_cast<int>(input->readLong(4)); |
| 1287 |
if (block.m_plc[0]==0 && block.m_plc[1]==0) { |
| 1288 |
f << "empty,"; |
| 1289 |
m_blockList.push_back(block); |
| 1290 |
return true; |
| 1291 |
} |
| 1292 |
f << "PLC" << block.m_plc[0] << "<->" << block.m_plc[1] << ","; |
| 1293 |
libmwaw::DebugStream f2; |
| 1294 |
auto val=static_cast<int>(input->readULong(2)); |
| 1295 |
if (val) f2 << "fl=" << std::hex << val << std::dec << ","; |
| 1296 |
for (int i=0; i<2; ++i) { // f0=a|1e, f1=1-e, f2=[02][145] |
| 1297 |
val=static_cast<int>(input->readLong(2)); |
| 1298 |
if (val) f2 << "f" << i << "=" << val << ","; |
| 1299 |
} |
| 1300 |
auto fl=input->readULong(2); |
| 1301 |
if (fl) |
| 1302 |
f2 << "fl=" << std::hex << fl << std::dec << ","; |
| 1303 |
for (int i=0; i<4; ++i) { // f3=1-30, f6=1-5c |
| 1304 |
val=static_cast<int>(input->readLong(1)); |
| 1305 |
if (val) f2 << "f" << i+3 << "=" << val << ","; |
| 1306 |
} |
| 1307 |
f << f2.str(); |
| 1308 |
block.m_extra=f2.str(); |
| 1309 |
m_blockList.push_back(block); |
| 1310 |
return true; |
| 1311 |
} |
| 1312 |
|
| 1313 |
//! the list of block |
| 1314 |
std::vector<Block> m_blockList; |
| 1315 |
private: |
| 1316 |
//! copy constructor, not implemented |
| 1317 |
BlockCellListParser(BlockCellListParser &orig) = delete; |
| 1318 |
//! copy operator, not implemented |
| 1319 |
BlockCellListParser &operator=(BlockCellListParser &orig) = delete; |
| 1320 |
}; |
| 1321 |
|
| 1322 |
BlockCellListParser::~BlockCellListParser() |
| 1323 |
{ |
| 1324 |
} |
| 1325 |
|
| 1326 |
// |
| 1327 |
//! low level: parser of text cluster |
| 1328 |
// |
| 1329 |
struct TextCParser final : public RagTime5ClusterManager::ClusterParser { |
| 1330 |
enum { F_block, F_indexList, F_footnote, F_linkDefs=F_footnote+2, F_parentLink=F_linkDefs+5, F_nextId, F_plc, F_plcToStyle, F_text, F_textDefs, F_textRoot, F_textList, F_unknLongs=F_textList+3, F_unknData }; |
| 1331 |
|
| 1332 |
//! constructor |
| 1333 |
TextCParser(RagTime5ClusterManager &parser, int type, libmwaw::DebugFile &ascii) |
| 1334 |
: ClusterParser(parser, type, "ClustText") |
| 1335 |
, m_cluster(new ClusterText) |
| 1336 |
, m_expectedIdToType() |
| 1337 |
, m_NToBlockIdMap() |
| 1338 |
, m_fieldName("") |
| 1339 |
, m_asciiFile(ascii) |
| 1340 |
{ |
| 1341 |
} |
| 1342 |
//! destructor |
| 1343 |
~TextCParser() final; |
| 1344 |
//! return the current cluster |
| 1345 |
std::shared_ptr<RagTime5ClusterManager::Cluster> getCluster() final |
| 1346 |
{ |
| 1347 |
return m_cluster; |
| 1348 |
} |
| 1349 |
//! return the text cluster |
| 1350 |
std::shared_ptr<ClusterText> getTextCluster() |
| 1351 |
{ |
| 1352 |
return m_cluster; |
| 1353 |
} |
| 1354 |
//! end of a start zone call |
| 1355 |
void endZone() final |
| 1356 |
{ |
| 1357 |
if (m_link.empty()) |
| 1358 |
return; |
| 1359 |
auto const &it=m_expectedIdToType.find(m_dataId); |
| 1360 |
int expected=(it!=m_expectedIdToType.end())?it->second : -1; |
| 1361 |
switch (expected) { |
| 1362 |
case F_linkDefs: |
| 1363 |
case F_linkDefs+1: |
| 1364 |
case F_linkDefs+2: |
| 1365 |
case F_linkDefs+3: |
| 1366 |
case F_linkDefs+4: |
| 1367 |
if (m_cluster->m_linkDefs[expected-F_linkDefs].empty()) |
| 1368 |
m_cluster->m_linkDefs[expected-F_linkDefs]=m_link; |
| 1369 |
else { |
| 1370 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: parent link pos %d is already set\n", expected)); |
| 1371 |
m_cluster->m_linksList.push_back(m_link); |
| 1372 |
} |
| 1373 |
break; |
| 1374 |
case F_footnote: |
| 1375 |
if (m_cluster->m_footnoteLink.empty()) |
| 1376 |
m_cluster->m_footnoteLink=m_link; |
| 1377 |
else { |
| 1378 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: footnote link is already set\n")); |
| 1379 |
m_cluster->m_linksList.push_back(m_link); |
| 1380 |
} |
| 1381 |
break; |
| 1382 |
case F_indexList: |
| 1383 |
if (m_cluster->m_indexLink.empty()) |
| 1384 |
m_cluster->m_indexLink=m_link; |
| 1385 |
else { |
| 1386 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: index link is already set\n")); |
| 1387 |
m_cluster->m_linksList.push_back(m_link); |
| 1388 |
} |
| 1389 |
break; |
| 1390 |
case F_parentLink: |
| 1391 |
if (m_cluster->m_parentLink.empty()) |
| 1392 |
m_cluster->m_parentLink=m_link; |
| 1393 |
else { |
| 1394 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: parent link is already set\n")); |
| 1395 |
m_cluster->m_linksList.push_back(m_link); |
| 1396 |
} |
| 1397 |
break; |
| 1398 |
case F_plcToStyle: |
| 1399 |
if (m_cluster->m_plcToStyleLink.empty()) |
| 1400 |
m_cluster->m_plcToStyleLink=m_link; |
| 1401 |
else { |
| 1402 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: link plcToTextStyle is already set\n")); |
| 1403 |
m_cluster->m_linksList.push_back(m_link); |
| 1404 |
} |
| 1405 |
break; |
| 1406 |
case F_plc: |
| 1407 |
if (m_cluster->m_plcDefLink.empty()) |
| 1408 |
m_cluster->m_plcDefLink=m_link; |
| 1409 |
else { |
| 1410 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: link plcDef is already set\n")); |
| 1411 |
m_cluster->m_linksList.push_back(m_link); |
| 1412 |
} |
| 1413 |
break; |
| 1414 |
case F_textList+2: |
| 1415 |
if (m_cluster->m_textIntListLink.empty()) |
| 1416 |
m_cluster->m_textIntListLink=m_link; |
| 1417 |
else { |
| 1418 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: link text int list is already set\n")); |
| 1419 |
m_cluster->m_linksList.push_back(m_link); |
| 1420 |
} |
| 1421 |
break; |
| 1422 |
case F_unknData+1: |
| 1423 |
m_cluster->m_unknownLinks1.push_back(m_link); |
| 1424 |
break; |
| 1425 |
case F_unknData+2: |
| 1426 |
case F_unknData+3: |
| 1427 |
if (m_cluster->m_unknownLink[expected-F_unknData-2].empty()) |
| 1428 |
m_cluster->m_unknownLink[expected-F_unknData-2]=m_link; |
| 1429 |
else { |
| 1430 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::endZone: unknown link %d is already set\n", expected)); |
| 1431 |
m_cluster->m_linksList.push_back(m_link); |
| 1432 |
} |
| 1433 |
break; |
| 1434 |
default: |
| 1435 |
m_cluster->m_linksList.push_back(m_link); |
| 1436 |
break; |
| 1437 |
} |
| 1438 |
} |
| 1439 |
//! parse a zone |
| 1440 |
bool parseZone(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) final |
| 1441 |
{ |
| 1442 |
m_fieldName=""; |
| 1443 |
if (m_dataId==0) |
| 1444 |
return parseHeaderZone(input,fSz,N,flag,f); |
| 1445 |
|
| 1446 |
auto const &it=m_expectedIdToType.find(m_dataId); |
| 1447 |
int expected=(it!=m_expectedIdToType.end())?it->second : -1; |
| 1448 |
if (expected!=-1) |
| 1449 |
f << "[F" << m_dataId << "]"; |
| 1450 |
/* |
| 1451 |
normally the header is followed by num[zones] or less but sometimes block zone happens after other zones, |
| 1452 |
so just test also fSz. |
| 1453 |
*/ |
| 1454 |
if (expected==F_block || fSz==80) { |
| 1455 |
return parseZoneBlock(input,fSz,N,flag,f); |
| 1456 |
} |
| 1457 |
if (N<0) { |
| 1458 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: expected N value\n")); |
| 1459 |
f << "###N=" << N << ","; |
| 1460 |
return true; |
| 1461 |
} |
| 1462 |
return parseDataZone(input, fSz, N, flag, f); |
| 1463 |
} |
| 1464 |
//! parse a field |
| 1465 |
bool parseField(RagTime5StructManager::Field const &field, int /*m*/, libmwaw::DebugStream &f) final |
| 1466 |
{ |
| 1467 |
if (!m_fieldName.empty()) |
| 1468 |
f << m_fieldName << ","; |
| 1469 |
if (m_dataId==0) { |
| 1470 |
if (field.m_type==RagTime5StructManager::Field::T_FieldList && field.m_fileType==0x15e0825) { |
| 1471 |
for (auto const &child : field.m_fieldList) { |
| 1472 |
if (child.m_type==RagTime5StructManager::Field::T_LongList && child.m_fileType==0xd7842) { |
| 1473 |
if ((child.m_longList.size()%3)!=0) { |
| 1474 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: block def child seen bad\n")); |
| 1475 |
f << "###blockDef[sz]=" << child.m_longList.size() << ","; |
| 1476 |
} |
| 1477 |
size_t N=child.m_longList.size()/3; |
| 1478 |
m_cluster->m_blockList.resize(N); |
| 1479 |
f << "blockDef=["; |
| 1480 |
for (size_t b=0; b<N; ++b) { |
| 1481 |
if (child.m_longList[3*b]==0) { |
| 1482 |
f << "_,"; |
| 1483 |
continue; |
| 1484 |
} |
| 1485 |
auto id=int(child.m_longList[3*b]-1); |
| 1486 |
m_expectedIdToType[id]=F_block; |
| 1487 |
if (m_NToBlockIdMap.find(id)!=m_NToBlockIdMap.end()) { |
| 1488 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: block pos is already set\n")); |
| 1489 |
f << "#"; |
| 1490 |
} |
| 1491 |
else |
| 1492 |
m_NToBlockIdMap[id]=b; |
| 1493 |
f << "F" << child.m_longList[3*b]-1; |
| 1494 |
for (size_t j=1; j<3; ++j) { |
| 1495 |
if (child.m_longList[3*b+j]) f << ":" << child.m_longList[3*b+j]; |
| 1496 |
else f << ":_"; |
| 1497 |
} |
| 1498 |
f << ","; |
| 1499 |
} |
| 1500 |
f << "],"; |
| 1501 |
continue; |
| 1502 |
} |
| 1503 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected unkn child[header]\n")); |
| 1504 |
f << "####[" << child << "],"; |
| 1505 |
} |
| 1506 |
} |
| 1507 |
else if (field.m_type==RagTime5StructManager::Field::T_LongList && field.m_fileType==0x3c057) { |
| 1508 |
for (auto const &id : field.m_longList) { |
| 1509 |
if (id) { |
| 1510 |
m_expectedIdToType[int(id-1)]=F_unknData; |
| 1511 |
f << "unknData=F" << id-1 << ","; |
| 1512 |
} |
| 1513 |
else |
| 1514 |
f << "unkn0=" << id << ","; |
| 1515 |
} |
| 1516 |
} |
| 1517 |
// extended header |
| 1518 |
else if (field.m_type==RagTime5StructManager::Field::T_FieldList && field.m_fileType==0x15f9015) { |
| 1519 |
f << "unknExt=["; |
| 1520 |
for (auto const &child : field.m_fieldList) { |
| 1521 |
if (child.m_type==RagTime5StructManager::Field::T_Unstructured && child.m_fileType==0xce017) { |
| 1522 |
f << "unkn="<<child.m_extra << ","; |
| 1523 |
continue; |
| 1524 |
} |
| 1525 |
if (child.m_type==RagTime5StructManager::Field::T_FieldList && child.m_fileType==0x15f6815) { |
| 1526 |
for (auto const &child2 : child.m_fieldList) { |
| 1527 |
if (child2.m_type==RagTime5StructManager::Field::T_Unstructured && child2.m_fileType==0xce017) { |
| 1528 |
f << "unkn15f6815="<<child2.m_extra << ","; |
| 1529 |
continue; |
| 1530 |
} |
| 1531 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected unkn child2[header]\n")); |
| 1532 |
f << "###"<<child2.m_extra << ","; |
| 1533 |
} |
| 1534 |
continue; |
| 1535 |
} |
| 1536 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected unkn child[header]\n")); |
| 1537 |
f << "####[" << child << "],"; |
| 1538 |
} |
| 1539 |
f << "],"; |
| 1540 |
} |
| 1541 |
else { |
| 1542 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected header field\n")); |
| 1543 |
f << "###" << field; |
| 1544 |
} |
| 1545 |
return true; |
| 1546 |
} |
| 1547 |
auto const &it=m_expectedIdToType.find(m_dataId); |
| 1548 |
int expected=(it!=m_expectedIdToType.end())?it->second : -1; |
| 1549 |
switch (expected) { |
| 1550 |
case F_plc: |
| 1551 |
if (field.m_type==RagTime5StructManager::Field::T_2Long && field.m_fileType==0x15e3017) { |
| 1552 |
f << "unk=" << field.m_longValue[0] << "x" << field.m_longValue[1] << ","; |
| 1553 |
break; |
| 1554 |
} |
| 1555 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected plc link field\n")); |
| 1556 |
f << "###" << field; |
| 1557 |
break; |
| 1558 |
case F_linkDefs: |
| 1559 |
case F_linkDefs+1: |
| 1560 |
case F_linkDefs+2: |
| 1561 |
case F_linkDefs+3: |
| 1562 |
case F_linkDefs+4: |
| 1563 |
if (field.m_type==RagTime5StructManager::Field::T_FieldList && |
| 1564 |
(field.m_fileType==0x15f4815 /* v5?*/ || field.m_fileType==0x160f815 /* v6? */)) { |
| 1565 |
f << "decal=["; |
| 1566 |
for (auto const &child : field.m_fieldList) { |
| 1567 |
if (child.m_type==RagTime5StructManager::Field::T_LongList && child.m_fileType==0xce842) { |
| 1568 |
for (auto val : child.m_longList) |
| 1569 |
f << val << ","; |
| 1570 |
m_link.m_longList=child.m_longList; |
| 1571 |
continue; |
| 1572 |
} |
| 1573 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected decal child[linkDefs]\n")); |
| 1574 |
f << "#[" << child << "],"; |
| 1575 |
} |
| 1576 |
f << "],"; |
| 1577 |
break; |
| 1578 |
} |
| 1579 |
else if (field.m_type==RagTime5StructManager::Field::T_FieldList && field.m_fileType==0x15f4015) { |
| 1580 |
f << "id=["; |
| 1581 |
for (auto const &child : field.m_fieldList) { |
| 1582 |
if (child.m_type==RagTime5StructManager::Field::T_Unstructured && child.m_fileType==0xce017) { |
| 1583 |
f << "unkn0=" << field.m_longValue[0] << field.m_extra; // id to ? |
| 1584 |
continue; |
| 1585 |
} |
| 1586 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected id child[linkDefs]\n")); |
| 1587 |
f << "#[" << child << "],"; |
| 1588 |
} |
| 1589 |
f << "],"; |
| 1590 |
break; |
| 1591 |
} |
| 1592 |
else if (field.m_type==RagTime5StructManager::Field::T_Unstructured && field.m_fileType==0xce017) { |
| 1593 |
f << "unkn0=" << field.m_longValue[0] << field.m_extra; // id to a fSz=0x31 zone |
| 1594 |
break; |
| 1595 |
} |
| 1596 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected child[linkDefs]\n")); |
| 1597 |
f << "###" << field; |
| 1598 |
break; |
| 1599 |
case F_indexList: |
| 1600 |
case F_parentLink: |
| 1601 |
case F_textList: |
| 1602 |
case F_textList+1: |
| 1603 |
case F_unknData+2: |
| 1604 |
case F_unknData+3: |
| 1605 |
if (field.m_type==RagTime5StructManager::Field::T_LongList && field.m_fileType==0xce842) { |
| 1606 |
f << "pos=["; |
| 1607 |
for (auto val : field.m_longList) |
| 1608 |
f << val << ","; |
| 1609 |
f << "],"; |
| 1610 |
m_link.m_longList=field.m_longList; |
| 1611 |
break; |
| 1612 |
} |
| 1613 |
if (field.m_type==RagTime5StructManager::Field::T_Unstructured && field.m_fileType==0xce017) { |
| 1614 |
// 1,2 |
| 1615 |
f << "unkn=" << field.m_longValue[0] <<field.m_extra << ","; |
| 1616 |
break; |
| 1617 |
} |
| 1618 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected child[clustList]\n")); |
| 1619 |
f << "###" << field; |
| 1620 |
break; |
| 1621 |
case F_textDefs: // list of id |
| 1622 |
case F_unknLongs: |
| 1623 |
if (field.m_type==RagTime5StructManager::Field::T_LongList && field.m_fileType==0xcf042) { |
| 1624 |
f << "unkn=["; |
| 1625 |
for (auto val : field.m_longList) { |
| 1626 |
if (val==0) |
| 1627 |
f << "_,"; |
| 1628 |
else |
| 1629 |
f << val << ","; |
| 1630 |
} |
| 1631 |
break; |
| 1632 |
} |
| 1633 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected child[textDefs]\n")); |
| 1634 |
f << "###" << field; |
| 1635 |
break; |
| 1636 |
default: |
| 1637 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseField: find unexpected field %d\n", expected)); |
| 1638 |
f << "###" << field; |
| 1639 |
break; |
| 1640 |
} |
| 1641 |
return true; |
| 1642 |
} |
| 1643 |
protected: |
| 1644 |
//! parse a data block |
| 1645 |
bool parseDataZone(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) |
| 1646 |
{ |
| 1647 |
f << "fl=" << std::hex << flag << std::dec << ","; |
| 1648 |
auto const &it=m_expectedIdToType.find(m_dataId); |
| 1649 |
int expected=(it!=m_expectedIdToType.end())?it->second : -1; |
| 1650 |
|
| 1651 |
m_link.m_N=N; |
| 1652 |
int val; |
| 1653 |
long linkValues[4]; |
| 1654 |
std::string mess(""); |
| 1655 |
|
| 1656 |
switch (expected) { |
| 1657 |
case F_footnote: |
| 1658 |
case F_linkDefs+2: |
| 1659 |
case F_linkDefs+3: |
| 1660 |
case F_linkDefs+4: |
| 1661 |
case F_parentLink: |
| 1662 |
case F_plc: |
| 1663 |
case F_plcToStyle: |
| 1664 |
case F_textDefs: |
| 1665 |
case F_textList: |
| 1666 |
case F_textList+1: |
| 1667 |
case F_textList+2: |
| 1668 |
case F_unknData+1: |
| 1669 |
case F_unknData+2: // related to column |
| 1670 |
case F_unknData+3: { // related to colum ? |
| 1671 |
if (fSz<28 || !readLinkHeader(input, fSz, m_link, linkValues, mess)) { |
| 1672 |
f << "###fType=" << RagTime5Text::printType(m_link.m_fileType[0]) << ","; |
| 1673 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 1674 |
return true; |
| 1675 |
} |
| 1676 |
f << m_link << "," << mess; |
| 1677 |
long expectedFileType1=0, expectedFieldSize=0; |
| 1678 |
if (expected==F_parentLink && fSz>=36) { |
| 1679 |
if (m_link.m_fileType[0]) { |
| 1680 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected file type0\n")); |
| 1681 |
f << "###type0"; |
| 1682 |
} |
| 1683 |
expectedFileType1=0x10; |
| 1684 |
m_link.m_name="textParentLst"; |
| 1685 |
m_link.m_type=RagTime5ClusterManager::Link::L_ClusterLink; |
| 1686 |
for (int i=0; i<2; ++i) { // small value between 3e and 74 some data id ? |
| 1687 |
val=static_cast<int>(input->readLong(2)); |
| 1688 |
if (val) f << "g" << i << "=" << val << ","; |
| 1689 |
} |
| 1690 |
} |
| 1691 |
else if (((expected>=F_linkDefs+2 && expected<=F_linkDefs+4) || expected==F_footnote) && fSz>=39) { |
| 1692 |
if (linkValues[3]!=0x15f3817) { // fSz=39 |
| 1693 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected link type\n")); |
| 1694 |
f << "###values3"; |
| 1695 |
} |
| 1696 |
// fieldSize=12|16 |
| 1697 |
expectedFileType1=expected==F_footnote ? 0x43 : 0x50; |
| 1698 |
if (expected==F_footnote) |
| 1699 |
m_link.m_name="footnote"; |
| 1700 |
else |
| 1701 |
m_link.m_name=expected==F_linkDefs+2 ? "linkDef2" : expected==F_linkDefs+3 ? "linkIndex" : "linkField"; |
| 1702 |
val=static_cast<int>(input->readLong(4)); // 1|8 |
| 1703 |
if (val) f << "g0=" << val << ","; |
| 1704 |
for (int i=0; i<3; ++i) { // g1=language[0:US,7:UK,9:croatian...], g2=1, linkIndex: g2=9 |
| 1705 |
val=static_cast<int>(input->readLong(i==2 ? 1 : 2)); |
| 1706 |
if (!val) |
| 1707 |
continue; |
| 1708 |
f << "g" << i+1 << "=" << val << ","; |
| 1709 |
} |
| 1710 |
} |
| 1711 |
else if (expected==F_plc && fSz>=52) { |
| 1712 |
if (m_link.m_fileType[0]!=0 || m_link.m_fieldSize!=6) { |
| 1713 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected plc file type\n")); |
| 1714 |
f << "###plc"; |
| 1715 |
} |
| 1716 |
expectedFileType1=0; |
| 1717 |
m_link.m_name="plc"; |
| 1718 |
for (int i=0; i<5; ++i) { // g2=0 maybe an 2xint other small number |
| 1719 |
val=static_cast<int>(input->readLong(4)); |
| 1720 |
switch (i) { |
| 1721 |
case 0: |
| 1722 |
if (m_cluster->m_plcDefFreeBegin) { |
| 1723 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: the plc root is already set\n")); |
| 1724 |
f << "###"; |
| 1725 |
} |
| 1726 |
else |
| 1727 |
m_cluster->m_plcDefFreeBegin=val; |
| 1728 |
f << "free[rootId]=" << val << ","; |
| 1729 |
break; |
| 1730 |
case 4: |
| 1731 |
if (m_cluster->m_plcDefNumFree<0) |
| 1732 |
m_cluster->m_plcDefNumFree=val; |
| 1733 |
f << "free[num]=" << val << ","; |
| 1734 |
break; |
| 1735 |
default: |
| 1736 |
if (val) f << "g" << i << "=" << val << ","; |
| 1737 |
break; |
| 1738 |
} |
| 1739 |
} |
| 1740 |
val=static_cast<int>(input->readLong(2)); // always 1 |
| 1741 |
if (val!=1) |
| 1742 |
f << "g5=" << val << ","; |
| 1743 |
} |
| 1744 |
else if (expected==F_plcToStyle && fSz==34) { |
| 1745 |
if (m_link.m_fieldSize!=6 || linkValues[3]!=0x15e4817) { |
| 1746 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected file type1\n")); |
| 1747 |
f << "###type"; |
| 1748 |
} |
| 1749 |
m_link.m_name="plcToCStyle"; |
| 1750 |
expectedFileType1=0x47; |
| 1751 |
val=static_cast<int>(input->readLong(4)); // always 1 |
| 1752 |
if (val!=1) f << "g0=" << val << ","; |
| 1753 |
} |
| 1754 |
else if (expected==F_textDefs && m_link.m_fileType[0]==0x3c052 && fSz>=41) { // fSz==41|46 |
| 1755 |
m_link.m_name="textDefs"; |
| 1756 |
expectedFileType1=0x40; |
| 1757 |
val=static_cast<int>(input->readLong(1)); // always 1 |
| 1758 |
if (val!=1) f << "g0=" << val << ","; |
| 1759 |
if (fSz>41) { |
| 1760 |
f << "#extra,"; |
| 1761 |
input->seek(fSz-41, librevenge::RVNG_SEEK_CUR); |
| 1762 |
} |
| 1763 |
// first g2, g3 are ids to textZone and plc |
| 1764 |
for (int i=0; i<3; ++i) { // g1=1, g3=g2+1 |
| 1765 |
val=static_cast<int>(input->readLong(4)); |
| 1766 |
if (!val) |
| 1767 |
continue; |
| 1768 |
if (i==1) { |
| 1769 |
m_expectedIdToType[int(val-1)]=F_text; |
| 1770 |
f << "textZone=F" << val-1 << ","; |
| 1771 |
} |
| 1772 |
else if (i==2) { |
| 1773 |
m_expectedIdToType[int(val-1)]=F_plc; |
| 1774 |
f << "plc=F" << val-1 << ","; |
| 1775 |
} |
| 1776 |
else |
| 1777 |
f << "g" << i+1 << "=" << val << ","; |
| 1778 |
} |
| 1779 |
// in unkn0, id to textZone |
| 1780 |
} |
| 1781 |
else if (expected==F_unknData+1 && fSz>=39) { |
| 1782 |
expectedFileType1=0x47; |
| 1783 |
m_link.m_name="unknData1"; |
| 1784 |
for (int i=0; i<3; ++i) { // g0=probably previous |
| 1785 |
val=static_cast<int>(input->readLong(i==2 ? 1 : 4)); |
| 1786 |
if (val) f << "g" << i << "=" << val << ","; |
| 1787 |
} |
| 1788 |
} |
| 1789 |
else if (expected==F_unknData+2 && fSz==32) { |
| 1790 |
expectedFileType1=0x210; |
| 1791 |
m_link.m_name="TextUnknData2"; |
| 1792 |
} |
| 1793 |
else if (expected==F_unknData+3 && fSz==32) { |
| 1794 |
expectedFileType1=0x10; |
| 1795 |
m_link.m_name="TextUnknData3"; |
| 1796 |
} |
| 1797 |
// v6.5 |
| 1798 |
else if (expected==F_textList && m_link.m_fileType[0]==0x3e800) |
| 1799 |
m_link.m_name="textList0"; |
| 1800 |
else if (expected==F_textList+1 && m_link.m_fileType[0]==0x35800) |
| 1801 |
m_link.m_name="textList1"; |
| 1802 |
else if (expected==F_textList+2 && m_link.m_fileType[0]==0x45080) { |
| 1803 |
m_link.m_name="textListInt"; |
| 1804 |
expectedFieldSize=2; |
| 1805 |
} |
| 1806 |
else { |
| 1807 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 1808 |
f << "###"; |
| 1809 |
} |
| 1810 |
if (!m_link.m_name.empty()) { |
| 1811 |
m_fieldName=m_link.m_name; |
| 1812 |
f << m_link.m_name << ","; |
| 1813 |
} |
| 1814 |
if (expectedFileType1>0 && long(m_link.m_fileType[1]&0xFFD7)!=expectedFileType1) { |
| 1815 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: the expected field[%d] fileType1 seems odd\n", expected)); |
| 1816 |
f << "###fileType1=" << std::hex << m_link.m_fileType[1] << std::dec << ","; |
| 1817 |
} |
| 1818 |
if (expectedFieldSize>0 && m_link.m_fieldSize!=expectedFieldSize) { |
| 1819 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: fieldSize seems odd[%d]\n", expected)); |
| 1820 |
f << "###fieldSize,"; |
| 1821 |
} |
| 1822 |
return true; |
| 1823 |
} |
| 1824 |
case F_linkDefs: // fSz=69 attachment |
| 1825 |
case F_linkDefs+1: { // fSz=71 |
| 1826 |
m_fieldName=(expected==F_linkDefs ? "attachmentLink" : "itemLink"); |
| 1827 |
f << m_fieldName << ","; |
| 1828 |
if (fSz<69) { |
| 1829 |
f << "##fSz,"; |
| 1830 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected size\n")); |
| 1831 |
return true; |
| 1832 |
} |
| 1833 |
if (!readLinkHeader(input, fSz, m_link, linkValues, mess)) { |
| 1834 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: can not read the link position field\n")); |
| 1835 |
f << "###link"; |
| 1836 |
return true; |
| 1837 |
} |
| 1838 |
if (linkValues[3]==0x15f3817) { |
| 1839 |
if ((m_link.m_fileType[1]&0xFFF7)!=0x43 && (m_link.m_fileType[1]&0xFFF7)!=0x50) { |
| 1840 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: fileType1 seems odd\n")); |
| 1841 |
f << "###fileType1,"; |
| 1842 |
} |
| 1843 |
m_link.m_name="linkDef"; |
| 1844 |
} |
| 1845 |
else { |
| 1846 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected field\n")); |
| 1847 |
m_fieldName="##unknown"; |
| 1848 |
} |
| 1849 |
f << m_link << "," << mess; |
| 1850 |
for (int i=0; i<2; ++i) { // g0=1, g1=2,b,c |
| 1851 |
val=static_cast<int>(input->readLong(4)); |
| 1852 |
if (val) f << "g" << i << "=" << val << ","; |
| 1853 |
} |
| 1854 |
val=static_cast<int>(input->readLong(1)); // always 0 |
| 1855 |
if (val) f << "g2=" << val << ","; |
| 1856 |
val=static_cast<int>(input->readLong(2)); // always 0 |
| 1857 |
if (val!=0x10) f << "g3=" << val << ","; |
| 1858 |
val=static_cast<int>(input->readLong(4)); // 1,3, 5 |
| 1859 |
if (val) f << "g3=" << val << ","; |
| 1860 |
RagTime5ClusterManager::Link link2; |
| 1861 |
mess=""; |
| 1862 |
if (!readLinkHeader(input, fSz, link2, linkValues, mess)) { |
| 1863 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: can not read the link second field\n")); |
| 1864 |
f << "###link2"; |
| 1865 |
return true; |
| 1866 |
} |
| 1867 |
if (fSz==69 && link2.m_fieldSize==12) |
| 1868 |
m_cluster->m_childLink=link2; |
| 1869 |
else if (fSz==71 && link2.m_ids.size()==2) { |
| 1870 |
// FIXME: store directly the field pos and set link2 as main link |
| 1871 |
m_link.m_ids.push_back(link2.m_ids[0]); |
| 1872 |
m_link.m_ids.push_back(link2.m_ids[1]); |
| 1873 |
} |
| 1874 |
else if (!link2.empty()) { |
| 1875 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: can not find the second link field\n")); |
| 1876 |
f << "###"; |
| 1877 |
m_cluster->m_linksList.push_back(link2); |
| 1878 |
} |
| 1879 |
f << "link2=[" << link2 << "]," << mess; |
| 1880 |
return true; |
| 1881 |
} |
| 1882 |
case F_text: { |
| 1883 |
f << "textZone,"; |
| 1884 |
if (fSz<28) { |
| 1885 |
f << "##fSz,"; |
| 1886 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected size\n")); |
| 1887 |
return true; |
| 1888 |
} |
| 1889 |
val=static_cast<int>(input->readULong(2)); |
| 1890 |
if (val!=0x10) { |
| 1891 |
f << "##fType=" << std::hex << val << std::dec << ","; |
| 1892 |
} |
| 1893 |
m_fieldName="textZone"; |
| 1894 |
val=static_cast<int>(input->readULong(2)); |
| 1895 |
if (val!=4) { |
| 1896 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: the first value\n")); |
| 1897 |
f << "##f0=" << val << ","; |
| 1898 |
} |
| 1899 |
val=static_cast<int>(input->readLong(2)); // always 0? |
| 1900 |
if (val) f << "f1=" << val << ","; |
| 1901 |
val=static_cast<int>(input->readLong(2)); // always f? |
| 1902 |
if (val!=15) f << "f2=" << val << ","; |
| 1903 |
std::vector<int> listIds; |
| 1904 |
if (RagTime5StructManager::readDataIdList(input, 1, listIds) && listIds[0]) { |
| 1905 |
if (!m_cluster->m_separatorLink.m_ids.empty()) { |
| 1906 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: oops the text separator is already set\n")); |
| 1907 |
f << "###"; |
| 1908 |
} |
| 1909 |
m_cluster->m_separatorLink.m_ids.push_back(static_cast<int>(listIds[0])); |
| 1910 |
f << "textSep=data" << listIds[0] << "A,"; |
| 1911 |
} |
| 1912 |
else { |
| 1913 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: can not read the text separator\n")); |
| 1914 |
f << "##textSeparator,"; |
| 1915 |
} |
| 1916 |
m_link.m_N=static_cast<int>(input->readULong(4)); |
| 1917 |
val=static_cast<int>(input->readLong(1)); // always 0? |
| 1918 |
if (val) f << "f3=" << val << ","; |
| 1919 |
listIds.clear(); |
| 1920 |
if (RagTime5StructManager::readDataIdList(input, 1, listIds) && listIds[0]) { |
| 1921 |
if (!m_cluster->m_contentLink.m_ids.empty()) { |
| 1922 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: oops the text content is already set\n")); |
| 1923 |
f << "###"; |
| 1924 |
} |
| 1925 |
m_cluster->m_contentLink.m_ids.push_back(listIds[0]); |
| 1926 |
f << "content=data" << listIds[0] << "A,"; |
| 1927 |
} |
| 1928 |
else { |
| 1929 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: can not read the text content\n")); |
| 1930 |
f << "##textContent,"; |
| 1931 |
} |
| 1932 |
val=static_cast<int>(input->readLong(1)); // always 1? |
| 1933 |
if (val) f << "f4=" << val << ","; |
| 1934 |
f << m_link; |
| 1935 |
return true; |
| 1936 |
} |
| 1937 |
case F_footnote+1: { // checkme, seens rarely with no data... |
| 1938 |
f << "footnote1,"; |
| 1939 |
if (fSz<106) { |
| 1940 |
f << "###fSz,"; |
| 1941 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 1942 |
return true; |
| 1943 |
} |
| 1944 |
for (int i=0; i<8; ++i) { // f1=1, f2=17, f4=2048, |
| 1945 |
val=static_cast<int>(input->readLong(2)); |
| 1946 |
if (val) f << "f" << i << "=" << val << ","; |
| 1947 |
} |
| 1948 |
for (int i=0; i<6; ++i) { //some dim ? dim0=dim4=712,dim1=dim5=532,dim3=517, |
| 1949 |
val=static_cast<int>(input->readLong(4)); |
| 1950 |
if (val) f << "dim" << i << "=" << val << ","; |
| 1951 |
} |
| 1952 |
for (int i=0; i<7; ++i) { // f2=2 |
| 1953 |
val=static_cast<int>(input->readLong(2)); |
| 1954 |
if (val) f << "g" << i << "=" << val << ","; |
| 1955 |
} |
| 1956 |
for (int i=0; i<2; ++i) { //some dim ? dim6=121,dim7=74 |
| 1957 |
val=static_cast<int>(input->readLong(4)); |
| 1958 |
if (val) f << "dim" << i+6 << "=" << val << ","; |
| 1959 |
} |
| 1960 |
for (int i=0; i<9; ++i) { // h7=1,h8=1, |
| 1961 |
val=static_cast<int>(input->readLong(2)); |
| 1962 |
if (val) f << "h" << i << "=" << val << ","; |
| 1963 |
} |
| 1964 |
// then 02050000000e4000020500000205000000000000 |
| 1965 |
return true; |
| 1966 |
} |
| 1967 |
case F_unknData: { // checkme, seens rarely with no data... |
| 1968 |
if (fSz<49) { |
| 1969 |
f << "###fSz,"; |
| 1970 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: the expected field[%d] seems bad\n", expected)); |
| 1971 |
return true; |
| 1972 |
} |
| 1973 |
f << "unknData0,"; |
| 1974 |
for (int i=0; i<6; ++i) { // f3=1, f4=1c |
| 1975 |
val=static_cast<int>(input->readLong(2)); |
| 1976 |
if (val) f << "f" << i << "=" << val << ","; |
| 1977 |
} |
| 1978 |
auto type=input->readULong(4); |
| 1979 |
if (type!=0x15e0842) { |
| 1980 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: fileType0 seems odd\n")); |
| 1981 |
f << "###fileType0=" << RagTime5Text::printType(type) << ","; |
| 1982 |
} |
| 1983 |
for (int i=0; i<4; ++i) { // f6=1, f7=1|2 |
| 1984 |
val=static_cast<int>(input->readLong(2)); |
| 1985 |
if (val) f << "f" << i+6 << "=" << val << ","; |
| 1986 |
} |
| 1987 |
for (int i=0; i<3; ++i) { |
| 1988 |
val=static_cast<int>(input->readLong(4)); |
| 1989 |
if (!val) continue; |
| 1990 |
if (i==0) { |
| 1991 |
m_expectedIdToType[int(val-1)]=F_unknData+1; |
| 1992 |
f << "unknData1=F" << val-1 << ","; |
| 1993 |
} |
| 1994 |
else |
| 1995 |
f << "g" << i << "=" << val << ","; |
| 1996 |
} |
| 1997 |
for (int i=0; i<3; ++i) { // g3: big number, g5=2|3 |
| 1998 |
val=static_cast<int>(input->readLong(2)); |
| 1999 |
if (val) f << "g" << i+3 << "=" << val << ","; |
| 2000 |
} |
| 2001 |
val=static_cast<int>(input->readLong(1)); // always 0? |
| 2002 |
if (val) f << "g7=" << val << ","; |
| 2003 |
return true; |
| 2004 |
} |
| 2005 |
case F_block: |
| 2006 |
case F_nextId: |
| 2007 |
case F_indexList: |
| 2008 |
case F_textRoot: |
| 2009 |
case F_unknLongs: |
| 2010 |
default: |
| 2011 |
break; |
| 2012 |
} |
| 2013 |
if (expected==-1) { |
| 2014 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::PictCParser::parseDataZone: find unexpected field\n")); |
| 2015 |
f << "###field,"; |
| 2016 |
} |
| 2017 |
switch (fSz) { |
| 2018 |
case 29: // unknLong0 |
| 2019 |
case 44: { // indexlist |
| 2020 |
if (!readLinkHeader(input, fSz, m_link, linkValues, mess)) { |
| 2021 |
f << "###fType=" << RagTime5Text::printType(m_link.m_fileType[0]) << ","; |
| 2022 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: the expected field[%d] seems bad\n", m_dataId)); |
| 2023 |
return true; |
| 2024 |
} |
| 2025 |
f << m_link << "," << mess; |
| 2026 |
long expectedFileType1=0; |
| 2027 |
if (fSz==44 && linkValues[0]==0x1484017) { |
| 2028 |
if (m_link.m_fileType[0]) { |
| 2029 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unexpected file type0\n")); |
| 2030 |
f << "###type0"; |
| 2031 |
} |
| 2032 |
expectedFileType1=0x10; |
| 2033 |
m_link.m_name="textIndexData"; |
| 2034 |
m_expectedIdToType[m_dataId]=F_indexList; |
| 2035 |
for (int i=0; i<2; ++i) { // g0=1 |
| 2036 |
val=static_cast<int>(input->readLong(2)); |
| 2037 |
if (val) f << "g" << i << "=" << val << ","; |
| 2038 |
} |
| 2039 |
for (int i=0; i<2; ++i) { |
| 2040 |
val=static_cast<int>(input->readLong(4)); |
| 2041 |
if (!val) continue; |
| 2042 |
m_expectedIdToType[int(val-1)]=F_unknData+2+i; |
| 2043 |
f << "unknData" << i+2 << "=F" << val-1 << ","; |
| 2044 |
} |
| 2045 |
} |
| 2046 |
else if (fSz==29 && m_link.m_fileType[0]==0x3c052) { // v5-v6.5 |
| 2047 |
m_expectedIdToType[m_dataId]=F_unknLongs; |
| 2048 |
m_link.m_name="unknLongs0"; |
| 2049 |
expectedFileType1=0x50; |
| 2050 |
val=int(input->readLong(1)); |
| 2051 |
if (val!=1) f << "g0=" << val << ","; |
| 2052 |
} |
| 2053 |
else { |
| 2054 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: unknow field[%d]\n", m_dataId)); |
| 2055 |
f << "###field,"; |
| 2056 |
} |
| 2057 |
if (linkValues[2]) { |
| 2058 |
m_expectedIdToType[int(linkValues[2]-1)]=F_nextId; |
| 2059 |
f << "nextId=F" << linkValues[2]-1 << ","; |
| 2060 |
} |
| 2061 |
if (!m_link.m_name.empty()) { |
| 2062 |
m_fieldName=m_link.m_name; |
| 2063 |
f << m_link.m_name << ","; |
| 2064 |
} |
| 2065 |
if (expectedFileType1>0 && long(m_link.m_fileType[1]&0xFFD7)!=expectedFileType1) { |
| 2066 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: the expected field[%d] fileType1 seems odd\n", expected)); |
| 2067 |
f << "###fileType1=" << std::hex << m_link.m_fileType[1] << std::dec << ","; |
| 2068 |
} |
| 2069 |
return true; |
| 2070 |
} |
| 2071 |
case 36: { // v6.6 |
| 2072 |
m_fieldName="textList[root]"; |
| 2073 |
m_expectedIdToType[m_dataId]=F_textRoot; |
| 2074 |
f << m_fieldName << ","; |
| 2075 |
val=static_cast<int>(input->readLong(4)); |
| 2076 |
if (val) f << "#f0=" << val << ","; |
| 2077 |
val=static_cast<int>(input->readLong(4)); |
| 2078 |
if (val!=0x17db042) { |
| 2079 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: find unexpected type0\n")); |
| 2080 |
f << "#fileType0=" << std::hex << val << std::dec << ","; |
| 2081 |
} |
| 2082 |
for (int i=0; i<2; ++i) { |
| 2083 |
val=static_cast<int>(input->readLong(4)); |
| 2084 |
if (val) f << "f" << i+1 << "=" << val << ","; |
| 2085 |
} |
| 2086 |
val=static_cast<int>(input->readULong(2)); |
| 2087 |
if ((val&0xFFD7)!=0x10) { |
| 2088 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZone: find unexpected type1[fSz36]\n")); |
| 2089 |
f << "#fileType1=" << std::hex << val << std::dec << ","; |
| 2090 |
} |
| 2091 |
f << "ids=["; |
| 2092 |
for (int i=0; i<3; ++i) { |
| 2093 |
val=static_cast<int>(input->readLong(4)); |
| 2094 |
if (!val) { |
| 2095 |
f << "_,"; |
| 2096 |
continue; |
| 2097 |
} |
| 2098 |
m_expectedIdToType[val-1]=F_textList+i; |
| 2099 |
f << "F" << val-1 << ","; |
| 2100 |
} |
| 2101 |
f << "],"; |
| 2102 |
return true; |
| 2103 |
} |
| 2104 |
default: |
| 2105 |
break; |
| 2106 |
} |
| 2107 |
f << "###fSz=" << fSz; |
| 2108 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseDataZone: find unexpected field size\n")); |
| 2109 |
return true; |
| 2110 |
} |
| 2111 |
//! parse the header zone |
| 2112 |
bool parseHeaderZone(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) |
| 2113 |
{ |
| 2114 |
f << "header, fl=" << std::hex << flag << std::dec << ","; |
| 2115 |
m_fieldName="header"; |
| 2116 |
if (N!=-5 || m_dataId!=0 || (fSz!=135 && fSz!=140 && fSz!=143 && fSz!=208 && fSz!=212 && fSz!=213 && fSz!=216)) { |
| 2117 |
f << "###N=" << N << ",fSz=" << fSz << ","; |
| 2118 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: find unexpected main field\n")); |
| 2119 |
return true; |
| 2120 |
} |
| 2121 |
bool hasData1=(fSz==140||fSz==213); |
| 2122 |
int numData2=(fSz==143||fSz==216) ? 2 : fSz==212 ? 1 : 0; |
| 2123 |
int val; |
| 2124 |
for (int i=0; i<2; ++i) { // always 0? |
| 2125 |
val=static_cast<int>(input->readLong(2)); |
| 2126 |
if (val) f << "f" << i << "=" << val << ","; |
| 2127 |
} |
| 2128 |
val=static_cast<int>(input->readLong(2)); |
| 2129 |
f << "id=" << val << ","; |
| 2130 |
val=static_cast<int>(input->readULong(2)); |
| 2131 |
if (m_type>0 && val!=m_type) { |
| 2132 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: unexpected zone type\n")); |
| 2133 |
f << "##zoneType=" << std::hex << val << std::dec << ","; |
| 2134 |
} |
| 2135 |
// f2,f3 are also some ids to listClust and to zone:longs2 |
| 2136 |
for (int i=0; i<2; ++i) { // f2=9-5d, f3=0 |
| 2137 |
val=static_cast<int>(input->readLong(4)); |
| 2138 |
if (!val) continue; |
| 2139 |
if (i==0) { |
| 2140 |
m_expectedIdToType[int(val-1)]=F_parentLink; |
| 2141 |
f << "textParentLst=F" << val-1 << ","; |
| 2142 |
} |
| 2143 |
else { |
| 2144 |
m_expectedIdToType[int(val-1)]=F_nextId; |
| 2145 |
f << "nextId=F" << val-1 << ","; |
| 2146 |
} |
| 2147 |
} |
| 2148 |
val=static_cast<int>(input->readLong(1)); // 0|1 |
| 2149 |
if (val) |
| 2150 |
f << "fl=" << val << ","; |
| 2151 |
val=static_cast<int>(input->readULong(2)); |
| 2152 |
if (val&1) |
| 2153 |
f << "area[widest,only],"; |
| 2154 |
if (val&8) |
| 2155 |
f << "noShift[baseline,start],"; |
| 2156 |
if (val&0x10) |
| 2157 |
f << "recalculate[demand],"; |
| 2158 |
if (val&0x1000) |
| 2159 |
f << "vertical[writing],"; |
| 2160 |
val&=0xefe6; |
| 2161 |
if (val) // [08]0[08][049] |
| 2162 |
f << "fl2=" << std::hex << val << std::dec << ","; |
| 2163 |
val=static_cast<int>(input->readLong(1)); // 1|1d |
| 2164 |
if ((val&1)==0) f << "hyphen[end],"; |
| 2165 |
if (val&2) f << "column[balanced],"; |
| 2166 |
if ((val&4)==0) f << "space[between,para,sum],"; |
| 2167 |
if ((val&8)==0) f << "footnote[endComponent],"; |
| 2168 |
if (val&0x10) f << "footnote[number,restart],"; |
| 2169 |
if (val&0x20) f << "footnote[symbol,cycle],"; |
| 2170 |
val &= 0xc0; |
| 2171 |
if (val) |
| 2172 |
f << "fl3=" << std::hex << val << std::dec << ","; |
| 2173 |
val=static_cast<int>(input->readULong(2)); // alway 10 |
| 2174 |
if (val!=0x10) |
| 2175 |
f << "f4=" << val << ","; |
| 2176 |
int numZones=static_cast<int>(input->readLong(4)); |
| 2177 |
if (numZones) |
| 2178 |
f << "num[zones]=" << numZones << ","; |
| 2179 |
for (int i=0; i<11; ++i) { // g8=40|60 |
| 2180 |
val=static_cast<int>(input->readLong(2)); |
| 2181 |
if (val) |
| 2182 |
f << "g" << i << "=" << val << ","; |
| 2183 |
} |
| 2184 |
val=static_cast<int>(input->readLong(1)); // always 1 |
| 2185 |
if (val!=1) |
| 2186 |
f << "fl4=" << val << ","; |
| 2187 |
if (hasData1) { |
| 2188 |
for (int i=0; i<5; ++i) { // unsure find only 0 here |
| 2189 |
val=static_cast<int>(input->readLong(1)); |
| 2190 |
if (val) |
| 2191 |
f << "flA" << i << "=" << val << ","; |
| 2192 |
} |
| 2193 |
} |
| 2194 |
|
| 2195 |
for (int i=0; i<2; ++i) { // always 1,2 checkme id? |
| 2196 |
val=static_cast<int>(input->readLong(4)); |
| 2197 |
if (val!=i+1) |
| 2198 |
f << "h" << i << "=" << val << ","; |
| 2199 |
} |
| 2200 |
for (int i=0; i<2; ++i) { // always 0,4 |
| 2201 |
val=static_cast<int>(input->readLong(2)); |
| 2202 |
if (!val) continue; |
| 2203 |
if (i==1) |
| 2204 |
f << "column[line,style]=" << val << ","; // 5: contain border, ... |
| 2205 |
else |
| 2206 |
f << "h" << i+2 << "=" << val << ","; |
| 2207 |
} |
| 2208 |
for (int i=0; i<4; ++i) { // always h4=3, h5=id to plcToCStyle and zone:longs2 |
| 2209 |
val=static_cast<int>(input->readLong(4)); |
| 2210 |
if (!val) continue; |
| 2211 |
if (i==1) { |
| 2212 |
m_expectedIdToType[int(val-1)]=F_plcToStyle; |
| 2213 |
f << "plcToStyle=F" << val-1 << ","; |
| 2214 |
} |
| 2215 |
else if (i==2) { |
| 2216 |
m_expectedIdToType[int(val-1)]=F_textDefs; |
| 2217 |
f << "textDefs=F" << val-1 << ","; |
| 2218 |
} |
| 2219 |
else if (i==3) { |
| 2220 |
m_expectedIdToType[int(val-1)]=F_footnote; |
| 2221 |
f << "footnote=F" << val-1 << ","; |
| 2222 |
} |
| 2223 |
else |
| 2224 |
f << "h" << i+4 << "=" << val << ","; |
| 2225 |
} |
| 2226 |
for (int i=0; i<2; ++i) { // always 1,4 |
| 2227 |
val=static_cast<int>(input->readLong(2)); |
| 2228 |
if (!val) continue; |
| 2229 |
if (i==1) |
| 2230 |
f << "footnote[sep,style]=" << val << ","; |
| 2231 |
else |
| 2232 |
f << "h" << i+8 << "=" << val << ","; |
| 2233 |
} |
| 2234 |
auto sepLen=input->readULong(4); |
| 2235 |
if (sepLen!=0x5555) |
| 2236 |
f << "footnote[len,separator]=" << 100*double(sepLen)/double(0x10000) << "%,"; |
| 2237 |
sepLen=input->readULong(4); |
| 2238 |
if (sepLen!=0x18000) |
| 2239 |
f << "footnote[margins,vert]=" << 100*double(sepLen)/double(0x10000) << "%,"; |
| 2240 |
for (int i=0; i<5; ++i) { // always 0 |
| 2241 |
val=static_cast<int>(input->readLong(2)); |
| 2242 |
if (!val) continue; |
| 2243 |
f << "j" << i << "=" << val << ","; |
| 2244 |
} |
| 2245 |
for (int i=0; i<5; ++i) { // j5=0|5, j6=0|5, |
| 2246 |
val=static_cast<int>(input->readLong(4)); |
| 2247 |
if (!val) continue; |
| 2248 |
m_expectedIdToType[int(val-1)]=F_linkDefs+i; |
| 2249 |
char const *what[]= {"attachLink", "itemLink", "linkDef2", "indexLink", "fieldLink"}; |
| 2250 |
f << what[i] << "=F" << val-1 << ","; |
| 2251 |
} |
| 2252 |
f << "IDS=["; |
| 2253 |
for (int i=0; i<2; ++i) // unsure, junk |
| 2254 |
f << std::hex << input->readULong(4) << std::dec << ","; |
| 2255 |
f << "],"; |
| 2256 |
val=static_cast<int>(input->readULong(2)); // c00|cef |
| 2257 |
if (val) |
| 2258 |
f << "fl5=" << std::hex << val << std::dec << ","; |
| 2259 |
for (int i=0; i<numData2; ++i) { // always 0 |
| 2260 |
val=static_cast<int>(input->readLong(4)); |
| 2261 |
if (!val) continue; |
| 2262 |
if (i==1) { |
| 2263 |
m_expectedIdToType[int(val-1)]=F_linkDefs+1; // checkme: another link with fSz=47 |
| 2264 |
f << "linkDef1[bis]=F" << val-1 << ","; |
| 2265 |
} |
| 2266 |
else |
| 2267 |
f << "k" << i << "=" << val << ","; |
| 2268 |
} |
| 2269 |
if (fSz<=143) |
| 2270 |
return true; |
| 2271 |
|
| 2272 |
f << "link2=["; |
| 2273 |
long linkValues[4]; |
| 2274 |
std::string mess(""); |
| 2275 |
val=static_cast<int>(input->readULong(2)); |
| 2276 |
if (val!=0x10) f << "fl=" << std::hex << val << std::dec << ","; |
| 2277 |
RagTime5ClusterManager::Link link2; |
| 2278 |
link2.m_N=static_cast<int>(input->readLong(4)); |
| 2279 |
mess=""; |
| 2280 |
if (!readLinkHeader(input, fSz, link2, linkValues, mess)) { |
| 2281 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: can not read the second link\n")); |
| 2282 |
f << "###link2"; |
| 2283 |
return true; |
| 2284 |
} |
| 2285 |
if (linkValues[3]==0x15f3817 && link2.m_fieldSize==20) |
| 2286 |
m_cluster->m_blockCellToPlcLink=link2; |
| 2287 |
else { |
| 2288 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: blockCell to plc link\n")); |
| 2289 |
f << "###"; |
| 2290 |
} |
| 2291 |
f << link2 << "," << mess; |
| 2292 |
for (int i=0; i<2; ++i) { // always 1 and 4 |
| 2293 |
val=static_cast<int>(input->readLong(4)); |
| 2294 |
if (val) f << "f" << i << "=" << val << ","; |
| 2295 |
} |
| 2296 |
val=static_cast<int>(input->readLong(1)); // always 1 |
| 2297 |
if (val) f << "f2=" << val << ","; |
| 2298 |
f << "],"; |
| 2299 |
|
| 2300 |
f << "link3=["; |
| 2301 |
val=static_cast<int>(input->readULong(2)); |
| 2302 |
if (val!=0x10) f << "fl=" << std::hex << val << std::dec << ","; |
| 2303 |
RagTime5ClusterManager::Link link3; |
| 2304 |
link3.m_N=static_cast<int>(input->readLong(4)); |
| 2305 |
mess=""; |
| 2306 |
if (!readLinkHeader(input, fSz, link3, linkValues, mess)) { |
| 2307 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: can not read the third link\n")); |
| 2308 |
f << "###link3"; |
| 2309 |
return true; |
| 2310 |
} |
| 2311 |
if (link3.m_fieldSize==12) |
| 2312 |
m_cluster->m_unknownLink[2]=link3; |
| 2313 |
else { |
| 2314 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: third link seems bad\n")); |
| 2315 |
f << "###"; |
| 2316 |
} |
| 2317 |
f << link3 << "," << mess; |
| 2318 |
f << "],"; |
| 2319 |
|
| 2320 |
std::vector<int> listIds; |
| 2321 |
if (!RagTime5StructManager::readDataIdList(input, 1, listIds)) { |
| 2322 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseHeaderZone: can not read an cluster id\n")); |
| 2323 |
f << "##clusterIds,"; |
| 2324 |
return false; |
| 2325 |
} |
| 2326 |
if (listIds[0]) { |
| 2327 |
m_cluster->m_clusterIdsList.push_back(listIds[0]); |
| 2328 |
f << "cluster=" << getClusterDebugName(listIds[0]) << ","; |
| 2329 |
} |
| 2330 |
return true; |
| 2331 |
} |
| 2332 |
//! parse a zone block |
| 2333 |
bool parseZoneBlock(MWAWInputStreamPtr &input, long fSz, int N, int flag, libmwaw::DebugStream &f) |
| 2334 |
{ |
| 2335 |
if (N<0 || fSz!=80) { |
| 2336 |
f << "###N=" << N << ",fSz=" << fSz << ","; |
| 2337 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZoneBlock: find unexpected main field\n")); |
| 2338 |
return false; |
| 2339 |
} |
| 2340 |
RagTime5TextInternal::Block block; |
| 2341 |
m_fieldName="block"; |
| 2342 |
std::string debugHeader=f.str(); |
| 2343 |
f.str(""); |
| 2344 |
if (N!=1) { |
| 2345 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZoneBlock: zone N seems badA\n")); |
| 2346 |
f << "#N=" << N << ","; |
| 2347 |
} |
| 2348 |
auto val=static_cast<int>(input->readULong(2)); // always 0? |
| 2349 |
if (val) f << "f0=" << val << ","; |
| 2350 |
block.m_id=static_cast<int>(input->readULong(2)); |
| 2351 |
val=static_cast<int>(input->readULong(2)); //[04][01248a][01][23] |
| 2352 |
if (val) f << "fl=" << std::hex << val << std::dec << ","; |
| 2353 |
block.m_subId=static_cast<int>(input->readULong(2)); |
| 2354 |
val=static_cast<int>(input->readULong(2)); //f1=0|3ffe |
| 2355 |
if (val) f << "f1=" << val << ","; |
| 2356 |
float dim[4]; |
| 2357 |
for (auto &d : dim) d=float(input->readLong(4))/65536.f; |
| 2358 |
block.m_dimension=MWAWBox2f(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[2],dim[3])); |
| 2359 |
for (float &i : dim) i=float(input->readLong(4))/65536.f; |
| 2360 |
MWAWBox2f box2(MWAWVec2f(dim[0],dim[1]), MWAWVec2f(dim[2],dim[3])); |
| 2361 |
if (block.m_dimension!=box2) |
| 2362 |
f << "boxA=" << box2 << ","; |
| 2363 |
int nextId=0; |
| 2364 |
for (int i=0; i<4; ++i) { // g1=0|2, g3=9|7 |
| 2365 |
val=static_cast<int>(input->readLong(i<2 ? 4 : 2)); |
| 2366 |
if (!val) continue; |
| 2367 |
switch (i) { |
| 2368 |
case 0: // prev |
| 2369 |
m_expectedIdToType[int(val-1)]=F_block; |
| 2370 |
f << "prev=F" << val-1 << ","; |
| 2371 |
break; |
| 2372 |
case 1: // next |
| 2373 |
m_expectedIdToType[int(val-1)]=F_block; |
| 2374 |
f << "next=F" << val-1 << ","; |
| 2375 |
nextId=val; |
| 2376 |
break; |
| 2377 |
case 3: |
| 2378 |
m_expectedIdToType[int(val-1)]=F_footnote+1; |
| 2379 |
f << "footnote1=F" << val-1 << ","; |
| 2380 |
break; |
| 2381 |
default: |
| 2382 |
f << "g" << i << "=" << val << ","; |
| 2383 |
break; |
| 2384 |
} |
| 2385 |
} |
| 2386 |
for (int &i : block.m_plc) i=static_cast<int>(input->readULong(4)); |
| 2387 |
for (int i=0; i<6; ++i) { // h1=h2=0|-1 |
| 2388 |
val=static_cast<int>(input->readLong(2)); |
| 2389 |
if (!val) continue; |
| 2390 |
f << "h" << i << "=" << val << ","; |
| 2391 |
} |
| 2392 |
block.m_extra=f.str(); |
| 2393 |
f.str(""); |
| 2394 |
f << debugHeader << "block,fl=" << std::hex << flag << std::dec << "," << block; |
| 2395 |
|
| 2396 |
if (m_NToBlockIdMap.find(m_dataId)==m_NToBlockIdMap.end()) { |
| 2397 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZoneBlock: unknown block for N=%d\n", m_dataId)); |
| 2398 |
f << "###unknown,"; |
| 2399 |
} |
| 2400 |
else { |
| 2401 |
m_cluster->m_blockList[m_NToBlockIdMap.find(m_dataId)->second].push_back(block); |
| 2402 |
if (nextId && m_NToBlockIdMap.find(nextId)!=m_NToBlockIdMap.end()) { |
| 2403 |
MWAW_DEBUG_MSG(("RagTime5TextInternal::TextCParser::parseZoneBlock: next id block for N=%d is already set\n", nextId)); |
| 2404 |
f << "###nextId,"; |
| 2405 |
} |
| 2406 |
else if (nextId) |
| 2407 |
m_NToBlockIdMap[nextId-1]=m_NToBlockIdMap.find(m_dataId)->second; |
| 2408 |
} |
| 2409 |
return true; |
| 2410 |
} |
| 2411 |
|
| 2412 |
//! the current cluster |
| 2413 |
std::shared_ptr<ClusterText> m_cluster; |
| 2414 |
//! the expected id |
| 2415 |
std::map<int,int> m_expectedIdToType; |
| 2416 |
//! the field pos to block map |
| 2417 |
std::map<int, size_t> m_NToBlockIdMap; |
| 2418 |
//! the actual field name |
| 2419 |
std::string m_fieldName; |
| 2420 |
//! the ascii file |
| 2421 |
libmwaw::DebugFile &m_asciiFile; |
| 2422 |
private: |
| 2423 |
//! copy constructor (not implemented) |
| 2424 |
TextCParser(TextCParser const &orig) = delete; |
| 2425 |
//! copy operator (not implemented) |
| 2426 |
TextCParser &operator=(TextCParser const &orig) = delete; |
| 2427 |
}; |
| 2428 |
|
| 2429 |
TextCParser::~TextCParser() |
| 2430 |
{ |
| 2431 |
} |
| 2432 |
|
| 2433 |
} |
| 2434 |
|
| 2435 |
std::shared_ptr<RagTime5ClusterManager::Cluster> RagTime5Text::readTextCluster(RagTime5Zone &zone, int zoneType) |
| 2436 |
{ |
| 2437 |
auto clusterManager=m_document.getClusterManager(); |
| 2438 |
if (!clusterManager) { |
| 2439 |
MWAW_DEBUG_MSG(("RagTime5Text::readTextCluster: oops can not find the cluster manager\n")); |
| 2440 |
return std::shared_ptr<RagTime5ClusterManager::Cluster>(); |
| 2441 |
} |
| 2442 |
RagTime5TextInternal::TextCParser parser(*clusterManager, zoneType, zone.ascii()); |
| 2443 |
if (!clusterManager->readCluster(zone, parser) || !parser.getTextCluster()) { |
| 2444 |
MWAW_DEBUG_MSG(("RagTime5Text::readTextCluster: oops can not find the cluster\n")); |
| 2445 |
return std::shared_ptr<RagTime5ClusterManager::Cluster>(); |
| 2446 |
} |
| 2447 |
auto cluster=parser.getTextCluster(); |
| 2448 |
if (m_state->m_idTextMap.find(zone.m_ids[0])!=m_state->m_idTextMap.end()) { |
| 2449 |
MWAW_DEBUG_MSG(("RagTime5Text::readTextCluster: oops text zone %d is already stored\n", zone.m_ids[0])); |
| 2450 |
} |
| 2451 |
else |
| 2452 |
m_state->m_idTextMap[zone.m_ids[0]]=cluster; |
| 2453 |
m_document.checkClusterList(cluster->m_clusterIdsList); |
| 2454 |
|
| 2455 |
if (!cluster->m_dataLink.empty()) { |
| 2456 |
MWAW_DEBUG_MSG(("RagTime5Text::readTextCluster: oops do not know how to read the dataLink\n")); |
| 2457 |
} |
| 2458 |
|
| 2459 |
// the text<->separator zone cluster->m_separatorLink.m_ids[0] will be parsed when we send the cluster |
| 2460 |
// the textzone cluster->m_contentLink.m_ids[0] will be parsed when we send the cluster |
| 2461 |
|
| 2462 |
if (!cluster->m_plcDefLink.m_ids.empty()) |
| 2463 |
readPLC(*cluster, cluster->m_plcDefLink.m_ids[0]); |
| 2464 |
readPLCToCharStyle(*cluster); // read cluster->m_plcToStyleLink |
| 2465 |
if (!cluster->m_blockCellToPlcLink.empty()) { |
| 2466 |
RagTime5TextInternal::BlockCellListParser blockCellParser; |
| 2467 |
m_document.readFixedSizeZone(cluster->m_blockCellToPlcLink, blockCellParser); |
| 2468 |
cluster->m_blockCellList=blockCellParser.m_blockList; |
| 2469 |
} |
| 2470 |
for (auto const &link : cluster->m_unknownLinks1) |
| 2471 |
m_document.readFixedSizeZone(link, "TextUnkn0"); |
| 2472 |
if (!cluster->m_unknownLink[0].empty()) { // some unicode string related to index ? |
| 2473 |
std::map<int, librevenge::RVNGString> idToStringMap; |
| 2474 |
m_document.readUnicodeStringList(RagTime5ClusterManager::NameLink(cluster->m_unknownLink[0]), idToStringMap); |
| 2475 |
} |
| 2476 |
if (!cluster->m_unknownLink[1].empty()) // related to column/section ? |
| 2477 |
m_document.readListZone(cluster->m_unknownLink[1]); |
| 2478 |
if (!cluster->m_unknownLink[2].empty()) |
| 2479 |
m_document.readFixedSizeZone(cluster->m_unknownLink[2], "TextUnkn3"); |
| 2480 |
// parent zones: graphic or pipeline, ... |
| 2481 |
if (!cluster->m_parentLink.empty()) { |
| 2482 |
RagTime5TextInternal::ClustListParser linkParser(*clusterManager, "TextParentLst"); |
| 2483 |
m_document.readListZone(cluster->m_parentLink, linkParser); |
| 2484 |
m_document.checkClusterList(linkParser.m_clusterList); |
| 2485 |
} |
| 2486 |
if (!cluster->m_indexLink.empty()) |
| 2487 |
m_document.readListZone(cluster->m_indexLink); |
| 2488 |
if (!cluster->m_childLink.empty()) { |
| 2489 |
cluster->m_childLink.m_name="TextChildLst"; |
| 2490 |
m_document.readChildList(cluster->m_childLink, cluster->m_childList, true); |
| 2491 |
} |
| 2492 |
for (int i=0; i<5; ++i) { |
| 2493 |
// 0: attachement, pos sz=32, id, dim, ?? |
| 2494 |
// 1: item: list type in unicode pos sz=12 or v6 sz=24 |
| 2495 |
// 2: maybe end doc or section, pos sz=16 |
| 2496 |
// 3: index, pos sz=12 |
| 2497 |
// 4: pos sz=16 |
| 2498 |
auto &lnk = cluster->m_linkDefs[i]; |
| 2499 |
if (lnk.empty()) continue; |
| 2500 |
std::stringstream s; |
| 2501 |
if (i==0) |
| 2502 |
lnk.m_name="TextLinkAttach"; |
| 2503 |
else if (i==1) |
| 2504 |
lnk.m_name="TextLinkItem"; |
| 2505 |
else if (i==3) |
| 2506 |
lnk.m_name="TextLinkIndex"; |
| 2507 |
else if (i==4) |
| 2508 |
lnk.m_name="TextLinkFormula"; |
| 2509 |
else { |
| 2510 |
s << "TextLink" << i; |
| 2511 |
lnk.m_name=s.str(); |
| 2512 |
} |
| 2513 |
readLinkZones(*cluster, lnk, i); |
| 2514 |
} |
| 2515 |
if (!cluster->m_footnoteLink.empty()) { |
| 2516 |
cluster->m_footnoteLink.m_name="TextLinkFootnote"; |
| 2517 |
readLinkZones(*cluster, cluster->m_footnoteLink, 5); |
| 2518 |
} |
| 2519 |
if (!cluster->m_textIntListLink.empty()) { // only v6 |
| 2520 |
std::vector<long> intList; |
| 2521 |
cluster->m_textIntListLink.m_name="TextListInt"; |
| 2522 |
m_document.readLongList(cluster->m_textIntListLink, intList); |
| 2523 |
} |
| 2524 |
for (auto const &link : cluster->m_linksList) { |
| 2525 |
if (link.m_type==RagTime5ClusterManager::Link::L_List) { |
| 2526 |
m_document.readListZone(link); |
| 2527 |
continue; |
| 2528 |
} |
| 2529 |
std::stringstream s; |
| 2530 |
s << "Text_Data" << link.m_fieldSize; |
| 2531 |
RagTime5StructManager::DataParser defaultParser(link.m_name.empty() ? s.str() : link.m_name); |
| 2532 |
m_document.readFixedSizeZone(link, defaultParser); |
| 2533 |
} |
| 2534 |
return cluster; |
| 2535 |
} |
| 2536 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |