| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#include <iomanip> |
| 35 |
#include <iostream> |
| 36 |
#include <limits> |
| 37 |
#include <map> |
| 38 |
#include <sstream> |
| 39 |
#include <string> |
| 40 |
|
| 41 |
#include <librevenge/librevenge.h> |
| 42 |
|
| 43 |
#include "MWAWCell.hxx" |
| 44 |
#include "MWAWTextListener.hxx" |
| 45 |
#include "MWAWFont.hxx" |
| 46 |
#include "MWAWFontConverter.hxx" |
| 47 |
#include "MWAWHeader.hxx" |
| 48 |
#include "MWAWList.hxx" |
| 49 |
#include "MWAWParagraph.hxx" |
| 50 |
#include "MWAWPosition.hxx" |
| 51 |
#include "MWAWPictMac.hxx" |
| 52 |
#include "MWAWPrinter.hxx" |
| 53 |
#include "MWAWRSRCParser.hxx" |
| 54 |
#include "MWAWSubDocument.hxx" |
| 55 |
|
| 56 |
#include "MindWrtParser.hxx" |
| 57 |
|
| 58 |
/** Internal: the structures of a MindWrtParser */ |
| 59 |
namespace MindWrtParserInternal |
| 60 |
{ |
| 61 |
//////////////////////////////////////// |
| 62 |
//! Internal: a field of a MindWrtParser |
| 63 |
struct Field { |
| 64 |
//! constructor |
| 65 |
explicit Field(MWAWField::Type type=MWAWField::None) |
| 66 |
: m_type(type) |
| 67 |
, m_pos(0,-1) |
| 68 |
, m_extra("") |
| 69 |
{ |
| 70 |
} |
| 71 |
//! return true is the field is defined |
| 72 |
bool ok() const |
| 73 |
{ |
| 74 |
return m_type!=MWAWField::None && m_pos[1] > 0; |
| 75 |
} |
| 76 |
MWAWField getField() const |
| 77 |
{ |
| 78 |
MWAWField res(m_type); |
| 79 |
if (m_type==MWAWField::Date) |
| 80 |
res.m_DTFormat="%B %d, %Y"; |
| 81 |
else if (m_type==MWAWField::Time) |
| 82 |
res.m_DTFormat="%H:%M"; |
| 83 |
return res; |
| 84 |
} |
| 85 |
//! operator<< |
| 86 |
friend std::ostream &operator<<(std::ostream &o, Field const &field) |
| 87 |
{ |
| 88 |
if (!field.ok()) { |
| 89 |
o << "undef,"; |
| 90 |
return o; |
| 91 |
} |
| 92 |
switch (field.m_type) { |
| 93 |
case MWAWField::Date: |
| 94 |
o << "date,"; |
| 95 |
break; |
| 96 |
case MWAWField::Time: |
| 97 |
o << "time,"; |
| 98 |
break; |
| 99 |
case MWAWField::PageNumber: |
| 100 |
o << "pagenumber,"; |
| 101 |
break; |
| 102 |
case MWAWField::Title: |
| 103 |
o << "title,"; |
| 104 |
break; |
| 105 |
case MWAWField::None: |
| 106 |
case MWAWField::BookmarkStart: |
| 107 |
case MWAWField::BookmarkEnd: |
| 108 |
case MWAWField::PageCount: |
| 109 |
case MWAWField::Database: |
| 110 |
#if !defined(__clang__) |
| 111 |
default: |
| 112 |
#endif |
| 113 |
MWAW_DEBUG_MSG(("MindWrtParserInternal::Field: unexpected field type %d\n", int(field.m_type))); |
| 114 |
break; |
| 115 |
} |
| 116 |
o << "line=" << field.m_pos[1] << ", x=" << field.m_pos[0] << ","; |
| 117 |
o << field.m_extra; |
| 118 |
return o; |
| 119 |
} |
| 120 |
//! the field type |
| 121 |
MWAWField::Type m_type; |
| 122 |
//! the field position: x position in point, y position in line (-1: means no field ) |
| 123 |
MWAWVec2i m_pos; |
| 124 |
//! extra data |
| 125 |
std::string m_extra; |
| 126 |
}; |
| 127 |
|
| 128 |
//////////////////////////////////////// |
| 129 |
//! Internal: the list properties of a MindWrtParser |
| 130 |
struct ListProperties { |
| 131 |
//! constructor |
| 132 |
ListProperties() |
| 133 |
: m_startListIndex(1) |
| 134 |
, m_headingStyle(1) |
| 135 |
, m_headingFullSubLevels(true) |
| 136 |
, m_headingListLevels() |
| 137 |
, m_listLevelsRepeatPos(1) |
| 138 |
, m_showFirstLevel(false) |
| 139 |
, m_useHeadingStyle(false) |
| 140 |
{ |
| 141 |
} |
| 142 |
//! updates the heading list |
| 143 |
void updateHeadingList(); |
| 144 |
//! returns a list level |
| 145 |
MWAWListLevel getLevel(int level) const; |
| 146 |
//! the first list index |
| 147 |
int m_startListIndex; |
| 148 |
//! the heading labels style |
| 149 |
int m_headingStyle; |
| 150 |
//! true if heading labels show all sub level |
| 151 |
bool m_headingFullSubLevels; |
| 152 |
//! the heading list |
| 153 |
std::vector<MWAWListLevel> m_headingListLevels; |
| 154 |
//! the position used to repeat level |
| 155 |
int m_listLevelsRepeatPos; |
| 156 |
//! true if we show the level 1 label |
| 157 |
bool m_showFirstLevel; |
| 158 |
//! true if we need to use heading style |
| 159 |
bool m_useHeadingStyle; |
| 160 |
}; |
| 161 |
|
| 162 |
MWAWListLevel ListProperties::getLevel(int level) const |
| 163 |
{ |
| 164 |
auto numLevels=int(m_headingListLevels.size()); |
| 165 |
if (level < 0 || numLevels <= 0) { |
| 166 |
MWAW_DEBUG_MSG(("ListProperties::updateHeadingList: can not find any level\n")); |
| 167 |
return MWAWListLevel(); |
| 168 |
} |
| 169 |
|
| 170 |
MWAWListLevel res; |
| 171 |
int numSubLevels = 0; |
| 172 |
if (m_headingFullSubLevels) { |
| 173 |
numSubLevels = level; |
| 174 |
if (!m_showFirstLevel) |
| 175 |
numSubLevels--; |
| 176 |
} |
| 177 |
if (level < numLevels) |
| 178 |
res=m_headingListLevels[size_t(level)]; |
| 179 |
else { |
| 180 |
int firstRepeatLevel=m_headingFullSubLevels-1; |
| 181 |
int numLevelsRepeat=numLevels-firstRepeatLevel; |
| 182 |
if (numLevelsRepeat <= 0) { |
| 183 |
numLevelsRepeat = numLevels; |
| 184 |
firstRepeatLevel = 0; |
| 185 |
} |
| 186 |
level = firstRepeatLevel+((level-firstRepeatLevel)%numLevelsRepeat); |
| 187 |
res=m_headingListLevels[size_t(level)]; |
| 188 |
} |
| 189 |
if (numSubLevels>0) |
| 190 |
res.m_numBeforeLabels=numSubLevels; |
| 191 |
return res; |
| 192 |
} |
| 193 |
|
| 194 |
void ListProperties::updateHeadingList() |
| 195 |
{ |
| 196 |
if (m_headingStyle==4) { |
| 197 |
if (!m_headingListLevels.size()) { |
| 198 |
MWAW_DEBUG_MSG(("ListProperties::updateHeadingList: can not find custom list\n")); |
| 199 |
} |
| 200 |
return; |
| 201 |
} |
| 202 |
m_headingListLevels.resize(0); |
| 203 |
if (m_headingStyle < 1 || m_headingStyle > 4) { |
| 204 |
MWAW_DEBUG_MSG(("ListProperties::updateHeadingList: unknown style %d\n", m_headingStyle)); |
| 205 |
return; |
| 206 |
} |
| 207 |
MWAWListLevel level; |
| 208 |
if (m_headingStyle==1) { // I. A. 1. a) i) |
| 209 |
m_listLevelsRepeatPos = 3; |
| 210 |
level.m_suffix = "."; |
| 211 |
level.m_type=MWAWListLevel::UPPER_ROMAN; |
| 212 |
m_headingListLevels.push_back(level); |
| 213 |
level.m_type=MWAWListLevel::UPPER_ALPHA; |
| 214 |
m_headingListLevels.push_back(level); |
| 215 |
level.m_type=MWAWListLevel::DECIMAL; |
| 216 |
m_headingListLevels.push_back(level); |
| 217 |
level.m_suffix = ")"; |
| 218 |
level.m_type=MWAWListLevel::LOWER_ALPHA; |
| 219 |
m_headingListLevels.push_back(level); |
| 220 |
level.m_type=MWAWListLevel::LOWER_ROMAN; |
| 221 |
m_headingListLevels.push_back(level); |
| 222 |
} |
| 223 |
else if (m_headingStyle==2) { // I. A. 1. a) (1), (a), i) |
| 224 |
m_listLevelsRepeatPos = 4; |
| 225 |
level.m_suffix = "."; |
| 226 |
level.m_type=MWAWListLevel::UPPER_ROMAN; |
| 227 |
m_headingListLevels.push_back(level); |
| 228 |
level.m_type=MWAWListLevel::UPPER_ALPHA; |
| 229 |
m_headingListLevels.push_back(level); |
| 230 |
level.m_type=MWAWListLevel::DECIMAL; |
| 231 |
m_headingListLevels.push_back(level); |
| 232 |
level.m_suffix = ")"; |
| 233 |
level.m_type=MWAWListLevel::LOWER_ALPHA; |
| 234 |
m_headingListLevels.push_back(level); |
| 235 |
level.m_prefix = "("; |
| 236 |
level.m_type=MWAWListLevel::DECIMAL; |
| 237 |
m_headingListLevels.push_back(level); |
| 238 |
level.m_type=MWAWListLevel::LOWER_ALPHA; |
| 239 |
m_headingListLevels.push_back(level); |
| 240 |
level.m_prefix = ""; |
| 241 |
level.m_type=MWAWListLevel::LOWER_ROMAN; |
| 242 |
m_headingListLevels.push_back(level); |
| 243 |
} |
| 244 |
else { |
| 245 |
m_listLevelsRepeatPos = 2; |
| 246 |
level.m_suffix = "."; |
| 247 |
level.m_type=MWAWListLevel::DECIMAL; |
| 248 |
m_headingListLevels.push_back(level); |
| 249 |
level.m_suffix = "."; |
| 250 |
level.m_type=MWAWListLevel::DECIMAL; |
| 251 |
m_headingListLevels.push_back(level); |
| 252 |
} |
| 253 |
} |
| 254 |
//////////////////////////////////////// |
| 255 |
//! Internal: a line information of a MindWrtParser |
| 256 |
struct LineInfo { |
| 257 |
LineInfo() |
| 258 |
: m_entry() |
| 259 |
, m_type(-1000) |
| 260 |
, m_height(0) |
| 261 |
, m_y(-1) |
| 262 |
, m_page(-1) |
| 263 |
, m_paragraph() |
| 264 |
, m_specialHeadingInterface(false) |
| 265 |
, m_paragraphSet(false) |
| 266 |
, m_listLevel(0) |
| 267 |
, m_listType(0) |
| 268 |
, m_extra("") |
| 269 |
{ |
| 270 |
for (auto &fl : m_flags) fl=0; |
| 271 |
} |
| 272 |
|
| 273 |
//! operator<< |
| 274 |
friend std::ostream &operator<<(std::ostream &o, LineInfo const &line) |
| 275 |
{ |
| 276 |
if (line.m_entry.valid()) |
| 277 |
o << "textPos=" << std::hex << line.m_entry.begin() |
| 278 |
<< "<->" << line.m_entry.end() << std::dec << ","; |
| 279 |
switch (line.m_type) { |
| 280 |
case -1000: |
| 281 |
break; |
| 282 |
case 0: |
| 283 |
o << "text,"; |
| 284 |
break; |
| 285 |
case -1: |
| 286 |
o << "graphic,"; |
| 287 |
break; |
| 288 |
case -2: |
| 289 |
o << "newpage,"; |
| 290 |
break; |
| 291 |
// find also -3 will no data ( nop ? ) |
| 292 |
default: |
| 293 |
o << "#type=" << line.m_type << ","; |
| 294 |
break; |
| 295 |
} |
| 296 |
if (line.m_height>0) o << "h=" << line.m_height << ","; |
| 297 |
if (line.m_y>=0) o << "y=" << line.m_y << ","; |
| 298 |
if (line.m_page>0) o << "page?=" << line.m_page << ","; |
| 299 |
if (line.m_flags[1] & 0x40) { |
| 300 |
switch (line.m_flags[1]&0x3) { |
| 301 |
case 0: |
| 302 |
o << "left,"; |
| 303 |
break; |
| 304 |
case 1: |
| 305 |
o << "center,"; |
| 306 |
break; |
| 307 |
case 2: |
| 308 |
o << "right,"; |
| 309 |
break; |
| 310 |
case 3: |
| 311 |
o << "full,"; |
| 312 |
break; |
| 313 |
default: |
| 314 |
break; |
| 315 |
} |
| 316 |
} |
| 317 |
if (line.m_flags[1] & 0x4) o << "interline[normal],"; |
| 318 |
if (line.m_flags[1] & 0x8) |
| 319 |
o << "compressed,"; |
| 320 |
o << "list=" << "["; |
| 321 |
if (line.m_listLevel) |
| 322 |
o << "levl=" << line.m_listLevel << ","; |
| 323 |
switch (line.m_listType) { |
| 324 |
case 0: |
| 325 |
o << "Head,"; |
| 326 |
break; // Heading |
| 327 |
case 1: |
| 328 |
o << "Unl,"; |
| 329 |
break; // unlabelled |
| 330 |
case 2: |
| 331 |
o << "Num,"; |
| 332 |
break; // numbered |
| 333 |
case 3: |
| 334 |
o << "Bul,"; |
| 335 |
break; // bullet |
| 336 |
default: |
| 337 |
o << "#type=" << line.m_listType << ","; |
| 338 |
} |
| 339 |
o << "],"; |
| 340 |
if (line.m_flags[0]) |
| 341 |
o << "fl0=" << std::hex << line.m_flags[0] << std::dec << ","; |
| 342 |
if (line.m_flags[1] & 0xb0) { |
| 343 |
if (line.m_flags[1] & 0x90) o << "#"; |
| 344 |
o << "fl1=" << std::hex << (line.m_flags[1]& 0xb0) << std::dec << ","; |
| 345 |
} |
| 346 |
for (int i = 2; i < 4; i++) { // [067a][1-4], [0-4] |
| 347 |
if (!line.m_flags[i]) |
| 348 |
continue; |
| 349 |
o << "fl" << i << "=" << std::hex << line.m_flags[i] << std::dec << ","; |
| 350 |
} |
| 351 |
if (line.m_extra.length()) o << line.m_extra << ","; |
| 352 |
return o; |
| 353 |
} |
| 354 |
|
| 355 |
//! the main entry |
| 356 |
MWAWEntry m_entry; |
| 357 |
//! the entry type |
| 358 |
int m_type; |
| 359 |
//! the height |
| 360 |
int m_height; |
| 361 |
//! the y pos |
| 362 |
int m_y; |
| 363 |
//! the page number |
| 364 |
int m_page; |
| 365 |
//! the paragraph |
| 366 |
MWAWParagraph m_paragraph; |
| 367 |
//! true if the paragraph |
| 368 |
bool m_specialHeadingInterface; |
| 369 |
//! true if the paragraph is reset |
| 370 |
bool m_paragraphSet; |
| 371 |
//! the item level |
| 372 |
int m_listLevel; |
| 373 |
//! the item type |
| 374 |
int m_listType; |
| 375 |
//! two flags |
| 376 |
int m_flags[4]; |
| 377 |
//! extra data |
| 378 |
std::string m_extra; |
| 379 |
}; |
| 380 |
|
| 381 |
//////////////////////////////////////// |
| 382 |
//! Internal: a zone information of a MindWrtParser |
| 383 |
struct ZoneInfo { |
| 384 |
ZoneInfo() |
| 385 |
: m_linesList() |
| 386 |
{ |
| 387 |
} |
| 388 |
|
| 389 |
//! update the line list id |
| 390 |
void updateListId(ListProperties const &prop, MWAWListManager &listManager); |
| 391 |
|
| 392 |
//! the list of line information |
| 393 |
std::vector<LineInfo> m_linesList; |
| 394 |
}; |
| 395 |
|
| 396 |
void ZoneInfo::updateListId(ListProperties const &prop, MWAWListManager &listManager) |
| 397 |
{ |
| 398 |
bool headingStyle=prop.m_useHeadingStyle && prop.m_headingStyle>=1 && prop.m_headingStyle<=4; |
| 399 |
|
| 400 |
/* we have 4 list, we are almost independent: heading, unlabelled, decimal, bullet */ |
| 401 |
MWAWListLevel levelsList[4]; |
| 402 |
levelsList[0].m_type = levelsList[1].m_type = MWAWListLevel::NONE; |
| 403 |
levelsList[2].m_type = MWAWListLevel::DECIMAL; |
| 404 |
levelsList[3].m_type = MWAWListLevel::BULLET; |
| 405 |
libmwaw::appendUnicode(0x2022, levelsList[3].m_bullet); |
| 406 |
|
| 407 |
std::shared_ptr<MWAWList> listsList[4]; |
| 408 |
int maxLevelSet=0; |
| 409 |
|
| 410 |
for (auto &line : m_linesList) { |
| 411 |
if (line.m_height == 0 || // ruler or false graphic |
| 412 |
(line.m_type==-1 && line.m_entry.length()==0)) continue; |
| 413 |
MWAWParagraph ¶ = line.m_paragraph; |
| 414 |
if (line.m_flags[1] & 0x40) { |
| 415 |
switch (line.m_flags[1]&0x3) { |
| 416 |
case 0: |
| 417 |
para.m_justify = MWAWParagraph::JustificationLeft; |
| 418 |
break; |
| 419 |
case 1: |
| 420 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 421 |
break; |
| 422 |
case 2: |
| 423 |
para.m_justify = MWAWParagraph::JustificationRight; |
| 424 |
break; |
| 425 |
case 3: |
| 426 |
para.m_justify = MWAWParagraph::JustificationFull; |
| 427 |
break; |
| 428 |
default: |
| 429 |
break; |
| 430 |
} |
| 431 |
} |
| 432 |
int level = line.m_listLevel+(prop.m_showFirstLevel ? 1 : 0); |
| 433 |
if (level < 0) |
| 434 |
level = 0; |
| 435 |
para.m_listLevelIndex=level; |
| 436 |
if (!level || line.m_listType<0 || line.m_listType > 3) continue; |
| 437 |
|
| 438 |
// create/update the different lists level |
| 439 |
for (int type=0; type < 4; type++) { |
| 440 |
int numLevels = listsList[type] ? listsList[type]->numLevels() : 0; |
| 441 |
int firstL = numLevels+1; |
| 442 |
if (firstL>level && type==line.m_listType) firstL=level; |
| 443 |
for (int l=firstL ; l <= level; l++) { |
| 444 |
bool onlyUpdate = numLevels >= l; |
| 445 |
if (onlyUpdate && type != line.m_listType) continue; |
| 446 |
MWAWListLevel newLevel = (type==0 && headingStyle) ? prop.getLevel(l-1) : levelsList[type]; |
| 447 |
if (!onlyUpdate && newLevel.isNumeric()) |
| 448 |
newLevel.m_startValue=l==1 ? prop.m_startListIndex : 1; |
| 449 |
|
| 450 |
if (line.m_specialHeadingInterface && type==0) { |
| 451 |
newLevel.m_labelWidth=0.2; |
| 452 |
newLevel.m_labelBeforeSpace=0.2*l; |
| 453 |
} |
| 454 |
else { |
| 455 |
newLevel.m_labelWidth=0.2; |
| 456 |
newLevel.m_labelBeforeSpace=0.2*(l-1); |
| 457 |
newLevel.m_labelAfterSpace=*(para.m_margins[0])/72.; |
| 458 |
} |
| 459 |
listsList[type]=listManager.getNewList(listsList[type], l, newLevel); |
| 460 |
} |
| 461 |
} |
| 462 |
if (maxLevelSet < level) maxLevelSet=level; |
| 463 |
|
| 464 |
// update the margins, ... |
| 465 |
if (line.m_specialHeadingInterface && line.m_listType==0) |
| 466 |
// checkme: true on some file but in other files, the display does not change:-~ |
| 467 |
*(para.m_margins[0])= *(para.m_margins[1]) = 0; |
| 468 |
else |
| 469 |
*(para.m_margins[0])=-0.2; |
| 470 |
|
| 471 |
auto const &actList=listsList[line.m_listType]; |
| 472 |
if (!actList) // we have a pb.... |
| 473 |
continue; |
| 474 |
for (auto const &type : listsList) |
| 475 |
if (type) type->setLevel(level); |
| 476 |
if (line.m_listType==0) |
| 477 |
listsList[2]->setStartValueForNextElement(level==1 ? prop.m_startListIndex : 1); |
| 478 |
|
| 479 |
line.m_paragraph.m_listId=actList->getId(); |
| 480 |
para.m_listStartValue = actList->getStartValueForNextElement(); |
| 481 |
actList->openElement(); |
| 482 |
actList->closeElement(); |
| 483 |
} |
| 484 |
} |
| 485 |
|
| 486 |
//////////////////////////////////////// |
| 487 |
//! Internal: the state of a MindWrtParser |
| 488 |
struct State { |
| 489 |
//! constructor |
| 490 |
State() |
| 491 |
: m_compressCorr(" etnroaisdlhcfp") |
| 492 |
, m_entryMap() |
| 493 |
, m_listProperties() |
| 494 |
, m_actPage(0) |
| 495 |
, m_numPages(0) |
| 496 |
, m_headerFieldList() |
| 497 |
, m_footerFieldList() |
| 498 |
{ |
| 499 |
for (auto &num : m_numLinesByZone) num = 0; |
| 500 |
} |
| 501 |
|
| 502 |
//! the correspondance between int compressed and char : must be 15 character |
| 503 |
std::string m_compressCorr; |
| 504 |
|
| 505 |
//! the number of paragraph by zones ( main, header, footer ) |
| 506 |
int m_numLinesByZone[3]; |
| 507 |
//! the zones |
| 508 |
ZoneInfo m_zones[3]; |
| 509 |
|
| 510 |
//! the zones map |
| 511 |
std::multimap<std::string, MWAWEntry> m_entryMap; |
| 512 |
|
| 513 |
//! the list properties |
| 514 |
ListProperties m_listProperties; |
| 515 |
int m_actPage /** the actual page */, m_numPages /** the number of page of the final document */; |
| 516 |
//! the actual list id |
| 517 |
//! the header field list |
| 518 |
std::vector<Field> m_headerFieldList; |
| 519 |
//! the footer field list |
| 520 |
std::vector<Field> m_footerFieldList; |
| 521 |
}; |
| 522 |
|
| 523 |
//////////////////////////////////////// |
| 524 |
//! Internal: the subdocument of a MindWrtParser |
| 525 |
class SubDocument final : public MWAWSubDocument |
| 526 |
{ |
| 527 |
public: |
| 528 |
SubDocument(MindWrtParser &pars, MWAWInputStreamPtr const &input, int zoneId, int step) |
| 529 |
: MWAWSubDocument(&pars, input, MWAWEntry()) |
| 530 |
, m_id(zoneId) |
| 531 |
, m_step(step) |
| 532 |
{ |
| 533 |
} |
| 534 |
|
| 535 |
//! destructor |
| 536 |
~SubDocument() final {} |
| 537 |
|
| 538 |
//! operator!= |
| 539 |
bool operator!=(MWAWSubDocument const &doc) const final |
| 540 |
{ |
| 541 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 542 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 543 |
if (!sDoc) return true; |
| 544 |
if (m_id != sDoc->m_id) return true; |
| 545 |
if (m_step != sDoc->m_step) return true; |
| 546 |
return false; |
| 547 |
} |
| 548 |
|
| 549 |
//! the parser function |
| 550 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 551 |
|
| 552 |
protected: |
| 553 |
//! the subdocument id |
| 554 |
int m_id; |
| 555 |
//! the current step: 0 mean send header, 1 mean send header fields |
| 556 |
int m_step; |
| 557 |
}; |
| 558 |
|
| 559 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/) |
| 560 |
{ |
| 561 |
if (!listener.get()) { |
| 562 |
MWAW_DEBUG_MSG(("MindWrtParserInternal::SubDocument::parse: no listener\n")); |
| 563 |
return; |
| 564 |
} |
| 565 |
if (m_id != 1 && m_id != 2) { |
| 566 |
MWAW_DEBUG_MSG(("MindWrtParserInternal::SubDocument::parse: unknown zone\n")); |
| 567 |
return; |
| 568 |
} |
| 569 |
if (m_step < 0 || m_step > 1) { |
| 570 |
MWAW_DEBUG_MSG(("MindWrtParserInternal::SubDocument::parse: unknown step\n")); |
| 571 |
return; |
| 572 |
} |
| 573 |
auto *parser=dynamic_cast<MindWrtParser *>(m_parser); |
| 574 |
if (!parser) { |
| 575 |
MWAW_DEBUG_MSG(("MindWrtParserInternal::SubDocument::parse: no parser\n")); |
| 576 |
return; |
| 577 |
} |
| 578 |
long pos = m_input->tell(); |
| 579 |
if (m_step==0) |
| 580 |
parser->sendHeaderFooter(m_id==1); |
| 581 |
else |
| 582 |
parser->sendHeaderFooterFields(m_id==1); |
| 583 |
m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
//////////////////////////////////////////////////////////// |
| 588 |
// constructor/destructor, ... |
| 589 |
//////////////////////////////////////////////////////////// |
| 590 |
MindWrtParser::MindWrtParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 591 |
: MWAWTextParser(input, rsrcParser, header) |
| 592 |
, m_state() |
| 593 |
{ |
| 594 |
init(); |
| 595 |
} |
| 596 |
|
| 597 |
MindWrtParser::~MindWrtParser() |
| 598 |
{ |
| 599 |
} |
| 600 |
|
| 601 |
void MindWrtParser::init() |
| 602 |
{ |
| 603 |
resetTextListener(); |
| 604 |
setAsciiName("main-1"); |
| 605 |
|
| 606 |
m_state.reset(new MindWrtParserInternal::State); |
| 607 |
|
| 608 |
// reduce the margin (in case, the page is not defined) |
| 609 |
getPageSpan().setMargins(0.1); |
| 610 |
} |
| 611 |
|
| 612 |
//////////////////////////////////////////////////////////// |
| 613 |
// new page |
| 614 |
//////////////////////////////////////////////////////////// |
| 615 |
void MindWrtParser::newPage(int number) |
| 616 |
{ |
| 617 |
if (number <= m_state->m_actPage || number > m_state->m_numPages) |
| 618 |
return; |
| 619 |
|
| 620 |
while (m_state->m_actPage < number) { |
| 621 |
m_state->m_actPage++; |
| 622 |
if (!getTextListener() || m_state->m_actPage == 1) |
| 623 |
continue; |
| 624 |
getTextListener()->insertBreak(MWAWTextListener::PageBreak); |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
MWAWEntry MindWrtParser::readEntry() |
| 629 |
{ |
| 630 |
MWAWEntry res; |
| 631 |
MWAWInputStreamPtr input = getInput(); |
| 632 |
res.setBegin(long(input->readULong(4))); |
| 633 |
res.setLength(long(input->readULong(4))); |
| 634 |
if (res.length() && !input->checkPosition(res.end())) { |
| 635 |
MWAW_DEBUG_MSG(("MindWrtParser::readEntry: find an invalid entry\n")); |
| 636 |
res.setLength(0); |
| 637 |
} |
| 638 |
return res; |
| 639 |
} |
| 640 |
//////////////////////////////////////////////////////////// |
| 641 |
// the parser |
| 642 |
//////////////////////////////////////////////////////////// |
| 643 |
void MindWrtParser::parse(librevenge::RVNGTextInterface *docInterface) |
| 644 |
{ |
| 645 |
if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException()); |
| 646 |
bool ok = true; |
| 647 |
try { |
| 648 |
// create the asciiFile |
| 649 |
ascii().setStream(getInput()); |
| 650 |
ascii().open(asciiName()); |
| 651 |
|
| 652 |
checkHeader(nullptr); |
| 653 |
if (getRSRCParser()) { |
| 654 |
MWAWEntry corrEntry = getRSRCParser()->getEntry("STR ", 700); |
| 655 |
std::string corrString(""); |
| 656 |
if (corrEntry.valid() && getRSRCParser()->parseSTR(corrEntry, corrString)) { |
| 657 |
if (corrString.length() != 15) { |
| 658 |
MWAW_DEBUG_MSG(("MindWrtParser::parse: resource correspondance string seems bad\n")); |
| 659 |
} |
| 660 |
else |
| 661 |
m_state->m_compressCorr = corrString; |
| 662 |
} |
| 663 |
} |
| 664 |
ok = createZones(); |
| 665 |
if (ok) { |
| 666 |
createDocument(docInterface); |
| 667 |
sendZone(0); |
| 668 |
} |
| 669 |
|
| 670 |
libmwaw::DebugStream f; |
| 671 |
for (auto const &it : m_state->m_entryMap) { |
| 672 |
MWAWEntry const &entry = it.second; |
| 673 |
if (entry.isParsed()) |
| 674 |
continue; |
| 675 |
f.str(""); |
| 676 |
f << entry; |
| 677 |
ascii().addPos(entry.begin()); |
| 678 |
ascii().addNote(f.str().c_str()); |
| 679 |
ascii().addPos(entry.end()); |
| 680 |
ascii().addNote("_"); |
| 681 |
} |
| 682 |
ascii().reset(); |
| 683 |
} |
| 684 |
catch (...) { |
| 685 |
MWAW_DEBUG_MSG(("MindWrtParser::parse: exception catched when parsing\n")); |
| 686 |
ok = false; |
| 687 |
} |
| 688 |
|
| 689 |
resetTextListener(); |
| 690 |
if (!ok) throw(libmwaw::ParseException()); |
| 691 |
} |
| 692 |
|
| 693 |
//////////////////////////////////////////////////////////// |
| 694 |
// create the document |
| 695 |
//////////////////////////////////////////////////////////// |
| 696 |
void MindWrtParser::createDocument(librevenge::RVNGTextInterface *documentInterface) |
| 697 |
{ |
| 698 |
if (!documentInterface) return; |
| 699 |
if (getTextListener()) { |
| 700 |
MWAW_DEBUG_MSG(("MindWrtParser::createDocument: listener already exist\n")); |
| 701 |
return; |
| 702 |
} |
| 703 |
|
| 704 |
// update the page |
| 705 |
m_state->m_actPage = 0; |
| 706 |
|
| 707 |
int numPage = 0, numBreakPage = 0; |
| 708 |
for (auto const &line : m_state->m_zones[0].m_linesList) { |
| 709 |
if (line.m_type == -2) |
| 710 |
numBreakPage++; |
| 711 |
if (line.m_page > numPage) |
| 712 |
numPage = line.m_page; |
| 713 |
} |
| 714 |
if (numBreakPage > numPage) numPage = numBreakPage; |
| 715 |
m_state->m_numPages = numPage+1; |
| 716 |
|
| 717 |
// create the page list |
| 718 |
MWAWPageSpan ps(getPageSpan()); |
| 719 |
for (int i = 1; i <= 2; i++) { |
| 720 |
if (m_state->m_zones[i].m_linesList.empty()) |
| 721 |
continue; |
| 722 |
MWAWHeaderFooter hF((i==1) ? MWAWHeaderFooter::HEADER : MWAWHeaderFooter::FOOTER, MWAWHeaderFooter::ALL); |
| 723 |
hF.m_subDocument.reset(new MindWrtParserInternal::SubDocument(*this, getInput(), i, 0)); |
| 724 |
ps.setHeaderFooter(hF); |
| 725 |
} |
| 726 |
ps.setPageSpan(m_state->m_numPages+1); |
| 727 |
std::vector<MWAWPageSpan> pageList(1,ps); |
| 728 |
// |
| 729 |
MWAWTextListenerPtr listen(new MWAWTextListener(*getParserState(), pageList, documentInterface)); |
| 730 |
setTextListener(listen); |
| 731 |
listen->startDocument(); |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
//////////////////////////////////////////////////////////// |
| 736 |
// |
| 737 |
// Intermediate level |
| 738 |
// |
| 739 |
//////////////////////////////////////////////////////////// |
| 740 |
bool MindWrtParser::createZones() |
| 741 |
{ |
| 742 |
MWAWInputStreamPtr input = getInput(); |
| 743 |
libmwaw::DebugStream f; |
| 744 |
long pos = input->tell(); |
| 745 |
if (!input->checkPosition(pos+128+56)) { |
| 746 |
MWAW_DEBUG_MSG(("MindWrtParser::createZones: zones Zone is too short\n")); |
| 747 |
return false; |
| 748 |
} |
| 749 |
|
| 750 |
for (int i = 0; i < 16; i++) { |
| 751 |
pos = input->tell(); |
| 752 |
MWAWEntry entry = readEntry(); |
| 753 |
if (!entry.valid()) { |
| 754 |
ascii().addPos(pos); |
| 755 |
ascii().addNote("_"); |
| 756 |
continue; |
| 757 |
} |
| 758 |
switch (i) { |
| 759 |
case 0: |
| 760 |
case 1: |
| 761 |
case 2: |
| 762 |
entry.setType("LineInfo"); |
| 763 |
entry.setId(i); |
| 764 |
break; |
| 765 |
case 6: |
| 766 |
entry.setType("PrintInfo"); |
| 767 |
break; |
| 768 |
case 7: |
| 769 |
entry.setType("LastZone"); |
| 770 |
break; |
| 771 |
case 10: |
| 772 |
entry.setType("HeadState"); |
| 773 |
break; |
| 774 |
case 12: |
| 775 |
entry.setType("HeadField"); |
| 776 |
break; |
| 777 |
case 14: |
| 778 |
entry.setType("HeadProp"); |
| 779 |
break; |
| 780 |
case 15: |
| 781 |
entry.setType("HeadCust"); |
| 782 |
break; |
| 783 |
default: { |
| 784 |
std::stringstream s; |
| 785 |
s << "Zone" << i; |
| 786 |
entry.setType(s.str()); |
| 787 |
break; |
| 788 |
} |
| 789 |
} |
| 790 |
m_state->m_entryMap.insert(std::multimap<std::string,MWAWEntry>::value_type |
| 791 |
(entry.type(), entry)); |
| 792 |
f.str(""); |
| 793 |
f << "Entries(" << entry.type() << "):" << std::hex << entry.begin() << "-" << entry.end() << std::dec << ","; |
| 794 |
ascii().addPos(pos); |
| 795 |
ascii().addNote(f.str().c_str()); |
| 796 |
} |
| 797 |
|
| 798 |
pos = input->tell(); |
| 799 |
f.str(""); |
| 800 |
f << "Entries(ZoneDef):"; |
| 801 |
for (int i = 0; i < 24; i++) { // always 0 ? |
| 802 |
long val = input->readLong(2); |
| 803 |
if (val) f << "f" << i << "=" << val << ","; |
| 804 |
} |
| 805 |
ascii().addPos(pos); |
| 806 |
ascii().addNote(f.str().c_str()); |
| 807 |
|
| 808 |
// first read print info |
| 809 |
auto it = m_state->m_entryMap.find("PrintInfo"); |
| 810 |
if (it != m_state->m_entryMap.end()) |
| 811 |
readPrintInfo(it->second); |
| 812 |
// now the heading properties |
| 813 |
it = m_state->m_entryMap.find("HeadProp"); |
| 814 |
if (it != m_state->m_entryMap.end()) |
| 815 |
readHeadingProperties(it->second); |
| 816 |
it = m_state->m_entryMap.find("HeadState"); |
| 817 |
if (it != m_state->m_entryMap.end()) |
| 818 |
readHeadingStates(it->second); |
| 819 |
it = m_state->m_entryMap.find("HeadCust"); |
| 820 |
if (it != m_state->m_entryMap.end()) |
| 821 |
readHeadingCustom(it->second); |
| 822 |
it = m_state->m_entryMap.find("HeadField"); |
| 823 |
if (it != m_state->m_entryMap.end()) |
| 824 |
readHeadingFields(it->second); |
| 825 |
it = m_state->m_entryMap.find("Zone8"); |
| 826 |
if (it != m_state->m_entryMap.end()) |
| 827 |
readZone8(it->second); |
| 828 |
#ifdef DEBUG |
| 829 |
// some unknown zone |
| 830 |
it = m_state->m_entryMap.find("LastZone"); |
| 831 |
if (it != m_state->m_entryMap.end()) |
| 832 |
readLastZone(it->second); |
| 833 |
#endif |
| 834 |
m_state->m_listProperties.updateHeadingList(); |
| 835 |
// finally, we can read the line info |
| 836 |
it = m_state->m_entryMap.find("LineInfo"); |
| 837 |
while (it != m_state->m_entryMap.end() && it->first == "LineInfo") |
| 838 |
readLinesInfo(it++->second); |
| 839 |
|
| 840 |
for (auto const &info : m_state->m_zones) |
| 841 |
if (info.m_linesList.size()) |
| 842 |
return true; |
| 843 |
return false; |
| 844 |
} |
| 845 |
|
| 846 |
//////////////////////////////////////////////////////////// |
| 847 |
// |
| 848 |
// Low level |
| 849 |
// |
| 850 |
//////////////////////////////////////////////////////////// |
| 851 |
|
| 852 |
//////////////////////////////////////////////////////////// |
| 853 |
// try to send a text zone |
| 854 |
//////////////////////////////////////////////////////////// |
| 855 |
bool MindWrtParser::sendZone(int id) |
| 856 |
{ |
| 857 |
if (id < 0 || id >= 3) { |
| 858 |
MWAW_DEBUG_MSG(("MindWrtParser::sendZone: find unexpected id %d\n", id)); |
| 859 |
return false; |
| 860 |
} |
| 861 |
MWAWTextListenerPtr listener=getTextListener(); |
| 862 |
if (!listener) { |
| 863 |
MWAW_DEBUG_MSG(("MindWrtParser::sendZone: can not find a listener\n")); |
| 864 |
return false; |
| 865 |
} |
| 866 |
|
| 867 |
MWAWParagraph para; |
| 868 |
// FIXME: writerperfect or libreoffice seems to loose page dimensions and header/footer if we begin by a list |
| 869 |
if (id==0) { |
| 870 |
para.setInterline(1,librevenge::RVNG_POINT); |
| 871 |
setProperty(para); |
| 872 |
getTextListener()->insertEOL(); |
| 873 |
} |
| 874 |
else |
| 875 |
setProperty(para); |
| 876 |
|
| 877 |
libmwaw::DebugStream f; |
| 878 |
if (id==0) m_state->m_actPage = 1; |
| 879 |
auto &zone = m_state->m_zones[id]; |
| 880 |
for (size_t i = 0; i < zone.m_linesList.size(); i++) { |
| 881 |
auto &line = zone.m_linesList[i]; |
| 882 |
if (i==0) { |
| 883 |
ascii().addPos(line.m_entry.begin()); |
| 884 |
ascii().addNote("Entries(Text)"); |
| 885 |
} |
| 886 |
if (id==0 && line.m_page+1 > m_state->m_actPage) |
| 887 |
newPage(line.m_page+1); |
| 888 |
bool done=false; |
| 889 |
switch (line.m_type) { |
| 890 |
case 0: |
| 891 |
if (line.m_height) { |
| 892 |
listener->setParagraph(line.m_paragraph); |
| 893 |
if (line.m_flags[1]&8) |
| 894 |
done = readCompressedText(line); |
| 895 |
else |
| 896 |
done = readText(line); |
| 897 |
} |
| 898 |
else if (line.m_paragraphSet) { |
| 899 |
done = true; |
| 900 |
setProperty(line.m_paragraph); |
| 901 |
} |
| 902 |
break; |
| 903 |
case -1: |
| 904 |
if (line.m_entry.length()==0) { |
| 905 |
done = true; |
| 906 |
break; |
| 907 |
} |
| 908 |
listener->setParagraph(line.m_paragraph); |
| 909 |
if (!readGraphic(line)) |
| 910 |
break; |
| 911 |
done = true; |
| 912 |
listener->insertEOL(); |
| 913 |
break; |
| 914 |
case -2: |
| 915 |
if (id!=0) { |
| 916 |
MWAW_DEBUG_MSG(("MindWrtParser::sendZone: find page break on not main zone\n")); |
| 917 |
break; |
| 918 |
} |
| 919 |
newPage(m_state->m_actPage+1); |
| 920 |
done = true; |
| 921 |
break; |
| 922 |
case -3: // a nop ? |
| 923 |
done = true; |
| 924 |
break; |
| 925 |
default: |
| 926 |
break; |
| 927 |
} |
| 928 |
if (done) |
| 929 |
continue; |
| 930 |
f.str(""); |
| 931 |
f << "Text[" << line << "]"; |
| 932 |
ascii().addPos(line.m_entry.begin()); |
| 933 |
ascii().addNote(f.str().c_str()); |
| 934 |
} |
| 935 |
return true; |
| 936 |
} |
| 937 |
|
| 938 |
//////////////////////////////////////////////////////////// |
| 939 |
// read a graphic zone |
| 940 |
//////////////////////////////////////////////////////////// |
| 941 |
bool MindWrtParser::readGraphic(MindWrtParserInternal::LineInfo const &line) |
| 942 |
{ |
| 943 |
if (!line.m_entry.valid()) |
| 944 |
return false; |
| 945 |
|
| 946 |
MWAWInputStreamPtr input = getInput(); |
| 947 |
libmwaw::DebugStream f; |
| 948 |
auto sz = static_cast<int>(line.m_entry.length()); |
| 949 |
if (sz < 10) { |
| 950 |
MWAW_DEBUG_MSG(("MindWrtParser::readGraphic: zone size is two short or odd\n")); |
| 951 |
return false; |
| 952 |
} |
| 953 |
|
| 954 |
long pos=line.m_entry.begin(); |
| 955 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 956 |
|
| 957 |
int dim[4]; |
| 958 |
for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
| 959 |
MWAWBox2f box(MWAWVec2f(static_cast<float>(dim[1]),static_cast<float>(dim[0])), |
| 960 |
MWAWVec2f(static_cast<float>(dim[3]),static_cast<float>(dim[2]))); |
| 961 |
f << "Entries(graphic): bdBox=" << box << ","; |
| 962 |
|
| 963 |
std::shared_ptr<MWAWPict> pict(MWAWPictData::get(input, sz-8)); |
| 964 |
if (!pict) { |
| 965 |
MWAW_DEBUG_MSG(("MindWrtParser::readGraphic: can not read the picture\n")); |
| 966 |
return false; |
| 967 |
} |
| 968 |
MWAWEmbeddedObject picture; |
| 969 |
if (getTextListener() && pict->getBinary(picture)) { |
| 970 |
MWAWPosition pictPos=MWAWPosition(MWAWVec2f(0,0),box.size(), librevenge::RVNG_POINT); |
| 971 |
pictPos.setRelativePosition(MWAWPosition::Char); |
| 972 |
getTextListener()->insertPicture(pictPos,picture); |
| 973 |
} |
| 974 |
ascii().skipZone(pos+8, pos+sz-1); |
| 975 |
ascii().addPos(pos); |
| 976 |
ascii().addNote(f.str().c_str()); |
| 977 |
return true; |
| 978 |
} |
| 979 |
|
| 980 |
//////////////////////////////////////////////////////////// |
| 981 |
// read a ruler zone |
| 982 |
//////////////////////////////////////////////////////////// |
| 983 |
bool MindWrtParser::readRuler(MindWrtParserInternal::LineInfo &line) |
| 984 |
{ |
| 985 |
line.m_paragraph = MWAWParagraph(); |
| 986 |
MWAWInputStreamPtr input = getInput(); |
| 987 |
libmwaw::DebugStream f; |
| 988 |
|
| 989 |
if (line.m_entry.length() < 10 || (line.m_entry.length()%2) || !input->checkPosition(line.m_entry.end())) { |
| 990 |
MWAW_DEBUG_MSG(("MindWrtParser::readRuler: zone size is two short or odd\n")); |
| 991 |
return false; |
| 992 |
} |
| 993 |
line.m_specialHeadingInterface = (line.m_flags[1] & 0x4)==0; |
| 994 |
|
| 995 |
long pos=line.m_entry.begin(); |
| 996 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 997 |
|
| 998 |
MWAWParagraph para; |
| 999 |
para.m_marginsUnit = librevenge::RVNG_POINT; |
| 1000 |
para.m_margins[1] = double(input->readULong(2)); |
| 1001 |
para.m_margins[2] = getPageWidth()*72.0-double(input->readULong(2)); |
| 1002 |
if (*(para.m_margins[2]) < 0) { |
| 1003 |
f << "#rightMargin=" << getPageWidth()*72.0-*(para.m_margins[2]); |
| 1004 |
para.m_margins[2] = 0.0; |
| 1005 |
} |
| 1006 |
auto val = long(input->readULong(1)); |
| 1007 |
switch (val) { |
| 1008 |
case 0: |
| 1009 |
para.m_justify = MWAWParagraph::JustificationLeft; |
| 1010 |
break; |
| 1011 |
case 1: |
| 1012 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 1013 |
break; |
| 1014 |
case 2: |
| 1015 |
para.m_justify = MWAWParagraph::JustificationRight; |
| 1016 |
break; |
| 1017 |
case 3: |
| 1018 |
para.m_justify = MWAWParagraph::JustificationFull; |
| 1019 |
break; |
| 1020 |
default: |
| 1021 |
f << "#align=" << std::hex << val << std::dec << ","; |
| 1022 |
break; |
| 1023 |
} |
| 1024 |
auto N = static_cast<int>(input->readULong(1)); |
| 1025 |
if (line.m_entry.length() != 2*N+10) { |
| 1026 |
MWAW_DEBUG_MSG(("MindWrtParser::readRuler: num tabs is incorrect\n")); |
| 1027 |
line.m_paragraph = para; |
| 1028 |
line.m_paragraphSet = true; |
| 1029 |
return false; |
| 1030 |
} |
| 1031 |
val = long(input->readULong(2)); |
| 1032 |
double factor = 1.0; |
| 1033 |
switch (val & 0x7FFF) { |
| 1034 |
case 0: |
| 1035 |
break; |
| 1036 |
case 1: |
| 1037 |
factor = 1.5; |
| 1038 |
break; |
| 1039 |
case 2: |
| 1040 |
factor = 2.; |
| 1041 |
break; |
| 1042 |
default: |
| 1043 |
if (val) f << "#interline=" << std::hex << (val&0x7FFF) << std::dec << ","; |
| 1044 |
} |
| 1045 |
if (val & 0x8000) { // 6 inches by line + potential before space |
| 1046 |
para.m_spacings[1] = (factor-1.)/6; |
| 1047 |
para.setInterline(12, librevenge::RVNG_POINT); |
| 1048 |
} |
| 1049 |
else |
| 1050 |
para.setInterline(factor, librevenge::RVNG_PERCENT); |
| 1051 |
para.m_margins[0] = double(input->readULong(2))-*(para.m_margins[1]); |
| 1052 |
for (int i = 0; i < N; i++) { |
| 1053 |
MWAWTabStop tab; |
| 1054 |
val = input->readLong(2); |
| 1055 |
if (val > 0) |
| 1056 |
tab.m_position = double(val)/72.; |
| 1057 |
else { |
| 1058 |
tab.m_position = -double(val)/72.; |
| 1059 |
tab.m_alignment = MWAWTabStop::CENTER; |
| 1060 |
} |
| 1061 |
para.m_tabs->push_back(tab); |
| 1062 |
} |
| 1063 |
para.m_extra = f.str(); |
| 1064 |
line.m_paragraph = para; |
| 1065 |
line.m_paragraphSet = true; |
| 1066 |
|
| 1067 |
f.str(""); |
| 1068 |
f << "Text[ruler]:" << para; |
| 1069 |
|
| 1070 |
ascii().addPos(pos); |
| 1071 |
ascii().addNote(f.str().c_str()); |
| 1072 |
return true; |
| 1073 |
} |
| 1074 |
|
| 1075 |
//////////////////////////////////////////////////////////// |
| 1076 |
// send the header data |
| 1077 |
//////////////////////////////////////////////////////////// |
| 1078 |
void MindWrtParser::sendHeaderFooter(bool header) |
| 1079 |
{ |
| 1080 |
MWAWTextListenerPtr listener=getTextListener(); |
| 1081 |
if (!listener) { |
| 1082 |
MWAW_DEBUG_MSG(("MindWrtParser::sendHeaderFooter: can note find the listener\n")); |
| 1083 |
return; |
| 1084 |
} |
| 1085 |
int zId=header ? 1 : 2; |
| 1086 |
auto const &fieldList= header ? m_state->m_headerFieldList : m_state->m_footerFieldList; |
| 1087 |
if (!fieldList.empty()) { |
| 1088 |
/** field are separated from the main text |
| 1089 |
-> we need to use an intermediate frame */ |
| 1090 |
MWAWPosition fPos(MWAWVec2f(0,0), MWAWVec2f(float(getPageWidth()),0), librevenge::RVNG_INCH); |
| 1091 |
fPos.m_anchorTo = MWAWPosition::Paragraph; |
| 1092 |
fPos.m_wrapping = MWAWPosition::WBackground; |
| 1093 |
std::shared_ptr<MindWrtParserInternal::SubDocument> subDoc |
| 1094 |
(new MindWrtParserInternal::SubDocument(*this, getInput(), zId, 1)); |
| 1095 |
listener->insertTextBox(fPos, subDoc); |
| 1096 |
} |
| 1097 |
sendZone(zId); |
| 1098 |
} |
| 1099 |
|
| 1100 |
void MindWrtParser::sendHeaderFooterFields(bool header) |
| 1101 |
{ |
| 1102 |
MWAWTextListenerPtr listener=getTextListener(); |
| 1103 |
if (!listener) { |
| 1104 |
MWAW_DEBUG_MSG(("MindWrtParser::sendHeaderFooterFields: can note find the listener\n")); |
| 1105 |
return; |
| 1106 |
} |
| 1107 |
auto fieldList=header ? m_state->m_headerFieldList : m_state->m_footerFieldList; |
| 1108 |
size_t numFields=fieldList.size(); |
| 1109 |
if (!numFields) { |
| 1110 |
MWAW_DEBUG_MSG(("MindWrtParser::sendHeaderFooterFields: called with empty field list\n")); |
| 1111 |
return; |
| 1112 |
} |
| 1113 |
// sort the field list by position ; at most 4 elements, so... |
| 1114 |
for (size_t i=0; i+1 < numFields; i++) { |
| 1115 |
for (size_t j=i+1; j < numFields; j++) { |
| 1116 |
int diffLine = fieldList[j].m_pos[1]-fieldList[i].m_pos[1]; |
| 1117 |
if (diffLine > 0 || |
| 1118 |
(diffLine==0 && fieldList[j].m_pos[0]>fieldList[i].m_pos[0])) |
| 1119 |
continue; |
| 1120 |
std::swap(fieldList[i], fieldList[j]); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
if (fieldList[numFields-1].m_pos[1]>10) { |
| 1124 |
MWAW_DEBUG_MSG(("MindWrtParser::sendHeaderFooterFields: the line position seems too big\n")); |
| 1125 |
return; |
| 1126 |
} |
| 1127 |
int actLine = 0; |
| 1128 |
MWAWParagraph defPara; |
| 1129 |
defPara.setInterline(16, librevenge::RVNG_POINT); |
| 1130 |
listener->setParagraph(defPara); |
| 1131 |
size_t f=0; |
| 1132 |
while (f < numFields) { |
| 1133 |
while (fieldList[f].m_pos[1]>++actLine) |
| 1134 |
listener->insertEOL(); |
| 1135 |
// first prepare the tabs |
| 1136 |
MWAWParagraph newPara(defPara); |
| 1137 |
int actPos=0; |
| 1138 |
for (size_t f1=f; f1 < numFields; f1++) { |
| 1139 |
if (fieldList[f1].m_pos[1]!=actLine) |
| 1140 |
break; |
| 1141 |
if (fieldList[f1].m_pos[0]==actPos) |
| 1142 |
continue; |
| 1143 |
actPos=fieldList[f1].m_pos[0]; |
| 1144 |
MWAWTabStop tab; |
| 1145 |
tab.m_position = double(actPos)/72.; |
| 1146 |
newPara.m_tabs->push_back(tab); |
| 1147 |
} |
| 1148 |
listener->setParagraph(newPara); |
| 1149 |
|
| 1150 |
actPos=0; |
| 1151 |
while (f < numFields) { |
| 1152 |
if (fieldList[f].m_pos[1]!=actLine) |
| 1153 |
break; |
| 1154 |
if (fieldList[f].m_pos[0]!=actPos) { |
| 1155 |
actPos=fieldList[f].m_pos[0]; |
| 1156 |
listener->insertTab(); |
| 1157 |
} |
| 1158 |
listener->insertField(fieldList[f].getField()); |
| 1159 |
f++; |
| 1160 |
} |
| 1161 |
if (f != numFields) |
| 1162 |
listener->insertEOL(); |
| 1163 |
} |
| 1164 |
} |
| 1165 |
//////////////////////////////////////////////////////////// |
| 1166 |
// read the text zone |
| 1167 |
//////////////////////////////////////////////////////////// |
| 1168 |
bool MindWrtParser::readText(MindWrtParserInternal::LineInfo const &line) |
| 1169 |
{ |
| 1170 |
if (!line.m_entry.valid()) |
| 1171 |
return false; |
| 1172 |
|
| 1173 |
MWAWInputStreamPtr input = getInput(); |
| 1174 |
libmwaw::DebugStream f; |
| 1175 |
|
| 1176 |
long pos=line.m_entry.begin(); |
| 1177 |
long endPos=line.m_entry.end(); |
| 1178 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1179 |
auto num = static_cast<int>(input->readULong(2)); |
| 1180 |
if (pos+num >= endPos) { |
| 1181 |
MWAW_DEBUG_MSG(("MindWrtParser::readText: numChar is too long\n")); |
| 1182 |
return false; |
| 1183 |
} |
| 1184 |
|
| 1185 |
f << "Text:"; |
| 1186 |
if (line.m_listType!=1) { |
| 1187 |
f << "[list=" << line.m_listLevel; |
| 1188 |
switch (line.m_listType) { |
| 1189 |
case 0: |
| 1190 |
f << "Head,"; |
| 1191 |
break; // Heading |
| 1192 |
case 1: |
| 1193 |
f << "Unl,"; |
| 1194 |
break; // unlabelled |
| 1195 |
case 2: |
| 1196 |
f << "Num,"; |
| 1197 |
break; // bullet |
| 1198 |
case 3: |
| 1199 |
f << "Bul,"; |
| 1200 |
break; // paragraph |
| 1201 |
default: |
| 1202 |
f << "[#type=" << line.m_listType << "],"; |
| 1203 |
} |
| 1204 |
f << "],"; |
| 1205 |
} |
| 1206 |
std::string text(""); |
| 1207 |
for (int n = 0; n < num; n++) { |
| 1208 |
auto c = char(input->readULong(1)); |
| 1209 |
if (!c) { |
| 1210 |
MWAW_DEBUG_MSG(("MindWrtParser::readText: find 0 char\n")); |
| 1211 |
continue; |
| 1212 |
} |
| 1213 |
text+=char(c); |
| 1214 |
} |
| 1215 |
f << text; |
| 1216 |
|
| 1217 |
// realign to 2 |
| 1218 |
if (input->tell()&1) |
| 1219 |
input->seek(1,librevenge::RVNG_SEEK_CUR); |
| 1220 |
|
| 1221 |
ascii().addPos(line.m_entry.begin()); |
| 1222 |
ascii().addNote(f.str().c_str()); |
| 1223 |
|
| 1224 |
std::vector<int> textPos; |
| 1225 |
std::vector<MWAWFont> fonts; |
| 1226 |
if (!readFonts(line.m_entry, fonts, textPos)) |
| 1227 |
return false; |
| 1228 |
sendText(text, fonts, textPos); |
| 1229 |
if (input->tell()!=endPos) { |
| 1230 |
ascii().addPos(input->tell()); |
| 1231 |
ascii().addNote("Text(II):#"); |
| 1232 |
} |
| 1233 |
return true; |
| 1234 |
} |
| 1235 |
|
| 1236 |
bool MindWrtParser::readCompressedText(MindWrtParserInternal::LineInfo const &line) |
| 1237 |
{ |
| 1238 |
if (!line.m_entry.valid()) |
| 1239 |
return false; |
| 1240 |
MWAWInputStreamPtr input = getInput(); |
| 1241 |
libmwaw::DebugStream f; |
| 1242 |
|
| 1243 |
long pos=line.m_entry.begin(); |
| 1244 |
long endPos=line.m_entry.end(); |
| 1245 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1246 |
auto num = static_cast<int>(input->readULong(2)); |
| 1247 |
if (pos+num/2 > endPos) { |
| 1248 |
MWAW_DEBUG_MSG(("MindWrtParser::readCompressedText: numChar is too long\n")); |
| 1249 |
return false; |
| 1250 |
} |
| 1251 |
|
| 1252 |
f << "Text:"; |
| 1253 |
if (line.m_listType!=1) { |
| 1254 |
f << "[list=" << line.m_listLevel; |
| 1255 |
switch (line.m_listType) { |
| 1256 |
case 0: |
| 1257 |
f << "Head,"; |
| 1258 |
break; // Heading |
| 1259 |
case 1: |
| 1260 |
f << "Unl,"; |
| 1261 |
break; // unlabelled |
| 1262 |
case 2: |
| 1263 |
f << "Num,"; |
| 1264 |
break; // bullet |
| 1265 |
case 3: |
| 1266 |
f << "Bul,"; |
| 1267 |
break; // paragraph |
| 1268 |
default: |
| 1269 |
f << "[#type=" << line.m_listType << "],"; |
| 1270 |
} |
| 1271 |
f << "],"; |
| 1272 |
} |
| 1273 |
int actualChar = 0; |
| 1274 |
bool actualCharSet = false; |
| 1275 |
std::string text(""); |
| 1276 |
for (int n = 0; n < num; n++) { |
| 1277 |
if (input->tell() >= endPos) { |
| 1278 |
MWAW_DEBUG_MSG(("MindWrtParser::readCompressedText: entry is too short\n")); |
| 1279 |
return false; |
| 1280 |
} |
| 1281 |
int highByte = 0; |
| 1282 |
for (int st = 0; st < 3; st++) { |
| 1283 |
int actVal; |
| 1284 |
if (!actualCharSet) { |
| 1285 |
if (input->isEnd()) { |
| 1286 |
MWAW_DEBUG_MSG(("MindWrtParser::readCompressedText: text is too long\n")); |
| 1287 |
return false; |
| 1288 |
} |
| 1289 |
actualChar = static_cast<int>(input->readULong(1)); |
| 1290 |
actVal = (actualChar >> 4); |
| 1291 |
} |
| 1292 |
else |
| 1293 |
actVal = (actualChar & 0xf); |
| 1294 |
actualCharSet = !actualCharSet; |
| 1295 |
if (st == 0) { |
| 1296 |
if (actVal == 0xf) continue; |
| 1297 |
text += char(m_state->m_compressCorr[size_t(actVal)]); |
| 1298 |
break; |
| 1299 |
} |
| 1300 |
if (st == 1) { // high bytes |
| 1301 |
highByte = (actVal<<4); |
| 1302 |
continue; |
| 1303 |
} |
| 1304 |
if (highByte == 0 && actVal==0) { |
| 1305 |
MWAW_DEBUG_MSG(("rser::readCompressedText: find 0 char\n")); |
| 1306 |
continue; |
| 1307 |
} |
| 1308 |
text += char(highByte | actVal); |
| 1309 |
} |
| 1310 |
} |
| 1311 |
f << text; |
| 1312 |
|
| 1313 |
// realign to 2 |
| 1314 |
if (input->tell()&1) |
| 1315 |
input->seek(1,librevenge::RVNG_SEEK_CUR); |
| 1316 |
|
| 1317 |
ascii().addPos(line.m_entry.begin()); |
| 1318 |
ascii().addNote(f.str().c_str()); |
| 1319 |
|
| 1320 |
std::vector<int> textPos; |
| 1321 |
std::vector<MWAWFont> fonts; |
| 1322 |
if (!readFonts(line.m_entry, fonts, textPos)) |
| 1323 |
return false; |
| 1324 |
sendText(text, fonts, textPos); |
| 1325 |
if (input->tell()!=endPos) { |
| 1326 |
ascii().addPos(input->tell()); |
| 1327 |
ascii().addNote("Text(II):#"); |
| 1328 |
} |
| 1329 |
return true; |
| 1330 |
} |
| 1331 |
|
| 1332 |
//////////////////////////////////////////////////////////// |
| 1333 |
// read the fonts |
| 1334 |
//////////////////////////////////////////////////////////// |
| 1335 |
bool MindWrtParser::readFonts(MWAWEntry const &entry, std::vector<MWAWFont> &fonts, |
| 1336 |
std::vector<int> &textPos) |
| 1337 |
{ |
| 1338 |
textPos.resize(0); |
| 1339 |
fonts.resize(0); |
| 1340 |
|
| 1341 |
MWAWInputStreamPtr input = getInput(); |
| 1342 |
libmwaw::DebugStream f; |
| 1343 |
|
| 1344 |
long pos = input->tell(); |
| 1345 |
long endPos= entry.end(); |
| 1346 |
if (pos+2 > endPos) { |
| 1347 |
MWAW_DEBUG_MSG(("MindWrtParser::readFonts: zone is too short\n")); |
| 1348 |
return false; |
| 1349 |
} |
| 1350 |
auto sz = static_cast<int>(input->readULong(2)); |
| 1351 |
if (pos+2+sz > endPos || (sz%6)) { |
| 1352 |
MWAW_DEBUG_MSG(("MindWrtParser::readFonts: sz is odd\n")); |
| 1353 |
return false; |
| 1354 |
} |
| 1355 |
int N = sz/6; |
| 1356 |
f.str(""); |
| 1357 |
f << "Text[Font]:N=" << N; |
| 1358 |
ascii().addPos(pos); |
| 1359 |
ascii().addNote(f.str().c_str()); |
| 1360 |
for (int i = 0; i < N; i++) { |
| 1361 |
pos = input->tell(); |
| 1362 |
f.str(""); |
| 1363 |
f << "Text:Font" << i << ":"; |
| 1364 |
auto tPos = static_cast<int>(input->readULong(2)); |
| 1365 |
textPos.push_back(tPos); |
| 1366 |
f << "pos=" << tPos << ","; |
| 1367 |
MWAWFont font; |
| 1368 |
font.setSize(float(input->readULong(1))); |
| 1369 |
auto flag = static_cast<int>(input->readULong(1)); |
| 1370 |
uint32_t flags = 0; |
| 1371 |
// bit 1 = plain |
| 1372 |
if (flag&0x1) flags |= MWAWFont::boldBit; |
| 1373 |
if (flag&0x2) flags |= MWAWFont::italicBit; |
| 1374 |
if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 1375 |
if (flag&0x8) flags |= MWAWFont::embossBit; |
| 1376 |
if (flag&0x10) flags |= MWAWFont::shadowBit; |
| 1377 |
if (flag&0x20) font.set(MWAWFont::Script::super100()); |
| 1378 |
if (flag&0x40) font.set(MWAWFont::Script::sub100()); |
| 1379 |
if (flag&0x80) f << "#fFlags80,"; |
| 1380 |
font.setFlags(flags); |
| 1381 |
font.setId(static_cast<int>(input->readULong(2))); |
| 1382 |
fonts.push_back(font); |
| 1383 |
#ifdef DEBUG |
| 1384 |
f << font.getDebugString(getFontConverter()); |
| 1385 |
#endif |
| 1386 |
input->seek(pos+6, librevenge::RVNG_SEEK_SET); |
| 1387 |
|
| 1388 |
ascii().addPos(pos); |
| 1389 |
ascii().addNote(f.str().c_str()); |
| 1390 |
} |
| 1391 |
return true; |
| 1392 |
} |
| 1393 |
|
| 1394 |
//////////////////////////////////////////////////////////// |
| 1395 |
// read the header |
| 1396 |
//////////////////////////////////////////////////////////// |
| 1397 |
bool MindWrtParser::checkHeader(MWAWHeader *header, bool strict) |
| 1398 |
{ |
| 1399 |
*m_state = MindWrtParserInternal::State(); |
| 1400 |
|
| 1401 |
MWAWInputStreamPtr input = getInput(); |
| 1402 |
if (!input || !input->hasDataFork()) |
| 1403 |
return false; |
| 1404 |
libmwaw::DebugStream f; |
| 1405 |
|
| 1406 |
int const headerSize=0x50; |
| 1407 |
if (!input->checkPosition(headerSize)) { |
| 1408 |
MWAW_DEBUG_MSG(("MindWrtParser::checkHeader: file is too short\n")); |
| 1409 |
return false; |
| 1410 |
} |
| 1411 |
input->seek(0,librevenge::RVNG_SEEK_SET); |
| 1412 |
if (input->readULong(2) != 0x7704) |
| 1413 |
return false; |
| 1414 |
if (header) |
| 1415 |
header->reset(MWAWDocument::MWAW_T_MINDWRITE, 2); |
| 1416 |
|
| 1417 |
f << "Entries(Header):"; |
| 1418 |
for (auto &num : m_state->m_numLinesByZone) num = static_cast<int>(input->readULong(2)); |
| 1419 |
f << "nLines=" << m_state->m_numLinesByZone[0] << ","; |
| 1420 |
if (m_state->m_numLinesByZone[1]) |
| 1421 |
f << "nLines[Head]=" << m_state->m_numLinesByZone[1] << ","; |
| 1422 |
if (m_state->m_numLinesByZone[2]) |
| 1423 |
f << "nLines[Foot]=" << m_state->m_numLinesByZone[2] << ","; |
| 1424 |
long val; |
| 1425 |
for (int i = 0; i < 2; i++) { // find [01] [15] |
| 1426 |
val = input->readLong(1); |
| 1427 |
if (val) f << "f" << i << "=" << val << ","; |
| 1428 |
} |
| 1429 |
for (int i = 0; i < 3; i++) { // always 0 ? |
| 1430 |
val = input->readLong(2); |
| 1431 |
if (val) f << "g" << i << "=" << val << ","; |
| 1432 |
} |
| 1433 |
val = long(input->readULong(2)); // always 0x7fff |
| 1434 |
if (val != 0x7fff) f << "g3=" << std::hex << val << std::dec << ","; |
| 1435 |
ascii().addPos(0); |
| 1436 |
ascii().addNote(f.str().c_str()); |
| 1437 |
|
| 1438 |
long pos=input->tell(); |
| 1439 |
f.str(""); |
| 1440 |
f << "Header(II):"; |
| 1441 |
val = input->readLong(2); // 0 or 0x80 |
| 1442 |
if (val) f << "f0=" << val << ","; |
| 1443 |
for (int i = 1; i < 5; i++) { // 08, 0, [60|62], [40|60|66|70] |
| 1444 |
val = long(input->readULong(1)); |
| 1445 |
if (val) f << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 1446 |
} |
| 1447 |
for (int i = 0; i < 2; i++) { // -1, -1|0 |
| 1448 |
val = input->readLong(1); |
| 1449 |
if (!val) continue; |
| 1450 |
f << "g" << i; |
| 1451 |
if (val!=-1) f << "=" << val; |
| 1452 |
f << ","; |
| 1453 |
} |
| 1454 |
val = input->readLong(2); // always 1 ? |
| 1455 |
if (val != 1) f << "g2=" << val << ","; |
| 1456 |
m_state->m_listProperties.m_startListIndex = static_cast<int>(input->readULong(1))+1; |
| 1457 |
if (m_state->m_listProperties.m_startListIndex!=1) |
| 1458 |
f << "list[start]=" << m_state->m_listProperties.m_startListIndex << ","; |
| 1459 |
val = long(input->readULong(1)); |
| 1460 |
if (val) |
| 1461 |
f << "g3=" << val << ","; |
| 1462 |
|
| 1463 |
for (int i = 0; i < 17; i++) { // always 0 ? |
| 1464 |
val = input->readLong(2); |
| 1465 |
if (val) f << "h" << i << "=" << val << ","; |
| 1466 |
} |
| 1467 |
val = input->readLong(2); // always 0x10 ? |
| 1468 |
if (val!=0x10) f << "fl0=" << std::hex << val << std::dec << ","; |
| 1469 |
val = input->readLong(2); // always 0x100, maybe textFirstPos ? |
| 1470 |
if (val!=0x100) f << "fl1=" << std::hex << val << std::dec << ","; |
| 1471 |
val = input->readLong(2);// always 0x0 ? |
| 1472 |
if (val) f << "fl2=" << std::hex << val << std::dec << ","; |
| 1473 |
val = input->readLong(2);// always 0x1 ? |
| 1474 |
if (val != 1) f << "fl3=" << std::hex << val << std::dec << ","; |
| 1475 |
for (int i = 0; i < 4; i++) { // always 0 ? |
| 1476 |
val = input->readLong(2); |
| 1477 |
if (val) f << "j" << i << "=" << val << ","; |
| 1478 |
} |
| 1479 |
|
| 1480 |
bool ok = true; |
| 1481 |
if (strict) { |
| 1482 |
// check the line info block size |
| 1483 |
input->seek(0x50, librevenge::RVNG_SEEK_SET); |
| 1484 |
for (int i : m_state->m_numLinesByZone) { |
| 1485 |
input->seek(4, librevenge::RVNG_SEEK_CUR); |
| 1486 |
if (input->readLong(4) == 32*i) |
| 1487 |
continue; |
| 1488 |
ok = false; |
| 1489 |
break; |
| 1490 |
} |
| 1491 |
input->seek(0x50, librevenge::RVNG_SEEK_SET); |
| 1492 |
} |
| 1493 |
ascii().addPos(pos); |
| 1494 |
ascii().addNote(f.str().c_str()); |
| 1495 |
ascii().addPos(input->tell()); |
| 1496 |
ascii().addNote("_"); |
| 1497 |
|
| 1498 |
return ok; |
| 1499 |
} |
| 1500 |
|
| 1501 |
//////////////////////////////////////////////////////////// |
| 1502 |
// read the line info zones |
| 1503 |
//////////////////////////////////////////////////////////// |
| 1504 |
bool MindWrtParser::readLinesInfo(MWAWEntry &entry) |
| 1505 |
{ |
| 1506 |
if (!entry.valid()) |
| 1507 |
return false; |
| 1508 |
if (entry.id() < 0 || entry.id() >= 3) { |
| 1509 |
MWAW_DEBUG_MSG(("MindWrtParser::readLinesInfo: bad entry id %d\n", entry.id())); |
| 1510 |
return false; |
| 1511 |
} |
| 1512 |
if (entry.length()%32) { |
| 1513 |
MWAW_DEBUG_MSG(("MindWrtParser::readLinesInfo: the size seems odd\n")); |
| 1514 |
return false; |
| 1515 |
} |
| 1516 |
if (entry.isParsed()) { |
| 1517 |
MWAW_DEBUG_MSG(("MindWrtParser::readLinesInfo: entry is already parsed\n")); |
| 1518 |
return true; |
| 1519 |
} |
| 1520 |
entry.setParsed(true); |
| 1521 |
MWAWInputStreamPtr input = getInput(); |
| 1522 |
long pos = entry.begin(); |
| 1523 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1524 |
int N = int(entry.length())/32; |
| 1525 |
|
| 1526 |
libmwaw::DebugStream f; |
| 1527 |
auto &textZone = m_state->m_zones[entry.id()]; |
| 1528 |
textZone.m_linesList.clear(); |
| 1529 |
for (int n = 0; n < N; n++) { |
| 1530 |
MindWrtParserInternal::LineInfo line; |
| 1531 |
|
| 1532 |
pos = input->tell(); |
| 1533 |
f.str(""); |
| 1534 |
line.m_type = static_cast<int>(input->readLong(1)); // 0, fd, ff |
| 1535 |
line.m_height = static_cast<int>(input->readULong(1)); |
| 1536 |
line.m_y = static_cast<int>(input->readLong(2)); |
| 1537 |
line.m_page = static_cast<int>(input->readULong(1)); // check me |
| 1538 |
long val = input->readLong(2); // -1 or between 5d7-5de |
| 1539 |
f << "f0=" << std::hex << val << std::dec << ","; |
| 1540 |
for (int i=0; i < 2; i++) |
| 1541 |
line.m_flags[i] = static_cast<int>(input->readULong(1)); |
| 1542 |
auto ptr = long(input->readULong(1)); |
| 1543 |
line.m_entry.setBegin((ptr << 16) | long(input->readULong(2))); |
| 1544 |
line.m_entry.setLength(long(input->readULong(2))); |
| 1545 |
line.m_extra=f.str(); |
| 1546 |
for (int i=2; i < 4; i++) |
| 1547 |
line.m_flags[i] = static_cast<int>(input->readULong(1)); |
| 1548 |
line.m_listLevel = static_cast<int>(input->readLong(2)); |
| 1549 |
line.m_listType = static_cast<int>(input->readLong(2)); //0: heading, 1: unlabelled 2: paragraph, 3: bullet |
| 1550 |
/** 01[45]0 */ |
| 1551 |
|
| 1552 |
textZone.m_linesList.push_back(line); |
| 1553 |
|
| 1554 |
f.str(""); |
| 1555 |
f << "LineInfo-" << entry.id() << "[" << n << "]:" << line; |
| 1556 |
ascii().addDelimiter(input->tell(),'|'); |
| 1557 |
input->seek(pos+32, librevenge::RVNG_SEEK_SET); |
| 1558 |
ascii().addPos(pos); |
| 1559 |
ascii().addNote(f.str().c_str()); |
| 1560 |
|
| 1561 |
} |
| 1562 |
// first, we must read and update the paragraph |
| 1563 |
MWAWParagraph para; |
| 1564 |
bool hasSpecialHeadInterface = false; |
| 1565 |
for (auto &line : textZone.m_linesList) { |
| 1566 |
if (line.m_height || line.m_type) { |
| 1567 |
line.m_paragraph=para; |
| 1568 |
line.m_specialHeadingInterface = hasSpecialHeadInterface; |
| 1569 |
continue; |
| 1570 |
} |
| 1571 |
readRuler(line); |
| 1572 |
para = line.m_paragraph; |
| 1573 |
hasSpecialHeadInterface = line.m_specialHeadingInterface; |
| 1574 |
} |
| 1575 |
if (entry.id()==0) // only main zone has list, ouff... |
| 1576 |
textZone.updateListId(m_state->m_listProperties, *getParserState()->m_listManager); |
| 1577 |
return true; |
| 1578 |
} |
| 1579 |
|
| 1580 |
//////////////////////////////////////////////////////////// |
| 1581 |
// read the last zone ( use ?) |
| 1582 |
//////////////////////////////////////////////////////////// |
| 1583 |
bool MindWrtParser::readLastZone(MWAWEntry const &entry) |
| 1584 |
{ |
| 1585 |
if (!entry.valid()) |
| 1586 |
return false; |
| 1587 |
if (entry.length()<0x8 || (entry.length())%4!=0) { |
| 1588 |
MWAW_DEBUG_MSG(("MindWrtParser::readLastZone: the size seems odd\n")); |
| 1589 |
return false; |
| 1590 |
} |
| 1591 |
if (entry.isParsed()) { |
| 1592 |
MWAW_DEBUG_MSG(("MindWrtParser::readLastZone: entry is already parsed\n")); |
| 1593 |
return true; |
| 1594 |
} |
| 1595 |
entry.setParsed(true); |
| 1596 |
MWAWInputStreamPtr input = getInput(); |
| 1597 |
long pos = entry.begin(); |
| 1598 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1599 |
|
| 1600 |
libmwaw::DebugStream f; |
| 1601 |
f << "LastZone:"; |
| 1602 |
int N=int(entry.length()>>2)-2; |
| 1603 |
long val; |
| 1604 |
for (int i = 0; i < N; i++) { // find one time two value 0x154, 0xc ? |
| 1605 |
val = long(input->readULong(4)); |
| 1606 |
if (val) f << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 1607 |
} |
| 1608 |
val = long(input->readULong(4)); |
| 1609 |
if (val != pos) { |
| 1610 |
MWAW_DEBUG_MSG(("MindWrtParser::readLastZone: the ptr seems odd\n")); |
| 1611 |
f << "#ptr=" << std::hex << val << std::dec << ","; |
| 1612 |
} |
| 1613 |
val = long(input->readULong(2)); // always 0x7fff |
| 1614 |
if (val != 0x7fff) f << "g0=" << std::hex << val << std::dec << ","; |
| 1615 |
val = input->readLong(2); // always -1 |
| 1616 |
if (val != -1) f << "g1=" << val << ","; |
| 1617 |
ascii().addPos(pos); |
| 1618 |
ascii().addNote(f.str().c_str()); |
| 1619 |
return true; |
| 1620 |
} |
| 1621 |
|
| 1622 |
//////////////////////////////////////////////////////////// |
| 1623 |
// read the heading state/properties/custom |
| 1624 |
//////////////////////////////////////////////////////////// |
| 1625 |
bool MindWrtParser::readHeadingStates(MWAWEntry &entry) |
| 1626 |
{ |
| 1627 |
if (!entry.valid()) |
| 1628 |
return false; |
| 1629 |
if (!entry.length() || (entry.length()%2)) { |
| 1630 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingStates: the size seems odd\n")); |
| 1631 |
return false; |
| 1632 |
} |
| 1633 |
entry.setParsed(true); |
| 1634 |
MWAWInputStreamPtr input = getInput(); |
| 1635 |
long pos = entry.begin(); |
| 1636 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1637 |
libmwaw::DebugStream f; |
| 1638 |
f << "HeadState:"; |
| 1639 |
long unkn = input->readLong(2); // always 2? |
| 1640 |
if (unkn!=2) f << "unkn=" << unkn << ","; |
| 1641 |
int N=int(entry.length()/2)-1; |
| 1642 |
for (int i = 0; i < N; i++) { |
| 1643 |
auto fl=static_cast<int>(input->readULong(1)); |
| 1644 |
auto wh=static_cast<int>(input->readULong(1)); |
| 1645 |
if (fl==0 && wh==4) |
| 1646 |
continue; |
| 1647 |
f << "L" << i << "=["; |
| 1648 |
switch (fl) { |
| 1649 |
case 0: // visible |
| 1650 |
break; |
| 1651 |
case 1: |
| 1652 |
f << "hidden,"; |
| 1653 |
break; |
| 1654 |
default: |
| 1655 |
f << "#state=" << std::hex << fl << std::dec << ","; |
| 1656 |
break; |
| 1657 |
} |
| 1658 |
switch (wh) { |
| 1659 |
// find also 0 and 1 |
| 1660 |
case 4: // standard |
| 1661 |
break; |
| 1662 |
default: |
| 1663 |
f << "#wh=" << std::hex << fl << std::dec << ","; |
| 1664 |
break; |
| 1665 |
} |
| 1666 |
f << "],"; |
| 1667 |
} |
| 1668 |
ascii().addPos(pos); |
| 1669 |
ascii().addNote(f.str().c_str()); |
| 1670 |
return true; |
| 1671 |
} |
| 1672 |
|
| 1673 |
bool MindWrtParser::readHeadingCustom(MWAWEntry &entry) |
| 1674 |
{ |
| 1675 |
if (!entry.valid()) |
| 1676 |
return false; |
| 1677 |
auto len=int(entry.length()); |
| 1678 |
if (len<16) { |
| 1679 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingCustom: the size seems odd\n")); |
| 1680 |
return false; |
| 1681 |
} |
| 1682 |
entry.setParsed(true); |
| 1683 |
MWAWInputStreamPtr input = getInput(); |
| 1684 |
long pos = entry.begin(), beginPos=pos; |
| 1685 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1686 |
libmwaw::DebugStream f; |
| 1687 |
f << "HeadCust:"; |
| 1688 |
if (static_cast<int>(input->readULong(2))!= len) { |
| 1689 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingCustom: the size field seems odd\n")); |
| 1690 |
f << "###"; |
| 1691 |
ascii().addPos(pos); |
| 1692 |
ascii().addNote(f.str().c_str()); |
| 1693 |
return false; |
| 1694 |
} |
| 1695 |
auto N=static_cast<int>(input->readULong(2)); |
| 1696 |
f << "N=" << N << ","; |
| 1697 |
if (len < 16+2*N) { |
| 1698 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingCustom: N seems bads\n")); |
| 1699 |
f << "###"; |
| 1700 |
ascii().addPos(pos); |
| 1701 |
ascii().addNote(f.str().c_str()); |
| 1702 |
return false; |
| 1703 |
} |
| 1704 |
|
| 1705 |
auto val = static_cast<int>(input->readLong(2)); |
| 1706 |
m_state->m_listProperties.m_listLevelsRepeatPos = val; |
| 1707 |
if (val) f << "repeatPos=" << val << ","; |
| 1708 |
auto debDeplPos = static_cast<int>(input->readLong(2)); |
| 1709 |
auto debStringPos = static_cast<int>(input->readLong(2)); |
| 1710 |
if (debDeplPos+2*N >= len || debStringPos > len) { |
| 1711 |
f << "##deplPos=" << debDeplPos << "," |
| 1712 |
<< "##stringPos=" << debStringPos << ","; |
| 1713 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingCustom: can not read first pos\n")); |
| 1714 |
ascii().addPos(pos); |
| 1715 |
ascii().addNote(f.str().c_str()); |
| 1716 |
return false; |
| 1717 |
} |
| 1718 |
for (int i = 0; i < 3; i++) { // always 0 ? |
| 1719 |
val = static_cast<int>(input->readLong(2)); |
| 1720 |
if (!val) continue; |
| 1721 |
f << "f" << i << "=" << val << ","; |
| 1722 |
} |
| 1723 |
input->seek(beginPos+long(debDeplPos), librevenge::RVNG_SEEK_SET); |
| 1724 |
|
| 1725 |
std::vector<int> listPos; |
| 1726 |
for (int i = 0; i < N; i++) |
| 1727 |
listPos.push_back(static_cast<int>(input->readLong(2))); |
| 1728 |
listPos.push_back(len); |
| 1729 |
|
| 1730 |
std::string str(""); |
| 1731 |
for (size_t i = 0; i < size_t(N); i++) { |
| 1732 |
input->seek(beginPos+long(listPos[i]), librevenge::RVNG_SEEK_SET); |
| 1733 |
int sSz=listPos[i+1]-listPos[i]; |
| 1734 |
if (sSz < 0) { |
| 1735 |
f << "###len"<<i<<"="<< sSz << ","; |
| 1736 |
ascii().addPos(pos); |
| 1737 |
ascii().addNote(f.str().c_str()); |
| 1738 |
return false; |
| 1739 |
} |
| 1740 |
MWAWListLevel level; |
| 1741 |
bool seeIndex=false; |
| 1742 |
for (int s = 0; s < sSz; s++) { |
| 1743 |
auto c = char(input->readULong(1)); |
| 1744 |
int unicode; |
| 1745 |
str+=c; |
| 1746 |
if (c==0) |
| 1747 |
break; |
| 1748 |
// check for end of field |
| 1749 |
if (seeIndex && (s >= sSz-2) && (c==',' || c==';' || c==' ')) { |
| 1750 |
if (s==sSz-1) |
| 1751 |
break; |
| 1752 |
if (char(input->readULong(1))==' ') |
| 1753 |
break; |
| 1754 |
input->seek(-1, librevenge::RVNG_SEEK_CUR); |
| 1755 |
} |
| 1756 |
if (!seeIndex) { |
| 1757 |
seeIndex = true; |
| 1758 |
switch (c) { |
| 1759 |
case '1': |
| 1760 |
level.m_type=MWAWListLevel::DECIMAL; |
| 1761 |
break; |
| 1762 |
case 'a': |
| 1763 |
level.m_type=MWAWListLevel::LOWER_ALPHA; |
| 1764 |
break; |
| 1765 |
case 'A': |
| 1766 |
level.m_type=MWAWListLevel::UPPER_ALPHA; |
| 1767 |
break; |
| 1768 |
case 'i': |
| 1769 |
level.m_type=MWAWListLevel::LOWER_ROMAN; |
| 1770 |
break; |
| 1771 |
case 'I': |
| 1772 |
level.m_type=MWAWListLevel::UPPER_ROMAN; |
| 1773 |
break; |
| 1774 |
default: |
| 1775 |
seeIndex=false; |
| 1776 |
unicode = getParserState()->m_fontConverter->unicode(3, static_cast<unsigned char>(c)); |
| 1777 |
if (unicode==-1) |
| 1778 |
libmwaw::appendUnicode(static_cast<unsigned char>(c), level.m_prefix); |
| 1779 |
else |
| 1780 |
libmwaw::appendUnicode(uint32_t(unicode), level.m_prefix); |
| 1781 |
break; |
| 1782 |
} |
| 1783 |
continue; |
| 1784 |
} |
| 1785 |
unicode = getParserState()->m_fontConverter->unicode(3, static_cast<unsigned char>(c)); |
| 1786 |
if (unicode==-1) |
| 1787 |
libmwaw::appendUnicode(static_cast<unsigned char>(c), level.m_suffix); |
| 1788 |
else |
| 1789 |
libmwaw::appendUnicode(uint32_t(unicode), level.m_suffix); |
| 1790 |
} |
| 1791 |
m_state->m_listProperties.m_headingListLevels.push_back(level); |
| 1792 |
str+='|'; |
| 1793 |
} |
| 1794 |
f << "\"" << str << "\""; |
| 1795 |
ascii().addPos(pos); |
| 1796 |
ascii().addNote(f.str().c_str()); |
| 1797 |
return true; |
| 1798 |
} |
| 1799 |
|
| 1800 |
bool MindWrtParser::readHeadingProperties(MWAWEntry &entry) |
| 1801 |
{ |
| 1802 |
if (!entry.valid()) |
| 1803 |
return false; |
| 1804 |
if (entry.length()!=32) { |
| 1805 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingProperties: the size seems odd\n")); |
| 1806 |
return false; |
| 1807 |
} |
| 1808 |
if (entry.isParsed()) { |
| 1809 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingProperties: entry is already parsed\n")); |
| 1810 |
return true; |
| 1811 |
} |
| 1812 |
entry.setParsed(true); |
| 1813 |
MWAWInputStreamPtr input = getInput(); |
| 1814 |
long pos = entry.begin(); |
| 1815 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1816 |
libmwaw::DebugStream f; |
| 1817 |
f << "HeadProp:"; |
| 1818 |
long val=input->readLong(1); // always 0 ? |
| 1819 |
if (val) f << "f0=" << val << ","; |
| 1820 |
m_state->m_listProperties.m_headingStyle=static_cast<int>(input->readULong(1)); |
| 1821 |
switch (m_state->m_listProperties.m_headingStyle) { |
| 1822 |
case 1: |
| 1823 |
f << "list[type]=Hardvard,"; // I. A. 1. a) i) |
| 1824 |
break; |
| 1825 |
case 2: |
| 1826 |
f << "list[type]=Chicago,"; // I. A. 1. a) (1), (a), i) |
| 1827 |
break; |
| 1828 |
case 3: |
| 1829 |
f << "list[type]=Section,"; // 1. 1. |
| 1830 |
break; |
| 1831 |
case 4: |
| 1832 |
f << "list[type]=custom,"; |
| 1833 |
break; |
| 1834 |
default: |
| 1835 |
f << "#list[type]=" << m_state->m_listProperties.m_headingStyle << ","; |
| 1836 |
break; |
| 1837 |
} |
| 1838 |
val = input->readLong(1); |
| 1839 |
switch (val) { |
| 1840 |
case 1: // show all level |
| 1841 |
break; |
| 1842 |
case 2: |
| 1843 |
m_state->m_listProperties.m_headingFullSubLevels = false; |
| 1844 |
f << "list[showOneLevel],"; |
| 1845 |
break; |
| 1846 |
default: |
| 1847 |
f << "#list[showOneLevel]=" << val << ","; |
| 1848 |
break; |
| 1849 |
} |
| 1850 |
val = long(input->readULong(1)); // short, long? |
| 1851 |
if (val) |
| 1852 |
f << "f1=" << val << ","; |
| 1853 |
long const expectedValues[]= {0,0x7ffe,0xf,0xc}; |
| 1854 |
for (int i = 0; i < 4; i++) { |
| 1855 |
val = input->readLong(2); |
| 1856 |
if (val!=expectedValues[i]) |
| 1857 |
f << "f" << i+4 << "=" << val << ","; |
| 1858 |
} |
| 1859 |
for (int i = 0; i < 6; i++) { // always 0? |
| 1860 |
val = input->readLong(2); |
| 1861 |
if (val) |
| 1862 |
f << "g" << i << "=" << val << ","; |
| 1863 |
} |
| 1864 |
val = long(input->readULong(4)); // 5e3be|5e3c2|5e49c|2975a4|69dce0|69e10c |
| 1865 |
f << "ptr?=" << std::hex << val << std::dec << ","; |
| 1866 |
val = long(input->readULong(4)); // always FFFFFF? |
| 1867 |
if (val != 0xFFFFFF) |
| 1868 |
f << "unkn?=" << std::hex << val << std::dec << ","; |
| 1869 |
ascii().addPos(pos); |
| 1870 |
ascii().addNote(f.str().c_str()); |
| 1871 |
return true; |
| 1872 |
} |
| 1873 |
|
| 1874 |
//////////////////////////////////////////////////////////// |
| 1875 |
// read zone8 |
| 1876 |
//////////////////////////////////////////////////////////// |
| 1877 |
bool MindWrtParser::readZone8(MWAWEntry &entry) |
| 1878 |
{ |
| 1879 |
if (!entry.valid()) |
| 1880 |
return false; |
| 1881 |
if (entry.length()!=48) { |
| 1882 |
MWAW_DEBUG_MSG(("MindWrtParser::readZone8: the size seems odd\n")); |
| 1883 |
return false; |
| 1884 |
} |
| 1885 |
if (entry.isParsed()) { |
| 1886 |
MWAW_DEBUG_MSG(("MindWrtParser::readZone8: entry is already parsed\n")); |
| 1887 |
return true; |
| 1888 |
} |
| 1889 |
entry.setParsed(true); |
| 1890 |
MWAWInputStreamPtr input = getInput(); |
| 1891 |
long pos = entry.begin(); |
| 1892 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1893 |
libmwaw::DebugStream f; |
| 1894 |
f << "Zone8:"; |
| 1895 |
auto val = long(input->readULong(1));// fl0=0|1|2c|2d, |
| 1896 |
if (val) |
| 1897 |
f << "fl0=" << std::hex << val << std::dec << ","; |
| 1898 |
val = long(input->readULong(1)); // fl1=2b|6b|ab |
| 1899 |
if (val & 0x80) { // checkme |
| 1900 |
f << "showFirstLevel?,"; |
| 1901 |
m_state->m_listProperties.m_showFirstLevel = true; |
| 1902 |
val &= 0x7F; |
| 1903 |
} |
| 1904 |
if (val) |
| 1905 |
f << "fl1=" << std::hex << val << std::dec << ","; |
| 1906 |
/* f0=0|9|a, f1=4|10|5c, f2=0|1|1c,f3=1|3|9|c|24|29,f4=1|2,4|6|c|24,f5=0|17|63, |
| 1907 |
f6=0, f7=26|c5, f8=0 |
| 1908 |
f3=f4 related to visible heading? |
| 1909 |
*/ |
| 1910 |
for (int i = 0; i < 9; i++) { |
| 1911 |
val = input->readLong(2); |
| 1912 |
if (val) |
| 1913 |
f << "f" << i << "=" << val << ","; |
| 1914 |
} |
| 1915 |
int dim[2]; |
| 1916 |
for (auto &d : dim) d = static_cast<int>(input->readLong(2)); |
| 1917 |
f << "dim=" << dim[0] << "x" << dim[1] << ","; |
| 1918 |
for (int i = 0; i < 12; i++) { // always 0... |
| 1919 |
val = input->readLong(2); |
| 1920 |
if (val) |
| 1921 |
f << "g" << i << "=" << val << ","; |
| 1922 |
} |
| 1923 |
ascii().addPos(pos); |
| 1924 |
ascii().addNote(f.str().c_str()); |
| 1925 |
return true; |
| 1926 |
} |
| 1927 |
|
| 1928 |
//////////////////////////////////////////////////////////// |
| 1929 |
// header/footer fields position |
| 1930 |
//////////////////////////////////////////////////////////// |
| 1931 |
bool MindWrtParser::readHeadingFields(MWAWEntry &entry) |
| 1932 |
{ |
| 1933 |
if (!entry.valid()) |
| 1934 |
return false; |
| 1935 |
if (entry.length()%12) { |
| 1936 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingFields: the size seems odd\n")); |
| 1937 |
return false; |
| 1938 |
} |
| 1939 |
if (entry.isParsed()) { |
| 1940 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingFields: entry is already parsed\n")); |
| 1941 |
return true; |
| 1942 |
} |
| 1943 |
entry.setParsed(true); |
| 1944 |
MWAWInputStreamPtr input = getInput(); |
| 1945 |
long pos = entry.begin(); |
| 1946 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1947 |
|
| 1948 |
auto num = int(entry.length()/12); |
| 1949 |
if (num != 8) { |
| 1950 |
MWAW_DEBUG_MSG(("MindWrtParser::readHeadingFields: the number of fields seems odd\n")); |
| 1951 |
} |
| 1952 |
libmwaw::DebugStream f; |
| 1953 |
long val; |
| 1954 |
static MWAWField::Type const listType[4] = { |
| 1955 |
MWAWField::Date, MWAWField::Time, MWAWField::PageNumber, MWAWField::Title |
| 1956 |
}; |
| 1957 |
for (int i = 0; i < num; i++) { |
| 1958 |
pos = input->tell(); |
| 1959 |
MindWrtParserInternal::Field field(listType[i%4]); |
| 1960 |
f.str(""); |
| 1961 |
int dim[2]; |
| 1962 |
for (int j=0; j < 2; j++) dim[j] = static_cast<int>(input->readLong(j==0 ? 2:4)); |
| 1963 |
field.m_pos=MWAWVec2i(dim[1], dim[0]); |
| 1964 |
static int const expectedVal[3] = {3,12,0}; |
| 1965 |
for (int j=0; j < 3; j++) { |
| 1966 |
val = input->readLong(2); |
| 1967 |
if (val!=expectedVal[j]) |
| 1968 |
f << "f" << j << "=" << val << ","; |
| 1969 |
} |
| 1970 |
field.m_extra=f.str(); |
| 1971 |
f.str(""); |
| 1972 |
f << "HeadField[" << i << "]:" << field; |
| 1973 |
if (num==8 && field.ok()) { |
| 1974 |
if (i < 4) |
| 1975 |
m_state->m_headerFieldList.push_back(field); |
| 1976 |
else |
| 1977 |
m_state->m_footerFieldList.push_back(field); |
| 1978 |
} |
| 1979 |
input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
| 1980 |
ascii().addPos(pos); |
| 1981 |
ascii().addNote(f.str().c_str()); |
| 1982 |
} |
| 1983 |
return true; |
| 1984 |
} |
| 1985 |
|
| 1986 |
//////////////////////////////////////////////////////////// |
| 1987 |
// read the print info |
| 1988 |
//////////////////////////////////////////////////////////// |
| 1989 |
bool MindWrtParser::readPrintInfo(MWAWEntry const &entry) |
| 1990 |
{ |
| 1991 |
if (!entry.valid()) |
| 1992 |
return false; |
| 1993 |
if (entry.length()!=0x78) { |
| 1994 |
MWAW_DEBUG_MSG(("MindWrtParser::readPrintInfo: the size seems odd\n")); |
| 1995 |
if (entry.length() < 0x78) |
| 1996 |
return false; |
| 1997 |
} |
| 1998 |
if (entry.isParsed()) { |
| 1999 |
MWAW_DEBUG_MSG(("MindWrtParser::readPrintInfo: entry is already parsed\n")); |
| 2000 |
return true; |
| 2001 |
} |
| 2002 |
MWAWInputStreamPtr input = getInput(); |
| 2003 |
long pos = entry.begin(); |
| 2004 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2005 |
|
| 2006 |
libmwaw::DebugStream f; |
| 2007 |
// print info |
| 2008 |
libmwaw::PrinterInfo info; |
| 2009 |
if (!info.read(input)) return false; |
| 2010 |
f << "Entries(PrintInfo):"<< info; |
| 2011 |
|
| 2012 |
MWAWVec2i paperSize = info.paper().size(); |
| 2013 |
MWAWVec2i pageSize = info.page().size(); |
| 2014 |
if (pageSize.x() <= 0 || pageSize.y() <= 0 || |
| 2015 |
paperSize.x() <= 0 || paperSize.y() <= 0) return false; |
| 2016 |
|
| 2017 |
// define margin from print info |
| 2018 |
MWAWVec2i lTopMargin= -1 * info.paper().pos(0); |
| 2019 |
MWAWVec2i rBotMargin=info.paper().size() - info.page().size(); |
| 2020 |
|
| 2021 |
// move margin left | top |
| 2022 |
int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0; |
| 2023 |
int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0; |
| 2024 |
lTopMargin -= MWAWVec2i(decalX, decalY); |
| 2025 |
rBotMargin += MWAWVec2i(decalX, decalY); |
| 2026 |
|
| 2027 |
// decrease right | bottom |
| 2028 |
int rightMarg = rBotMargin.x() -50; |
| 2029 |
if (rightMarg < 0) rightMarg=0; |
| 2030 |
int botMarg = rBotMargin.y() -50; |
| 2031 |
if (botMarg < 0) botMarg=0; |
| 2032 |
|
| 2033 |
getPageSpan().setMarginTop(lTopMargin.y()/72.0); |
| 2034 |
getPageSpan().setMarginBottom(botMarg/72.0); |
| 2035 |
getPageSpan().setMarginLeft(lTopMargin.x()/72.0); |
| 2036 |
getPageSpan().setMarginRight(rightMarg/72.0); |
| 2037 |
getPageSpan().setFormLength(paperSize.y()/72.); |
| 2038 |
getPageSpan().setFormWidth(paperSize.x()/72.); |
| 2039 |
|
| 2040 |
ascii().addPos(pos); |
| 2041 |
ascii().addNote(f.str().c_str()); |
| 2042 |
|
| 2043 |
input->seek(pos+0x78, librevenge::RVNG_SEEK_SET); |
| 2044 |
if (long(input->tell()) != pos+0x78) { |
| 2045 |
MWAW_DEBUG_MSG(("MindWrtParser::readPrintInfo: file is too short\n")); |
| 2046 |
return false; |
| 2047 |
} |
| 2048 |
|
| 2049 |
return true; |
| 2050 |
} |
| 2051 |
|
| 2052 |
//////////////////////////////////////////////////////////// |
| 2053 |
// send the text, ... |
| 2054 |
//////////////////////////////////////////////////////////// |
| 2055 |
void MindWrtParser::sendText(std::string const &text, std::vector<MWAWFont> const &fonts, std::vector<int> const &textPos) |
| 2056 |
{ |
| 2057 |
if (!getTextListener() || !text.length()) |
| 2058 |
return; |
| 2059 |
size_t numFonts = fonts.size(); |
| 2060 |
if (numFonts != textPos.size()) { |
| 2061 |
MWAW_DEBUG_MSG(("MindWrtParser::sendText: find fonts/textPos incompatibility\n")); |
| 2062 |
if (numFonts > textPos.size()) |
| 2063 |
numFonts = textPos.size(); |
| 2064 |
} |
| 2065 |
size_t actFontId = 0; |
| 2066 |
size_t numChar = text.length(); |
| 2067 |
for (size_t c = 0; c < numChar; c++) { |
| 2068 |
if (actFontId < numFonts && int(c) == textPos[actFontId]) |
| 2069 |
getTextListener()->setFont(fonts[actFontId++]); |
| 2070 |
auto ch = static_cast<unsigned char>(text[c]); |
| 2071 |
switch (ch) { |
| 2072 |
case 0x9: |
| 2073 |
getTextListener()->insertTab(); |
| 2074 |
break; |
| 2075 |
case 0xd: |
| 2076 |
getTextListener()->insertEOL(c!=numChar-1); |
| 2077 |
break; |
| 2078 |
default: |
| 2079 |
getTextListener()->insertCharacter(static_cast<unsigned char>(ch)); |
| 2080 |
break; |
| 2081 |
} |
| 2082 |
} |
| 2083 |
} |
| 2084 |
|
| 2085 |
void MindWrtParser::setProperty(MWAWParagraph const ¶) |
| 2086 |
{ |
| 2087 |
if (!getTextListener()) return; |
| 2088 |
getTextListener()->setParagraph(para); |
| 2089 |
} |
| 2090 |
|
| 2091 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |