| 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 |
#include <stack> |
| 42 |
|
| 43 |
#include <librevenge/librevenge.h> |
| 44 |
|
| 45 |
#include "MWAWFont.hxx" |
| 46 |
#include "MWAWGraphicListener.hxx" |
| 47 |
#include "MWAWGraphicShape.hxx" |
| 48 |
#include "MWAWGraphicStyle.hxx" |
| 49 |
#include "MWAWListener.hxx" |
| 50 |
#include "MWAWParagraph.hxx" |
| 51 |
#include "MWAWParser.hxx" |
| 52 |
#include "MWAWPictBitmap.hxx" |
| 53 |
#include "MWAWPictMac.hxx" |
| 54 |
#include "MWAWPosition.hxx" |
| 55 |
#include "MWAWSubDocument.hxx" |
| 56 |
|
| 57 |
#include "ClarisWksStruct.hxx" |
| 58 |
|
| 59 |
#include "ClarisDrawParser.hxx" |
| 60 |
#include "ClarisDrawStyleManager.hxx" |
| 61 |
|
| 62 |
#include "ClarisDrawGraph.hxx" |
| 63 |
|
| 64 |
#include "libmwaw_internal.hxx" |
| 65 |
|
| 66 |
/** Internal: the structures of a ClarisDrawGraph */ |
| 67 |
namespace ClarisDrawGraphInternal |
| 68 |
{ |
| 69 |
//! Internal: the structure used to a point of a ClarisDrawGraph |
| 70 |
struct CurvePoint { |
| 71 |
explicit CurvePoint(MWAWVec2f point=MWAWVec2f()) |
| 72 |
: m_pos(point) |
| 73 |
, m_type(1) |
| 74 |
{ |
| 75 |
for (auto &control : m_controlPoints) control = point; |
| 76 |
} |
| 77 |
//! operator<< |
| 78 |
friend std::ostream &operator<<(std::ostream &o, CurvePoint const &pt) |
| 79 |
{ |
| 80 |
o << pt.m_pos; |
| 81 |
if (pt.m_pos != pt.m_controlPoints[0]) |
| 82 |
o << ":prev=" << pt.m_controlPoints[0]; |
| 83 |
if (pt.m_pos != pt.m_controlPoints[1]) |
| 84 |
o << ":next=" << pt.m_controlPoints[1]; |
| 85 |
switch (pt.m_type) { |
| 86 |
case 0: |
| 87 |
o << ":point2"; |
| 88 |
break; |
| 89 |
case 1: |
| 90 |
break; |
| 91 |
case 2: |
| 92 |
o << ":spline"; |
| 93 |
break; |
| 94 |
case 3: |
| 95 |
o << ":spline2"; |
| 96 |
break; |
| 97 |
default: |
| 98 |
o << ":#type=" << pt.m_type; |
| 99 |
} |
| 100 |
return o; |
| 101 |
} |
| 102 |
//! the main position |
| 103 |
MWAWVec2f m_pos; |
| 104 |
//! the control point: previous, next |
| 105 |
MWAWVec2f m_controlPoints[2]; |
| 106 |
//! the point type |
| 107 |
int m_type; |
| 108 |
}; |
| 109 |
|
| 110 |
//! Internal: the structure used to store a transformation ClarisDrawGraph |
| 111 |
struct Transformation { |
| 112 |
//! constructor |
| 113 |
Transformation() |
| 114 |
: m_rotate(0) |
| 115 |
, m_originalSize() |
| 116 |
{ |
| 117 |
for (auto &val : m_values) val=0; |
| 118 |
} |
| 119 |
friend std::ostream &operator<<(std::ostream &o, Transformation const &trans) |
| 120 |
{ |
| 121 |
if (trans.m_rotate<0||trans.m_rotate>0) |
| 122 |
o << "rot=" << trans.m_rotate << ","; |
| 123 |
if (trans.m_originalSize!=MWAWVec2f(0,0)) |
| 124 |
o << "size=" << trans.m_originalSize << ","; |
| 125 |
o << "val=["; |
| 126 |
for (float value : trans.m_values) o << value << ","; |
| 127 |
o << "],"; |
| 128 |
return o; |
| 129 |
} |
| 130 |
|
| 131 |
//! the rotation |
| 132 |
float m_rotate; |
| 133 |
//! the original size |
| 134 |
MWAWVec2f m_originalSize; |
| 135 |
//! other values |
| 136 |
float m_values[2]; |
| 137 |
}; |
| 138 |
//! Internal: the structure used to store a style of a ClarisDrawGraph |
| 139 |
struct Style final : public MWAWGraphicStyle { |
| 140 |
//! constructor |
| 141 |
Style() |
| 142 |
: MWAWGraphicStyle() |
| 143 |
, m_wrapping(0) |
| 144 |
, m_surfacePatternType(0) |
| 145 |
{ |
| 146 |
} |
| 147 |
Style(Style const &)=default; |
| 148 |
//! destructor |
| 149 |
~Style() final; |
| 150 |
//! returns the wrapping |
| 151 |
MWAWPosition::Wrapping getWrapping() const |
| 152 |
{ |
| 153 |
switch (m_wrapping&3) { |
| 154 |
case 0: |
| 155 |
return MWAWPosition::WBackground; |
| 156 |
case 1: |
| 157 |
case 2: |
| 158 |
return MWAWPosition::WDynamic; |
| 159 |
default: |
| 160 |
break; |
| 161 |
} |
| 162 |
return MWAWPosition::WNone; |
| 163 |
} |
| 164 |
//! operator<< |
| 165 |
friend std::ostream &operator<<(std::ostream &o, Style const &st) |
| 166 |
{ |
| 167 |
o << static_cast<MWAWGraphicStyle const &>(st); |
| 168 |
switch (st.m_wrapping & 3) { |
| 169 |
case 0: |
| 170 |
o << "wrap=none,"; |
| 171 |
break; // RunThrough |
| 172 |
case 1: |
| 173 |
o << "wrap=regular,"; |
| 174 |
break; // Page Wrap |
| 175 |
case 2: |
| 176 |
o << "wrap=irregular,"; |
| 177 |
break; // Optimal page Wrap |
| 178 |
default: |
| 179 |
o << "#wrap=3,"; |
| 180 |
break; |
| 181 |
} |
| 182 |
switch (st.m_surfacePatternType) { |
| 183 |
case 0: |
| 184 |
break; // pattern |
| 185 |
case 1: |
| 186 |
o << "wallPattern,"; |
| 187 |
break; |
| 188 |
default: |
| 189 |
o << "pattType=" << st.m_surfacePatternType << ","; |
| 190 |
} |
| 191 |
return o; |
| 192 |
} |
| 193 |
//! the wrap type |
| 194 |
int m_wrapping; |
| 195 |
//! the surface pattern type |
| 196 |
int m_surfacePatternType; |
| 197 |
}; |
| 198 |
|
| 199 |
Style::~Style() |
| 200 |
{ |
| 201 |
} |
| 202 |
|
| 203 |
//! Internal: the generic structure used to store a zone of a ClarisDrawGraph |
| 204 |
struct Zone { |
| 205 |
//! the list of types |
| 206 |
enum Type { T_Zone, T_Pict, T_Shape, T_Unknown, |
| 207 |
/* basic subtype */ |
| 208 |
T_Line, T_Rect, T_RectOval, T_Oval, T_Arc, T_Poly, T_Connector |
| 209 |
}; |
| 210 |
//! constructor |
| 211 |
Zone() |
| 212 |
: m_zoneType(0) |
| 213 |
, m_flag(0) |
| 214 |
, m_page(-1) |
| 215 |
, m_box() |
| 216 |
, m_ordering(-1) |
| 217 |
, m_style() {} |
| 218 |
Zone(Zone const &)=default; |
| 219 |
//! destructor |
| 220 |
virtual ~Zone(); |
| 221 |
//! operator<< |
| 222 |
friend std::ostream &operator<<(std::ostream &o, Zone const &zone) |
| 223 |
{ |
| 224 |
if (zone.m_flag) o << "fl=" << std::hex << zone.m_flag << std::dec << ","; |
| 225 |
if (zone.m_page >= 0) o << "pg=" << zone.m_page << ","; |
| 226 |
o << "box=" << zone.m_box << ","; |
| 227 |
if (zone.m_ordering>0) o << "ordering=" << zone.m_ordering << ","; |
| 228 |
switch (zone.m_zoneType&0xF) { |
| 229 |
case 0: |
| 230 |
break; |
| 231 |
case 4: |
| 232 |
o << "header/footer,"; |
| 233 |
break; |
| 234 |
case 0xa: |
| 235 |
o << "master,"; |
| 236 |
break; |
| 237 |
default: |
| 238 |
o << "zoneType=" << (zone.m_zoneType&0xF) << ","; |
| 239 |
break; |
| 240 |
} |
| 241 |
if (zone.m_zoneType&0x20) |
| 242 |
o << "zoneType[0x20],"; |
| 243 |
zone.print(o); |
| 244 |
o << "style=[" << zone.m_style << "],"; |
| 245 |
return o; |
| 246 |
} |
| 247 |
//! return the zone bdbox |
| 248 |
MWAWBox2f getBdBox() const |
| 249 |
{ |
| 250 |
MWAWVec2f minPt(m_box[0][0], m_box[0][1]); |
| 251 |
MWAWVec2f maxPt(m_box[1][0], m_box[1][1]); |
| 252 |
for (int c=0; c<2; ++c) { |
| 253 |
if (m_box.size()[c]>=0) continue; |
| 254 |
minPt[c]=m_box[1][c]; |
| 255 |
maxPt[c]=m_box[0][c]; |
| 256 |
} |
| 257 |
return MWAWBox2f(minPt,maxPt); |
| 258 |
} |
| 259 |
//! return the main type |
| 260 |
virtual Type getType() const |
| 261 |
{ |
| 262 |
return T_Unknown; |
| 263 |
} |
| 264 |
//! return the subtype |
| 265 |
virtual Type getSubType() const |
| 266 |
{ |
| 267 |
return T_Unknown; |
| 268 |
} |
| 269 |
//! return the number of data to define this zone in the file |
| 270 |
virtual int getNumData() const |
| 271 |
{ |
| 272 |
return 0; |
| 273 |
} |
| 274 |
//! print the data contains |
| 275 |
virtual void print(std::ostream &) const { } |
| 276 |
//! return a child corresponding to this zone |
| 277 |
virtual ClarisWksStruct::DSET::Child getChild() const |
| 278 |
{ |
| 279 |
ClarisWksStruct::DSET::Child child; |
| 280 |
child.m_box = m_box; |
| 281 |
return child; |
| 282 |
} |
| 283 |
//! returns the id of the reference zone |
| 284 |
virtual int getZoneId() const |
| 285 |
{ |
| 286 |
return 0; |
| 287 |
} |
| 288 |
//! the zone type |
| 289 |
int m_zoneType; |
| 290 |
//! the zone main flag |
| 291 |
int m_flag; |
| 292 |
//! the page (checkme: or frame linked ) |
| 293 |
int m_page; |
| 294 |
//! the bdbox |
| 295 |
MWAWBox2f m_box; |
| 296 |
//! the ordering |
| 297 |
int m_ordering; |
| 298 |
//! the style |
| 299 |
Style m_style; |
| 300 |
}; |
| 301 |
|
| 302 |
Zone::~Zone() |
| 303 |
{ |
| 304 |
} |
| 305 |
//! Internal: small class to store a basic graphic zone of a ClarisDrawGraph |
| 306 |
struct ZoneShape final : public Zone { |
| 307 |
//! constructor |
| 308 |
ZoneShape(Zone const &z, Type type) : Zone(z), m_type(type), m_shape(), m_autosize(false) |
| 309 |
{ |
| 310 |
} |
| 311 |
//! destructor |
| 312 |
~ZoneShape() final; |
| 313 |
//! print the data |
| 314 |
void print(std::ostream &o) const final |
| 315 |
{ |
| 316 |
o << m_shape; |
| 317 |
if (m_autosize) o << "autosize,"; |
| 318 |
} |
| 319 |
//! return the main type |
| 320 |
Type getType() const final |
| 321 |
{ |
| 322 |
return T_Shape; |
| 323 |
} |
| 324 |
//! return the sub type |
| 325 |
Type getSubType() const final |
| 326 |
{ |
| 327 |
return m_type; |
| 328 |
} |
| 329 |
//! return the number of data |
| 330 |
int getNumData() const final |
| 331 |
{ |
| 332 |
return (m_type==T_Connector || m_type==T_Poly) ? 1 : 0; |
| 333 |
} |
| 334 |
//! return a child corresponding to this zone |
| 335 |
ClarisWksStruct::DSET::Child getChild() const final |
| 336 |
{ |
| 337 |
ClarisWksStruct::DSET::Child child; |
| 338 |
child.m_box = m_box; |
| 339 |
child.m_type = ClarisWksStruct::DSET::C_Graphic; |
| 340 |
return child; |
| 341 |
} |
| 342 |
|
| 343 |
//! the sub type |
| 344 |
Type m_type; |
| 345 |
//! the shape |
| 346 |
MWAWGraphicShape m_shape; |
| 347 |
//! true if autosize is set |
| 348 |
bool m_autosize; |
| 349 |
}; |
| 350 |
|
| 351 |
ZoneShape::~ZoneShape() |
| 352 |
{ |
| 353 |
} |
| 354 |
|
| 355 |
//! Internal: the structure used to store a PICT |
| 356 |
struct ZonePict final : public Zone { |
| 357 |
//! constructor |
| 358 |
explicit ZonePict(Zone const &z) : Zone(z), m_type(T_Pict) |
| 359 |
{ |
| 360 |
} |
| 361 |
//! destructor |
| 362 |
~ZonePict() final; |
| 363 |
//! print the data |
| 364 |
void print(std::ostream &o) const final |
| 365 |
{ |
| 366 |
o << "PICTURE,"; |
| 367 |
} |
| 368 |
//! return the main type T_Picture |
| 369 |
Type getType() const final |
| 370 |
{ |
| 371 |
return T_Pict; |
| 372 |
} |
| 373 |
//! return the sub type |
| 374 |
Type getSubType() const final |
| 375 |
{ |
| 376 |
return T_Pict; |
| 377 |
} |
| 378 |
//! return the number of data in a file |
| 379 |
int getNumData() const final |
| 380 |
{ |
| 381 |
return 2; |
| 382 |
} |
| 383 |
//! return a child corresponding to this zone |
| 384 |
ClarisWksStruct::DSET::Child getChild() const final |
| 385 |
{ |
| 386 |
ClarisWksStruct::DSET::Child child; |
| 387 |
child.m_box = m_box; |
| 388 |
child.m_type = ClarisWksStruct::DSET::C_Graphic; |
| 389 |
return child; |
| 390 |
} |
| 391 |
|
| 392 |
//! the sub type |
| 393 |
Type m_type; |
| 394 |
//! the picture entry followed by a ps entry or ole entry ( if defined) |
| 395 |
MWAWEntry m_entries[2]; |
| 396 |
}; |
| 397 |
|
| 398 |
ZonePict::~ZonePict() |
| 399 |
{ |
| 400 |
} |
| 401 |
|
| 402 |
//! Internal: structure to store a bitmap of a ClarisDrawGraph |
| 403 |
struct Bitmap final : public ClarisWksStruct::DSET { |
| 404 |
//! constructor |
| 405 |
explicit Bitmap(ClarisWksStruct::DSET const &dset = ClarisWksStruct::DSET()) |
| 406 |
: DSET(dset) |
| 407 |
, m_numBytesPerPixel(0) |
| 408 |
, m_bitmapSize(0,0) |
| 409 |
, m_bitmapRowSize(0) |
| 410 |
, m_entry() |
| 411 |
, m_colorMap() |
| 412 |
{ |
| 413 |
} |
| 414 |
//! destructor |
| 415 |
~Bitmap() final; |
| 416 |
//! operator<< |
| 417 |
friend std::ostream &operator<<(std::ostream &o, Bitmap const &bt) |
| 418 |
{ |
| 419 |
o << static_cast<ClarisWksStruct::DSET const &>(bt); |
| 420 |
if (bt.m_numBytesPerPixel > 0) o << "type=" << bt.m_numBytesPerPixel << ","; |
| 421 |
else if (bt.m_numBytesPerPixel < 0) o << "type=1/" << (-bt.m_numBytesPerPixel) << ","; |
| 422 |
return o; |
| 423 |
} |
| 424 |
|
| 425 |
//! the number of bite by pixel |
| 426 |
int m_numBytesPerPixel; |
| 427 |
//! the bitmap size |
| 428 |
MWAWVec2i m_bitmapSize; |
| 429 |
//! the bitmap row size in the file ( with potential alignment) |
| 430 |
int m_bitmapRowSize; |
| 431 |
//! the bitmap entry |
| 432 |
MWAWEntry m_entry; |
| 433 |
//! the color map |
| 434 |
std::vector<MWAWColor> m_colorMap; |
| 435 |
}; |
| 436 |
|
| 437 |
Bitmap::~Bitmap() |
| 438 |
{ |
| 439 |
} |
| 440 |
|
| 441 |
//! Internal: structure to store a link to a zone of a ClarisDrawGraph |
| 442 |
struct ZoneZone final : public Zone { |
| 443 |
//! constructor |
| 444 |
ZoneZone(Zone const &z, Type fileType) |
| 445 |
: Zone(z) |
| 446 |
, m_subType(fileType) |
| 447 |
, m_id(-1) |
| 448 |
, m_subId(-1) |
| 449 |
, m_frameId(-1) |
| 450 |
, m_frameSubId(-1) |
| 451 |
, m_frameLast(true) |
| 452 |
, m_transformationId(-1) |
| 453 |
, m_wrappingSep(5) |
| 454 |
{ |
| 455 |
for (auto &fl : m_flags) fl = 0; |
| 456 |
} |
| 457 |
//! destructor |
| 458 |
~ZoneZone() final; |
| 459 |
//! return true if the zone is a note |
| 460 |
bool isANote() const |
| 461 |
{ |
| 462 |
return m_flags[5]==1; |
| 463 |
} |
| 464 |
/** check if we need to send the frame is linked to another frmae */ |
| 465 |
bool isLinked() const |
| 466 |
{ |
| 467 |
return m_frameId>=0 && m_frameSubId>=0; |
| 468 |
} |
| 469 |
/** add the frame name if needed */ |
| 470 |
bool addFrameName(MWAWGraphicStyle &style) const |
| 471 |
{ |
| 472 |
if (!isLinked()) return false; |
| 473 |
if (m_frameSubId>0) { |
| 474 |
librevenge::RVNGString fName; |
| 475 |
fName.sprintf("Frame%d-%d", m_frameId, m_frameSubId); |
| 476 |
style.m_frameName=fName.cstr(); |
| 477 |
} |
| 478 |
if (!m_frameLast) { |
| 479 |
librevenge::RVNGString fName; |
| 480 |
fName.sprintf("Frame%d-%d", m_frameId, m_frameSubId+1); |
| 481 |
style.m_frameNextName=fName.cstr(); |
| 482 |
} |
| 483 |
return true; |
| 484 |
} |
| 485 |
|
| 486 |
//! print the zone |
| 487 |
void print(std::ostream &o) const final |
| 488 |
{ |
| 489 |
o << "ZONE, id=" << m_id << ","; |
| 490 |
if (m_subId > 0) o << "subId=" << m_subId << ","; |
| 491 |
if (m_transformationId >= 0) o << "transf=T" << m_transformationId << ","; |
| 492 |
if (m_wrappingSep != 5) o << "wrappingSep=" << m_wrappingSep << ","; |
| 493 |
for (int i = 0; i < 9; i++) { |
| 494 |
if (m_flags[i]) o << "fl" << i << "=" << m_flags[i] << ","; |
| 495 |
} |
| 496 |
} |
| 497 |
//! return the main type Zone |
| 498 |
Type getType() const final |
| 499 |
{ |
| 500 |
return T_Zone; |
| 501 |
} |
| 502 |
//! return the sub type Zone |
| 503 |
Type getSubType() const final |
| 504 |
{ |
| 505 |
return m_subType; |
| 506 |
} |
| 507 |
//! return the number of data to define this zone in the file |
| 508 |
int getNumData() const final |
| 509 |
{ |
| 510 |
return 0; |
| 511 |
} |
| 512 |
//! returns the id of the reference zone |
| 513 |
int getZoneId() const final |
| 514 |
{ |
| 515 |
return m_id; |
| 516 |
} |
| 517 |
|
| 518 |
//! return a child corresponding to this zone |
| 519 |
ClarisWksStruct::DSET::Child getChild() const final |
| 520 |
{ |
| 521 |
ClarisWksStruct::DSET::Child child; |
| 522 |
child.m_box = m_box; |
| 523 |
child.m_id = m_id; |
| 524 |
child.m_type = ClarisWksStruct::DSET::C_Zone; |
| 525 |
return child; |
| 526 |
} |
| 527 |
|
| 528 |
//! the file type ( zone or zone2 ) |
| 529 |
Type m_subType; |
| 530 |
//! the zoneId |
| 531 |
int m_id; |
| 532 |
//! the zoneSubId: can be page/column/frame linked number |
| 533 |
int m_subId; |
| 534 |
//! the frame id (for a linked frame) |
| 535 |
int m_frameId; |
| 536 |
//! the frame sub id (for a linked frame) |
| 537 |
int m_frameSubId; |
| 538 |
//! true if this is the last frame of a frame zone |
| 539 |
bool m_frameLast; |
| 540 |
//! the transformation id |
| 541 |
int m_transformationId; |
| 542 |
//! the wrapping separator |
| 543 |
int m_wrappingSep; |
| 544 |
//! flag |
| 545 |
int m_flags[9]; |
| 546 |
}; |
| 547 |
|
| 548 |
ZoneZone::~ZoneZone() |
| 549 |
{ |
| 550 |
} |
| 551 |
|
| 552 |
//! Internal: structure used to store an unknown zone of a ClarisDrawGraph |
| 553 |
struct ZoneUnknown final : public Zone { |
| 554 |
//! construtor |
| 555 |
explicit ZoneUnknown(Zone const &z) |
| 556 |
: Zone(z), |
| 557 |
m_type(T_Unknown) |
| 558 |
, m_typeId(-1) |
| 559 |
{ |
| 560 |
} |
| 561 |
//! destructor |
| 562 |
~ZoneUnknown() final; |
| 563 |
//! print the zone |
| 564 |
void print(std::ostream &o) const final |
| 565 |
{ |
| 566 |
o << "##type=" << m_typeId << ","; |
| 567 |
} |
| 568 |
//! return the main type |
| 569 |
Type getType() const final |
| 570 |
{ |
| 571 |
return m_type; |
| 572 |
} |
| 573 |
//! return the sub type |
| 574 |
Type getSubType() const final |
| 575 |
{ |
| 576 |
return m_type; |
| 577 |
} |
| 578 |
//! return the number of data |
| 579 |
int getNumData() const final |
| 580 |
{ |
| 581 |
return 0; |
| 582 |
} |
| 583 |
//! return a child corresponding to this zone |
| 584 |
ClarisWksStruct::DSET::Child getChild() const final |
| 585 |
{ |
| 586 |
ClarisWksStruct::DSET::Child child; |
| 587 |
child.m_box = m_box; |
| 588 |
child.m_type = ClarisWksStruct::DSET::C_Graphic; |
| 589 |
return child; |
| 590 |
} |
| 591 |
|
| 592 |
//! the sub type |
| 593 |
Type m_type; |
| 594 |
//! type number |
| 595 |
int m_typeId; |
| 596 |
}; |
| 597 |
|
| 598 |
ZoneUnknown::~ZoneUnknown() |
| 599 |
{ |
| 600 |
} |
| 601 |
|
| 602 |
//////////////////////////////////////// |
| 603 |
//! Internal: class which stores a group of graphics, ... |
| 604 |
struct Group final : public ClarisWksStruct::DSET { |
| 605 |
//! constructor |
| 606 |
explicit Group(ClarisWksStruct::DSET const &dset = ClarisWksStruct::DSET()) |
| 607 |
: ClarisWksStruct::DSET(dset) |
| 608 |
, m_zones() |
| 609 |
, m_hasMainZone(false) |
| 610 |
, m_zonesToSend() |
| 611 |
{ |
| 612 |
m_page=0; |
| 613 |
} |
| 614 |
//! destructor |
| 615 |
~Group() final; |
| 616 |
|
| 617 |
//! returns true if the group is empty |
| 618 |
bool isEmpty() const |
| 619 |
{ |
| 620 |
return m_zones.empty(); |
| 621 |
} |
| 622 |
//! operator<< |
| 623 |
friend std::ostream &operator<<(std::ostream &o, Group const &doc) |
| 624 |
{ |
| 625 |
o << static_cast<ClarisWksStruct::DSET const &>(doc); |
| 626 |
return o; |
| 627 |
} |
| 628 |
/** remove a child from a list. |
| 629 |
|
| 630 |
Normally, this function is not called, so optimizing it is not usefull |
| 631 |
*/ |
| 632 |
void removeChild(int cId, bool normalChild) final |
| 633 |
{ |
| 634 |
DSET::removeChild(cId, normalChild); |
| 635 |
for (auto it=m_zones.begin(); it!=m_zones.end(); ++it) { |
| 636 |
std::shared_ptr<ClarisDrawGraphInternal::Zone> child = *it; |
| 637 |
if (!child || child->getType() != ClarisDrawGraphInternal::Zone::T_Zone) |
| 638 |
continue; |
| 639 |
auto const &childZone = static_cast<ClarisDrawGraphInternal::ZoneZone &>(*child); |
| 640 |
if (childZone.m_id != cId) continue; |
| 641 |
m_zones.erase(it); |
| 642 |
return; |
| 643 |
} |
| 644 |
MWAW_DEBUG_MSG(("ClarisDrawGraphInternal::Group can not detach %d\n", cId)); |
| 645 |
} |
| 646 |
|
| 647 |
/** the list of child zones */ |
| 648 |
std::vector<std::shared_ptr<Zone> > m_zones; |
| 649 |
|
| 650 |
//! a flag to know if this zone contains or no the call to zone 1 |
| 651 |
bool m_hasMainZone; |
| 652 |
//! the list of block to send |
| 653 |
std::vector<std::shared_ptr<Zone> > m_zonesToSend; |
| 654 |
}; |
| 655 |
|
| 656 |
Group::~Group() |
| 657 |
{ |
| 658 |
} |
| 659 |
|
| 660 |
//////////////////////////////////////// |
| 661 |
//! Internal: the state of a ClarisDrawGraph |
| 662 |
struct State { |
| 663 |
//! constructor |
| 664 |
State() |
| 665 |
: m_numPages(0) |
| 666 |
, m_pageDimensions(0,0) |
| 667 |
, m_masterId(-1) |
| 668 |
, m_transformations() |
| 669 |
, m_groupMap() |
| 670 |
, m_bitmapMap() |
| 671 |
, m_positionsComputed(false) |
| 672 |
, m_frameId(0) |
| 673 |
, m_groupSet() { } |
| 674 |
//! returns true if a group does not exist or is empty |
| 675 |
bool isEmptyGroup(int gId) const |
| 676 |
{ |
| 677 |
auto it=m_groupMap.find(gId); |
| 678 |
return it==m_groupMap.end() || !it->second || it->second->isEmpty(); |
| 679 |
} |
| 680 |
//! the number of pages |
| 681 |
int m_numPages; |
| 682 |
//! the page dimension if known (in point) |
| 683 |
MWAWVec2f m_pageDimensions; |
| 684 |
//! the master group id ( in a draw file ) |
| 685 |
int m_masterId; |
| 686 |
//! the list of transformation |
| 687 |
std::vector<Transformation> m_transformations; |
| 688 |
//! a map zoneId -> group |
| 689 |
std::map<int, std::shared_ptr<Group> > m_groupMap; |
| 690 |
//! a map zoneId -> group |
| 691 |
std::map<int, std::shared_ptr<Bitmap> > m_bitmapMap; |
| 692 |
//! true if the ClarisDrawGraph::computePositions was called |
| 693 |
bool m_positionsComputed; |
| 694 |
//! the actuel frame id |
| 695 |
int m_frameId; |
| 696 |
//! stack of send group(used avoid infinite loop- |
| 697 |
std::set<int> m_groupSet; |
| 698 |
}; |
| 699 |
|
| 700 |
//////////////////////////////////////// |
| 701 |
//! Internal: the subdocument of a ClarisDrawGraph |
| 702 |
class SubDocument final : public MWAWSubDocument |
| 703 |
{ |
| 704 |
public: |
| 705 |
//! constructor for zone |
| 706 |
SubDocument(ClarisDrawGraph &pars, MWAWInputStreamPtr &input, int zoneId, int subId) |
| 707 |
: MWAWSubDocument(pars.m_mainParser, input, MWAWEntry()) |
| 708 |
, m_graphParser(&pars) |
| 709 |
, m_id(zoneId) |
| 710 |
, m_subId(subId) |
| 711 |
, m_measure("") {} |
| 712 |
//! constructor for measure |
| 713 |
SubDocument(ClarisDrawGraph &pars, MWAWInputStreamPtr &input, std::string const &measure) |
| 714 |
: MWAWSubDocument(pars.m_mainParser, input, MWAWEntry()) |
| 715 |
, m_graphParser(&pars) |
| 716 |
, m_id(-1) |
| 717 |
, m_subId(-1) |
| 718 |
, m_measure(measure) {} |
| 719 |
|
| 720 |
//! destructor |
| 721 |
~SubDocument() final {} |
| 722 |
|
| 723 |
//! operator!= |
| 724 |
bool operator!=(MWAWSubDocument const &doc) const final |
| 725 |
{ |
| 726 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 727 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 728 |
if (!sDoc) return true; |
| 729 |
if (m_graphParser != sDoc->m_graphParser) return true; |
| 730 |
if (m_id != sDoc->m_id) return true; |
| 731 |
if (m_subId != sDoc->m_subId) return true; |
| 732 |
if (m_measure != sDoc->m_measure) return true; |
| 733 |
return false; |
| 734 |
} |
| 735 |
|
| 736 |
//! the parser function |
| 737 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 738 |
/** the graph parser */ |
| 739 |
ClarisDrawGraph *m_graphParser; |
| 740 |
|
| 741 |
protected: |
| 742 |
//! the subdocument id |
| 743 |
int m_id; |
| 744 |
//! the subdocument sub id |
| 745 |
int m_subId; |
| 746 |
//! the measure |
| 747 |
std::string m_measure; |
| 748 |
private: |
| 749 |
SubDocument(SubDocument const &orig) = delete; |
| 750 |
SubDocument &operator=(SubDocument const &orig) = delete; |
| 751 |
}; |
| 752 |
|
| 753 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) |
| 754 |
{ |
| 755 |
if (!listener || (type==libmwaw::DOC_TEXT_BOX&&!listener->canWriteText())) { |
| 756 |
MWAW_DEBUG_MSG(("ClarisDrawGraphInternal::SubDocument::parse: no listener\n")); |
| 757 |
return; |
| 758 |
} |
| 759 |
if (!m_graphParser) { |
| 760 |
MWAW_DEBUG_MSG(("ClarisDrawGraphInternal::SubDocument::parse: no graph parser\n")); |
| 761 |
return; |
| 762 |
} |
| 763 |
if (m_id<0) { |
| 764 |
if (m_measure.empty()) { |
| 765 |
MWAW_DEBUG_MSG(("ClarisDrawGraphInternal::SubDocument::parse: can not find the measure\n")); |
| 766 |
return; |
| 767 |
} |
| 768 |
listener->setFont(MWAWFont(3,10)); |
| 769 |
MWAWParagraph para; |
| 770 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 771 |
listener->setParagraph(para); |
| 772 |
listener->insertUnicodeString(librevenge::RVNGString(m_measure.c_str())); |
| 773 |
return; |
| 774 |
} |
| 775 |
long pos = m_input->tell(); |
| 776 |
m_graphParser->sendTextZone(m_id, m_subId); |
| 777 |
m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 778 |
} |
| 779 |
|
| 780 |
} |
| 781 |
|
| 782 |
//////////////////////////////////////////////////////////// |
| 783 |
// constructor/destructor, ... |
| 784 |
//////////////////////////////////////////////////////////// |
| 785 |
ClarisDrawGraph::ClarisDrawGraph(ClarisDrawParser &parser) |
| 786 |
: m_parserState(parser.getParserState()) |
| 787 |
, m_state(new ClarisDrawGraphInternal::State) |
| 788 |
, m_mainParser(&parser) |
| 789 |
, m_styleManager(parser.m_styleManager) |
| 790 |
{ |
| 791 |
} |
| 792 |
|
| 793 |
ClarisDrawGraph::~ClarisDrawGraph() |
| 794 |
{ } |
| 795 |
|
| 796 |
int ClarisDrawGraph::version() const |
| 797 |
{ |
| 798 |
return m_parserState->m_version; |
| 799 |
} |
| 800 |
|
| 801 |
void ClarisDrawGraph::resetState() |
| 802 |
{ |
| 803 |
m_state.reset(new ClarisDrawGraphInternal::State); |
| 804 |
} |
| 805 |
|
| 806 |
int ClarisDrawGraph::numPages() const |
| 807 |
{ |
| 808 |
if (m_state->m_numPages>0) return m_state->m_numPages; |
| 809 |
|
| 810 |
int nPages = 1; |
| 811 |
for (auto const &iter : m_state->m_groupMap) { |
| 812 |
auto group = iter.second; |
| 813 |
if (!group) continue; |
| 814 |
int lastPage=group->getMaximumPage(); |
| 815 |
if (lastPage>nPages) nPages=lastPage; |
| 816 |
} |
| 817 |
m_state->m_numPages=nPages; |
| 818 |
return nPages; |
| 819 |
} |
| 820 |
|
| 821 |
bool ClarisDrawGraph::sendTextZone(int number, int subZone) |
| 822 |
{ |
| 823 |
return m_mainParser->sendTextZone(number, subZone); |
| 824 |
} |
| 825 |
|
| 826 |
bool ClarisDrawGraph::isEmptyGroup(int gId) const |
| 827 |
{ |
| 828 |
return m_state->isEmptyGroup(gId); |
| 829 |
} |
| 830 |
|
| 831 |
//////////////////////////////////////////////////////////// |
| 832 |
// Intermediate level |
| 833 |
//////////////////////////////////////////////////////////// |
| 834 |
void ClarisDrawGraph::updateGroup(bool isLibrary) |
| 835 |
{ |
| 836 |
// first looked for frame link and remove the empty link |
| 837 |
std::stack<int> emptyGroup; |
| 838 |
std::multimap<int, int> fatherMap; |
| 839 |
std::map<int, std::map<int, ClarisDrawGraphInternal::ZoneZone *> > idSIdCIdMap; |
| 840 |
|
| 841 |
for (auto &iter : m_state->m_groupMap) { |
| 842 |
std::shared_ptr<ClarisDrawGraphInternal::Group> group = iter.second; |
| 843 |
if (!group) continue; |
| 844 |
if (group->isEmpty()) { |
| 845 |
emptyGroup.push(group->m_id); |
| 846 |
continue; |
| 847 |
} |
| 848 |
for (auto const &child : group->m_zones) { |
| 849 |
if (!child) continue; |
| 850 |
if (child->getType() != ClarisDrawGraphInternal::Zone::T_Zone) continue; |
| 851 |
auto *cChild = dynamic_cast<ClarisDrawGraphInternal::ZoneZone *>(child.get()); |
| 852 |
if (!cChild) { |
| 853 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::updateGroup: oops can not find a child\n")); |
| 854 |
continue; |
| 855 |
} |
| 856 |
int zId=cChild->getZoneId(); |
| 857 |
fatherMap.insert(std::multimap<int,int>::value_type(group->m_id,zId)); |
| 858 |
|
| 859 |
// now look for linked text box text |
| 860 |
if (m_mainParser->getFileType(zId)!=1) continue; |
| 861 |
if (idSIdCIdMap.find(zId)==idSIdCIdMap.end()) |
| 862 |
idSIdCIdMap.insert(std::map<int, std::map<int, ClarisDrawGraphInternal::ZoneZone *> >::value_type |
| 863 |
(zId, std::map<int, ClarisDrawGraphInternal::ZoneZone *>())); |
| 864 |
auto &sIdCIdMap=idSIdCIdMap.find(zId)->second; |
| 865 |
if (sIdCIdMap.find(cChild->m_subId)!=sIdCIdMap.end()) { |
| 866 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::updateGroup: zone %d already find with subId %d\n", |
| 867 |
zId, cChild->m_subId)); |
| 868 |
} |
| 869 |
else |
| 870 |
sIdCIdMap[cChild->m_subId]=cChild; |
| 871 |
} |
| 872 |
} |
| 873 |
|
| 874 |
// update the linked frame data, ie. zone->m_frame* |
| 875 |
for (auto const &it : idSIdCIdMap) { |
| 876 |
auto const &sIdCIdMap=it.second; |
| 877 |
if (sIdCIdMap.size()<=1) continue; |
| 878 |
int frameId=m_state->m_frameId++; |
| 879 |
int frameSubId=0; |
| 880 |
for (auto cIt=sIdCIdMap.begin(); cIt!=sIdCIdMap.end(); ++cIt) { |
| 881 |
auto *child =cIt->second; |
| 882 |
child->m_frameId=frameId; |
| 883 |
child->m_frameSubId=frameSubId++; |
| 884 |
child->m_frameLast=cIt==sIdCIdMap.end(); |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
while (!emptyGroup.empty()) { |
| 889 |
int id=emptyGroup.top(); |
| 890 |
emptyGroup.pop(); |
| 891 |
auto fIt=fatherMap.find(id); |
| 892 |
while (fIt!=fatherMap.end() && fIt->first==id) { |
| 893 |
int fId=fIt++->second; |
| 894 |
if (isLibrary && fId==1) continue; |
| 895 |
auto iter=m_state->m_groupMap.find(fId); |
| 896 |
if (iter==m_state->m_groupMap.end() || !iter->second) { |
| 897 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readTransformations: oops can not find a father\n")); |
| 898 |
continue; |
| 899 |
} |
| 900 |
iter->second->removeChild(id, true); |
| 901 |
if (iter->second->isEmpty()) |
| 902 |
emptyGroup.push(fId); |
| 903 |
} |
| 904 |
} |
| 905 |
} |
| 906 |
|
| 907 |
bool ClarisDrawGraph::getSurfaceColor(ClarisDrawGraphInternal::Style const &style, MWAWColor &col) const |
| 908 |
{ |
| 909 |
if (!style.hasSurfaceColor()) |
| 910 |
return false; |
| 911 |
col = style.m_surfaceColor; |
| 912 |
return true; |
| 913 |
} |
| 914 |
|
| 915 |
bool ClarisDrawGraph::readTransformations() |
| 916 |
{ |
| 917 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 918 |
long pos=input->tell(); |
| 919 |
if (!input->checkPosition(pos+12)) return false; |
| 920 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 921 |
libmwaw::DebugStream f; |
| 922 |
f << "Entries(Transformation):"; |
| 923 |
ClarisWksStruct::Struct header; |
| 924 |
if (!header.readHeader(input,false)) { |
| 925 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readTransformations: the data size seems bad\n")); |
| 926 |
f << "###"; |
| 927 |
ascFile.addPos(pos); |
| 928 |
ascFile.addNote(f.str().c_str()); |
| 929 |
return false; |
| 930 |
} |
| 931 |
if (header.m_size==0) { |
| 932 |
ascFile.addPos(pos); |
| 933 |
ascFile.addNote("_"); |
| 934 |
return true; |
| 935 |
} |
| 936 |
long endPos=pos+4+header.m_size; |
| 937 |
f << header; |
| 938 |
if (header.m_headerSize) { |
| 939 |
ascFile.addDelimiter(input->tell(),'|'); |
| 940 |
input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR); |
| 941 |
} |
| 942 |
ascFile.addPos(pos); |
| 943 |
ascFile.addNote(f.str().c_str()); |
| 944 |
|
| 945 |
pos=input->tell(); |
| 946 |
if (header.m_dataSize!=30) { |
| 947 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 948 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readTransformations: no sure how to read the data\n")); |
| 949 |
ascFile.addPos(pos); |
| 950 |
ascFile.addNote("Transformation-data:###"); |
| 951 |
return true; |
| 952 |
} |
| 953 |
|
| 954 |
for (int i=0; i<int(header.m_numData); ++i) { |
| 955 |
pos=input->tell(); |
| 956 |
f.str(""); |
| 957 |
f << "Transformation-" << i << ":"; |
| 958 |
ClarisDrawGraphInternal::Transformation trans; |
| 959 |
double angle= double(input->readLong(4))/65536.; // in radians |
| 960 |
trans.m_rotate = float(180./M_PI*angle); |
| 961 |
float dim[2]; |
| 962 |
for (auto &j : dim) j=float(input->readLong(4))/256.f; |
| 963 |
trans.m_originalSize=MWAWVec2f(dim[1],dim[0]); |
| 964 |
for (auto &value : trans.m_values) value=float(input->readLong(4))/256.f; |
| 965 |
f << trans; |
| 966 |
for (int j=0; j<5; ++j) { // always 0 |
| 967 |
auto val=static_cast<int>(input->readLong(2)); |
| 968 |
if (val) f << "f" << j+1 << "=" << val << ","; |
| 969 |
} |
| 970 |
m_state->m_transformations.push_back(trans); |
| 971 |
input->seek(pos+header.m_dataSize, librevenge::RVNG_SEEK_SET); |
| 972 |
ascFile.addPos(pos); |
| 973 |
ascFile.addNote(f.str().c_str()); |
| 974 |
} |
| 975 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 976 |
return true; |
| 977 |
} |
| 978 |
|
| 979 |
//////////////////////////////////////////////////////////// |
| 980 |
// a group of data mainly graphic |
| 981 |
//////////////////////////////////////////////////////////// |
| 982 |
std::shared_ptr<ClarisWksStruct::DSET> ClarisDrawGraph::readGroupZone |
| 983 |
(ClarisWksStruct::DSET const &zone, MWAWEntry const &entry, bool isLibHeader) |
| 984 |
{ |
| 985 |
if (!entry.valid() || zone.m_fileType != 0) |
| 986 |
return std::shared_ptr<ClarisWksStruct::DSET>(); |
| 987 |
long pos = entry.begin(); |
| 988 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 989 |
input->seek(pos+8+16, librevenge::RVNG_SEEK_SET); // avoid header+8 generic number |
| 990 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 991 |
libmwaw::DebugStream f; |
| 992 |
std::shared_ptr<ClarisDrawGraphInternal::Group> group(new ClarisDrawGraphInternal::Group(zone)); |
| 993 |
|
| 994 |
f << "Entries(GroupDef):" << *group << ","; |
| 995 |
if (isLibHeader) f << "isLib,"; |
| 996 |
auto val = static_cast<int>(input->readLong(2)); // a small int between 0 and 3 |
| 997 |
switch (val) { |
| 998 |
case 0: |
| 999 |
break; // normal |
| 1000 |
default: |
| 1001 |
f << "#type?=" << val << ","; |
| 1002 |
break; |
| 1003 |
} |
| 1004 |
val = static_cast<int>(input->readLong(2)); // a small number between 0 and 1e8 |
| 1005 |
if (val) f << "f1=" << val << ","; |
| 1006 |
|
| 1007 |
ascFile.addDelimiter(input->tell(), '|'); |
| 1008 |
ascFile.addPos(pos); |
| 1009 |
ascFile.addNote(f.str().c_str()); |
| 1010 |
|
| 1011 |
// read the last part |
| 1012 |
long data0Length = zone.m_dataSz; |
| 1013 |
long N = zone.m_numData; |
| 1014 |
if (zone.m_headerSz<0 || data0Length<0 || entry.length() -8-12 != data0Length*N + zone.m_headerSz) { |
| 1015 |
if (zone.m_headerSz<0 || data0Length<0 || (data0Length==0 && N) || 8+12+data0Length*N + zone.m_headerSz>entry.length()) { |
| 1016 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupZone: can not find definition size\n")); |
| 1017 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1018 |
return std::shared_ptr<ClarisWksStruct::DSET>(); |
| 1019 |
} |
| 1020 |
|
| 1021 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupZone: unexpected size for zone definition, try to continue\n")); |
| 1022 |
} |
| 1023 |
|
| 1024 |
long beginDefGroup = entry.end()-N*data0Length; |
| 1025 |
if (long(input->tell())+42 <= beginDefGroup) { |
| 1026 |
input->seek(beginDefGroup-42, librevenge::RVNG_SEEK_SET); |
| 1027 |
pos = input->tell(); |
| 1028 |
if (!readGroupUnknown(*group, 42, -1)) { |
| 1029 |
ascFile.addPos(pos); |
| 1030 |
ascFile.addNote("GroupDef_A###:"); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
input->seek(beginDefGroup, librevenge::RVNG_SEEK_SET); |
| 1035 |
|
| 1036 |
for (long i = 0; i < N; i++) { |
| 1037 |
pos = input->tell(); |
| 1038 |
MWAWEntry gEntry; |
| 1039 |
gEntry.setBegin(pos); |
| 1040 |
gEntry.setLength(data0Length); |
| 1041 |
auto def = readGroupDef(gEntry); |
| 1042 |
group->m_zones.push_back(def); |
| 1043 |
|
| 1044 |
if (!def) { |
| 1045 |
f.str(""); |
| 1046 |
f << "GroupDef#"; |
| 1047 |
ascFile.addPos(pos); |
| 1048 |
ascFile.addNote(f.str().c_str()); |
| 1049 |
} |
| 1050 |
input->seek(gEntry.end(), librevenge::RVNG_SEEK_SET); |
| 1051 |
} |
| 1052 |
|
| 1053 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1054 |
readGroupData(*group, entry.begin(), isLibHeader); |
| 1055 |
|
| 1056 |
group->m_childs.resize(group->m_zones.size()); |
| 1057 |
for (size_t i = 0; i < group->m_zones.size(); ++i) { |
| 1058 |
if (!group->m_zones[i]) continue; |
| 1059 |
group->m_childs[size_t(i)] = group->m_zones[i]->getChild(); |
| 1060 |
} |
| 1061 |
|
| 1062 |
if (m_state->m_groupMap.find(group->m_id) != m_state->m_groupMap.end()) { |
| 1063 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupZone: zone %d already exists!!!\n", group->m_id)); |
| 1064 |
} |
| 1065 |
else |
| 1066 |
m_state->m_groupMap[group->m_id] = group; |
| 1067 |
|
| 1068 |
return group; |
| 1069 |
} |
| 1070 |
|
| 1071 |
//////////////////////////////////////////////////////////// |
| 1072 |
// read a bitmap zone |
| 1073 |
//////////////////////////////////////////////////////////// |
| 1074 |
std::shared_ptr<ClarisWksStruct::DSET> ClarisDrawGraph::readBitmapZone(ClarisWksStruct::DSET const &zone, MWAWEntry const &entry) |
| 1075 |
{ |
| 1076 |
if (!entry.valid() || zone.m_fileType != 4) |
| 1077 |
return std::shared_ptr<ClarisWksStruct::DSET>(); |
| 1078 |
long pos = entry.begin(); |
| 1079 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1080 |
input->seek(pos+8+16, librevenge::RVNG_SEEK_SET); // avoid header+8 generic number |
| 1081 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 1082 |
libmwaw::DebugStream f; |
| 1083 |
std::shared_ptr<ClarisDrawGraphInternal::Bitmap> bitmap(new ClarisDrawGraphInternal::Bitmap(zone)); |
| 1084 |
|
| 1085 |
f << "Entries(BitmapDef):" << *bitmap << ","; |
| 1086 |
|
| 1087 |
ascFile.addDelimiter(input->tell(), '|'); |
| 1088 |
|
| 1089 |
// read the last part |
| 1090 |
long data0Length = zone.m_dataSz; |
| 1091 |
long N = zone.m_numData; |
| 1092 |
if (zone.m_headerSz<0 || data0Length<0 || entry.length() -8-12 != data0Length*N + zone.m_headerSz) { |
| 1093 |
if (zone.m_headerSz<0 || data0Length<0 || (data0Length==0 && N) || 8+12+data0Length*N + zone.m_headerSz>entry.length()) { |
| 1094 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapZone: unexpected size for zone definition\n")); |
| 1095 |
f << "###"; |
| 1096 |
ascFile.addPos(pos); |
| 1097 |
ascFile.addNote(f.str().c_str()); |
| 1098 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1099 |
return std::shared_ptr<ClarisWksStruct::DSET>(); |
| 1100 |
} |
| 1101 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapZone: unexpected size for zone definition, try to continue\n")); |
| 1102 |
} |
| 1103 |
|
| 1104 |
bool sizeSet=false; |
| 1105 |
int const sizePos = 88; |
| 1106 |
if (pos+sizePos+4+N*data0Length < entry.end()) { |
| 1107 |
input->seek(pos+sizePos, librevenge::RVNG_SEEK_SET); |
| 1108 |
ascFile.addDelimiter(pos+sizePos,'['); |
| 1109 |
int dim[2]; // ( we must add 2 to add the border ) |
| 1110 |
for (auto &j : dim) j= static_cast<int>(input->readLong(2)); |
| 1111 |
f << "sz=" << dim[1] << "x" << dim[0] << ","; |
| 1112 |
if (dim[0] > 0 && dim[1] > 0) { |
| 1113 |
bitmap->m_bitmapSize = MWAWVec2i(dim[1]+2, dim[0]+2); |
| 1114 |
sizeSet = true; |
| 1115 |
} |
| 1116 |
ascFile.addDelimiter(input->tell(),']'); |
| 1117 |
} |
| 1118 |
ascFile.addPos(pos); |
| 1119 |
ascFile.addNote(f.str().c_str()); |
| 1120 |
|
| 1121 |
/** the end of this block is very simillar to a bitmapdef, excepted |
| 1122 |
maybe the first integer .... */ |
| 1123 |
if (long(input->tell())+(N+1)*data0Length <= entry.end()) |
| 1124 |
N++; |
| 1125 |
|
| 1126 |
input->seek(entry.end()-N*data0Length, librevenge::RVNG_SEEK_SET); |
| 1127 |
|
| 1128 |
for (long i = 0; i < N; i++) { |
| 1129 |
pos = input->tell(); |
| 1130 |
MWAWEntry gEntry; |
| 1131 |
gEntry.setBegin(pos); |
| 1132 |
gEntry.setLength(data0Length); |
| 1133 |
f.str(""); |
| 1134 |
f << "BitmapDef-" << i << ":"; |
| 1135 |
auto val = long(input->readULong(4)); |
| 1136 |
if (val) { |
| 1137 |
if (i == 0) |
| 1138 |
f << "unkn=" << val << ","; |
| 1139 |
else |
| 1140 |
f << "ptr=" << std::hex << val << std::dec << ","; |
| 1141 |
} |
| 1142 |
// f0 : 0 true color, if not number of bytes |
| 1143 |
for (int j = 0; j < 3; j++) { |
| 1144 |
val = static_cast<int>(input->readLong(2)); |
| 1145 |
if (val) f << "f" << j << "=" << val << ","; |
| 1146 |
} |
| 1147 |
int dim[2]; // ( we must add 2 to add the border ) |
| 1148 |
for (auto &j : dim) j = static_cast<int>(input->readLong(2)); |
| 1149 |
if (i == N-1 && !sizeSet) |
| 1150 |
bitmap->m_bitmapSize = MWAWVec2i(dim[0]+2, dim[1]+2); |
| 1151 |
|
| 1152 |
f << "dim?=" << dim[0] << "x" << dim[1] << ","; |
| 1153 |
for (int j = 3; j < 6; j++) { |
| 1154 |
val = static_cast<int>(input->readLong(2)); |
| 1155 |
if ((j != 5 && val!=1) || (j==5 && val)) // always 1, 1, 0 |
| 1156 |
f << "f" << j << "=" << val << ","; |
| 1157 |
} |
| 1158 |
if (long(input->tell()) != gEntry.end()) |
| 1159 |
ascFile.addDelimiter(input->tell(), '|'); |
| 1160 |
ascFile.addPos(pos); |
| 1161 |
ascFile.addNote(f.str().c_str()); |
| 1162 |
input->seek(gEntry.end(), librevenge::RVNG_SEEK_SET); |
| 1163 |
} |
| 1164 |
|
| 1165 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1166 |
pos = entry.end(); |
| 1167 |
bool ok = readBitmapColorMap(bitmap->m_colorMap); |
| 1168 |
if (ok) { |
| 1169 |
pos = input->tell(); |
| 1170 |
ok = readBitmapData(*bitmap); |
| 1171 |
} |
| 1172 |
if (!ok) |
| 1173 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1174 |
|
| 1175 |
// fixme: in general followed by another zone |
| 1176 |
bitmap->m_otherChilds.push_back(bitmap->m_id+1); |
| 1177 |
|
| 1178 |
if (m_state->m_bitmapMap.find(bitmap->m_id) != m_state->m_bitmapMap.end()) { |
| 1179 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupZone: zone %d already exists!!!\n", bitmap->m_id)); |
| 1180 |
} |
| 1181 |
else |
| 1182 |
m_state->m_bitmapMap[bitmap->m_id] = bitmap; |
| 1183 |
|
| 1184 |
return bitmap; |
| 1185 |
} |
| 1186 |
|
| 1187 |
//////////////////////////////////////////////////////////// |
| 1188 |
// definition of an element of a group |
| 1189 |
//////////////////////////////////////////////////////////// |
| 1190 |
std::shared_ptr<ClarisDrawGraphInternal::Zone> ClarisDrawGraph::readGroupDef(MWAWEntry const &entry) |
| 1191 |
{ |
| 1192 |
std::shared_ptr<ClarisDrawGraphInternal::Zone> res; |
| 1193 |
if (entry.length() < 32) { |
| 1194 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: sz is too short!!!\n")); |
| 1195 |
return res; |
| 1196 |
} |
| 1197 |
long pos = entry.begin(); |
| 1198 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1199 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1200 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 1201 |
libmwaw::DebugStream f; |
| 1202 |
f << "GroupDef:"; |
| 1203 |
|
| 1204 |
ClarisDrawGraphInternal::Zone zone; |
| 1205 |
auto &style = zone.m_style; |
| 1206 |
|
| 1207 |
auto typeId = static_cast<int>(input->readULong(1)); |
| 1208 |
auto type = ClarisDrawGraphInternal::Zone::T_Unknown; |
| 1209 |
switch (typeId) { |
| 1210 |
case 1: |
| 1211 |
type = ClarisDrawGraphInternal::Zone::T_Zone; |
| 1212 |
break; |
| 1213 |
case 2: |
| 1214 |
type = ClarisDrawGraphInternal::Zone::T_Line; |
| 1215 |
break; |
| 1216 |
case 3: |
| 1217 |
type = ClarisDrawGraphInternal::Zone::T_Rect; |
| 1218 |
break; |
| 1219 |
case 4: |
| 1220 |
type = ClarisDrawGraphInternal::Zone::T_RectOval; |
| 1221 |
break; |
| 1222 |
case 5: |
| 1223 |
type = ClarisDrawGraphInternal::Zone::T_Oval; |
| 1224 |
break; |
| 1225 |
case 6: |
| 1226 |
type = ClarisDrawGraphInternal::Zone::T_Arc; |
| 1227 |
break; |
| 1228 |
case 7: |
| 1229 |
type = ClarisDrawGraphInternal::Zone::T_Connector; |
| 1230 |
break; |
| 1231 |
case 8: |
| 1232 |
type = ClarisDrawGraphInternal::Zone::T_Poly; |
| 1233 |
break; |
| 1234 |
case 10: |
| 1235 |
type = ClarisDrawGraphInternal::Zone::T_Pict; |
| 1236 |
break; |
| 1237 |
default: |
| 1238 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: find unknown type=%d!!!\n", typeId)); |
| 1239 |
f << "###typeId=" << typeId << ","; |
| 1240 |
break; |
| 1241 |
} |
| 1242 |
zone.m_flag = static_cast<int>(input->readULong(1)); |
| 1243 |
style.m_wrapping=(zone.m_flag&3); |
| 1244 |
zone.m_zoneType = static_cast<int>(input->readULong(1)); |
| 1245 |
if (zone.m_zoneType & 0x40) style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain(); |
| 1246 |
if (zone.m_zoneType & 0x80) style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 1247 |
zone.m_zoneType &= 0x3F; |
| 1248 |
auto val = static_cast<int>(input->readULong(1)); |
| 1249 |
if (val) f << "f0=" << std::hex << val << std::dec << ","; |
| 1250 |
float dim[4]; |
| 1251 |
for (auto &j : dim) { |
| 1252 |
j = float(input->readLong(4))/256.f; |
| 1253 |
if (j < -100) f << "##dim?,"; |
| 1254 |
} |
| 1255 |
zone.m_box = MWAWBox2f(MWAWVec2f(dim[1], dim[0]), MWAWVec2f(dim[3], dim[2])); |
| 1256 |
style.m_lineWidth = float(input->readLong(2))/256.f; |
| 1257 |
for (int j = 0; j < 2; j++) { |
| 1258 |
auto col = static_cast<int>(input->readULong(1)); |
| 1259 |
MWAWColor color; |
| 1260 |
if (!m_styleManager->getColor(col, color)) { |
| 1261 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: unknown color!!!\n")); |
| 1262 |
f << "###col" << j << "=" << col << ","; |
| 1263 |
} |
| 1264 |
else if (j==0) |
| 1265 |
style.m_lineColor=color; |
| 1266 |
else |
| 1267 |
style.setSurfaceColor(color); |
| 1268 |
} |
| 1269 |
|
| 1270 |
for (int j = 0; j < 2; j++) { |
| 1271 |
// CHECKME |
| 1272 |
val = static_cast<int>(input->readULong(1)); // probably also related to surface |
| 1273 |
if (val) f << "pat" << j << "[high]=" << val << ","; |
| 1274 |
auto pat = static_cast<int>(input->readULong(1)); |
| 1275 |
if (j==1 && (zone.m_zoneType & 0x10)) { |
| 1276 |
f << "hasGrad,"; |
| 1277 |
zone.m_zoneType &= 0xEF; |
| 1278 |
m_styleManager->updateGradient(pat, style); |
| 1279 |
continue; |
| 1280 |
} |
| 1281 |
if (pat==1) { |
| 1282 |
if (j==0) style.m_lineOpacity=0; |
| 1283 |
else style.m_surfaceOpacity=0; |
| 1284 |
continue; |
| 1285 |
} |
| 1286 |
MWAWGraphicStyle::Pattern pattern; |
| 1287 |
if (!m_styleManager->getPattern(pat,pattern)) { |
| 1288 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: unknown pattern!!!\n")); |
| 1289 |
f << "###pat" << j << "=" << pat << ","; |
| 1290 |
} |
| 1291 |
pattern.m_colors[1]=j==0 ? style.m_lineColor : style.m_surfaceColor; |
| 1292 |
MWAWColor color; |
| 1293 |
if (!pattern.getUniqueColor(color)) { |
| 1294 |
pattern.getAverageColor(color); |
| 1295 |
if (j==1) style.setPattern(pattern); |
| 1296 |
} |
| 1297 |
if (j==0) |
| 1298 |
style.m_lineColor=color; |
| 1299 |
else |
| 1300 |
style.m_surfaceColor=color; |
| 1301 |
} |
| 1302 |
// checkme: look like an ordering, minimal value corresponding to front, actually unused |
| 1303 |
zone.m_ordering = static_cast<int>(input->readLong(2)); |
| 1304 |
|
| 1305 |
switch (type) { |
| 1306 |
case ClarisDrawGraphInternal::Zone::T_Zone: { |
| 1307 |
int nFlags = 0; |
| 1308 |
auto z = std::make_shared<ClarisDrawGraphInternal::ZoneZone>(zone, type); |
| 1309 |
res = z; |
| 1310 |
for (int j=0; j < 3; ++j) |
| 1311 |
z->m_flags[nFlags++] = static_cast<int>(input->readLong(2)); |
| 1312 |
z->m_id = static_cast<int>(input->readULong(2)); |
| 1313 |
|
| 1314 |
auto numRemains = int(entry.end()-long(input->tell())); |
| 1315 |
numRemains/=2; |
| 1316 |
if (numRemains > 9) numRemains = 9; |
| 1317 |
for (int j = 0; j < numRemains; j++) { |
| 1318 |
val = static_cast<int>(input->readLong(2)); |
| 1319 |
switch (j) { |
| 1320 |
case 1: |
| 1321 |
z->m_subId = val; |
| 1322 |
break; |
| 1323 |
case 2: |
| 1324 |
z->m_wrappingSep = val; |
| 1325 |
break; |
| 1326 |
case 6: |
| 1327 |
z->m_transformationId = val; |
| 1328 |
break; |
| 1329 |
default: |
| 1330 |
z->m_flags[nFlags++] = val; |
| 1331 |
break; |
| 1332 |
} |
| 1333 |
} |
| 1334 |
break; |
| 1335 |
} |
| 1336 |
case ClarisDrawGraphInternal::Zone::T_Connector: |
| 1337 |
case ClarisDrawGraphInternal::Zone::T_Line: |
| 1338 |
case ClarisDrawGraphInternal::Zone::T_Rect: |
| 1339 |
case ClarisDrawGraphInternal::Zone::T_RectOval: |
| 1340 |
case ClarisDrawGraphInternal::Zone::T_Oval: |
| 1341 |
case ClarisDrawGraphInternal::Zone::T_Arc: |
| 1342 |
case ClarisDrawGraphInternal::Zone::T_Poly: { |
| 1343 |
auto z = std::make_shared<ClarisDrawGraphInternal::ZoneShape>(zone, type); |
| 1344 |
res = z; |
| 1345 |
readShape(entry, *z); |
| 1346 |
break; |
| 1347 |
} |
| 1348 |
case ClarisDrawGraphInternal::Zone::T_Pict: // CHECKME |
| 1349 |
res.reset(new ClarisDrawGraphInternal::ZonePict(zone)); |
| 1350 |
break; |
| 1351 |
case ClarisDrawGraphInternal::Zone::T_Shape: |
| 1352 |
case ClarisDrawGraphInternal::Zone::T_Unknown: |
| 1353 |
#if !defined(__clang__) |
| 1354 |
default: |
| 1355 |
#endif |
| 1356 |
{ |
| 1357 |
auto z = std::make_shared<ClarisDrawGraphInternal::ZoneUnknown>(zone); |
| 1358 |
res = z; |
| 1359 |
z->m_type = type; |
| 1360 |
z->m_typeId = typeId; |
| 1361 |
break; |
| 1362 |
} |
| 1363 |
} |
| 1364 |
|
| 1365 |
f << *res; |
| 1366 |
|
| 1367 |
long actPos = input->tell(); |
| 1368 |
if (actPos != entry.begin() && actPos != entry.end()) |
| 1369 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1370 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 1371 |
|
| 1372 |
ascFile.addPos(entry.begin()); |
| 1373 |
ascFile.addNote(f.str().c_str()); |
| 1374 |
return res; |
| 1375 |
} |
| 1376 |
|
| 1377 |
//////////////////////////////////////////////////////////// |
| 1378 |
// |
| 1379 |
// Intermediate level |
| 1380 |
// |
| 1381 |
//////////////////////////////////////////////////////////// |
| 1382 |
|
| 1383 |
//////////////////////////////////////////////////////////// |
| 1384 |
// extra data associated to some group's element |
| 1385 |
//////////////////////////////////////////////////////////// |
| 1386 |
bool ClarisDrawGraph::readGroupData(ClarisDrawGraphInternal::Group &group, long beginGroupPos, bool isLibHeader) |
| 1387 |
{ |
| 1388 |
if (!readGroupHeader(group)) { |
| 1389 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: unexpected graphic1\n")); |
| 1390 |
return false; |
| 1391 |
} |
| 1392 |
|
| 1393 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1394 |
|
| 1395 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 1396 |
libmwaw::DebugStream f; |
| 1397 |
long pos, sz; |
| 1398 |
int numError = 0; |
| 1399 |
int numConnectors=0; |
| 1400 |
for (auto const &z : group.m_zones) { |
| 1401 |
pos=input->tell(); |
| 1402 |
if (!z) |
| 1403 |
continue; |
| 1404 |
if (isLibHeader || z->getSubType()==ClarisDrawGraphInternal::Zone::T_Connector) { |
| 1405 |
++numConnectors; |
| 1406 |
if (!ClarisWksStruct::readStructZone(*m_parserState, "ConnectorData", false)) { |
| 1407 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: can not retrieve connector data\n")); |
| 1408 |
ascFile.addPos(pos); |
| 1409 |
ascFile.addNote("###"); |
| 1410 |
return false; |
| 1411 |
} |
| 1412 |
} |
| 1413 |
int numZoneExpected = z->getNumData(); |
| 1414 |
if (!numZoneExpected) |
| 1415 |
continue; |
| 1416 |
/* Argh, zones with linked text can also begin with a |
| 1417 |
ConnectorData group, so we must look for extra such groups */ |
| 1418 |
while (!input->isEnd()) { |
| 1419 |
pos=input->tell(); |
| 1420 |
input->seek(6, librevenge::RVNG_SEEK_CUR); |
| 1421 |
if (input->readLong(2)==-1 && input->readULong(4)==8 && input->readULong(2)==0x1c) { |
| 1422 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1423 |
if (ClarisWksStruct::readStructZone(*m_parserState, "ConnectorData", false)) { |
| 1424 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: find unexpected connector\n")); |
| 1425 |
++numConnectors; |
| 1426 |
ascFile.addPos(pos); |
| 1427 |
ascFile.addNote("###"); |
| 1428 |
continue; |
| 1429 |
} |
| 1430 |
} |
| 1431 |
break; |
| 1432 |
} |
| 1433 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1434 |
sz = long(input->readULong(4)); |
| 1435 |
f.str(""); |
| 1436 |
if (sz == 0) { |
| 1437 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: find a nop zone for type: %d\n", |
| 1438 |
z->getSubType())); |
| 1439 |
ascFile.addPos(pos); |
| 1440 |
ascFile.addNote("GroupDef-before:###"); |
| 1441 |
if (!numError++) { |
| 1442 |
ascFile.addPos(beginGroupPos); |
| 1443 |
ascFile.addNote("###"); |
| 1444 |
} |
| 1445 |
else { |
| 1446 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: too many errors, zone parsing STOPS\n")); |
| 1447 |
return false; |
| 1448 |
} |
| 1449 |
pos = input->tell(); |
| 1450 |
sz = long(input->readULong(4)); |
| 1451 |
} |
| 1452 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1453 |
bool parsed = true; |
| 1454 |
switch (z->getSubType()) { |
| 1455 |
case ClarisDrawGraphInternal::Zone::T_Poly: |
| 1456 |
case ClarisDrawGraphInternal::Zone::T_Connector: |
| 1457 |
if (z->getNumData() && !readPolygonData(z)) { |
| 1458 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: can not retrieve polygon child\n")); |
| 1459 |
return false; |
| 1460 |
} |
| 1461 |
break; |
| 1462 |
case ClarisDrawGraphInternal::Zone::T_Pict: { |
| 1463 |
if (!input->checkPosition(pos+4+sz)) { |
| 1464 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1465 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: find a odd zone for picture\n")); |
| 1466 |
return false; |
| 1467 |
} |
| 1468 |
auto *pict=dynamic_cast<ClarisDrawGraphInternal::ZonePict *>(z.get()); |
| 1469 |
f.str(""); |
| 1470 |
f << "Entries(PictData):"; |
| 1471 |
if (!pict) { |
| 1472 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: oops can not find the picture\n")); |
| 1473 |
} |
| 1474 |
else { |
| 1475 |
pict->m_entries[0].setBegin(pos+4); |
| 1476 |
pict->m_entries[0].setLength(sz); |
| 1477 |
} |
| 1478 |
if (sz) |
| 1479 |
ascFile.skipZone(pos+4, pos+4+sz-1); |
| 1480 |
ascFile.addPos(pos); |
| 1481 |
ascFile.addNote(f.str().c_str()); |
| 1482 |
input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET); |
| 1483 |
|
| 1484 |
pos = input->tell(); |
| 1485 |
sz = long(input->readULong(4)); |
| 1486 |
if (!sz) { |
| 1487 |
ascFile.addPos(pos); |
| 1488 |
ascFile.addNote("_"); |
| 1489 |
break; |
| 1490 |
} |
| 1491 |
if (!input->checkPosition(pos+4+sz)) { |
| 1492 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1493 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: find a odd zone2 for picture\n")); |
| 1494 |
return false; |
| 1495 |
} |
| 1496 |
if (pict) { |
| 1497 |
pict->m_entries[1].setBegin(pos+4); |
| 1498 |
pict->m_entries[1].setLength(sz); |
| 1499 |
} |
| 1500 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: find a zone2 for picture\n")); |
| 1501 |
ascFile.addPos(pos); |
| 1502 |
ascFile.addNote("PictData-B:###"); |
| 1503 |
input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET); |
| 1504 |
break; |
| 1505 |
} |
| 1506 |
case ClarisDrawGraphInternal::Zone::T_Line: |
| 1507 |
case ClarisDrawGraphInternal::Zone::T_Rect: |
| 1508 |
case ClarisDrawGraphInternal::Zone::T_RectOval: |
| 1509 |
case ClarisDrawGraphInternal::Zone::T_Oval: |
| 1510 |
case ClarisDrawGraphInternal::Zone::T_Arc: |
| 1511 |
case ClarisDrawGraphInternal::Zone::T_Zone: |
| 1512 |
case ClarisDrawGraphInternal::Zone::T_Shape: |
| 1513 |
case ClarisDrawGraphInternal::Zone::T_Unknown: |
| 1514 |
#if !defined(__clang__) |
| 1515 |
default: |
| 1516 |
#endif |
| 1517 |
parsed = false; |
| 1518 |
break; |
| 1519 |
} |
| 1520 |
|
| 1521 |
if (parsed) continue; |
| 1522 |
if (!input->checkPosition(pos+4+sz)) { |
| 1523 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1524 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: find a odd zone for type: %d\n", |
| 1525 |
z->getSubType())); |
| 1526 |
return false; |
| 1527 |
} |
| 1528 |
f.str(""); |
| 1529 |
f << "Entries(UnknownDATA)-" << z->getSubType(); |
| 1530 |
ascFile.addPos(pos); |
| 1531 |
ascFile.addNote(f.str().c_str()); |
| 1532 |
input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET); |
| 1533 |
if (numZoneExpected==2) { |
| 1534 |
pos = input->tell(); |
| 1535 |
sz = long(input->readULong(4)); |
| 1536 |
if (sz) { |
| 1537 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1538 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: two zones is not implemented for zone: %d\n", |
| 1539 |
z->getSubType())); |
| 1540 |
return false; |
| 1541 |
} |
| 1542 |
ascFile.addPos(pos); |
| 1543 |
ascFile.addNote("NOP"); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
if (input->isEnd()) |
| 1548 |
return true; |
| 1549 |
pos=input->tell(); |
| 1550 |
if (numConnectors) { |
| 1551 |
auto n=static_cast<int>(input->readULong(2)); |
| 1552 |
if (n>numConnectors+1) { |
| 1553 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: unexpected connector data\n")); |
| 1554 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1555 |
n=0; |
| 1556 |
ascFile.addPos(pos); |
| 1557 |
ascFile.addNote("###"); |
| 1558 |
} |
| 1559 |
else { |
| 1560 |
f.str(""); |
| 1561 |
f << "Entries(ConnectorN):" << n; |
| 1562 |
ascFile.addPos(pos); |
| 1563 |
ascFile.addNote(f.str().c_str()); |
| 1564 |
} |
| 1565 |
for (int i=1; i<n; ++i) { |
| 1566 |
pos=input->tell(); |
| 1567 |
if (!ClarisWksStruct::readStructZone(*m_parserState, "ConnectorDef", false)) { |
| 1568 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupData: unexpected connector data\n")); |
| 1569 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1570 |
ascFile.addPos(pos); |
| 1571 |
ascFile.addNote("###"); |
| 1572 |
break; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
} |
| 1576 |
|
| 1577 |
return true; |
| 1578 |
} |
| 1579 |
|
| 1580 |
//////////////////////////////////////////////////////////// |
| 1581 |
// |
| 1582 |
// Low level |
| 1583 |
// |
| 1584 |
//////////////////////////////////////////////////////////// |
| 1585 |
bool ClarisDrawGraph::readShape(MWAWEntry const &entry, ClarisDrawGraphInternal::ZoneShape &zone) |
| 1586 |
{ |
| 1587 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1588 |
auto remainBytes = int(entry.end()-input->tell()); |
| 1589 |
if (remainBytes < 4) |
| 1590 |
return false; |
| 1591 |
|
| 1592 |
MWAWVec2f pictSz=zone.getBdBox().size(); |
| 1593 |
MWAWBox2f box(MWAWVec2f(0,0), pictSz); |
| 1594 |
auto &shape=zone.m_shape; |
| 1595 |
shape.m_bdBox=shape.m_formBox=box; |
| 1596 |
libmwaw::DebugStream f; |
| 1597 |
bool canHaveDash=false; |
| 1598 |
int val; |
| 1599 |
for (int i=0; i<2; ++i) { |
| 1600 |
val=static_cast<int>(input->readLong(2)); |
| 1601 |
if (val) f << "f" << i << "=" << val << ","; |
| 1602 |
} |
| 1603 |
remainBytes-=4; |
| 1604 |
int decal=0; |
| 1605 |
switch (zone.getSubType()) { |
| 1606 |
case ClarisDrawGraphInternal::Zone::T_Line: { |
| 1607 |
int yDeb=(zone.m_zoneType&1)?1:0; |
| 1608 |
shape = MWAWGraphicShape::line(MWAWVec2f(zone.m_box[0][0],zone.m_box[yDeb][1]), |
| 1609 |
MWAWVec2f(zone.m_box[1][0],zone.m_box[1-yDeb][1])); |
| 1610 |
zone.m_autosize=(zone.m_zoneType&4); |
| 1611 |
/* checkme: find also where the grid align is defined and do something like that |
| 1612 |
MWAWVec2f vec=shape.m_vertices[1]-shape.m_vertices[0]; |
| 1613 |
float absDiff[2]={vec[0]<0 ? -vec[0]:vec[0], vec[1]<0 ? -vec[1]:vec[1]}; |
| 1614 |
if (absDiff[0]<absDiff[1]/4.f) |
| 1615 |
shape=MWAWGraphicShape::line(shape.m_vertices[0], shape.m_vertices[0]+MWAWVec2f(0, vec[1])); |
| 1616 |
else if (absDiff[1]<absDiff[0]/4.f) |
| 1617 |
shape=MWAWGraphicShape::line(shape.m_vertices[0], shape.m_vertices[0]+MWAWVec2f(vec[0],0)); |
| 1618 |
*/ |
| 1619 |
canHaveDash=true; |
| 1620 |
break; |
| 1621 |
} |
| 1622 |
case ClarisDrawGraphInternal::Zone::T_Connector: |
| 1623 |
canHaveDash=true; |
| 1624 |
shape.m_type = MWAWGraphicShape::Polygon; // value are defined in second zone |
| 1625 |
break; |
| 1626 |
case ClarisDrawGraphInternal::Zone::T_Rect: |
| 1627 |
shape.m_type = MWAWGraphicShape::Rectangle; |
| 1628 |
break; |
| 1629 |
case ClarisDrawGraphInternal::Zone::T_Oval: |
| 1630 |
shape.m_type = MWAWGraphicShape::Circle; |
| 1631 |
break; |
| 1632 |
case ClarisDrawGraphInternal::Zone::T_Poly: |
| 1633 |
shape.m_type = MWAWGraphicShape::Polygon; |
| 1634 |
break; // value are defined in next zone |
| 1635 |
case ClarisDrawGraphInternal::Zone::T_Arc: { |
| 1636 |
if (remainBytes < 7) { |
| 1637 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readSimpleGraphicZone: arc zone is too short\n")); |
| 1638 |
return false; |
| 1639 |
} |
| 1640 |
decal=3; |
| 1641 |
int fileAngle[2]; |
| 1642 |
for (auto &angle : fileAngle) angle = static_cast<int>(input->readLong(2)); |
| 1643 |
val=static_cast<int>(input->readLong(1)); |
| 1644 |
if (val==1) f<< "show[axis],"; |
| 1645 |
else if (val) f << "#show[axis]=" << val << ","; |
| 1646 |
int angle[2] = { 90-fileAngle[0]-fileAngle[1], 90-fileAngle[0] }; |
| 1647 |
if (angle[1]>360) { |
| 1648 |
int numLoop=int(angle[1]/360)-1; |
| 1649 |
angle[0]-=numLoop*360; |
| 1650 |
angle[1]-=numLoop*360; |
| 1651 |
while (angle[1] > 360) { |
| 1652 |
angle[0]-=360; |
| 1653 |
angle[1]-=360; |
| 1654 |
} |
| 1655 |
} |
| 1656 |
if (angle[0] < -360) { |
| 1657 |
int numLoop=int(angle[0]/360)+1; |
| 1658 |
angle[0]-=numLoop*360; |
| 1659 |
angle[1]-=numLoop*360; |
| 1660 |
while (angle[0] < -360) { |
| 1661 |
angle[0]+=360; |
| 1662 |
angle[1]+=360; |
| 1663 |
} |
| 1664 |
} |
| 1665 |
MWAWVec2f center = box.center(); |
| 1666 |
MWAWVec2f axis = 0.5f*MWAWVec2f(box.size()); |
| 1667 |
// we must compute the real bd box |
| 1668 |
float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 }; |
| 1669 |
int limitAngle[2]; |
| 1670 |
for (int i = 0; i < 2; i++) |
| 1671 |
limitAngle[i] = (angle[i] < 0) ? int(angle[i]/90)-1 : int(angle[i]/90); |
| 1672 |
for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; bord++) { |
| 1673 |
float ang = (bord == limitAngle[0]) ? float(angle[0]) : |
| 1674 |
(bord == limitAngle[1]+1) ? float(angle[1]) : float(90 * bord); |
| 1675 |
ang *= float(M_PI/180.); |
| 1676 |
float const actVal[2] = { axis[0] *std::cos(ang), -axis[1] *std::sin(ang)}; |
| 1677 |
if (actVal[0] < minVal[0]) minVal[0] = actVal[0]; |
| 1678 |
else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0]; |
| 1679 |
if (actVal[1] < minVal[1]) minVal[1] = actVal[1]; |
| 1680 |
else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1]; |
| 1681 |
} |
| 1682 |
MWAWBox2f realBox(MWAWVec2f(center[0]+minVal[0],center[1]+minVal[1]), |
| 1683 |
MWAWVec2f(center[0]+maxVal[0],center[1]+maxVal[1])); |
| 1684 |
zone.m_box=MWAWBox2f(MWAWVec2f(zone.m_box[0])+realBox[0],MWAWVec2f(zone.m_box[0])+realBox[1]); |
| 1685 |
shape = MWAWGraphicShape::pie(realBox, box, MWAWVec2f(float(angle[0]),float(angle[1]))); |
| 1686 |
break; |
| 1687 |
} |
| 1688 |
case ClarisDrawGraphInternal::Zone::T_RectOval: { |
| 1689 |
decal=4; |
| 1690 |
shape.m_type = MWAWGraphicShape::Rectangle; |
| 1691 |
if (remainBytes < 8) { |
| 1692 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readSimpleGraphicZone: arc zone is too short\n")); |
| 1693 |
return false; |
| 1694 |
} |
| 1695 |
for (int i = 0; i < 2; i++) { |
| 1696 |
float dim=float(input->readLong(2))/2.0f; |
| 1697 |
shape.m_cornerWidth[i]=(2.f*dim <= pictSz[i]) ? dim : pictSz[i]/2.f; |
| 1698 |
val = static_cast<int>(input->readULong(2)); |
| 1699 |
if (val) f << "rRect" << i << "=" << val << ","; |
| 1700 |
} |
| 1701 |
break; |
| 1702 |
} |
| 1703 |
case ClarisDrawGraphInternal::Zone::T_Pict: |
| 1704 |
case ClarisDrawGraphInternal::Zone::T_Zone: |
| 1705 |
case ClarisDrawGraphInternal::Zone::T_Shape: |
| 1706 |
case ClarisDrawGraphInternal::Zone::T_Unknown: |
| 1707 |
#if !defined(__clang__) |
| 1708 |
default: |
| 1709 |
#endif |
| 1710 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readSimpleGraphicZone: unknown type\n")); |
| 1711 |
return false; |
| 1712 |
} |
| 1713 |
auto numRemain = int(entry.end()-input->tell()); |
| 1714 |
if ((numRemain%2)==1) |
| 1715 |
input->seek(1, librevenge::RVNG_SEEK_CUR); |
| 1716 |
numRemain /= 2; |
| 1717 |
int dashId=0; |
| 1718 |
bool hasShadow=false; |
| 1719 |
for (int i = 0; i < numRemain; i++) { |
| 1720 |
int decalI=i+decal; |
| 1721 |
if (decalI==9) { |
| 1722 |
zone.m_style.m_shadowOffset=MWAWVec2f(float(input->readLong(1)), float(input->readLong(1))); |
| 1723 |
hasShadow=(zone.m_style.m_shadowOffset!=MWAWVec2f(0,0)); |
| 1724 |
continue; |
| 1725 |
} |
| 1726 |
if (decalI==10) { |
| 1727 |
auto col=static_cast<int>(input->readULong(1)); |
| 1728 |
MWAWColor color; |
| 1729 |
if (!m_styleManager->getColor(col, color)) { |
| 1730 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: unknown shadow color!!!\n")); |
| 1731 |
f << "###shadow[col]=" << col << ","; |
| 1732 |
} |
| 1733 |
else if (hasShadow) |
| 1734 |
zone.m_style.setShadowColor(color); |
| 1735 |
col=static_cast<int>(input->readLong(1)); |
| 1736 |
if (col) { |
| 1737 |
static bool first=true; |
| 1738 |
if (first) { |
| 1739 |
first=false; |
| 1740 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: lighting is not implemented!!!\n")); |
| 1741 |
} |
| 1742 |
if (!m_styleManager->getColor(col, color)) { |
| 1743 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: unknown lighting color!!!\n")); |
| 1744 |
f << "###lighting[col]=" << col << ","; |
| 1745 |
} |
| 1746 |
else |
| 1747 |
f << "lighting[col]=" << color << ","; |
| 1748 |
} |
| 1749 |
continue; |
| 1750 |
} |
| 1751 |
val = static_cast<int>(input->readULong(2)); |
| 1752 |
if (decalI==8) { |
| 1753 |
if (val==0xFFFF) |
| 1754 |
continue; |
| 1755 |
else { |
| 1756 |
f << "transf=T" << val << ","; |
| 1757 |
if (val<0 || val>=int(m_state->m_transformations.size())) { |
| 1758 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupDef: can not find the transformation!!!\n")); |
| 1759 |
f << "###"; |
| 1760 |
} |
| 1761 |
else if (shape.m_type!=MWAWGraphicShape::Polygon && shape.m_type!=MWAWGraphicShape::Line) { |
| 1762 |
ClarisDrawGraphInternal::Transformation const &trans=m_state->m_transformations[size_t(val)]; |
| 1763 |
if (shape.m_type!=MWAWGraphicShape::Arc && shape.m_type!=MWAWGraphicShape::Pie) |
| 1764 |
shape.m_bdBox.resizeFromCenter(trans.m_originalSize); |
| 1765 |
if (shape.m_type==MWAWGraphicShape::Arc || shape.m_type==MWAWGraphicShape::Pie || |
| 1766 |
shape.m_type==MWAWGraphicShape::Circle) |
| 1767 |
shape.m_formBox.resizeFromCenter(trans.m_originalSize); |
| 1768 |
shape=shape.rotate(trans.m_rotate, shape.m_bdBox.center()); |
| 1769 |
MWAWVec2f orig=zone.m_box[0]+shape.m_bdBox[0]; |
| 1770 |
shape.translate(-1.f*shape.m_bdBox[0]); |
| 1771 |
zone.m_box=MWAWBox2f(orig, orig+shape.m_bdBox.size()); |
| 1772 |
} |
| 1773 |
} |
| 1774 |
} |
| 1775 |
if (!val) continue; |
| 1776 |
if (decalI==3 && canHaveDash) { |
| 1777 |
dashId=(val&0xFFFF); |
| 1778 |
if (val>>8) |
| 1779 |
f << "g3=" << (val>>8) << ","; |
| 1780 |
} |
| 1781 |
else if (decalI==4 && canHaveDash && (val>>8)==1) { |
| 1782 |
if (!m_styleManager->getDash(dashId+1, zone.m_style.m_lineDashWidth)) |
| 1783 |
f << "###"; |
| 1784 |
f << "dashId=D" << dashId+1 << ","; |
| 1785 |
if (val&0xFFFF) |
| 1786 |
f << "g4=" << (val&0xFFFF) << ","; |
| 1787 |
} |
| 1788 |
else |
| 1789 |
f << "g" << decalI << "=" << std::hex << val << std::dec << ","; |
| 1790 |
} |
| 1791 |
shape.m_extra=f.str(); |
| 1792 |
return true; |
| 1793 |
} |
| 1794 |
|
| 1795 |
bool ClarisDrawGraph::readGroupHeader(ClarisDrawGraphInternal::Group &group) |
| 1796 |
{ |
| 1797 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1798 |
long pos = input->tell(); |
| 1799 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 1800 |
libmwaw::DebugStream f; |
| 1801 |
f << "GroupDef(Header):"; |
| 1802 |
ClarisWksStruct::Struct header; |
| 1803 |
if (!header.readHeader(input,false) || (header.m_size && !header.m_dataSize)) { |
| 1804 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupHeader: zone is too short\n")); |
| 1805 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1806 |
return false; |
| 1807 |
} |
| 1808 |
if (header.m_size == 0) { |
| 1809 |
ascFile.addPos(pos); |
| 1810 |
ascFile.addNote(f.str().c_str()); |
| 1811 |
return true; |
| 1812 |
} |
| 1813 |
long endPos=pos+4+header.m_size; |
| 1814 |
f << header; |
| 1815 |
if (header.m_headerSize) { |
| 1816 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1817 |
input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR); |
| 1818 |
} |
| 1819 |
ascFile.addPos(pos); |
| 1820 |
ascFile.addNote(f.str().c_str()); |
| 1821 |
|
| 1822 |
for (int i = 0; i < int(header.m_numData); i++) { |
| 1823 |
pos = input->tell(); |
| 1824 |
if (readGroupUnknown(group, int(header.m_dataSize), i)) |
| 1825 |
continue; |
| 1826 |
ascFile.addPos(pos); |
| 1827 |
ascFile.addNote("GroupDef-B###:"); |
| 1828 |
input->seek(pos+header.m_dataSize, librevenge::RVNG_SEEK_SET); |
| 1829 |
} |
| 1830 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1831 |
|
| 1832 |
int const numHeaders= header.m_numData==0 ? 1 : int(header.m_numData); |
| 1833 |
for (int i = 0; i < numHeaders; i++) { |
| 1834 |
pos = input->tell(); |
| 1835 |
std::vector<int> res; |
| 1836 |
bool ok = ClarisWksStruct::readIntZone(*m_parserState, "GroupDef", false, 2, res); |
| 1837 |
f.str(""); |
| 1838 |
f << "[GroupDef_B" <<i << "[data0]"; |
| 1839 |
if (ok) { |
| 1840 |
ascFile.addPos(pos); |
| 1841 |
ascFile.addNote(f.str().c_str()); |
| 1842 |
continue; |
| 1843 |
} |
| 1844 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1845 |
f << "###"; |
| 1846 |
ascFile.addPos(pos); |
| 1847 |
ascFile.addNote(f.str().c_str()); |
| 1848 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupHeader: can not find data for %d\n", i)); |
| 1849 |
return true; |
| 1850 |
} |
| 1851 |
// normally, this is often followed by another list of nop/list of int zone (but not always...) |
| 1852 |
for (int i = 0; i < int(header.m_numData); i++) { |
| 1853 |
pos = input->tell(); |
| 1854 |
auto sz=long(input->readULong(4)); |
| 1855 |
f.str(""); |
| 1856 |
f << "[GroupDef_B" << i << "[data1]:"; |
| 1857 |
if (!sz) { |
| 1858 |
ascFile.addPos(pos); |
| 1859 |
ascFile.addNote(f.str().c_str()); |
| 1860 |
continue; |
| 1861 |
} |
| 1862 |
if (sz>12) { // test if this is a list of int |
| 1863 |
input->seek(pos+10, librevenge::RVNG_SEEK_SET); |
| 1864 |
if (input->readLong(2)==2) { |
| 1865 |
std::vector<int> res; |
| 1866 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1867 |
if (sz>12 && ClarisWksStruct::readIntZone(*m_parserState, "GroupDef", false, 2, res)) { |
| 1868 |
ascFile.addPos(pos); |
| 1869 |
ascFile.addNote(f.str().c_str()); |
| 1870 |
continue; |
| 1871 |
} |
| 1872 |
} |
| 1873 |
} |
| 1874 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1875 |
if (i!=0) { |
| 1876 |
f << "###"; |
| 1877 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupHeader: find some data for a dataB zone\n")); |
| 1878 |
} |
| 1879 |
break; |
| 1880 |
} |
| 1881 |
|
| 1882 |
return true; |
| 1883 |
} |
| 1884 |
|
| 1885 |
bool ClarisDrawGraph::readGroupUnknown(ClarisDrawGraphInternal::Group &group, int zoneSz, int id) |
| 1886 |
{ |
| 1887 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1888 |
long pos = input->tell(); |
| 1889 |
input->seek(pos+zoneSz, librevenge::RVNG_SEEK_SET); |
| 1890 |
if (input->tell() != pos+zoneSz) { |
| 1891 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1892 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupUnknown: zone is too short\n")); |
| 1893 |
return false; |
| 1894 |
} |
| 1895 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 1896 |
libmwaw::DebugStream f; |
| 1897 |
if (id >= 0) f << "GroupDef_B" << id << ":"; |
| 1898 |
else f << "GroupDef_A" << ":"; |
| 1899 |
if (zoneSz < 42) { |
| 1900 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readGroupUnknown: zone is too short\n")); |
| 1901 |
f << "###"; |
| 1902 |
ascFile.addPos(pos); |
| 1903 |
ascFile.addNote(f.str().c_str()); |
| 1904 |
return true; |
| 1905 |
} |
| 1906 |
|
| 1907 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1908 |
auto type = static_cast<int>(input->readLong(2)); // find -1, 0, 3 |
| 1909 |
if (type) f << "f0=" << type << ","; |
| 1910 |
for (int i = 0; i < 6; i++) { |
| 1911 |
/** find f1=8|9|f|14|15|2a|40|73|e9, f2=0|d4, f5=0|80, f6=0|33 */ |
| 1912 |
auto val = long(input->readULong(1)); |
| 1913 |
if (val) f << "f" << i+1 << "=" << std::hex << val << std::dec << ","; |
| 1914 |
} |
| 1915 |
std::vector<int16_t> values16; // some values can be small or little endian, so... |
| 1916 |
std::vector<int32_t> values32; |
| 1917 |
for (int i = 0; i < 2; i++) |
| 1918 |
values32.push_back(static_cast<int32_t>(input->readLong(4))); |
| 1919 |
// now two small number also in big or small endian |
| 1920 |
for (int i = 0; i < 2; i++) |
| 1921 |
values16.push_back(static_cast<int16_t>(input->readLong(2))); |
| 1922 |
// a very big number |
| 1923 |
values32.push_back(static_cast<int32_t>(input->readLong(4))); |
| 1924 |
|
| 1925 |
MWAWVec2i dim(static_cast<int>(values32[0]),static_cast<int>(values32[1])); |
| 1926 |
if (id < 0) |
| 1927 |
group.m_pageDimension=MWAWVec2f(dim); |
| 1928 |
if (dim[0] || dim[1]) f << "dim=" << dim << ","; |
| 1929 |
if (values16[0]!=1 || values16[1]!=1) |
| 1930 |
f << "pages[num]=" << values16[0] << "x" << values16[1] << ","; |
| 1931 |
if (values32[2]) |
| 1932 |
f << "g0=" << std::hex << values32[2] << std::dec << ","; |
| 1933 |
|
| 1934 |
if (input->tell() != pos+zoneSz) { |
| 1935 |
ascFile.addDelimiter(input->tell(), '|'); |
| 1936 |
input->seek(pos+zoneSz, librevenge::RVNG_SEEK_SET); |
| 1937 |
} |
| 1938 |
ascFile.addPos(pos); |
| 1939 |
ascFile.addNote(f.str().c_str()); |
| 1940 |
return true; |
| 1941 |
} |
| 1942 |
|
| 1943 |
//////////////////////////////////////////////////////////// |
| 1944 |
// read the polygon vertices |
| 1945 |
//////////////////////////////////////////////////////////// |
| 1946 |
bool ClarisDrawGraph::readPolygonData(std::shared_ptr<ClarisDrawGraphInternal::Zone> zone) |
| 1947 |
{ |
| 1948 |
if (!zone || zone->getType() != ClarisDrawGraphInternal::Zone::T_Shape) |
| 1949 |
return false; |
| 1950 |
auto *bZone = static_cast<ClarisDrawGraphInternal::ZoneShape *>(zone.get()); |
| 1951 |
MWAWGraphicShape &shape = bZone->m_shape; |
| 1952 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 1953 |
long pos = input->tell(); |
| 1954 |
ClarisWksStruct::Struct header; |
| 1955 |
if (!header.readHeader(input,false) || header.m_size==0 || (header.m_size && header.m_dataSize<8)) { |
| 1956 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1957 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readPolygonData: file is too short\n")); |
| 1958 |
return false; |
| 1959 |
} |
| 1960 |
|
| 1961 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 1962 |
libmwaw::DebugStream f; |
| 1963 |
f << "Entries(PolygonData):"; |
| 1964 |
long endPos=pos+4+header.m_size; |
| 1965 |
f << header; |
| 1966 |
if (header.m_headerSize) { |
| 1967 |
ascFile.addDelimiter(input->tell(),'|'); |
| 1968 |
input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR); |
| 1969 |
} |
| 1970 |
ascFile.addPos(pos); |
| 1971 |
ascFile.addNote(f.str().c_str()); |
| 1972 |
|
| 1973 |
bool isSpline=false; |
| 1974 |
std::vector<ClarisDrawGraphInternal::CurvePoint> vertices; |
| 1975 |
for (int i = 0; i < int(header.m_numData); i++) { |
| 1976 |
pos = input->tell(); |
| 1977 |
f.str(""); |
| 1978 |
f << "PolygonData-" << i << ":"; |
| 1979 |
float position[2]; |
| 1980 |
for (auto &posi : position) posi = float(input->readLong(4))/256.f; |
| 1981 |
ClarisDrawGraphInternal::CurvePoint point(MWAWVec2f(position[1], position[0])); |
| 1982 |
if (header.m_dataSize >= 26) { |
| 1983 |
for (auto &controlPoint : point.m_controlPoints) { |
| 1984 |
float ctrlPos[2]; |
| 1985 |
for (auto &ctrl : ctrlPos) ctrl= float(input->readLong(4))/256.f; |
| 1986 |
controlPoint = MWAWVec2f(ctrlPos[1], ctrlPos[0]); |
| 1987 |
} |
| 1988 |
auto fl = static_cast<int>(input->readULong(2)); |
| 1989 |
point.m_type = (fl>>14); |
| 1990 |
f << point << ","; |
| 1991 |
if (fl&0x3FFF) |
| 1992 |
f << "unkn=" << std::hex << int(fl&0x3FFF) << std::dec << ","; |
| 1993 |
} |
| 1994 |
else |
| 1995 |
f << point << ","; |
| 1996 |
if (point.m_type >= 2) isSpline=true; |
| 1997 |
vertices.push_back(point); |
| 1998 |
|
| 1999 |
ascFile.addPos(pos); |
| 2000 |
ascFile.addNote(f.str().c_str()); |
| 2001 |
|
| 2002 |
input->seek(pos+header.m_dataSize, librevenge::RVNG_SEEK_SET); |
| 2003 |
} |
| 2004 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 2005 |
if (!isSpline) { |
| 2006 |
// if (zone.m_zoneType & 1) : we must close the polygon ? |
| 2007 |
for (auto const &pt : vertices) |
| 2008 |
shape.m_vertices.push_back(pt.m_pos); |
| 2009 |
return true; |
| 2010 |
} |
| 2011 |
shape.m_type = MWAWGraphicShape::Path; |
| 2012 |
MWAWVec2f prevPoint, pt1; |
| 2013 |
bool hasPrevPoint = false; |
| 2014 |
for (size_t i = 0; i < vertices.size(); ++i) { |
| 2015 |
auto const &pt = vertices[i]; |
| 2016 |
if (pt.m_type >= 2) pt1 = pt.m_controlPoints[0]; |
| 2017 |
else pt1 = pt.m_pos; |
| 2018 |
char type = hasPrevPoint ? 'C' : i==0 ? 'M' : pt.m_type<2 ? 'L' : 'S'; |
| 2019 |
shape.m_path.push_back(MWAWGraphicShape::PathData(type, pt.m_pos, hasPrevPoint ? prevPoint : pt1, pt1)); |
| 2020 |
hasPrevPoint = pt.m_type >= 2; |
| 2021 |
if (hasPrevPoint) prevPoint = pt.m_controlPoints[1]; |
| 2022 |
} |
| 2023 |
|
| 2024 |
return true; |
| 2025 |
} |
| 2026 |
|
| 2027 |
//////////////////////////////////////////////////////////// |
| 2028 |
// read bitmap picture |
| 2029 |
//////////////////////////////////////////////////////////// |
| 2030 |
bool ClarisDrawGraph::readBitmapColorMap(std::vector<MWAWColor> &cMap) |
| 2031 |
{ |
| 2032 |
cMap.resize(0); |
| 2033 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 2034 |
long pos = input->tell(); |
| 2035 |
auto sz = long(input->readULong(4)); |
| 2036 |
long endPos = pos+4+sz; |
| 2037 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 2038 |
if (!sz) { |
| 2039 |
ascFile.addPos(pos); |
| 2040 |
ascFile.addNote("Nop"); |
| 2041 |
return true; |
| 2042 |
} |
| 2043 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 2044 |
if (long(input->tell()) != endPos) { |
| 2045 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapColorMap: file is too short\n")); |
| 2046 |
return false; |
| 2047 |
} |
| 2048 |
|
| 2049 |
input->seek(pos+4, librevenge::RVNG_SEEK_SET); |
| 2050 |
libmwaw::DebugStream f; |
| 2051 |
f << "Entries(BitmapColor):"; |
| 2052 |
f << "unkn=" << input->readLong(4) << ","; |
| 2053 |
auto maxColor = static_cast<int>(input->readLong(4)); |
| 2054 |
if (sz != 8+8*(maxColor+1)) { |
| 2055 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapColorMap: sz is odd\n")); |
| 2056 |
return false; |
| 2057 |
} |
| 2058 |
cMap.resize(size_t(maxColor+1)); |
| 2059 |
for (int i = 0; i <= maxColor; i++) { |
| 2060 |
auto id = static_cast<int>(input->readULong(2)); |
| 2061 |
if (id != i) { |
| 2062 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapColorMap: find odd index : %d\n", i)); |
| 2063 |
return false; |
| 2064 |
} |
| 2065 |
unsigned char col[3]; |
| 2066 |
for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8); |
| 2067 |
cMap[size_t(i)] = MWAWColor(col[0], col[1], col[2]); |
| 2068 |
} |
| 2069 |
|
| 2070 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 2071 |
ascFile.addPos(pos); |
| 2072 |
ascFile.addNote(f.str().c_str()); |
| 2073 |
|
| 2074 |
return true; |
| 2075 |
} |
| 2076 |
|
| 2077 |
bool ClarisDrawGraph::readBitmapData(ClarisDrawGraphInternal::Bitmap &zone) |
| 2078 |
{ |
| 2079 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 2080 |
long pos = input->tell(); |
| 2081 |
auto sz = long(input->readULong(4)); |
| 2082 |
long endPos = pos+4+sz; |
| 2083 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 2084 |
if (long(input->tell()) != endPos || !sz) { |
| 2085 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapData: file is too short\n")); |
| 2086 |
return false; |
| 2087 |
} |
| 2088 |
|
| 2089 |
long numPixels = zone.m_bitmapSize[0]*zone.m_bitmapSize[1]; |
| 2090 |
if (numPixels<=0) { |
| 2091 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapData: unexpected empty size\n")); |
| 2092 |
return false; |
| 2093 |
} |
| 2094 |
|
| 2095 |
auto numBytesPerPixel = int(sz/numPixels); |
| 2096 |
int bitmapRowSize=zone.m_bitmapSize[0]*numBytesPerPixel; |
| 2097 |
if (sz < numPixels) { |
| 2098 |
int nHalfPixel=(zone.m_bitmapSize[0]+1)/2; |
| 2099 |
for (int align=1; align <= 4; align*=2) { |
| 2100 |
int diffToAlign=align==1 ? 0 : align-(nHalfPixel%align); |
| 2101 |
if (diffToAlign==align) continue; |
| 2102 |
if (sz == (nHalfPixel+diffToAlign)*zone.m_bitmapSize[1]) { |
| 2103 |
bitmapRowSize=(nHalfPixel+diffToAlign); |
| 2104 |
numBytesPerPixel=-2; |
| 2105 |
break; |
| 2106 |
} |
| 2107 |
} |
| 2108 |
} |
| 2109 |
else if (sz > numBytesPerPixel*numPixels) { |
| 2110 |
// check for different row alignment: 2 and 4 |
| 2111 |
for (int align=2; align <= 4; align*=2) { |
| 2112 |
int diffToAlign=align-(zone.m_bitmapSize[0]%align); |
| 2113 |
if (diffToAlign==align) continue; |
| 2114 |
numPixels = (zone.m_bitmapSize[0]+diffToAlign)*zone.m_bitmapSize[1]; |
| 2115 |
if (numPixels<=0) continue; |
| 2116 |
numBytesPerPixel = int(sz/numPixels); |
| 2117 |
if (sz == numBytesPerPixel*numPixels) { |
| 2118 |
bitmapRowSize=(zone.m_bitmapSize[0]+diffToAlign)*numBytesPerPixel; |
| 2119 |
break; |
| 2120 |
} |
| 2121 |
} |
| 2122 |
} |
| 2123 |
|
| 2124 |
if (sz != bitmapRowSize*zone.m_bitmapSize[1]) { |
| 2125 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::readBitmapData: unexpected size\n")); |
| 2126 |
return false; |
| 2127 |
} |
| 2128 |
zone.m_numBytesPerPixel = numBytesPerPixel; |
| 2129 |
zone.m_bitmapRowSize = bitmapRowSize; |
| 2130 |
zone.m_entry.setBegin(pos+4); |
| 2131 |
zone.m_entry.setEnd(endPos); |
| 2132 |
libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; |
| 2133 |
libmwaw::DebugStream f; |
| 2134 |
f << "Entries(BitmapData):[" << numBytesPerPixel << "]"; |
| 2135 |
ascFile.addPos(pos); |
| 2136 |
ascFile.addNote(f.str().c_str()); |
| 2137 |
ascFile.skipZone(pos+4, endPos-1); |
| 2138 |
|
| 2139 |
return true; |
| 2140 |
} |
| 2141 |
|
| 2142 |
//////////////////////////////////////////////////////////// |
| 2143 |
// update the group information |
| 2144 |
//////////////////////////////////////////////////////////// |
| 2145 |
|
| 2146 |
//////////////////////////////////////////////////////////// |
| 2147 |
// send data to the listener |
| 2148 |
//////////////////////////////////////////////////////////// |
| 2149 |
|
| 2150 |
bool ClarisDrawGraph::sendMainGroupChild(int childId, MWAWPosition const &position) |
| 2151 |
{ |
| 2152 |
MWAWGraphicListenerPtr listener=m_mainParser->getGraphicListener(); |
| 2153 |
if (!listener) { |
| 2154 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendMainGroupChild: can not find the listener\n")); |
| 2155 |
return false; |
| 2156 |
} |
| 2157 |
auto iter= m_state->m_groupMap.find(1); |
| 2158 |
if (iter == m_state->m_groupMap.end() || !iter->second) { |
| 2159 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendMainGroupChild: can not find the main group\n")); |
| 2160 |
return false; |
| 2161 |
} |
| 2162 |
auto group = iter->second; |
| 2163 |
group->m_parsed=true; |
| 2164 |
if (childId<0||childId>=static_cast<int>(group->m_zones.size()) || !group->m_zones[size_t(childId)]) { |
| 2165 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendMainGroupChild: can not find child %d\n", childId)); |
| 2166 |
return false; |
| 2167 |
} |
| 2168 |
auto child=group->m_zones[size_t(childId)]; |
| 2169 |
MWAWBox2f box=child->getBdBox(); |
| 2170 |
MWAWPosition pos(position.origin(), box.size(), librevenge::RVNG_POINT); |
| 2171 |
pos.m_anchorTo=MWAWPosition::Page; |
| 2172 |
|
| 2173 |
auto cStyle = child->m_style; |
| 2174 |
pos.m_wrapping=cStyle.getWrapping(); |
| 2175 |
pos.setOrder(child->m_ordering); |
| 2176 |
auto type = child->getType(); |
| 2177 |
if (type==ClarisDrawGraphInternal::Zone::T_Shape) |
| 2178 |
sendShape(static_cast<ClarisDrawGraphInternal::ZoneShape &>(*child), pos); |
| 2179 |
else if (type==ClarisDrawGraphInternal::Zone::T_Pict) { |
| 2180 |
auto &pict=static_cast<ClarisDrawGraphInternal::ZonePict &>(*child); |
| 2181 |
if (pict.m_entries[0].valid()) { |
| 2182 |
MWAWInputStreamPtr input=m_parserState->m_input; |
| 2183 |
long actPos=input->tell(); |
| 2184 |
input->seek(pict.m_entries[0].begin(), librevenge::RVNG_SEEK_SET); |
| 2185 |
std::shared_ptr<MWAWPict> thePict(MWAWPictData::get(input, static_cast<int>(pict.m_entries[0].length()))); |
| 2186 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 2187 |
MWAWEmbeddedObject picture; |
| 2188 |
if (thePict && thePict->getBinary(picture)) |
| 2189 |
listener->insertPicture(pos, picture); |
| 2190 |
} |
| 2191 |
} |
| 2192 |
else if (type==ClarisDrawGraphInternal::Zone::T_Zone) { |
| 2193 |
int cId=child->getZoneId(); |
| 2194 |
switch (m_mainParser->getFileType(child->getZoneId())) { |
| 2195 |
case 0: |
| 2196 |
if (m_state->isEmptyGroup(cId)) |
| 2197 |
break; |
| 2198 |
listener->openGroup(pos); |
| 2199 |
sendGroup(cId, MWAWPosition(pos.origin())); |
| 2200 |
listener->closeGroup(); |
| 2201 |
break; |
| 2202 |
case 1: { |
| 2203 |
auto *cZone=dynamic_cast<ClarisDrawGraphInternal::ZoneZone *>(child.get()); |
| 2204 |
if (!cZone) { |
| 2205 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendMainGroupChild: can not find text sub zone\n")); |
| 2206 |
break; |
| 2207 |
} |
| 2208 |
if (cZone->isANote()) { |
| 2209 |
cStyle.m_lineWidth=1; |
| 2210 |
|
| 2211 |
MWAWBorder border; |
| 2212 |
border.m_color=MWAWColor::black(); |
| 2213 |
border.m_width=1; |
| 2214 |
cStyle.setBorders(libmwaw::LeftBit|libmwaw::BottomBit|libmwaw::RightBit, border); |
| 2215 |
border.m_color=MWAWColor(0x60,0x60,0); // normally pattern of yellow and black |
| 2216 |
border.m_width=20; |
| 2217 |
cStyle.setBorders(libmwaw::TopBit, border); |
| 2218 |
|
| 2219 |
cStyle.setSurfaceColor(MWAWColor(0xff,0xff,0)); |
| 2220 |
cStyle.m_shadowOffset=MWAWVec2f(3,3); |
| 2221 |
cStyle.setShadowColor(MWAWColor(0x80,0x80,0x80)); |
| 2222 |
} |
| 2223 |
if (cZone->m_transformationId>=0 && cZone->m_transformationId<static_cast<int>(m_state->m_transformations.size())) |
| 2224 |
cStyle.m_rotate=m_state->m_transformations[size_t(cZone->m_transformationId)].m_rotate; |
| 2225 |
std::shared_ptr<MWAWSubDocument> doc(new ClarisDrawGraphInternal::SubDocument |
| 2226 |
(*this, m_parserState->m_input, cId, -1)); |
| 2227 |
listener->insertTextBox(pos, doc, cStyle); |
| 2228 |
break; |
| 2229 |
} |
| 2230 |
case 4: |
| 2231 |
sendBitmap(cId, pos); |
| 2232 |
break; |
| 2233 |
default: |
| 2234 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendMainGroupChild: find unexpected group type\n")); |
| 2235 |
break; |
| 2236 |
} |
| 2237 |
} |
| 2238 |
|
| 2239 |
return true; |
| 2240 |
} |
| 2241 |
bool ClarisDrawGraph::sendGroup(int number, MWAWPosition const &position) |
| 2242 |
{ |
| 2243 |
MWAWGraphicListenerPtr listener=m_mainParser->getGraphicListener(); |
| 2244 |
if (!listener) { |
| 2245 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendGroup: can not find the listener\n")); |
| 2246 |
return false; |
| 2247 |
} |
| 2248 |
auto iter = m_state->m_groupMap.find(number); |
| 2249 |
if (iter == m_state->m_groupMap.end() || !iter->second) |
| 2250 |
return false; |
| 2251 |
if (m_state->m_groupSet.find(number)!=m_state->m_groupSet.end()) { |
| 2252 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendGroup: oops find a loop for group %d\n", number)); |
| 2253 |
return false; |
| 2254 |
} |
| 2255 |
m_state->m_groupSet.insert(number); |
| 2256 |
auto group = iter->second; |
| 2257 |
group->m_parsed=true; |
| 2258 |
for (auto const &child : group->m_zones) { |
| 2259 |
if (!child) |
| 2260 |
continue; |
| 2261 |
|
| 2262 |
MWAWBox2f box=child->getBdBox(); |
| 2263 |
MWAWPosition pos(box[0]+position.origin(), box.size(), librevenge::RVNG_POINT); |
| 2264 |
pos.m_anchorTo=MWAWPosition::Page; |
| 2265 |
|
| 2266 |
auto cStyle = child->m_style; |
| 2267 |
pos.m_wrapping=cStyle.getWrapping(); |
| 2268 |
pos.setOrder(child->m_ordering); |
| 2269 |
auto type = child->getType(); |
| 2270 |
if (type==ClarisDrawGraphInternal::Zone::T_Shape) |
| 2271 |
sendShape(static_cast<ClarisDrawGraphInternal::ZoneShape &>(*child), pos); |
| 2272 |
else if (type==ClarisDrawGraphInternal::Zone::T_Pict) { |
| 2273 |
auto &pict=static_cast<ClarisDrawGraphInternal::ZonePict &>(*child); |
| 2274 |
if (pict.m_entries[0].valid()) { |
| 2275 |
MWAWInputStreamPtr input=m_parserState->m_input; |
| 2276 |
long actPos=input->tell(); |
| 2277 |
input->seek(pict.m_entries[0].begin(), librevenge::RVNG_SEEK_SET); |
| 2278 |
std::shared_ptr<MWAWPict> thePict(MWAWPictData::get(input, static_cast<int>(pict.m_entries[0].length()))); |
| 2279 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 2280 |
MWAWEmbeddedObject picture; |
| 2281 |
if (thePict && thePict->getBinary(picture)) |
| 2282 |
listener->insertPicture(pos, picture); |
| 2283 |
} |
| 2284 |
} |
| 2285 |
else if (type==ClarisDrawGraphInternal::Zone::T_Zone) { |
| 2286 |
int cId=child->getZoneId(); |
| 2287 |
switch (m_mainParser->getFileType(child->getZoneId())) { |
| 2288 |
case 0: |
| 2289 |
if (m_state->isEmptyGroup(cId)) |
| 2290 |
break; |
| 2291 |
listener->openGroup(pos); |
| 2292 |
sendGroup(cId, MWAWPosition(pos.origin())); |
| 2293 |
listener->closeGroup(); |
| 2294 |
break; |
| 2295 |
case 1: { |
| 2296 |
auto *cZone=dynamic_cast<ClarisDrawGraphInternal::ZoneZone *>(child.get()); |
| 2297 |
if (!cZone) { |
| 2298 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendGroup: can not find text sub zone\n")); |
| 2299 |
break; |
| 2300 |
} |
| 2301 |
if (cZone->isANote()) { |
| 2302 |
cStyle.m_lineWidth=1; |
| 2303 |
|
| 2304 |
MWAWBorder border; |
| 2305 |
border.m_color=MWAWColor::black(); |
| 2306 |
border.m_width=1; |
| 2307 |
cStyle.setBorders(libmwaw::LeftBit|libmwaw::BottomBit|libmwaw::RightBit, border); |
| 2308 |
border.m_color=MWAWColor(0x60,0x60,0); // normally pattern of yellow and black |
| 2309 |
border.m_width=20; |
| 2310 |
cStyle.setBorders(libmwaw::TopBit, border); |
| 2311 |
|
| 2312 |
cStyle.setSurfaceColor(MWAWColor(0xff,0xff,0)); |
| 2313 |
cStyle.m_shadowOffset=MWAWVec2f(3,3); |
| 2314 |
cStyle.setShadowColor(MWAWColor(0x80,0x80,0x80)); |
| 2315 |
} |
| 2316 |
else if (cStyle.m_surfaceColor.isWhite()) // fixme: not normal, but often better |
| 2317 |
cStyle.m_surfaceOpacity=0; |
| 2318 |
if (cZone->m_transformationId>=0 && cZone->m_transformationId<static_cast<int>(m_state->m_transformations.size())) |
| 2319 |
cStyle.m_rotate=m_state->m_transformations[size_t(cZone->m_transformationId)].m_rotate; |
| 2320 |
|
| 2321 |
/* if we can link text frame, use: |
| 2322 |
cZone->addFrameName(cStyle); |
| 2323 |
std::shared_ptr<MWAWSubDocument> doc; |
| 2324 |
if (!cZone->isLinked()||cZone->m_subId==0) |
| 2325 |
doc.reset(new ClarisDrawGraphInternal::SubDocument(*this, m_parserState->m_input, cId)); |
| 2326 |
*/ |
| 2327 |
std::shared_ptr<MWAWSubDocument> doc(new ClarisDrawGraphInternal::SubDocument |
| 2328 |
(*this, m_parserState->m_input, cId, cZone->isLinked() ? cZone->m_subId : -1)); |
| 2329 |
listener->insertTextBox(pos, doc, cStyle); |
| 2330 |
break; |
| 2331 |
} |
| 2332 |
case 4: |
| 2333 |
sendBitmap(cId, pos); |
| 2334 |
break; |
| 2335 |
default: |
| 2336 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendGroup: find unexpected group type\n")); |
| 2337 |
break; |
| 2338 |
} |
| 2339 |
} |
| 2340 |
} |
| 2341 |
m_state->m_groupSet.erase(number); |
| 2342 |
return true; |
| 2343 |
} |
| 2344 |
|
| 2345 |
//////////////////////////////////////////////////////////// |
| 2346 |
// basic shape, bitmap |
| 2347 |
//////////////////////////////////////////////////////////// |
| 2348 |
bool ClarisDrawGraph::sendShape(ClarisDrawGraphInternal::ZoneShape &pict, MWAWPosition pos) |
| 2349 |
{ |
| 2350 |
MWAWListenerPtr listener=m_mainParser->getGraphicListener(); |
| 2351 |
if (!listener) { |
| 2352 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendShape: can not find the listener\n")); |
| 2353 |
return false; |
| 2354 |
} |
| 2355 |
if (pos.size()[0] < 0 || pos.size()[1] < 0) |
| 2356 |
pos.setSize(pict.getBdBox().size()); |
| 2357 |
MWAWGraphicStyle pStyle(pict.m_style); |
| 2358 |
if (pict.m_shape.m_type!=MWAWGraphicShape::Line) |
| 2359 |
pStyle.m_arrows[0]=pStyle.m_arrows[1]=MWAWGraphicStyle::Arrow(); |
| 2360 |
listener->insertShape(pos, pict.m_shape, pStyle); |
| 2361 |
if (pict.m_shape.m_type!=MWAWGraphicShape::Line || !pict.m_autosize) |
| 2362 |
return true; |
| 2363 |
|
| 2364 |
MWAWVec2f lineSz=pos.size(); |
| 2365 |
MWAWVec2f center=pos.origin() + 0.5f*lineSz; |
| 2366 |
MWAWPosition measurePos(pos); |
| 2367 |
measurePos.setOrigin(center-MWAWVec2f(30,6)); |
| 2368 |
measurePos.setSize(MWAWVec2f(60,12)); |
| 2369 |
measurePos.setOrder(pos.order()+1); |
| 2370 |
std::stringstream s; |
| 2371 |
s << std::setprecision(0) << std::fixed << std::sqrt(lineSz[0]*lineSz[0]+lineSz[1]*lineSz[1]) << " pt"; |
| 2372 |
std::shared_ptr<MWAWSubDocument> doc(new ClarisDrawGraphInternal::SubDocument(*this, m_parserState->m_input, s.str())); |
| 2373 |
MWAWGraphicStyle measureStyle; |
| 2374 |
measureStyle.m_lineWidth=0; |
| 2375 |
measureStyle.setSurfaceColor(MWAWColor::white()); |
| 2376 |
listener->insertTextBox(measurePos, doc, measureStyle); |
| 2377 |
return true; |
| 2378 |
} |
| 2379 |
|
| 2380 |
bool ClarisDrawGraph::sendBitmap(int number, MWAWPosition const &pos) |
| 2381 |
{ |
| 2382 |
auto iter = m_state->m_bitmapMap.find(number); |
| 2383 |
if (iter == m_state->m_bitmapMap.end() || !iter->second) { |
| 2384 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: can not find bitmap %d\n", number)); |
| 2385 |
return false; |
| 2386 |
} |
| 2387 |
return sendBitmap(*iter->second, pos); |
| 2388 |
} |
| 2389 |
|
| 2390 |
bool ClarisDrawGraph::sendBitmap(ClarisDrawGraphInternal::Bitmap &bitmap, MWAWPosition pos) |
| 2391 |
{ |
| 2392 |
MWAWListenerPtr listener=m_mainParser->getGraphicListener(); |
| 2393 |
if (!listener) { |
| 2394 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: can not find the listener\n")); |
| 2395 |
return false; |
| 2396 |
} |
| 2397 |
bitmap.m_parsed=true; |
| 2398 |
if (!bitmap.m_entry.valid() || !bitmap.m_numBytesPerPixel) |
| 2399 |
return false; |
| 2400 |
int bytesPerPixel = bitmap.m_numBytesPerPixel; |
| 2401 |
if (bytesPerPixel<0 && (bytesPerPixel!=-2 && bytesPerPixel!=-4)) { |
| 2402 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: unknown group of color\n")); |
| 2403 |
return false; |
| 2404 |
} |
| 2405 |
auto numColors = int(bitmap.m_colorMap.size()); |
| 2406 |
std::shared_ptr<MWAWPictBitmap> bmap; |
| 2407 |
|
| 2408 |
MWAWPictBitmapIndexed *bmapIndexed = nullptr; |
| 2409 |
MWAWPictBitmapColor *bmapColor = nullptr; |
| 2410 |
bool indexed = false; |
| 2411 |
if (numColors > 2) { |
| 2412 |
bmapIndexed = new MWAWPictBitmapIndexed(bitmap.m_bitmapSize); |
| 2413 |
bmapIndexed->setColors(bitmap.m_colorMap); |
| 2414 |
bmap.reset(bmapIndexed); |
| 2415 |
indexed = true; |
| 2416 |
} |
| 2417 |
else { |
| 2418 |
if (bytesPerPixel<0) { |
| 2419 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: unexpected mode for compressed bitmap. Bitmap ignored.\n")); |
| 2420 |
return false; |
| 2421 |
} |
| 2422 |
bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_bitmapSize))); |
| 2423 |
} |
| 2424 |
|
| 2425 |
bool const isCompressed = bytesPerPixel<0; |
| 2426 |
int const numColorByData= isCompressed ? -bytesPerPixel : 1; |
| 2427 |
long const colorMask= !isCompressed ? 0 : numColorByData==2 ? 0xF : 0x3; |
| 2428 |
int const numColorBytes = isCompressed ? 8/numColorByData : 8*bytesPerPixel; |
| 2429 |
//! let go |
| 2430 |
MWAWInputStreamPtr &input= m_parserState->m_input; |
| 2431 |
input->seek(bitmap.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2432 |
for (int r = 0; r < bitmap.m_bitmapSize[1]; r++) { |
| 2433 |
long rPos=input->tell(); |
| 2434 |
int numRead=0; |
| 2435 |
long read=0; |
| 2436 |
for (int c = 0; c < bitmap.m_bitmapSize[0]; c++) { |
| 2437 |
if (numRead==0) { |
| 2438 |
read=long(input->readULong(isCompressed ? 1 : bytesPerPixel)); |
| 2439 |
numRead=numColorByData; |
| 2440 |
} |
| 2441 |
--numRead; |
| 2442 |
long val=!isCompressed ? read : (read>>(numColorBytes*numRead))&colorMask; |
| 2443 |
if (indexed) { |
| 2444 |
bmapIndexed->set(c,r,static_cast<int>(val)); |
| 2445 |
continue; |
| 2446 |
} |
| 2447 |
switch (bytesPerPixel) { |
| 2448 |
case 1: |
| 2449 |
bmapColor->set(c,r, MWAWColor(static_cast<unsigned char>(val),static_cast<unsigned char>(val),static_cast<unsigned char>(val))); |
| 2450 |
break; |
| 2451 |
case 2: // rgb compressed ? |
| 2452 |
bmapColor->set(c,r, MWAWColor(static_cast<unsigned char>(((val>>10)&0x1F) << 3),static_cast<unsigned char>(((val>>5)&0x1F) << 3),static_cast<unsigned char>(((val>>0)&0x1F) << 3))); |
| 2453 |
break; |
| 2454 |
case 4: |
| 2455 |
bmapColor->set(c,r, MWAWColor(static_cast<uint32_t>(val)|0xFF000000)); // checkme |
| 2456 |
break; |
| 2457 |
default: { |
| 2458 |
static bool first = true; |
| 2459 |
if (first) { |
| 2460 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: unknown data size\n")); |
| 2461 |
first = false; |
| 2462 |
} |
| 2463 |
break; |
| 2464 |
} |
| 2465 |
} |
| 2466 |
} |
| 2467 |
input->seek(rPos+bitmap.m_bitmapRowSize, librevenge::RVNG_SEEK_SET); |
| 2468 |
} |
| 2469 |
|
| 2470 |
MWAWEmbeddedObject picture; |
| 2471 |
if (!bmap->getBinary(picture)) return false; |
| 2472 |
if (pos.size()[0] <= 0 || pos.size()[1] <= 0) { |
| 2473 |
pos.m_anchorTo=MWAWPosition::Char; |
| 2474 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: can not find bitmap size\n")); |
| 2475 |
pos.setSize(MWAWVec2f(70,70)); |
| 2476 |
} |
| 2477 |
if (pos.m_anchorTo==MWAWPosition::Unknown) { |
| 2478 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::sendBitmap: anchor is not set, revert to page\n")); |
| 2479 |
pos.m_anchorTo=MWAWPosition::Page; |
| 2480 |
} |
| 2481 |
listener->insertPicture(pos, picture); |
| 2482 |
return true; |
| 2483 |
} |
| 2484 |
|
| 2485 |
|
| 2486 |
//////////////////////////////////////////////////////////// |
| 2487 |
// basic shape, bitmap, pict |
| 2488 |
//////////////////////////////////////////////////////////// |
| 2489 |
void ClarisDrawGraph::flushExtra() |
| 2490 |
{ |
| 2491 |
std::shared_ptr<MWAWListener> listener=m_mainParser->getGraphicListener(); |
| 2492 |
if (!listener) return; |
| 2493 |
|
| 2494 |
MWAWVec2f leftTop=72.0f*m_mainParser->getPageLeftTop(); |
| 2495 |
|
| 2496 |
// first group |
| 2497 |
for (auto const &gIter : m_state->m_groupMap) { |
| 2498 |
auto zone = gIter.second; |
| 2499 |
// can be some footer print on the last page or an unused header/footer |
| 2500 |
if (!zone || zone->m_parsed || zone->isHeaderFooter()) |
| 2501 |
continue; |
| 2502 |
static bool first=true; |
| 2503 |
if (first) { |
| 2504 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::flushExtra: find some extra graph %d\n", zone->m_id)); |
| 2505 |
first=false; |
| 2506 |
} |
| 2507 |
MWAWPosition pos(leftTop,MWAWVec2f(0,0),librevenge::RVNG_POINT); |
| 2508 |
pos.setRelativePosition(MWAWPosition::Page); |
| 2509 |
sendGroup(gIter.first, pos); |
| 2510 |
} |
| 2511 |
// first second |
| 2512 |
for (auto const &bIter : m_state->m_bitmapMap) { |
| 2513 |
auto zone = bIter.second; |
| 2514 |
// can be some footer print on the last page or an unused header/footer |
| 2515 |
if (!zone || zone->m_parsed || zone->isHeaderFooter()) |
| 2516 |
continue; |
| 2517 |
static bool first=true; |
| 2518 |
if (first) { |
| 2519 |
MWAW_DEBUG_MSG(("ClarisDrawGraph::flushExtra: find some extra bitmap %d\n", zone->m_id)); |
| 2520 |
first=false; |
| 2521 |
} |
| 2522 |
MWAWPosition pos(leftTop,MWAWVec2f(0,0),librevenge::RVNG_POINT); |
| 2523 |
pos.setRelativePosition(MWAWPosition::Page); |
| 2524 |
sendBitmap(bIter.first, pos); |
| 2525 |
} |
| 2526 |
} |
| 2527 |
|
| 2528 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |