| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#include <iomanip> |
| 35 |
#include <iostream> |
| 36 |
#include <limits> |
| 37 |
#include <set> |
| 38 |
#include <sstream> |
| 39 |
|
| 40 |
#include <librevenge/librevenge.h> |
| 41 |
|
| 42 |
#include "MWAWTextListener.hxx" |
| 43 |
#include "MWAWFont.hxx" |
| 44 |
#include "MWAWFontConverter.hxx" |
| 45 |
#include "MWAWHeader.hxx" |
| 46 |
#include "MWAWParagraph.hxx" |
| 47 |
#include "MWAWPictData.hxx" |
| 48 |
#include "MWAWPosition.hxx" |
| 49 |
#include "MWAWPrinter.hxx" |
| 50 |
#include "MWAWRSRCParser.hxx" |
| 51 |
#include "MWAWSubDocument.hxx" |
| 52 |
|
| 53 |
#include "StyleParser.hxx" |
| 54 |
|
| 55 |
/** Internal: the structures of a StyleParser */ |
| 56 |
namespace StyleParserInternal |
| 57 |
{ |
| 58 |
//! small structure used to store picture data in StyleParser |
| 59 |
struct Picture { |
| 60 |
//! constructor |
| 61 |
Picture() |
| 62 |
: m_size(0,0) |
| 63 |
, m_entry() |
| 64 |
{ |
| 65 |
} |
| 66 |
//! returns true if the picture is valid |
| 67 |
bool valid() const |
| 68 |
{ |
| 69 |
return m_entry.valid(); |
| 70 |
} |
| 71 |
//! the picture size in point |
| 72 |
MWAWVec2i m_size; |
| 73 |
//! the picture entry |
| 74 |
MWAWEntry m_entry; |
| 75 |
}; |
| 76 |
|
| 77 |
//! small structure used to store a font and a picture |
| 78 |
struct Font { |
| 79 |
//! constructor |
| 80 |
Font() |
| 81 |
: m_font() |
| 82 |
, m_picture() |
| 83 |
{ |
| 84 |
} |
| 85 |
//! returns true if the picture is valid |
| 86 |
bool hasPicture() const |
| 87 |
{ |
| 88 |
return m_picture.valid(); |
| 89 |
} |
| 90 |
//! the font |
| 91 |
MWAWFont m_font; |
| 92 |
//! the picture |
| 93 |
Picture m_picture; |
| 94 |
}; |
| 95 |
|
| 96 |
//////////////////////////////////////// |
| 97 |
//! Internal: the state of a StyleParser |
| 98 |
struct State { |
| 99 |
//! constructor |
| 100 |
State() |
| 101 |
: m_entryMap() |
| 102 |
, m_unicodeChar(false) |
| 103 |
, m_textEntry() |
| 104 |
, m_backgroundColor(MWAWColor::white()) |
| 105 |
, m_fontIdToFinalIdList() |
| 106 |
, m_fontList() |
| 107 |
, m_paragraphList() |
| 108 |
, m_posFontIdMap() |
| 109 |
, m_posParagraphIdMap() |
| 110 |
, m_posPictureMap() |
| 111 |
, m_actPage(0) |
| 112 |
, m_numPages(0) |
| 113 |
{ |
| 114 |
} |
| 115 |
//! the map type to entry |
| 116 |
std::map<std::string, MWAWEntry> m_entryMap; |
| 117 |
//! true if the character are unicode character |
| 118 |
bool m_unicodeChar; |
| 119 |
//! the text entry |
| 120 |
MWAWEntry m_textEntry; |
| 121 |
//! the background color |
| 122 |
MWAWColor m_backgroundColor; |
| 123 |
//! list of font final id |
| 124 |
std::vector<int> m_fontIdToFinalIdList; |
| 125 |
//! the list of font style |
| 126 |
std::vector<Font> m_fontList; |
| 127 |
//! the list of paragraph style |
| 128 |
std::vector<MWAWParagraph> m_paragraphList; |
| 129 |
//! a map pos->font id |
| 130 |
std::map<long,int> m_posFontIdMap; |
| 131 |
//! a map pos->paragraphId |
| 132 |
std::map<long,int> m_posParagraphIdMap; |
| 133 |
//! a map pos->pictEntry |
| 134 |
std::map<long,Picture> m_posPictureMap; |
| 135 |
int m_actPage /** the actual page */, m_numPages /** the number of page of the final document */; |
| 136 |
}; |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
//////////////////////////////////////////////////////////// |
| 141 |
// constructor/destructor, ... |
| 142 |
//////////////////////////////////////////////////////////// |
| 143 |
StyleParser::StyleParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 144 |
: MWAWTextParser(input, rsrcParser, header) |
| 145 |
, m_state(new StyleParserInternal::State) |
| 146 |
{ |
| 147 |
getPageSpan().setMargins(0.1); |
| 148 |
} |
| 149 |
|
| 150 |
StyleParser::~StyleParser() |
| 151 |
{ |
| 152 |
} |
| 153 |
|
| 154 |
//////////////////////////////////////////////////////////// |
| 155 |
// new page |
| 156 |
//////////////////////////////////////////////////////////// |
| 157 |
void StyleParser::newPage(int number) |
| 158 |
{ |
| 159 |
if (number <= m_state->m_actPage || number > m_state->m_numPages) |
| 160 |
return; |
| 161 |
|
| 162 |
while (m_state->m_actPage < number) { |
| 163 |
m_state->m_actPage++; |
| 164 |
if (!getTextListener() || m_state->m_actPage == 1) |
| 165 |
continue; |
| 166 |
getTextListener()->insertBreak(MWAWTextListener::PageBreak); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
//////////////////////////////////////////////////////////// |
| 171 |
// the parser |
| 172 |
//////////////////////////////////////////////////////////// |
| 173 |
void StyleParser::parse(librevenge::RVNGTextInterface *docInterface) |
| 174 |
{ |
| 175 |
if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
| 176 |
bool ok = false; |
| 177 |
try { |
| 178 |
// create the asciiFile |
| 179 |
ascii().setStream(getInput()); |
| 180 |
ascii().open("main-1"); |
| 181 |
checkHeader(nullptr); |
| 182 |
ok = createZones(); |
| 183 |
if (ok) { |
| 184 |
createDocument(docInterface); |
| 185 |
sendText(m_state->m_textEntry, m_state->m_unicodeChar); |
| 186 |
} |
| 187 |
ascii().reset(); |
| 188 |
} |
| 189 |
catch (...) { |
| 190 |
MWAW_DEBUG_MSG(("StyleParser::parse: exception catched when parsing\n")); |
| 191 |
ok = false; |
| 192 |
} |
| 193 |
|
| 194 |
resetTextListener(); |
| 195 |
if (!ok) throw(libmwaw::ParseException()); |
| 196 |
} |
| 197 |
|
| 198 |
//////////////////////////////////////////////////////////// |
| 199 |
// create the document |
| 200 |
//////////////////////////////////////////////////////////// |
| 201 |
void StyleParser::createDocument(librevenge::RVNGTextInterface *documentInterface) |
| 202 |
{ |
| 203 |
if (!documentInterface) return; |
| 204 |
if (getTextListener()) { |
| 205 |
MWAW_DEBUG_MSG(("StyleParser::createDocument: listener already exist\n")); |
| 206 |
return; |
| 207 |
} |
| 208 |
|
| 209 |
// update the page |
| 210 |
m_state->m_actPage = 0; |
| 211 |
|
| 212 |
// create the page list |
| 213 |
int numPages=m_state->m_textEntry.valid() ? computeNumPages(m_state->m_textEntry, m_state->m_unicodeChar) : 1; |
| 214 |
m_state->m_numPages = numPages; |
| 215 |
MWAWPageSpan ps(getPageSpan()); |
| 216 |
ps.setPageSpan(m_state->m_numPages+1); |
| 217 |
if (!m_state->m_backgroundColor.isWhite()) |
| 218 |
ps.setBackgroundColor(m_state->m_backgroundColor); |
| 219 |
std::vector<MWAWPageSpan> pageList(1,ps); |
| 220 |
MWAWTextListenerPtr listen(new MWAWTextListener(*getParserState(), pageList, documentInterface)); |
| 221 |
setTextListener(listen); |
| 222 |
listen->startDocument(); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
//////////////////////////////////////////////////////////// |
| 227 |
// |
| 228 |
// Intermediate level |
| 229 |
// |
| 230 |
//////////////////////////////////////////////////////////// |
| 231 |
bool StyleParser::createZones() |
| 232 |
{ |
| 233 |
if (!readTypeEntryMap()) |
| 234 |
return false; |
| 235 |
libmwaw::DebugStream f; |
| 236 |
auto &entryMap = m_state->m_entryMap; |
| 237 |
|
| 238 |
// basic data |
| 239 |
auto it = entryMap.find("vers"); |
| 240 |
if (it != entryMap.end()) { |
| 241 |
MWAWEntry const &entry = it++->second; |
| 242 |
readVersion(entry); |
| 243 |
} |
| 244 |
it = entryMap.find("bgcl"); |
| 245 |
if (it != entryMap.end()) { |
| 246 |
MWAWEntry const &entry = it++->second; |
| 247 |
readBackgroundColor(entry); |
| 248 |
} |
| 249 |
it = entryMap.find("marg"); |
| 250 |
if (it != entryMap.end()) { |
| 251 |
MWAWEntry const &entry = it++->second; |
| 252 |
readMargins(entry); |
| 253 |
} |
| 254 |
it = entryMap.find("prec"); |
| 255 |
if (it != entryMap.end()) { |
| 256 |
MWAWEntry const &entry = it++->second; |
| 257 |
readPrintInfo(entry); |
| 258 |
} |
| 259 |
it = entryMap.find("stat"); |
| 260 |
if (it != entryMap.end()) { |
| 261 |
MWAWEntry const &entry = it++->second; |
| 262 |
readStat(entry); |
| 263 |
} |
| 264 |
it = entryMap.find("tabw"); |
| 265 |
if (it != entryMap.end()) { |
| 266 |
MWAWEntry const &entry = it++->second; |
| 267 |
readTabWidth(entry); |
| 268 |
} |
| 269 |
bool findTextEntry=false; |
| 270 |
it = entryMap.find("text"); |
| 271 |
if (it != entryMap.end()) { |
| 272 |
findTextEntry=true; |
| 273 |
MWAWEntry const &entry = it++->second; |
| 274 |
entry.setParsed(true); |
| 275 |
m_state->m_unicodeChar=false; |
| 276 |
m_state->m_textEntry=entry; |
| 277 |
} |
| 278 |
it = entryMap.find("utxt"); |
| 279 |
if (it != entryMap.end()) { |
| 280 |
findTextEntry=true; |
| 281 |
MWAWEntry const &entry = it++->second; |
| 282 |
entry.setParsed(true); |
| 283 |
m_state->m_unicodeChar=true; |
| 284 |
m_state->m_textEntry=entry; |
| 285 |
} |
| 286 |
|
| 287 |
// font |
| 288 |
|
| 289 |
// v1.9 |
| 290 |
it = entryMap.find("cfor"); |
| 291 |
if (it != entryMap.end()) { |
| 292 |
MWAWEntry const &entry = it++->second; |
| 293 |
readFormats(entry); |
| 294 |
} |
| 295 |
// or v1.6 |
| 296 |
it = entryMap.find("font"); |
| 297 |
if (it != entryMap.end()) { |
| 298 |
MWAWEntry const &entry = it++->second; |
| 299 |
readFontCorr(entry); |
| 300 |
} |
| 301 |
it = entryMap.find("fntb"); |
| 302 |
if (it != entryMap.end()) { |
| 303 |
MWAWEntry const &entry = it++->second; |
| 304 |
readFontNames(entry); |
| 305 |
} |
| 306 |
it = entryMap.find("styl"); |
| 307 |
if (it != entryMap.end()) { |
| 308 |
MWAWEntry const &entry = it++->second; |
| 309 |
readStyleTable(entry); |
| 310 |
} |
| 311 |
// v1.6 or v1.9 |
| 312 |
it = entryMap.find("runa"); |
| 313 |
if (it != entryMap.end()) { |
| 314 |
MWAWEntry const &entry = it++->second; |
| 315 |
readPLCs(entry, false); |
| 316 |
} |
| 317 |
|
| 318 |
// para |
| 319 |
it = entryMap.find("rule"); |
| 320 |
if (it != entryMap.end()) { |
| 321 |
MWAWEntry const &entry = it++->second; |
| 322 |
readRules(entry); |
| 323 |
} |
| 324 |
it = entryMap.find("para"); |
| 325 |
if (it != entryMap.end()) { |
| 326 |
MWAWEntry const &entry = it++->second; |
| 327 |
readPLCs(entry, true); |
| 328 |
} |
| 329 |
|
| 330 |
// image |
| 331 |
it = entryMap.find("soup"); |
| 332 |
if (it != entryMap.end()) { |
| 333 |
MWAWEntry const &entry = it++->second; |
| 334 |
readPictures(entry); |
| 335 |
} |
| 336 |
|
| 337 |
// extra |
| 338 |
it = entryMap.find("xprc"); |
| 339 |
if (it != entryMap.end()) { |
| 340 |
MWAWEntry const &entry = it++->second; |
| 341 |
readExtraProperties(entry); |
| 342 |
} |
| 343 |
|
| 344 |
// other |
| 345 |
for (auto const &iter : entryMap) { |
| 346 |
MWAWEntry const &entry=iter.second; |
| 347 |
if (entry.isParsed()) continue; |
| 348 |
f.str(""); |
| 349 |
f << "Entries(" << entry.type() << "):"; |
| 350 |
ascii().addPos(entry.begin()); |
| 351 |
ascii().addNote(f.str().c_str()); |
| 352 |
ascii().addPos(entry.end()); |
| 353 |
ascii().addNote("_"); |
| 354 |
} |
| 355 |
return m_state->m_textEntry.valid() || findTextEntry; |
| 356 |
} |
| 357 |
|
| 358 |
bool StyleParser::readTypeEntryMap() |
| 359 |
{ |
| 360 |
MWAWInputStreamPtr input = getInput(); |
| 361 |
if (!input->checkPosition(16)) return false; |
| 362 |
input->seek(8, librevenge::RVNG_SEEK_SET); |
| 363 |
long pos=input->tell(); |
| 364 |
libmwaw::DebugStream f; |
| 365 |
f << "Entries(ZoneList):"; |
| 366 |
int val; |
| 367 |
auto N=static_cast<int>(input->readLong(2)); |
| 368 |
f << "N=" << N+1 << ","; |
| 369 |
if (!input->checkPosition(16+16*(N+1))) return false; |
| 370 |
for (int i=0; i<3; ++i) { // always 0 |
| 371 |
val=static_cast<int>(input->readLong(2)); |
| 372 |
if (val) |
| 373 |
f << "f" << i << "=" << val << ","; |
| 374 |
} |
| 375 |
ascii().addPos(pos); |
| 376 |
ascii().addNote(f.str().c_str()); |
| 377 |
m_state->m_entryMap.clear(); |
| 378 |
bool ok=false; |
| 379 |
for (int i=0; i<=N; ++i) { |
| 380 |
pos=input->tell(); |
| 381 |
f.str(""); |
| 382 |
f << "ZoneList-" << i << ":"; |
| 383 |
std::string wh(""); |
| 384 |
for (int c=0; c<4; ++c) wh+=char(input->readULong(1)); |
| 385 |
f << wh << ","; |
| 386 |
if (wh=="text" || wh=="utxt") ok=true; |
| 387 |
for (int j=0; j<2; ++j) { |
| 388 |
// always 0 |
| 389 |
val=static_cast<int>(input->readLong(2)); |
| 390 |
if (val) |
| 391 |
f << "f" << i << "=" << val << ","; |
| 392 |
} |
| 393 |
MWAWEntry entry; |
| 394 |
entry.setType(wh); |
| 395 |
entry.setBegin(long(input->readLong(4))); |
| 396 |
entry.setLength(long(input->readLong(4))); |
| 397 |
f << std::hex << entry.begin() << "<->" << entry.end() << ","; |
| 398 |
if (!entry.length()) { |
| 399 |
// ok if the document is empty |
| 400 |
if (wh=="text" || wh=="utxt") |
| 401 |
m_state->m_entryMap[wh]=entry; |
| 402 |
} |
| 403 |
else if (entry.begin()<16+16*(N+1) || !input->checkPosition(entry.end()) || |
| 404 |
m_state->m_entryMap.find(wh)!=m_state->m_entryMap.end()) { |
| 405 |
MWAW_DEBUG_MSG(("StyleParser::readTypeEntryMap: find some bad entry")); |
| 406 |
f << "###"; |
| 407 |
} |
| 408 |
else |
| 409 |
m_state->m_entryMap[wh]=entry; |
| 410 |
ascii().addPos(pos); |
| 411 |
ascii().addNote(f.str().c_str()); |
| 412 |
} |
| 413 |
ascii().addPos(input->tell()); |
| 414 |
ascii().addNote("_"); |
| 415 |
return ok && !m_state->m_entryMap.empty(); |
| 416 |
} |
| 417 |
|
| 418 |
//////////////////////////////////////////////////////////// |
| 419 |
// font |
| 420 |
//////////////////////////////////////////////////////////// |
| 421 |
bool StyleParser::readFontNames(MWAWEntry const &entry) |
| 422 |
{ |
| 423 |
MWAWInputStreamPtr input = getInput(); |
| 424 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 425 |
MWAW_DEBUG_MSG(("StyleParser::readFontNames: the entry seems bad\n")); |
| 426 |
return false; |
| 427 |
} |
| 428 |
entry.setParsed(true); |
| 429 |
libmwaw::DebugStream f; |
| 430 |
f << "Entries(Font)[names]:"; |
| 431 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 432 |
long endPos=entry.end(); |
| 433 |
while (input->tell()<endPos) { |
| 434 |
long actPos=input->tell(); |
| 435 |
auto dSz=static_cast<int>(input->readULong(1)); |
| 436 |
if (!dSz || actPos+1+dSz > endPos) { |
| 437 |
MWAW_DEBUG_MSG(("StyleParser::readFontNames: can not read some entry\n")); |
| 438 |
ascii().addDelimiter(input->tell(),'|'); |
| 439 |
f << "###"; |
| 440 |
break; |
| 441 |
} |
| 442 |
std::string name(""); |
| 443 |
for (int i=0; i<dSz; ++i) name+=char(input->readULong(1)); |
| 444 |
f << name << ","; |
| 445 |
m_state->m_fontIdToFinalIdList.push_back(getFontConverter()->getId(name)); |
| 446 |
} |
| 447 |
ascii().addPos(entry.begin()); |
| 448 |
ascii().addNote(f.str().c_str()); |
| 449 |
ascii().addPos(entry.end()); |
| 450 |
ascii().addNote("_"); |
| 451 |
return true; |
| 452 |
} |
| 453 |
|
| 454 |
bool StyleParser::readFontCorr(MWAWEntry const &entry) |
| 455 |
{ |
| 456 |
MWAWInputStreamPtr input = getInput(); |
| 457 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 458 |
MWAW_DEBUG_MSG(("StyleParser::readFontCorr: the entry seems bad\n")); |
| 459 |
return false; |
| 460 |
} |
| 461 |
entry.setParsed(true); |
| 462 |
libmwaw::DebugStream f; |
| 463 |
f << "Entries(Font)[correspondance]:"; |
| 464 |
if (entry.length()%32) { |
| 465 |
MWAW_DEBUG_MSG(("StyleParser::readFontCorr: the entry size seems bad\n")); |
| 466 |
f << "###"; |
| 467 |
ascii().addPos(entry.begin()); |
| 468 |
ascii().addNote(f.str().c_str()); |
| 469 |
ascii().addPos(entry.end()); |
| 470 |
ascii().addNote("_"); |
| 471 |
return true; |
| 472 |
} |
| 473 |
|
| 474 |
ascii().addPos(entry.begin()); |
| 475 |
ascii().addNote(f.str().c_str()); |
| 476 |
ascii().addPos(entry.end()); |
| 477 |
ascii().addNote("_"); |
| 478 |
|
| 479 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 480 |
auto N=int(entry.length()/30); |
| 481 |
for (int j=0; j<N; ++j) { |
| 482 |
long pos=input->tell(); |
| 483 |
f.str(""); |
| 484 |
f << "Font-" << j << ":"; |
| 485 |
f << "id=" << input->readULong(2); |
| 486 |
for (int i=0; i<15; ++i) { // except f5, always 0 |
| 487 |
auto val=static_cast<int>(input->readULong(2)); |
| 488 |
if (!val) |
| 489 |
continue; |
| 490 |
if (i==5) // pos in fntb |
| 491 |
f << "pos=" << val << ","; |
| 492 |
else |
| 493 |
f << "f" << i << "=" << val << ","; |
| 494 |
} |
| 495 |
ascii().addPos(pos); |
| 496 |
ascii().addNote(f.str().c_str()); |
| 497 |
input->seek(pos+32, librevenge::RVNG_SEEK_SET); |
| 498 |
} |
| 499 |
return true; |
| 500 |
} |
| 501 |
|
| 502 |
bool StyleParser::readStyleTable(MWAWEntry const &entry) |
| 503 |
{ |
| 504 |
MWAWInputStreamPtr input = getInput(); |
| 505 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 506 |
MWAW_DEBUG_MSG(("StyleParser::readStyleTable: the entry seems bad\n")); |
| 507 |
return false; |
| 508 |
} |
| 509 |
entry.setParsed(true); |
| 510 |
libmwaw::DebugStream f; |
| 511 |
f << "Entries(Style):"; |
| 512 |
if (entry.length()%20) { |
| 513 |
MWAW_DEBUG_MSG(("StyleParser::readStyleTable: the entry size seems bad\n")); |
| 514 |
f << "###"; |
| 515 |
ascii().addPos(entry.begin()); |
| 516 |
ascii().addNote(f.str().c_str()); |
| 517 |
ascii().addPos(entry.end()); |
| 518 |
ascii().addNote("_"); |
| 519 |
return true; |
| 520 |
} |
| 521 |
|
| 522 |
ascii().addPos(entry.begin()); |
| 523 |
ascii().addNote(f.str().c_str()); |
| 524 |
ascii().addPos(entry.end()); |
| 525 |
ascii().addNote("_"); |
| 526 |
|
| 527 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 528 |
auto N=int(entry.length()/20); |
| 529 |
m_state->m_fontList.clear(); |
| 530 |
for (int i=0; i<N; ++i) { |
| 531 |
long pos=input->tell(); |
| 532 |
StyleParserInternal::Font font; |
| 533 |
f.str(""); |
| 534 |
long used = input->readLong(4); |
| 535 |
int dim[2]; |
| 536 |
for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
| 537 |
f << "height?=" << dim[0] << ":" << dim[1] << ","; |
| 538 |
auto fId=static_cast<int>(input->readLong(2)); |
| 539 |
if (fId < 0 && -fId<=static_cast<int>(m_state->m_fontIdToFinalIdList.size())) |
| 540 |
font.m_font.setId(m_state->m_fontIdToFinalIdList[size_t(-fId-1)]); |
| 541 |
else if (fId>0) // checkme, never seen |
| 542 |
font.m_font.setId(fId); |
| 543 |
else { |
| 544 |
MWAW_DEBUG_MSG(("StyleParser::readStyleTable: the font id seems bad\n")); |
| 545 |
f << "##fId=" << fId << ","; |
| 546 |
} |
| 547 |
auto flag=static_cast<int>(input->readULong(1)); |
| 548 |
uint32_t flags = 0; |
| 549 |
if (flag&0x1) flags |= MWAWFont::boldBit; |
| 550 |
if (flag&0x2) flags |= MWAWFont::italicBit; |
| 551 |
if (flag&0x4) font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 552 |
if (flag&0x8) flags |= MWAWFont::embossBit; |
| 553 |
if (flag&0x10) flags |= MWAWFont::shadowBit; |
| 554 |
if (flag&0x20) font.m_font.setDeltaLetterSpacing(-1.); |
| 555 |
if (flag&0x40) font.m_font.setDeltaLetterSpacing(1.); |
| 556 |
if (flag&0x80) f << "#flags=" << std::hex << (flag&0x80) << std::dec << ","; |
| 557 |
flag=static_cast<int>(input->readULong(1)); |
| 558 |
if (flag) f << "#flags1=" << std::hex << flag << std::dec << ","; |
| 559 |
font.m_font.setSize(float(input->readULong(2))); |
| 560 |
font.m_font.setFlags(flags); |
| 561 |
unsigned char col[3]; |
| 562 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 563 |
font.m_font.setColor(MWAWColor(col[0],col[1],col[2])); |
| 564 |
font.m_font.m_extra=f.str(); |
| 565 |
m_state->m_fontList.push_back(font); |
| 566 |
|
| 567 |
f.str(""); |
| 568 |
f << "Style-" << i << ":"; |
| 569 |
if (used!=1) f << "used?=" << used << ","; |
| 570 |
#ifdef DEBUG |
| 571 |
f << ",font=[" << font.m_font.getDebugString(getFontConverter()) << "]"; |
| 572 |
#endif |
| 573 |
ascii().addPos(pos); |
| 574 |
ascii().addNote(f.str().c_str()); |
| 575 |
input->seek(pos+20, librevenge::RVNG_SEEK_SET); |
| 576 |
} |
| 577 |
return true; |
| 578 |
} |
| 579 |
|
| 580 |
bool StyleParser::readFormats(MWAWEntry const &entry) |
| 581 |
{ |
| 582 |
MWAWInputStreamPtr input = getInput(); |
| 583 |
if (!entry.valid() || !input->checkPosition(entry.end()) || entry.length()<24) { |
| 584 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: the entry seems bad\n")); |
| 585 |
return false; |
| 586 |
} |
| 587 |
entry.setParsed(true); |
| 588 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 589 |
ascii().addPos(entry.end()); |
| 590 |
ascii().addNote("_"); |
| 591 |
libmwaw::DebugStream f; |
| 592 |
f << "Entries(Format):"; |
| 593 |
int val; |
| 594 |
for (int i=0; i<6; ++i) { // f5=0|18 |
| 595 |
val=static_cast<int>(input->readLong(2)); |
| 596 |
if (val) |
| 597 |
f << "f" << i << "=" << val << ","; |
| 598 |
} |
| 599 |
std::string marker(""); |
| 600 |
for (int i=0; i<4; ++i) marker+=char(input->readULong(1)); |
| 601 |
if (marker!="list") { |
| 602 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: can not find the list marker\n")); |
| 603 |
f << "###"; |
| 604 |
ascii().addPos(entry.begin()); |
| 605 |
ascii().addNote(f.str().c_str()); |
| 606 |
return false; |
| 607 |
} |
| 608 |
auto N=static_cast<int>(input->readLong(4)); |
| 609 |
f << "N=" << N << ","; |
| 610 |
for (int i=0; i<2; ++i) { // always 0 |
| 611 |
val=static_cast<int>(input->readLong(2)); |
| 612 |
if (val) |
| 613 |
f << "g" << i << "=" << val << ","; |
| 614 |
} |
| 615 |
|
| 616 |
input->seek(entry.begin()+24, librevenge::RVNG_SEEK_SET); |
| 617 |
ascii().addPos(entry.begin()); |
| 618 |
ascii().addNote(f.str().c_str()); |
| 619 |
|
| 620 |
for (int form=0; form<N; ++form) { |
| 621 |
long pos=input->tell(); |
| 622 |
marker=""; |
| 623 |
for (int c=0; c<4; ++c) marker+=char(input->readLong(1)); |
| 624 |
long dSz=static_cast<int>(input->readLong(4)); |
| 625 |
long endPos=pos+8+dSz; |
| 626 |
if (marker!="reco" || dSz<8 || endPos>entry.end()) { |
| 627 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 628 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: can not read some format\n")); |
| 629 |
break; |
| 630 |
} |
| 631 |
StyleParserInternal::Font font; |
| 632 |
f.str(""); |
| 633 |
f << "Format-C" << form << ":"; |
| 634 |
long N1=static_cast<int>(input->readULong(4)); |
| 635 |
f << "N1=" << N1 << ","; |
| 636 |
for (int i=0; i<2; ++i) { // always 0 |
| 637 |
val=static_cast<int>(input->readLong(2)); |
| 638 |
if (val) |
| 639 |
f << "f" << i << "=" << val << ","; |
| 640 |
} |
| 641 |
if (dSz<8+12*N1) { |
| 642 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: N1 is bad\n")); |
| 643 |
f << "###N1,"; |
| 644 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 645 |
ascii().addPos(pos); |
| 646 |
ascii().addNote(f.str().c_str()); |
| 647 |
m_state->m_fontList.push_back(font); |
| 648 |
continue; |
| 649 |
} |
| 650 |
ascii().addPos(pos); |
| 651 |
ascii().addNote(f.str().c_str()); |
| 652 |
std::string type(""); |
| 653 |
for (long i=0; i<N1; ++i) { |
| 654 |
pos=input->tell(); |
| 655 |
f.str(""); |
| 656 |
f << "Format-C" << form << "-" << i << ":"; |
| 657 |
marker=type=""; |
| 658 |
for (int c=0; c<4; ++c) marker+=char(input->readULong(1)); |
| 659 |
for (int c=0; c<4; ++c) type+=char(input->readULong(1)); |
| 660 |
f << marker << "[" << type << "],"; |
| 661 |
dSz=input->readLong(4); |
| 662 |
if (dSz<0 || pos+12+dSz>endPos) { |
| 663 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: can not read a subformat\n")); |
| 664 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 665 |
break; |
| 666 |
} |
| 667 |
if (type=="enum" || type=="TEXT") { |
| 668 |
// font |
| 669 |
std::string string(""); |
| 670 |
for (long c=0; c<dSz; ++c) string+=char(input->readULong(1)); |
| 671 |
f << string; |
| 672 |
if (marker=="font") |
| 673 |
font.m_font.setId(getFontConverter()->getId(string)); |
| 674 |
else { |
| 675 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 676 |
f << "###"; |
| 677 |
} |
| 678 |
} |
| 679 |
else if (dSz==1 && type=="bool") { |
| 680 |
val=static_cast<int>(input->readLong(1)); |
| 681 |
f << val; |
| 682 |
if (val<0 || val>1) { |
| 683 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: find some old bool value\n")); |
| 684 |
f << "###"; |
| 685 |
} |
| 686 |
else if (val==0) |
| 687 |
; |
| 688 |
else if (marker=="bold") |
| 689 |
font.m_font.setFlags(font.m_font.flags()|MWAWFont::boldBit); |
| 690 |
else if (marker=="cond") |
| 691 |
font.m_font.setDeltaLetterSpacing(-1.); |
| 692 |
else if (marker=="ital") |
| 693 |
font.m_font.setFlags(font.m_font.flags()|MWAWFont::italicBit); |
| 694 |
else if (marker=="outl") |
| 695 |
font.m_font.setFlags(font.m_font.flags()|MWAWFont::embossBit); |
| 696 |
else if (marker=="pexp") |
| 697 |
font.m_font.setDeltaLetterSpacing(1.); |
| 698 |
else if (marker=="shad") |
| 699 |
font.m_font.setFlags(font.m_font.flags()|MWAWFont::shadowBit); |
| 700 |
else if (marker=="strk") |
| 701 |
font.m_font.setStrikeOutStyle(MWAWFont::Line::Simple); |
| 702 |
else if (marker=="undl") |
| 703 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 704 |
else { |
| 705 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 706 |
f << "###"; |
| 707 |
} |
| 708 |
} |
| 709 |
else if (dSz==2 && type=="shor") { |
| 710 |
val=static_cast<int>(input->readLong(2)); |
| 711 |
f << val; |
| 712 |
if (marker=="fnt#") // fontId, ok to ignore |
| 713 |
; |
| 714 |
else if (marker=="objb" || marker=="pptm") // CHECKME |
| 715 |
f << "##"; |
| 716 |
else { |
| 717 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 718 |
f << "###"; |
| 719 |
} |
| 720 |
} |
| 721 |
else if (dSz==4 && type=="long") { |
| 722 |
val=static_cast<int>(input->readLong(4)); |
| 723 |
if (marker=="ptxe") // always 2000? |
| 724 |
f << float(val)/65536.f; |
| 725 |
else { |
| 726 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 727 |
f << "###" << val; |
| 728 |
} |
| 729 |
} |
| 730 |
else if (dSz==4 && type=="fixd") { |
| 731 |
float value=float(input->readLong(4))/65536.f; |
| 732 |
f << value; |
| 733 |
if (marker=="ptsz") |
| 734 |
font.m_font.setSize(value); |
| 735 |
else if (marker=="xshf") |
| 736 |
font.m_font.set(MWAWFont::Script(value,librevenge::RVNG_POINT)); |
| 737 |
else { |
| 738 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 739 |
f << "###"; |
| 740 |
} |
| 741 |
} |
| 742 |
else if (dSz==4 && type=="QDpt") { |
| 743 |
// objs |
| 744 |
int dim[2]; |
| 745 |
for (int &j : dim) j=static_cast<int>(input->readLong(2)); |
| 746 |
font.m_picture.m_size=MWAWVec2i(dim[1],dim[0]); |
| 747 |
f << font.m_picture.m_size; |
| 748 |
} |
| 749 |
else if (dSz==6 && type=="cRGB") { |
| 750 |
unsigned char col[3]; |
| 751 |
for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8); |
| 752 |
MWAWColor color(col[0],col[1],col[2]); |
| 753 |
f << color; |
| 754 |
if (marker=="colr") |
| 755 |
font.m_font.setColor(color); |
| 756 |
else if (marker=="pbcl") |
| 757 |
font.m_font.setBackgroundColor(color); |
| 758 |
else { |
| 759 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 760 |
f << "###"; |
| 761 |
} |
| 762 |
} |
| 763 |
else if (type=="PICT" && dSz) { |
| 764 |
if (marker=="obj ") { |
| 765 |
font.m_picture.m_entry.setBegin(pos+12); |
| 766 |
font.m_picture.m_entry.setLength(dSz); |
| 767 |
} |
| 768 |
else { |
| 769 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown marker\n")); |
| 770 |
f << "###"; |
| 771 |
} |
| 772 |
#ifdef DEBUG_WITH_FILES |
| 773 |
ascii().skipZone(pos+12, pos+12+dSz-1); |
| 774 |
librevenge::RVNGBinaryData file; |
| 775 |
input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
| 776 |
input->readDataBlock(dSz, file); |
| 777 |
static int volatile pictName = 0; |
| 778 |
libmwaw::DebugStream f2; |
| 779 |
f2 << "PICT-" << ++pictName << ".pct"; |
| 780 |
libmwaw::Debug::dumpFile(file, f2.str().c_str()); |
| 781 |
#endif |
| 782 |
} |
| 783 |
else { |
| 784 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: unknown type\n")); |
| 785 |
f << "###type"; |
| 786 |
} |
| 787 |
if (dSz%2) ++dSz; |
| 788 |
input->seek(pos+12+dSz, librevenge::RVNG_SEEK_SET); |
| 789 |
ascii().addPos(pos); |
| 790 |
ascii().addNote(f.str().c_str()); |
| 791 |
} |
| 792 |
m_state->m_fontList.push_back(font); |
| 793 |
if (input->tell()==endPos) continue; |
| 794 |
|
| 795 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 796 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: find extra data\n")); |
| 797 |
f.str(""); |
| 798 |
f << "Format-" << form << ":###extra"; |
| 799 |
ascii().addPos(pos); |
| 800 |
ascii().addNote(f.str().c_str()); |
| 801 |
} |
| 802 |
if (input->tell()!=entry.end()) { |
| 803 |
MWAW_DEBUG_MSG(("StyleParser::readFormats: find extra data\n")); |
| 804 |
ascii().addPos(input->tell()); |
| 805 |
ascii().addNote("Format:###extra"); |
| 806 |
} |
| 807 |
return true; |
| 808 |
} |
| 809 |
//////////////////////////////////////////////////////////// |
| 810 |
// rules/plc |
| 811 |
//////////////////////////////////////////////////////////// |
| 812 |
bool StyleParser::readRules(MWAWEntry const &entry) |
| 813 |
{ |
| 814 |
MWAWInputStreamPtr input = getInput(); |
| 815 |
if (!entry.valid() || !input->checkPosition(entry.end()) || entry.length()<24) { |
| 816 |
MWAW_DEBUG_MSG(("StyleParser::readRules: the entry seems bad\n")); |
| 817 |
return false; |
| 818 |
} |
| 819 |
|
| 820 |
entry.setParsed(true); |
| 821 |
ascii().addPos(entry.end()); |
| 822 |
ascii().addNote("_"); |
| 823 |
|
| 824 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 825 |
long pos=input->tell(); |
| 826 |
libmwaw::DebugStream f; |
| 827 |
f << "Entries(Rule):"; |
| 828 |
int val; |
| 829 |
for (int i=0; i<5; ++i) { |
| 830 |
val=static_cast<int>(input->readLong(2)); |
| 831 |
if (val) |
| 832 |
f << "f" << i << "=" << val << ","; |
| 833 |
} |
| 834 |
val=static_cast<int>(input->readLong(2)); |
| 835 |
if (val!=24) // always 18? |
| 836 |
f << "f5=" << val << ","; |
| 837 |
std::string marker(""); |
| 838 |
for (int i=0; i<4; ++i) marker+=char(input->readULong(1)); |
| 839 |
if (marker!="list") { |
| 840 |
MWAW_DEBUG_MSG(("StyleParser::readRules: can not find the list marker\n")); |
| 841 |
f << "###"; |
| 842 |
ascii().addPos(pos); |
| 843 |
ascii().addNote(f.str().c_str()); |
| 844 |
return false; |
| 845 |
} |
| 846 |
auto N=static_cast<int>(input->readLong(4)); |
| 847 |
f << "N=" << N << ","; |
| 848 |
for (int i=0; i<2; ++i) { // always 0 |
| 849 |
val=static_cast<int>(input->readLong(2)); |
| 850 |
if (val) |
| 851 |
f << "g" << i << "=" << val << ","; |
| 852 |
} |
| 853 |
ascii().addPos(pos); |
| 854 |
ascii().addNote(f.str().c_str()); |
| 855 |
|
| 856 |
m_state->m_paragraphList.clear(); |
| 857 |
for (int r=0; r<N; ++r) { |
| 858 |
pos=input->tell(); |
| 859 |
if (!input->checkPosition(pos+8)) |
| 860 |
break; |
| 861 |
f.str(""); |
| 862 |
f << "Rule-P" << r << ":"; |
| 863 |
marker=""; |
| 864 |
for (int i=0; i<4; ++i) marker+=char(input->readULong(1)); |
| 865 |
long dSz=input->readLong(4); |
| 866 |
long endPos=pos+8+dSz; |
| 867 |
if (marker!="reco" || dSz<8 || !input->checkPosition(endPos)) { |
| 868 |
MWAW_DEBUG_MSG(("StyleParser::readRules: can not read a rule\n")); |
| 869 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 870 |
break; |
| 871 |
} |
| 872 |
long N1=static_cast<int>(input->readULong(4)); |
| 873 |
f << "N1=" << N1 << ","; |
| 874 |
for (int i=0; i<2; ++i) { // always 0 |
| 875 |
val=static_cast<int>(input->readLong(2)); |
| 876 |
if (val) |
| 877 |
f << "f" << i << "=" << val << ","; |
| 878 |
} |
| 879 |
MWAWParagraph para; |
| 880 |
if (dSz<8+12*N1) { |
| 881 |
MWAW_DEBUG_MSG(("StyleParser::readRules: N1 is bad\n")); |
| 882 |
f << "###N1,"; |
| 883 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 884 |
ascii().addPos(pos); |
| 885 |
ascii().addNote(f.str().c_str()); |
| 886 |
m_state->m_paragraphList.push_back(para); |
| 887 |
continue; |
| 888 |
} |
| 889 |
ascii().addPos(pos); |
| 890 |
ascii().addNote(f.str().c_str()); |
| 891 |
|
| 892 |
std::string type(""); |
| 893 |
for (long i=0; i<N1; ++i) { |
| 894 |
pos=input->tell(); |
| 895 |
f.str(""); |
| 896 |
f << "Rule-P" << r << "-" << i << ":"; |
| 897 |
marker=type=""; |
| 898 |
for (int c=0; c<4; ++c) marker+=char(input->readULong(1)); |
| 899 |
for (int c=0; c<4; ++c) type+=char(input->readULong(1)); |
| 900 |
f << marker << "[" << type << "],"; |
| 901 |
dSz=input->readLong(4); |
| 902 |
if (dSz<0 || pos+12+dSz>endPos) { |
| 903 |
MWAW_DEBUG_MSG(("StyleParser::readRules: can not read a subrule\n")); |
| 904 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 905 |
break; |
| 906 |
} |
| 907 |
if (type=="enum") { |
| 908 |
std::string string(""); |
| 909 |
for (long c=0; c<dSz; ++c) string+=char(input->readULong(1)); |
| 910 |
f << string; |
| 911 |
if (marker=="pjst") { |
| 912 |
if (string=="cent") |
| 913 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 914 |
else if (string=="rght") |
| 915 |
para.m_justify = MWAWParagraph::JustificationRight; |
| 916 |
else if (string=="full") |
| 917 |
para.m_justify = MWAWParagraph::JustificationFull; |
| 918 |
else if (string!="left") { |
| 919 |
MWAW_DEBUG_MSG(("StyleParser::readRules: find unexpected align\n")); |
| 920 |
f << "###align,"; |
| 921 |
} |
| 922 |
} |
| 923 |
else if (marker=="BBRD") { // bottom border |
| 924 |
if (string=="DTDL") { |
| 925 |
MWAWBorder border; |
| 926 |
border.m_style=MWAWBorder::Dot; |
| 927 |
para.m_borders.resize(libmwaw::Bottom+1); |
| 928 |
para.m_borders[libmwaw::Bottom]=border; |
| 929 |
} |
| 930 |
else if (string=="SLDL") { |
| 931 |
para.m_borders.resize(libmwaw::Bottom+1); |
| 932 |
para.m_borders[libmwaw::Bottom]=MWAWBorder(); |
| 933 |
} |
| 934 |
else if (string=="THKL") { |
| 935 |
MWAWBorder border; |
| 936 |
border.m_width=2; |
| 937 |
para.m_borders.resize(libmwaw::Bottom+1); |
| 938 |
para.m_borders[libmwaw::Bottom]=border; |
| 939 |
} |
| 940 |
else { |
| 941 |
MWAW_DEBUG_MSG(("StyleParser::readRules: sorry, unknown bottom border\n")); |
| 942 |
f << "###"; |
| 943 |
} |
| 944 |
} |
| 945 |
else { |
| 946 |
MWAW_DEBUG_MSG(("StyleParser::readRules: unexpected marker\n")); |
| 947 |
f << "###"; |
| 948 |
} |
| 949 |
} |
| 950 |
else if (type=="fixd" && dSz==4) { |
| 951 |
// riin[right], lein[left], fidt[firstIndent], spaf[after], spbe[before] |
| 952 |
double value=double(input->readLong(4))/65536.; |
| 953 |
f << value; |
| 954 |
if (marker=="ledg") |
| 955 |
para.setInterline(1.0+value, librevenge::RVNG_PERCENT); |
| 956 |
else if (marker=="lein") |
| 957 |
para.m_margins[1]=value/72.; |
| 958 |
else if (marker=="riin") |
| 959 |
para.m_margins[2]=value/72.; |
| 960 |
else if (marker=="fidt") |
| 961 |
para.m_margins[0]=value/72.; |
| 962 |
else if (marker=="spbe") |
| 963 |
para.m_spacings[1]=value/72.; |
| 964 |
else if (marker=="spaf") |
| 965 |
para.m_spacings[2]=value/72.; |
| 966 |
else { |
| 967 |
MWAW_DEBUG_MSG(("StyleParser::readRules: unexpected marker\n")); |
| 968 |
f << "###"; |
| 969 |
} |
| 970 |
} |
| 971 |
else { |
| 972 |
MWAW_DEBUG_MSG(("StyleParser::readRules: unknown type\n")); |
| 973 |
f << "###type"; |
| 974 |
} |
| 975 |
if (dSz%2) ++dSz; |
| 976 |
input->seek(pos+12+dSz, librevenge::RVNG_SEEK_SET); |
| 977 |
ascii().addPos(pos); |
| 978 |
ascii().addNote(f.str().c_str()); |
| 979 |
} |
| 980 |
m_state->m_paragraphList.push_back(para); |
| 981 |
if (input->tell()==endPos) continue; |
| 982 |
|
| 983 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 984 |
MWAW_DEBUG_MSG(("StyleParser::readRules: find extra data\n")); |
| 985 |
f.str(""); |
| 986 |
f << "Rule-P" << r << ":###extra"; |
| 987 |
ascii().addPos(pos); |
| 988 |
ascii().addNote(f.str().c_str()); |
| 989 |
} |
| 990 |
if (input->tell()!=entry.end()) { |
| 991 |
MWAW_DEBUG_MSG(("StyleParser::readRules: find extra data\n")); |
| 992 |
ascii().addPos(input->tell()); |
| 993 |
ascii().addNote("Rule:###extra"); |
| 994 |
} |
| 995 |
return true; |
| 996 |
} |
| 997 |
|
| 998 |
bool StyleParser::readPLCs(MWAWEntry const &entry, bool para) |
| 999 |
{ |
| 1000 |
MWAWInputStreamPtr input = getInput(); |
| 1001 |
if (!entry.valid() || !input->checkPosition(entry.end()) || (entry.length()%8)!=0) { |
| 1002 |
MWAW_DEBUG_MSG(("StyleParser::readPLCs: the entry seems bad\n")); |
| 1003 |
return false; |
| 1004 |
} |
| 1005 |
entry.setParsed(true); |
| 1006 |
libmwaw::DebugStream f; |
| 1007 |
if (!para) |
| 1008 |
f << "Entries(PLC)[char]:"; |
| 1009 |
else |
| 1010 |
f << "Entries(PLC)[para]:"; |
| 1011 |
std::map<long,int> &map=para ? m_state->m_posParagraphIdMap : m_state->m_posFontIdMap; |
| 1012 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1013 |
char wh=para ? 'P' : 'S'; |
| 1014 |
auto N=int(entry.length()/8); |
| 1015 |
for (int i=0; i<N; ++i) { |
| 1016 |
auto pos=long(input->readULong(4)); |
| 1017 |
auto id=static_cast<int>(input->readLong(4)); |
| 1018 |
f << pos; |
| 1019 |
if (id!=-1) f << ":" << wh << id; |
| 1020 |
f << ","; |
| 1021 |
if (map.find(pos)!=map.end()) { |
| 1022 |
MWAW_DEBUG_MSG(("StyleParser::readPLCs: pos %ld already exists\n", pos)); |
| 1023 |
f << "###"; |
| 1024 |
} |
| 1025 |
else |
| 1026 |
map[pos]=id; |
| 1027 |
} |
| 1028 |
ascii().addPos(entry.begin()); |
| 1029 |
ascii().addNote(f.str().c_str()); |
| 1030 |
ascii().addPos(entry.end()); |
| 1031 |
ascii().addNote("_"); |
| 1032 |
return true; |
| 1033 |
} |
| 1034 |
|
| 1035 |
//////////////////////////////////////////////////////////// |
| 1036 |
// picture |
| 1037 |
//////////////////////////////////////////////////////////// |
| 1038 |
bool StyleParser::readPictures(MWAWEntry const &entry) |
| 1039 |
{ |
| 1040 |
MWAWInputStreamPtr input = getInput(); |
| 1041 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 1042 |
MWAW_DEBUG_MSG(("StyleParser::readPictures: the entry seems bad\n")); |
| 1043 |
return false; |
| 1044 |
} |
| 1045 |
|
| 1046 |
entry.setParsed(true); |
| 1047 |
ascii().addPos(entry.begin()); |
| 1048 |
ascii().addNote("Entries(Picture):"); |
| 1049 |
ascii().addPos(entry.end()); |
| 1050 |
ascii().addNote("_"); |
| 1051 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1052 |
|
| 1053 |
std::string type; |
| 1054 |
while (input->tell()<entry.end()) { |
| 1055 |
long pos=input->tell(); |
| 1056 |
if (!input->checkPosition(pos+24)) |
| 1057 |
break; |
| 1058 |
libmwaw::DebugStream f; |
| 1059 |
f << "Picture:"; |
| 1060 |
auto pictPos=long(input->readULong(4)); |
| 1061 |
if (pictPos) f << "pictPos=" << pictPos << ","; |
| 1062 |
StyleParserInternal::Picture pict; |
| 1063 |
type=""; |
| 1064 |
for (int i=0; i<4; ++i) type+=char(input->readULong(1)); |
| 1065 |
f << type << ","; |
| 1066 |
int val; |
| 1067 |
for (int i=0; i<2; ++i) { // always 0? |
| 1068 |
val=static_cast<int>(input->readLong(2)); |
| 1069 |
if (val) |
| 1070 |
f << "f" << i << "=" << val << ","; |
| 1071 |
} |
| 1072 |
long dSz=input->readLong(4); |
| 1073 |
if (dSz<0 || !input->checkPosition(pos+24+dSz)) { |
| 1074 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1075 |
break; |
| 1076 |
} |
| 1077 |
int dim[2]; |
| 1078 |
for (auto &d : dim) d=static_cast<int>(input->readULong(2)); |
| 1079 |
pict.m_size = MWAWVec2i(dim[1],dim[0]); |
| 1080 |
f << "sz=" << pict.m_size << ","; |
| 1081 |
for (int i=0; i<2; ++i) { // always 0 |
| 1082 |
val=static_cast<int>(input->readLong(2)); |
| 1083 |
if (val) |
| 1084 |
f << "f" << i+2 << "=" << val << ","; |
| 1085 |
} |
| 1086 |
|
| 1087 |
ascii().addPos(pos); |
| 1088 |
ascii().addNote(f.str().c_str()); |
| 1089 |
if (!dSz) continue; |
| 1090 |
|
| 1091 |
pict.m_entry.setBegin(pos+24); |
| 1092 |
pict.m_entry.setLength(dSz); |
| 1093 |
if (m_state->m_posPictureMap.find(pictPos) != m_state->m_posPictureMap.end()) { |
| 1094 |
MWAW_DEBUG_MSG(("StyleParser::readPictures: a picture already exist at %ld\n", pictPos)); |
| 1095 |
} |
| 1096 |
else |
| 1097 |
m_state->m_posPictureMap[pictPos]=pict; |
| 1098 |
#ifdef DEBUG_WITH_FILES |
| 1099 |
ascii().skipZone(pos+24, pos+24+dSz-1); |
| 1100 |
librevenge::RVNGBinaryData file; |
| 1101 |
input->seek(pos+24, librevenge::RVNG_SEEK_SET); |
| 1102 |
input->readDataBlock(dSz, file); |
| 1103 |
static int volatile pictName = 0; |
| 1104 |
libmwaw::DebugStream f2; |
| 1105 |
f2 << "PICT-" << ++pictName << ".pct"; |
| 1106 |
libmwaw::Debug::dumpFile(file, f2.str().c_str()); |
| 1107 |
#endif |
| 1108 |
input->seek(pos+24+dSz, librevenge::RVNG_SEEK_SET); |
| 1109 |
} |
| 1110 |
if (input->tell()!=entry.end()) { |
| 1111 |
MWAW_DEBUG_MSG(("StyleParser::readPictures: find extra data\n")); |
| 1112 |
ascii().addPos(input->tell()); |
| 1113 |
ascii().addNote("Picture:###extra"); |
| 1114 |
} |
| 1115 |
return true; |
| 1116 |
|
| 1117 |
} |
| 1118 |
//////////////////////////////////////////////////////////// |
| 1119 |
// other |
| 1120 |
//////////////////////////////////////////////////////////// |
| 1121 |
bool StyleParser::readExtraProperties(MWAWEntry const &entry) |
| 1122 |
{ |
| 1123 |
MWAWInputStreamPtr input = getInput(); |
| 1124 |
if (!entry.valid() || !input->checkPosition(entry.end()) || entry.length()<16) { |
| 1125 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: the entry seems bad\n")); |
| 1126 |
return false; |
| 1127 |
} |
| 1128 |
entry.setParsed(true); |
| 1129 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1130 |
ascii().addPos(entry.end()); |
| 1131 |
ascii().addNote("_"); |
| 1132 |
libmwaw::DebugStream f; |
| 1133 |
f << "Entries(XProp):"; |
| 1134 |
std::string marker(""); |
| 1135 |
for (int c=0; c<4; ++c) marker+=char(input->readULong(1)); |
| 1136 |
if (marker!="grow" && marker!="More") { |
| 1137 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: can not find main marker\n")); |
| 1138 |
f << "###marker=" << marker << ","; |
| 1139 |
ascii().addPos(entry.begin()); |
| 1140 |
ascii().addNote(f.str().c_str()); |
| 1141 |
return true; |
| 1142 |
} |
| 1143 |
f << marker << ","; |
| 1144 |
int val; |
| 1145 |
for (int i=0; i<5; ++i) { |
| 1146 |
val=static_cast<int>(input->readLong(2)); |
| 1147 |
static const int expected[]= {1,0,0x4000,0,0}; |
| 1148 |
if (val!=expected[i]) |
| 1149 |
f << "f" << i << "=" << val << ","; |
| 1150 |
} |
| 1151 |
auto N=static_cast<int>(input->readULong(2)); |
| 1152 |
f << "N=" << N << ","; |
| 1153 |
if (16*(N+1)>entry.length()) { |
| 1154 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: can not read the number of entry\n")); |
| 1155 |
f << "###"; |
| 1156 |
ascii().addPos(entry.begin()); |
| 1157 |
ascii().addNote(f.str().c_str()); |
| 1158 |
return true; |
| 1159 |
} |
| 1160 |
ascii().addPos(entry.begin()); |
| 1161 |
ascii().addNote(f.str().c_str()); |
| 1162 |
std::vector<MWAWEntry> entryList; |
| 1163 |
for (int x=0; x<N; ++x) { |
| 1164 |
long pos=input->tell(); |
| 1165 |
f.str(""); |
| 1166 |
f << "XProp-" << x << ":"; |
| 1167 |
marker=""; |
| 1168 |
for (int c=0; c<4; ++c) marker+=char(input->readULong(1)); |
| 1169 |
f << marker << ","; |
| 1170 |
int id=1; |
| 1171 |
if (marker!="Info") { |
| 1172 |
id=static_cast<int>(input->readLong(4)); |
| 1173 |
if (id!=1) f << "id=" << id << ","; |
| 1174 |
} |
| 1175 |
else { |
| 1176 |
std::string type; |
| 1177 |
for (int c=0; c<4; ++c) type+=char(input->readULong(1)); |
| 1178 |
f << type << ","; |
| 1179 |
} |
| 1180 |
for (int i=0; i<2; ++i) { |
| 1181 |
val=static_cast<int>(input->readLong(2)); |
| 1182 |
static const int expected[]= {0x4000,0}; |
| 1183 |
if (val==expected[i]) |
| 1184 |
continue; |
| 1185 |
f << "f" << i << "=" << val << ","; |
| 1186 |
} |
| 1187 |
long dPos=input->readLong(4); |
| 1188 |
f << "pos=" << dPos << ","; |
| 1189 |
ascii().addPos(pos); |
| 1190 |
ascii().addNote(f.str().c_str()); |
| 1191 |
|
| 1192 |
if (dPos>0 && 16*(N+1)+dPos<entry.length()) { |
| 1193 |
MWAWEntry dEntry; |
| 1194 |
dEntry.setType(marker); |
| 1195 |
dEntry.setId(id); |
| 1196 |
dEntry.setBegin(entry.begin()+16*(N+1)+dPos); |
| 1197 |
entryList.push_back(dEntry); |
| 1198 |
} |
| 1199 |
else if (dPos) { |
| 1200 |
ascii().addPos(pos); |
| 1201 |
ascii().addNote("###"); |
| 1202 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: dataPos seems bad\n")); |
| 1203 |
} |
| 1204 |
} |
| 1205 |
|
| 1206 |
long pos=input->tell(); |
| 1207 |
if (pos==entry.end() && entryList.empty()) |
| 1208 |
return true; |
| 1209 |
auto dSize=long(input->readULong(4)); |
| 1210 |
f.str(""); |
| 1211 |
f << "XProp[dataSz]:sz=" << dSize << ","; |
| 1212 |
if (dSize<0 || !input->checkPosition(pos+4+dSize)) { |
| 1213 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: can not read data size\n")); |
| 1214 |
f << "###"; |
| 1215 |
ascii().addPos(pos); |
| 1216 |
ascii().addNote(f.str().c_str()); |
| 1217 |
return true; |
| 1218 |
} |
| 1219 |
ascii().addPos(pos); |
| 1220 |
ascii().addNote(f.str().c_str()); |
| 1221 |
|
| 1222 |
for (auto const &dEntry : entryList) { |
| 1223 |
f.str(""); |
| 1224 |
f << "XProp[" << dEntry.type() << "-" << dEntry.id() << "]:"; |
| 1225 |
input->seek(dEntry.begin(), librevenge::RVNG_SEEK_SET); |
| 1226 |
dSize=long(input->readULong(4)); |
| 1227 |
long endPos=dEntry.begin()+4+dSize; |
| 1228 |
if (dSize<0 || !input->checkPosition(endPos)) { |
| 1229 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: can not read a data size\n")); |
| 1230 |
f << "###"; |
| 1231 |
ascii().addPos(pos); |
| 1232 |
ascii().addNote(f.str().c_str()); |
| 1233 |
continue; |
| 1234 |
} |
| 1235 |
if (dSize==1 && (dEntry.type()=="covr" || dEntry.type()=="cusg" || |
| 1236 |
dEntry.type()=="ehnd" || dEntry.type()=="ornt" || |
| 1237 |
dEntry.type()=="Coll" || dEntry.type()=="Dgok")) |
| 1238 |
f << "val=" << input->readLong(1) << ","; |
| 1239 |
else if (dSize==4 && (dEntry.type()=="copy" || dEntry.type()=="NTnt"|| dEntry.type()=="Ucpy")) |
| 1240 |
f << "val=" << input->readLong(4) << ","; |
| 1241 |
else if (dSize==6 && dEntry.type()=="Bkpr") { |
| 1242 |
for (int i=0; i<2; ++i) { // fl0=fl1=1 |
| 1243 |
val=static_cast<int>(input->readLong(1)); |
| 1244 |
if (val) f << "fl" << i << "=" << val << ","; |
| 1245 |
} |
| 1246 |
f << "ids=["; // af84,4f8 | b291,de8c |
| 1247 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(2) << std::dec << ","; |
| 1248 |
f << "],"; |
| 1249 |
} |
| 1250 |
else if (dSize==20 && dEntry.type()=="nupd") { |
| 1251 |
for (int i=0; i<10; ++i) { // f5=f7=1, f8=-256, f9=1|168 |
| 1252 |
val=static_cast<int>(input->readLong(2)); |
| 1253 |
if (val) f << "f" << i << "=" << val << ","; |
| 1254 |
} |
| 1255 |
} |
| 1256 |
else if (dSize>7 && dEntry.type()=="dprf") { |
| 1257 |
for (int i=0; i<3; ++i) { // f0=-1, f2=635f |
| 1258 |
val=static_cast<int>(input->readLong(2)); |
| 1259 |
if (val) f << "f" << i << "=" << val << ","; |
| 1260 |
} |
| 1261 |
auto dSz=static_cast<int>(input->readULong(1)); |
| 1262 |
if (dSz+7<=dSize) { |
| 1263 |
// printer name |
| 1264 |
std::string text(""); |
| 1265 |
for (int i=0; i<dSz; ++i) text+=char(input->readULong(1)); |
| 1266 |
f << text << ","; |
| 1267 |
// then 793530010cf85c010cf86001032fe80000000000000000010cf6180000004c01032fe8ffff |
| 1268 |
} |
| 1269 |
else |
| 1270 |
f << "###dSz=" << dSz << ","; |
| 1271 |
} |
| 1272 |
else if (dSize>=1 && dEntry.type()=="psnt") { // find A4Small, |
| 1273 |
auto dSz=static_cast<int>(input->readULong(1)); |
| 1274 |
if (dSz+1<=dSize) { |
| 1275 |
std::string text(""); |
| 1276 |
for (int i=0; i<dSz; ++i) text+=char(input->readULong(1)); |
| 1277 |
f << text << ","; |
| 1278 |
} |
| 1279 |
else |
| 1280 |
f << "###dSz=" << dSz << ","; |
| 1281 |
} |
| 1282 |
else if (dEntry.type()=="feat") { // find InputSlot,Upper,ManualFeed,False,PageRegion,A4Small |
| 1283 |
while (input->tell()<endPos) { |
| 1284 |
auto dSz=static_cast<int>(input->readULong(1)); |
| 1285 |
if (input->tell()+dSz>endPos) { |
| 1286 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: can not read a feat string\n")); |
| 1287 |
f << "###dSz=" << dSz << ","; |
| 1288 |
break; |
| 1289 |
} |
| 1290 |
std::string text(""); |
| 1291 |
for (int i=0; i<dSz; ++i) text+=char(input->readULong(1)); |
| 1292 |
f << text << ","; |
| 1293 |
} |
| 1294 |
} |
| 1295 |
else if (dSize>=1 && dEntry.type()=="Info") { |
| 1296 |
std::string text(""); |
| 1297 |
for (long i=0; i<dSize; ++i) text+=char(input->readULong(1)); |
| 1298 |
f << text << ","; |
| 1299 |
} |
| 1300 |
else if (dEntry.type()=="ppnf") { |
| 1301 |
auto dSz=static_cast<int>(input->readULong(2)); |
| 1302 |
if (dSz+2<=dSize) { // A4Small |
| 1303 |
std::string text(""); |
| 1304 |
for (int i=0; i<dSz; ++i) text+=char(input->readULong(1)); |
| 1305 |
f << text << ","; |
| 1306 |
/* then 000000006c61fd03ae816000554c7803ae8180220002480bfc44d00000000003ae8190000e4734041fccb400000000fe0200000000000103ae81d0000000c003ae81b00062666400000023 */ |
| 1307 |
} |
| 1308 |
else |
| 1309 |
f << "###dSz=" << dSz << ","; |
| 1310 |
} |
| 1311 |
else { |
| 1312 |
MWAW_DEBUG_MSG(("StyleParser::readExtraProperties: find unknown type\n")); |
| 1313 |
f << "###unknown"; |
| 1314 |
} |
| 1315 |
if (input->tell()!=endPos) |
| 1316 |
ascii().addDelimiter(input->tell(),'|'); |
| 1317 |
ascii().addPos(dEntry.begin()); |
| 1318 |
ascii().addNote(f.str().c_str()); |
| 1319 |
ascii().addPos(endPos); |
| 1320 |
ascii().addNote("_"); |
| 1321 |
} |
| 1322 |
return true; |
| 1323 |
} |
| 1324 |
|
| 1325 |
bool StyleParser::readBackgroundColor(MWAWEntry const &entry) |
| 1326 |
{ |
| 1327 |
MWAWInputStreamPtr input = getInput(); |
| 1328 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 1329 |
MWAW_DEBUG_MSG(("StyleParser::readBackgroundColor: the entry seems bad\n")); |
| 1330 |
return false; |
| 1331 |
} |
| 1332 |
entry.setParsed(true); |
| 1333 |
libmwaw::DebugStream f; |
| 1334 |
f << "Entries(BgColor):"; |
| 1335 |
if (entry.length()!=6) { |
| 1336 |
MWAW_DEBUG_MSG(("StyleParser::readBackgroundColor: the entry size seems bad\n")); |
| 1337 |
f << "###"; |
| 1338 |
} |
| 1339 |
else { |
| 1340 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1341 |
unsigned char col[3]; |
| 1342 |
for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8); |
| 1343 |
m_state->m_backgroundColor=MWAWColor(col[0], col[1], col[2]); |
| 1344 |
f << m_state->m_backgroundColor << ","; |
| 1345 |
} |
| 1346 |
|
| 1347 |
ascii().addPos(entry.begin()); |
| 1348 |
ascii().addNote(f.str().c_str()); |
| 1349 |
ascii().addPos(entry.end()); |
| 1350 |
ascii().addNote("_"); |
| 1351 |
return true; |
| 1352 |
} |
| 1353 |
|
| 1354 |
bool StyleParser::readMargins(MWAWEntry const &entry) |
| 1355 |
{ |
| 1356 |
MWAWInputStreamPtr input = getInput(); |
| 1357 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 1358 |
MWAW_DEBUG_MSG(("StyleParser::readMargins: the entry seems bad\n")); |
| 1359 |
return false; |
| 1360 |
} |
| 1361 |
entry.setParsed(true); |
| 1362 |
libmwaw::DebugStream f; |
| 1363 |
f << "Entries(Margins):"; |
| 1364 |
if (entry.length()!=16) { |
| 1365 |
MWAW_DEBUG_MSG(("StyleParser::readMargins: the entry size seems bad\n")); |
| 1366 |
f << "###"; |
| 1367 |
} |
| 1368 |
else { |
| 1369 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1370 |
float margins[4]; |
| 1371 |
bool ok=true; |
| 1372 |
f << "marg=["; |
| 1373 |
for (auto &margin : margins) { |
| 1374 |
margin=float(input->readULong(4))/72.0f/65536.0f; |
| 1375 |
if (margin<0) { |
| 1376 |
MWAW_DEBUG_MSG(("StyleParser::readMargins: some margin seems bad\n")); |
| 1377 |
f << "###"; |
| 1378 |
ok = false; |
| 1379 |
} |
| 1380 |
f << margin << ","; |
| 1381 |
} |
| 1382 |
f << "],"; |
| 1383 |
if (ok) { // checkme: order |
| 1384 |
getPageSpan().setMarginLeft(double(margins[0])); |
| 1385 |
getPageSpan().setMarginTop(double(margins[1])); |
| 1386 |
getPageSpan().setMarginRight(double(margins[2])); |
| 1387 |
getPageSpan().setMarginBottom(double(margins[3])); |
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
ascii().addPos(entry.begin()); |
| 1392 |
ascii().addNote(f.str().c_str()); |
| 1393 |
ascii().addPos(entry.end()); |
| 1394 |
ascii().addNote("_"); |
| 1395 |
return true; |
| 1396 |
} |
| 1397 |
|
| 1398 |
bool StyleParser::readPrintInfo(MWAWEntry const &entry) |
| 1399 |
{ |
| 1400 |
MWAWInputStreamPtr input = getInput(); |
| 1401 |
if (!entry.valid() || !input->checkPosition(entry.end()) || entry.length() < 0x78) { |
| 1402 |
MWAW_DEBUG_MSG(("StyleParser::readPrintInfo: zone size is invalid\n")); |
| 1403 |
return false; |
| 1404 |
} |
| 1405 |
|
| 1406 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1407 |
libmwaw::DebugStream f; |
| 1408 |
f << "Entries(PrintInfo):"; |
| 1409 |
libmwaw::PrinterInfo info; |
| 1410 |
if (!info.read(input)) { |
| 1411 |
MWAW_DEBUG_MSG(("StyleParser::readPrintInfo: can not read print info\n")); |
| 1412 |
return false; |
| 1413 |
} |
| 1414 |
entry.setParsed(true); |
| 1415 |
f << info; |
| 1416 |
|
| 1417 |
MWAWVec2i paperSize = info.paper().size(); |
| 1418 |
MWAWVec2i pageSize = info.page().size(); |
| 1419 |
if (pageSize.x() <= 0 || pageSize.y() <= 0 || |
| 1420 |
paperSize.x() <= 0 || paperSize.y() <= 0) { |
| 1421 |
MWAW_DEBUG_MSG(("StyleParser::readPrintInfo: the paper size seems bad\n")); |
| 1422 |
f << "###"; |
| 1423 |
ascii().addPos(entry.begin()); |
| 1424 |
ascii().addNote(f.str().c_str()); |
| 1425 |
ascii().addPos(entry.end()); |
| 1426 |
ascii().addNote("_"); |
| 1427 |
return true; |
| 1428 |
} |
| 1429 |
|
| 1430 |
// define margin from print info |
| 1431 |
MWAWVec2i lTopMargin= -1 * info.paper().pos(0); |
| 1432 |
MWAWVec2i rBotMargin=info.paper().size() - info.page().size(); |
| 1433 |
|
| 1434 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 1435 |
getPageSpan().setMarginBottom(rBotMargin.y()/72.0); |
| 1436 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 1437 |
getPageSpan().setMarginRight(rBotMargin.x()/72.0); |
| 1438 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 1439 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 1440 |
|
| 1441 |
ascii().addPos(entry.begin()); |
| 1442 |
ascii().addNote(f.str().c_str()); |
| 1443 |
ascii().addPos(entry.end()); |
| 1444 |
ascii().addNote("_"); |
| 1445 |
return true; |
| 1446 |
} |
| 1447 |
|
| 1448 |
bool StyleParser::readStat(MWAWEntry const &entry) |
| 1449 |
{ |
| 1450 |
MWAWInputStreamPtr input = getInput(); |
| 1451 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 1452 |
MWAW_DEBUG_MSG(("StyleParser::readStat: the entry seems bad\n")); |
| 1453 |
return false; |
| 1454 |
} |
| 1455 |
entry.setParsed(true); |
| 1456 |
libmwaw::DebugStream f; |
| 1457 |
f << "Entries(Stat):"; |
| 1458 |
if (entry.length()!=40) { |
| 1459 |
MWAW_DEBUG_MSG(("StyleParser::readStat: the entry size seems bad\n")); |
| 1460 |
f << "###"; |
| 1461 |
} |
| 1462 |
else { |
| 1463 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1464 |
f << "ids=["; |
| 1465 |
for (int i=0; i<2; ++i) f << std::hex << input->readULong(2) << std::dec << ","; |
| 1466 |
f << "],"; |
| 1467 |
int dim[4]; |
| 1468 |
for (auto &d : dim) d=static_cast<int>(input->readLong(2)); |
| 1469 |
f << "dim?=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]), MWAWVec2i(dim[3],dim[2])) << ","; |
| 1470 |
for (int i=0; i<14; ++i) { // f4=0|-1, f5=0|-2292, f13=0|1|3 |
| 1471 |
auto val=static_cast<int>(input->readLong(2)); |
| 1472 |
if (val) |
| 1473 |
f << "f" << i << "=" << val << ","; |
| 1474 |
} |
| 1475 |
} |
| 1476 |
|
| 1477 |
ascii().addPos(entry.begin()); |
| 1478 |
ascii().addNote(f.str().c_str()); |
| 1479 |
ascii().addPos(entry.end()); |
| 1480 |
ascii().addNote("_"); |
| 1481 |
return true; |
| 1482 |
} |
| 1483 |
|
| 1484 |
bool StyleParser::readTabWidth(MWAWEntry const &entry) |
| 1485 |
{ |
| 1486 |
MWAWInputStreamPtr input = getInput(); |
| 1487 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 1488 |
MWAW_DEBUG_MSG(("StyleParser::readTabWidth: the entry seems bad\n")); |
| 1489 |
return false; |
| 1490 |
} |
| 1491 |
entry.setParsed(true); |
| 1492 |
libmwaw::DebugStream f; |
| 1493 |
f << "Entries(TabWidth):"; |
| 1494 |
if (entry.length()!=4) { |
| 1495 |
MWAW_DEBUG_MSG(("StyleParser::readTabWidth: the entry size seems bad\n")); |
| 1496 |
f << "###"; |
| 1497 |
} |
| 1498 |
else { |
| 1499 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1500 |
f << "val=" << float(input->readLong(4))/72.f/65536.f; |
| 1501 |
} |
| 1502 |
|
| 1503 |
ascii().addPos(entry.begin()); |
| 1504 |
ascii().addNote(f.str().c_str()); |
| 1505 |
ascii().addPos(entry.end()); |
| 1506 |
ascii().addNote("_"); |
| 1507 |
return true; |
| 1508 |
} |
| 1509 |
|
| 1510 |
bool StyleParser::readVersion(MWAWEntry const &entry) |
| 1511 |
{ |
| 1512 |
MWAWInputStreamPtr input = getInput(); |
| 1513 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 1514 |
MWAW_DEBUG_MSG(("StyleParser::readVersion: the entry seems bad\n")); |
| 1515 |
return false; |
| 1516 |
} |
| 1517 |
entry.setParsed(true); |
| 1518 |
libmwaw::DebugStream f; |
| 1519 |
f << "Entries(Version):"; |
| 1520 |
if (entry.length()!=4) { |
| 1521 |
MWAW_DEBUG_MSG(("StyleParser::readVersion: the entry size seems bad\n")); |
| 1522 |
f << "###"; |
| 1523 |
} |
| 1524 |
else { |
| 1525 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1526 |
// find 0x160 for version 1.6, 0x191 for version 1.9.1 |
| 1527 |
f << "vers=" << std::hex << input->readULong(2) << std::dec << ","; |
| 1528 |
auto val=static_cast<int>(input->readULong(2)); |
| 1529 |
if (val!=0x8000) |
| 1530 |
f << "f0=" << std::hex << val << std::dec << ","; |
| 1531 |
} |
| 1532 |
|
| 1533 |
ascii().addPos(entry.begin()); |
| 1534 |
ascii().addNote(f.str().c_str()); |
| 1535 |
ascii().addPos(entry.end()); |
| 1536 |
ascii().addNote("_"); |
| 1537 |
return true; |
| 1538 |
} |
| 1539 |
|
| 1540 |
//////////////////////////////////////////////////////////// |
| 1541 |
// send data |
| 1542 |
//////////////////////////////////////////////////////////// |
| 1543 |
int StyleParser::computeNumPages(MWAWEntry const &entry, bool unicodeChar) const |
| 1544 |
{ |
| 1545 |
MWAWInputStreamPtr input = const_cast<StyleParser *>(this)->getInput(); |
| 1546 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1547 |
int nPages=1; |
| 1548 |
|
| 1549 |
int const cSize=unicodeChar ? 2 : 1; |
| 1550 |
while (!input->isEnd() && input->tell()<entry.end()) { |
| 1551 |
if (input->readLong(cSize)==0xc) |
| 1552 |
nPages++; |
| 1553 |
} |
| 1554 |
return nPages; |
| 1555 |
} |
| 1556 |
|
| 1557 |
bool StyleParser::sendText(MWAWEntry const &entry, bool unicodeChar) |
| 1558 |
{ |
| 1559 |
if (!getTextListener()) { |
| 1560 |
MWAW_DEBUG_MSG(("StyleParser::sendText: can not find the listener\n")); |
| 1561 |
return false; |
| 1562 |
} |
| 1563 |
if (!entry.valid()) { |
| 1564 |
// ok no text |
| 1565 |
return true; |
| 1566 |
} |
| 1567 |
MWAWInputStreamPtr input = getInput(); |
| 1568 |
long debPos=entry.begin(); |
| 1569 |
input->seek(debPos, librevenge::RVNG_SEEK_SET); |
| 1570 |
|
| 1571 |
libmwaw::DebugStream f; |
| 1572 |
f << "Entries(TEXT):"; |
| 1573 |
getTextListener()->setFont(MWAWFont(3,12)); |
| 1574 |
|
| 1575 |
int actPage=1; |
| 1576 |
auto numFonts=static_cast<int>(m_state->m_fontList.size()); |
| 1577 |
auto numParagraphs=static_cast<int>(m_state->m_paragraphList.size()); |
| 1578 |
long endChar = entry.length(), endPos = entry.end(); |
| 1579 |
int const cSize=unicodeChar ? 2 : 1; |
| 1580 |
for (long i=0; i <= endChar; i+=cSize) { |
| 1581 |
bool isEnd = i==endChar; |
| 1582 |
int c=isEnd ? static_cast<int>(0) : static_cast<int>(input->readULong(cSize)); |
| 1583 |
if (isEnd || c==0xd || c==0xc || c==0x2029) { |
| 1584 |
ascii().addPos(debPos); |
| 1585 |
ascii().addNote(f.str().c_str()); |
| 1586 |
debPos = input->tell(); |
| 1587 |
if (isEnd) break; |
| 1588 |
f.str(""); |
| 1589 |
f << "TEXT:"; |
| 1590 |
} |
| 1591 |
auto plcIt=m_state->m_posParagraphIdMap.find(i); |
| 1592 |
if (plcIt != m_state->m_posParagraphIdMap.end()) { |
| 1593 |
if (plcIt->second>=0 && plcIt->second<numParagraphs) |
| 1594 |
getTextListener()->setParagraph(m_state->m_paragraphList[size_t(plcIt->second)]); |
| 1595 |
f << "[Style:P" << plcIt->second << "]"; |
| 1596 |
} |
| 1597 |
plcIt=m_state->m_posFontIdMap.find(i); |
| 1598 |
if (plcIt != m_state->m_posFontIdMap.end()) { |
| 1599 |
if (plcIt->second>=0 && plcIt->second<numFonts) { |
| 1600 |
auto const &font=m_state->m_fontList[size_t(plcIt->second)]; |
| 1601 |
getTextListener()->setFont(font.m_font); |
| 1602 |
if (font.hasPicture()) |
| 1603 |
sendPicture(font.m_picture); |
| 1604 |
} |
| 1605 |
f << "[Style:C" << plcIt->second << "]"; |
| 1606 |
} |
| 1607 |
if (c>=0x100) |
| 1608 |
f << "[" << std::hex << c << std::dec << "]"; |
| 1609 |
else if (c) |
| 1610 |
f << char(c); |
| 1611 |
if (c==0xc) { |
| 1612 |
newPage(++actPage); |
| 1613 |
continue; |
| 1614 |
} |
| 1615 |
if (c==0 && !unicodeChar && !isEnd) { |
| 1616 |
// tex-edit accept control character, ... |
| 1617 |
auto nextC=static_cast<unsigned char>(input->readULong(1)); |
| 1618 |
if (nextC < 0x20) { |
| 1619 |
i++; |
| 1620 |
getTextListener()->insertChar('^'); |
| 1621 |
getTextListener()->insertChar(uint8_t('@'+nextC)); |
| 1622 |
continue; |
| 1623 |
} |
| 1624 |
input->seek(-1, librevenge::RVNG_SEEK_CUR); |
| 1625 |
} |
| 1626 |
switch (c) { |
| 1627 |
case 0x1: |
| 1628 |
if (m_state->m_posPictureMap.find(i)==m_state->m_posPictureMap.end() || |
| 1629 |
!m_state->m_posPictureMap.find(i)->second.valid()) { |
| 1630 |
MWAW_DEBUG_MSG(("StyleParser::sendPicture: can not find picture for id=%ld\n",i)); |
| 1631 |
f << "[##pict]"; |
| 1632 |
break; |
| 1633 |
} |
| 1634 |
sendPicture(m_state->m_posPictureMap.find(i)->second); |
| 1635 |
break; |
| 1636 |
case 0x9: |
| 1637 |
getTextListener()->insertTab(); |
| 1638 |
break; |
| 1639 |
case 0x2028: |
| 1640 |
getTextListener()->insertEOL(true); |
| 1641 |
break; |
| 1642 |
case 0xd: |
| 1643 |
case 0x2029: |
| 1644 |
getTextListener()->insertEOL(); |
| 1645 |
break; |
| 1646 |
case 0x11: // command key |
| 1647 |
getTextListener()->insertUnicode(0x2318); |
| 1648 |
break; |
| 1649 |
case 0x14: // apple logo: check me |
| 1650 |
getTextListener()->insertUnicode(0xf8ff); |
| 1651 |
break; |
| 1652 |
case 0xfffc: // image |
| 1653 |
break; |
| 1654 |
default: |
| 1655 |
if (c < 0x20) f << "##[" << std::hex << c << std::dec << "]"; |
| 1656 |
if (unicodeChar) |
| 1657 |
getTextListener()->insertUnicode(uint32_t(c)); |
| 1658 |
else |
| 1659 |
i += getTextListener()->insertCharacter(static_cast<unsigned char>(c), input, endPos); |
| 1660 |
break; |
| 1661 |
} |
| 1662 |
} |
| 1663 |
return true; |
| 1664 |
} |
| 1665 |
|
| 1666 |
// the pictures |
| 1667 |
bool StyleParser::sendPicture(StyleParserInternal::Picture const &pict) |
| 1668 |
{ |
| 1669 |
if (!getTextListener()) { |
| 1670 |
MWAW_DEBUG_MSG(("StyleParser::sendPicture: can not find the listener\n")); |
| 1671 |
return false; |
| 1672 |
} |
| 1673 |
|
| 1674 |
MWAWInputStreamPtr input = getInput(); |
| 1675 |
librevenge::RVNGBinaryData data; |
| 1676 |
long pos = input->tell(); |
| 1677 |
input->seek(pict.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 1678 |
input->readDataBlock(pict.m_entry.length(), data); |
| 1679 |
input->seek(pos,librevenge::RVNG_SEEK_SET); |
| 1680 |
|
| 1681 |
auto dataSz=int(data.size()); |
| 1682 |
if (!dataSz) |
| 1683 |
return false; |
| 1684 |
MWAWPosition pictPos=MWAWPosition(MWAWVec2f(0,0),MWAWVec2f(pict.m_size), librevenge::RVNG_POINT); |
| 1685 |
pictPos.setRelativePosition(MWAWPosition::Char); |
| 1686 |
MWAWEmbeddedObject picture(data); |
| 1687 |
getTextListener()->insertPicture(pictPos, picture); |
| 1688 |
return true; |
| 1689 |
} |
| 1690 |
|
| 1691 |
//////////////////////////////////////////////////////////// |
| 1692 |
// |
| 1693 |
// Low level |
| 1694 |
// |
| 1695 |
//////////////////////////////////////////////////////////// |
| 1696 |
|
| 1697 |
|
| 1698 |
//////////////////////////////////////////////////////////// |
| 1699 |
// read the header |
| 1700 |
//////////////////////////////////////////////////////////// |
| 1701 |
bool StyleParser::checkHeader(MWAWHeader *header, bool strict) |
| 1702 |
{ |
| 1703 |
*m_state = StyleParserInternal::State(); |
| 1704 |
MWAWInputStreamPtr input = getInput(); |
| 1705 |
if (!input || !input->hasDataFork() || !input->checkPosition(40)) |
| 1706 |
return false; |
| 1707 |
input->seek(0, librevenge::RVNG_SEEK_SET); |
| 1708 |
if (input->readULong(2)!=0x4348 || input->readULong(2)!=0x4e4b || |
| 1709 |
input->readULong(2)!=0x100 || input->readULong(2)!=0) |
| 1710 |
return false; |
| 1711 |
if (strict && !readTypeEntryMap()) |
| 1712 |
return false; |
| 1713 |
setVersion(1); |
| 1714 |
if (header) |
| 1715 |
header->reset(MWAWDocument::MWAW_T_STYLE, version()); |
| 1716 |
ascii().addPos(0); |
| 1717 |
ascii().addNote("FileHeader:"); |
| 1718 |
return true; |
| 1719 |
} |
| 1720 |
|
| 1721 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |