| 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 |
#ifdef DEBUG |
| 35 |
// set to 1 to debug the font property |
| 36 |
# define DEBUG_FP 1 |
| 37 |
// set to 1 to debug the paragraph property |
| 38 |
# define DEBUG_PP 1 |
| 39 |
// set to 1 to print the plc position |
| 40 |
# define DEBUG_PLC_POS 1 |
| 41 |
#else |
| 42 |
# define DEBUG_FP 0 |
| 43 |
# define DEBUG_PP 0 |
| 44 |
# define DEBUG_PLC_POS 0 |
| 45 |
#endif |
| 46 |
|
| 47 |
#include <iomanip> |
| 48 |
#include <iostream> |
| 49 |
|
| 50 |
#include <map> |
| 51 |
#include <vector> |
| 52 |
|
| 53 |
#include <librevenge/librevenge.h> |
| 54 |
|
| 55 |
#include "libmwaw_internal.hxx" |
| 56 |
|
| 57 |
#include "MWAWListener.hxx" |
| 58 |
#include "MWAWFont.hxx" |
| 59 |
#include "MWAWFontConverter.hxx" |
| 60 |
#include "MWAWParagraph.hxx" |
| 61 |
|
| 62 |
#include "MsWks4Zone.hxx" |
| 63 |
#include "MsWksDocument.hxx" |
| 64 |
|
| 65 |
#include "MsWks4Text.hxx" |
| 66 |
|
| 67 |
////////////////////////////////////////////////////////////////////////////// |
| 68 |
// general enum |
| 69 |
////////////////////////////////////////////////////////////////////////////// |
| 70 |
namespace MsWks4TextInternal |
| 71 |
{ |
| 72 |
/** different types |
| 73 |
* |
| 74 |
* - BTE: font/paragraph properties |
| 75 |
* - PGD: page break |
| 76 |
* - FTNT: footnote |
| 77 |
* - TOKEN: field type |
| 78 |
*/ |
| 79 |
enum PLCType { BTE=0, PGD, FTNT, TOKEN, EOBJ, Unknown}; |
| 80 |
} |
| 81 |
|
| 82 |
//////////////////////////////////////////////////////////// |
| 83 |
// Low level struct to read the plc |
| 84 |
//////////////////////////////////////////////////////////// |
| 85 |
/** Internal and low level: the structures of a MsWks4Text used to parse PLC*/ |
| 86 |
namespace MsWks4PLCInternal |
| 87 |
{ |
| 88 |
/** Internal and low level: the PLC different types and their structures */ |
| 89 |
struct PLC { |
| 90 |
/** the PLC types */ |
| 91 |
typedef enum MsWks4TextInternal::PLCType PLCType; |
| 92 |
/** the way to define the text positions |
| 93 |
* |
| 94 |
* - P_ABS: absolute position, |
| 95 |
* - P_REL: position are relative to the beginning text offset, |
| 96 |
* - P_INCR: position are the length of text consecutive zones */ |
| 97 |
typedef enum { P_ABS=0, P_REL, P_INCR, P_UNKNOWN} Position; |
| 98 |
/** the type of the content |
| 99 |
* |
| 100 |
* - T_CST: size is constant |
| 101 |
* - T_STRUCT: a structured type ( which unknown size) */ |
| 102 |
typedef enum { T_CST=0, T_STRUCT, T_UNKNOWN} Type; |
| 103 |
//! constructor |
| 104 |
explicit PLC(PLCType w= MsWks4TextInternal::Unknown, Position p=P_UNKNOWN, Type t=T_UNKNOWN) |
| 105 |
: m_type(w) |
| 106 |
, m_pos(p) |
| 107 |
, m_contentType(t) |
| 108 |
{ |
| 109 |
} |
| 110 |
//! PLC type |
| 111 |
PLCType m_type; |
| 112 |
//! the way to define the text positions |
| 113 |
Position m_pos; |
| 114 |
//! the type of the content |
| 115 |
Type m_contentType; |
| 116 |
}; |
| 117 |
|
| 118 |
//! a map of known plc |
| 119 |
struct KnownPLC { |
| 120 |
public: |
| 121 |
//! creates the mapping |
| 122 |
KnownPLC() |
| 123 |
: m_knowns() |
| 124 |
{ |
| 125 |
createMapping(); |
| 126 |
} |
| 127 |
|
| 128 |
//! returns the PLC corresponding to a name |
| 129 |
PLC get(std::string const &name) |
| 130 |
{ |
| 131 |
auto pos = m_knowns.find(name); |
| 132 |
if (pos == m_knowns.end()) return PLC(); |
| 133 |
return pos->second; |
| 134 |
} |
| 135 |
|
| 136 |
protected: |
| 137 |
//! creates the map of known PLC |
| 138 |
void createMapping() |
| 139 |
{ |
| 140 |
m_knowns["BTEP"] = |
| 141 |
PLC(MsWks4TextInternal::BTE,PLC::P_ABS, PLC::T_CST); |
| 142 |
m_knowns["BTEC"] = |
| 143 |
PLC(MsWks4TextInternal::BTE,PLC::P_ABS, PLC::T_CST); |
| 144 |
m_knowns["FTNT"] = |
| 145 |
PLC(MsWks4TextInternal::FTNT,PLC::P_REL, PLC::T_STRUCT); |
| 146 |
m_knowns["PGD "] = |
| 147 |
PLC(MsWks4TextInternal::PGD,PLC::P_REL, PLC::T_STRUCT); |
| 148 |
m_knowns["TOKN"] = |
| 149 |
PLC(MsWks4TextInternal::TOKEN,PLC::P_REL,PLC:: T_STRUCT); |
| 150 |
m_knowns["EOBJ"] = |
| 151 |
PLC(MsWks4TextInternal::EOBJ,PLC::P_REL, PLC::T_STRUCT); |
| 152 |
} |
| 153 |
|
| 154 |
//! map name -> known PLC |
| 155 |
std::map<std::string, PLC> m_knowns; |
| 156 |
}; |
| 157 |
} |
| 158 |
|
| 159 |
//////////////////////////////////////////////////////////// |
| 160 |
// Internal structures to store/parse the Zone |
| 161 |
//////////////////////////////////////////////////////////// |
| 162 |
|
| 163 |
/** Internal: the structures of a MsWks4Text */ |
| 164 |
namespace MsWks4TextInternal |
| 165 |
{ |
| 166 |
/** Internal: class to store a font name: name with sysid */ |
| 167 |
class FontName |
| 168 |
{ |
| 169 |
public: |
| 170 |
//! constructor |
| 171 |
FontName() |
| 172 |
: m_name("") |
| 173 |
, m_id(-1) |
| 174 |
, m_unknown(0) |
| 175 |
{ |
| 176 |
} |
| 177 |
|
| 178 |
//! operator<< |
| 179 |
friend std::ostream &operator<<(std::ostream &o, FontName const &ft); |
| 180 |
|
| 181 |
//! the font name |
| 182 |
std::string m_name; |
| 183 |
//! the font id |
| 184 |
int m_id; |
| 185 |
//! unknown |
| 186 |
int m_unknown; |
| 187 |
}; |
| 188 |
|
| 189 |
std::ostream &operator<<(std::ostream &o, FontName const &ft) |
| 190 |
{ |
| 191 |
o << "Font(name=" << ft.m_name << ", id=" << ft.m_id; |
| 192 |
if (ft.m_unknown != 0) o << ", unk=" << ft.m_unknown; |
| 193 |
o << ")"; |
| 194 |
return o; |
| 195 |
} |
| 196 |
|
| 197 |
/** Internal: class to store a font properties */ |
| 198 |
struct Font { |
| 199 |
//! the field type: pagenumber, note, DTT=date/time/type |
| 200 |
enum FieldType { None, Page, Eobj, Note, DTT, DTTUnk}; |
| 201 |
//! constructor: default value Geneva:12 |
| 202 |
explicit Font(int fId=3, int size=12) |
| 203 |
: m_font(fId,float(size)) |
| 204 |
, m_fieldType(None) |
| 205 |
, m_error("") |
| 206 |
{ |
| 207 |
} |
| 208 |
//! copy constructor |
| 209 |
explicit Font(MWAWFont const &ft) |
| 210 |
: m_font(ft) |
| 211 |
, m_fieldType(None) |
| 212 |
, m_error("") |
| 213 |
{ |
| 214 |
} |
| 215 |
//! operator << |
| 216 |
friend std::ostream &operator<<(std::ostream &o, Font const &ft); |
| 217 |
//! the font |
| 218 |
MWAWFont m_font; |
| 219 |
//! the field type |
| 220 |
FieldType m_fieldType; |
| 221 |
|
| 222 |
//! a string used to store the parsing errors |
| 223 |
std::string m_error; |
| 224 |
}; |
| 225 |
//! operator<< for a font |
| 226 |
std::ostream &operator<<(std::ostream &o, Font const &ft) |
| 227 |
{ |
| 228 |
o << std::dec; |
| 229 |
switch (ft.m_fieldType) { |
| 230 |
case Font::Page: |
| 231 |
o << ", field[Page]"; |
| 232 |
break; |
| 233 |
case Font::Eobj: |
| 234 |
o << ", field[Eobj]"; |
| 235 |
break; |
| 236 |
case Font::Note: |
| 237 |
o << ", field[Note]"; |
| 238 |
break; |
| 239 |
case Font::DTT: |
| 240 |
case Font::DTTUnk: |
| 241 |
o << ", field[with content]"; |
| 242 |
break; |
| 243 |
case Font::None: |
| 244 |
#if !defined(__clang__) |
| 245 |
default: |
| 246 |
#endif |
| 247 |
break; |
| 248 |
} |
| 249 |
if (!ft.m_error.empty()) o << ", errors=(" << ft.m_error << ")"; |
| 250 |
return o; |
| 251 |
} |
| 252 |
|
| 253 |
/** Internal: class to store a paragraph properties */ |
| 254 |
struct Paragraph final : public MWAWParagraph { |
| 255 |
//! constructor |
| 256 |
Paragraph() |
| 257 |
: MWAWParagraph() |
| 258 |
, m_pageBreak(false) |
| 259 |
{ |
| 260 |
} |
| 261 |
Paragraph(Paragraph const &)=default; |
| 262 |
Paragraph &operator=(Paragraph const &)=default; |
| 263 |
//! destructor |
| 264 |
~Paragraph() final; |
| 265 |
//! operator << |
| 266 |
friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind); |
| 267 |
|
| 268 |
//! flag to know if there is a pagebreak before the paragraph |
| 269 |
bool m_pageBreak; |
| 270 |
}; |
| 271 |
//! operator<< |
| 272 |
std::ostream &operator<<(std::ostream &o, Paragraph const &ind) |
| 273 |
{ |
| 274 |
o << static_cast<MWAWParagraph const &>(ind); |
| 275 |
if (ind.m_pageBreak) o << "pgBrk, "; |
| 276 |
return o; |
| 277 |
} |
| 278 |
|
| 279 |
Paragraph::~Paragraph() |
| 280 |
{ |
| 281 |
} |
| 282 |
|
| 283 |
/** Internal: class to store footnote definition */ |
| 284 |
struct Ftnt { |
| 285 |
//! constructor |
| 286 |
Ftnt() |
| 287 |
: m_type(-1) |
| 288 |
, m_id(-1) |
| 289 |
, m_begin(-1) |
| 290 |
, m_end(-1) |
| 291 |
, m_error("") |
| 292 |
{ |
| 293 |
} |
| 294 |
//! operator<< |
| 295 |
friend std::ostream &operator<<(std::ostream &o, Ftnt const &ftnt); |
| 296 |
/** the note type |
| 297 |
* |
| 298 |
* Checkme: can we find other values than 1 ?*/ |
| 299 |
int m_type; |
| 300 |
//! the footnote number |
| 301 |
int m_id; |
| 302 |
long m_begin /**the first offset in the text*/, m_end/**the last offset in the text*/; |
| 303 |
//! a string used to store the parsing errors |
| 304 |
std::string m_error; |
| 305 |
}; |
| 306 |
//!operator<< for footnote |
| 307 |
std::ostream &operator<<(std::ostream &o, Ftnt const &ftnt) |
| 308 |
{ |
| 309 |
o << std::dec; |
| 310 |
switch (ftnt.m_type) { |
| 311 |
case 1: |
| 312 |
o << "footnote,"; |
| 313 |
break; |
| 314 |
default: |
| 315 |
o << "###type=" << ftnt.m_type << ","; |
| 316 |
} |
| 317 |
if (ftnt.m_id != -1) o << "id=" << ftnt.m_id; |
| 318 |
if (ftnt.m_begin > 0) |
| 319 |
o << std::hex << ",pos=" << ftnt.m_begin |
| 320 |
<< "(" << ftnt.m_end-ftnt.m_begin <<")" << std::dec; |
| 321 |
if (!ftnt.m_error.empty()) o << ",error=(" << ftnt.m_error << ")"; |
| 322 |
return o; |
| 323 |
} |
| 324 |
|
| 325 |
/** Internal: class to store field definition: TOKN entry*/ |
| 326 |
struct Token { |
| 327 |
//! constructor |
| 328 |
Token() |
| 329 |
: m_type(MWAWField::None) |
| 330 |
, m_textLength(-1) |
| 331 |
, m_unknown(-1) |
| 332 |
, m_error("") |
| 333 |
{ |
| 334 |
} |
| 335 |
//! operator << |
| 336 |
friend std::ostream &operator<<(std::ostream &o, Token const &tok); |
| 337 |
//! the type |
| 338 |
MWAWField::Type m_type; |
| 339 |
//! the length of the text corresponding to the token |
| 340 |
int m_textLength; |
| 341 |
//! unknown field |
| 342 |
int m_unknown; |
| 343 |
//! a string used to store the parsing errors |
| 344 |
std::string m_error; |
| 345 |
}; |
| 346 |
//! operator<< for Token |
| 347 |
std::ostream &operator<<(std::ostream &o, Token const &tok) |
| 348 |
{ |
| 349 |
o << std::dec; |
| 350 |
switch (tok.m_type) { |
| 351 |
case MWAWField::PageCount: |
| 352 |
o << "field[pageCount],"; |
| 353 |
break; |
| 354 |
case MWAWField::PageNumber: |
| 355 |
o << "field[page],"; |
| 356 |
break; |
| 357 |
case MWAWField::Date: |
| 358 |
o << "field[date],"; |
| 359 |
break; |
| 360 |
case MWAWField::Time: |
| 361 |
o << "field[time],"; |
| 362 |
break; |
| 363 |
case MWAWField::Title: |
| 364 |
o << "field[title],"; |
| 365 |
break; |
| 366 |
case MWAWField::Database: |
| 367 |
o << "field[database],"; |
| 368 |
break; |
| 369 |
case MWAWField::BookmarkStart: |
| 370 |
case MWAWField::BookmarkEnd: |
| 371 |
case MWAWField::None: |
| 372 |
#if !defined(__clang__) |
| 373 |
default: |
| 374 |
#endif |
| 375 |
o << "##field[unknown]" << ","; |
| 376 |
break; |
| 377 |
} |
| 378 |
if (tok.m_textLength != -1) o << "textLen=" << tok.m_textLength << ","; |
| 379 |
if (tok.m_unknown != -1) o << "unkn=" << std::hex << tok.m_unknown << std::dec << ","; |
| 380 |
if (!tok.m_error.empty()) o << "err=[" << tok.m_error << "]"; |
| 381 |
return o; |
| 382 |
} |
| 383 |
|
| 384 |
/** Internal: class to store field definition: TOKN entry*/ |
| 385 |
struct Object { |
| 386 |
//! constructor |
| 387 |
Object() |
| 388 |
: m_type(-1) |
| 389 |
, m_id(-1) |
| 390 |
, m_dim() |
| 391 |
, m_fileId(-1) |
| 392 |
, m_error("") |
| 393 |
{ |
| 394 |
} |
| 395 |
//! operator << |
| 396 |
friend std::ostream &operator<<(std::ostream &o, Object const &tok); |
| 397 |
//! the object type |
| 398 |
int m_type; |
| 399 |
//! the local id |
| 400 |
int m_id; |
| 401 |
//! the dimension |
| 402 |
MWAWVec2i m_dim; |
| 403 |
//! the file id |
| 404 |
long m_fileId; |
| 405 |
//! a string used to store the parsing errors |
| 406 |
std::string m_error; |
| 407 |
}; |
| 408 |
//! operator<< for Object |
| 409 |
std::ostream &operator<<(std::ostream &o, Object const &obj) |
| 410 |
{ |
| 411 |
if (obj.m_type != 1) o << "###type=" << obj.m_type << ","; |
| 412 |
if (obj.m_id >= 0) o << "id=" << obj.m_id << ","; |
| 413 |
o << "dim=" << obj.m_dim << ","; |
| 414 |
if (obj.m_fileId > 0) o << "X" << std::hex << obj.m_fileId << std::dec << ","; |
| 415 |
if (!obj.m_error.empty()) o << "err=[" << obj.m_error << "]"; |
| 416 |
return o; |
| 417 |
} |
| 418 |
|
| 419 |
/** Internal: class to store the PLC: Pointer List Content ? */ |
| 420 |
struct DataPLC { |
| 421 |
//! constructor |
| 422 |
DataPLC() |
| 423 |
: m_name("") |
| 424 |
, m_type(Unknown) |
| 425 |
, m_value(-1) |
| 426 |
, m_error("") |
| 427 |
{ |
| 428 |
} |
| 429 |
//! operator<< |
| 430 |
friend std::ostream &operator<<(std::ostream &o, DataPLC const &plc); |
| 431 |
//! the entry name |
| 432 |
std::string m_name; |
| 433 |
//! the type |
| 434 |
PLCType m_type; |
| 435 |
//! a potential value |
| 436 |
long m_value; |
| 437 |
//! a string used to store the parsing errors |
| 438 |
std::string m_error; |
| 439 |
}; |
| 440 |
//! operator<< for DataPLC |
| 441 |
std::ostream &operator<<(std::ostream &o, DataPLC const &plc) |
| 442 |
{ |
| 443 |
o << "type=" << plc.m_name << ","; |
| 444 |
if (plc.m_value != -1) o << "val=" << std::hex << plc.m_value << std::dec << ", "; |
| 445 |
if (!plc.m_error.empty()) o << "errors=(" << plc.m_error << ")"; |
| 446 |
return o; |
| 447 |
} |
| 448 |
|
| 449 |
/** Internal: the state of a MsWks4Text |
| 450 |
* |
| 451 |
* \note in order to diffenciate a note definition with |
| 452 |
* its main text position, we define a flag to indicate that we parse the MN0 |
| 453 |
* ole or the Footnote ole ( see parseMain, setParse) |
| 454 |
*/ |
| 455 |
struct State { |
| 456 |
//! constructor |
| 457 |
State() |
| 458 |
: m_paragraph() |
| 459 |
, m_defFont(3,12) |
| 460 |
, m_fontNames() |
| 461 |
, m_fontList() |
| 462 |
, m_paragraphList() |
| 463 |
, m_pgdList() |
| 464 |
, m_ftntList() |
| 465 |
, m_ftntMap() |
| 466 |
, m_eobjMap() |
| 467 |
, m_plcList() |
| 468 |
, m_knownPLC() |
| 469 |
, m_main(false) |
| 470 |
{ |
| 471 |
} |
| 472 |
|
| 473 |
//! returns true if we parse the main block |
| 474 |
bool parseMain() const |
| 475 |
{ |
| 476 |
return m_main; |
| 477 |
} |
| 478 |
//! sets \a main to true if we parse the main block |
| 479 |
void setParse(bool main) |
| 480 |
{ |
| 481 |
m_main = main; |
| 482 |
} |
| 483 |
|
| 484 |
//! the actual paragraph |
| 485 |
Paragraph m_paragraph; |
| 486 |
|
| 487 |
//! the default font |
| 488 |
MWAWFont m_defFont; |
| 489 |
|
| 490 |
//! the list of fonts names |
| 491 |
std::vector<FontName> m_fontNames; |
| 492 |
|
| 493 |
//! a list of all font properties |
| 494 |
std::vector<Font> m_fontList; |
| 495 |
//! a list of all paragraph properties |
| 496 |
std::vector<Paragraph> m_paragraphList; |
| 497 |
//! a list of all page breaks |
| 498 |
std::vector<long> m_pgdList; |
| 499 |
|
| 500 |
//! list of footnotes |
| 501 |
std::vector<Ftnt> m_ftntList; |
| 502 |
//! mapping text offset to footnote |
| 503 |
std::map<long, Ftnt> m_ftntMap; |
| 504 |
|
| 505 |
//! mapping text offset to object |
| 506 |
std::map<long, Object> m_eobjMap; |
| 507 |
|
| 508 |
//! list of all PLCs |
| 509 |
std::vector<DataPLC> m_plcList; |
| 510 |
|
| 511 |
//! the known plc |
| 512 |
MsWks4PLCInternal::KnownPLC m_knownPLC; |
| 513 |
protected: |
| 514 |
//! true if we parse the main block |
| 515 |
bool m_main; |
| 516 |
}; |
| 517 |
|
| 518 |
} |
| 519 |
|
| 520 |
////////////////////////////////////////////////////////////////////////////// |
| 521 |
// |
| 522 |
// MAIN CODE |
| 523 |
// |
| 524 |
////////////////////////////////////////////////////////////////////////////// |
| 525 |
|
| 526 |
//////////////////////////////////////////////////////////// |
| 527 |
// constructor/destructor |
| 528 |
//////////////////////////////////////////////////////////// |
| 529 |
MsWks4Text::MsWks4Text(MsWksDocument &document) |
| 530 |
: m_mainParser(&document.getMainParser()) |
| 531 |
, m_parserState() |
| 532 |
, m_document(document) |
| 533 |
, m_textPositions() |
| 534 |
, m_state() |
| 535 |
, m_FODsList() |
| 536 |
, m_FDPCs() |
| 537 |
, m_FDPPs() |
| 538 |
{ |
| 539 |
m_parserState=m_mainParser->getParserState(); |
| 540 |
m_state.reset(new MsWks4TextInternal::State); |
| 541 |
} |
| 542 |
|
| 543 |
MsWks4Text::~MsWks4Text() |
| 544 |
{ |
| 545 |
} |
| 546 |
|
| 547 |
//////////////////////////////////////////////////////////// |
| 548 |
// number of page |
| 549 |
//////////////////////////////////////////////////////////// |
| 550 |
int MsWks4Text::numPages() const |
| 551 |
{ |
| 552 |
int res = 1; |
| 553 |
for (auto const &fod : m_FODsList) { |
| 554 |
if (fod.m_type != DataFOD::ATTR_PARAG) continue; |
| 555 |
|
| 556 |
int id = fod.m_id; |
| 557 |
if (id < 0) continue; |
| 558 |
if (m_state->m_paragraphList[size_t(id)].m_pageBreak) res++; |
| 559 |
} |
| 560 |
|
| 561 |
if (res < int(m_state->m_pgdList.size())-1) |
| 562 |
res = int(m_state->m_pgdList.size())-1; |
| 563 |
|
| 564 |
return res; |
| 565 |
} |
| 566 |
|
| 567 |
//////////////////////////////////////////////////////////// |
| 568 |
// |
| 569 |
// find all the text structures |
| 570 |
// |
| 571 |
//////////////////////////////////////////////////////////// |
| 572 |
bool MsWks4Text::readStructures(MWAWInputStreamPtr input, bool mainOle) |
| 573 |
{ |
| 574 |
m_state->setParse(mainOle); |
| 575 |
// reset data |
| 576 |
m_textPositions = MWAWEntry(); |
| 577 |
m_FODsList.resize(0); |
| 578 |
|
| 579 |
m_state->m_fontNames.resize(0); |
| 580 |
m_state->m_fontList.resize(0); |
| 581 |
m_state->m_paragraphList.resize(0); |
| 582 |
m_state->m_plcList.resize(0); |
| 583 |
m_state->m_ftntList.resize(0); |
| 584 |
m_state->m_ftntMap.clear(); |
| 585 |
m_state->m_pgdList.resize(0); |
| 586 |
|
| 587 |
auto const &entryMap = m_document.getEntryMap(); |
| 588 |
|
| 589 |
/* the text limit */ |
| 590 |
auto pos = entryMap.find("TEXT"); |
| 591 |
if (entryMap.end() == pos) { |
| 592 |
MWAW_DEBUG_MSG(("MsWks4Text::readStructures: error: no TEXT in header index table\n")); |
| 593 |
throw libmwaw::ParseException(); |
| 594 |
} |
| 595 |
m_textPositions = pos->second; |
| 596 |
|
| 597 |
/* read fonts table */ |
| 598 |
pos = entryMap.lower_bound("FONT"); |
| 599 |
if (entryMap.end() == pos) { |
| 600 |
MWAW_DEBUG_MSG(("MsWks4Text::readStructures: error: no FONT in header index table\n")); |
| 601 |
throw libmwaw::ParseException(); |
| 602 |
} |
| 603 |
readFontNames(input, pos->second); |
| 604 |
|
| 605 |
// |
| 606 |
// find the FDDP and FDPC positions |
| 607 |
// |
| 608 |
for (int st = 0; st < 2; st++) { |
| 609 |
if (!findFDPStructures(input, st)) |
| 610 |
findFDPStructuresByHand(input, st); |
| 611 |
} |
| 612 |
|
| 613 |
/* read character FODs (FOrmatting Descriptors) */ |
| 614 |
std::vector<DataFOD> fdps; |
| 615 |
|
| 616 |
for (auto fdp : m_FDPCs) |
| 617 |
readFDP(input, *fdp, fdps, FDPParser(&MsWks4Text::readFont)); |
| 618 |
m_FODsList = mergeSortedLists(fdps, m_FODsList); |
| 619 |
|
| 620 |
fdps.resize(0); |
| 621 |
for (auto fdp : m_FDPPs) |
| 622 |
readFDP(input, *fdp, fdps, FDPParser(&MsWks4Text::readParagraph)); |
| 623 |
m_FODsList = mergeSortedLists(fdps, m_FODsList); |
| 624 |
|
| 625 |
// |
| 626 |
// read the plc data |
| 627 |
// |
| 628 |
pos = entryMap.lower_bound("FTNT"); |
| 629 |
while (pos != entryMap.end()) { |
| 630 |
MWAWEntry const &entry = pos++->second; |
| 631 |
if (!entry.hasName("FTNT")) break; |
| 632 |
if (!entry.hasType("PLC ")) continue; |
| 633 |
|
| 634 |
std::vector<long> textPtrs, listValues; |
| 635 |
readPLC(input, entry, textPtrs, listValues, &MsWks4Text::ftntDataParser); |
| 636 |
} |
| 637 |
pos = entryMap.lower_bound("TOKN"); |
| 638 |
while (pos != entryMap.end()) { |
| 639 |
MWAWEntry const &entry = pos++->second; |
| 640 |
if (!entry.hasName("TOKN")) break; |
| 641 |
if (!entry.hasType("PLC ")) continue; |
| 642 |
|
| 643 |
std::vector<long> textPtrs, listValues; |
| 644 |
readPLC(input, entry, textPtrs, listValues, &MsWks4Text::toknDataParser); |
| 645 |
} |
| 646 |
/** |
| 647 |
eobj and RBIL seems linked ( and associate with a 0xc6 symbol in file) |
| 648 |
RBIL: can store a chart, a calendar, ... |
| 649 |
*/ |
| 650 |
pos = entryMap.lower_bound("EOBJ"); |
| 651 |
while (pos != entryMap.end()) { |
| 652 |
MWAWEntry const &entry = pos++->second; |
| 653 |
if (!entry.hasName("EOBJ")) break; |
| 654 |
if (!entry.hasType("PLC ")) continue; |
| 655 |
|
| 656 |
std::vector<long> textPtrs, listValues; |
| 657 |
readPLC(input, entry, textPtrs, listValues, &MsWks4Text::eobjDataParser); |
| 658 |
} |
| 659 |
pos = entryMap.lower_bound("PGD "); |
| 660 |
while (pos != entryMap.end()) { |
| 661 |
MWAWEntry const &entry = pos++->second; |
| 662 |
if (!entry.hasName("PGD ")) break; |
| 663 |
if (!entry.hasType("PLC ")) continue; |
| 664 |
|
| 665 |
std::vector<long> listValues; |
| 666 |
readPLC(input, entry, m_state->m_pgdList, listValues, &MsWks4Text::pgdDataParser); |
| 667 |
} |
| 668 |
|
| 669 |
return true; |
| 670 |
} |
| 671 |
|
| 672 |
//////////////////////////////////////////////////////////// |
| 673 |
// |
| 674 |
// Read the text of a foot note. |
| 675 |
// FIXME: keep a trace of what is read... |
| 676 |
// |
| 677 |
//////////////////////////////////////////////////////////// |
| 678 |
bool MsWks4Text::readFootNote(MWAWInputStreamPtr input, int id) |
| 679 |
{ |
| 680 |
MWAWListenerPtr listener=m_parserState->getMainListener(); |
| 681 |
if (!listener) return true; |
| 682 |
if (id < 0 || id >= int(m_state->m_ftntList.size())) { |
| 683 |
if (id >= 0) { |
| 684 |
MWAW_DEBUG_MSG(("MsWks4Text::readFootNote: can not find footnote: %d\n", id)); |
| 685 |
} |
| 686 |
listener->insertChar(' '); |
| 687 |
return false; |
| 688 |
} |
| 689 |
auto const &ft = m_state->m_ftntList[size_t(id)]; |
| 690 |
if (ft.m_begin < m_textPositions.begin() || ft.m_end > m_textPositions.end()) { |
| 691 |
MWAW_DEBUG_MSG(("MsWks4Text::readFootNote: invalid zone\n")); |
| 692 |
listener->insertChar(' '); |
| 693 |
return false; |
| 694 |
} |
| 695 |
|
| 696 |
MWAWEntry entry; |
| 697 |
entry.setBegin(ft.m_begin); |
| 698 |
entry.setEnd(ft.m_end); |
| 699 |
entry.setType("TEXT"); |
| 700 |
// if the last character is a newline, delete if |
| 701 |
input->seek(ft.m_end-1, librevenge::RVNG_SEEK_SET); |
| 702 |
if (input->readULong(1) == 0xd) entry.setEnd(ft.m_end-1); |
| 703 |
|
| 704 |
return readText(input, entry, false); |
| 705 |
} |
| 706 |
|
| 707 |
//////////////////////////////////////////////////////////// |
| 708 |
// |
| 709 |
// Read the text of the document using previously-read |
| 710 |
// formatting information. |
| 711 |
// |
| 712 |
//////////////////////////////////////////////////////////// |
| 713 |
bool MsWks4Text::readText(MWAWInputStreamPtr input, MWAWEntry const &zone, |
| 714 |
bool mainOle) |
| 715 |
{ |
| 716 |
MWAWListenerPtr listener=m_parserState->getMainListener(); |
| 717 |
if (zone.begin() < m_textPositions.begin() || zone.end() > m_textPositions.end()) { |
| 718 |
MWAW_DEBUG_MSG(("MsWks4Text::readText: invalid zone\n")); |
| 719 |
if (listener) listener->insertChar(' '); |
| 720 |
return false; |
| 721 |
} |
| 722 |
|
| 723 |
m_state->setParse(mainOle); |
| 724 |
|
| 725 |
// update the property to correspond to the text |
| 726 |
int prevFId = -1, prevPId = -1; |
| 727 |
auto FODs_iter = m_FODsList.begin(); |
| 728 |
for (; FODs_iter!= m_FODsList.end(); ++FODs_iter) { |
| 729 |
DataFOD const &fod = *(FODs_iter); |
| 730 |
if (fod.m_pos >= zone.begin()) break; |
| 731 |
|
| 732 |
int id = (*FODs_iter).m_id; |
| 733 |
if (fod.m_type == DataFOD::ATTR_TEXT) prevFId = id; |
| 734 |
else if (fod.m_type == DataFOD::ATTR_PARAG) prevPId = id; |
| 735 |
} |
| 736 |
|
| 737 |
MWAWFont actFont(prevFId != -1 ? |
| 738 |
m_state->m_fontList[size_t(prevFId)].m_font : |
| 739 |
m_state->m_defFont); |
| 740 |
if (actFont.id()<=0) |
| 741 |
actFont.setId(3); |
| 742 |
if (listener) listener->setFont(actFont); |
| 743 |
if (prevPId != -1) setProperty(m_state->m_paragraphList[size_t(prevPId)]); |
| 744 |
else setProperty(MsWks4TextInternal::Paragraph()); |
| 745 |
|
| 746 |
bool first = true; |
| 747 |
auto fType = MsWks4TextInternal::Font::None; |
| 748 |
bool pageBreak = false; |
| 749 |
int page=1; |
| 750 |
libmwaw::DebugFile &ascFile = m_document.ascii(); |
| 751 |
for (; FODs_iter!= m_FODsList.end(); ++FODs_iter) { |
| 752 |
DataFOD const &fod = *(FODs_iter); |
| 753 |
uint32_t actPos = uint32_t(first ? zone.begin() : fod.m_pos), lastPos; |
| 754 |
if (long(actPos) >= zone.end()) break; |
| 755 |
bool isObject = false; |
| 756 |
first = false; |
| 757 |
|
| 758 |
libmwaw::DebugStream f; |
| 759 |
f << "TEXT"; |
| 760 |
|
| 761 |
if (++FODs_iter!= m_FODsList.end()) lastPos = uint32_t((*FODs_iter).m_pos); |
| 762 |
else lastPos = uint32_t(zone.end()); |
| 763 |
--FODs_iter; |
| 764 |
auto len = int(lastPos-actPos); |
| 765 |
|
| 766 |
if (fod.m_type == DataFOD::ATTR_TEXT) { |
| 767 |
#if DEBUG_FP |
| 768 |
f << "["; |
| 769 |
if (fod.m_id >= 0 && fod.m_id<static_cast<int>(m_state->m_fontList.size())) { |
| 770 |
f << "C"<<fod.m_id << ":"; |
| 771 |
f << m_state->m_fontList[size_t(fod.m_id)].m_font.getDebugString(m_parserState->m_fontConverter); |
| 772 |
f << m_state->m_fontList[size_t(fod.m_id)]; |
| 773 |
} |
| 774 |
else if (fod.m_id>=0) { |
| 775 |
MWAW_DEBUG_MSG(("MsWks4Text::readText:find a bad font id=%d\n", fod.m_id)); |
| 776 |
f << "###C" << fod.m_id; |
| 777 |
} |
| 778 |
else f << "C_"; |
| 779 |
f << "]"; |
| 780 |
#endif |
| 781 |
if (fod.m_id >= 0 && fod.m_id<static_cast<int>(m_state->m_fontList.size())) { |
| 782 |
fType = m_state->m_fontList[size_t(fod.m_id)].m_fieldType; |
| 783 |
actFont=m_state->m_fontList[size_t(fod.m_id)].m_font; |
| 784 |
} |
| 785 |
else actFont=m_state->m_defFont; |
| 786 |
if (listener) listener->setFont(actFont); |
| 787 |
} |
| 788 |
else if (fod.m_type == DataFOD::ATTR_PARAG) { |
| 789 |
#if DEBUG_PP |
| 790 |
f << "["; |
| 791 |
if (fod.m_id >= 0 && fod.m_id<static_cast<int>(m_state->m_paragraphList.size())) |
| 792 |
f << "P"<<fod.m_id << ":" << m_state->m_paragraphList[size_t(fod.m_id)]; |
| 793 |
else if (fod.m_id>=0) { |
| 794 |
MWAW_DEBUG_MSG(("MsWks4Text::readText:find a bad paragraph id=%d\n", fod.m_id)); |
| 795 |
f << "###P" << fod.m_id; |
| 796 |
} |
| 797 |
else f << "P_"; |
| 798 |
f << "]"; |
| 799 |
#endif |
| 800 |
if (fod.m_id >= 0 && fod.m_id<static_cast<int>(m_state->m_paragraphList.size())) { |
| 801 |
setProperty(m_state->m_paragraphList[size_t(fod.m_id)]); |
| 802 |
if (m_state->m_paragraphList[size_t(fod.m_id)].m_pageBreak) pageBreak = true; |
| 803 |
} |
| 804 |
else setProperty(MsWks4TextInternal::Paragraph()); |
| 805 |
} |
| 806 |
else { |
| 807 |
#if DEBUG_PLC_POS |
| 808 |
f << "[PLC" << fod.m_id << ":"; |
| 809 |
if (fod.m_id >= 0 && fod.m_id<static_cast<int>(m_state->m_plcList.size())) f << m_state->m_plcList[size_t(fod.m_id)]; |
| 810 |
else if (fod.m_id>=0) { |
| 811 |
MWAW_DEBUG_MSG(("MsWks4Text::readText:find a bad plc id=%d\n", fod.m_id)); |
| 812 |
f << "###"; |
| 813 |
} |
| 814 |
f << "]"; |
| 815 |
#endif |
| 816 |
if (fod.m_id >= 0 && fod.m_id<static_cast<int>(m_state->m_plcList.size()) && long(actPos) != zone.begin() && long(actPos) < zone.end()-1) { |
| 817 |
if (m_state->m_plcList[size_t(fod.m_id)].m_type == MsWks4TextInternal::PGD) |
| 818 |
pageBreak = true; |
| 819 |
else if (m_state->m_plcList[size_t(fod.m_id)].m_type == MsWks4TextInternal::EOBJ) { |
| 820 |
auto eobjIt=m_state->m_eobjMap.find(long(actPos)); |
| 821 |
if (eobjIt == m_state->m_eobjMap.end()) { |
| 822 |
MWAW_DEBUG_MSG(("MsWks4Text::readText: can not find object\n")); |
| 823 |
} |
| 824 |
else { |
| 825 |
m_document.sendRBIL(eobjIt->second.m_id, eobjIt->second.m_dim); |
| 826 |
isObject = true; |
| 827 |
} |
| 828 |
} |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
/* plain text */ |
| 833 |
input->seek(long(actPos), librevenge::RVNG_SEEK_SET); |
| 834 |
|
| 835 |
std::string s; |
| 836 |
if (fType == MsWks4TextInternal::Font::Page && listener) { |
| 837 |
listener->insertField(MWAWField(MWAWField::PageNumber)); |
| 838 |
fType = MsWks4TextInternal::Font::None; |
| 839 |
} |
| 840 |
if (len) { |
| 841 |
if (pageBreak) { |
| 842 |
pageBreak = false; |
| 843 |
m_document.newPage(++page); |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
for (auto i = uint32_t(len); i>0; i--) { |
| 848 |
auto readVal = static_cast<uint8_t>(input->readULong(1)); |
| 849 |
s += char(readVal); |
| 850 |
if (isObject) { |
| 851 |
isObject = false; |
| 852 |
if (readVal != 0xc6) { |
| 853 |
s+='#'; |
| 854 |
MWAW_DEBUG_MSG(("MsWks4Text::readText: warning: odd caracter for object\n")); |
| 855 |
} |
| 856 |
continue; |
| 857 |
} |
| 858 |
|
| 859 |
if (0x00 == readVal) continue; |
| 860 |
|
| 861 |
if (fType == MsWks4TextInternal::Font::Note && readVal == 0x5e) { // '^' |
| 862 |
fType = MsWks4TextInternal::Font::None; |
| 863 |
if (!m_state->parseMain()) continue; |
| 864 |
|
| 865 |
if (m_state->m_ftntMap.find(long(actPos)) == m_state->m_ftntMap.end()) { |
| 866 |
MWAW_DEBUG_MSG(("MsWks4Text::readText: warning: can not find footnote for entry at %x\n", actPos)); |
| 867 |
m_document.sendFootnote(-1); |
| 868 |
} |
| 869 |
else |
| 870 |
m_document.sendFootnote(m_state->m_ftntMap[long(actPos)].m_id); |
| 871 |
continue; |
| 872 |
} |
| 873 |
|
| 874 |
switch (readVal) { |
| 875 |
case 0x09: |
| 876 |
if (!listener) break; |
| 877 |
listener->insertTab(); |
| 878 |
break; |
| 879 |
|
| 880 |
case 0x0D: { |
| 881 |
if (!listener) break; |
| 882 |
listener->insertEOL(); |
| 883 |
break; |
| 884 |
} |
| 885 |
default: { |
| 886 |
if (!listener) break; |
| 887 |
auto extra = static_cast<uint32_t>(listener->insertCharacter(static_cast<unsigned char>(readVal), input, input->tell()+long(i)-1)); |
| 888 |
if (extra > i-1) { |
| 889 |
MWAW_DEBUG_MSG(("MsWks4Text::readText: warning: extra is too large\n")); |
| 890 |
input->seek(-long(extra+1-i), librevenge::RVNG_SEEK_CUR); |
| 891 |
i = 0; |
| 892 |
} |
| 893 |
else |
| 894 |
i -= extra; |
| 895 |
} |
| 896 |
} |
| 897 |
} |
| 898 |
if (len && fType == MsWks4TextInternal::Font::DTTUnk && listener) |
| 899 |
fType = MsWks4TextInternal::Font::None; |
| 900 |
|
| 901 |
f << ", '" << s << "'"; |
| 902 |
ascFile.addPos(long(actPos)); |
| 903 |
ascFile.addNote(f.str().c_str()); |
| 904 |
} |
| 905 |
return true; |
| 906 |
} |
| 907 |
|
| 908 |
////////////////////////////////////////////////////////////////////////////// |
| 909 |
// |
| 910 |
// PLC gestion |
| 911 |
// |
| 912 |
////////////////////////////////////////////////////////////////////////////// |
| 913 |
|
| 914 |
//////////////////////////////////////// |
| 915 |
// read a plc |
| 916 |
// CHECKME: how does this code differs with MWAW4Text |
| 917 |
//////////////////////////////////////// |
| 918 |
bool MsWks4Text::readPLC(MWAWInputStreamPtr input, |
| 919 |
MWAWEntry const &entry, |
| 920 |
std::vector<long> &textPtrs, |
| 921 |
std::vector<long> &listValues, |
| 922 |
MsWks4Text::DataParser parser) |
| 923 |
{ |
| 924 |
if (!entry.hasType("PLC ")) { |
| 925 |
MWAW_DEBUG_MSG(("MsWks4Text::readPLC: warning: PLC name=%s, type=%s\n", |
| 926 |
entry.name().c_str(), entry.type().c_str())); |
| 927 |
return false; |
| 928 |
} |
| 929 |
|
| 930 |
auto page_offset = static_cast<uint32_t>(entry.begin()); |
| 931 |
long length = entry.length(); |
| 932 |
long endPos = entry.end(); |
| 933 |
|
| 934 |
input->seek(long(page_offset), librevenge::RVNG_SEEK_SET); |
| 935 |
auto nPLC = static_cast<uint16_t>(input->readULong(2)); /* number of PLC */ |
| 936 |
if (4*nPLC+10 > length) { |
| 937 |
MWAW_DEBUG_MSG(("MsWks4Text::readPLC: error: nPLC = %i, pSize=%ld\n", |
| 938 |
nPLC, length)); |
| 939 |
return false; |
| 940 |
} |
| 941 |
auto dataSz = static_cast<int>(input->readULong(2)); |
| 942 |
bool ok = true; |
| 943 |
|
| 944 |
libmwaw::DebugFile &ascFile = m_document.ascii(); |
| 945 |
libmwaw::DebugStream f, f2; |
| 946 |
|
| 947 |
auto plcType = m_state->m_knownPLC.get(entry.name()); |
| 948 |
if (plcType.m_type == MsWks4TextInternal::Unknown) { |
| 949 |
MWAW_DEBUG_MSG(("MsWks4Text::readPLC: unknown PLC name=%s, type=%s\n", |
| 950 |
entry.name().c_str(), entry.type().c_str())); |
| 951 |
} |
| 952 |
|
| 953 |
auto nPLC_ = static_cast<long>(static_cast<unsigned long>(nPLC)); |
| 954 |
if (4*nPLC_+10 + dataSz *nPLC_ != length || length/(4+dataSz) < nPLC_) { |
| 955 |
MWAW_DEBUG_MSG(("MsWks4Text::readPLC: error: odd dataSize: nPLC = %i, pSize=%ld\n", |
| 956 |
nPLC, length)); |
| 957 |
if (length/(4+dataSz) < nPLC_) |
| 958 |
dataSz=0; |
| 959 |
ok = false; |
| 960 |
} |
| 961 |
|
| 962 |
f << "N=" << nPLC << ", SZ=" << dataSz << ", unk=" << input->readLong(2) << ")"; |
| 963 |
|
| 964 |
// read text pointer |
| 965 |
std::vector<DataFOD> fods; |
| 966 |
textPtrs.resize(0); |
| 967 |
long lastPtr =m_textPositions.begin(); |
| 968 |
f << ",pos = ("; |
| 969 |
for (int i = 0; i <= nPLC; i++) { |
| 970 |
auto pos = long(input->readULong(4)); |
| 971 |
switch (plcType.m_pos) { |
| 972 |
case MsWks4PLCInternal::PLC::P_ABS: |
| 973 |
if (pos == 0) pos = m_textPositions.begin(); |
| 974 |
break; |
| 975 |
case MsWks4PLCInternal::PLC::P_REL: |
| 976 |
pos += m_textPositions.begin(); |
| 977 |
break; |
| 978 |
case MsWks4PLCInternal::PLC::P_INCR: { |
| 979 |
long newPos = lastPtr + pos; |
| 980 |
pos = lastPtr; |
| 981 |
lastPtr = newPos; |
| 982 |
break; |
| 983 |
} |
| 984 |
case MsWks4PLCInternal::PLC::P_UNKNOWN: |
| 985 |
#if !defined(__clang__) |
| 986 |
default: |
| 987 |
#endif |
| 988 |
if (pos < m_textPositions.begin() && |
| 989 |
pos+m_textPositions.begin() <= m_textPositions.end()) { |
| 990 |
plcType.m_pos = MsWks4PLCInternal::PLC::P_REL; |
| 991 |
pos += m_textPositions.begin(); |
| 992 |
} |
| 993 |
else |
| 994 |
plcType.m_pos = MsWks4PLCInternal::PLC::P_ABS; |
| 995 |
break; |
| 996 |
} |
| 997 |
// this can happen for some token, ... |
| 998 |
if (pos == m_textPositions.end()+1) pos = m_textPositions.end(); |
| 999 |
bool posOk = pos >= m_textPositions.begin() && pos <= m_textPositions.end(); |
| 1000 |
if (!posOk) f << "###"; |
| 1001 |
f << std::hex << pos << ","; |
| 1002 |
|
| 1003 |
DataFOD fod; |
| 1004 |
fod.m_type = DataFOD::ATTR_PLC; |
| 1005 |
fod.m_pos = posOk ? pos : 0; |
| 1006 |
|
| 1007 |
textPtrs.push_back(fod.m_pos); |
| 1008 |
if (i != nPLC) fods.push_back(fod); |
| 1009 |
} |
| 1010 |
f << ")"; |
| 1011 |
ascFile.addPos(long(page_offset)); |
| 1012 |
ascFile.addNote(f.str().c_str()); |
| 1013 |
|
| 1014 |
listValues.resize(0); |
| 1015 |
long pos = input->tell(); |
| 1016 |
for (size_t i = 0; i < size_t(nPLC); i++) { |
| 1017 |
MsWks4TextInternal::DataPLC plc; |
| 1018 |
plc.m_type = plcType.m_type; |
| 1019 |
plc.m_name = entry.name(); |
| 1020 |
bool printPLC = true, dataOk=true; |
| 1021 |
|
| 1022 |
switch (plcType.m_contentType) { |
| 1023 |
case MsWks4PLCInternal::PLC::T_CST : { |
| 1024 |
if (dataSz == 0) { |
| 1025 |
printPLC = false; |
| 1026 |
break; |
| 1027 |
} |
| 1028 |
if (dataSz > 4) { |
| 1029 |
f2.str(""); |
| 1030 |
for (int j = 0; j < dataSz; j++) |
| 1031 |
f2 << std::hex << input->readULong(1) << ","; |
| 1032 |
plc.m_error = f2.str(); |
| 1033 |
} |
| 1034 |
else { |
| 1035 |
plc.m_value = long(input->readULong(dataSz)); |
| 1036 |
listValues.push_back(plc.m_value); |
| 1037 |
} |
| 1038 |
|
| 1039 |
break; |
| 1040 |
} |
| 1041 |
case MsWks4PLCInternal::PLC::T_STRUCT : { |
| 1042 |
if (dataSz == 0) { |
| 1043 |
printPLC = false; |
| 1044 |
break; |
| 1045 |
} |
| 1046 |
if (parser) { |
| 1047 |
std::string mess; |
| 1048 |
if (!(this->*parser) |
| 1049 |
(input, dataSz+pos, textPtrs[i], textPtrs[i+1], static_cast<int>(i), mess)) { |
| 1050 |
dataOk = false; |
| 1051 |
break; |
| 1052 |
} |
| 1053 |
plc.m_error = mess; |
| 1054 |
} |
| 1055 |
else { |
| 1056 |
plc.m_error = "###unread"; |
| 1057 |
printPLC=true; |
| 1058 |
} |
| 1059 |
break; |
| 1060 |
} |
| 1061 |
case MsWks4PLCInternal::PLC::T_UNKNOWN: |
| 1062 |
#if !defined(__clang__) |
| 1063 |
default: |
| 1064 |
#endif |
| 1065 |
dataOk = false; |
| 1066 |
break; |
| 1067 |
} |
| 1068 |
|
| 1069 |
fods[i].m_id = static_cast<int>(m_state->m_plcList.size()); |
| 1070 |
if (dataOk) fods[i].m_defPos = pos; |
| 1071 |
m_state->m_plcList.push_back(plc); |
| 1072 |
|
| 1073 |
if (printPLC) { |
| 1074 |
f2.str(""); |
| 1075 |
f2 << plc.m_name << "(PLC"<<i<<"):" << plc; |
| 1076 |
ascFile.addPos(pos); |
| 1077 |
ascFile.addNote(f2.str().c_str()); |
| 1078 |
} |
| 1079 |
|
| 1080 |
pos += dataSz; |
| 1081 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1082 |
|
| 1083 |
if (!dataOk) plcType.m_contentType = MsWks4PLCInternal::PLC::T_UNKNOWN; |
| 1084 |
} |
| 1085 |
|
| 1086 |
if (fods.size()) |
| 1087 |
m_FODsList = mergeSortedLists(m_FODsList, fods); |
| 1088 |
|
| 1089 |
ascFile.addPos(input->tell()); |
| 1090 |
if (input->tell() != endPos) { |
| 1091 |
static bool first = false; |
| 1092 |
if (!first) { |
| 1093 |
first = true; |
| 1094 |
MWAW_DEBUG_MSG(("MsWks4Text::readPLC: problem reading end plc")); |
| 1095 |
} |
| 1096 |
f.str(""); |
| 1097 |
f << "###" << entry.name() << "/PLC"; |
| 1098 |
ascFile.addNote(f.str().c_str()); |
| 1099 |
} |
| 1100 |
|
| 1101 |
entry.setParsed(true); |
| 1102 |
return ok; |
| 1103 |
} |
| 1104 |
|
| 1105 |
// default |
| 1106 |
bool MsWks4Text::defDataParser(MWAWInputStreamPtr input, long endPos, |
| 1107 |
long, long, int, std::string &mess) |
| 1108 |
{ |
| 1109 |
mess = ""; |
| 1110 |
libmwaw::DebugStream f; |
| 1111 |
|
| 1112 |
long actPos = input->tell(); |
| 1113 |
long length = endPos-actPos; |
| 1114 |
int sz = length%4==0 ? 4 : length%2==0 ? 2 : 1; |
| 1115 |
auto nbElt = int(length/sz); |
| 1116 |
|
| 1117 |
f << "[" << sz << "]{" << std::hex; |
| 1118 |
for (int c = 0; c < nbElt; c++) f << input->readULong(sz) << ","; |
| 1119 |
f << "}"; |
| 1120 |
|
| 1121 |
mess = f.str(); |
| 1122 |
return true; |
| 1123 |
} |
| 1124 |
|
| 1125 |
//////////////////////////////////////////////////////////// |
| 1126 |
// |
| 1127 |
// the font name list |
| 1128 |
// |
| 1129 |
//////////////////////////////////////////////////////////// |
| 1130 |
bool MsWks4Text::readFontNames(MWAWInputStreamPtr input, MWAWEntry const &entry) |
| 1131 |
{ |
| 1132 |
long debPos = entry.begin(); |
| 1133 |
long endPos = entry.end(); |
| 1134 |
entry.setParsed(true); |
| 1135 |
|
| 1136 |
input->seek(debPos, librevenge::RVNG_SEEK_SET); |
| 1137 |
auto len = static_cast<uint32_t>(input->readULong(2)); |
| 1138 |
auto n_fonts = static_cast<uint32_t>(input->readULong(2)); |
| 1139 |
libmwaw::DebugFile &ascFile = m_document.ascii(); |
| 1140 |
libmwaw::DebugStream f; |
| 1141 |
|
| 1142 |
f << "N=" << n_fonts; |
| 1143 |
if (int(len)+10 != entry.length()) |
| 1144 |
f << ", ###size=" << std::hex << len+10 << std::dec ; |
| 1145 |
for (int i = 0; i < 3; i++) f << ", " << input->readLong(2); // -1/4/0 |
| 1146 |
if (debPos+10+2*long(n_fonts)>endPos) { |
| 1147 |
MWAW_DEBUG_MSG(("MsWks4Text::readFontNames: the number of font seems bad\n")); |
| 1148 |
f << "###"; |
| 1149 |
ascFile.addPos(debPos); |
| 1150 |
ascFile.addNote(f.str().c_str()); |
| 1151 |
return false; |
| 1152 |
} |
| 1153 |
f << ", defPos=[" << std::hex; // FIXME: used it |
| 1154 |
for (int i = 0; i < int(n_fonts); i++) |
| 1155 |
f << debPos+10+input->readLong(2) << ", "; |
| 1156 |
f << "]" << std::dec; |
| 1157 |
|
| 1158 |
ascFile.addPos(debPos); |
| 1159 |
ascFile.addNote(f.str().c_str()); |
| 1160 |
|
| 1161 |
/* read each font in the table */ |
| 1162 |
while (input->tell() > 0 && long(input->tell()+8) < endPos |
| 1163 |
&& m_state->m_fontNames.size() < n_fonts) { |
| 1164 |
debPos = input->tell(); |
| 1165 |
auto string_size = static_cast<uint16_t>(input->readULong(1)); |
| 1166 |
|
| 1167 |
std::string s; |
| 1168 |
for (; string_size>0; string_size--) s.append(1, char(input->readULong(1))); |
| 1169 |
|
| 1170 |
MsWks4TextInternal::FontName ft; |
| 1171 |
ft.m_name = s; |
| 1172 |
ft.m_id = static_cast<int>(input->readULong(2)); |
| 1173 |
ft.m_unknown = static_cast<int>(input->readULong(2)); |
| 1174 |
|
| 1175 |
if (s.empty()) continue; |
| 1176 |
|
| 1177 |
// fixed the relation id<->name |
| 1178 |
m_parserState->m_fontConverter->setCorrespondance(ft.m_id, s); |
| 1179 |
m_state->m_fontNames.push_back(ft); |
| 1180 |
|
| 1181 |
f.str(""); |
| 1182 |
f << ft; |
| 1183 |
|
| 1184 |
ascFile.addPos(debPos); |
| 1185 |
ascFile.addNote(f.str().c_str()); |
| 1186 |
} |
| 1187 |
|
| 1188 |
if (m_state->m_fontNames.size() != n_fonts) { |
| 1189 |
MWAW_DEBUG_MSG(("MsWks4Text::readFontNames: warning: expected %i fonts but only found %i\n", |
| 1190 |
static_cast<int>(n_fonts), static_cast<int>(m_state->m_fontNames.size()))); |
| 1191 |
return false; |
| 1192 |
} |
| 1193 |
return true; |
| 1194 |
} |
| 1195 |
|
| 1196 |
//////////////////////////////////////////////////////////// |
| 1197 |
// |
| 1198 |
// the font: |
| 1199 |
// |
| 1200 |
//////////////////////////////////////////////////////////// |
| 1201 |
void MsWks4Text::setDefault(MWAWFont const &font) |
| 1202 |
{ |
| 1203 |
m_state->m_defFont = font; |
| 1204 |
} |
| 1205 |
|
| 1206 |
// read |
| 1207 |
bool MsWks4Text::readFont(MWAWInputStreamPtr &input, long endPos, |
| 1208 |
int &id, std::string &mess) |
| 1209 |
{ |
| 1210 |
libmwaw::DebugStream f; |
| 1211 |
|
| 1212 |
MsWks4TextInternal::Font font(-1,-1); |
| 1213 |
|
| 1214 |
// 4[c] : gras, 5[c] : italic, 6[c] : souligne, 7[c] : ombre, |
| 1215 |
// c[c] : normal ?, e[i]:font ?, f[i]: size?, 18[c] : supper, 19[c] : subs |
| 1216 |
uint32_t textAttributeBits = 0; |
| 1217 |
|
| 1218 |
unsigned char col[3]= {0,0,0}; |
| 1219 |
|
| 1220 |
while (input->tell() <= endPos-2) { |
| 1221 |
bool ok = true; |
| 1222 |
|
| 1223 |
auto val = static_cast<int>(input->readLong(1)); |
| 1224 |
long pos = input->tell(); |
| 1225 |
|
| 1226 |
switch (val) { |
| 1227 |
case 0x3: { |
| 1228 |
auto v = static_cast<int>(input->readLong(1)); |
| 1229 |
switch (v) { |
| 1230 |
case 1: |
| 1231 |
font.m_fieldType = MsWks4TextInternal::Font::Page; |
| 1232 |
break; |
| 1233 |
case 2: |
| 1234 |
font.m_fieldType = MsWks4TextInternal::Font::Eobj; |
| 1235 |
break; |
| 1236 |
case 3: // this one is the indication to add a note (with char ^) |
| 1237 |
font.m_fieldType = MsWks4TextInternal::Font::Note; |
| 1238 |
break; |
| 1239 |
default: |
| 1240 |
f << "#3=" << v; |
| 1241 |
break; |
| 1242 |
} |
| 1243 |
break; |
| 1244 |
} |
| 1245 |
case 0x12: { // date or title |
| 1246 |
font.m_fieldType = MsWks4TextInternal::Font::DTT; |
| 1247 |
auto unkn = static_cast<int>(input->readLong(1)); |
| 1248 |
if (unkn) { |
| 1249 |
font.m_fieldType = MsWks4TextInternal::Font::DTTUnk; |
| 1250 |
f << "#DTT=" << unkn; |
| 1251 |
} |
| 1252 |
break; |
| 1253 |
} |
| 1254 |
case 0xc: { // ??? |
| 1255 |
f << "#c="<< input->readLong(1) << ","; |
| 1256 |
break; |
| 1257 |
} |
| 1258 |
case 0x4: { |
| 1259 |
auto v = static_cast<int>(input->readLong(1)); |
| 1260 |
if (v != 1) f << "##bold=" << v << ","; |
| 1261 |
textAttributeBits |= MWAWFont::boldBit; |
| 1262 |
break; |
| 1263 |
} |
| 1264 |
case 0x5: { |
| 1265 |
auto v = static_cast<int>(input->readLong(1)); |
| 1266 |
if (v != 1) f << "##it=" << v << ","; |
| 1267 |
textAttributeBits |= MWAWFont::italicBit; |
| 1268 |
break; |
| 1269 |
} |
| 1270 |
case 0x6: { |
| 1271 |
auto v = static_cast<int>(input->readLong(1)); |
| 1272 |
if (v != 1) f << "##under=" << v << ","; |
| 1273 |
font.m_font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 1274 |
break; |
| 1275 |
} |
| 1276 |
case 0x7: { |
| 1277 |
auto v = static_cast<int>(input->readLong(1)); |
| 1278 |
if (v != 1) f << "##emboss=" << v << ","; |
| 1279 |
textAttributeBits |= MWAWFont::embossBit; |
| 1280 |
break; |
| 1281 |
} |
| 1282 |
case 0x8: { |
| 1283 |
auto v = static_cast<int>(input->readLong(1)); |
| 1284 |
if (v != 1) f << "##shadow=" << v << ","; |
| 1285 |
textAttributeBits |= MWAWFont::shadowBit; |
| 1286 |
break; |
| 1287 |
} |
| 1288 |
case 0x9: { // small interval between char |
| 1289 |
font.m_font.setDeltaLetterSpacing(-1); |
| 1290 |
auto v = static_cast<int>(input->readLong(1)); |
| 1291 |
if (v != 1) f << "##Condensed=" << v << ","; |
| 1292 |
else f << "Cond,"; |
| 1293 |
break; |
| 1294 |
} |
| 1295 |
case 0xa: { // big interval between char |
| 1296 |
font.m_font.setDeltaLetterSpacing(1); |
| 1297 |
auto v = static_cast<int>(input->readLong(1)); |
| 1298 |
if (v != 1) f << "##Expand=" << v << ","; |
| 1299 |
else f << "Expand,"; |
| 1300 |
break; |
| 1301 |
} |
| 1302 |
case 0x18: { |
| 1303 |
auto v = static_cast<int>(input->readLong(1)); |
| 1304 |
if (v != 1) f << "##super=" << v << ","; |
| 1305 |
font.m_font.set(MWAWFont::Script::super100()); |
| 1306 |
break; |
| 1307 |
} |
| 1308 |
case 0x19: { |
| 1309 |
auto v = static_cast<int>(input->readLong(1)); |
| 1310 |
if (v != 1) f << "##sub =" << v << ","; |
| 1311 |
font.m_font.set(MWAWFont::Script::sub100()); |
| 1312 |
} |
| 1313 |
break; |
| 1314 |
case 0xe: |
| 1315 |
case 0xf: { |
| 1316 |
if (pos+2 > endPos) { |
| 1317 |
ok = false; |
| 1318 |
break; |
| 1319 |
} |
| 1320 |
auto v = static_cast<int>(input->readLong(2)); |
| 1321 |
|
| 1322 |
if (val == 0xe) { // fontId |
| 1323 |
if (v < 0 || v >= int(m_state->m_fontNames.size())) { |
| 1324 |
ok = false; |
| 1325 |
break; |
| 1326 |
} |
| 1327 |
font.m_font.setId(m_state->m_fontNames[size_t(v)].m_id); |
| 1328 |
font.m_font.setSize(12); |
| 1329 |
} |
| 1330 |
else { // fontSize |
| 1331 |
if (v <= 0 || v > 200) { |
| 1332 |
ok = false; |
| 1333 |
break; |
| 1334 |
} |
| 1335 |
font.m_font.setSize(float(v)); |
| 1336 |
} |
| 1337 |
break; |
| 1338 |
} |
| 1339 |
case 0x10: { // color |
| 1340 |
if (pos+6 > endPos) { |
| 1341 |
ok = false; |
| 1342 |
break; |
| 1343 |
} |
| 1344 |
|
| 1345 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 1346 |
break; |
| 1347 |
} |
| 1348 |
default: |
| 1349 |
ok = false; |
| 1350 |
break; |
| 1351 |
} |
| 1352 |
|
| 1353 |
if (ok) continue; |
| 1354 |
|
| 1355 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1356 |
// try to guess the attribute size |
| 1357 |
auto v = static_cast<int>(input->readULong(1)); |
| 1358 |
if (v == 1) ok = true; |
| 1359 |
else if (pos+2 < endPos && v == 0 && input->readULong(1) == 1) ok = true; |
| 1360 |
|
| 1361 |
if (ok) { |
| 1362 |
f << "#" << val << "=" << std::hex << 1 << std::dec << ","; |
| 1363 |
continue; |
| 1364 |
} |
| 1365 |
|
| 1366 |
input->seek(pos-1, librevenge::RVNG_SEEK_SET); |
| 1367 |
f << "#end=" << std::hex; |
| 1368 |
while (pos++ < endPos) f << input->readULong(1) << ","; |
| 1369 |
break; |
| 1370 |
} |
| 1371 |
|
| 1372 |
font.m_font.setColor(MWAWColor(col[0],col[1],col[2])); |
| 1373 |
font.m_font.setFlags(textAttributeBits); |
| 1374 |
font.m_error = f.str(); |
| 1375 |
|
| 1376 |
id = static_cast<int>(m_state->m_fontList.size()); |
| 1377 |
m_state->m_fontList.push_back(font); |
| 1378 |
|
| 1379 |
f.str(""); |
| 1380 |
f << font.m_font.getDebugString(m_parserState->m_fontConverter); |
| 1381 |
f << font; |
| 1382 |
mess = f.str(); |
| 1383 |
|
| 1384 |
return true; |
| 1385 |
} |
| 1386 |
|
| 1387 |
//////////////////////////////////////////////////////////// |
| 1388 |
// |
| 1389 |
// the paragraph properties: |
| 1390 |
// |
| 1391 |
//////////////////////////////////////////////////////////// |
| 1392 |
void MsWks4Text::setProperty(MsWks4TextInternal::Paragraph const &p) |
| 1393 |
{ |
| 1394 |
if (!m_parserState->getMainListener()) return; |
| 1395 |
m_parserState->getMainListener()->setParagraph(p); |
| 1396 |
m_state->m_paragraph = p; |
| 1397 |
} |
| 1398 |
|
| 1399 |
// read |
| 1400 |
bool MsWks4Text::readParagraph(MWAWInputStreamPtr &input, long endPos, |
| 1401 |
int &id, std::string &mess) |
| 1402 |
{ |
| 1403 |
MsWks4TextInternal::Paragraph parag; |
| 1404 |
|
| 1405 |
libmwaw::DebugFile &ascFile = m_document.ascii(); |
| 1406 |
libmwaw::DebugStream f; |
| 1407 |
|
| 1408 |
bool customSpacing = false; |
| 1409 |
|
| 1410 |
while (input->tell() < endPos) { |
| 1411 |
auto val = static_cast<int>(input->readLong(1)); |
| 1412 |
auto pos = long(input->tell()); |
| 1413 |
|
| 1414 |
bool ok = true; |
| 1415 |
switch (val) { |
| 1416 |
case 0x1b: { // justification : 1:right 2:center, 3:full |
| 1417 |
if (pos + 1 > endPos) { |
| 1418 |
ok = false; |
| 1419 |
break; |
| 1420 |
} |
| 1421 |
auto value = static_cast<int>(input->readLong(1)); |
| 1422 |
switch (value) { |
| 1423 |
case 0: |
| 1424 |
parag.m_justify = MWAWParagraph::JustificationLeft; |
| 1425 |
break; |
| 1426 |
case 1: |
| 1427 |
parag.m_justify = MWAWParagraph::JustificationRight; |
| 1428 |
break; |
| 1429 |
case 2: |
| 1430 |
parag.m_justify = MWAWParagraph::JustificationCenter; |
| 1431 |
break; |
| 1432 |
case 3: |
| 1433 |
parag.m_justify = MWAWParagraph::JustificationFull; |
| 1434 |
break; |
| 1435 |
default: |
| 1436 |
parag.m_justify = MWAWParagraph::JustificationLeft; |
| 1437 |
f << "#just="<<value<<","; |
| 1438 |
break; |
| 1439 |
} |
| 1440 |
break; |
| 1441 |
} |
| 1442 |
case 0x21: { // page break ? |
| 1443 |
if (pos + 1 > endPos) { |
| 1444 |
ok = false; |
| 1445 |
break; |
| 1446 |
} |
| 1447 |
auto value= static_cast<int>(input->readLong(1)); |
| 1448 |
if (value == 1) parag.m_pageBreak = true; |
| 1449 |
else f << "#pgBreak="<<value<<","; |
| 1450 |
break; |
| 1451 |
} |
| 1452 |
case 0x22: { // bullet |
| 1453 |
if (pos + 1 > endPos) { |
| 1454 |
ok = false; |
| 1455 |
break; |
| 1456 |
} |
| 1457 |
auto value= static_cast<int>(input->readLong(1)); |
| 1458 |
if (value != 1) { |
| 1459 |
f << "#bullet="<<value<<","; |
| 1460 |
break; |
| 1461 |
} |
| 1462 |
MWAWListLevel level; |
| 1463 |
level.m_type = MWAWListLevel::BULLET; |
| 1464 |
level.m_labelWidth = 0.1; |
| 1465 |
libmwaw::appendUnicode(0x2022, level.m_bullet); |
| 1466 |
auto list = m_parserState->m_listManager->getNewList(std::shared_ptr<MWAWList>(), 1, level); |
| 1467 |
if (!list) { |
| 1468 |
f << "#bullet,"; |
| 1469 |
MWAW_DEBUG_MSG(("MsWks4Text::readParagraph: can not create bullet list\n")); |
| 1470 |
break; |
| 1471 |
} |
| 1472 |
parag.m_listId = list->getId(); |
| 1473 |
parag.m_listLevelIndex = 1; |
| 1474 |
break; |
| 1475 |
} |
| 1476 |
case 0x23: { // alignment -2 (up space), -3 (large?) |
| 1477 |
if (pos + 2 > endPos) { |
| 1478 |
ok = false; |
| 1479 |
break; |
| 1480 |
} |
| 1481 |
auto value = static_cast<int>(input->readLong(2)); |
| 1482 |
if (value > 100) { |
| 1483 |
ok = false; |
| 1484 |
break; |
| 1485 |
} |
| 1486 |
if (value > 0) { |
| 1487 |
customSpacing = true; |
| 1488 |
parag.setInterline(value, librevenge::RVNG_POINT, MWAWParagraph::AtLeast); |
| 1489 |
} |
| 1490 |
else { |
| 1491 |
switch (-value) { |
| 1492 |
case 1: // normal |
| 1493 |
break; |
| 1494 |
case 2: |
| 1495 |
parag.setInterline(1.5, librevenge::RVNG_PERCENT); |
| 1496 |
break; |
| 1497 |
case 3: // double |
| 1498 |
parag.setInterline(2.0, librevenge::RVNG_PERCENT); |
| 1499 |
break; |
| 1500 |
default: |
| 1501 |
f << "#spacing=" << value << ","; |
| 1502 |
break; |
| 1503 |
} |
| 1504 |
break; |
| 1505 |
} |
| 1506 |
break; |
| 1507 |
} |
| 1508 |
case 0x24: |
| 1509 |
case 0x25: |
| 1510 |
case 0x26: { |
| 1511 |
if (pos + 2 > endPos) { |
| 1512 |
ok = false; |
| 1513 |
break; |
| 1514 |
} |
| 1515 |
auto v = static_cast<int>(input->readLong(2)); |
| 1516 |
if (v < -300 || v > 1000) { |
| 1517 |
ok = false; |
| 1518 |
break; |
| 1519 |
} |
| 1520 |
|
| 1521 |
if (val==0x26 && v > 28) // decrease a little the right margins |
| 1522 |
parag.m_margins[2] = double(v-28)/72.; |
| 1523 |
else |
| 1524 |
parag.m_margins[val-0x24] = double(v)/72.; |
| 1525 |
break; |
| 1526 |
} |
| 1527 |
case 0x27: { |
| 1528 |
if (pos + 42 > endPos) { |
| 1529 |
ok = false; |
| 1530 |
break; |
| 1531 |
} |
| 1532 |
auto nbt = static_cast<int>(input->readLong(2)); |
| 1533 |
if (nbt < 0 || nbt > 20) { |
| 1534 |
ok = false; |
| 1535 |
break; |
| 1536 |
} |
| 1537 |
|
| 1538 |
parag.m_tabs->resize(size_t(nbt)); |
| 1539 |
for (auto &tab : *parag.m_tabs) { |
| 1540 |
auto value = static_cast<int>(input->readULong(2)); |
| 1541 |
int flag = (value & 0xc000) >> 14; |
| 1542 |
auto align = MWAWTabStop::LEFT; |
| 1543 |
switch (flag) { |
| 1544 |
case 0: |
| 1545 |
align = MWAWTabStop::LEFT; |
| 1546 |
break; |
| 1547 |
case 1: |
| 1548 |
align = MWAWTabStop::DECIMAL; |
| 1549 |
break; |
| 1550 |
case 2: |
| 1551 |
align = MWAWTabStop::RIGHT; |
| 1552 |
break; |
| 1553 |
case 3: |
| 1554 |
align = MWAWTabStop::CENTER; |
| 1555 |
break; |
| 1556 |
default: |
| 1557 |
; |
| 1558 |
} |
| 1559 |
value &= 0x3fff; |
| 1560 |
|
| 1561 |
tab.m_alignment = align; |
| 1562 |
tab.m_position = value/72.0; |
| 1563 |
} |
| 1564 |
input->seek(pos+42, librevenge::RVNG_SEEK_SET); |
| 1565 |
break; |
| 1566 |
} |
| 1567 |
case 0x28: { // alignment: exact or not |
| 1568 |
if (pos + 1 > endPos) { |
| 1569 |
ok = false; |
| 1570 |
break; |
| 1571 |
} |
| 1572 |
auto value= static_cast<int>(input->readLong(1)); |
| 1573 |
if (value != 1) |
| 1574 |
f << "#spacingType=" << value << ","; |
| 1575 |
else if (customSpacing) |
| 1576 |
parag.m_spacingsInterlineType = MWAWParagraph::Fixed; |
| 1577 |
break; |
| 1578 |
} |
| 1579 |
default: |
| 1580 |
ok = false; |
| 1581 |
break; |
| 1582 |
} |
| 1583 |
|
| 1584 |
if (ok) continue; |
| 1585 |
|
| 1586 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1587 |
ascFile.addDelimiter(pos, '|'); |
| 1588 |
f << "#end=("; |
| 1589 |
while (input->tell() < endPos) |
| 1590 |
f << std::hex << static_cast<unsigned int>(input->readLong(1)) << ","; |
| 1591 |
f << ")"; |
| 1592 |
break; |
| 1593 |
} |
| 1594 |
// absolute first indent -> relative |
| 1595 |
parag.m_margins[0] = *parag.m_margins[0]-*parag.m_margins[1]; |
| 1596 |
|
| 1597 |
parag.m_extra=f.str(); |
| 1598 |
id = static_cast<int>(m_state->m_paragraphList.size()); |
| 1599 |
m_state->m_paragraphList.push_back(parag); |
| 1600 |
|
| 1601 |
f.str(""); |
| 1602 |
f << parag; |
| 1603 |
mess = f.str(); |
| 1604 |
|
| 1605 |
return true; |
| 1606 |
} |
| 1607 |
|
| 1608 |
//////////////////////////////////////////////////////////// |
| 1609 |
// |
| 1610 |
// the object ( data stored in RBIL ? ) |
| 1611 |
// |
| 1612 |
//////////////////////////////////////////////////////////// |
| 1613 |
bool MsWks4Text::eobjDataParser(MWAWInputStreamPtr input, long endPos, |
| 1614 |
long bot, long, int id, std::string &mess) |
| 1615 |
{ |
| 1616 |
mess = ""; |
| 1617 |
libmwaw::DebugStream f; |
| 1618 |
long actPos = input->tell(); |
| 1619 |
long length = endPos-actPos; |
| 1620 |
|
| 1621 |
if (length != 10) { |
| 1622 |
mess = "###"; |
| 1623 |
return true; |
| 1624 |
} |
| 1625 |
MsWks4TextInternal::Object obj; |
| 1626 |
obj.m_id = id; |
| 1627 |
obj.m_type = static_cast<int>(input->readLong(2)); |
| 1628 |
for (int i = 0; i < 2; i++) obj.m_dim[i] = static_cast<int>(input->readLong(2)); |
| 1629 |
obj.m_fileId = long(input->readULong(4)); |
| 1630 |
obj.m_error = f.str(); |
| 1631 |
|
| 1632 |
m_state->m_eobjMap[bot] = obj; |
| 1633 |
|
| 1634 |
f.str(""); |
| 1635 |
f << obj; |
| 1636 |
mess = f.str(); |
| 1637 |
return true; |
| 1638 |
} |
| 1639 |
|
| 1640 |
//////////////////////////////////////////////////////////// |
| 1641 |
// |
| 1642 |
// the ftnt ( footnote ) |
| 1643 |
// |
| 1644 |
//////////////////////////////////////////////////////////// |
| 1645 |
bool MsWks4Text::ftntDataParser(MWAWInputStreamPtr input, long endPos, |
| 1646 |
long bot, long eot, int id, std::string &mess) |
| 1647 |
{ |
| 1648 |
mess = ""; |
| 1649 |
libmwaw::DebugStream f; |
| 1650 |
long actPos = input->tell(); |
| 1651 |
long length = endPos-actPos; |
| 1652 |
|
| 1653 |
if (length != 10) { |
| 1654 |
mess = "###"; |
| 1655 |
return true; |
| 1656 |
} |
| 1657 |
MsWks4TextInternal::Ftnt ftnt; |
| 1658 |
ftnt.m_type = static_cast<int>(input->readULong(2)); // always 1=footnote, endnote=? |
| 1659 |
if (ftnt.m_type != 1) { |
| 1660 |
MWAW_DEBUG_MSG(("MsWks4Text::ftntDataParser: unknown type=%d\n",ftnt.m_type)); |
| 1661 |
} |
| 1662 |
ftnt.m_id = id; |
| 1663 |
if (!m_state->parseMain()) { |
| 1664 |
ftnt.m_begin = bot; |
| 1665 |
ftnt.m_end = eot; |
| 1666 |
} |
| 1667 |
for (int i = 0; i < 4; i++) { |
| 1668 |
auto val = static_cast<int>(input->readLong(2)); |
| 1669 |
if (val) f << "unkn" << i << "=" << val << ","; |
| 1670 |
} |
| 1671 |
ftnt.m_error= f.str(); |
| 1672 |
if (m_state->parseMain()) |
| 1673 |
m_state->m_ftntMap[bot] = ftnt; |
| 1674 |
else |
| 1675 |
m_state->m_ftntList.push_back(ftnt); |
| 1676 |
|
| 1677 |
f.str(""); |
| 1678 |
f << ftnt; |
| 1679 |
mess = f.str(); |
| 1680 |
return true; |
| 1681 |
} |
| 1682 |
|
| 1683 |
//////////////////////////////////////////////////////////// |
| 1684 |
// |
| 1685 |
// the pgd (page break ) |
| 1686 |
// Fixme: only parsed..... |
| 1687 |
//////////////////////////////////////////////////////////// |
| 1688 |
bool MsWks4Text::pgdDataParser(MWAWInputStreamPtr input, long endPos, |
| 1689 |
long, long, int, std::string &mess) |
| 1690 |
{ |
| 1691 |
mess = ""; |
| 1692 |
libmwaw::DebugStream f; |
| 1693 |
|
| 1694 |
long actPos = input->tell(); |
| 1695 |
long length = endPos-actPos; |
| 1696 |
|
| 1697 |
if (length != 2) { |
| 1698 |
mess = "###"; |
| 1699 |
return false; |
| 1700 |
} |
| 1701 |
f << "val=" << input->readULong(1); // 0, 1, 2, 0x12, 0x1a |
| 1702 |
auto val = static_cast<int>(input->readLong(1)); |
| 1703 |
if (val) f << ":" << val; |
| 1704 |
mess = f.str(); |
| 1705 |
return true; |
| 1706 |
} |
| 1707 |
|
| 1708 |
//////////////////////////////////////////////////////////// |
| 1709 |
// |
| 1710 |
// the token (ie. a field) |
| 1711 |
// Fixme: only parsed..... |
| 1712 |
// |
| 1713 |
//////////////////////////////////////////////////////////// |
| 1714 |
bool MsWks4Text::toknDataParser(MWAWInputStreamPtr input, long endPos, |
| 1715 |
long bot, long, int id, std::string &mess) |
| 1716 |
{ |
| 1717 |
mess = ""; |
| 1718 |
libmwaw::DebugFile &ascFile = m_document.ascii(); |
| 1719 |
libmwaw::DebugStream f; |
| 1720 |
|
| 1721 |
long actPos = input->tell(); |
| 1722 |
long length = endPos-actPos; |
| 1723 |
|
| 1724 |
if (length < 10 || !input->checkPosition(endPos)) { |
| 1725 |
mess = "###"; |
| 1726 |
return true; |
| 1727 |
} |
| 1728 |
MsWks4TextInternal::Token tok; |
| 1729 |
auto type = static_cast<int>(input->readLong(2)); |
| 1730 |
int beginType = 0; |
| 1731 |
switch (type) { |
| 1732 |
case 1: |
| 1733 |
tok.m_type = MWAWField::Date; |
| 1734 |
beginType=1; |
| 1735 |
break; |
| 1736 |
case 2: |
| 1737 |
tok.m_type = MWAWField::Time; |
| 1738 |
beginType=1; |
| 1739 |
break; |
| 1740 |
case 4: |
| 1741 |
tok.m_type = MWAWField::PageNumber; |
| 1742 |
beginType = 0; |
| 1743 |
break; |
| 1744 |
// next int |
| 1745 |
case 8: |
| 1746 |
tok.m_type = MWAWField::Title; |
| 1747 |
beginType = 0; |
| 1748 |
break; |
| 1749 |
// next int |
| 1750 |
case 16: |
| 1751 |
tok.m_type = MWAWField::Database; |
| 1752 |
beginType = 2; |
| 1753 |
break; |
| 1754 |
default: |
| 1755 |
MWAW_DEBUG_MSG(("MsWks4Text::toknDataParser: unknown type=%d\n",type)); |
| 1756 |
f << "###type=" << type <<","; |
| 1757 |
break; |
| 1758 |
} |
| 1759 |
// the text length |
| 1760 |
tok.m_textLength = static_cast<int>(input->readLong(2)); |
| 1761 |
|
| 1762 |
switch (beginType) { |
| 1763 |
case 1: { |
| 1764 |
tok.m_unknown = static_cast<int>(input->readULong(2)); |
| 1765 |
auto v = static_cast<int>(input->readLong(2)); |
| 1766 |
if (v) f << std::hex << "###unkn0=" << v << "," << std::dec; |
| 1767 |
break; |
| 1768 |
} |
| 1769 |
case 2: { |
| 1770 |
long len = input->readLong(1); |
| 1771 |
if (len>=0 && actPos+5+len <= endPos) { |
| 1772 |
std::string str; |
| 1773 |
for (long i = 0; i < len; i++) |
| 1774 |
str+= char(input->readULong(1)); |
| 1775 |
f << "str=" << str <<","; |
| 1776 |
} |
| 1777 |
else |
| 1778 |
input->seek(-1, librevenge::RVNG_SEEK_CUR); |
| 1779 |
break; |
| 1780 |
} |
| 1781 |
default: |
| 1782 |
break; |
| 1783 |
} |
| 1784 |
|
| 1785 |
// sometimes, followed by the bot or by val, 0, bot |
| 1786 |
// sometines, no |
| 1787 |
auto debDataPos = static_cast<int>(input->readLong(2)); |
| 1788 |
if (m_textPositions.begin()+debDataPos == bot); |
| 1789 |
else { |
| 1790 |
MWAW_DEBUG_MSG(("MsWks4Text::toknDataParser: odd token\n")); |
| 1791 |
f << std::hex << "###deb=" << debDataPos << "," << std::dec; |
| 1792 |
} |
| 1793 |
f << tok; |
| 1794 |
|
| 1795 |
mess = f.str(); |
| 1796 |
|
| 1797 |
actPos = input->tell(); |
| 1798 |
if (actPos != endPos) { |
| 1799 |
f.str(""); |
| 1800 |
f << std::dec << "TOKN(PLC" << id << "):len=" << endPos-actPos<< ",###" << tok ; |
| 1801 |
ascFile.addPos(actPos); |
| 1802 |
ascFile.addNote(f.str().c_str()); |
| 1803 |
} |
| 1804 |
|
| 1805 |
return true; |
| 1806 |
} |
| 1807 |
|
| 1808 |
//////////////////////////////////////////////////////////// |
| 1809 |
// find data |
| 1810 |
//////////////////////////////////////////////////////////// |
| 1811 |
bool MsWks4Text::findFDPStructures(MWAWInputStreamPtr &input, int which) |
| 1812 |
{ |
| 1813 |
auto &zones = which ? m_FDPCs : m_FDPPs; |
| 1814 |
zones.resize(0); |
| 1815 |
|
| 1816 |
char const *indexName = which ? "BTEC" : "BTEP"; |
| 1817 |
char const *sIndexName = which ? "FDPC" : "FDPP"; |
| 1818 |
|
| 1819 |
auto pos = m_document.getEntryMap().lower_bound(indexName); |
| 1820 |
std::vector<MWAWEntry const *> listIndexed; |
| 1821 |
while (pos != m_document.getEntryMap().end()) { |
| 1822 |
MWAWEntry const &entry = pos++->second; |
| 1823 |
if (!entry.hasName(indexName)) break; |
| 1824 |
if (!entry.hasType("PLC ")) continue; |
| 1825 |
listIndexed.push_back(&entry); |
| 1826 |
} |
| 1827 |
|
| 1828 |
size_t nFind = listIndexed.size(); |
| 1829 |
if (nFind==0) return false; |
| 1830 |
|
| 1831 |
// can nFind be > 1 ? |
| 1832 |
for (size_t i = 0; i < nFind-1; i++) { |
| 1833 |
bool ok = true; |
| 1834 |
for (size_t j = 0; j < nFind-1-i; j++) { |
| 1835 |
if (listIndexed[j]->id() <= listIndexed[j+1]->id()) continue; |
| 1836 |
std::swap(listIndexed[j],listIndexed[j+1]); |
| 1837 |
ok = false; |
| 1838 |
} |
| 1839 |
if (ok) break; |
| 1840 |
} |
| 1841 |
|
| 1842 |
for (size_t i = 0; i < nFind-1; i++) |
| 1843 |
if (listIndexed[i]->id() == listIndexed[i+1]->id()) return false; |
| 1844 |
|
| 1845 |
// create a map offset -> entry |
| 1846 |
std::map<long, MWAWEntry const *> offsetMap; |
| 1847 |
pos = m_document.getEntryMap().lower_bound(sIndexName); |
| 1848 |
while (pos != m_document.getEntryMap().end()) { |
| 1849 |
MWAWEntry const &entry = pos++->second; |
| 1850 |
if (!entry.hasName(sIndexName)) break; |
| 1851 |
offsetMap.insert(std::map<long, MWAWEntry const *>::value_type |
| 1852 |
(entry.begin(), &entry)); |
| 1853 |
} |
| 1854 |
|
| 1855 |
for (auto entry : listIndexed) { |
| 1856 |
std::vector<long> textPtrs; |
| 1857 |
std::vector<long> listValues; |
| 1858 |
|
| 1859 |
if (!readSimplePLC(input, *entry, textPtrs, listValues)) return false; |
| 1860 |
|
| 1861 |
size_t numV = listValues.size(); |
| 1862 |
if (textPtrs.size() != numV+1) return false; |
| 1863 |
|
| 1864 |
for (auto position : listValues) { |
| 1865 |
if (position <= 0) return false; |
| 1866 |
|
| 1867 |
auto offsIt = offsetMap.find(position); |
| 1868 |
if (offsIt == offsetMap.end()) return false; |
| 1869 |
|
| 1870 |
zones.push_back(offsIt->second); |
| 1871 |
} |
| 1872 |
} |
| 1873 |
|
| 1874 |
return true; |
| 1875 |
} |
| 1876 |
|
| 1877 |
bool MsWks4Text::findFDPStructuresByHand(MWAWInputStreamPtr &/*input*/, int which) |
| 1878 |
{ |
| 1879 |
char const *indexName = which ? "FDPC" : "FDPP"; |
| 1880 |
MWAW_DEBUG_MSG(("MsWks4Text::findFDPStructuresByHand: error: need to create %s list by hand \n", indexName)); |
| 1881 |
|
| 1882 |
auto &zones = which ? m_FDPCs : m_FDPPs; |
| 1883 |
zones.resize(0); |
| 1884 |
|
| 1885 |
auto pos = m_document.getEntryMap().lower_bound(indexName); |
| 1886 |
while (pos != m_document.getEntryMap().end()) { |
| 1887 |
MWAWEntry const &entry = pos++->second; |
| 1888 |
if (!entry.hasName(indexName)) break; |
| 1889 |
if (!entry.hasType(indexName)) continue; |
| 1890 |
|
| 1891 |
zones.push_back(&entry); |
| 1892 |
} |
| 1893 |
return zones.size() != 0; |
| 1894 |
} |
| 1895 |
|
| 1896 |
//////////////////////////////////////////////////////////// |
| 1897 |
// read data |
| 1898 |
//////////////////////////////////////////////////////////// |
| 1899 |
bool MsWks4Text::readFDP(MWAWInputStreamPtr &input, MWAWEntry const &entry, |
| 1900 |
std::vector<DataFOD> &fods, |
| 1901 |
MsWks4Text::FDPParser parser) |
| 1902 |
{ |
| 1903 |
if (entry.length() <= 0 || entry.begin() <= 0) { |
| 1904 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP warning: FDP entry unintialized")); |
| 1905 |
return false; |
| 1906 |
} |
| 1907 |
|
| 1908 |
entry.setParsed(); |
| 1909 |
auto page_offset = static_cast<uint32_t>(entry.begin()); |
| 1910 |
long length = entry.length(); |
| 1911 |
long endPage = entry.end(); |
| 1912 |
|
| 1913 |
int const deplSize = 2; |
| 1914 |
int const headerSize = 8; |
| 1915 |
|
| 1916 |
if (length < headerSize) { |
| 1917 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: warning: FDP offset=0x%X, length=0x%lx\n", |
| 1918 |
page_offset, static_cast<long unsigned int>(length))); |
| 1919 |
return false; |
| 1920 |
} |
| 1921 |
|
| 1922 |
libmwaw::DebugFile &ascFile = m_document.ascii(); |
| 1923 |
libmwaw::DebugStream f; |
| 1924 |
input->seek(long(page_offset), librevenge::RVNG_SEEK_SET); |
| 1925 |
auto cfod = static_cast<uint16_t>(input->readULong(deplSize)); |
| 1926 |
|
| 1927 |
f << "FDP: N="<<static_cast<int>(cfod); |
| 1928 |
f << ", unk=" << input->readLong(2); |
| 1929 |
|
| 1930 |
if (headerSize+(4+deplSize)*cfod > length) { |
| 1931 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: error: cfod = %i (0x%X)\n", cfod, static_cast<unsigned int>(cfod))); |
| 1932 |
return false; |
| 1933 |
} |
| 1934 |
|
| 1935 |
auto firstFod = static_cast<int>(fods.size()); |
| 1936 |
long lastLimit = firstFod ? fods.back().m_pos : 0; |
| 1937 |
|
| 1938 |
long lastReadPos = 0L; |
| 1939 |
|
| 1940 |
DataFOD::Type type = DataFOD::ATTR_UNKN; |
| 1941 |
if (entry.hasType("FDPC")) type = DataFOD::ATTR_TEXT; |
| 1942 |
else if (entry.hasType("FDPP")) type = DataFOD::ATTR_PARAG; |
| 1943 |
else { |
| 1944 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: FDP error: unknown type = '%s'\n", entry.type().c_str())); |
| 1945 |
} |
| 1946 |
|
| 1947 |
/* Read array of fcLim of FODs. The fcLim refers to the offset of the |
| 1948 |
last character covered by the formatting. */ |
| 1949 |
for (int i = 0; i <= cfod; i++) { |
| 1950 |
DataFOD fod; |
| 1951 |
fod.m_type = type; |
| 1952 |
fod.m_pos = long(input->readULong(4)); |
| 1953 |
if (fod.m_pos == 0) fod.m_pos=m_textPositions.begin(); |
| 1954 |
|
| 1955 |
/* check that fcLim is not too large */ |
| 1956 |
if (fod.m_pos > m_textPositions.end()) { |
| 1957 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: error: length of 'text selection' %ld > " |
| 1958 |
"total text length %ld\n", fod.m_pos, m_textPositions.end())); |
| 1959 |
return false; |
| 1960 |
} |
| 1961 |
|
| 1962 |
/* check that pos is monotonic */ |
| 1963 |
if (lastLimit > fod.m_pos) { |
| 1964 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: error: character position list must " |
| 1965 |
"be monotonic, but found %ld, %ld\n", lastLimit, fod.m_pos)); |
| 1966 |
return false; |
| 1967 |
} |
| 1968 |
|
| 1969 |
lastLimit = fod.m_pos; |
| 1970 |
|
| 1971 |
if (i != cfod) |
| 1972 |
fods.push_back(fod); |
| 1973 |
else // ignore the last text position |
| 1974 |
lastReadPos = fod.m_pos; |
| 1975 |
} |
| 1976 |
|
| 1977 |
std::vector<DataFOD>::iterator fods_iter; |
| 1978 |
/* Read array of bfprop of FODs. The bfprop is the offset where |
| 1979 |
the FPROP is located. */ |
| 1980 |
f << ", Tpos:defP=(" << std::hex; |
| 1981 |
for (fods_iter = fods.begin() + firstFod; fods_iter!= fods.end(); ++fods_iter) { |
| 1982 |
auto depl = static_cast<int>(input->readULong(deplSize)); |
| 1983 |
/* check size of bfprop */ |
| 1984 |
if ((depl < headerSize+(4+deplSize)*cfod && depl > 0) || |
| 1985 |
long(page_offset)+depl > endPage) { |
| 1986 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: error: pos of bfprop is bad " |
| 1987 |
"%i (0x%X)\n", depl, static_cast<unsigned int>(depl))); |
| 1988 |
return false; |
| 1989 |
} |
| 1990 |
|
| 1991 |
if (depl) |
| 1992 |
(*fods_iter).m_defPos = depl + long(page_offset); |
| 1993 |
|
| 1994 |
f << (*fods_iter).m_pos << ":"; |
| 1995 |
if (depl) f << (*fods_iter).m_defPos << ", "; |
| 1996 |
else f << "_, "; |
| 1997 |
} |
| 1998 |
f << "), lstPos=" << lastReadPos << ", "; |
| 1999 |
|
| 2000 |
ascFile.addPos(long(page_offset)); |
| 2001 |
ascFile.addNote(f.str().c_str()); |
| 2002 |
ascFile.addPos(input->tell()); |
| 2003 |
|
| 2004 |
std::map<long,int> mapPtr; |
| 2005 |
for (fods_iter = fods.begin() + firstFod; fods_iter!= fods.end(); ++fods_iter) { |
| 2006 |
long pos = (*fods_iter).m_defPos; |
| 2007 |
if (pos == 0) continue; |
| 2008 |
|
| 2009 |
auto it= mapPtr.find(pos); |
| 2010 |
if (it != mapPtr.end()) { |
| 2011 |
(*fods_iter).m_id = mapPtr[pos]; |
| 2012 |
continue; |
| 2013 |
} |
| 2014 |
|
| 2015 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2016 |
auto szProp = static_cast<int>(input->readULong(1)); |
| 2017 |
szProp++; |
| 2018 |
if (szProp == 0) { |
| 2019 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: error: 0 == szProp at file offset 0x%lx\n", static_cast<unsigned long int>(input->tell()-1))); |
| 2020 |
return false; |
| 2021 |
} |
| 2022 |
long endPos = pos+szProp; |
| 2023 |
if (endPos > endPage) { |
| 2024 |
MWAW_DEBUG_MSG(("MsWks4Text::readFDP: error: cch = %d, too large\n", szProp)); |
| 2025 |
return false; |
| 2026 |
} |
| 2027 |
|
| 2028 |
ascFile.addPos(endPos); |
| 2029 |
ascFile.addPos(pos); |
| 2030 |
int id=0; |
| 2031 |
std::string mess; |
| 2032 |
if (parser &&(this->*parser)(input, endPos, id, mess)) { |
| 2033 |
(*fods_iter).m_id = mapPtr[pos] = id; |
| 2034 |
|
| 2035 |
f.str(""); |
| 2036 |
f << entry.type() << std::dec << id <<":" << mess; |
| 2037 |
ascFile.addNote(f.str().c_str()); |
| 2038 |
pos = input->tell(); |
| 2039 |
} |
| 2040 |
|
| 2041 |
if (pos != endPos) { |
| 2042 |
ascFile.addPos(pos); |
| 2043 |
f.str(""); |
| 2044 |
f << entry.type() << "###"; |
| 2045 |
} |
| 2046 |
} |
| 2047 |
|
| 2048 |
/* go to end of page */ |
| 2049 |
input->seek(endPage, librevenge::RVNG_SEEK_SET); |
| 2050 |
|
| 2051 |
return m_textPositions.end() > lastReadPos; |
| 2052 |
} |
| 2053 |
|
| 2054 |
std::vector<MsWks4Text::DataFOD> MsWks4Text::mergeSortedLists |
| 2055 |
(std::vector<MsWks4Text::DataFOD> const &lst1, |
| 2056 |
std::vector<MsWks4Text::DataFOD> const &lst2) const |
| 2057 |
{ |
| 2058 |
std::vector<MsWks4Text::DataFOD> res; |
| 2059 |
// we regroup these two lists in one list |
| 2060 |
size_t num1 = lst1.size(), i1 = 0; |
| 2061 |
size_t num2 = lst2.size(), i2 = 0; |
| 2062 |
|
| 2063 |
while (i1 < num1 || i2 < num2) { |
| 2064 |
DataFOD val; |
| 2065 |
if (i2 == num2) val = lst1[i1++]; |
| 2066 |
else if (i1 == num1 || lst2[i2].m_pos < lst1[i1].m_pos) |
| 2067 |
val = lst2[i2++]; |
| 2068 |
else val = lst1[i1++]; |
| 2069 |
|
| 2070 |
if (val.m_pos < m_textPositions.begin() || val.m_pos > m_textPositions.end()) |
| 2071 |
continue; |
| 2072 |
|
| 2073 |
res.push_back(val); |
| 2074 |
} |
| 2075 |
return res; |
| 2076 |
} |
| 2077 |
|
| 2078 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |