| 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 <cstring> |
| 35 |
#include <iomanip> |
| 36 |
#include <iostream> |
| 37 |
#include <limits> |
| 38 |
#include <map> |
| 39 |
#include <sstream> |
| 40 |
|
| 41 |
#include <librevenge/librevenge.h> |
| 42 |
|
| 43 |
#include "MWAWTextListener.hxx" |
| 44 |
#include "MWAWDebug.hxx" |
| 45 |
#include "MWAWFont.hxx" |
| 46 |
#include "MWAWFontConverter.hxx" |
| 47 |
#include "MWAWPageSpan.hxx" |
| 48 |
#include "MWAWParagraph.hxx" |
| 49 |
#include "MWAWPosition.hxx" |
| 50 |
#include "MWAWRSRCParser.hxx" |
| 51 |
#include "MWAWSection.hxx" |
| 52 |
#include "MWAWSubDocument.hxx" |
| 53 |
|
| 54 |
#include "LightWayTxtParser.hxx" |
| 55 |
|
| 56 |
#include "LightWayTxtText.hxx" |
| 57 |
|
| 58 |
/** Internal: the structures of a LightWayTxtText */ |
| 59 |
namespace LightWayTxtTextInternal |
| 60 |
{ |
| 61 |
/** the different plc type */ |
| 62 |
enum PLCType { P_Font, P_Font2, P_Ruler, P_Ruby, P_StyleU, P_StyleV, P_Unknown}; |
| 63 |
|
| 64 |
/** Internal : the different plc types: mainly for debugging */ |
| 65 |
struct PLC { |
| 66 |
/// the constructor |
| 67 |
PLC() |
| 68 |
: m_type(P_Unknown) |
| 69 |
, m_id(-1) |
| 70 |
, m_extra("") |
| 71 |
{ |
| 72 |
} |
| 73 |
//! operator<< |
| 74 |
friend std::ostream &operator<<(std::ostream &o, PLC const &plc); |
| 75 |
/** the PLC types */ |
| 76 |
PLCType m_type; |
| 77 |
/** the id */ |
| 78 |
int m_id; |
| 79 |
/** extra data */ |
| 80 |
std::string m_extra; |
| 81 |
}; |
| 82 |
|
| 83 |
std::ostream &operator<<(std::ostream &o, PLC const &plc) |
| 84 |
{ |
| 85 |
switch (plc.m_type) { |
| 86 |
case P_Font: |
| 87 |
o << "F"; |
| 88 |
break; |
| 89 |
case P_Ruler: |
| 90 |
o << "P"; |
| 91 |
break; |
| 92 |
case P_StyleU: |
| 93 |
o << "U"; |
| 94 |
break; |
| 95 |
case P_StyleV: |
| 96 |
o << "V"; |
| 97 |
break; |
| 98 |
case P_Font2: |
| 99 |
o << "Fa"; |
| 100 |
break; |
| 101 |
case P_Ruby: |
| 102 |
o << "Rb"; |
| 103 |
break; |
| 104 |
case P_Unknown: |
| 105 |
#if !defined(__clang__) |
| 106 |
default: |
| 107 |
#endif |
| 108 |
o << "#Unkn"; |
| 109 |
break; |
| 110 |
} |
| 111 |
if (plc.m_id >= 0) o << plc.m_id; |
| 112 |
else o << "_"; |
| 113 |
if (plc.m_extra.length()) o << ":" << plc.m_extra; |
| 114 |
else o << ","; |
| 115 |
return o; |
| 116 |
} |
| 117 |
|
| 118 |
//////////////////////////////////////// |
| 119 |
//! Internal: struct used to store the font of a LightWayTxtText |
| 120 |
struct Font { |
| 121 |
//! constructor |
| 122 |
Font() |
| 123 |
: m_font() |
| 124 |
, m_height(0) |
| 125 |
, m_pictId(0) |
| 126 |
{ |
| 127 |
} |
| 128 |
//! operator<< |
| 129 |
friend std::ostream &operator<<(std::ostream &o, Font const &font); |
| 130 |
|
| 131 |
//! merge extra data to get final font |
| 132 |
void merge(Font const &fExtra) |
| 133 |
{ |
| 134 |
m_font.setFlags(m_font.flags()|fExtra.m_font.flags()); |
| 135 |
if (fExtra.m_font.getUnderline().isSet()) |
| 136 |
m_font.setUnderline(fExtra.m_font.getUnderline()); |
| 137 |
if (fExtra.m_font.getStrikeOut().isSet()) |
| 138 |
m_font.setStrikeOut(fExtra.m_font.getStrikeOut()); |
| 139 |
if (fExtra.m_font.getOverline().isSet()) |
| 140 |
m_font.setOverline(fExtra.m_font.getOverline()); |
| 141 |
m_font.set(fExtra.m_font.script()); |
| 142 |
MWAWColor backColor; |
| 143 |
fExtra.m_font.getBackgroundColor(backColor); |
| 144 |
m_font.setBackgroundColor(backColor); |
| 145 |
m_font.m_extra += fExtra.m_font.m_extra; |
| 146 |
m_pictId = fExtra.m_pictId; |
| 147 |
} |
| 148 |
|
| 149 |
//! the font |
| 150 |
MWAWFont m_font; |
| 151 |
//! the line height |
| 152 |
int m_height; |
| 153 |
//! the pict id (if set) |
| 154 |
int m_pictId; |
| 155 |
}; |
| 156 |
|
| 157 |
std::ostream &operator<<(std::ostream &o, Font const &font) |
| 158 |
{ |
| 159 |
if (font.m_height > 0) |
| 160 |
o << "h=" << font.m_height << ","; |
| 161 |
if (font.m_pictId > 0) |
| 162 |
o << "pictId=" << font.m_pictId << ","; |
| 163 |
return o; |
| 164 |
} |
| 165 |
|
| 166 |
/** Internal: class to store the paragraph properties */ |
| 167 |
struct Paragraph final : public MWAWParagraph { |
| 168 |
//! Constructor |
| 169 |
Paragraph() |
| 170 |
: MWAWParagraph() |
| 171 |
, m_deltaSpacing(0) |
| 172 |
{ |
| 173 |
} |
| 174 |
Paragraph(Paragraph const &)=default; |
| 175 |
//! destructor |
| 176 |
~Paragraph() final; |
| 177 |
//! operator<< |
| 178 |
friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind) |
| 179 |
{ |
| 180 |
o << static_cast<MWAWParagraph const &>(ind); |
| 181 |
if (ind.m_deltaSpacing<0 || ind.m_deltaSpacing>0) o << "deltaSpacing=" << ind.m_deltaSpacing << ","; |
| 182 |
return o; |
| 183 |
} |
| 184 |
//! the paragraph delta spacing |
| 185 |
float m_deltaSpacing; |
| 186 |
}; |
| 187 |
|
| 188 |
Paragraph::~Paragraph() |
| 189 |
{ |
| 190 |
} |
| 191 |
|
| 192 |
//////////////////////////////////////// |
| 193 |
//! Internal: the header/footer zone of a LightWayTxtText |
| 194 |
struct HFZone { |
| 195 |
//! constructor |
| 196 |
HFZone() |
| 197 |
: m_numChar(0) |
| 198 |
, m_pos() |
| 199 |
, m_height(0) |
| 200 |
, m_font() |
| 201 |
, m_justify(MWAWParagraph::JustificationLeft) |
| 202 |
, m_extra("") |
| 203 |
{ |
| 204 |
} |
| 205 |
//! operator<< |
| 206 |
friend std::ostream &operator<<(std::ostream &o, HFZone const &hf); |
| 207 |
//! the number of char |
| 208 |
int m_numChar; |
| 209 |
//! the position of the text in the file |
| 210 |
MWAWEntry m_pos; |
| 211 |
//! the height |
| 212 |
int m_height; |
| 213 |
//! the font |
| 214 |
MWAWFont m_font; |
| 215 |
/** the paragraph justification */ |
| 216 |
MWAWParagraph::Justification m_justify; |
| 217 |
//! extra data |
| 218 |
std::string m_extra; |
| 219 |
}; |
| 220 |
|
| 221 |
std::ostream &operator<<(std::ostream &o, HFZone const &hf) |
| 222 |
{ |
| 223 |
if (hf.m_numChar > 0) |
| 224 |
o << "nC=" << hf.m_numChar << ","; |
| 225 |
if (hf.m_height > 0) |
| 226 |
o << "h=" << hf.m_height << ","; |
| 227 |
switch (hf.m_justify) { |
| 228 |
case MWAWParagraph::JustificationLeft: |
| 229 |
break; |
| 230 |
case MWAWParagraph::JustificationCenter: |
| 231 |
o << "just=centered, "; |
| 232 |
break; |
| 233 |
case MWAWParagraph::JustificationRight: |
| 234 |
o << "just=right, "; |
| 235 |
break; |
| 236 |
case MWAWParagraph::JustificationFull: |
| 237 |
o << "just=full, "; |
| 238 |
break; |
| 239 |
case MWAWParagraph::JustificationFullAllLines: |
| 240 |
o << "just=fullAllLines, "; |
| 241 |
break; |
| 242 |
#if !defined(__clang__) |
| 243 |
default: |
| 244 |
o << "#just=" << hf.m_justify << ", "; |
| 245 |
#endif |
| 246 |
} |
| 247 |
o << hf.m_extra; |
| 248 |
return o; |
| 249 |
} |
| 250 |
|
| 251 |
//////////////////////////////////////// |
| 252 |
//! Internal: the state of a LightWayTxtText |
| 253 |
struct State { |
| 254 |
//! constructor |
| 255 |
State() |
| 256 |
: m_version(-1) |
| 257 |
, m_numPages(-1) |
| 258 |
, m_actualPage(0) |
| 259 |
, m_fontsList() |
| 260 |
, m_auxiFontsList() |
| 261 |
, m_paragraphsList() |
| 262 |
, m_plcMap() |
| 263 |
, m_header() |
| 264 |
, m_footer() |
| 265 |
{ |
| 266 |
} |
| 267 |
|
| 268 |
//! the file version |
| 269 |
mutable int m_version; |
| 270 |
|
| 271 |
int m_numPages /* the number of pages */, m_actualPage /* the actual page */; |
| 272 |
|
| 273 |
//! the list of fonts |
| 274 |
std::vector<Font> m_fontsList; |
| 275 |
//! the auxiliar list of fonts |
| 276 |
std::vector<Font> m_auxiFontsList; |
| 277 |
//! the list of paragraph |
| 278 |
std::vector<Paragraph> m_paragraphsList; |
| 279 |
std::multimap<long, PLC> m_plcMap /** the plc map */; |
| 280 |
|
| 281 |
HFZone m_header /** header */, m_footer /** footer */; |
| 282 |
}; |
| 283 |
|
| 284 |
} |
| 285 |
|
| 286 |
//////////////////////////////////////////////////////////// |
| 287 |
// constructor/destructor, ... |
| 288 |
//////////////////////////////////////////////////////////// |
| 289 |
LightWayTxtText::LightWayTxtText(LightWayTxtParser &parser) |
| 290 |
: m_parserState(parser.getParserState()) |
| 291 |
, m_state(new LightWayTxtTextInternal::State) |
| 292 |
, m_mainParser(&parser) |
| 293 |
{ |
| 294 |
} |
| 295 |
|
| 296 |
LightWayTxtText::~LightWayTxtText() |
| 297 |
{ |
| 298 |
} |
| 299 |
|
| 300 |
int LightWayTxtText::version() const |
| 301 |
{ |
| 302 |
if (m_state->m_version < 0) |
| 303 |
m_state->m_version = m_parserState->m_version; |
| 304 |
return m_state->m_version; |
| 305 |
} |
| 306 |
|
| 307 |
int LightWayTxtText::numPages() const |
| 308 |
{ |
| 309 |
if (m_state->m_numPages >= 0) |
| 310 |
return m_state->m_numPages; |
| 311 |
const_cast<LightWayTxtText *>(this)->computePositions(); |
| 312 |
return m_state->m_numPages; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
void LightWayTxtText::computePositions() |
| 317 |
{ |
| 318 |
int nPages = 1; |
| 319 |
m_state->m_actualPage = 1; |
| 320 |
m_state->m_numPages = nPages; |
| 321 |
} |
| 322 |
|
| 323 |
bool LightWayTxtText::hasHeaderFooter(bool header) const |
| 324 |
{ |
| 325 |
if (header) |
| 326 |
return m_state->m_header.m_pos.valid(); |
| 327 |
return m_state->m_footer.m_pos.valid(); |
| 328 |
} |
| 329 |
|
| 330 |
bool LightWayTxtText::getColor(int id, MWAWColor &col) const |
| 331 |
{ |
| 332 |
if (id < 0 || id >= 11) { |
| 333 |
MWAW_DEBUG_MSG(("LightWayTxtText::createZones: can not find col for id=%d\n", id)); |
| 334 |
return false; |
| 335 |
} |
| 336 |
static uint32_t const color[] = { |
| 337 |
0, 0xFF0000, 0x00FF00, 0xFF, 0xFFFF, 0xFF00FF, 0xFFFF00, |
| 338 |
0xFF8040, 0x800000, 0x808080, 0xFFFFFF |
| 339 |
}; |
| 340 |
col = color[id]; |
| 341 |
return true; |
| 342 |
} |
| 343 |
|
| 344 |
//////////////////////////////////////////////////////////// |
| 345 |
// Intermediate level |
| 346 |
//////////////////////////////////////////////////////////// |
| 347 |
|
| 348 |
// find the different zones |
| 349 |
bool LightWayTxtText::createZones() |
| 350 |
{ |
| 351 |
MWAWRSRCParserPtr rsrcParser = m_mainParser->getRSRCParser(); |
| 352 |
if (!rsrcParser) { |
| 353 |
MWAW_DEBUG_MSG(("LightWayTxtText::createZones: can not find the entry map\n")); |
| 354 |
return false; |
| 355 |
} |
| 356 |
auto const &entryMap = rsrcParser->getEntriesMap(); |
| 357 |
|
| 358 |
// the different zones |
| 359 |
auto it = entryMap.lower_bound("styl"); |
| 360 |
while (it != entryMap.end()) { |
| 361 |
if (it->first != "styl") |
| 362 |
break; |
| 363 |
|
| 364 |
MWAWEntry const &entry = it++->second; |
| 365 |
readFonts(entry); |
| 366 |
} |
| 367 |
it = entryMap.lower_bound("styw"); |
| 368 |
while (it != entryMap.end()) { |
| 369 |
if (it->first != "styw") |
| 370 |
break; |
| 371 |
MWAWEntry const &entry = it++->second; |
| 372 |
readFont2(entry); |
| 373 |
} |
| 374 |
it = entryMap.lower_bound("styx"); |
| 375 |
while (it != entryMap.end()) { |
| 376 |
if (it->first != "styx") |
| 377 |
break; |
| 378 |
|
| 379 |
MWAWEntry const &entry = it++->second; |
| 380 |
readRulers(entry); |
| 381 |
} |
| 382 |
|
| 383 |
it = entryMap.lower_bound("styu"); // pos, flags, 0? |
| 384 |
while (it != entryMap.end()) { |
| 385 |
if (it->first != "styu") |
| 386 |
break; |
| 387 |
MWAWEntry const &entry = it++->second; |
| 388 |
readStyleU(entry); |
| 389 |
} |
| 390 |
it = entryMap.lower_bound("styv"); // never seen |
| 391 |
while (it != entryMap.end()) { |
| 392 |
if (it->first != "styv") |
| 393 |
break; |
| 394 |
MWAWEntry const &entry = it++->second; |
| 395 |
readUnknownStyle(entry); |
| 396 |
} |
| 397 |
it = entryMap.lower_bound("styy"); // pos, 2 flags |
| 398 |
while (it != entryMap.end()) { |
| 399 |
if (it->first != "styy") |
| 400 |
break; |
| 401 |
MWAWEntry const &entry = it++->second; |
| 402 |
readRuby(entry); |
| 403 |
} |
| 404 |
|
| 405 |
// now update the different data |
| 406 |
computePositions(); |
| 407 |
return true; |
| 408 |
} |
| 409 |
|
| 410 |
bool LightWayTxtText::sendMainText() |
| 411 |
{ |
| 412 |
MWAWTextListenerPtr listener=m_parserState->m_textListener; |
| 413 |
if (!listener) { |
| 414 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendMainText: can not find a listener\n")); |
| 415 |
return false; |
| 416 |
} |
| 417 |
bool useDataFork=m_mainParser->textInDataFork(); |
| 418 |
libmwaw::DebugFile &ascFile = |
| 419 |
useDataFork ? m_parserState->m_asciiFile : m_mainParser->rsrcAscii(); |
| 420 |
libmwaw::DebugStream f, f2; |
| 421 |
MWAWInputStreamPtr input= |
| 422 |
useDataFork ? m_parserState->m_input : m_mainParser->rsrcInput(); |
| 423 |
|
| 424 |
long beginPos=0, endPos=-1; |
| 425 |
if (!useDataFork) { |
| 426 |
MWAWEntry entry = m_mainParser->getRSRCParser()->getEntry("TEXT", 128); |
| 427 |
if (!entry.valid()) { |
| 428 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendMainText: can not find text entry\n")); |
| 429 |
return false; |
| 430 |
} |
| 431 |
beginPos=entry.begin(); |
| 432 |
endPos=entry.end(); |
| 433 |
} |
| 434 |
|
| 435 |
long pos = beginPos; |
| 436 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 437 |
LightWayTxtTextInternal::Font font, auxiFont; |
| 438 |
|
| 439 |
int numCols, sepWidth; |
| 440 |
if (m_mainParser->getColumnInfo(numCols, sepWidth) && numCols > 1) { |
| 441 |
MWAWSection sec; |
| 442 |
sec.setColumns(numCols, m_mainParser->getPageWidth()/double(numCols), librevenge::RVNG_INCH); |
| 443 |
listener->openSection(sec); |
| 444 |
} |
| 445 |
|
| 446 |
float deltaSpacing=0; |
| 447 |
while (1) { |
| 448 |
long actPos = input->tell(); |
| 449 |
bool done = input->isEnd() || (endPos>=0&&actPos>=endPos); |
| 450 |
char c = done ? char(0) : char(input->readULong(1)); |
| 451 |
if (c==0xd || done) { |
| 452 |
f2.str(""); |
| 453 |
f2 << "Entries(TextContent):" << f.str(); |
| 454 |
ascFile.addPos(pos); |
| 455 |
ascFile.addNote(f2.str().c_str()); |
| 456 |
f.str(""); |
| 457 |
pos = actPos+1; |
| 458 |
} |
| 459 |
if (done) break; |
| 460 |
|
| 461 |
long actC=actPos-beginPos; |
| 462 |
auto plcIt = m_state->m_plcMap.find(actC); |
| 463 |
bool fontChanged = false; |
| 464 |
while (plcIt != m_state->m_plcMap.end() && plcIt->first<=actC) { |
| 465 |
auto const &plc = plcIt++->second; |
| 466 |
f << "[" << plc << "]"; |
| 467 |
switch (plc.m_type) { |
| 468 |
case LightWayTxtTextInternal::P_Font: |
| 469 |
if (plc.m_id < 0 || plc.m_id >= int(m_state->m_fontsList.size())) { |
| 470 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendMainText: can not find font %d\n", plc.m_id)); |
| 471 |
break; |
| 472 |
} |
| 473 |
font = m_state->m_fontsList[size_t(plc.m_id)]; |
| 474 |
fontChanged = true; |
| 475 |
break; |
| 476 |
case LightWayTxtTextInternal::P_Font2: |
| 477 |
if (plc.m_id < 0 || plc.m_id >= int(m_state->m_auxiFontsList.size())) { |
| 478 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendMainText: can not find auxi font %d\n", plc.m_id)); |
| 479 |
break; |
| 480 |
} |
| 481 |
auxiFont = m_state->m_auxiFontsList[size_t(plc.m_id)]; |
| 482 |
fontChanged = true; |
| 483 |
break; |
| 484 |
case LightWayTxtTextInternal::P_Ruler: { |
| 485 |
float newDeltaSpacing = 0; |
| 486 |
if (plc.m_id < 0 || plc.m_id >= int(m_state->m_paragraphsList.size())) { |
| 487 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendMainText: can not find paragraph %d\n", plc.m_id)); |
| 488 |
} |
| 489 |
else { |
| 490 |
auto const ¶=m_state->m_paragraphsList[size_t(plc.m_id)]; |
| 491 |
newDeltaSpacing = para.m_deltaSpacing; |
| 492 |
setProperty(para); |
| 493 |
} |
| 494 |
if (deltaSpacing < newDeltaSpacing || deltaSpacing > newDeltaSpacing) { |
| 495 |
deltaSpacing=newDeltaSpacing; |
| 496 |
fontChanged = true; |
| 497 |
} |
| 498 |
break; |
| 499 |
} |
| 500 |
case LightWayTxtTextInternal::P_Ruby: |
| 501 |
case LightWayTxtTextInternal::P_StyleU: |
| 502 |
case LightWayTxtTextInternal::P_StyleV: |
| 503 |
case LightWayTxtTextInternal::P_Unknown: |
| 504 |
#if !defined(__clang__) |
| 505 |
default: |
| 506 |
#endif |
| 507 |
break; |
| 508 |
} |
| 509 |
} |
| 510 |
f << c; |
| 511 |
if (fontChanged) { |
| 512 |
LightWayTxtTextInternal::Font final(font); |
| 513 |
final.merge(auxiFont); |
| 514 |
if (deltaSpacing<0||deltaSpacing>0) |
| 515 |
final.m_font.setDeltaLetterSpacing(deltaSpacing+final.m_font.deltaLetterSpacing()); |
| 516 |
listener->setFont(final.m_font); |
| 517 |
if (final.m_pictId>0) { |
| 518 |
m_mainParser->sendGraphic(final.m_pictId); |
| 519 |
if (c=='\xca') |
| 520 |
continue; |
| 521 |
} |
| 522 |
} |
| 523 |
switch (c) { |
| 524 |
case 0x9: |
| 525 |
listener->insertTab(); |
| 526 |
break; |
| 527 |
case 0xa: |
| 528 |
listener->insertEOL(true); |
| 529 |
break; |
| 530 |
case 0xc: // new section (done) |
| 531 |
break; |
| 532 |
case 0xd: |
| 533 |
listener->insertEOL(); |
| 534 |
break; |
| 535 |
|
| 536 |
default: |
| 537 |
listener->insertCharacter(static_cast<unsigned char>(c), input); |
| 538 |
break; |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
return true; |
| 543 |
} |
| 544 |
|
| 545 |
////////////////////////////////////////////// |
| 546 |
// Fonts |
| 547 |
////////////////////////////////////////////// |
| 548 |
bool LightWayTxtText::readFonts(MWAWEntry const &entry) |
| 549 |
{ |
| 550 |
if (!entry.valid() || entry.length() < 2) { |
| 551 |
MWAW_DEBUG_MSG(("LightWayTxtText::readFonts: the entry is bad\n")); |
| 552 |
return false; |
| 553 |
} |
| 554 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 555 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 556 |
long pos = entry.begin(); |
| 557 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 558 |
|
| 559 |
libmwaw::DebugStream f; |
| 560 |
f << "Entries(Fonts)[" << entry.id() << "]:"; |
| 561 |
entry.setParsed(true); |
| 562 |
auto N=static_cast<int>(input->readULong(2)); |
| 563 |
f << "N=" << N << ","; |
| 564 |
if (long(N*20+2) != entry.length()) { |
| 565 |
MWAW_DEBUG_MSG(("LightWayTxtText::readFonts: the number of entry seems bad\n")); |
| 566 |
f << "###"; |
| 567 |
ascFile.addPos(pos-4); |
| 568 |
ascFile.addNote(f.str().c_str()); |
| 569 |
return false; |
| 570 |
} |
| 571 |
ascFile.addPos(pos-4); |
| 572 |
ascFile.addNote(f.str().c_str()); |
| 573 |
|
| 574 |
LightWayTxtTextInternal::PLC plc; |
| 575 |
plc.m_type = LightWayTxtTextInternal::P_Font; |
| 576 |
for (int i = 0; i < N; i++) { |
| 577 |
pos = input->tell(); |
| 578 |
LightWayTxtTextInternal::Font font; |
| 579 |
f.str(""); |
| 580 |
long cPos = input->readLong(4); |
| 581 |
font.m_height = static_cast<int>(input->readLong(2)); |
| 582 |
auto sz = float(input->readLong(2)); |
| 583 |
font.m_font.setId(static_cast<int>(input->readULong(2))); |
| 584 |
uint32_t flags=0; |
| 585 |
auto flag=static_cast<int>(input->readULong(1)); |
| 586 |
if (flag&0x1) flags |= MWAWFont::boldBit; |
| 587 |
if (flag&0x2) flags |= MWAWFont::italicBit; |
| 588 |
if (flag&0x4) font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 589 |
if (flag&0x8) flags |= MWAWFont::embossBit; |
| 590 |
if (flag&0x10) flags |= MWAWFont::shadowBit; |
| 591 |
if (flag&0x20) font.m_font.setDeltaLetterSpacing(-1); |
| 592 |
if (flag&0x40) font.m_font.setDeltaLetterSpacing(1); |
| 593 |
if (flag&0x80) f << "#fl80,"; |
| 594 |
auto val = static_cast<int>(input->readULong(1)); // always 0? |
| 595 |
if (val) f << "#f0=" << val << ","; |
| 596 |
font.m_font.setFlags(flags); |
| 597 |
font.m_font.setSize(float(input->readLong(2))); |
| 598 |
if (sz < font.m_font.size() || sz > font.m_font.size()) |
| 599 |
f << "#sz=" << sz << ","; |
| 600 |
unsigned char col[3]; |
| 601 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 602 |
if (col[0] || col[1] || col[2]) |
| 603 |
font.m_font.setColor(MWAWColor(col[0],col[1],col[2])); |
| 604 |
font.m_font.m_extra=f.str(); |
| 605 |
f.str(""); |
| 606 |
f << "Fonts-" << i << ":cPos=" << std::hex << cPos << std::dec << "," |
| 607 |
<< font.m_font.getDebugString(m_parserState->m_fontConverter) << font; |
| 608 |
|
| 609 |
m_state->m_fontsList.push_back(font); |
| 610 |
plc.m_id = i; |
| 611 |
m_state->m_plcMap.insert(std::map<long, LightWayTxtTextInternal::PLC>::value_type(cPos, plc)); |
| 612 |
|
| 613 |
ascFile.addPos(pos); |
| 614 |
ascFile.addNote(f.str().c_str()); |
| 615 |
|
| 616 |
input->seek(pos+20, librevenge::RVNG_SEEK_SET); |
| 617 |
} |
| 618 |
return true; |
| 619 |
} |
| 620 |
|
| 621 |
bool LightWayTxtText::readFont2(MWAWEntry const &entry) |
| 622 |
{ |
| 623 |
if (!entry.valid() || (entry.length()%10) != 2) { |
| 624 |
MWAW_DEBUG_MSG(("LightWayTxtText::readFont2: the entry seems bad\n")); |
| 625 |
return false; |
| 626 |
} |
| 627 |
|
| 628 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 629 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 630 |
long pos = entry.begin(); |
| 631 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 632 |
|
| 633 |
libmwaw::DebugStream f; |
| 634 |
f << "Entries(Font2)[" << entry.id() << "]:"; |
| 635 |
entry.setParsed(true); |
| 636 |
auto N=static_cast<int>(input->readULong(2)); |
| 637 |
f << "N=" << N << ","; |
| 638 |
if (entry.length() != N*10+2) { |
| 639 |
f << "###"; |
| 640 |
MWAW_DEBUG_MSG(("LightWayTxtText::readFont2: N seems bad\n")); |
| 641 |
ascFile.addPos(pos-4); |
| 642 |
ascFile.addNote(f.str().c_str()); |
| 643 |
|
| 644 |
return false; |
| 645 |
} |
| 646 |
|
| 647 |
ascFile.addPos(pos-4); |
| 648 |
ascFile.addNote(f.str().c_str()); |
| 649 |
LightWayTxtTextInternal::PLC plc; |
| 650 |
plc.m_type = LightWayTxtTextInternal::P_Font2; |
| 651 |
for (int i = 0; i < N; i++) { |
| 652 |
pos = input->tell(); |
| 653 |
f.str(""); |
| 654 |
LightWayTxtTextInternal::Font font; |
| 655 |
|
| 656 |
long cPos = input->readLong(4); |
| 657 |
uint32_t flag = static_cast<uint32_t>(input->readULong(2)), flags=0; |
| 658 |
switch ((flag>>3)&7) { |
| 659 |
case 0: |
| 660 |
break; |
| 661 |
case 1: |
| 662 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 663 |
break; |
| 664 |
case 2: |
| 665 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 666 |
font.m_font.setUnderlineType(MWAWFont::Line::Double); |
| 667 |
break; |
| 668 |
case 3: |
| 669 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 670 |
font.m_font.setUnderlineWidth(2.0); |
| 671 |
break; |
| 672 |
case 4: |
| 673 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Dot); |
| 674 |
break; |
| 675 |
case 5: |
| 676 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Dot); |
| 677 |
font.m_font.setUnderlineWidth(2.0); |
| 678 |
break; |
| 679 |
default: |
| 680 |
f << "#underline=" << ((flag>>3)&7) << ","; |
| 681 |
break; |
| 682 |
} |
| 683 |
switch ((flag>>6)&7) { |
| 684 |
case 0: |
| 685 |
break; |
| 686 |
case 1: |
| 687 |
font.m_font.setStrikeOutStyle(MWAWFont::Line::Simple); |
| 688 |
break; |
| 689 |
case 2: |
| 690 |
font.m_font.setStrikeOutStyle(MWAWFont::Line::Simple); |
| 691 |
font.m_font.setStrikeOutType(MWAWFont::Line::Double); |
| 692 |
break; |
| 693 |
case 3: |
| 694 |
font.m_font.setStrikeOutStyle(MWAWFont::Line::Simple); |
| 695 |
font.m_font.setStrikeOutWidth(2.0); |
| 696 |
break; |
| 697 |
case 4: |
| 698 |
font.m_font.setStrikeOutStyle(MWAWFont::Line::Dot); |
| 699 |
break; |
| 700 |
case 5: |
| 701 |
font.m_font.setStrikeOutStyle(MWAWFont::Line::Dot); |
| 702 |
font.m_font.setStrikeOutWidth(2.0); |
| 703 |
break; |
| 704 |
default: |
| 705 |
f << "#strike=" << ((flag>>6)&7) << ","; |
| 706 |
break; |
| 707 |
} |
| 708 |
switch ((flag>>9)&7) { |
| 709 |
case 0: |
| 710 |
break; |
| 711 |
case 1: |
| 712 |
font.m_font.setOverlineStyle(MWAWFont::Line::Simple); |
| 713 |
break; |
| 714 |
case 2: |
| 715 |
font.m_font.setOverlineStyle(MWAWFont::Line::Simple); |
| 716 |
font.m_font.setOverlineType(MWAWFont::Line::Double); |
| 717 |
break; |
| 718 |
case 3: |
| 719 |
font.m_font.setOverlineStyle(MWAWFont::Line::Simple); |
| 720 |
font.m_font.setOverlineWidth(2.0); |
| 721 |
break; |
| 722 |
case 4: |
| 723 |
font.m_font.setOverlineStyle(MWAWFont::Line::Dot); |
| 724 |
break; |
| 725 |
case 5: |
| 726 |
font.m_font.setOverlineStyle(MWAWFont::Line::Dot); |
| 727 |
font.m_font.setOverlineWidth(2.0); |
| 728 |
break; |
| 729 |
default: |
| 730 |
f << "#over=" << ((flag>>9)&7) << ","; |
| 731 |
break; |
| 732 |
} |
| 733 |
if (flag >> 12) { |
| 734 |
MWAWColor col(0); |
| 735 |
if (getColor(int(flag >> 12), col)) { |
| 736 |
font.m_font.setOverlineColor(col); |
| 737 |
font.m_font.setStrikeOutColor(col); |
| 738 |
font.m_font.setUnderlineColor(col); |
| 739 |
} |
| 740 |
else |
| 741 |
f << "#colorId[line]=" << (flag >> 12) << ","; |
| 742 |
} |
| 743 |
flag &= 0x0004; |
| 744 |
if (flag) f << "flags=#" << std::hex << flag << std::dec << ","; |
| 745 |
/* fl0=0|2|b|40|42|..|a0 */ |
| 746 |
auto val = long(input->readULong(1)); |
| 747 |
MWAWColor backColor(MWAWColor::black()); |
| 748 |
if ((val & 0xf0) && !getColor(int(val>>4), backColor)) |
| 749 |
f << "#backColorId=" << (val>>4) << ","; |
| 750 |
int percent = (val & 0xf); |
| 751 |
if (percent >= 0 && percent <= 10) { |
| 752 |
float percentVal = 0.1f*float(percent); |
| 753 |
backColor =MWAWColor::barycenter(percentVal,backColor,1.f-percentVal,MWAWColor::white()); |
| 754 |
font.m_font.setBackgroundColor(backColor); |
| 755 |
} |
| 756 |
else if (percent == 11) // fixme: backColor is the border color |
| 757 |
flags |= MWAWFont::boxedBit; |
| 758 |
else { |
| 759 |
MWAW_DEBUG_MSG(("LightWayTxtText::readFont2: find unknown percent id=%d\n", percent)); |
| 760 |
} |
| 761 |
// 0: 0%, .. 10:100%, 11:border |
| 762 |
if (val & 0xf) |
| 763 |
f << "backPatternId=" << (val&0xf) << ","; |
| 764 |
flag = static_cast<uint32_t>(input->readULong(1)); |
| 765 |
switch (flag&7) { |
| 766 |
case 0: |
| 767 |
break; |
| 768 |
case 1: |
| 769 |
font.m_font.set(MWAWFont::Script(33)); |
| 770 |
break; |
| 771 |
case 2: |
| 772 |
font.m_font.set(MWAWFont::Script(-33)); |
| 773 |
break; |
| 774 |
case 5: |
| 775 |
font.m_font.set(MWAWFont::Script::super()); |
| 776 |
break; |
| 777 |
case 6: |
| 778 |
font.m_font.set(MWAWFont::Script::sub()); |
| 779 |
break; |
| 780 |
default: |
| 781 |
f << "#pos=" << (flag&7) << ","; |
| 782 |
} |
| 783 |
if (flag&8) f << "write[hor],"; |
| 784 |
if (flag & 0xF0) |
| 785 |
f << "#pos2=" << std::hex << (flag&0xF0) << std::dec << ","; |
| 786 |
font.m_pictId = static_cast<int>(input->readULong(2)); |
| 787 |
font.m_font.setFlags(flags); |
| 788 |
font.m_font.m_extra = f.str(); |
| 789 |
plc.m_id = i; |
| 790 |
plc.m_extra = f.str(); |
| 791 |
m_state->m_auxiFontsList.push_back(font); |
| 792 |
m_state->m_plcMap.insert(std::map<long, LightWayTxtTextInternal::PLC>::value_type(cPos, plc)); |
| 793 |
|
| 794 |
f.str(""); |
| 795 |
f << "Font2-" << i << ":cPos=" << std::hex << cPos << std::dec << ",Fa" << i << "," |
| 796 |
<< font.m_font.getDebugString(m_parserState->m_fontConverter) << font; |
| 797 |
ascFile.addPos(pos); |
| 798 |
ascFile.addNote(f.str().c_str()); |
| 799 |
input->seek(pos+10, librevenge::RVNG_SEEK_SET); |
| 800 |
} |
| 801 |
return true; |
| 802 |
} |
| 803 |
|
| 804 |
////////////////////////////////////////////// |
| 805 |
// Ruler |
| 806 |
////////////////////////////////////////////// |
| 807 |
void LightWayTxtText::setProperty(MWAWParagraph const &ruler) |
| 808 |
{ |
| 809 |
if (!m_parserState->m_textListener) return; |
| 810 |
m_parserState->m_textListener->setParagraph(ruler); |
| 811 |
} |
| 812 |
|
| 813 |
bool LightWayTxtText::readRulers(MWAWEntry const &entry) |
| 814 |
{ |
| 815 |
if (!entry.valid() || (entry.length()%84) != 2) { |
| 816 |
MWAW_DEBUG_MSG(("LightWayTxtText::readRulers: the entry seems bad\n")); |
| 817 |
return false; |
| 818 |
} |
| 819 |
|
| 820 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 821 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 822 |
long pos = entry.begin(); |
| 823 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 824 |
|
| 825 |
libmwaw::DebugStream f; |
| 826 |
f << "Entries(Ruler)[" << entry.id() << "]:"; |
| 827 |
entry.setParsed(true); |
| 828 |
auto N=static_cast<int>(input->readULong(2)); |
| 829 |
f << "N=" << N << ","; |
| 830 |
if (entry.length() != N*84+2) { |
| 831 |
f << "###"; |
| 832 |
MWAW_DEBUG_MSG(("LightWayTxtText::readRulers: N seems bad\n")); |
| 833 |
ascFile.addPos(pos-4); |
| 834 |
ascFile.addNote(f.str().c_str()); |
| 835 |
|
| 836 |
return false; |
| 837 |
} |
| 838 |
|
| 839 |
ascFile.addPos(pos-4); |
| 840 |
ascFile.addNote(f.str().c_str()); |
| 841 |
LightWayTxtTextInternal::PLC plc; |
| 842 |
plc.m_type = LightWayTxtTextInternal::P_Ruler; |
| 843 |
for (int i = 0; i < N; i++) { |
| 844 |
LightWayTxtTextInternal::Paragraph para; |
| 845 |
|
| 846 |
pos = input->tell(); |
| 847 |
f.str(""); |
| 848 |
long cPos = input->readLong(4); |
| 849 |
para.m_marginsUnit = librevenge::RVNG_POINT; |
| 850 |
para.m_margins[0] = static_cast<int>(input->readLong(2)); |
| 851 |
para.m_margins[1] = static_cast<int>(input->readLong(2)); |
| 852 |
para.m_margins[2] = static_cast<int>(input->readLong(2)); |
| 853 |
para.m_margins[0] = para.m_margins[0].get()-para.m_margins[1].get(); |
| 854 |
|
| 855 |
long val = static_cast<int>(input->readLong(2)); |
| 856 |
if (val) |
| 857 |
para.m_spacings[1]=para.m_spacings[2]=double(val)/72.; |
| 858 |
para.m_deltaSpacing = float(input->readLong(2)); |
| 859 |
auto flag = long(input->readULong(1)); |
| 860 |
switch (flag) { |
| 861 |
case 0: |
| 862 |
break; // left |
| 863 |
case 1: |
| 864 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 865 |
break; |
| 866 |
case 2: |
| 867 |
para.m_justify = MWAWParagraph::JustificationRight; |
| 868 |
break; |
| 869 |
case 3: |
| 870 |
para.m_justify = MWAWParagraph::JustificationFull; |
| 871 |
break; |
| 872 |
default: |
| 873 |
f << "#justify=" << flag << ","; |
| 874 |
} |
| 875 |
auto numTabs = static_cast<int>(input->readULong(1)); |
| 876 |
if (numTabs > 16) { |
| 877 |
MWAW_DEBUG_MSG(("LightWayTxtText::readRulers: the numbers of tabs seems bad\n")); |
| 878 |
f << "###nTabs=" << numTabs << ","; |
| 879 |
numTabs=0; |
| 880 |
} |
| 881 |
auto tabsType = static_cast<uint32_t>(input->readULong(4)); |
| 882 |
for (int j = 0; j < numTabs; j++) { |
| 883 |
MWAWTabStop tab; |
| 884 |
tab.m_position = double(input->readLong(2))/72.; |
| 885 |
switch (tabsType&3) { |
| 886 |
case 1: |
| 887 |
tab.m_alignment = MWAWTabStop::CENTER; |
| 888 |
break; |
| 889 |
case 2: |
| 890 |
tab.m_alignment = MWAWTabStop::RIGHT; |
| 891 |
break; |
| 892 |
case 3: |
| 893 |
tab.m_alignment = MWAWTabStop::DECIMAL; |
| 894 |
break; |
| 895 |
case 0: // left |
| 896 |
default: |
| 897 |
break; |
| 898 |
} |
| 899 |
tabsType = tabsType>>2; |
| 900 |
para.m_tabs->push_back(tab); |
| 901 |
} |
| 902 |
input->seek(pos+52, librevenge::RVNG_SEEK_SET); |
| 903 |
auto tabsLeader = static_cast<uint32_t>(input->readULong(4)); |
| 904 |
for (auto &tab : *para.m_tabs) { |
| 905 |
uint16_t leader=0; |
| 906 |
switch (tabsLeader&3) { |
| 907 |
case 1: |
| 908 |
leader='.'; |
| 909 |
break; |
| 910 |
case 2: |
| 911 |
leader='-'; |
| 912 |
break; |
| 913 |
case 3: |
| 914 |
leader='_'; |
| 915 |
break; |
| 916 |
case 0: // none |
| 917 |
default: |
| 918 |
break; |
| 919 |
} |
| 920 |
tabsLeader = tabsLeader>>2; |
| 921 |
if (!leader) continue; |
| 922 |
tab.m_leaderCharacter = leader; |
| 923 |
} |
| 924 |
for (int j = 0; j < 3; j++) { // g0=0|0b13 |
| 925 |
val = static_cast<int>(input->readLong(2)); |
| 926 |
if (val) |
| 927 |
f << "g" << j << "=" << std::hex << val << std::dec << ","; |
| 928 |
} |
| 929 |
for (int j = 0; j < 2; j++) { // g5=5|14 |
| 930 |
val = long(input->readULong(1)); |
| 931 |
if (val) f << "g" << j+3 << "=" << val << ","; |
| 932 |
} |
| 933 |
for (int j = 0; j < 10; j++) { // always 0 |
| 934 |
val = static_cast<int>(input->readLong(2)); |
| 935 |
if (val) |
| 936 |
f << "h" << j << "=" << std::hex << val << std::dec << ","; |
| 937 |
} |
| 938 |
para.m_extra = f.str(); |
| 939 |
m_state->m_paragraphsList.push_back(para); |
| 940 |
plc.m_id = i; |
| 941 |
m_state->m_plcMap.insert(std::map<long, LightWayTxtTextInternal::PLC>::value_type(cPos, plc)); |
| 942 |
|
| 943 |
f.str(""); |
| 944 |
f << "Ruler-" << i << ":cPos=" << std::hex << cPos << std::dec << "," << para; |
| 945 |
ascFile.addPos(pos); |
| 946 |
ascFile.addNote(f.str().c_str()); |
| 947 |
input->seek(pos+84, librevenge::RVNG_SEEK_SET); |
| 948 |
} |
| 949 |
return true; |
| 950 |
} |
| 951 |
|
| 952 |
////////////////////////////////////////////// |
| 953 |
// HF |
| 954 |
////////////////////////////////////////////// |
| 955 |
bool LightWayTxtText::sendHeaderFooter(bool header) |
| 956 |
{ |
| 957 |
MWAWTextListenerPtr listener=m_parserState->m_textListener; |
| 958 |
if (!listener) { |
| 959 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendHeaderFooter: can not find the listener\n")); |
| 960 |
return false; |
| 961 |
} |
| 962 |
LightWayTxtTextInternal::HFZone const &zone = |
| 963 |
header ? m_state->m_header : m_state->m_footer; |
| 964 |
if (!zone.m_pos.valid()) { |
| 965 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendHeaderFooter: can not find the text\n")); |
| 966 |
return false; |
| 967 |
} |
| 968 |
MWAWParagraph para; |
| 969 |
para.m_justify=zone.m_justify; |
| 970 |
listener->setParagraph(para); |
| 971 |
listener->setFont(zone.m_font); |
| 972 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 973 |
input->seek(zone.m_pos.begin(), librevenge::RVNG_SEEK_SET); |
| 974 |
|
| 975 |
auto numChar = static_cast<int>(zone.m_pos.length()); |
| 976 |
std::string str(""); |
| 977 |
for (int c = 0; c < numChar; c++) { |
| 978 |
if (input->isEnd()) { |
| 979 |
MWAW_DEBUG_MSG(("LightWayTxtText::sendHeaderFooter: can not read end of text\n")); |
| 980 |
break; |
| 981 |
} |
| 982 |
str += char(input->readULong(1)); |
| 983 |
} |
| 984 |
auto it = str.begin(); |
| 985 |
while (it!=str.end()) { |
| 986 |
char c=*(it++); |
| 987 |
if (c=='<' && it!= str.end()) { |
| 988 |
char const *strPtr = &(*it); |
| 989 |
bool done = true; |
| 990 |
if (strncmp(strPtr, "PAGE>", 5)==0) |
| 991 |
listener->insertField(MWAWField(MWAWField::PageNumber)); |
| 992 |
else if (strncmp(strPtr, "DATE>", 5)==0) |
| 993 |
listener->insertField(MWAWField(MWAWField::Date)); |
| 994 |
else if (strncmp(strPtr, "TIME>", 5)==0) |
| 995 |
listener->insertField(MWAWField(MWAWField::Time)); |
| 996 |
else if (strncmp(strPtr, "PMAX>", 5)==0) |
| 997 |
listener->insertField(MWAWField(MWAWField::PageCount)); |
| 998 |
else if (strncmp(strPtr, "NAME>", 5)==0) |
| 999 |
listener->insertField(MWAWField(MWAWField::Title)); |
| 1000 |
else |
| 1001 |
done=false; |
| 1002 |
if (done) { |
| 1003 |
it += 5; |
| 1004 |
continue; |
| 1005 |
} |
| 1006 |
} |
| 1007 |
if (c == 0xd) { |
| 1008 |
listener->insertEOL(); |
| 1009 |
continue; |
| 1010 |
} |
| 1011 |
listener->insertCharacter(static_cast<unsigned char>(c)); |
| 1012 |
} |
| 1013 |
return true; |
| 1014 |
} |
| 1015 |
|
| 1016 |
bool LightWayTxtText::readDocumentHF(MWAWEntry const &entry) |
| 1017 |
{ |
| 1018 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 1019 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 1020 |
long pos = input->tell(); |
| 1021 |
|
| 1022 |
libmwaw::DebugStream f, f2; |
| 1023 |
f << "Document(HF):"; |
| 1024 |
if (entry.length()<0x50) { |
| 1025 |
f << "###"; |
| 1026 |
MWAW_DEBUG_MSG(("LightWayTxtText::readDocumentHF: HF seems too short\n")); |
| 1027 |
ascFile.addPos(pos); |
| 1028 |
ascFile.addNote(f.str().c_str()); |
| 1029 |
return false; |
| 1030 |
} |
| 1031 |
|
| 1032 |
for (int s=0; s < 2; s++) { |
| 1033 |
LightWayTxtTextInternal::HFZone zone; |
| 1034 |
zone.m_height = static_cast<int>(input->readLong(2)); |
| 1035 |
zone.m_numChar = static_cast<int>(input->readLong(2)); |
| 1036 |
// ruler align |
| 1037 |
auto flag = static_cast<int>(input->readULong(1)); // [012] |
| 1038 |
f2.str(""); |
| 1039 |
switch (flag) { |
| 1040 |
case 0: |
| 1041 |
break; // left |
| 1042 |
case 1: |
| 1043 |
zone.m_justify = MWAWParagraph::JustificationCenter; |
| 1044 |
break; |
| 1045 |
case 2: |
| 1046 |
zone.m_justify = MWAWParagraph::JustificationRight; |
| 1047 |
break; |
| 1048 |
case 3: |
| 1049 |
zone.m_justify = MWAWParagraph::JustificationFull; |
| 1050 |
break; |
| 1051 |
default: |
| 1052 |
f2 << "#justify=" << flag << ","; |
| 1053 |
} |
| 1054 |
uint32_t flags=0; |
| 1055 |
flag=static_cast<int>(input->readULong(1)); |
| 1056 |
if (flag&0x1) flags |= MWAWFont::boldBit; |
| 1057 |
if (flag&0x2) flags |= MWAWFont::italicBit; |
| 1058 |
if (flag&0x4) zone.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 1059 |
if (flag&0x8) flags |= MWAWFont::embossBit; |
| 1060 |
if (flag&0x10) flags |= MWAWFont::shadowBit; |
| 1061 |
if (flag&0x20) zone.m_font.setDeltaLetterSpacing(-1); |
| 1062 |
if (flag&0x40) zone.m_font.setDeltaLetterSpacing(1); |
| 1063 |
if (flag&0x80) f2 << "#fl80,"; |
| 1064 |
zone.m_font.setFlags(flags); |
| 1065 |
zone.m_font.setId(static_cast<int>(input->readULong(2))); |
| 1066 |
zone.m_font.setSize(float(input->readULong(2))); |
| 1067 |
unsigned char col[3]; |
| 1068 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 1069 |
if (col[0] || col[1] || col[2]) |
| 1070 |
zone.m_font.setColor(MWAWColor(col[0],col[1],col[2])); |
| 1071 |
long val = input->readLong(2); // can be 0x200 |
| 1072 |
if (val) f2 << "f0=" << std::hex << val << std::dec << ","; |
| 1073 |
zone.m_extra = f2.str(); |
| 1074 |
|
| 1075 |
if (s==0) |
| 1076 |
m_state->m_header = zone; |
| 1077 |
else |
| 1078 |
m_state->m_footer = zone; |
| 1079 |
f << (s==0 ? "header" : "footer") << "=[" << zone << "," |
| 1080 |
<< zone.m_font.getDebugString(m_parserState->m_fontConverter) << "],"; |
| 1081 |
|
| 1082 |
val = input->readLong(2); |
| 1083 |
if (val) { |
| 1084 |
if (s==0) f << "fPage=" << val+1 << ","; |
| 1085 |
else |
| 1086 |
f << "#f1=" << std::hex << val << std::dec << ","; |
| 1087 |
} |
| 1088 |
} |
| 1089 |
long debText = input->tell(); |
| 1090 |
auto numRemains=int(entry.end()-debText); |
| 1091 |
bool ok = numRemains == m_state->m_header.m_numChar+m_state->m_footer.m_numChar; |
| 1092 |
if (ok) { |
| 1093 |
if (m_state->m_header.m_numChar) { |
| 1094 |
m_state->m_header.m_pos.setBegin(debText); |
| 1095 |
m_state->m_header.m_pos.setLength(m_state->m_header.m_numChar); |
| 1096 |
debText+=m_state->m_header.m_numChar; |
| 1097 |
} |
| 1098 |
if (m_state->m_footer.m_numChar) { |
| 1099 |
m_state->m_footer.m_pos.setBegin(debText); |
| 1100 |
m_state->m_footer.m_pos.setLength(m_state->m_footer.m_numChar); |
| 1101 |
} |
| 1102 |
} |
| 1103 |
else { |
| 1104 |
MWAW_DEBUG_MSG(("LightWayTxtText::readDocumentHF: HF can not determine header/footer text\n")); |
| 1105 |
f << "###"; |
| 1106 |
} |
| 1107 |
std::string name(""); // something like <NAME>(<PAGE>) |
| 1108 |
for (int i = 0; i < numRemains; i++) |
| 1109 |
name += char(input->readULong(1)); |
| 1110 |
f << name << ","; |
| 1111 |
ascFile.addPos(pos); |
| 1112 |
ascFile.addNote(f.str().c_str()); |
| 1113 |
return true; |
| 1114 |
} |
| 1115 |
|
| 1116 |
////////////////////////////////////////////// |
| 1117 |
// Unknown |
| 1118 |
////////////////////////////////////////////// |
| 1119 |
bool LightWayTxtText::readStyleU(MWAWEntry const &entry) |
| 1120 |
{ |
| 1121 |
if (!entry.valid() || (entry.length()%8) != 4) { |
| 1122 |
MWAW_DEBUG_MSG(("LightWayTxtText::readStyleU: the entry seems bad\n")); |
| 1123 |
return false; |
| 1124 |
} |
| 1125 |
|
| 1126 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 1127 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 1128 |
long pos = entry.begin(); |
| 1129 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1130 |
|
| 1131 |
libmwaw::DebugStream f; |
| 1132 |
f << "Entries(StyleU)[" << entry.id() << "]:"; |
| 1133 |
entry.setParsed(true); |
| 1134 |
auto N=static_cast<int>(input->readULong(4)); |
| 1135 |
f << "N=" << N << ","; |
| 1136 |
if (entry.length() != N*8+4) { |
| 1137 |
f << "###"; |
| 1138 |
MWAW_DEBUG_MSG(("LightWayTxtText::readStyleU: N seems bad\n")); |
| 1139 |
ascFile.addPos(pos-4); |
| 1140 |
ascFile.addNote(f.str().c_str()); |
| 1141 |
|
| 1142 |
return false; |
| 1143 |
} |
| 1144 |
|
| 1145 |
ascFile.addPos(pos-4); |
| 1146 |
ascFile.addNote(f.str().c_str()); |
| 1147 |
LightWayTxtTextInternal::PLC plc; |
| 1148 |
plc.m_type = LightWayTxtTextInternal::P_StyleU; |
| 1149 |
for (int i = 0; i < N; i++) { |
| 1150 |
pos = input->tell(); |
| 1151 |
f.str(""); |
| 1152 |
long cPos = input->readLong(4); |
| 1153 |
auto flag = long(input->readULong(2)); // 2022 |
| 1154 |
if (flag) |
| 1155 |
f << "flag=" << std::hex << flag << std::dec << ","; |
| 1156 |
long val = input->readLong(2); // always 0 |
| 1157 |
if (val) f << "f0=" << val << ","; |
| 1158 |
plc.m_id = i; |
| 1159 |
plc.m_extra = f.str(); |
| 1160 |
m_state->m_plcMap.insert(std::map<long, LightWayTxtTextInternal::PLC>::value_type(cPos, plc)); |
| 1161 |
|
| 1162 |
f.str(""); |
| 1163 |
f << "StyleU-" << i << ":cPos=" << std::hex << cPos << std::dec << "," << plc; |
| 1164 |
ascFile.addPos(pos); |
| 1165 |
ascFile.addNote(f.str().c_str()); |
| 1166 |
input->seek(pos+8, librevenge::RVNG_SEEK_SET); |
| 1167 |
} |
| 1168 |
return true; |
| 1169 |
} |
| 1170 |
|
| 1171 |
bool LightWayTxtText::readRuby(MWAWEntry const &entry) |
| 1172 |
{ |
| 1173 |
if (!entry.valid() || (entry.length()%6) != 4) { |
| 1174 |
MWAW_DEBUG_MSG(("LightWayTxtText::readRuby: the entry seems bad\n")); |
| 1175 |
return false; |
| 1176 |
} |
| 1177 |
|
| 1178 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 1179 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 1180 |
long pos = entry.begin(); |
| 1181 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1182 |
|
| 1183 |
libmwaw::DebugStream f; |
| 1184 |
f << "Entries(Ruby)[" << entry.id() << "]:"; |
| 1185 |
entry.setParsed(true); |
| 1186 |
auto N=static_cast<int>(input->readULong(4)); |
| 1187 |
f << "N=" << N << ","; |
| 1188 |
if (entry.length() != N*6+4) { |
| 1189 |
f << "###"; |
| 1190 |
MWAW_DEBUG_MSG(("LightWayTxtText::readRuby: N seems bad\n")); |
| 1191 |
ascFile.addPos(pos-4); |
| 1192 |
ascFile.addNote(f.str().c_str()); |
| 1193 |
|
| 1194 |
return false; |
| 1195 |
} |
| 1196 |
|
| 1197 |
ascFile.addPos(pos-4); |
| 1198 |
ascFile.addNote(f.str().c_str()); |
| 1199 |
LightWayTxtTextInternal::PLC plc; |
| 1200 |
plc.m_type = LightWayTxtTextInternal::P_Ruby; |
| 1201 |
for (int i = 0; i < N; i++) { |
| 1202 |
pos = input->tell(); |
| 1203 |
f.str(""); |
| 1204 |
long cPos = input->readLong(4); |
| 1205 |
f << "n[text]=" << static_cast<int>(input->readULong(1)) << ","; |
| 1206 |
f << "n[ruby]=" << static_cast<int>(input->readULong(1)) << ","; |
| 1207 |
plc.m_id = i; |
| 1208 |
plc.m_extra = f.str(); |
| 1209 |
m_state->m_plcMap.insert(std::map<long, LightWayTxtTextInternal::PLC>::value_type(cPos, plc)); |
| 1210 |
|
| 1211 |
f.str(""); |
| 1212 |
f << "Ruby-" << i << ":cPos=" << std::hex << cPos << std::dec << "," << plc; |
| 1213 |
ascFile.addPos(pos); |
| 1214 |
ascFile.addNote(f.str().c_str()); |
| 1215 |
input->seek(pos+6, librevenge::RVNG_SEEK_SET); |
| 1216 |
} |
| 1217 |
return true; |
| 1218 |
} |
| 1219 |
|
| 1220 |
bool LightWayTxtText::readUnknownStyle(MWAWEntry const &entry) |
| 1221 |
{ |
| 1222 |
if (!entry.valid() || entry.length() < 4) { |
| 1223 |
MWAW_DEBUG_MSG(("LightWayTxtText::readUnknownStyle: the entry is bad\n")); |
| 1224 |
return false; |
| 1225 |
} |
| 1226 |
MWAWInputStreamPtr input = m_mainParser->rsrcInput(); |
| 1227 |
libmwaw::DebugFile &ascFile = m_mainParser->rsrcAscii(); |
| 1228 |
long pos = entry.begin(); |
| 1229 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1230 |
|
| 1231 |
libmwaw::DebugStream f; |
| 1232 |
f << "Entries(" << entry.type() << ")[" << entry.id() << "]:"; |
| 1233 |
entry.setParsed(true); |
| 1234 |
int numSz=2; |
| 1235 |
auto N=static_cast<int>(input->readULong(2)); |
| 1236 |
if (!N) { |
| 1237 |
N=static_cast<int>(input->readULong(2)); |
| 1238 |
numSz+=2; |
| 1239 |
} |
| 1240 |
f << "N=" << N << ","; |
| 1241 |
int fSz = N ? int((entry.length()-numSz)/N) : 0; |
| 1242 |
if (long(N*fSz+numSz) != entry.length()) { |
| 1243 |
MWAW_DEBUG_MSG(("LightWayTxtText::readUnknownStyle: the number of entry seems bad\n")); |
| 1244 |
f << "###"; |
| 1245 |
ascFile.addPos(pos-4); |
| 1246 |
ascFile.addNote(f.str().c_str()); |
| 1247 |
return false; |
| 1248 |
} |
| 1249 |
ascFile.addPos(pos-4); |
| 1250 |
ascFile.addNote(f.str().c_str()); |
| 1251 |
|
| 1252 |
for (int i = 0; i < N; i++) { |
| 1253 |
pos = input->tell(); |
| 1254 |
f.str(""); |
| 1255 |
f << entry.type() << "-" << i << ":"; |
| 1256 |
ascFile.addPos(pos); |
| 1257 |
ascFile.addNote(f.str().c_str()); |
| 1258 |
|
| 1259 |
input->seek(pos+fSz, librevenge::RVNG_SEEK_SET); |
| 1260 |
} |
| 1261 |
return true; |
| 1262 |
} |
| 1263 |
|
| 1264 |
//////////////////////////////////////////////////////////// |
| 1265 |
// |
| 1266 |
// Low level |
| 1267 |
// |
| 1268 |
//////////////////////////////////////////////////////////// |
| 1269 |
|
| 1270 |
void LightWayTxtText::flushExtra() |
| 1271 |
{ |
| 1272 |
} |
| 1273 |
|
| 1274 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |