| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#include <cmath> |
| 35 |
#include <iomanip> |
| 36 |
#include <iostream> |
| 37 |
#include <limits> |
| 38 |
#include <map> |
| 39 |
#include <set> |
| 40 |
#include <sstream> |
| 41 |
|
| 42 |
#include <librevenge/librevenge.h> |
| 43 |
|
| 44 |
#include "MWAWCell.hxx" |
| 45 |
#include "MWAWFont.hxx" |
| 46 |
#include "MWAWFontConverter.hxx" |
| 47 |
#include "MWAWGraphicEncoder.hxx" |
| 48 |
#include "MWAWGraphicListener.hxx" |
| 49 |
#include "MWAWGraphicShape.hxx" |
| 50 |
#include "MWAWGraphicStyle.hxx" |
| 51 |
#include "MWAWPictMac.hxx" |
| 52 |
#include "MWAWPosition.hxx" |
| 53 |
#include "MWAWSubDocument.hxx" |
| 54 |
#include "MWAWTable.hxx" |
| 55 |
#include "MWAWTextListener.hxx" |
| 56 |
|
| 57 |
#include "HanMacWrdJParser.hxx" |
| 58 |
|
| 59 |
#include "HanMacWrdJGraph.hxx" |
| 60 |
|
| 61 |
/** Internal: the structures of a HanMacWrdJGraph */ |
| 62 |
namespace HanMacWrdJGraphInternal |
| 63 |
{ |
| 64 |
//////////////////////////////////////// |
| 65 |
//! a cell format in HanMacWrdJGraph |
| 66 |
struct CellFormat { |
| 67 |
public: |
| 68 |
//! constructor |
| 69 |
CellFormat() |
| 70 |
: m_backColor(MWAWColor::white()) |
| 71 |
, m_borders() |
| 72 |
, m_extra("") |
| 73 |
{ |
| 74 |
} |
| 75 |
//! operator<< |
| 76 |
friend std::ostream &operator<<(std::ostream &o, CellFormat const &frmt) |
| 77 |
{ |
| 78 |
if (!frmt.m_backColor.isWhite()) |
| 79 |
o << "backColor=" << frmt.m_backColor << ","; |
| 80 |
char const *what[] = {"T", "L", "B", "R"}; |
| 81 |
for (size_t b = 0; b < frmt.m_borders.size(); b++) |
| 82 |
o << "bord" << what[b] << "=[" << frmt.m_borders[b] << "],"; |
| 83 |
o << frmt.m_extra; |
| 84 |
return o; |
| 85 |
} |
| 86 |
//! the background color |
| 87 |
MWAWColor m_backColor; |
| 88 |
//! the border: order defined by MWAWBorder::Pos |
| 89 |
std::vector<MWAWBorder> m_borders; |
| 90 |
//! extra data |
| 91 |
std::string m_extra; |
| 92 |
}; |
| 93 |
|
| 94 |
//////////////////////////////////////// |
| 95 |
//! a table cell in a table in HanMacWrdJGraph |
| 96 |
struct TableCell final : public MWAWCell { |
| 97 |
//! constructor |
| 98 |
explicit TableCell(long tId) |
| 99 |
: MWAWCell() |
| 100 |
, m_zId(0) |
| 101 |
, m_tId(tId) |
| 102 |
, m_cPos(-1) |
| 103 |
, m_fileId(0) |
| 104 |
, m_formatId(0) |
| 105 |
, m_flags(0) |
| 106 |
, m_extra("") |
| 107 |
{ |
| 108 |
} |
| 109 |
//! use cell format to finish updating cell |
| 110 |
void update(CellFormat const &format); |
| 111 |
//! call when the content of a cell must be send |
| 112 |
bool sendContent(MWAWListenerPtr listener, MWAWTable &table) final; |
| 113 |
//! operator<< |
| 114 |
friend std::ostream &operator<<(std::ostream &o, TableCell const &cell); |
| 115 |
//! the cell zone id |
| 116 |
long m_zId; |
| 117 |
//! the cell text zone id |
| 118 |
long m_tId; |
| 119 |
//! the first character position in m_zId |
| 120 |
long m_cPos; |
| 121 |
//! the file id |
| 122 |
long m_fileId; |
| 123 |
//! the cell format id |
| 124 |
int m_formatId; |
| 125 |
//! the cell flags |
| 126 |
int m_flags; |
| 127 |
//! extra data |
| 128 |
std::string m_extra; |
| 129 |
|
| 130 |
}; |
| 131 |
|
| 132 |
void TableCell::update(CellFormat const &format) |
| 133 |
{ |
| 134 |
setBackgroundColor(format.m_backColor); |
| 135 |
static int const wh[] = { libmwaw::LeftBit, libmwaw::RightBit, libmwaw::TopBit, libmwaw::BottomBit}; |
| 136 |
for (size_t b = 0; b < format.m_borders.size(); b++) |
| 137 |
setBorders(wh[b], format.m_borders[b]); |
| 138 |
if (hasExtraLine() && format.m_borders.size()>=2) { |
| 139 |
MWAWBorder extraL; |
| 140 |
extraL.m_width=format.m_borders[1].m_width; |
| 141 |
extraL.m_color=format.m_borders[1].m_color; |
| 142 |
setExtraLine(extraLine(), extraL); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
std::ostream &operator<<(std::ostream &o, TableCell const &cell) |
| 147 |
{ |
| 148 |
o << static_cast<MWAWCell const &>(cell); |
| 149 |
if (cell.m_flags&0x100) o << "justify[full],"; |
| 150 |
if (cell.m_flags&0x800) o << "lock,"; |
| 151 |
if (cell.m_flags&0x1000) o << "merge,"; |
| 152 |
if (cell.m_flags&0x2000) o << "inactive,"; |
| 153 |
if (cell.m_flags&0xC07F) |
| 154 |
o << "#linesFlags=" << std::hex << (cell.m_flags&0xC07F) << std::dec << ","; |
| 155 |
if (cell.m_zId > 0) |
| 156 |
o << "cellId=" << std::hex << cell.m_zId << std::dec << "[" << cell.m_cPos << "],"; |
| 157 |
if (cell.m_formatId > 0) |
| 158 |
o << "formatId=" << std::hex << cell.m_formatId << std::dec << ","; |
| 159 |
o << cell.m_extra; |
| 160 |
return o; |
| 161 |
} |
| 162 |
|
| 163 |
//////////////////////////////////////// |
| 164 |
//! Internal: the table of a HanMacWrdJGraph |
| 165 |
struct Table final : public MWAWTable { |
| 166 |
//! constructor |
| 167 |
explicit Table(HanMacWrdJGraph &parser) |
| 168 |
: MWAWTable(MWAWTable::CellPositionBit|MWAWTable::TableDimBit) |
| 169 |
, m_parser(&parser) |
| 170 |
, m_rows(1) |
| 171 |
, m_columns(1) |
| 172 |
, m_height(0) |
| 173 |
, m_textFileId(0) |
| 174 |
, m_formatsList() |
| 175 |
{ |
| 176 |
} |
| 177 |
//! destructor |
| 178 |
~Table() final; |
| 179 |
//! update all cells using the formats list |
| 180 |
void updateCells(); |
| 181 |
//! send a text zone |
| 182 |
bool sendText(long id, long cPos) const |
| 183 |
{ |
| 184 |
return m_parser->sendText(id, cPos); |
| 185 |
} |
| 186 |
//! the graph parser |
| 187 |
HanMacWrdJGraph *m_parser; |
| 188 |
//! the number of row |
| 189 |
int m_rows; |
| 190 |
//! the number of columns |
| 191 |
int m_columns; |
| 192 |
//! the table height |
| 193 |
int m_height; |
| 194 |
//! the text file id |
| 195 |
long m_textFileId; |
| 196 |
//! a list of cell format |
| 197 |
std::vector<CellFormat> m_formatsList; |
| 198 |
|
| 199 |
private: |
| 200 |
Table(Table const &orig) = delete; |
| 201 |
Table &operator=(Table const &orig) = delete; |
| 202 |
}; |
| 203 |
|
| 204 |
Table::~Table() |
| 205 |
{ |
| 206 |
} |
| 207 |
|
| 208 |
bool TableCell::sendContent(MWAWListenerPtr, MWAWTable &table) |
| 209 |
{ |
| 210 |
if (m_tId) |
| 211 |
return static_cast<Table &>(table).sendText(m_tId, m_cPos); |
| 212 |
return true; |
| 213 |
} |
| 214 |
|
| 215 |
void Table::updateCells() |
| 216 |
{ |
| 217 |
auto numFormats=static_cast<int>(m_formatsList.size()); |
| 218 |
for (int c=0; c<numCells(); ++c) { |
| 219 |
if (!get(c)) continue; |
| 220 |
TableCell &cell=static_cast<TableCell &>(*get(c)); |
| 221 |
if (cell.m_formatId < 0 || cell.m_formatId>=numFormats) { |
| 222 |
static bool first = true; |
| 223 |
if (first) { |
| 224 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::Table::updateCells: can not find the format\n")); |
| 225 |
first = false; |
| 226 |
} |
| 227 |
continue; |
| 228 |
} |
| 229 |
cell.update(m_formatsList[size_t(cell.m_formatId)]); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
//////////////////////////////////////// |
| 234 |
//! a frame format in HanMacWrdJGraph |
| 235 |
struct FrameFormat { |
| 236 |
public: |
| 237 |
//! constructor |
| 238 |
FrameFormat() |
| 239 |
: m_style() |
| 240 |
, m_borderType(0) |
| 241 |
{ |
| 242 |
m_style.m_lineWidth=0; |
| 243 |
for (auto &wrap : m_intWrap) wrap=1.0; |
| 244 |
for (auto &wrap : m_extWrap) wrap=1.0; |
| 245 |
} |
| 246 |
//! add property to frame extra values |
| 247 |
void addTo(MWAWGraphicStyle &style) const |
| 248 |
{ |
| 249 |
if (m_style.hasLine()) { |
| 250 |
MWAWBorder border; |
| 251 |
border.m_width=double(m_style.m_lineWidth); |
| 252 |
border.m_color=m_style.m_lineColor; |
| 253 |
switch (m_borderType) { |
| 254 |
case 0: // solid |
| 255 |
break; |
| 256 |
case 1: |
| 257 |
border.m_type = MWAWBorder::Double; |
| 258 |
break; |
| 259 |
case 2: |
| 260 |
border.m_type = MWAWBorder::Double; |
| 261 |
border.m_widthsList.resize(3,1.); |
| 262 |
border.m_widthsList[0]=2.0; |
| 263 |
break; |
| 264 |
case 3: |
| 265 |
border.m_type = MWAWBorder::Double; |
| 266 |
border.m_widthsList.resize(3,1.); |
| 267 |
border.m_widthsList[2]=2.0; |
| 268 |
break; |
| 269 |
default: |
| 270 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::FrameFormat::addTo: unexpected type\n")); |
| 271 |
break; |
| 272 |
} |
| 273 |
style.setBorders(15, border); |
| 274 |
} |
| 275 |
if (m_style.hasSurfaceColor()) |
| 276 |
style.setBackgroundColor(m_style.m_surfaceColor); |
| 277 |
} |
| 278 |
|
| 279 |
//! operator<< |
| 280 |
friend std::ostream &operator<<(std::ostream &o, FrameFormat const &frmt) |
| 281 |
{ |
| 282 |
o << "style=[" << frmt.m_style << "],"; |
| 283 |
if (frmt.m_borderType) o << "border[type]=" << frmt.m_borderType << ","; |
| 284 |
bool intDiff=false, extDiff=false; |
| 285 |
for (int i=1; i < 4; ++i) { |
| 286 |
if (frmt.m_intWrap[i]<frmt.m_intWrap[0] || frmt.m_intWrap[i]>frmt.m_intWrap[0]) |
| 287 |
intDiff=true; |
| 288 |
if (frmt.m_extWrap[i]<frmt.m_extWrap[0] || frmt.m_extWrap[i]>frmt.m_extWrap[0]) |
| 289 |
extDiff=true; |
| 290 |
} |
| 291 |
if (intDiff) { |
| 292 |
o << "dim/intWrap/border=["; |
| 293 |
for (double i : frmt.m_intWrap) |
| 294 |
o << i << ","; |
| 295 |
o << "],"; |
| 296 |
} |
| 297 |
else |
| 298 |
o << "dim/intWrap/border=" << frmt.m_intWrap[0] << ","; |
| 299 |
if (extDiff) { |
| 300 |
o << "exterior[wrap]=["; |
| 301 |
for (auto &wrap : frmt.m_extWrap) |
| 302 |
o << wrap << ","; |
| 303 |
o << "],"; |
| 304 |
} |
| 305 |
else |
| 306 |
o << "exterior[wrap]=" << frmt.m_extWrap[0] << ","; |
| 307 |
return o; |
| 308 |
} |
| 309 |
//! the graphic style |
| 310 |
MWAWGraphicStyle m_style; |
| 311 |
//! the border type |
| 312 |
int m_borderType; |
| 313 |
//! the interior wrap dim |
| 314 |
double m_intWrap[4]; |
| 315 |
//! the exterior wrap dim |
| 316 |
double m_extWrap[4]; |
| 317 |
}; |
| 318 |
|
| 319 |
//////////////////////////////////////// |
| 320 |
//! Internal: the frame header of a HanMacWrdJGraph |
| 321 |
struct Frame { |
| 322 |
//! constructor |
| 323 |
Frame() |
| 324 |
: m_type(-1) |
| 325 |
, m_fileId(-1) |
| 326 |
, m_id(-1) |
| 327 |
, m_formatId(0) |
| 328 |
, m_page(0) |
| 329 |
, m_pos() |
| 330 |
, m_baseline(0.f) |
| 331 |
, m_inGroup(false) |
| 332 |
, m_parsed(false) |
| 333 |
, m_extra("") |
| 334 |
{ |
| 335 |
} |
| 336 |
Frame(Frame const &)=default; |
| 337 |
//! destructor |
| 338 |
virtual ~Frame(); |
| 339 |
//! return the frame bdbox |
| 340 |
MWAWBox2f getBdBox() const |
| 341 |
{ |
| 342 |
MWAWVec2f minPt(m_pos[0][0], m_pos[0][1]); |
| 343 |
MWAWVec2f maxPt(m_pos[1][0], m_pos[1][1]); |
| 344 |
for (int c=0; c<2; ++c) { |
| 345 |
if (m_pos.size()[c]>=0) continue; |
| 346 |
minPt[c]=m_pos[1][c]; |
| 347 |
maxPt[c]=m_pos[0][c]; |
| 348 |
} |
| 349 |
return MWAWBox2f(minPt,maxPt); |
| 350 |
} |
| 351 |
//! returns true if the frame data are read |
| 352 |
virtual bool valid() const |
| 353 |
{ |
| 354 |
return false; |
| 355 |
} |
| 356 |
//! operator<< |
| 357 |
friend std::ostream &operator<<(std::ostream &o, Frame const &grph); |
| 358 |
//! the graph type |
| 359 |
int m_type; |
| 360 |
//! the file id |
| 361 |
long m_fileId; |
| 362 |
//! the local id |
| 363 |
int m_id; |
| 364 |
//! the format id |
| 365 |
int m_formatId; |
| 366 |
//! the page |
| 367 |
int m_page; |
| 368 |
//! the position |
| 369 |
MWAWBox2f m_pos; |
| 370 |
//! the baseline |
| 371 |
float m_baseline; |
| 372 |
//! true if this node is a group's child |
| 373 |
bool m_inGroup; |
| 374 |
//! true if we have send the data |
| 375 |
mutable bool m_parsed; |
| 376 |
//! an extra string |
| 377 |
std::string m_extra; |
| 378 |
}; |
| 379 |
|
| 380 |
Frame::~Frame() |
| 381 |
{ |
| 382 |
} |
| 383 |
|
| 384 |
std::ostream &operator<<(std::ostream &o, Frame const &grph) |
| 385 |
{ |
| 386 |
switch (grph.m_type) { |
| 387 |
case 0: // text or column |
| 388 |
break; |
| 389 |
case 1: |
| 390 |
o << "header,"; |
| 391 |
break; |
| 392 |
case 2: |
| 393 |
o << "footer,"; |
| 394 |
break; |
| 395 |
case 3: |
| 396 |
o << "footnote[frame],"; |
| 397 |
break; |
| 398 |
case 4: |
| 399 |
o << "textbox,"; |
| 400 |
break; |
| 401 |
case 6: |
| 402 |
o << "picture,"; |
| 403 |
break; |
| 404 |
case 8: |
| 405 |
o << "basicGraphic,"; |
| 406 |
break; |
| 407 |
case 9: |
| 408 |
o << "table,"; |
| 409 |
break; |
| 410 |
case 10: |
| 411 |
o << "comments,"; // memo |
| 412 |
break; |
| 413 |
case 11: |
| 414 |
o << "group"; |
| 415 |
break; |
| 416 |
case 12: |
| 417 |
o << "footnote[sep],"; |
| 418 |
break; |
| 419 |
default: |
| 420 |
o << "#type=" << grph.m_type << ","; |
| 421 |
break; |
| 422 |
case -1: |
| 423 |
break; |
| 424 |
} |
| 425 |
if (grph.m_fileId > 0) |
| 426 |
o << "fileId=" << std::hex << grph.m_fileId << std::dec << ","; |
| 427 |
if (grph.m_id>0) |
| 428 |
o << "id=" << grph.m_id << ","; |
| 429 |
if (grph.m_formatId > 0) |
| 430 |
o << "formatId=" << grph.m_formatId << ","; |
| 431 |
if (grph.m_page) o << "page=" << grph.m_page+1 << ","; |
| 432 |
o << "pos=" << grph.m_pos << ","; |
| 433 |
if (grph.m_baseline < 0 || grph.m_baseline>0) o << "baseline=" << grph.m_baseline << ","; |
| 434 |
o << grph.m_extra; |
| 435 |
return o; |
| 436 |
} |
| 437 |
|
| 438 |
//////////////////////////////////////// |
| 439 |
//! Internal: the comment frame of a HanMacWrdJGraph |
| 440 |
struct CommentFrame final : public Frame { |
| 441 |
public: |
| 442 |
//! constructor |
| 443 |
explicit CommentFrame(Frame const &orig) |
| 444 |
: Frame(orig) |
| 445 |
, m_zId(0) |
| 446 |
, m_width(0) |
| 447 |
, m_cPos(0) |
| 448 |
, m_dim(0,0) |
| 449 |
{ |
| 450 |
} |
| 451 |
//! destructor |
| 452 |
~CommentFrame() final; |
| 453 |
//! returns true if the frame data are read |
| 454 |
bool valid() const final |
| 455 |
{ |
| 456 |
return true; |
| 457 |
} |
| 458 |
//! print local data |
| 459 |
std::string print() const |
| 460 |
{ |
| 461 |
std::stringstream s; |
| 462 |
if (m_zId) s << "zId[TZone]=" << std::hex << m_zId << std::dec << ","; |
| 463 |
if (m_dim[0]>0 || m_dim[1] > 0) |
| 464 |
s << "auxi[dim]=" << m_dim << ","; |
| 465 |
if (m_width > 0) |
| 466 |
s << "width=" << m_width << ","; |
| 467 |
if (m_cPos) |
| 468 |
s << "cPos[first]=" << m_cPos << ","; |
| 469 |
return s.str(); |
| 470 |
} |
| 471 |
//! the text id |
| 472 |
long m_zId; |
| 473 |
//! the zone width |
| 474 |
double m_width; |
| 475 |
//! the first char pos |
| 476 |
long m_cPos; |
| 477 |
//! the auxilliary dim |
| 478 |
MWAWVec2f m_dim; |
| 479 |
}; |
| 480 |
|
| 481 |
CommentFrame::~CommentFrame() |
| 482 |
{ |
| 483 |
} |
| 484 |
|
| 485 |
//////////////////////////////////////// |
| 486 |
//! Internal: a group of a HanMacWrdJGraph |
| 487 |
struct Group final : public Frame { |
| 488 |
public: |
| 489 |
//! constructor |
| 490 |
explicit Group(Frame const &orig) |
| 491 |
: Frame(orig) |
| 492 |
, m_zId(0) |
| 493 |
, m_childsList() |
| 494 |
{ |
| 495 |
} |
| 496 |
//! destructor |
| 497 |
~Group() final; |
| 498 |
//! returns true if the frame data are read |
| 499 |
bool valid() const final |
| 500 |
{ |
| 501 |
return true; |
| 502 |
} |
| 503 |
//! the group id |
| 504 |
long m_zId; |
| 505 |
//! the child list |
| 506 |
std::vector<long> m_childsList; |
| 507 |
}; |
| 508 |
|
| 509 |
Group::~Group() |
| 510 |
{ |
| 511 |
} |
| 512 |
//////////////////////////////////////// |
| 513 |
//! Internal: the picture frame of a HanMacWrdJGraph |
| 514 |
struct PictureFrame final : public Frame { |
| 515 |
public: |
| 516 |
//! constructor |
| 517 |
explicit PictureFrame(Frame const &orig) |
| 518 |
: Frame(orig) |
| 519 |
, m_entry() |
| 520 |
, m_zId(0) |
| 521 |
, m_dim(100,100) |
| 522 |
, m_scale(1,1) |
| 523 |
{ |
| 524 |
} |
| 525 |
//! destructor |
| 526 |
~PictureFrame() final; |
| 527 |
//! returns true if the frame data are read |
| 528 |
bool valid() const final |
| 529 |
{ |
| 530 |
return true; |
| 531 |
} |
| 532 |
//! print local data |
| 533 |
std::string print() const |
| 534 |
{ |
| 535 |
std::stringstream s; |
| 536 |
if (m_zId) s << "zId=" << std::hex << m_zId << std::dec << ","; |
| 537 |
s << "dim[original]=" << m_dim << ","; |
| 538 |
s << "scale=" << m_scale << ","; |
| 539 |
return s.str(); |
| 540 |
} |
| 541 |
//! the picture entry |
| 542 |
MWAWEntry m_entry; |
| 543 |
//! the picture id |
| 544 |
long m_zId; |
| 545 |
//! the picture size |
| 546 |
MWAWVec2i m_dim; |
| 547 |
//! the scale |
| 548 |
MWAWVec2f m_scale; |
| 549 |
}; |
| 550 |
|
| 551 |
PictureFrame::~PictureFrame() |
| 552 |
{ |
| 553 |
} |
| 554 |
|
| 555 |
//////////////////////////////////////// |
| 556 |
//! Internal: a footnote separator of a HanMacWrdJGraph |
| 557 |
struct SeparatorFrame final : public Frame { |
| 558 |
public: |
| 559 |
//! constructor |
| 560 |
explicit SeparatorFrame(Frame const &orig) : Frame(orig) |
| 561 |
{ |
| 562 |
} |
| 563 |
//! destructor |
| 564 |
~SeparatorFrame() final; |
| 565 |
//! returns true if the frame data are read |
| 566 |
bool valid() const final |
| 567 |
{ |
| 568 |
return true; |
| 569 |
} |
| 570 |
}; |
| 571 |
|
| 572 |
SeparatorFrame::~SeparatorFrame() |
| 573 |
{ |
| 574 |
} |
| 575 |
|
| 576 |
//////////////////////////////////////// |
| 577 |
//! Internal: the table frame of a HanMacWrdJGraph |
| 578 |
struct TableFrame final : public Frame { |
| 579 |
public: |
| 580 |
//! constructor |
| 581 |
explicit TableFrame(Frame const &orig) |
| 582 |
: Frame(orig) |
| 583 |
, m_zId(0) |
| 584 |
, m_width(0) |
| 585 |
, m_length(0) |
| 586 |
, m_table() |
| 587 |
{ |
| 588 |
} |
| 589 |
//! destructor |
| 590 |
~TableFrame() final; |
| 591 |
//! returns true if the frame data are read |
| 592 |
bool valid() const final |
| 593 |
{ |
| 594 |
return true; |
| 595 |
} |
| 596 |
//! print local data |
| 597 |
std::string print() const |
| 598 |
{ |
| 599 |
std::stringstream s; |
| 600 |
if (m_zId) s << "zId[TZone]=" << std::hex << m_zId << std::dec << ","; |
| 601 |
if (m_width > 0) |
| 602 |
s << "width=" << m_width << ","; |
| 603 |
if (m_length) |
| 604 |
s << "length[text?]=" << m_length << ","; |
| 605 |
return s.str(); |
| 606 |
} |
| 607 |
//! the textzone id |
| 608 |
long m_zId; |
| 609 |
//! the zone width |
| 610 |
double m_width; |
| 611 |
//! related to text length? |
| 612 |
long m_length; |
| 613 |
//! the table |
| 614 |
std::shared_ptr<Table> m_table; |
| 615 |
}; |
| 616 |
|
| 617 |
TableFrame::~TableFrame() |
| 618 |
{ |
| 619 |
} |
| 620 |
|
| 621 |
//////////////////////////////////////// |
| 622 |
//! Internal: the textbox frame of a HanMacWrdJGraph |
| 623 |
struct TextboxFrame final : public Frame { |
| 624 |
public: |
| 625 |
//! constructor |
| 626 |
explicit TextboxFrame(Frame const &orig) |
| 627 |
: Frame(orig) |
| 628 |
, m_zId(0) |
| 629 |
, m_width(0) |
| 630 |
, m_cPos(0) |
| 631 |
, m_linkToFId(0) |
| 632 |
, m_isLinked(false) |
| 633 |
{ |
| 634 |
} |
| 635 |
//! destructor |
| 636 |
~TextboxFrame() final; |
| 637 |
//! returns true if the frame data are read |
| 638 |
bool valid() const final |
| 639 |
{ |
| 640 |
return true; |
| 641 |
} |
| 642 |
//! returns true if the box is linked to other textbox |
| 643 |
bool isLinked() const |
| 644 |
{ |
| 645 |
return m_linkToFId || m_isLinked; |
| 646 |
} |
| 647 |
//! print local data |
| 648 |
std::string print() const |
| 649 |
{ |
| 650 |
std::stringstream s; |
| 651 |
if (m_zId) s << "zId[TZone]=" << std::hex << m_zId << std::dec << ","; |
| 652 |
if (m_width > 0) |
| 653 |
s << "width=" << m_width << ","; |
| 654 |
if (m_cPos) |
| 655 |
s << "cPos[first]=" << m_cPos << ","; |
| 656 |
return s.str(); |
| 657 |
} |
| 658 |
//! the text id |
| 659 |
long m_zId; |
| 660 |
//! the zone width |
| 661 |
double m_width; |
| 662 |
//! the first char pos |
| 663 |
long m_cPos; |
| 664 |
//! the next link zone |
| 665 |
long m_linkToFId; |
| 666 |
//! true if this zone is linked |
| 667 |
bool m_isLinked; |
| 668 |
}; |
| 669 |
|
| 670 |
TextboxFrame::~TextboxFrame() |
| 671 |
{ |
| 672 |
} |
| 673 |
|
| 674 |
//////////////////////////////////////// |
| 675 |
//! Internal: the text frame (basic, header, footer, footnote) of a HanMacWrdJGraph |
| 676 |
struct TextFrame final : public Frame { |
| 677 |
public: |
| 678 |
//! constructor |
| 679 |
explicit TextFrame(Frame const &orig) : Frame(orig), m_zId(0), m_width(0), m_cPos(0) |
| 680 |
{ |
| 681 |
} |
| 682 |
//! destructor |
| 683 |
~TextFrame() final; |
| 684 |
//! returns true if the frame data are read |
| 685 |
bool valid() const final |
| 686 |
{ |
| 687 |
return true; |
| 688 |
} |
| 689 |
//! print local data |
| 690 |
std::string print() const |
| 691 |
{ |
| 692 |
std::stringstream s; |
| 693 |
if (m_zId) s << "zId[TZone]=" << std::hex << m_zId << std::dec << ","; |
| 694 |
if (m_width > 0) |
| 695 |
s << "width=" << m_width << ","; |
| 696 |
if (m_cPos) |
| 697 |
s << "cPos[first]=" << m_cPos << ","; |
| 698 |
return s.str(); |
| 699 |
} |
| 700 |
//! the text id |
| 701 |
long m_zId; |
| 702 |
//! the zone width |
| 703 |
double m_width; |
| 704 |
//! the first char pos |
| 705 |
long m_cPos; |
| 706 |
}; |
| 707 |
|
| 708 |
TextFrame::~TextFrame() |
| 709 |
{ |
| 710 |
} |
| 711 |
|
| 712 |
//////////////////////////////////////// |
| 713 |
//! Internal: the geometrical graph of a HanMacWrdJGraph |
| 714 |
struct ShapeGraph final : public Frame { |
| 715 |
//! constructor |
| 716 |
explicit ShapeGraph(Frame const &orig) |
| 717 |
: Frame(orig) |
| 718 |
, m_shape() |
| 719 |
, m_arrowsFlag(0) |
| 720 |
{ |
| 721 |
} |
| 722 |
//! destructor |
| 723 |
~ShapeGraph() final; |
| 724 |
//! returns true if the frame data are read |
| 725 |
bool valid() const final |
| 726 |
{ |
| 727 |
return true; |
| 728 |
} |
| 729 |
//! operator<< |
| 730 |
friend std::ostream &operator<<(std::ostream &o, ShapeGraph const &graph) |
| 731 |
{ |
| 732 |
o << graph.print(); |
| 733 |
o << static_cast<Frame const &>(graph); |
| 734 |
return o; |
| 735 |
} |
| 736 |
//! print local data |
| 737 |
std::string print() const |
| 738 |
{ |
| 739 |
std::stringstream s; |
| 740 |
s << m_shape; |
| 741 |
if (m_arrowsFlag&1) s << "startArrow,"; |
| 742 |
if (m_arrowsFlag&2) s << "endArrow,"; |
| 743 |
return s.str(); |
| 744 |
} |
| 745 |
|
| 746 |
//! the shape m_shape |
| 747 |
MWAWGraphicShape m_shape; |
| 748 |
//! the lines arrow flag |
| 749 |
int m_arrowsFlag; |
| 750 |
}; |
| 751 |
|
| 752 |
ShapeGraph::~ShapeGraph() |
| 753 |
{ |
| 754 |
} |
| 755 |
|
| 756 |
//////////////////////////////////////// |
| 757 |
//! Internal: the pattern of a HanMacWrdJGraph |
| 758 |
struct Pattern final : public MWAWGraphicStyle::Pattern { |
| 759 |
//! constructor ( 4 int by patterns ) |
| 760 |
explicit Pattern(uint16_t const *pat=nullptr) |
| 761 |
: MWAWGraphicStyle::Pattern() |
| 762 |
, m_percent(0) |
| 763 |
{ |
| 764 |
if (!pat) return; |
| 765 |
m_colors[0]=MWAWColor::white(); |
| 766 |
m_colors[1]=MWAWColor::black(); |
| 767 |
m_dim=MWAWVec2i(8,8); |
| 768 |
m_data.resize(8); |
| 769 |
for (size_t i=0; i < 4; ++i) { |
| 770 |
uint16_t val=pat[i]; |
| 771 |
m_data[2*i]=static_cast<unsigned char>(val>>8); |
| 772 |
m_data[2*i+1]=static_cast<unsigned char>(val&0xFF); |
| 773 |
} |
| 774 |
int numOnes=0; |
| 775 |
for (size_t j=0; j < 8; ++j) { |
| 776 |
auto val=static_cast<uint8_t>(m_data[j]); |
| 777 |
for (int b=0; b < 8; b++) { |
| 778 |
if (val&1) ++numOnes; |
| 779 |
val = uint8_t(val>>1); |
| 780 |
} |
| 781 |
} |
| 782 |
m_percent=float(numOnes)/64.f; |
| 783 |
} |
| 784 |
Pattern(Pattern const &)=default; |
| 785 |
Pattern &operator=(Pattern const &)=default; |
| 786 |
Pattern &operator=(Pattern &&)=default; |
| 787 |
//! destructor |
| 788 |
~Pattern() final; |
| 789 |
//! the percentage |
| 790 |
float m_percent; |
| 791 |
}; |
| 792 |
|
| 793 |
Pattern::~Pattern() |
| 794 |
{ |
| 795 |
} |
| 796 |
|
| 797 |
//////////////////////////////////////// |
| 798 |
//! Internal: the state of a HanMacWrdJGraph |
| 799 |
struct State { |
| 800 |
//! constructor |
| 801 |
State() |
| 802 |
: m_framesList() |
| 803 |
, m_framesMap() |
| 804 |
, m_frameFormatsList() |
| 805 |
, m_numPages(0) |
| 806 |
, m_colorList() |
| 807 |
, m_patternList() |
| 808 |
, m_defaultFormat() { } |
| 809 |
//! tries to find the lId the frame of a given type |
| 810 |
std::shared_ptr<Frame> findFrame(int type, int lId) const |
| 811 |
{ |
| 812 |
int actId = 0; |
| 813 |
for (auto const &frame : m_framesList) { |
| 814 |
if (!frame || frame->m_type != type) |
| 815 |
continue; |
| 816 |
if (actId++==lId) { |
| 817 |
if (!frame->valid()) |
| 818 |
break; |
| 819 |
return frame; |
| 820 |
} |
| 821 |
} |
| 822 |
return std::shared_ptr<Frame>(); |
| 823 |
} |
| 824 |
//! returns the frame format corresponding to an id |
| 825 |
FrameFormat const &getFrameFormat(int id) const |
| 826 |
{ |
| 827 |
if (id >= 0 && id < static_cast<int>(m_frameFormatsList.size())) |
| 828 |
return m_frameFormatsList[size_t(id)]; |
| 829 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::State::getFrameFormat: can not find format %d\n", id)); |
| 830 |
return m_defaultFormat; |
| 831 |
} |
| 832 |
//! returns a color correspond to an id |
| 833 |
bool getColor(int id, MWAWColor &col) |
| 834 |
{ |
| 835 |
initColors(); |
| 836 |
if (id < 0 || id >= int(m_colorList.size())) { |
| 837 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::State::getColor: can not find color %d\n", id)); |
| 838 |
return false; |
| 839 |
} |
| 840 |
col = m_colorList[size_t(id)]; |
| 841 |
return true; |
| 842 |
} |
| 843 |
//! returns a pattern correspond to an id |
| 844 |
bool getPattern(int id, Pattern &pattern) |
| 845 |
{ |
| 846 |
initPatterns(); |
| 847 |
if (id < 0 || id >= int(m_patternList.size())) { |
| 848 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::State::getPattern: can not find pattern %d\n", id)); |
| 849 |
return false; |
| 850 |
} |
| 851 |
pattern = m_patternList[size_t(id)]; |
| 852 |
return true; |
| 853 |
} |
| 854 |
//! returns a color corresponding to a pattern and a color |
| 855 |
static MWAWColor getColor(MWAWColor col, float pattern) |
| 856 |
{ |
| 857 |
return MWAWColor::barycenter(pattern,col,1.f-pattern,MWAWColor::white()); |
| 858 |
} |
| 859 |
|
| 860 |
//! init the color list |
| 861 |
void initColors(); |
| 862 |
//! init the pattenr list |
| 863 |
void initPatterns(); |
| 864 |
|
| 865 |
/** the list of frames */ |
| 866 |
std::vector<std::shared_ptr<Frame> > m_framesList; |
| 867 |
/** a map zId->frame pos in frames list */ |
| 868 |
std::map<long, int> m_framesMap; |
| 869 |
/** the list of frame format */ |
| 870 |
std::vector<FrameFormat> m_frameFormatsList; |
| 871 |
int m_numPages /* the number of pages */; |
| 872 |
//! a list colorId -> color |
| 873 |
std::vector<MWAWColor> m_colorList; |
| 874 |
//! a list patternId -> pattern |
| 875 |
std::vector<Pattern> m_patternList; |
| 876 |
//! empty format used to return a default format |
| 877 |
FrameFormat m_defaultFormat; |
| 878 |
}; |
| 879 |
|
| 880 |
void State::initPatterns() |
| 881 |
{ |
| 882 |
if (m_patternList.size()) return; |
| 883 |
static uint16_t const s_pattern[4*64] = { |
| 884 |
0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0x7fff, 0xffff, 0xf7ff, 0xffff, 0x7fff, 0xf7ff, 0x7fff, 0xf7ff, |
| 885 |
0xffee, 0xffbb, 0xffee, 0xffbb, 0x77dd, 0x77dd, 0x77dd, 0x77dd, 0xaa55, 0xaa55, 0xaa55, 0xaa55, 0x8822, 0x8822, 0x8822, 0x8822, |
| 886 |
0xaa00, 0xaa00, 0xaa00, 0xaa00, 0xaa00, 0x4400, 0xaa00, 0x1100, 0x8800, 0xaa00, 0x8800, 0xaa00, 0x8800, 0x2200, 0x8800, 0x2200, |
| 887 |
0x8000, 0x0800, 0x8000, 0x0800, 0x8800, 0x0000, 0x8800, 0x0000, 0x8000, 0x0000, 0x0800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, |
| 888 |
0xeedd, 0xbb77, 0xeedd, 0xbb77, 0x3366, 0xcc99, 0x3366, 0xcc99, 0x1122, 0x4488, 0x1122, 0x4488, 0x8307, 0x0e1c, 0x3870, 0xe0c1, |
| 889 |
0x0306, 0x0c18, 0x3060, 0xc081, 0x0102, 0x0408, 0x1020, 0x4080, 0xffff, 0x0000, 0x0000, 0x0000, 0xff00, 0x0000, 0x0000, 0x0000, |
| 890 |
0x77bb, 0xddee, 0x77bb, 0xddee, 0x99cc, 0x6633, 0x99cc, 0x6633, 0x8844, 0x2211, 0x8844, 0x2211, 0xe070, 0x381c, 0x0e07, 0x83c1, |
| 891 |
0xc060, 0x3018, 0x0c06, 0x0381, 0x8040, 0x2010, 0x0804, 0x0201, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0x8080, 0x8080, 0x8080, 0x8080, |
| 892 |
0xffaa, 0xffaa, 0xffaa, 0xffaa, 0xe4e4, 0xe4e4, 0xe4e4, 0xe4e4, 0xffff, 0xff00, 0x00ff, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, |
| 893 |
0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0x0000, 0xff00, 0x0000, 0x8888, 0x8888, 0x8888, 0x8888, 0xff80, 0x8080, 0x8080, 0x8080, |
| 894 |
0x4ecf, 0xfce4, 0x473f, 0xf372, 0x6006, 0x36b1, 0x8118, 0x1b63, 0x2004, 0x4002, 0x1080, 0x0801, 0x9060, 0x0609, 0x9060, 0x0609, |
| 895 |
0x8814, 0x2241, 0x8800, 0xaa00, 0x2050, 0x8888, 0x8888, 0x0502, 0xaa00, 0x8000, 0x8800, 0x8000, 0x2040, 0x8000, 0x0804, 0x0200, |
| 896 |
0xf0f0, 0xf0f0, 0x0f0f, 0x0f0f, 0x0077, 0x7777, 0x0077, 0x7777, 0xff88, 0x8888, 0xff88, 0x8888, 0xaa44, 0xaa11, 0xaa44, 0xaa11, |
| 897 |
0x8244, 0x2810, 0x2844, 0x8201, 0x8080, 0x413e, 0x0808, 0x14e3, 0x8142, 0x2418, 0x1020, 0x4080, 0x40a0, 0x0000, 0x040a, 0x0000, |
| 898 |
0x7789, 0x8f8f, 0x7798, 0xf8f8, 0xf1f8, 0x6cc6, 0x8f1f, 0x3663, 0xbf00, 0xbfbf, 0xb0b0, 0xb0b0, 0xff80, 0x8080, 0xff08, 0x0808, |
| 899 |
0x1020, 0x54aa, 0xff02, 0x0408, 0x0008, 0x142a, 0x552a, 0x1408, 0x55a0, 0x4040, 0x550a, 0x0404, 0x8244, 0x3944, 0x8201, 0x0101 |
| 900 |
}; |
| 901 |
|
| 902 |
m_patternList.resize(64); |
| 903 |
for (size_t i=0; i < 64; ++i) |
| 904 |
m_patternList[i] = Pattern(&s_pattern[i*4]); |
| 905 |
} |
| 906 |
|
| 907 |
void State::initColors() |
| 908 |
{ |
| 909 |
if (m_colorList.size()) return; |
| 910 |
uint32_t const defCol[256] = { |
| 911 |
0x000000, 0xffffff, 0xffffcc, 0xffff99, 0xffff66, 0xffff33, 0xffff00, 0xffccff, |
| 912 |
0xffcccc, 0xffcc99, 0xffcc66, 0xffcc33, 0xffcc00, 0xff99ff, 0xff99cc, 0xff9999, |
| 913 |
0xff9966, 0xff9933, 0xff9900, 0xff66ff, 0xff66cc, 0xff6699, 0xff6666, 0xff6633, |
| 914 |
0xff6600, 0xff33ff, 0xff33cc, 0xff3399, 0xff3366, 0xff3333, 0xff3300, 0xff00ff, |
| 915 |
0xff00cc, 0xff0099, 0xff0066, 0xff0033, 0xff0000, 0xccffff, 0xccffcc, 0xccff99, |
| 916 |
0xccff66, 0xccff33, 0xccff00, 0xccccff, 0xcccccc, 0xcccc99, 0xcccc66, 0xcccc33, |
| 917 |
0xcccc00, 0xcc99ff, 0xcc99cc, 0xcc9999, 0xcc9966, 0xcc9933, 0xcc9900, 0xcc66ff, |
| 918 |
0xcc66cc, 0xcc6699, 0xcc6666, 0xcc6633, 0xcc6600, 0xcc33ff, 0xcc33cc, 0xcc3399, |
| 919 |
0xcc3366, 0xcc3333, 0xcc3300, 0xcc00ff, 0xcc00cc, 0xcc0099, 0xcc0066, 0xcc0033, |
| 920 |
0xcc0000, 0x99ffff, 0x99ffcc, 0x99ff99, 0x99ff66, 0x99ff33, 0x99ff00, 0x99ccff, |
| 921 |
0x99cccc, 0x99cc99, 0x99cc66, 0x99cc33, 0x99cc00, 0x9999ff, 0x9999cc, 0x999999, |
| 922 |
0x999966, 0x999933, 0x999900, 0x9966ff, 0x9966cc, 0x996699, 0x996666, 0x996633, |
| 923 |
0x996600, 0x9933ff, 0x9933cc, 0x993399, 0x993366, 0x993333, 0x993300, 0x9900ff, |
| 924 |
0x9900cc, 0x990099, 0x990066, 0x990033, 0x990000, 0x66ffff, 0x66ffcc, 0x66ff99, |
| 925 |
0x66ff66, 0x66ff33, 0x66ff00, 0x66ccff, 0x66cccc, 0x66cc99, 0x66cc66, 0x66cc33, |
| 926 |
0x66cc00, 0x6699ff, 0x6699cc, 0x669999, 0x669966, 0x669933, 0x669900, 0x6666ff, |
| 927 |
0x6666cc, 0x666699, 0x666666, 0x666633, 0x666600, 0x6633ff, 0x6633cc, 0x663399, |
| 928 |
0x663366, 0x663333, 0x663300, 0x6600ff, 0x6600cc, 0x660099, 0x660066, 0x660033, |
| 929 |
0x660000, 0x33ffff, 0x33ffcc, 0x33ff99, 0x33ff66, 0x33ff33, 0x33ff00, 0x33ccff, |
| 930 |
0x33cccc, 0x33cc99, 0x33cc66, 0x33cc33, 0x33cc00, 0x3399ff, 0x3399cc, 0x339999, |
| 931 |
0x339966, 0x339933, 0x339900, 0x3366ff, 0x3366cc, 0x336699, 0x336666, 0x336633, |
| 932 |
0x336600, 0x3333ff, 0x3333cc, 0x333399, 0x333366, 0x333333, 0x333300, 0x3300ff, |
| 933 |
0x3300cc, 0x330099, 0x330066, 0x330033, 0x330000, 0x00ffff, 0x00ffcc, 0x00ff99, |
| 934 |
0x00ff66, 0x00ff33, 0x00ff00, 0x00ccff, 0x00cccc, 0x00cc99, 0x00cc66, 0x00cc33, |
| 935 |
0x00cc00, 0x0099ff, 0x0099cc, 0x009999, 0x009966, 0x009933, 0x009900, 0x0066ff, |
| 936 |
0x0066cc, 0x006699, 0x006666, 0x006633, 0x006600, 0x0033ff, 0x0033cc, 0x003399, |
| 937 |
0x003366, 0x003333, 0x003300, 0x0000ff, 0x0000cc, 0x000099, 0x000066, 0x000033, |
| 938 |
0xee0000, 0xdd0000, 0xbb0000, 0xaa0000, 0x880000, 0x770000, 0x550000, 0x440000, |
| 939 |
0x220000, 0x110000, 0x00ee00, 0x00dd00, 0x00bb00, 0x00aa00, 0x008800, 0x007700, |
| 940 |
0x005500, 0x004400, 0x002200, 0x001100, 0x0000ee, 0x0000dd, 0x0000bb, 0x0000aa, |
| 941 |
0x000088, 0x000077, 0x000055, 0x000044, 0x000022, 0x000011, 0xeeeeee, 0xdddddd, |
| 942 |
0xbbbbbb, 0xaaaaaa, 0x888888, 0x777777, 0x555555, 0x444444, 0x222222, 0x111111, |
| 943 |
}; |
| 944 |
m_colorList.resize(256); |
| 945 |
for (size_t i = 0; i < 256; ++i) |
| 946 |
m_colorList[i] = defCol[i]; |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
//////////////////////////////////////// |
| 951 |
//! Internal: the subdocument of a HanMacWrdJGraph |
| 952 |
class SubDocument final : public MWAWSubDocument |
| 953 |
{ |
| 954 |
public: |
| 955 |
//! the document type |
| 956 |
enum Type { FrameInFrame, Group, Text, UnformattedTable, EmptyPicture }; |
| 957 |
//! constructor |
| 958 |
SubDocument(HanMacWrdJGraph &pars, MWAWInputStreamPtr const &input, Type type, long id, long firstChar=0) |
| 959 |
: MWAWSubDocument(pars.m_mainParser, input, MWAWEntry()) |
| 960 |
, m_graphParser(&pars) |
| 961 |
, m_type(type) |
| 962 |
, m_id(id) |
| 963 |
, m_firstChar(firstChar) |
| 964 |
, m_pos() {} |
| 965 |
|
| 966 |
//! constructor |
| 967 |
SubDocument(HanMacWrdJGraph &pars, MWAWInputStreamPtr const &input, MWAWPosition const &pos, Type type, long id, int firstChar=0) |
| 968 |
: MWAWSubDocument(pars.m_mainParser, input, MWAWEntry()) |
| 969 |
, m_graphParser(&pars) |
| 970 |
, m_type(type) |
| 971 |
, m_id(id) |
| 972 |
, m_firstChar(firstChar) |
| 973 |
, m_pos(pos) {} |
| 974 |
|
| 975 |
//! destructor |
| 976 |
~SubDocument() final {} |
| 977 |
|
| 978 |
//! operator!= |
| 979 |
bool operator!=(MWAWSubDocument const &doc) const final; |
| 980 |
|
| 981 |
//! the parser function |
| 982 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 983 |
|
| 984 |
protected: |
| 985 |
/** the graph parser */ |
| 986 |
HanMacWrdJGraph *m_graphParser; |
| 987 |
//! the zone type |
| 988 |
Type m_type; |
| 989 |
//! the zone id |
| 990 |
long m_id; |
| 991 |
//! the first char position |
| 992 |
long m_firstChar; |
| 993 |
//! the position in a frame |
| 994 |
MWAWPosition m_pos; |
| 995 |
|
| 996 |
private: |
| 997 |
SubDocument(SubDocument const &orig) = delete; |
| 998 |
SubDocument &operator=(SubDocument const &orig) = delete; |
| 999 |
}; |
| 1000 |
|
| 1001 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/) |
| 1002 |
{ |
| 1003 |
if (!listener.get()) { |
| 1004 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::SubDocument::parse: no listener\n")); |
| 1005 |
return; |
| 1006 |
} |
| 1007 |
if (!m_graphParser) { |
| 1008 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::SubDocument::parse: no parser\n")); |
| 1009 |
return; |
| 1010 |
} |
| 1011 |
|
| 1012 |
long pos = m_input->tell(); |
| 1013 |
if (listener->getType()==MWAWListener::Graphic) { |
| 1014 |
if (m_type==Text) |
| 1015 |
m_graphParser->sendText(m_id, m_firstChar, listener); |
| 1016 |
else { |
| 1017 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::SubDocument::parse: send type %d is not implemented\n", m_type)); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
else { |
| 1021 |
switch (m_type) { |
| 1022 |
case EmptyPicture: |
| 1023 |
m_graphParser->sendEmptyPicture(m_pos); |
| 1024 |
break; |
| 1025 |
case Group: |
| 1026 |
m_graphParser->sendGroup(m_id, m_pos); |
| 1027 |
break; |
| 1028 |
case FrameInFrame: |
| 1029 |
m_graphParser->sendFrame(m_id, m_pos); |
| 1030 |
break; |
| 1031 |
case Text: |
| 1032 |
m_graphParser->sendText(m_id, m_firstChar); |
| 1033 |
break; |
| 1034 |
case UnformattedTable: |
| 1035 |
m_graphParser->sendTableUnformatted(m_id); |
| 1036 |
break; |
| 1037 |
#if !defined(__clang__) |
| 1038 |
default: |
| 1039 |
MWAW_DEBUG_MSG(("HanMacWrdJGraphInternal::SubDocument::parse: send type %d is not implemented\n", m_type)); |
| 1040 |
break; |
| 1041 |
#endif |
| 1042 |
} |
| 1043 |
} |
| 1044 |
m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1045 |
} |
| 1046 |
|
| 1047 |
bool SubDocument::operator!=(MWAWSubDocument const &doc) const |
| 1048 |
{ |
| 1049 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 1050 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 1051 |
if (!sDoc) return true; |
| 1052 |
if (m_graphParser != sDoc->m_graphParser) return true; |
| 1053 |
if (m_type != sDoc->m_type) return true; |
| 1054 |
if (m_id != sDoc->m_id) return true; |
| 1055 |
if (m_firstChar != sDoc->m_firstChar) return true; |
| 1056 |
if (m_pos != sDoc->m_pos) return true; |
| 1057 |
return false; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
//////////////////////////////////////////////////////////// |
| 1062 |
// constructor/destructor, ... |
| 1063 |
//////////////////////////////////////////////////////////// |
| 1064 |
HanMacWrdJGraph::HanMacWrdJGraph(HanMacWrdJParser &parser) |
| 1065 |
: m_parserState(parser.getParserState()) |
| 1066 |
, m_state(new HanMacWrdJGraphInternal::State) |
| 1067 |
, m_mainParser(&parser) |
| 1068 |
{ |
| 1069 |
} |
| 1070 |
|
| 1071 |
HanMacWrdJGraph::~HanMacWrdJGraph() |
| 1072 |
{ |
| 1073 |
} |
| 1074 |
|
| 1075 |
int HanMacWrdJGraph::version() const |
| 1076 |
{ |
| 1077 |
return m_parserState->m_version; |
| 1078 |
} |
| 1079 |
|
| 1080 |
bool HanMacWrdJGraph::getColor(int colId, int patternId, MWAWColor &color) const |
| 1081 |
{ |
| 1082 |
if (!m_state->getColor(colId, color)) { |
| 1083 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::getColor: can not find color for id=%d\n", colId)); |
| 1084 |
return false; |
| 1085 |
} |
| 1086 |
HanMacWrdJGraphInternal::Pattern pattern; |
| 1087 |
if (!m_state->getPattern(patternId, pattern)) { |
| 1088 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::getColor: can not find pattern for id=%d\n", patternId)); |
| 1089 |
return false; |
| 1090 |
} |
| 1091 |
color = m_state->getColor(color, pattern.m_percent); |
| 1092 |
return true; |
| 1093 |
} |
| 1094 |
|
| 1095 |
int HanMacWrdJGraph::numPages() const |
| 1096 |
{ |
| 1097 |
if (m_state->m_numPages) |
| 1098 |
return m_state->m_numPages; |
| 1099 |
int nPages = 0; |
| 1100 |
for (auto const &frame : m_state->m_framesList) { |
| 1101 |
if (!frame || !frame->valid()) continue; |
| 1102 |
int page = frame->m_page+1; |
| 1103 |
if (page <= nPages) continue; |
| 1104 |
if (page >= nPages+100) continue; // a pb ? |
| 1105 |
nPages = page; |
| 1106 |
} |
| 1107 |
m_state->m_numPages = nPages; |
| 1108 |
return nPages; |
| 1109 |
} |
| 1110 |
|
| 1111 |
bool HanMacWrdJGraph::sendText(long textId, long fPos, MWAWListenerPtr const &listener) |
| 1112 |
{ |
| 1113 |
return m_mainParser->sendText(textId, fPos, listener); |
| 1114 |
} |
| 1115 |
|
| 1116 |
std::map<long,int> HanMacWrdJGraph::getTextFrameInformations() const |
| 1117 |
{ |
| 1118 |
std::map<long,int> mapIdType; |
| 1119 |
for (auto const &frame : m_state->m_framesList) { |
| 1120 |
if (!frame || !frame->valid()) |
| 1121 |
continue; |
| 1122 |
long zId=0; |
| 1123 |
switch (frame->m_type) { |
| 1124 |
case 0: |
| 1125 |
case 1: |
| 1126 |
case 2: |
| 1127 |
case 3: |
| 1128 |
zId=static_cast<HanMacWrdJGraphInternal::TextFrame const &>(*frame).m_zId; |
| 1129 |
break; |
| 1130 |
case 4: |
| 1131 |
zId=static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(*frame).m_zId; |
| 1132 |
break; |
| 1133 |
case 9: |
| 1134 |
zId=static_cast<HanMacWrdJGraphInternal::TableFrame const &>(*frame).m_zId; |
| 1135 |
break; |
| 1136 |
case 10: |
| 1137 |
zId=static_cast<HanMacWrdJGraphInternal::CommentFrame const &>(*frame).m_zId; |
| 1138 |
break; |
| 1139 |
default: |
| 1140 |
break; |
| 1141 |
} |
| 1142 |
if (!zId) continue; |
| 1143 |
if (mapIdType.find(zId) == mapIdType.end()) |
| 1144 |
mapIdType[zId] = frame->m_type; |
| 1145 |
else if (mapIdType.find(zId)->second != frame->m_type) { |
| 1146 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::getTextFrameInformations: id %lx already set\n", static_cast<long unsigned int>(zId))); |
| 1147 |
} |
| 1148 |
} |
| 1149 |
return mapIdType; |
| 1150 |
} |
| 1151 |
|
| 1152 |
bool HanMacWrdJGraph::getFootnoteInformations(long &textZId, std::vector<long> &fPosList) const |
| 1153 |
{ |
| 1154 |
fPosList.clear(); |
| 1155 |
textZId = 0; |
| 1156 |
for (auto const &frame : m_state->m_framesList) { |
| 1157 |
if (!frame || !frame->valid() || frame->m_type != 3) |
| 1158 |
continue; |
| 1159 |
auto const &text=static_cast<HanMacWrdJGraphInternal::TextFrame const &>(*frame); |
| 1160 |
if (textZId && text.m_zId != textZId) { |
| 1161 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: find different textIds\n")); |
| 1162 |
} |
| 1163 |
else if (!textZId) |
| 1164 |
textZId = text.m_zId; |
| 1165 |
fPosList.push_back(text.m_cPos); |
| 1166 |
} |
| 1167 |
return fPosList.size(); |
| 1168 |
} |
| 1169 |
|
| 1170 |
//////////////////////////////////////////////////////////// |
| 1171 |
// |
| 1172 |
// Intermediate level |
| 1173 |
// |
| 1174 |
//////////////////////////////////////////////////////////// |
| 1175 |
bool HanMacWrdJGraph::readFrames(MWAWEntry const &entry) |
| 1176 |
{ |
| 1177 |
if (!entry.valid()) { |
| 1178 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: called without any entry\n")); |
| 1179 |
return false; |
| 1180 |
} |
| 1181 |
if (entry.length() <= 8) { |
| 1182 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: the entry seems too short\n")); |
| 1183 |
return false; |
| 1184 |
} |
| 1185 |
|
| 1186 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1187 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1188 |
libmwaw::DebugStream f; |
| 1189 |
entry.setParsed(true); |
| 1190 |
|
| 1191 |
long pos = entry.begin()+8; // skip header |
| 1192 |
long endPos = entry.end(); |
| 1193 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1194 |
|
| 1195 |
// first read the header |
| 1196 |
f << entry.name() << "[header]:"; |
| 1197 |
HanMacWrdJZoneHeader mainHeader(true); |
| 1198 |
if (!m_mainParser->readClassicHeader(mainHeader,endPos) || mainHeader.m_fieldSize != 4 || |
| 1199 |
16+12+mainHeader.m_n*4 > mainHeader.m_length) { |
| 1200 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: can not read the header\n")); |
| 1201 |
f << "###sz=" << mainHeader.m_length; |
| 1202 |
asciiFile.addPos(pos); |
| 1203 |
asciiFile.addNote(f.str().c_str()); |
| 1204 |
return false; |
| 1205 |
} |
| 1206 |
long headerEnd=pos+4+mainHeader.m_length; |
| 1207 |
long val; |
| 1208 |
for (int i = 0; i < 2; ++i) { |
| 1209 |
val = long(input->readULong(4)); |
| 1210 |
f << "id" << i << "=" << std::hex << val << std::dec << ","; |
| 1211 |
} |
| 1212 |
for (int i = 0; i < 2; ++i) { // f0:small number, 0 |
| 1213 |
val = input->readLong(2); |
| 1214 |
if (val) |
| 1215 |
f << "f" << i << "=" << val << ","; |
| 1216 |
} |
| 1217 |
f << "listIds=["; |
| 1218 |
std::vector<long> lIds(size_t(mainHeader.m_n)); |
| 1219 |
for (int i = 0; i < mainHeader.m_n; ++i) { |
| 1220 |
val = long(input->readULong(4)); |
| 1221 |
lIds[size_t(i)]=val; |
| 1222 |
m_state->m_framesMap[val]=i; |
| 1223 |
f << std::hex << val << std::dec << ","; |
| 1224 |
} |
| 1225 |
f << std::dec << "],"; |
| 1226 |
if (input->tell()!=headerEnd) { |
| 1227 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 1228 |
input->seek(headerEnd, librevenge::RVNG_SEEK_SET); |
| 1229 |
} |
| 1230 |
asciiFile.addPos(pos); |
| 1231 |
asciiFile.addNote(f.str().c_str()); |
| 1232 |
// the data |
| 1233 |
m_state->m_framesList.resize(size_t(mainHeader.m_n)); |
| 1234 |
for (int i = 0; i < mainHeader.m_n; ++i) { |
| 1235 |
pos = input->tell(); |
| 1236 |
auto frame=readFrame(i); |
| 1237 |
if (!frame) { |
| 1238 |
f << "###"; |
| 1239 |
asciiFile.addPos(pos); |
| 1240 |
asciiFile.addNote(f.str().c_str()); |
| 1241 |
return false; |
| 1242 |
} |
| 1243 |
frame->m_fileId = lIds[size_t(i)]; |
| 1244 |
m_state->m_framesList[size_t(i)]=frame; |
| 1245 |
} |
| 1246 |
|
| 1247 |
// normally there remains 2 block, ... |
| 1248 |
|
| 1249 |
// block 0 |
| 1250 |
pos = input->tell(); |
| 1251 |
f.str(""); |
| 1252 |
f << entry.name() << "-Format:"; |
| 1253 |
HanMacWrdJZoneHeader header(false); |
| 1254 |
if (!m_mainParser->readClassicHeader(header,endPos) || header.m_fieldSize!=48) { |
| 1255 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: can not read auxilliary block A\n")); |
| 1256 |
f << "###" << header; |
| 1257 |
asciiFile.addPos(pos); |
| 1258 |
asciiFile.addNote(f.str().c_str()); |
| 1259 |
return false; |
| 1260 |
} |
| 1261 |
long zoneEnd=pos+4+header.m_length; |
| 1262 |
f << header; |
| 1263 |
asciiFile.addPos(pos); |
| 1264 |
asciiFile.addNote(f.str().c_str()); |
| 1265 |
|
| 1266 |
for (int i = 0; i < header.m_n; ++i) { |
| 1267 |
HanMacWrdJGraphInternal::FrameFormat format; |
| 1268 |
MWAWGraphicStyle &style=format.m_style; |
| 1269 |
pos=input->tell(); |
| 1270 |
f.str(""); |
| 1271 |
val = input->readLong(2); |
| 1272 |
if (val != -2) |
| 1273 |
f << "f0=" << val << ","; |
| 1274 |
val = long(input->readULong(2)); |
| 1275 |
if (val) |
| 1276 |
f << "f1=" << std::hex << val << std::dec << ","; |
| 1277 |
for (auto &wrap : format.m_intWrap) wrap = double(input->readLong(4))/65536.; |
| 1278 |
for (auto &wrap : format.m_extWrap) wrap = double(input->readLong(4))/65536.; |
| 1279 |
style.m_lineWidth= float(input->readLong(4))/65536.f; |
| 1280 |
format.m_borderType= static_cast<int>(input->readULong(1)); |
| 1281 |
for (int j = 0; j < 2; j++) { |
| 1282 |
auto color = static_cast<int>(input->readULong(1)); |
| 1283 |
MWAWColor col = j==0 ? MWAWColor::black() : MWAWColor::white(); |
| 1284 |
if (!m_state->getColor(color, col)) |
| 1285 |
f << "#color[" << j << "]=" << color << ","; |
| 1286 |
auto pattern = static_cast<int>(input->readULong(1)); |
| 1287 |
if (pattern==0) { |
| 1288 |
if (i==0) style.m_lineOpacity=0; |
| 1289 |
else style.m_surfaceOpacity=0; |
| 1290 |
continue; |
| 1291 |
} |
| 1292 |
HanMacWrdJGraphInternal::Pattern pat; |
| 1293 |
if (m_state->getPattern(pattern, pat)) { |
| 1294 |
pat.m_colors[1]=col; |
| 1295 |
if (!pat.getUniqueColor(col)) { |
| 1296 |
pat.getAverageColor(col); |
| 1297 |
if (j) style.setPattern(pat); |
| 1298 |
} |
| 1299 |
} |
| 1300 |
else |
| 1301 |
f << "#pattern[" << j << "]=" << pattern << ","; |
| 1302 |
if (j==0) |
| 1303 |
style.m_lineColor=col; |
| 1304 |
else |
| 1305 |
style.setSurfaceColor(col,1); |
| 1306 |
} |
| 1307 |
for (int j = 0; j < 3; j++) { // always 0 |
| 1308 |
val = static_cast<int>(input->readULong(1)); |
| 1309 |
if (val) f << "g" << j << "=" << val << ","; |
| 1310 |
} |
| 1311 |
format.m_style.m_extra=f.str(); |
| 1312 |
m_state->m_frameFormatsList.push_back(format); |
| 1313 |
f.str(""); |
| 1314 |
f << entry.name() << "-F" << i << ":" << format; |
| 1315 |
asciiFile.addPos(pos); |
| 1316 |
asciiFile.addNote(f.str().c_str()); |
| 1317 |
input->seek(pos+48, librevenge::RVNG_SEEK_SET); |
| 1318 |
} |
| 1319 |
input->seek(zoneEnd, librevenge::RVNG_SEEK_SET); |
| 1320 |
|
| 1321 |
// block B |
| 1322 |
pos = input->tell(); |
| 1323 |
f.str(""); |
| 1324 |
f << entry.name() << "-B:"; |
| 1325 |
header=HanMacWrdJZoneHeader(false); |
| 1326 |
if (!m_mainParser->readClassicHeader(header,endPos) || header.m_fieldSize!=8 || |
| 1327 |
16+2+header.m_n*8 > header.m_length) { |
| 1328 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: can not read auxilliary block B\n")); |
| 1329 |
f << "###" << header; |
| 1330 |
asciiFile.addPos(pos); |
| 1331 |
asciiFile.addNote(f.str().c_str()); |
| 1332 |
return false; |
| 1333 |
} |
| 1334 |
for (int i = 0; i < 2; ++i) { // f0=1|3|4=N? |
| 1335 |
val = input->readLong(2); |
| 1336 |
if (val) f << "f" << i << "=" << val << ","; |
| 1337 |
} |
| 1338 |
f << "unk=["; |
| 1339 |
for (int i = 0; i < header.m_n; ++i) { |
| 1340 |
f << "["; |
| 1341 |
for (int j = 0; j < 2; j++) { // always 0? |
| 1342 |
val = input->readLong(2); |
| 1343 |
if (val) f << val << ","; |
| 1344 |
else f << "_,"; |
| 1345 |
} |
| 1346 |
f << std::hex << input->readULong(4) << std::dec; // id |
| 1347 |
f << "],"; |
| 1348 |
} |
| 1349 |
zoneEnd=pos+4+header.m_length; |
| 1350 |
f << header; |
| 1351 |
input->seek(zoneEnd, librevenge::RVNG_SEEK_SET); |
| 1352 |
asciiFile.addPos(pos); |
| 1353 |
asciiFile.addNote(f.str().c_str()); |
| 1354 |
|
| 1355 |
// and for each n, a list |
| 1356 |
for (int i = 0; i < header.m_n; ++i) { |
| 1357 |
pos = input->tell(); |
| 1358 |
f.str(""); |
| 1359 |
f << entry.name() << "-B" << i << ":"; |
| 1360 |
HanMacWrdJZoneHeader lHeader(false); |
| 1361 |
if (!m_mainParser->readClassicHeader(lHeader,endPos) || lHeader.m_fieldSize!=4) { |
| 1362 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: can not read auxilliary block B%d\n",i)); |
| 1363 |
f << "###" << lHeader; |
| 1364 |
asciiFile.addPos(pos); |
| 1365 |
asciiFile.addNote(f.str().c_str()); |
| 1366 |
return false; |
| 1367 |
} |
| 1368 |
f << "listId?=[" << std::hex; |
| 1369 |
for (int j = 0; j < lHeader.m_n; j++) { |
| 1370 |
val = long(input->readULong(4)); |
| 1371 |
f << val << ","; |
| 1372 |
} |
| 1373 |
f << std::dec << "],"; |
| 1374 |
|
| 1375 |
zoneEnd=pos+4+lHeader.m_length; |
| 1376 |
f << header; |
| 1377 |
input->seek(zoneEnd, librevenge::RVNG_SEEK_SET); |
| 1378 |
asciiFile.addPos(pos); |
| 1379 |
asciiFile.addNote(f.str().c_str()); |
| 1380 |
} |
| 1381 |
|
| 1382 |
asciiFile.addPos(endPos); |
| 1383 |
asciiFile.addNote("_"); |
| 1384 |
pos = input->tell(); |
| 1385 |
if (pos!=endPos) { |
| 1386 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrames: find unexpected end data\n")); |
| 1387 |
f.str(""); |
| 1388 |
f << entry.name() << "###:"; |
| 1389 |
asciiFile.addPos(pos); |
| 1390 |
asciiFile.addNote(f.str().c_str()); |
| 1391 |
} |
| 1392 |
return true; |
| 1393 |
} |
| 1394 |
|
| 1395 |
std::shared_ptr<HanMacWrdJGraphInternal::Frame> HanMacWrdJGraph::readFrame(int id) |
| 1396 |
{ |
| 1397 |
std::shared_ptr<HanMacWrdJGraphInternal::Frame> res; |
| 1398 |
HanMacWrdJGraphInternal::Frame graph; |
| 1399 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1400 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1401 |
libmwaw::DebugStream f; |
| 1402 |
|
| 1403 |
long pos = input->tell(); |
| 1404 |
auto len = long(input->readULong(4)); |
| 1405 |
long endPos = pos+4+len; |
| 1406 |
if (len < 32 || !input->checkPosition(endPos)) { |
| 1407 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrame: can not read the frame length\n")); |
| 1408 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1409 |
return res; |
| 1410 |
} |
| 1411 |
|
| 1412 |
auto fl = static_cast<int>(input->readULong(1)); |
| 1413 |
graph.m_type=(fl>>4); |
| 1414 |
f << "f0=" << std::hex << (fl&0xf) << std::dec << ","; |
| 1415 |
int val; |
| 1416 |
/* fl0=[0|1|2|3|4|6|8|9|a|b|c][2|6], fl1=0|1|20|24, |
| 1417 |
fl2=0|8|c|e|10|14|14|40|8a, fl3=0|10|80|c0 */ |
| 1418 |
for (int i = 1; i < 4; ++i) { |
| 1419 |
val = static_cast<int>(input->readULong(1)); |
| 1420 |
if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ","; |
| 1421 |
} |
| 1422 |
graph.m_page = static_cast<int>(input->readLong(2)); |
| 1423 |
graph.m_formatId = static_cast<int>(input->readULong(2)); |
| 1424 |
float dim[4]; |
| 1425 |
for (auto &d : dim) d = float(input->readLong(4))/65536.f; |
| 1426 |
graph.m_pos = MWAWBox2f(MWAWVec2f(dim[0],dim[1]),MWAWVec2f(dim[2],dim[3])); |
| 1427 |
graph.m_id = static_cast<int>(input->readLong(2)); // check me |
| 1428 |
val = static_cast<int>(input->readLong(2)); |
| 1429 |
if (val) f << "f1=" << val << ","; |
| 1430 |
graph.m_baseline = float(input->readLong(4))/65536.f; |
| 1431 |
graph.m_extra = f.str(); |
| 1432 |
|
| 1433 |
f.str(""); |
| 1434 |
f << "FrameDef-" << id << ":" << graph; |
| 1435 |
asciiFile.addPos(pos); |
| 1436 |
asciiFile.addNote(f.str().c_str()); |
| 1437 |
|
| 1438 |
switch (graph.m_type) { |
| 1439 |
case 0: // text |
| 1440 |
case 1: // header |
| 1441 |
case 2: // footer |
| 1442 |
case 3: // footnote |
| 1443 |
res=readTextData(graph, endPos); |
| 1444 |
break; |
| 1445 |
case 4: |
| 1446 |
res=readTextboxData(graph, endPos); |
| 1447 |
break; |
| 1448 |
case 6: |
| 1449 |
res=readPictureData(graph, endPos); |
| 1450 |
break; |
| 1451 |
case 8: |
| 1452 |
res=readShapeGraph(graph, endPos); |
| 1453 |
break; |
| 1454 |
case 9: |
| 1455 |
res=readTableData(graph, endPos); |
| 1456 |
break; |
| 1457 |
case 10: |
| 1458 |
res=readCommentData(graph, endPos); |
| 1459 |
break; |
| 1460 |
case 11: |
| 1461 |
if (len < 36) { |
| 1462 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrame: can not read the group id\n")); |
| 1463 |
break; |
| 1464 |
} |
| 1465 |
else { |
| 1466 |
auto group = std::make_shared<HanMacWrdJGraphInternal::Group>(graph); |
| 1467 |
res = group; |
| 1468 |
pos =input->tell(); |
| 1469 |
group->m_zId = long(input->readULong(4)); |
| 1470 |
f.str(""); |
| 1471 |
f << "FrameDef-group:zId=" << std::hex << group->m_zId << std::dec << ","; |
| 1472 |
asciiFile.addPos(pos); |
| 1473 |
asciiFile.addNote(f.str().c_str()); |
| 1474 |
break; |
| 1475 |
} |
| 1476 |
case 12: |
| 1477 |
if (len < 52) { |
| 1478 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readFrame: can not read the footnote[sep] data\n")); |
| 1479 |
break; |
| 1480 |
} |
| 1481 |
else { |
| 1482 |
auto sep = std::make_shared<HanMacWrdJGraphInternal::SeparatorFrame>(graph); |
| 1483 |
res = sep; |
| 1484 |
pos =input->tell(); |
| 1485 |
f.str(""); |
| 1486 |
f << "FrameDef-footnote[sep];"; |
| 1487 |
for (int i = 0; i < 8; ++i) { // f0=256,f2=8,f4=2,f6=146 |
| 1488 |
val = static_cast<int>(input->readLong(2)); |
| 1489 |
if (val) f << "f" << i << "=" << val << ","; |
| 1490 |
} |
| 1491 |
f << "zId=" << std::hex << long(input->readULong(4)) << std::dec << ","; |
| 1492 |
asciiFile.addPos(pos); |
| 1493 |
asciiFile.addNote(f.str().c_str()); |
| 1494 |
break; |
| 1495 |
} |
| 1496 |
default: |
| 1497 |
break; |
| 1498 |
} |
| 1499 |
if (!res) |
| 1500 |
res.reset(new HanMacWrdJGraphInternal::Frame(graph)); |
| 1501 |
if (input->tell() != endPos) |
| 1502 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 1503 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1504 |
return res; |
| 1505 |
} |
| 1506 |
|
| 1507 |
bool HanMacWrdJGraph::readGroupData(MWAWEntry const &entry, int actZone) |
| 1508 |
{ |
| 1509 |
if (!entry.valid()) { |
| 1510 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGroupData: called without any entry\n")); |
| 1511 |
return false; |
| 1512 |
} |
| 1513 |
if (entry.length() == 8) { |
| 1514 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGroupData: find an empty zone\n")); |
| 1515 |
entry.setParsed(true); |
| 1516 |
return true; |
| 1517 |
} |
| 1518 |
if (entry.length() < 12) { |
| 1519 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGroupData: the entry seems too short\n")); |
| 1520 |
return false; |
| 1521 |
} |
| 1522 |
|
| 1523 |
auto frame = m_state->findFrame(11, actZone); |
| 1524 |
std::vector<long> dummyList; |
| 1525 |
std::vector<long> *idsList=&dummyList; |
| 1526 |
if (!frame) { |
| 1527 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGroupData: can not find group %d\n", actZone)); |
| 1528 |
} |
| 1529 |
else { |
| 1530 |
auto *group = static_cast<HanMacWrdJGraphInternal::Group *>(frame.get()); |
| 1531 |
idsList = &group->m_childsList; |
| 1532 |
} |
| 1533 |
|
| 1534 |
long pos = entry.begin()+8; // skip header |
| 1535 |
long endPos = entry.end(); |
| 1536 |
|
| 1537 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1538 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1539 |
libmwaw::DebugStream f; |
| 1540 |
entry.setParsed(true); |
| 1541 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1542 |
// first read the header |
| 1543 |
f << entry.name() << "[header]:"; |
| 1544 |
HanMacWrdJZoneHeader mainHeader(true); |
| 1545 |
if (!m_mainParser->readClassicHeader(mainHeader,endPos) || mainHeader.m_fieldSize!=4) { |
| 1546 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGroupData: can not read an entry\n")); |
| 1547 |
f << "###sz=" << mainHeader.m_length; |
| 1548 |
asciiFile.addPos(pos); |
| 1549 |
asciiFile.addNote(f.str().c_str()); |
| 1550 |
return false; |
| 1551 |
} |
| 1552 |
long headerEnd=pos+4+mainHeader.m_length; |
| 1553 |
f << mainHeader; |
| 1554 |
f << "listId=[" << std::hex; |
| 1555 |
idsList->resize(size_t(mainHeader.m_n), 0); |
| 1556 |
for (int i = 0; i < mainHeader.m_n; ++i) { |
| 1557 |
auto val = long(input->readULong(4)); |
| 1558 |
(*idsList)[size_t(i)]=val; |
| 1559 |
f << val << ","; |
| 1560 |
} |
| 1561 |
f << std::dec << "],"; |
| 1562 |
asciiFile.addPos(pos); |
| 1563 |
asciiFile.addNote(f.str().c_str()); |
| 1564 |
if (input->tell()!=headerEnd) { |
| 1565 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 1566 |
input->seek(headerEnd, librevenge::RVNG_SEEK_SET); |
| 1567 |
} |
| 1568 |
|
| 1569 |
pos = input->tell(); |
| 1570 |
if (pos!=endPos) { |
| 1571 |
f.str(""); |
| 1572 |
f << entry.name() << "[last]:###"; |
| 1573 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGroupData: find unexpected end of data\n")); |
| 1574 |
asciiFile.addPos(pos); |
| 1575 |
asciiFile.addNote(f.str().c_str()); |
| 1576 |
} |
| 1577 |
|
| 1578 |
return true; |
| 1579 |
} |
| 1580 |
|
| 1581 |
// try to read the graph data |
| 1582 |
bool HanMacWrdJGraph::readGraphData(MWAWEntry const &entry, int actZone) |
| 1583 |
{ |
| 1584 |
if (!entry.valid()) { |
| 1585 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGraphData: called without any entry\n")); |
| 1586 |
return false; |
| 1587 |
} |
| 1588 |
if (entry.length() < 12) { |
| 1589 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGraphData: the entry seems too short\n")); |
| 1590 |
return false; |
| 1591 |
} |
| 1592 |
|
| 1593 |
long pos = entry.begin()+8; // skip header |
| 1594 |
long endPos = entry.end(); |
| 1595 |
|
| 1596 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1597 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1598 |
libmwaw::DebugStream f; |
| 1599 |
entry.setParsed(true); |
| 1600 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1601 |
// first read the header |
| 1602 |
f << entry.name() << "[header]:"; |
| 1603 |
HanMacWrdJZoneHeader mainHeader(false); |
| 1604 |
if (!m_mainParser->readClassicHeader(mainHeader,endPos) || mainHeader.m_fieldSize!=8) { |
| 1605 |
// sz=12 is ok, means no data |
| 1606 |
if (entry.length() != 12) { |
| 1607 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGraphData: can not read an entry\n")); |
| 1608 |
f << "###sz=" << mainHeader.m_length; |
| 1609 |
} |
| 1610 |
asciiFile.addPos(pos); |
| 1611 |
asciiFile.addNote(f.str().c_str()); |
| 1612 |
return false; |
| 1613 |
} |
| 1614 |
long headerEnd=pos+4+mainHeader.m_length; |
| 1615 |
f << mainHeader; |
| 1616 |
|
| 1617 |
std::vector<MWAWVec2f> lVertices(size_t(mainHeader.m_n)); |
| 1618 |
f << "listPt=["; |
| 1619 |
for (int i = 0; i < mainHeader.m_n; ++i) { |
| 1620 |
float point[2]; |
| 1621 |
for (auto &pt : point) pt = float(input->readLong(4))/65536.f; |
| 1622 |
MWAWVec2f pt(point[1], point[0]); |
| 1623 |
lVertices[size_t(i)]=pt; |
| 1624 |
f << pt << ","; |
| 1625 |
} |
| 1626 |
f << "],"; |
| 1627 |
|
| 1628 |
auto frame = m_state->findFrame(8, actZone); |
| 1629 |
if (!frame) { |
| 1630 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGraphData: can not find basic graph %d\n", actZone)); |
| 1631 |
} |
| 1632 |
else { |
| 1633 |
auto *graph = static_cast<HanMacWrdJGraphInternal::ShapeGraph *>(frame.get()); |
| 1634 |
if (graph->m_shape.m_type != MWAWGraphicShape::Polygon) { |
| 1635 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGraphData: basic graph %d is not a polygon\n", actZone)); |
| 1636 |
} |
| 1637 |
else { |
| 1638 |
graph->m_shape.m_vertices = lVertices; |
| 1639 |
for (auto &vertex : graph->m_shape.m_vertices) |
| 1640 |
vertex += graph->m_pos[0]; |
| 1641 |
} |
| 1642 |
} |
| 1643 |
|
| 1644 |
asciiFile.addPos(entry.begin()+8); |
| 1645 |
asciiFile.addNote(f.str().c_str()); |
| 1646 |
|
| 1647 |
if (headerEnd!=endPos) { |
| 1648 |
f.str(""); |
| 1649 |
f << entry.name() << "[last]:###"; |
| 1650 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readGraphData: find unexpected end of data\n")); |
| 1651 |
asciiFile.addPos(headerEnd); |
| 1652 |
asciiFile.addNote(f.str().c_str()); |
| 1653 |
} |
| 1654 |
|
| 1655 |
return true; |
| 1656 |
} |
| 1657 |
|
| 1658 |
// try to read the picture |
| 1659 |
bool HanMacWrdJGraph::readPicture(MWAWEntry const &entry, int actZone) |
| 1660 |
{ |
| 1661 |
if (!entry.valid()) { |
| 1662 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readPicture: called without any entry\n")); |
| 1663 |
return false; |
| 1664 |
} |
| 1665 |
if (entry.length() < 12) { |
| 1666 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readPicture: the entry seems too short\n")); |
| 1667 |
return false; |
| 1668 |
} |
| 1669 |
|
| 1670 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1671 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1672 |
libmwaw::DebugStream f; |
| 1673 |
entry.setParsed(true); |
| 1674 |
|
| 1675 |
long pos = entry.begin()+8; // skip header |
| 1676 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1677 |
auto sz=long(input->readULong(4)); |
| 1678 |
if (sz+12 != entry.length()) { |
| 1679 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readPicture: the entry sz seems bad\n")); |
| 1680 |
return false; |
| 1681 |
} |
| 1682 |
f << "Picture:pictSz=" << sz; |
| 1683 |
asciiFile.addPos(pos); |
| 1684 |
asciiFile.addNote(f.str().c_str()); |
| 1685 |
asciiFile.skipZone(entry.begin()+12, entry.end()-1); |
| 1686 |
|
| 1687 |
auto frame = m_state->findFrame(6, actZone); |
| 1688 |
if (!frame) { |
| 1689 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readPicture: can not find picture %d\n", actZone)); |
| 1690 |
} |
| 1691 |
else { |
| 1692 |
auto *picture = static_cast<HanMacWrdJGraphInternal::PictureFrame *>(frame.get()); |
| 1693 |
picture->m_entry.setBegin(pos+4); |
| 1694 |
picture->m_entry.setLength(sz); |
| 1695 |
} |
| 1696 |
|
| 1697 |
return true; |
| 1698 |
} |
| 1699 |
|
| 1700 |
// table |
| 1701 |
bool HanMacWrdJGraph::readTable(MWAWEntry const &entry, int actZone) |
| 1702 |
{ |
| 1703 |
if (!entry.valid()) { |
| 1704 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: called without any entry\n")); |
| 1705 |
return false; |
| 1706 |
} |
| 1707 |
if (entry.length() == 8) { |
| 1708 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: find an empty zone\n")); |
| 1709 |
entry.setParsed(true); |
| 1710 |
return true; |
| 1711 |
} |
| 1712 |
if (entry.length() < 12) { |
| 1713 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: the entry seems too short\n")); |
| 1714 |
return false; |
| 1715 |
} |
| 1716 |
long pos = entry.begin()+8; // skip header |
| 1717 |
long endPos = entry.end(); |
| 1718 |
|
| 1719 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1720 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1721 |
libmwaw::DebugStream f; |
| 1722 |
entry.setParsed(true); |
| 1723 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1724 |
// first read the header |
| 1725 |
f << entry.name() << "[header]:"; |
| 1726 |
HanMacWrdJZoneHeader mainHeader(true); |
| 1727 |
if (!m_mainParser->readClassicHeader(mainHeader,endPos) || mainHeader.m_fieldSize!=4 || |
| 1728 |
mainHeader.m_length < 16+12+4*mainHeader.m_n) { |
| 1729 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: can not read an entry\n")); |
| 1730 |
f << "###sz=" << mainHeader.m_length; |
| 1731 |
asciiFile.addPos(pos); |
| 1732 |
asciiFile.addNote(f.str().c_str()); |
| 1733 |
return false; |
| 1734 |
} |
| 1735 |
long headerEnd=pos+4+mainHeader.m_length; |
| 1736 |
f << mainHeader; |
| 1737 |
std::shared_ptr<HanMacWrdJGraphInternal::Table> table(new HanMacWrdJGraphInternal::Table(*this)); |
| 1738 |
|
| 1739 |
long textId = 0; |
| 1740 |
auto frame = m_state->findFrame(9, actZone); |
| 1741 |
if (!frame || !frame->valid()) { |
| 1742 |
MWAW_DEBUG_MSG(("HanMacWrdJTable::readTable: can not find basic table %d\n", actZone)); |
| 1743 |
} |
| 1744 |
else { |
| 1745 |
auto *tableFrame = static_cast<HanMacWrdJGraphInternal::TableFrame *>(frame.get()); |
| 1746 |
tableFrame->m_table = table; |
| 1747 |
textId = tableFrame->m_zId; |
| 1748 |
} |
| 1749 |
|
| 1750 |
table->m_rows = static_cast<int>(input->readULong(1)); |
| 1751 |
table->m_columns = static_cast<int>(input->readULong(1)); |
| 1752 |
f << "dim=" << table->m_rows << "x" << table->m_columns << ","; |
| 1753 |
long val; |
| 1754 |
for (int i = 0; i < 4; ++i) { // f0=4|5|7|8|9, f1=1|7|107, f2=3|4|5|6, f3=0 |
| 1755 |
val = long(input->readULong(2)); |
| 1756 |
if (val) f << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 1757 |
} |
| 1758 |
table->m_height = static_cast<int>(input->readLong(2)); |
| 1759 |
f << "h=" << table->m_height << ","; |
| 1760 |
f << "listId=[" << std::hex; |
| 1761 |
std::vector<long> listIds; |
| 1762 |
for (int i = 0; i < mainHeader.m_n; ++i) { |
| 1763 |
val = long(input->readULong(4)); |
| 1764 |
listIds.push_back(val); |
| 1765 |
f << val << ","; |
| 1766 |
} |
| 1767 |
f << std::dec << "],"; |
| 1768 |
asciiFile.addPos(pos); |
| 1769 |
asciiFile.addNote(f.str().c_str()); |
| 1770 |
if (input->tell()!=headerEnd) { |
| 1771 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 1772 |
input->seek(headerEnd, librevenge::RVNG_SEEK_SET); |
| 1773 |
} |
| 1774 |
|
| 1775 |
// first read the row |
| 1776 |
for (int i = 0; i < mainHeader.m_n; ++i) { |
| 1777 |
pos = input->tell(); |
| 1778 |
f.str(""); |
| 1779 |
f << entry.name() << "-row" << i << ":"; |
| 1780 |
HanMacWrdJZoneHeader header(false); |
| 1781 |
if (!m_mainParser->readClassicHeader(header,endPos) || header.m_fieldSize!=16) { |
| 1782 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: can not read zone %d\n", i)); |
| 1783 |
f << "###" << header; |
| 1784 |
asciiFile.addPos(pos); |
| 1785 |
asciiFile.addNote(f.str().c_str()); |
| 1786 |
if (header.m_length<16 || pos+4+header.m_length>endPos) |
| 1787 |
return false; |
| 1788 |
input->seek(pos+4+header.m_length, librevenge::RVNG_SEEK_SET); |
| 1789 |
continue; |
| 1790 |
} |
| 1791 |
long zoneEnd=pos+4+header.m_length; |
| 1792 |
f << header; |
| 1793 |
|
| 1794 |
asciiFile.addPos(pos); |
| 1795 |
asciiFile.addNote(f.str().c_str()); |
| 1796 |
|
| 1797 |
// the different cells in a row |
| 1798 |
for (int j = 0; j < header.m_n; j++) { |
| 1799 |
pos = input->tell(); |
| 1800 |
f.str(""); |
| 1801 |
std::shared_ptr<HanMacWrdJGraphInternal::TableCell> cell(new HanMacWrdJGraphInternal::TableCell(textId)); |
| 1802 |
cell->setPosition(MWAWVec2i(j,i)); |
| 1803 |
cell->m_cPos = long(input->readULong(4)); |
| 1804 |
cell->m_zId = long(input->readULong(4)); |
| 1805 |
cell->m_flags = static_cast<int>(input->readULong(2)); |
| 1806 |
if (cell->m_flags&0x80) |
| 1807 |
cell->setVAlignment(MWAWCell::VALIGN_CENTER); |
| 1808 |
switch ((cell->m_flags>>9)&3) { |
| 1809 |
case 1: |
| 1810 |
cell->setExtraLine(MWAWCell::E_Line1); |
| 1811 |
break; |
| 1812 |
case 2: |
| 1813 |
cell->setExtraLine(MWAWCell::E_Line2); |
| 1814 |
break; |
| 1815 |
case 3: |
| 1816 |
cell->setExtraLine(MWAWCell::E_Cross); |
| 1817 |
break; |
| 1818 |
case 0: // none |
| 1819 |
default: |
| 1820 |
break; |
| 1821 |
} |
| 1822 |
val = input->readLong(2); |
| 1823 |
if (val) f << "#f0=" << val << ","; |
| 1824 |
cell->m_formatId = static_cast<int>(input->readLong(2)); |
| 1825 |
int dim[2]; // for merge, inactive -> the other limit cell |
| 1826 |
for (auto &d : dim) d=static_cast<int>(input->readULong(1)); |
| 1827 |
if (cell->m_flags & 0x1000) { |
| 1828 |
if (dim[1]>=j&&dim[0]>=i) |
| 1829 |
cell->setNumSpannedCells(MWAWVec2i(dim[1]+1-j,dim[0]+1-i)); |
| 1830 |
else { |
| 1831 |
static bool first = true; |
| 1832 |
if (first) { |
| 1833 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: can not determine the span\n")); |
| 1834 |
first = false; |
| 1835 |
} |
| 1836 |
f << "##span=" << dim[1]+1-j << "x" << dim[0]+1-i << ","; |
| 1837 |
} |
| 1838 |
} |
| 1839 |
cell->m_extra = f.str(); |
| 1840 |
// do not push the ignore cell |
| 1841 |
if ((cell->m_flags&0x2000)==0) |
| 1842 |
table->add(cell); |
| 1843 |
f.str(""); |
| 1844 |
f << entry.name() << "-cell:" << cell; |
| 1845 |
asciiFile.addPos(pos); |
| 1846 |
asciiFile.addNote(f.str().c_str()); |
| 1847 |
input->seek(pos+16, librevenge::RVNG_SEEK_SET); |
| 1848 |
} |
| 1849 |
|
| 1850 |
if (input->tell() != zoneEnd) { |
| 1851 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 1852 |
input->seek(zoneEnd, librevenge::RVNG_SEEK_SET); |
| 1853 |
} |
| 1854 |
} |
| 1855 |
asciiFile.addPos(endPos); |
| 1856 |
asciiFile.addNote("_"); |
| 1857 |
if (input->tell()==endPos) { |
| 1858 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: can not find the 3 last blocks\n")); |
| 1859 |
return true; |
| 1860 |
} |
| 1861 |
|
| 1862 |
for (int i = 0; i < 2; ++i) { |
| 1863 |
pos = input->tell(); |
| 1864 |
f.str(""); |
| 1865 |
f << entry.name() << "-" << (i==0 ? "rowY" : "colX") << ":"; |
| 1866 |
HanMacWrdJZoneHeader header(false); |
| 1867 |
if (!m_mainParser->readClassicHeader(header,endPos) || header.m_fieldSize != 4) { |
| 1868 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: can not read zone %d\n", i)); |
| 1869 |
f << "###" << header; |
| 1870 |
asciiFile.addPos(pos); |
| 1871 |
asciiFile.addNote(f.str().c_str()); |
| 1872 |
if (header.m_length<16 || pos+4+header.m_length>endPos) |
| 1873 |
return false; |
| 1874 |
input->seek(pos+4+header.m_length, librevenge::RVNG_SEEK_SET); |
| 1875 |
continue; |
| 1876 |
} |
| 1877 |
long zoneEnd=pos+4+header.m_length; |
| 1878 |
f << header; |
| 1879 |
|
| 1880 |
f << "pos=["; |
| 1881 |
float prevPos = 0.; |
| 1882 |
std::vector<float> dim; |
| 1883 |
for (int j = 0; j < header.m_n; j++) { |
| 1884 |
float cPos = float(input->readULong(4))/65536.f; |
| 1885 |
f << cPos << ","; |
| 1886 |
if (j!=0) |
| 1887 |
dim.push_back(cPos-prevPos); |
| 1888 |
prevPos=cPos; |
| 1889 |
} |
| 1890 |
f << "],"; |
| 1891 |
if (i==0) |
| 1892 |
table->setRowsSize(dim); |
| 1893 |
else |
| 1894 |
table->setColsSize(dim); |
| 1895 |
asciiFile.addPos(pos); |
| 1896 |
asciiFile.addNote(f.str().c_str()); |
| 1897 |
input->seek(zoneEnd, librevenge::RVNG_SEEK_SET); |
| 1898 |
} |
| 1899 |
|
| 1900 |
// finally the format |
| 1901 |
readTableFormatsList(*table, endPos); |
| 1902 |
table->updateCells(); |
| 1903 |
|
| 1904 |
if (input->tell() != endPos) { |
| 1905 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTable: find unexpected last block\n")); |
| 1906 |
pos = input->tell(); |
| 1907 |
f.str(""); |
| 1908 |
f << entry.name() << "-###:"; |
| 1909 |
asciiFile.addPos(pos); |
| 1910 |
asciiFile.addNote(f.str().c_str()); |
| 1911 |
} |
| 1912 |
|
| 1913 |
return true; |
| 1914 |
} |
| 1915 |
|
| 1916 |
bool HanMacWrdJGraph::readTableFormatsList(HanMacWrdJGraphInternal::Table &table, long endPos) |
| 1917 |
{ |
| 1918 |
table.m_formatsList.clear(); |
| 1919 |
|
| 1920 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 1921 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 1922 |
libmwaw::DebugStream f, f2; |
| 1923 |
|
| 1924 |
long pos = input->tell(); |
| 1925 |
f.str(""); |
| 1926 |
f << "Table-format:"; |
| 1927 |
HanMacWrdJZoneHeader header(false); |
| 1928 |
if (!m_mainParser->readClassicHeader(header,endPos) || header.m_fieldSize != 40) { |
| 1929 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTableFormatsList: can not read format\n")); |
| 1930 |
f << "###" << header; |
| 1931 |
asciiFile.addPos(pos); |
| 1932 |
asciiFile.addNote(f.str().c_str()); |
| 1933 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1934 |
return false; |
| 1935 |
} |
| 1936 |
long zoneEnd=pos+4+header.m_length; |
| 1937 |
f << header; |
| 1938 |
asciiFile.addPos(pos); |
| 1939 |
asciiFile.addNote(f.str().c_str()); |
| 1940 |
table.m_formatsList.resize(size_t(header.m_n)); |
| 1941 |
for (int i = 0; i < header.m_n; ++i) { |
| 1942 |
HanMacWrdJGraphInternal::CellFormat format; |
| 1943 |
pos = input->tell(); |
| 1944 |
f.str(""); |
| 1945 |
long val = input->readLong(2); // always -2 |
| 1946 |
if (val != -2) |
| 1947 |
f << "f0=" << val << ","; |
| 1948 |
val = long(input->readULong(2)); // 0|2004|51|1dd4 |
| 1949 |
if (val) |
| 1950 |
f << "#f1=" << std::hex << val << std::dec << ","; |
| 1951 |
|
| 1952 |
int color, pattern; |
| 1953 |
format.m_borders.resize(4); |
| 1954 |
static char const *what[] = {"T", "L", "B", "R"}; |
| 1955 |
static size_t const which[] = { libmwaw::Top, libmwaw::Left, libmwaw::Bottom, libmwaw::Right }; |
| 1956 |
for (int b=0; b < 4; b++) { |
| 1957 |
f2.str(""); |
| 1958 |
MWAWBorder border; |
| 1959 |
border.m_width=double(input->readLong(4))/65536.; |
| 1960 |
auto type = int(input->readLong(1)); |
| 1961 |
switch (type) { |
| 1962 |
case 0: // solid |
| 1963 |
break; |
| 1964 |
case 1: |
| 1965 |
border.m_type = MWAWBorder::Double; |
| 1966 |
break; |
| 1967 |
case 2: |
| 1968 |
border.m_type = MWAWBorder::Double; |
| 1969 |
border.m_widthsList.resize(3,1.); |
| 1970 |
border.m_widthsList[0]=2.0; |
| 1971 |
break; |
| 1972 |
case 3: |
| 1973 |
border.m_type = MWAWBorder::Double; |
| 1974 |
border.m_widthsList.resize(3,1.); |
| 1975 |
border.m_widthsList[2]=2.0; |
| 1976 |
break; |
| 1977 |
default: |
| 1978 |
f2 << "#style=" << type << ","; |
| 1979 |
break; |
| 1980 |
} |
| 1981 |
color = static_cast<int>(input->readULong(1)); |
| 1982 |
MWAWColor col = MWAWColor::black(); |
| 1983 |
if (!m_state->getColor(color, col)) |
| 1984 |
f2 << "#color=" << color << ","; |
| 1985 |
pattern = static_cast<int>(input->readULong(1)); |
| 1986 |
HanMacWrdJGraphInternal::Pattern pat; |
| 1987 |
if (pattern==0) border.m_style=MWAWBorder::None; |
| 1988 |
else { |
| 1989 |
if (!m_state->getPattern(pattern, pat)) { |
| 1990 |
f2 << "#pattern=" << pattern << ","; |
| 1991 |
border.m_color = col; |
| 1992 |
} |
| 1993 |
else |
| 1994 |
border.m_color = m_state->getColor(col, pat.m_percent); |
| 1995 |
} |
| 1996 |
val = long(input->readULong(1)); |
| 1997 |
if (val) f2 << "unkn=" << val << ","; |
| 1998 |
|
| 1999 |
format.m_borders[which[b]] = border; |
| 2000 |
if (f2.str().length()) |
| 2001 |
f << "bord" << what[b] << "=[" << f2.str() << "],"; |
| 2002 |
} |
| 2003 |
color = static_cast<int>(input->readULong(1)); |
| 2004 |
MWAWColor backCol = MWAWColor::white(); |
| 2005 |
if (!m_state->getColor(color, backCol)) |
| 2006 |
f << "#backcolor=" << color << ","; |
| 2007 |
pattern = static_cast<int>(input->readULong(1)); |
| 2008 |
HanMacWrdJGraphInternal::Pattern pat; |
| 2009 |
if (!m_state->getPattern(pattern, pat)) |
| 2010 |
f << "#backPattern=" << pattern << ","; |
| 2011 |
else |
| 2012 |
format.m_backColor = m_state->getColor(backCol, pat.m_percent); |
| 2013 |
format.m_extra = f.str(); |
| 2014 |
table.m_formatsList[size_t(i)]=format; |
| 2015 |
f.str(""); |
| 2016 |
f << "Table-format" << i << ":" << format; |
| 2017 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2018 |
asciiFile.addPos(pos); |
| 2019 |
asciiFile.addNote(f.str().c_str()); |
| 2020 |
input->seek(pos+header.m_fieldSize, librevenge::RVNG_SEEK_SET); |
| 2021 |
} |
| 2022 |
input->seek(zoneEnd, librevenge::RVNG_SEEK_SET); |
| 2023 |
return true; |
| 2024 |
} |
| 2025 |
|
| 2026 |
|
| 2027 |
//////////////////////////////////////////////////////////// |
| 2028 |
// send data to a listener |
| 2029 |
//////////////////////////////////////////////////////////// |
| 2030 |
|
| 2031 |
bool HanMacWrdJGraph::sendFrame(long frameId, MWAWPosition const &pos) |
| 2032 |
{ |
| 2033 |
if (!m_parserState->m_textListener) return true; |
| 2034 |
|
| 2035 |
auto fIt=m_state->m_framesMap.find(frameId); |
| 2036 |
if (fIt == m_state->m_framesMap.end() || fIt->second < 0 || fIt->second >= int(m_state->m_framesList.size())) { |
| 2037 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendFrame: can not find frame %lx\n", static_cast<long unsigned int>(frameId))); |
| 2038 |
return false; |
| 2039 |
} |
| 2040 |
auto frame = m_state->m_framesList[size_t(fIt->second)]; |
| 2041 |
if (!frame || !frame->valid()) { |
| 2042 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendFrame: frame %lx is not initialized\n", static_cast<long unsigned int>(frameId))); |
| 2043 |
return false; |
| 2044 |
} |
| 2045 |
return sendFrame(*frame, pos); |
| 2046 |
} |
| 2047 |
|
| 2048 |
// --- basic shape |
| 2049 |
bool HanMacWrdJGraph::sendShapeGraph(HanMacWrdJGraphInternal::ShapeGraph const &pict, MWAWPosition const &lPos) |
| 2050 |
{ |
| 2051 |
if (!m_parserState->m_textListener) return true; |
| 2052 |
auto pos(lPos); |
| 2053 |
if (pos.size()[0] <= 0 || pos.size()[1] <= 0) |
| 2054 |
pos.setSize(pict.getBdBox().size()); |
| 2055 |
|
| 2056 |
auto const &format=m_state->getFrameFormat(pict.m_formatId); |
| 2057 |
|
| 2058 |
MWAWGraphicStyle style(format.m_style);; |
| 2059 |
if (pict.m_shape.m_type==MWAWGraphicShape::Line) { |
| 2060 |
if (pict.m_arrowsFlag&1) style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain(); |
| 2061 |
if (pict.m_arrowsFlag&2) style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 2062 |
} |
| 2063 |
|
| 2064 |
pos.setOrigin(pos.origin()); |
| 2065 |
pos.setSize(pos.size()+MWAWVec2f(4,4)); |
| 2066 |
m_parserState->m_textListener->insertShape(pos,pict.m_shape,style); |
| 2067 |
return true; |
| 2068 |
} |
| 2069 |
|
| 2070 |
// picture |
| 2071 |
bool HanMacWrdJGraph::sendPictureFrame(HanMacWrdJGraphInternal::PictureFrame const &pict, MWAWPosition const &lPos) |
| 2072 |
{ |
| 2073 |
if (!m_parserState->m_textListener) return true; |
| 2074 |
#ifdef DEBUG_WITH_FILES |
| 2075 |
bool firstTime = pict.m_parsed == false; |
| 2076 |
#endif |
| 2077 |
pict.m_parsed = true; |
| 2078 |
auto pos(lPos); |
| 2079 |
if (pos.size()[0] <= 0 || pos.size()[1] <= 0) |
| 2080 |
pos.setSize(pict.getBdBox().size()); |
| 2081 |
|
| 2082 |
if (!pict.m_entry.valid()) { |
| 2083 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendPictureFrame: can not find picture data\n")); |
| 2084 |
sendEmptyPicture(pos); |
| 2085 |
return true; |
| 2086 |
} |
| 2087 |
//fixme: check if we have border |
| 2088 |
|
| 2089 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2090 |
long fPos = input->tell(); |
| 2091 |
input->seek(pict.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2092 |
librevenge::RVNGBinaryData data; |
| 2093 |
input->readDataBlock(pict.m_entry.length(), data); |
| 2094 |
input->seek(fPos, librevenge::RVNG_SEEK_SET); |
| 2095 |
|
| 2096 |
#ifdef DEBUG_WITH_FILES |
| 2097 |
if (firstTime) { |
| 2098 |
libmwaw::DebugStream f; |
| 2099 |
static int volatile pictName = 0; |
| 2100 |
f << "Pict" << ++pictName << ".pct1"; |
| 2101 |
libmwaw::Debug::dumpFile(data, f.str().c_str()); |
| 2102 |
} |
| 2103 |
#endif |
| 2104 |
|
| 2105 |
m_parserState->m_textListener->insertPicture(pos, MWAWEmbeddedObject(data, "image/pict")); |
| 2106 |
|
| 2107 |
return true; |
| 2108 |
} |
| 2109 |
|
| 2110 |
bool HanMacWrdJGraph::sendEmptyPicture(MWAWPosition const &pos) |
| 2111 |
{ |
| 2112 |
if (!m_parserState->m_textListener) |
| 2113 |
return true; |
| 2114 |
MWAWVec2f pictSz = pos.size(); |
| 2115 |
std::shared_ptr<MWAWPict> pict; |
| 2116 |
MWAWPosition pictPos(MWAWVec2f(0,0), pictSz, librevenge::RVNG_POINT); |
| 2117 |
pictPos.setRelativePosition(MWAWPosition::Frame); |
| 2118 |
pictPos.setOrder(-1); |
| 2119 |
|
| 2120 |
MWAWBox2f box=MWAWBox2f(MWAWVec2f(0,0),pictSz); |
| 2121 |
MWAWPosition shapePos(MWAWVec2f(0,0),pictSz, librevenge::RVNG_POINT); |
| 2122 |
shapePos.m_anchorTo=MWAWPosition::Page; |
| 2123 |
MWAWGraphicEncoder graphicEncoder; |
| 2124 |
MWAWGraphicListener graphicListener(*m_parserState, box, &graphicEncoder); |
| 2125 |
graphicListener.startDocument(); |
| 2126 |
MWAWGraphicStyle defStyle; |
| 2127 |
graphicListener.insertShape(shapePos, MWAWGraphicShape::rectangle(box), defStyle); |
| 2128 |
graphicListener.insertShape(shapePos, MWAWGraphicShape::line(box[0],box[1]), defStyle); |
| 2129 |
graphicListener.insertShape(shapePos, MWAWGraphicShape::line(MWAWVec2f(0,pictSz[1]), MWAWVec2f(pictSz[0],0)), defStyle); |
| 2130 |
graphicListener.endDocument(); |
| 2131 |
MWAWEmbeddedObject picture; |
| 2132 |
if (!graphicEncoder.getBinaryResult(picture)) return false; |
| 2133 |
m_parserState->m_textListener->insertPicture(pictPos, picture); |
| 2134 |
return true; |
| 2135 |
} |
| 2136 |
|
| 2137 |
// ----- comment box |
| 2138 |
bool HanMacWrdJGraph::sendComment(HanMacWrdJGraphInternal::CommentFrame const &comment, MWAWPosition const &lPos, librevenge::RVNGPropertyList const &extras) |
| 2139 |
{ |
| 2140 |
if (!m_parserState->m_textListener) return true; |
| 2141 |
MWAWVec2f commentSz = comment.getBdBox().size(); |
| 2142 |
if (comment.m_dim[0] > commentSz[0]) commentSz[0]=comment.m_dim[0]; |
| 2143 |
if (comment.m_dim[1] > commentSz[1]) commentSz[1]=comment.m_dim[1]; |
| 2144 |
auto pos(lPos); |
| 2145 |
pos.setSize(commentSz); |
| 2146 |
|
| 2147 |
librevenge::RVNGPropertyList pList(extras); |
| 2148 |
|
| 2149 |
auto const &format=m_state->getFrameFormat(comment.m_formatId); |
| 2150 |
|
| 2151 |
MWAWGraphicStyle style=format.m_style; |
| 2152 |
MWAWBorder border; |
| 2153 |
border.m_color=style.m_lineColor; |
| 2154 |
border.m_width=double(style.m_lineWidth); |
| 2155 |
style.setBorders(libmwaw::LeftBit|libmwaw::BottomBit|libmwaw::RightBit, border); |
| 2156 |
|
| 2157 |
border.m_width=20*double(style.m_lineWidth); |
| 2158 |
style.setBorders(libmwaw::TopBit, border); |
| 2159 |
|
| 2160 |
if (style.hasSurfaceColor()) |
| 2161 |
style.setBackgroundColor(style.m_surfaceColor); |
| 2162 |
|
| 2163 |
MWAWSubDocumentPtr subdoc(new HanMacWrdJGraphInternal::SubDocument(*this, m_parserState->m_input, HanMacWrdJGraphInternal::SubDocument::Text, comment.m_zId)); |
| 2164 |
m_parserState->m_textListener->insertTextBox(pos, subdoc, style); |
| 2165 |
|
| 2166 |
return true; |
| 2167 |
} |
| 2168 |
|
| 2169 |
// ----- textbox |
| 2170 |
bool HanMacWrdJGraph::sendTextbox(HanMacWrdJGraphInternal::TextboxFrame const &textbox, MWAWPosition const &lPos) |
| 2171 |
{ |
| 2172 |
if (!m_parserState->m_textListener) return true; |
| 2173 |
auto pos(lPos); |
| 2174 |
if (pos.size()[0] <= 0 || pos.size()[1] <= 0) |
| 2175 |
pos.setSize(textbox.getBdBox().size()); |
| 2176 |
|
| 2177 |
auto const &format=m_state->getFrameFormat(textbox.m_formatId); |
| 2178 |
MWAWGraphicStyle style; |
| 2179 |
format.addTo(style); |
| 2180 |
MWAWSubDocumentPtr subdoc; |
| 2181 |
if (!textbox.m_isLinked) |
| 2182 |
subdoc.reset(new HanMacWrdJGraphInternal::SubDocument(*this, m_parserState->m_input, HanMacWrdJGraphInternal::SubDocument::Text, textbox.m_zId)); |
| 2183 |
else { |
| 2184 |
librevenge::RVNGString fName; |
| 2185 |
fName.sprintf("Frame%ld", textbox.m_fileId); |
| 2186 |
style.m_frameName=fName.cstr(); |
| 2187 |
} |
| 2188 |
if (textbox.m_linkToFId) { |
| 2189 |
librevenge::RVNGString fName; |
| 2190 |
fName.sprintf("Frame%ld", textbox.m_linkToFId); |
| 2191 |
style.m_frameNextName=fName.cstr(); |
| 2192 |
} |
| 2193 |
m_parserState->m_textListener->insertTextBox(pos, subdoc, style); |
| 2194 |
|
| 2195 |
return true; |
| 2196 |
} |
| 2197 |
|
| 2198 |
// ----- table |
| 2199 |
bool HanMacWrdJGraph::sendTableUnformatted(long fId) |
| 2200 |
{ |
| 2201 |
if (!m_parserState->m_textListener) |
| 2202 |
return true; |
| 2203 |
auto fIt = m_state->m_framesMap.find(fId); |
| 2204 |
if (fIt == m_state->m_framesMap.end()) { |
| 2205 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendTableUnformatted: can not find the table frame %lx\n", static_cast<long unsigned int>(fId))); |
| 2206 |
return false; |
| 2207 |
} |
| 2208 |
int id = fIt->second; |
| 2209 |
if (id < 0 || id >= static_cast<int>(m_state->m_framesList.size())) |
| 2210 |
return false; |
| 2211 |
auto &frame = *m_state->m_framesList[size_t(id)]; |
| 2212 |
if (!frame.valid() || frame.m_type != 9) { |
| 2213 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendTableUnformatted: can not find the table frame %lx(II)\n", static_cast<long unsigned int>(fId))); |
| 2214 |
return false; |
| 2215 |
} |
| 2216 |
auto &tableFrame = static_cast<HanMacWrdJGraphInternal::TableFrame &>(frame); |
| 2217 |
if (!tableFrame.m_table) { |
| 2218 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendTableUnformatted: can not find the table\n")); |
| 2219 |
return false; |
| 2220 |
} |
| 2221 |
tableFrame.m_table->sendAsText(m_parserState->m_textListener); |
| 2222 |
return true; |
| 2223 |
} |
| 2224 |
|
| 2225 |
//////////////////////////////////////////////////////////// |
| 2226 |
// low level |
| 2227 |
//////////////////////////////////////////////////////////// |
| 2228 |
bool HanMacWrdJGraph::sendFrame(HanMacWrdJGraphInternal::Frame const &frame, MWAWPosition const &lPos) |
| 2229 |
{ |
| 2230 |
MWAWTextListenerPtr listener=m_parserState->m_textListener; |
| 2231 |
if (!listener) return true; |
| 2232 |
|
| 2233 |
if (!frame.valid()) { |
| 2234 |
frame.m_parsed = true; |
| 2235 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendFrame: called with invalid frame\n")); |
| 2236 |
return false; |
| 2237 |
} |
| 2238 |
|
| 2239 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 2240 |
auto pos(lPos); |
| 2241 |
switch (frame.m_type) { |
| 2242 |
case 4: { |
| 2243 |
frame.m_parsed = true; |
| 2244 |
auto const &format=m_state->getFrameFormat(frame.m_formatId); |
| 2245 |
if (format.m_style.hasPattern()) { |
| 2246 |
auto const &textbox=static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(frame); |
| 2247 |
if (!textbox.isLinked() && m_mainParser->canSendTextAsGraphic(textbox.m_zId,0)) { |
| 2248 |
MWAWSubDocumentPtr subdoc |
| 2249 |
(new HanMacWrdJGraphInternal::SubDocument(*this, input, HanMacWrdJGraphInternal::SubDocument::Text, textbox.m_zId)); |
| 2250 |
MWAWBox2f box(MWAWVec2f(0,0),pos.size()); |
| 2251 |
MWAWGraphicEncoder graphicEncoder; |
| 2252 |
MWAWGraphicListener graphicListener(*m_parserState, box, &graphicEncoder); |
| 2253 |
graphicListener.startDocument(); |
| 2254 |
MWAWPosition textPos(box[0], box.size(), librevenge::RVNG_POINT); |
| 2255 |
textPos.m_anchorTo=MWAWPosition::Page; |
| 2256 |
graphicListener.insertTextBox(textPos, subdoc, format.m_style); |
| 2257 |
graphicListener.endDocument(); |
| 2258 |
MWAWEmbeddedObject picture; |
| 2259 |
if (!graphicEncoder.getBinaryResult(picture)) |
| 2260 |
return false; |
| 2261 |
listener->insertPicture(pos, picture); |
| 2262 |
return true; |
| 2263 |
} |
| 2264 |
} |
| 2265 |
return sendTextbox(static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(frame), pos); |
| 2266 |
} |
| 2267 |
case 6: { |
| 2268 |
auto const &pict = static_cast<HanMacWrdJGraphInternal::PictureFrame const &>(frame); |
| 2269 |
if (!pict.m_entry.valid()) { |
| 2270 |
pos.setSize(pict.getBdBox().size()); |
| 2271 |
|
| 2272 |
frame.m_parsed = true; |
| 2273 |
MWAWPosition framePos(pos); |
| 2274 |
framePos.m_anchorTo = MWAWPosition::Frame; |
| 2275 |
framePos.setOrigin(MWAWVec2f(0,0)); |
| 2276 |
|
| 2277 |
MWAWSubDocumentPtr subdoc |
| 2278 |
(new HanMacWrdJGraphInternal::SubDocument |
| 2279 |
(*this, input, framePos, HanMacWrdJGraphInternal::SubDocument::EmptyPicture, 0)); |
| 2280 |
listener->insertTextBox(pos, subdoc); |
| 2281 |
return true; |
| 2282 |
} |
| 2283 |
return sendPictureFrame(pict, pos); |
| 2284 |
} |
| 2285 |
case 8: |
| 2286 |
frame.m_parsed = true; |
| 2287 |
return sendShapeGraph(static_cast<HanMacWrdJGraphInternal::ShapeGraph const &>(frame), pos); |
| 2288 |
case 9: { |
| 2289 |
frame.m_parsed = true; |
| 2290 |
auto const &tableFrame = static_cast<HanMacWrdJGraphInternal::TableFrame const &>(frame); |
| 2291 |
if (!tableFrame.m_table) { |
| 2292 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendFrame: can not find the table\n")); |
| 2293 |
return false; |
| 2294 |
} |
| 2295 |
auto &table = *tableFrame.m_table; |
| 2296 |
|
| 2297 |
if (!table.updateTable()) { |
| 2298 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendFrame: can not find the table structure\n")); |
| 2299 |
MWAWSubDocumentPtr subdoc |
| 2300 |
(new HanMacWrdJGraphInternal::SubDocument |
| 2301 |
(*this, input, HanMacWrdJGraphInternal::SubDocument::UnformattedTable, frame.m_fileId)); |
| 2302 |
listener->insertTextBox(pos, subdoc); |
| 2303 |
return true; |
| 2304 |
} |
| 2305 |
if (pos.m_anchorTo==MWAWPosition::Page || |
| 2306 |
(pos.m_anchorTo!=MWAWPosition::Frame && table.hasExtraLines())) { |
| 2307 |
MWAWPosition framePos(pos); |
| 2308 |
framePos.m_anchorTo = MWAWPosition::Frame; |
| 2309 |
framePos.setOrigin(MWAWVec2f(0,0)); |
| 2310 |
|
| 2311 |
MWAWSubDocumentPtr subdoc |
| 2312 |
(new HanMacWrdJGraphInternal::SubDocument |
| 2313 |
(*this, input, framePos, HanMacWrdJGraphInternal::SubDocument::FrameInFrame, frame.m_fileId)); |
| 2314 |
pos.setSize(MWAWVec2f(-0.01f,-0.01f)); // autosize |
| 2315 |
listener->insertTextBox(pos, subdoc); |
| 2316 |
return true; |
| 2317 |
} |
| 2318 |
if (table.sendTable(listener, pos.m_anchorTo==MWAWPosition::Frame)) |
| 2319 |
return true; |
| 2320 |
return table.sendAsText(listener); |
| 2321 |
} |
| 2322 |
case 10: |
| 2323 |
frame.m_parsed = true; |
| 2324 |
return sendComment(static_cast<HanMacWrdJGraphInternal::CommentFrame const &>(frame), pos); |
| 2325 |
case 11: { |
| 2326 |
auto const &group=static_cast<HanMacWrdJGraphInternal::Group const &>(frame); |
| 2327 |
if ((pos.m_anchorTo==MWAWPosition::Char || pos.m_anchorTo==MWAWPosition::CharBaseLine) && !canCreateGraphic(group)) { |
| 2328 |
MWAWPosition framePos(pos); |
| 2329 |
framePos.m_anchorTo = MWAWPosition::Frame; |
| 2330 |
framePos.setOrigin(MWAWVec2f(0,0)); |
| 2331 |
pos.setSize(group.getBdBox().size()); |
| 2332 |
MWAWSubDocumentPtr subdoc |
| 2333 |
(new HanMacWrdJGraphInternal::SubDocument |
| 2334 |
(*this, input, framePos, HanMacWrdJGraphInternal::SubDocument::Group, group.m_fileId)); |
| 2335 |
listener->insertTextBox(pos, subdoc); |
| 2336 |
return true; |
| 2337 |
} |
| 2338 |
sendGroup(group, pos); |
| 2339 |
break; |
| 2340 |
} |
| 2341 |
default: |
| 2342 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendFrame: sending type %d is not implemented\n", frame.m_type)); |
| 2343 |
break; |
| 2344 |
} |
| 2345 |
frame.m_parsed = true; |
| 2346 |
return false; |
| 2347 |
} |
| 2348 |
|
| 2349 |
// try to read a basic comment zone |
| 2350 |
std::shared_ptr<HanMacWrdJGraphInternal::CommentFrame> HanMacWrdJGraph::readCommentData(HanMacWrdJGraphInternal::Frame const &header, long endPos) |
| 2351 |
{ |
| 2352 |
std::shared_ptr<HanMacWrdJGraphInternal::CommentFrame> comment; |
| 2353 |
|
| 2354 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2355 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 2356 |
libmwaw::DebugStream f; |
| 2357 |
|
| 2358 |
long pos = input->tell(); |
| 2359 |
if (endPos<pos+40) { |
| 2360 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readCommentData: the zone seems too short\n")); |
| 2361 |
return comment; |
| 2362 |
} |
| 2363 |
comment.reset(new HanMacWrdJGraphInternal::CommentFrame(header)); |
| 2364 |
comment->m_width = double(input->readLong(4))/65536.; |
| 2365 |
long val = input->readLong(2); // small number between 1 and 0x17 |
| 2366 |
if (val!=1) |
| 2367 |
f << "f0=" << val << ","; |
| 2368 |
val = input->readLong(2);// always 0? |
| 2369 |
if (val) |
| 2370 |
f << "f1=" << val << ","; |
| 2371 |
comment->m_cPos = long(input->readULong(4)); |
| 2372 |
val = long(input->readULong(4)); |
| 2373 |
f << "id0=" << std::hex << val << std::dec << ","; |
| 2374 |
comment->m_zId = long(input->readULong(4)); |
| 2375 |
for (int i=0; i < 4; ++i) { // g2=8000 if close? |
| 2376 |
val = input->readLong(2); |
| 2377 |
if (val) |
| 2378 |
f << "g" << i << "=" << val << ","; |
| 2379 |
} |
| 2380 |
float dim[2]; |
| 2381 |
for (auto &d : dim) d = float(input->readLong(4))/65536.f; |
| 2382 |
comment->m_dim=MWAWVec2f(dim[1],dim[0]); |
| 2383 |
for (int i=0; i < 2; ++i) { |
| 2384 |
val = input->readLong(2); |
| 2385 |
if (val) |
| 2386 |
f << "g" << i+4 << "=" << val << ","; |
| 2387 |
} |
| 2388 |
|
| 2389 |
std::string extra=f.str(); |
| 2390 |
comment->m_extra += extra; |
| 2391 |
f.str(""); |
| 2392 |
f << "FrameDef(Comment-data):" << comment->print() << extra; |
| 2393 |
if (input->tell() != endPos) |
| 2394 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2395 |
asciiFile.addPos(pos); |
| 2396 |
asciiFile.addNote(f.str().c_str()); |
| 2397 |
return comment; |
| 2398 |
} |
| 2399 |
|
| 2400 |
// try to read a basic picture zone |
| 2401 |
std::shared_ptr<HanMacWrdJGraphInternal::PictureFrame> HanMacWrdJGraph::readPictureData(HanMacWrdJGraphInternal::Frame const &header, long endPos) |
| 2402 |
{ |
| 2403 |
std::shared_ptr<HanMacWrdJGraphInternal::PictureFrame> picture; |
| 2404 |
|
| 2405 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2406 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 2407 |
libmwaw::DebugStream f; |
| 2408 |
|
| 2409 |
long pos = input->tell(); |
| 2410 |
if (endPos<pos+40) { |
| 2411 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readPictureData: the zone seems too short\n")); |
| 2412 |
return picture; |
| 2413 |
} |
| 2414 |
picture.reset(new HanMacWrdJGraphInternal::PictureFrame(header)); |
| 2415 |
long val; |
| 2416 |
for (int i=0; i < 2; ++i) { // always 0 |
| 2417 |
val = input->readLong(2); |
| 2418 |
if (val) |
| 2419 |
f << "f" << i << "=" << val << ","; |
| 2420 |
} |
| 2421 |
float fDim[2]; // a small size, typically 1x1 |
| 2422 |
for (auto &d : fDim) d = float(input->readLong(4))/65536.f; |
| 2423 |
picture->m_scale = MWAWVec2f(fDim[0], fDim[1]); |
| 2424 |
picture->m_zId = long(input->readULong(4)); |
| 2425 |
for (int i = 0; i < 2; ++i) { // f2=0, f3=0|-1 : maybe front/back color? |
| 2426 |
val = input->readLong(4); |
| 2427 |
if (val) |
| 2428 |
f << "f" << i << "=" << val << ","; |
| 2429 |
} |
| 2430 |
int dim[2]; |
| 2431 |
for (auto &d: dim) d = int(input->readLong(2)); |
| 2432 |
picture->m_dim=MWAWVec2i(dim[0],dim[1]); // checkme: xy |
| 2433 |
for (int i = 0; i < 6; ++i) { // g2=8400 |
| 2434 |
val = long(input->readULong(2)); |
| 2435 |
if (val) |
| 2436 |
f << "g" << i << "=" << std::hex << val << std::dec << ","; |
| 2437 |
} |
| 2438 |
std::string extra = f.str(); |
| 2439 |
picture->m_extra += extra; |
| 2440 |
f.str(""); |
| 2441 |
f << "FrameDef(picture-data):" << picture->print() << extra; |
| 2442 |
if (input->tell() != endPos) |
| 2443 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2444 |
asciiFile.addPos(pos); |
| 2445 |
asciiFile.addNote(f.str().c_str()); |
| 2446 |
return picture; |
| 2447 |
} |
| 2448 |
|
| 2449 |
// try to read a basic table zone |
| 2450 |
std::shared_ptr<HanMacWrdJGraphInternal::TableFrame> HanMacWrdJGraph::readTableData(HanMacWrdJGraphInternal::Frame const &header, long endPos) |
| 2451 |
{ |
| 2452 |
std::shared_ptr<HanMacWrdJGraphInternal::TableFrame> table; |
| 2453 |
|
| 2454 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2455 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 2456 |
libmwaw::DebugStream f; |
| 2457 |
|
| 2458 |
long pos = input->tell(); |
| 2459 |
if (endPos<pos+28) { |
| 2460 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTableData: the zone seems too short\n")); |
| 2461 |
return table; |
| 2462 |
} |
| 2463 |
table.reset(new HanMacWrdJGraphInternal::TableFrame(header)); |
| 2464 |
table->m_width = double(input->readLong(4))/65536.; |
| 2465 |
long val = input->readLong(2); // small number between 1 and 3 |
| 2466 |
if (val!=1) |
| 2467 |
f << "f0=" << val << ","; |
| 2468 |
val = input->readLong(2);// always 0? |
| 2469 |
if (val) |
| 2470 |
f << "f1=" << val << ","; |
| 2471 |
table->m_length = long(input->readULong(4)); |
| 2472 |
val = long(input->readULong(4)); |
| 2473 |
f << "id0=" << std::hex << val << std::dec << ","; |
| 2474 |
table->m_zId = long(input->readULong(4)); |
| 2475 |
for (int i = 0; i < 2; ++i) { |
| 2476 |
val = input->readLong(2); |
| 2477 |
if (val) f << "f" << i+2 << "=" << val << ","; |
| 2478 |
} |
| 2479 |
val = long(input->readULong(4)); |
| 2480 |
f << "id1=" << std::hex << val << std::dec << ","; |
| 2481 |
std::string extra=f.str(); |
| 2482 |
table->m_extra += extra; |
| 2483 |
f.str(""); |
| 2484 |
f << "FrameDef(table-data):" << table->print() << extra; |
| 2485 |
if (input->tell() != endPos) |
| 2486 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2487 |
asciiFile.addPos(pos); |
| 2488 |
asciiFile.addNote(f.str().c_str()); |
| 2489 |
return table; |
| 2490 |
} |
| 2491 |
|
| 2492 |
// try to read a basic text box zone |
| 2493 |
std::shared_ptr<HanMacWrdJGraphInternal::TextboxFrame> HanMacWrdJGraph::readTextboxData(HanMacWrdJGraphInternal::Frame const &header, long endPos) |
| 2494 |
{ |
| 2495 |
std::shared_ptr<HanMacWrdJGraphInternal::TextboxFrame> textbox; |
| 2496 |
|
| 2497 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2498 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 2499 |
libmwaw::DebugStream f; |
| 2500 |
|
| 2501 |
long pos = input->tell(); |
| 2502 |
if (endPos<pos+24) { |
| 2503 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTextboxData: the zone seems too short\n")); |
| 2504 |
return textbox; |
| 2505 |
} |
| 2506 |
textbox.reset(new HanMacWrdJGraphInternal::TextboxFrame(header)); |
| 2507 |
textbox->m_width = double(input->readLong(4))/65536.; |
| 2508 |
long val = input->readLong(2); // small number between 1 and 0x17 |
| 2509 |
if (val!=1) |
| 2510 |
f << "f0=" << val << ","; |
| 2511 |
val = input->readLong(2);// always 0? |
| 2512 |
if (val) |
| 2513 |
f << "f1=" << val << ","; |
| 2514 |
textbox->m_cPos = long(input->readULong(4)); |
| 2515 |
val = long(input->readULong(4)); |
| 2516 |
f << "id0=" << std::hex << val << std::dec << ","; |
| 2517 |
textbox->m_zId = long(input->readULong(4)); |
| 2518 |
float dim = float(input->readLong(4))/65536.f; // a small negative number: 0, -4 or -6.5 |
| 2519 |
if (dim < 0 || dim > 0) |
| 2520 |
f << "dim?=" << dim << ","; |
| 2521 |
std::string extra=f.str(); |
| 2522 |
textbox->m_extra += extra; |
| 2523 |
f.str(""); |
| 2524 |
f << "FrameDef(Textbox-data):" << textbox->print() << extra; |
| 2525 |
if (input->tell() != endPos) |
| 2526 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2527 |
asciiFile.addPos(pos); |
| 2528 |
asciiFile.addNote(f.str().c_str()); |
| 2529 |
return textbox; |
| 2530 |
} |
| 2531 |
|
| 2532 |
// try to read a basic text zone |
| 2533 |
std::shared_ptr<HanMacWrdJGraphInternal::TextFrame> HanMacWrdJGraph::readTextData(HanMacWrdJGraphInternal::Frame const &header, long endPos) |
| 2534 |
{ |
| 2535 |
std::shared_ptr<HanMacWrdJGraphInternal::TextFrame> text; |
| 2536 |
|
| 2537 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2538 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 2539 |
libmwaw::DebugStream f; |
| 2540 |
|
| 2541 |
long pos = input->tell(); |
| 2542 |
if (endPos<pos+20) { |
| 2543 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readTextData: the zone seems too short\n")); |
| 2544 |
return text; |
| 2545 |
} |
| 2546 |
text.reset(new HanMacWrdJGraphInternal::TextFrame(header)); |
| 2547 |
text->m_width = double(input->readLong(4))/65536.; |
| 2548 |
long val = input->readLong(2); // small number between 1 and 0x17 |
| 2549 |
if (val!=1) |
| 2550 |
f << "f0=" << val << ","; |
| 2551 |
val = input->readLong(2);// always 0? |
| 2552 |
if (val) |
| 2553 |
f << "f1=" << val << ","; |
| 2554 |
text->m_cPos = long(input->readULong(4)); |
| 2555 |
val = long(input->readULong(4)); |
| 2556 |
f << "id0=" << std::hex << val << std::dec << ","; |
| 2557 |
text->m_zId = long(input->readULong(4)); |
| 2558 |
|
| 2559 |
std::string extra=f.str(); |
| 2560 |
text->m_extra += extra; |
| 2561 |
f.str(""); |
| 2562 |
f << "FrameDef(Text-data):" << text->print() << extra; |
| 2563 |
if (input->tell() != endPos) |
| 2564 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2565 |
asciiFile.addPos(pos); |
| 2566 |
asciiFile.addNote(f.str().c_str()); |
| 2567 |
return text; |
| 2568 |
} |
| 2569 |
|
| 2570 |
// try to read a small graphic |
| 2571 |
std::shared_ptr<HanMacWrdJGraphInternal::ShapeGraph> HanMacWrdJGraph::readShapeGraph(HanMacWrdJGraphInternal::Frame const &header, long endPos) |
| 2572 |
{ |
| 2573 |
std::shared_ptr<HanMacWrdJGraphInternal::ShapeGraph> graph; |
| 2574 |
|
| 2575 |
MWAWInputStreamPtr input = m_parserState->m_input; |
| 2576 |
libmwaw::DebugFile &asciiFile = m_parserState->m_asciiFile; |
| 2577 |
libmwaw::DebugStream f; |
| 2578 |
|
| 2579 |
long pos = input->tell(); |
| 2580 |
if (endPos<pos+36) { |
| 2581 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::readShapeGraph: the zone seems too short\n")); |
| 2582 |
return graph; |
| 2583 |
} |
| 2584 |
|
| 2585 |
graph.reset(new HanMacWrdJGraphInternal::ShapeGraph(header)); |
| 2586 |
long val = static_cast<int>(input->readULong(1)); |
| 2587 |
auto graphType = static_cast<int>(val>>4); |
| 2588 |
auto flag = int(val&0xf); |
| 2589 |
bool isLine = graphType==0 || graphType==3; |
| 2590 |
bool ok = graphType >= 0 && graphType < 7; |
| 2591 |
MWAWBox2f bdbox=graph->m_pos; |
| 2592 |
MWAWGraphicShape &shape=graph->m_shape; |
| 2593 |
shape = MWAWGraphicShape(); |
| 2594 |
shape.m_bdBox = shape.m_formBox = bdbox; |
| 2595 |
if (isLine) { |
| 2596 |
graph->m_arrowsFlag = (flag>>2)&0x3; |
| 2597 |
flag &= 0x3; |
| 2598 |
} |
| 2599 |
auto flag1 = static_cast<int>(input->readULong(1)); |
| 2600 |
float angles[2]= {0,0}; |
| 2601 |
if (graphType==5) { // arc |
| 2602 |
auto transf = static_cast<int>((2*(flag&1)) | (flag1>>7)); |
| 2603 |
int decal = (transf%2) ? 4-transf : transf; |
| 2604 |
angles[0] = float(-90*decal); |
| 2605 |
angles[1] = float(90-90*decal); |
| 2606 |
flag &= 0xe; |
| 2607 |
flag1 &= 0x7f; |
| 2608 |
} |
| 2609 |
if (flag) f << "#fl0=" << std::hex << flag << std::dec << ","; |
| 2610 |
if (flag1) f << "#fl1=" << std::hex << flag1 << std::dec << ","; |
| 2611 |
val = input->readLong(2); // always 0 |
| 2612 |
if (val) f << "f0=" << val << ","; |
| 2613 |
|
| 2614 |
val = input->readLong(4); |
| 2615 |
float cornerDim=0; |
| 2616 |
if (graphType==4) |
| 2617 |
cornerDim = float(val)/65536.f; |
| 2618 |
else if (val) |
| 2619 |
f << "#cornerDim=" << val << ","; |
| 2620 |
if (isLine) { |
| 2621 |
shape.m_type=MWAWGraphicShape::Line; |
| 2622 |
float coord[2]; |
| 2623 |
for (int pt = 0; pt < 2; ++pt) { |
| 2624 |
for (auto &c : coord) c = float(input->readLong(4))/65536.f; |
| 2625 |
shape.m_vertices.push_back(MWAWVec2f(coord[1],coord[0])); |
| 2626 |
} |
| 2627 |
} |
| 2628 |
else { |
| 2629 |
switch (graphType) { |
| 2630 |
// case 0: already treated in isLine block |
| 2631 |
case 1: |
| 2632 |
shape.m_type = MWAWGraphicShape::Rectangle; |
| 2633 |
break; |
| 2634 |
case 2: |
| 2635 |
shape.m_type = MWAWGraphicShape::Circle; |
| 2636 |
break; |
| 2637 |
// case 3: already treated in isLine block |
| 2638 |
case 4: |
| 2639 |
shape.m_type = MWAWGraphicShape::Rectangle; |
| 2640 |
for (int c=0; c < 2; ++c) { |
| 2641 |
if (2.f*cornerDim <= bdbox.size()[c]) |
| 2642 |
shape.m_cornerWidth[c]=cornerDim; |
| 2643 |
else |
| 2644 |
shape.m_cornerWidth[c]=bdbox.size()[c]/2.0f; |
| 2645 |
} |
| 2646 |
break; |
| 2647 |
case 5: { |
| 2648 |
// we must compute the real bd box: first the box on the unit circle |
| 2649 |
float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 }; |
| 2650 |
int limitAngle[2]; |
| 2651 |
for (int i = 0; i < 2; ++i) |
| 2652 |
limitAngle[i] = (angles[i] < 0) ? int(angles[i]/90.f)-1 : int(angles[i]/90.f); |
| 2653 |
for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; ++bord) { |
| 2654 |
float ang = (bord == limitAngle[0]) ? float(angles[0]) : |
| 2655 |
(bord == limitAngle[1]+1) ? float(angles[1]) : float(90 * bord); |
| 2656 |
ang *= float(M_PI/180.); |
| 2657 |
float const actVal[2] = { std::cos(ang), -std::sin(ang)}; |
| 2658 |
if (actVal[0] < minVal[0]) minVal[0] = actVal[0]; |
| 2659 |
else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0]; |
| 2660 |
if (actVal[1] < minVal[1]) minVal[1] = actVal[1]; |
| 2661 |
else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1]; |
| 2662 |
} |
| 2663 |
float const factor[2]= {bdbox.size()[0]/(maxVal[0]>minVal[0]?maxVal[0]-minVal[0]:0.f), |
| 2664 |
bdbox.size()[1]/(maxVal[1]>minVal[1]?maxVal[1]-minVal[1]:0.f) |
| 2665 |
}; |
| 2666 |
float const delta[2]= {bdbox[0][0]-minVal[0] *factor[0],bdbox[0][1]-minVal[1] *factor[1]}; |
| 2667 |
shape.m_formBox=MWAWBox2f(MWAWVec2f(delta[0]-factor[0],delta[1]-factor[1]), |
| 2668 |
MWAWVec2f(delta[0]+factor[0],delta[1]+factor[1])); |
| 2669 |
shape.m_type=MWAWGraphicShape::Pie; |
| 2670 |
shape.m_arcAngles=MWAWVec2f(angles[0],angles[1]); |
| 2671 |
break; |
| 2672 |
} |
| 2673 |
case 6: |
| 2674 |
shape.m_type = MWAWGraphicShape::Polygon; |
| 2675 |
break; |
| 2676 |
default: |
| 2677 |
break; |
| 2678 |
} |
| 2679 |
for (int i = 0; i < 4; ++i) { |
| 2680 |
val = input->readLong(4); |
| 2681 |
if (val) f << "#coord" << i << "=" << val << ","; |
| 2682 |
} |
| 2683 |
} |
| 2684 |
auto id = long(input->readULong(4)); |
| 2685 |
if (id) { |
| 2686 |
if (graphType!=6) |
| 2687 |
f << "#id0=" << std::hex << id << std::dec << ","; |
| 2688 |
else |
| 2689 |
f << "id[poly]=" << std::hex << id << std::dec << ","; |
| 2690 |
} |
| 2691 |
id = long(input->readULong(4)); |
| 2692 |
f << "id=" << std::hex << id << std::dec << ","; |
| 2693 |
for (int i = 0; i < 2; ++i) { // always 1|0 |
| 2694 |
val = input->readLong(2); |
| 2695 |
if (val) f << "g" << i << "=" << val << ","; |
| 2696 |
} |
| 2697 |
std::string extra = f.str(); |
| 2698 |
graph->m_extra += extra; |
| 2699 |
|
| 2700 |
f.str(""); |
| 2701 |
f << "FrameDef(basicGraphic-data):" << graph->print() << extra; |
| 2702 |
|
| 2703 |
if (input->tell() != endPos) |
| 2704 |
asciiFile.addDelimiter(input->tell(),'|'); |
| 2705 |
asciiFile.addPos(pos); |
| 2706 |
asciiFile.addNote(f.str().c_str()); |
| 2707 |
if (!ok) |
| 2708 |
graph.reset(); |
| 2709 |
return graph; |
| 2710 |
} |
| 2711 |
|
| 2712 |
//////////////////////////////////////////////////////////// |
| 2713 |
// prepare data |
| 2714 |
//////////////////////////////////////////////////////////// |
| 2715 |
void HanMacWrdJGraph::prepareStructures() |
| 2716 |
{ |
| 2717 |
std::multimap<long,size_t> textZoneFrameMap; |
| 2718 |
auto numFrames = int(m_state->m_framesList.size()); |
| 2719 |
for (auto const &fIt : m_state->m_framesMap) { |
| 2720 |
int id = fIt.second; |
| 2721 |
if (id < 0 || id >= numFrames || !m_state->m_framesList[size_t(id)]) |
| 2722 |
continue; |
| 2723 |
auto const &frame = *m_state->m_framesList[size_t(id)]; |
| 2724 |
if (!frame.valid() || frame.m_type!=4) |
| 2725 |
continue; |
| 2726 |
auto const &text = static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(frame); |
| 2727 |
if (!text.m_zId) continue; |
| 2728 |
textZoneFrameMap.insert(std::multimap<long,size_t>::value_type(text.m_zId, size_t(id))); |
| 2729 |
} |
| 2730 |
auto tbIt=textZoneFrameMap.begin(); |
| 2731 |
while (tbIt!=textZoneFrameMap.end()) { |
| 2732 |
long textId=tbIt->first; |
| 2733 |
std::map<long, HanMacWrdJGraphInternal::TextboxFrame *> nCharTextMap; |
| 2734 |
bool ok=true; |
| 2735 |
while (tbIt!=textZoneFrameMap.end() && tbIt->first==textId) { |
| 2736 |
size_t id=tbIt++->second; |
| 2737 |
auto &text = static_cast<HanMacWrdJGraphInternal::TextboxFrame &>(*m_state->m_framesList[size_t(id)]); |
| 2738 |
if (nCharTextMap.find(text.m_cPos)!=nCharTextMap.end()) { |
| 2739 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::prepareStructures: pos %ld already exist for textZone %lx\n", |
| 2740 |
text.m_cPos, static_cast<long unsigned int>(textId))); |
| 2741 |
ok=false; |
| 2742 |
} |
| 2743 |
else |
| 2744 |
nCharTextMap[text.m_cPos]=&text; |
| 2745 |
} |
| 2746 |
size_t numIds=nCharTextMap.size(); |
| 2747 |
if (!ok || numIds<=1) continue; |
| 2748 |
HanMacWrdJGraphInternal::TextboxFrame *prevText=nullptr; |
| 2749 |
for (auto const &ctIt : nCharTextMap) { |
| 2750 |
HanMacWrdJGraphInternal::TextboxFrame *newText=ctIt.second; |
| 2751 |
if (prevText) { |
| 2752 |
prevText->m_linkToFId=newText->m_fileId; |
| 2753 |
newText->m_isLinked=true; |
| 2754 |
} |
| 2755 |
prevText=newText; |
| 2756 |
} |
| 2757 |
} |
| 2758 |
// now check that there is no loop |
| 2759 |
for (auto const &fIt : m_state->m_framesMap) { |
| 2760 |
int id = fIt.second; |
| 2761 |
if (id < 0 || id >= numFrames || !m_state->m_framesList[size_t(id)]) |
| 2762 |
continue; |
| 2763 |
auto const &frame = *m_state->m_framesList[size_t(id)]; |
| 2764 |
if (!frame.valid() || frame.m_inGroup || frame.m_type!=11) |
| 2765 |
continue; |
| 2766 |
std::set<long> seens; |
| 2767 |
checkGroupStructures(fIt.first, seens, false); |
| 2768 |
} |
| 2769 |
} |
| 2770 |
|
| 2771 |
bool HanMacWrdJGraph::checkGroupStructures(long zId, std::set<long> &seens, bool inGroup) |
| 2772 |
{ |
| 2773 |
while (seens.find(zId)!=seens.end()) { |
| 2774 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::checkGroupStructures: zone %ld already find\n", zId)); |
| 2775 |
return false; |
| 2776 |
} |
| 2777 |
seens.insert(zId); |
| 2778 |
auto fIt= m_state->m_framesMap.find(zId); |
| 2779 |
if (fIt==m_state->m_framesMap.end() || fIt->second < 0 || |
| 2780 |
fIt->second >= static_cast<int>(m_state->m_framesList.size()) || !m_state->m_framesList[size_t(fIt->second)]) { |
| 2781 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::checkGroupStructures: can not find zone %ld\n", zId)); |
| 2782 |
return false; |
| 2783 |
} |
| 2784 |
auto &frame = *m_state->m_framesList[size_t(fIt->second)]; |
| 2785 |
frame.m_inGroup=inGroup; |
| 2786 |
if (!frame.valid() || frame.m_type!=11) |
| 2787 |
return true; |
| 2788 |
auto &group = static_cast<HanMacWrdJGraphInternal::Group &>(frame); |
| 2789 |
for (size_t c=0; c < group.m_childsList.size(); ++c) { |
| 2790 |
if (checkGroupStructures(group.m_childsList[c], seens, true)) |
| 2791 |
continue; |
| 2792 |
group.m_childsList.resize(c); |
| 2793 |
break; |
| 2794 |
} |
| 2795 |
return true; |
| 2796 |
} |
| 2797 |
|
| 2798 |
//////////////////////////////////////////////////////////// |
| 2799 |
// send group |
| 2800 |
//////////////////////////////////////////////////////////// |
| 2801 |
bool HanMacWrdJGraph::sendGroup(long fId, MWAWPosition const &pos) |
| 2802 |
{ |
| 2803 |
if (!m_parserState->m_textListener) |
| 2804 |
return true; |
| 2805 |
auto fIt = m_state->m_framesMap.find(fId); |
| 2806 |
if (fIt == m_state->m_framesMap.end()) { |
| 2807 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroup: can not find table %lx\n", static_cast<long unsigned int>(fId))); |
| 2808 |
return false; |
| 2809 |
} |
| 2810 |
int id = fIt->second; |
| 2811 |
if (id < 0 || id >= static_cast<int>(m_state->m_framesList.size())) |
| 2812 |
return false; |
| 2813 |
auto &frame = *m_state->m_framesList[size_t(id)]; |
| 2814 |
if (!frame.valid() || frame.m_type != 11) { |
| 2815 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroup: can not find table %lx(II)\n", static_cast<long unsigned int>(fId))); |
| 2816 |
return false; |
| 2817 |
} |
| 2818 |
return sendGroup(static_cast<HanMacWrdJGraphInternal::Group &>(frame), pos); |
| 2819 |
} |
| 2820 |
|
| 2821 |
bool HanMacWrdJGraph::sendGroup(HanMacWrdJGraphInternal::Group const &group, MWAWPosition const &pos) |
| 2822 |
{ |
| 2823 |
group.m_parsed=true; |
| 2824 |
sendGroupChild(group,pos); |
| 2825 |
return true; |
| 2826 |
} |
| 2827 |
|
| 2828 |
bool HanMacWrdJGraph::canCreateGraphic(HanMacWrdJGraphInternal::Group const &group) |
| 2829 |
{ |
| 2830 |
int page = group.m_page; |
| 2831 |
auto numFrames = int(m_state->m_framesList.size()); |
| 2832 |
for (auto fId : group.m_childsList) { |
| 2833 |
auto fIt=m_state->m_framesMap.find(fId); |
| 2834 |
if (fIt == m_state->m_framesMap.end() || fIt->second < 0 || fIt->second >= numFrames || |
| 2835 |
!m_state->m_framesList[size_t(fIt->second)]) |
| 2836 |
continue; |
| 2837 |
auto const &frame=*m_state->m_framesList[size_t(fIt->second)]; |
| 2838 |
if (frame.m_page!=page) return false; |
| 2839 |
switch (frame.m_type) { |
| 2840 |
case 4: { |
| 2841 |
auto const &text=static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(frame); |
| 2842 |
if (text.isLinked() || !m_mainParser->canSendTextAsGraphic(text.m_zId,0)) |
| 2843 |
return false; |
| 2844 |
break; |
| 2845 |
} |
| 2846 |
case 8: // shape |
| 2847 |
break; |
| 2848 |
case 11: |
| 2849 |
if (!canCreateGraphic(static_cast<HanMacWrdJGraphInternal::Group const &>(frame))) |
| 2850 |
return false; |
| 2851 |
break; |
| 2852 |
default: |
| 2853 |
return false; |
| 2854 |
} |
| 2855 |
} |
| 2856 |
return true; |
| 2857 |
} |
| 2858 |
|
| 2859 |
void HanMacWrdJGraph::sendGroup(HanMacWrdJGraphInternal::Group const &group, MWAWGraphicListenerPtr const &listener) |
| 2860 |
{ |
| 2861 |
if (!listener) return; |
| 2862 |
group.m_parsed=true; |
| 2863 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 2864 |
auto numFrames = int(m_state->m_framesList.size()); |
| 2865 |
for (auto fId : group.m_childsList) { |
| 2866 |
auto fIt=m_state->m_framesMap.find(fId); |
| 2867 |
if (fIt == m_state->m_framesMap.end() || fIt->second < 0 || fIt->second >= numFrames || |
| 2868 |
!m_state->m_framesList[size_t(fIt->second)]) |
| 2869 |
continue; |
| 2870 |
auto const &frame=*m_state->m_framesList[size_t(fIt->second)]; |
| 2871 |
MWAWBox2f box=frame.getBdBox(); |
| 2872 |
auto const &format=m_state->getFrameFormat(frame.m_formatId); |
| 2873 |
MWAWPosition pictPos(box[0], box.size(), librevenge::RVNG_POINT); |
| 2874 |
pictPos.m_anchorTo=MWAWPosition::Page; |
| 2875 |
switch (frame.m_type) { |
| 2876 |
case 4: { |
| 2877 |
frame.m_parsed=true; |
| 2878 |
auto const &textbox=static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(frame); |
| 2879 |
MWAWSubDocumentPtr subdoc |
| 2880 |
(new HanMacWrdJGraphInternal::SubDocument(*this, input, HanMacWrdJGraphInternal::SubDocument::Text, textbox.m_zId)); |
| 2881 |
listener->insertTextBox(pictPos, subdoc, format.m_style); |
| 2882 |
break; |
| 2883 |
} |
| 2884 |
case 8: { |
| 2885 |
frame.m_parsed=true; |
| 2886 |
auto const &shape=static_cast<HanMacWrdJGraphInternal::ShapeGraph const &>(frame); |
| 2887 |
MWAWGraphicStyle style(format.m_style);; |
| 2888 |
if (shape.m_shape.m_type==MWAWGraphicShape::Line) { |
| 2889 |
if (shape.m_arrowsFlag&1) style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain(); |
| 2890 |
if (shape.m_arrowsFlag&2) style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 2891 |
} |
| 2892 |
listener->insertShape(pictPos, shape.m_shape, style); |
| 2893 |
break; |
| 2894 |
} |
| 2895 |
case 11: |
| 2896 |
sendGroup(static_cast<HanMacWrdJGraphInternal::Group const &>(frame), listener); |
| 2897 |
break; |
| 2898 |
default: |
| 2899 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroup: unexpected type %d\n", frame.m_type)); |
| 2900 |
break; |
| 2901 |
} |
| 2902 |
} |
| 2903 |
} |
| 2904 |
|
| 2905 |
void HanMacWrdJGraph::sendGroupChild(HanMacWrdJGraphInternal::Group const &group, MWAWPosition const &pos) |
| 2906 |
{ |
| 2907 |
MWAWTextListenerPtr listener=m_parserState->m_textListener; |
| 2908 |
if (!listener) { |
| 2909 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroupChild: can not find the listeners\n")); |
| 2910 |
return; |
| 2911 |
} |
| 2912 |
size_t numChilds=group.m_childsList.size(), childNotSent=0; |
| 2913 |
if (!numChilds) return; |
| 2914 |
|
| 2915 |
int numDataToMerge=0; |
| 2916 |
MWAWBox2f partialBdBox; |
| 2917 |
MWAWPosition partialPos(pos); |
| 2918 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 2919 |
auto numFrames = int(m_state->m_framesList.size()); |
| 2920 |
for (size_t c=0; c<numChilds; ++c) { |
| 2921 |
long fId=group.m_childsList[c]; |
| 2922 |
auto fIt=m_state->m_framesMap.find(fId); |
| 2923 |
if (fIt == m_state->m_framesMap.end() || fIt->second < 0 || fIt->second >= numFrames || |
| 2924 |
!m_state->m_framesList[size_t(fIt->second)]) { |
| 2925 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroupChild: can not find child %lx\n", static_cast<long unsigned int>(fId))); |
| 2926 |
continue; |
| 2927 |
} |
| 2928 |
auto const &frame=*m_state->m_framesList[size_t(fIt->second)]; |
| 2929 |
bool canMerge=false; |
| 2930 |
if (frame.m_page==group.m_page) { |
| 2931 |
switch (frame.m_type) { |
| 2932 |
case 4: { |
| 2933 |
auto const &text=static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(frame); |
| 2934 |
canMerge=!text.isLinked()&&m_mainParser->canSendTextAsGraphic(text.m_zId,0); |
| 2935 |
break; |
| 2936 |
} |
| 2937 |
case 8: // shape |
| 2938 |
canMerge = true; |
| 2939 |
break; |
| 2940 |
case 11: |
| 2941 |
canMerge = canCreateGraphic(static_cast<HanMacWrdJGraphInternal::Group const &>(frame)); |
| 2942 |
break; |
| 2943 |
default: |
| 2944 |
break; |
| 2945 |
} |
| 2946 |
} |
| 2947 |
bool isLast=false; |
| 2948 |
if (canMerge) { |
| 2949 |
MWAWBox2f box=frame.getBdBox(); |
| 2950 |
if (numDataToMerge == 0) |
| 2951 |
partialBdBox=box; |
| 2952 |
else |
| 2953 |
partialBdBox=partialBdBox.getUnion(box); |
| 2954 |
++numDataToMerge; |
| 2955 |
if (c+1 < numChilds) |
| 2956 |
continue; |
| 2957 |
isLast=true; |
| 2958 |
} |
| 2959 |
|
| 2960 |
if (numDataToMerge>1) { |
| 2961 |
partialBdBox.extend(3); |
| 2962 |
MWAWGraphicEncoder graphicEncoder; |
| 2963 |
MWAWGraphicListenerPtr graphicListener(new MWAWGraphicListener(*m_parserState, partialBdBox, &graphicEncoder)); |
| 2964 |
graphicListener->startDocument(); |
| 2965 |
size_t lastChild = isLast ? c : c-1; |
| 2966 |
for (size_t ch=childNotSent; ch <= lastChild; ++ch) { |
| 2967 |
long localFId=group.m_childsList[ch]; |
| 2968 |
fIt=m_state->m_framesMap.find(localFId); |
| 2969 |
if (fIt == m_state->m_framesMap.end() || fIt->second < 0 || fIt->second >= numFrames || |
| 2970 |
!m_state->m_framesList[size_t(fIt->second)]) |
| 2971 |
continue; |
| 2972 |
auto const &child=*m_state->m_framesList[size_t(fIt->second)]; |
| 2973 |
MWAWBox2f box=child.getBdBox(); |
| 2974 |
auto const &format=m_state->getFrameFormat(child.m_formatId); |
| 2975 |
MWAWPosition pictPos(box[0], box.size(), librevenge::RVNG_POINT); |
| 2976 |
pictPos.m_anchorTo=MWAWPosition::Page; |
| 2977 |
switch (child.m_type) { |
| 2978 |
case 4: { |
| 2979 |
child.m_parsed=true; |
| 2980 |
auto const &textbox=static_cast<HanMacWrdJGraphInternal::TextboxFrame const &>(child); |
| 2981 |
MWAWSubDocumentPtr subdoc |
| 2982 |
(new HanMacWrdJGraphInternal::SubDocument(*this, input, HanMacWrdJGraphInternal::SubDocument::Text, textbox.m_zId)); |
| 2983 |
graphicListener->insertTextBox(pictPos, subdoc, format.m_style); |
| 2984 |
break; |
| 2985 |
} |
| 2986 |
case 8: { |
| 2987 |
child.m_parsed=true; |
| 2988 |
auto const &shape=static_cast<HanMacWrdJGraphInternal::ShapeGraph const &>(child); |
| 2989 |
MWAWGraphicStyle style(format.m_style); |
| 2990 |
if (shape.m_shape.m_type==MWAWGraphicShape::Line) { |
| 2991 |
if (shape.m_arrowsFlag&1) style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain(); |
| 2992 |
if (shape.m_arrowsFlag&2) style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 2993 |
} |
| 2994 |
graphicListener->insertShape(pictPos, shape.m_shape, style); |
| 2995 |
break; |
| 2996 |
} |
| 2997 |
case 11: |
| 2998 |
sendGroup(static_cast<HanMacWrdJGraphInternal::Group const &>(child), graphicListener); |
| 2999 |
break; |
| 3000 |
default: |
| 3001 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroupChild: unexpected type %d\n", child.m_type)); |
| 3002 |
break; |
| 3003 |
} |
| 3004 |
} |
| 3005 |
graphicListener->endDocument(); |
| 3006 |
MWAWEmbeddedObject picture; |
| 3007 |
if (graphicEncoder.getBinaryResult(picture)) { |
| 3008 |
partialPos.setOrigin(pos.origin()+partialBdBox[0]-group.m_pos[0]); |
| 3009 |
partialPos.setSize(partialBdBox.size()); |
| 3010 |
listener->insertPicture(partialPos, picture); |
| 3011 |
if (isLast) |
| 3012 |
break; |
| 3013 |
childNotSent=c; |
| 3014 |
} |
| 3015 |
} |
| 3016 |
|
| 3017 |
// time to send back the data |
| 3018 |
for (; childNotSent <= c; ++childNotSent) { |
| 3019 |
long localFId=group.m_childsList[childNotSent]; |
| 3020 |
fIt=m_state->m_framesMap.find(localFId); |
| 3021 |
if (fIt == m_state->m_framesMap.end() || fIt->second < 0 || fIt->second >= numFrames || |
| 3022 |
!m_state->m_framesList[size_t(fIt->second)]) { |
| 3023 |
MWAW_DEBUG_MSG(("HanMacWrdJGraph::sendGroup: can not find child %lx\n", static_cast<long unsigned int>(localFId))); |
| 3024 |
continue; |
| 3025 |
} |
| 3026 |
auto const &childFrame=*m_state->m_framesList[size_t(fIt->second)]; |
| 3027 |
MWAWPosition fPos(pos); |
| 3028 |
fPos.setOrigin(childFrame.m_pos[0]-group.m_pos[0]+pos.origin()); |
| 3029 |
fPos.setSize(childFrame.m_pos.size()); |
| 3030 |
sendFrame(childFrame, fPos); |
| 3031 |
} |
| 3032 |
numDataToMerge=0; |
| 3033 |
} |
| 3034 |
} |
| 3035 |
|
| 3036 |
//////////////////////////////////////////////////////////// |
| 3037 |
// send data |
| 3038 |
//////////////////////////////////////////////////////////// |
| 3039 |
bool HanMacWrdJGraph::sendPageGraphics(std::vector<long> const &doNotSendIds) |
| 3040 |
{ |
| 3041 |
if (!m_parserState->m_textListener) |
| 3042 |
return true; |
| 3043 |
std::set<long> notSend; |
| 3044 |
for (auto id : doNotSendIds) |
| 3045 |
notSend.insert(id); |
| 3046 |
auto numFrames = int(m_state->m_framesList.size()); |
| 3047 |
for (auto const &fIt : m_state->m_framesMap) { |
| 3048 |
int id = fIt.second; |
| 3049 |
if (notSend.find(fIt.first) != notSend.end() || id < 0 || id >= numFrames || |
| 3050 |
!m_state->m_framesList[size_t(id)]) |
| 3051 |
continue; |
| 3052 |
auto const &frame = *m_state->m_framesList[size_t(id)]; |
| 3053 |
if (!frame.valid() || frame.m_parsed || frame.m_inGroup) |
| 3054 |
continue; |
| 3055 |
if (frame.m_type <= 3 || frame.m_type == 12) continue; |
| 3056 |
MWAWPosition pos(frame.m_pos[0],frame.m_pos.size(),librevenge::RVNG_POINT); |
| 3057 |
pos.setRelativePosition(MWAWPosition::Page); |
| 3058 |
pos.setPage(frame.m_page+1); |
| 3059 |
sendFrame(frame, pos); |
| 3060 |
} |
| 3061 |
return true; |
| 3062 |
} |
| 3063 |
|
| 3064 |
void HanMacWrdJGraph::flushExtra() |
| 3065 |
{ |
| 3066 |
if (!m_parserState->m_textListener) |
| 3067 |
return; |
| 3068 |
for (auto const &frame : m_state->m_framesList) { |
| 3069 |
if (!frame || !frame->valid() || frame->m_parsed) |
| 3070 |
continue; |
| 3071 |
if (frame->m_type <= 3 || frame->m_type == 12) continue; |
| 3072 |
MWAWPosition pos(MWAWVec2f(0,0),MWAWVec2f(0,0),librevenge::RVNG_POINT); |
| 3073 |
pos.setRelativePosition(MWAWPosition::Char); |
| 3074 |
sendFrame(*frame, pos); |
| 3075 |
} |
| 3076 |
} |
| 3077 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |