| 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 <array> |
| 35 |
#include <cmath> |
| 36 |
#include <iomanip> |
| 37 |
#include <iostream> |
| 38 |
#include <limits> |
| 39 |
#include <map> |
| 40 |
#include <set> |
| 41 |
#include <sstream> |
| 42 |
#include <stack> |
| 43 |
|
| 44 |
#include <librevenge/librevenge.h> |
| 45 |
|
| 46 |
#include "MWAWFont.hxx" |
| 47 |
#include "MWAWFontConverter.hxx" |
| 48 |
#include "MWAWGraphicListener.hxx" |
| 49 |
#include "MWAWGraphicShape.hxx" |
| 50 |
#include "MWAWGraphicStyle.hxx" |
| 51 |
#include "MWAWListener.hxx" |
| 52 |
#include "MWAWParagraph.hxx" |
| 53 |
#include "MWAWParser.hxx" |
| 54 |
#include "MWAWPictBitmap.hxx" |
| 55 |
#include "MWAWPictMac.hxx" |
| 56 |
#include "MWAWPosition.hxx" |
| 57 |
#include "MWAWSubDocument.hxx" |
| 58 |
|
| 59 |
#include "Canvas5Parser.hxx" |
| 60 |
|
| 61 |
#include "Canvas5Graph.hxx" |
| 62 |
#include "Canvas5Image.hxx" |
| 63 |
#include "Canvas5Structure.hxx" |
| 64 |
#include "Canvas5StyleManager.hxx" |
| 65 |
|
| 66 |
#include "libmwaw_internal.hxx" |
| 67 |
|
| 68 |
/** Internal: the structures of a Canvas5Graph */ |
| 69 |
namespace Canvas5GraphInternal |
| 70 |
{ |
| 71 |
//! Internal: the section data |
| 72 |
struct SectionData { |
| 73 |
//! constructor |
| 74 |
SectionData() |
| 75 |
: m_numColumns(1) |
| 76 |
, m_bdBox() |
| 77 |
{ |
| 78 |
} |
| 79 |
//! the number of columns |
| 80 |
int m_numColumns; |
| 81 |
//! the bounding box |
| 82 |
MWAWBox2f m_bdBox; |
| 83 |
}; |
| 84 |
|
| 85 |
//! Internal: the shape data |
| 86 |
struct ShapeData { |
| 87 |
//! constructor |
| 88 |
ShapeData() |
| 89 |
: m_inMainZone(true) |
| 90 |
, m_type(0) |
| 91 |
, m_stream() |
| 92 |
, m_streamReverted(false) |
| 93 |
, m_entry() |
| 94 |
, m_vertices() |
| 95 |
, m_children() |
| 96 |
, m_macoId() |
| 97 |
|
| 98 |
, m_grid(1,1) |
| 99 |
, m_ngonType(4) |
| 100 |
|
| 101 |
, m_gdeType(0) |
| 102 |
, m_sections() |
| 103 |
{ |
| 104 |
for (auto &l : m_local) l=0; |
| 105 |
for (auto &i : m_ids) i=0; |
| 106 |
for (auto &s : m_shapeIds) s=0; |
| 107 |
for (auto &s : m_specials) s=0; |
| 108 |
for (auto &e : m_cweb) e=MWAWEntry(); |
| 109 |
for (auto &d : m_doubleValues) d=0; |
| 110 |
} |
| 111 |
//! returns the data stream |
| 112 |
Canvas5Structure::Stream &getStream() const |
| 113 |
{ |
| 114 |
if (!m_stream || !m_stream->input()) { |
| 115 |
MWAW_DEBUG_MSG(("Canvas5GraphInternal::ShapeData::getStream: no input stream\n")); |
| 116 |
throw libmwaw::ParseException(); |
| 117 |
} |
| 118 |
m_stream->input()->setReadInverted(m_streamReverted); |
| 119 |
return *m_stream; |
| 120 |
} |
| 121 |
//! operator<< |
| 122 |
friend std::ostream &operator<<(std::ostream &o, ShapeData const &s) |
| 123 |
{ |
| 124 |
for (int i=0; i< int(MWAW_N_ELEMENTS(s.m_local)); ++i) { |
| 125 |
if (s.m_local[i]) o << "l" << i << "=" << s.m_local[i] << ","; |
| 126 |
} |
| 127 |
for (int i=0; i< int(MWAW_N_ELEMENTS(s.m_ids)); ++i) { |
| 128 |
if (!s.m_ids[i]) continue; |
| 129 |
char const *wh[]= {"TL", "Mat", "Str"}; |
| 130 |
o << wh[i] << s.m_ids[i] << ","; |
| 131 |
} |
| 132 |
for (int i=0; i< int(MWAW_N_ELEMENTS(s.m_shapeIds)); ++i) { |
| 133 |
if (!s.m_shapeIds[i]) continue; |
| 134 |
char const *wh[]= {"child", "parent", "shape1", "shape2"}; |
| 135 |
o << wh[i] << "=S" << s.m_shapeIds[i] << ","; |
| 136 |
} |
| 137 |
return o; |
| 138 |
} |
| 139 |
//! a flag to know if the shape is in the main zone or in Vkfl |
| 140 |
bool m_inMainZone; |
| 141 |
//! the shape type |
| 142 |
unsigned m_type; |
| 143 |
//! the data stream |
| 144 |
std::shared_ptr<Canvas5Structure::Stream> m_stream; |
| 145 |
//! a flag to know the stream endian |
| 146 |
bool m_streamReverted; |
| 147 |
//! the shape data entry |
| 148 |
MWAWEntry m_entry; |
| 149 |
//! the local variable |
| 150 |
int m_local[2]; |
| 151 |
//! the text link, matrix, name id |
| 152 |
unsigned m_ids[3]; |
| 153 |
//! the shape ids |
| 154 |
unsigned m_shapeIds[4]; |
| 155 |
|
| 156 |
//! the shape vertices: line, ... |
| 157 |
std::vector<MWAWVec2f> m_vertices; |
| 158 |
//! the childs: group |
| 159 |
std::vector<unsigned> m_children; |
| 160 |
//! the macro Id: MACO |
| 161 |
std::vector<unsigned> m_macoId; |
| 162 |
|
| 163 |
// special |
| 164 |
|
| 165 |
//! the grid subdivision |
| 166 |
MWAWVec2i m_grid; |
| 167 |
//! some special values |
| 168 |
int m_specials[4]; |
| 169 |
//! the buttons image entries |
| 170 |
MWAWEntry m_cweb[3]; |
| 171 |
//! the n-polygon type: NGON |
| 172 |
int m_ngonType; |
| 173 |
//! the #Gde type |
| 174 |
int m_gdeType; |
| 175 |
//! the sections: #Gde |
| 176 |
std::vector<SectionData> m_sections; |
| 177 |
//! the arc angles or rect oval size: v9 |
| 178 |
double m_doubleValues[4]; |
| 179 |
}; |
| 180 |
|
| 181 |
//! Internal: the shape of a Canvas5Graph |
| 182 |
struct Shape { |
| 183 |
//! constructor |
| 184 |
Shape() |
| 185 |
: m_type(-1) |
| 186 |
, m_id(0) |
| 187 |
, m_initialBox() |
| 188 |
, m_bdbox() |
| 189 |
, m_pos() |
| 190 |
, m_sent(false) |
| 191 |
{ |
| 192 |
for (auto &f : m_flags) f=0; |
| 193 |
for (auto &v : m_values) v=0; |
| 194 |
} |
| 195 |
|
| 196 |
//! returns the type name |
| 197 |
std::string getTypeName() const |
| 198 |
{ |
| 199 |
static std::map<int, std::string> const s_typeName= { |
| 200 |
{2,"text"}, |
| 201 |
{3,"line"}, |
| 202 |
{4,"rect"}, |
| 203 |
{5,"rectOval"}, |
| 204 |
{6,"oval"}, |
| 205 |
{7,"arc"}, |
| 206 |
{9,"polyline"}, |
| 207 |
{10,"spline"}, |
| 208 |
{52,"special"}, |
| 209 |
{99,"group"}, |
| 210 |
{100,"none"} |
| 211 |
}; |
| 212 |
auto const &it=s_typeName.find(m_type); |
| 213 |
if (it!=s_typeName.end()) |
| 214 |
return it->second; |
| 215 |
std::stringstream s; |
| 216 |
s << "Type" << m_type << "A"; |
| 217 |
return s.str(); |
| 218 |
} |
| 219 |
|
| 220 |
//! operator<< |
| 221 |
friend std::ostream &operator<<(std::ostream &o, Shape const &s) |
| 222 |
{ |
| 223 |
o << s.getTypeName() << ","; |
| 224 |
o << s.m_bdbox << ","; |
| 225 |
if (s.m_bdbox!=s.m_initialBox) |
| 226 |
o << "bdbox[orig]=" << s.m_initialBox << ","; |
| 227 |
if (s.m_type!=100 && s.m_pos>=0) |
| 228 |
o << "data=" << std::hex << s.m_pos << std::dec << ","; |
| 229 |
if (s.m_flags[0]) { |
| 230 |
if (s.m_flags[0]&1) o << "locked,"; |
| 231 |
if (s.m_flags[0]&4) o << "noPrint,"; |
| 232 |
if (s.m_flags[0]&0x200) o << "spread[trap],"; |
| 233 |
if (s.m_flags[0]&0x400) o << "overPrint,"; |
| 234 |
if (s.m_flags[0]&0x800) o << "trap[choke],"; |
| 235 |
int val=(s.m_flags[0]&0xf1fa); |
| 236 |
if (val) |
| 237 |
o << "fl=" << std::hex << val << std::dec << ","; |
| 238 |
} |
| 239 |
if (s.m_flags[1]) { |
| 240 |
if (s.m_flags[1]&1) o << "parent,"; |
| 241 |
if (s.m_flags[1]&2) o << "shape1,"; |
| 242 |
if (s.m_flags[1]&4) o << "shape2,"; |
| 243 |
if (s.m_flags[1]&8) o << "rot,"; |
| 244 |
int val=(s.m_flags[1]&0xfff9); |
| 245 |
if (val) |
| 246 |
o << "fl1=" << std::hex << val << std::dec << ","; |
| 247 |
} |
| 248 |
if (s.m_flags[2]) { |
| 249 |
if ((s.m_flags[2]&0x1)==0) o << "no[size],"; |
| 250 |
if (s.m_flags[2]&0x4) o << "txtPlc[id],"; |
| 251 |
if (s.m_flags[2]&0x10) o << "mat,"; |
| 252 |
if (s.m_flags[2]&0x20) o << "type,"; |
| 253 |
if (s.m_flags[2]&0x80) o << "shape[id],"; |
| 254 |
if (s.m_flags[2]&0x200) o << "loc1,"; |
| 255 |
if (s.m_flags[2]&0x400) o << "loc2,"; |
| 256 |
if (s.m_flags[2]&0x800) o << "name,"; |
| 257 |
int val=(s.m_flags[2]&0xf1ca); |
| 258 |
if (val) |
| 259 |
o << "fl2=" << std::hex << val << std::dec << ","; |
| 260 |
} |
| 261 |
for (int i=0; i<int(MWAW_N_ELEMENTS(s.m_values)); ++i) { |
| 262 |
int val=s.m_values[i]; |
| 263 |
if (val==0) continue; |
| 264 |
char const *wh[]= {nullptr, "col[surf]=Co", "col[line]=Co", "stroke=St"}; |
| 265 |
if (wh[i]) |
| 266 |
o << wh[i] << val << ","; |
| 267 |
else |
| 268 |
o << "f" << i << "=" << val << ","; |
| 269 |
} |
| 270 |
return o; |
| 271 |
} |
| 272 |
//! the shape type |
| 273 |
int m_type; |
| 274 |
//! the shape id |
| 275 |
int m_id; |
| 276 |
//! the original box |
| 277 |
MWAWBox2f m_initialBox; |
| 278 |
//! the bounding box |
| 279 |
MWAWBox2f m_bdbox; |
| 280 |
//! the beginning position |
| 281 |
long m_pos; |
| 282 |
//! some unknown value |
| 283 |
int m_values[4]; |
| 284 |
//! some unknown flag |
| 285 |
int m_flags[3]; |
| 286 |
//! a flag to know if the shape is already send |
| 287 |
mutable bool m_sent; |
| 288 |
}; |
| 289 |
|
| 290 |
//! Internal[low level]: a pseudo class to store the data corresponding to a shape |
| 291 |
struct PseudoShape { |
| 292 |
//! constructor |
| 293 |
PseudoShape() |
| 294 |
: m_shape() |
| 295 |
, m_data() |
| 296 |
{ |
| 297 |
} |
| 298 |
|
| 299 |
//! the shape |
| 300 |
Shape m_shape; |
| 301 |
//! the data shape |
| 302 |
ShapeData m_data; |
| 303 |
}; |
| 304 |
|
| 305 |
//////////////////////////////////////// |
| 306 |
//! Internal: the state of a Canvas5Graph |
| 307 |
struct State { |
| 308 |
//! constructor |
| 309 |
State() |
| 310 |
: m_dataStream() |
| 311 |
, m_dataStreamReverted(false) |
| 312 |
|
| 313 |
, m_shapeZones() |
| 314 |
, m_idToShapeMap() |
| 315 |
, m_posToShapeDataMap() |
| 316 |
, m_idToMatrices() |
| 317 |
|
| 318 |
, m_sendIdSet() |
| 319 |
, m_sendAGIFIdSet() |
| 320 |
, m_sendMACOIdSet() |
| 321 |
{ |
| 322 |
} |
| 323 |
|
| 324 |
//! the data shape stream |
| 325 |
std::shared_ptr<Canvas5Structure::Stream> m_dataStream; |
| 326 |
//! a flag to retrieved the data shape entry |
| 327 |
bool m_dataStreamReverted; |
| 328 |
|
| 329 |
//! the shape data zones |
| 330 |
std::vector<MWAWEntry> m_shapeZones; |
| 331 |
//! the map id to shape |
| 332 |
std::map<int, Shape> m_idToShapeMap; |
| 333 |
//! the map id to shape data |
| 334 |
std::map<long, ShapeData> m_posToShapeDataMap; |
| 335 |
//! the map id to matrices |
| 336 |
std::map<int, std::array<std::array<double,9>, 2> > m_idToMatrices; |
| 337 |
|
| 338 |
//! the list of current send shape id (used to avoid loop) |
| 339 |
std::set<int> m_sendIdSet; |
| 340 |
//! the list of current send GIF id (used to avoid loop) |
| 341 |
std::set<int> m_sendAGIFIdSet; |
| 342 |
//! the list of current send macro id (used to avoid loop) |
| 343 |
std::set<std::vector<unsigned> > m_sendMACOIdSet; |
| 344 |
}; |
| 345 |
|
| 346 |
//////////////////////////////////////// |
| 347 |
//! Internal: the subdocument of a Canvas5Graph |
| 348 |
class SubDocument final : public MWAWSubDocument |
| 349 |
{ |
| 350 |
public: |
| 351 |
//! constructor from a zoneId |
| 352 |
SubDocument(Canvas5Graph &parser, MWAWInputStreamPtr const &input, Shape const &shape, ShapeData const &data) |
| 353 |
: MWAWSubDocument(parser.m_mainParser, input, MWAWEntry()) |
| 354 |
, m_graphParser(parser) |
| 355 |
, m_shape(&shape) |
| 356 |
, m_data(&data) |
| 357 |
, m_measure() |
| 358 |
, m_font() |
| 359 |
{ |
| 360 |
} |
| 361 |
//! constructor from string |
| 362 |
SubDocument(Canvas5Graph &parser, MWAWInputStreamPtr const &input, librevenge::RVNGString const &measure, MWAWFont const &font) |
| 363 |
: MWAWSubDocument(parser.m_mainParser, input, MWAWEntry()) |
| 364 |
, m_graphParser(parser) |
| 365 |
, m_shape(nullptr) |
| 366 |
, m_data(nullptr) |
| 367 |
, m_measure(measure) |
| 368 |
, m_font(font) |
| 369 |
{ |
| 370 |
} |
| 371 |
|
| 372 |
//! destructor |
| 373 |
~SubDocument() final {} |
| 374 |
|
| 375 |
//! operator!= |
| 376 |
bool operator!=(MWAWSubDocument const &doc) const final |
| 377 |
{ |
| 378 |
if (MWAWSubDocument::operator!=(doc)) return true; |
| 379 |
auto const *sDoc = dynamic_cast<SubDocument const *>(&doc); |
| 380 |
if (!sDoc) return true; |
| 381 |
if (&m_graphParser != &sDoc->m_graphParser) return true; |
| 382 |
if (m_shape != sDoc->m_shape) return true; |
| 383 |
if (m_data != sDoc->m_data) return true; |
| 384 |
if (m_measure != sDoc->m_measure) return true; |
| 385 |
return false; |
| 386 |
} |
| 387 |
|
| 388 |
//! the parser function |
| 389 |
void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final; |
| 390 |
|
| 391 |
protected: |
| 392 |
//! the graph parser |
| 393 |
Canvas5Graph &m_graphParser; |
| 394 |
//! the shape |
| 395 |
Shape const *m_shape; |
| 396 |
//! the shape data |
| 397 |
ShapeData const *m_data; |
| 398 |
//! the measure |
| 399 |
librevenge::RVNGString m_measure; |
| 400 |
//! the font |
| 401 |
MWAWFont m_font; |
| 402 |
private: |
| 403 |
SubDocument(SubDocument const &orig) = delete; |
| 404 |
SubDocument &operator=(SubDocument const &orig) = delete; |
| 405 |
}; |
| 406 |
|
| 407 |
void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/) |
| 408 |
{ |
| 409 |
if (!listener || !listener->canWriteText()) { |
| 410 |
MWAW_DEBUG_MSG(("Canvas5GraphInternal::SubDocument::parse: no listener\n")); |
| 411 |
return; |
| 412 |
} |
| 413 |
if (!m_shape || !m_data) { |
| 414 |
if (m_measure.empty()) { |
| 415 |
MWAW_DEBUG_MSG(("Canvas5GraphInternal::SubDocument::parse: can not find the measure\n")); |
| 416 |
return; |
| 417 |
} |
| 418 |
listener->setFont(m_font); |
| 419 |
MWAWParagraph para; |
| 420 |
para.m_justify = MWAWParagraph::JustificationCenter; |
| 421 |
listener->setParagraph(para); |
| 422 |
listener->insertUnicodeString(m_measure); |
| 423 |
return; |
| 424 |
} |
| 425 |
long pos = m_input ? m_input->tell() : 0; |
| 426 |
m_graphParser.sendText(listener, *m_shape, *m_data); |
| 427 |
if (m_input) m_input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 428 |
} |
| 429 |
|
| 430 |
} |
| 431 |
|
| 432 |
//////////////////////////////////////////////////////////// |
| 433 |
// constructor/destructor, ... |
| 434 |
//////////////////////////////////////////////////////////// |
| 435 |
Canvas5Graph::Canvas5Graph(Canvas5Parser &parser) |
| 436 |
: m_parserState(parser.getParserState()) |
| 437 |
, m_state(new Canvas5GraphInternal::State) |
| 438 |
, m_mainParser(&parser) |
| 439 |
, m_imageParser(parser.m_imageParser) |
| 440 |
, m_styleManager(parser.m_styleManager) |
| 441 |
{ |
| 442 |
} |
| 443 |
|
| 444 |
Canvas5Graph::~Canvas5Graph() |
| 445 |
{ |
| 446 |
} |
| 447 |
|
| 448 |
int Canvas5Graph::version() const |
| 449 |
{ |
| 450 |
return m_parserState->m_version; |
| 451 |
} |
| 452 |
|
| 453 |
//////////////////////////////////////////////////////////// |
| 454 |
// |
| 455 |
// Intermediate level |
| 456 |
// |
| 457 |
//////////////////////////////////////////////////////////// |
| 458 |
|
| 459 |
bool Canvas5Graph::readMatrices(std::shared_ptr<Canvas5Structure::Stream> stream) |
| 460 |
{ |
| 461 |
if (!stream) { |
| 462 |
MWAW_DEBUG_MSG(("Canvas5Graph::readMatrices: no stream\n")); |
| 463 |
return false; |
| 464 |
} |
| 465 |
auto input=stream->input(); |
| 466 |
long pos=input->tell(); |
| 467 |
if (!input->checkPosition(pos+4)) { |
| 468 |
MWAW_DEBUG_MSG(("Canvas5Graph::readMatrices: the zone is too short\n")); |
| 469 |
return false; |
| 470 |
} |
| 471 |
libmwaw::DebugFile &ascFile = stream->ascii(); |
| 472 |
pos=input->tell(); |
| 473 |
libmwaw::DebugStream f; |
| 474 |
f << "Entries(Matrix):"; |
| 475 |
if (version()>=9) { |
| 476 |
ascFile.addPos(pos); |
| 477 |
ascFile.addNote(f.str().c_str()); |
| 478 |
return m_mainParser->readArray9(stream, "Matrix", |
| 479 |
[this](std::shared_ptr<Canvas5Structure::Stream> lStream, Canvas5Parser::Item const &item, std::string const &) { |
| 480 |
auto lInput=lStream->input(); |
| 481 |
libmwaw::DebugFile &asciiFile = lStream->ascii(); |
| 482 |
libmwaw::DebugStream lF; |
| 483 |
lF << "Mat" << item.m_id << ","; |
| 484 |
if (item.m_length!=144) { |
| 485 |
MWAW_DEBUG_MSG(("Canvas5Graph::readMatrices: a matrix is too short\n")); |
| 486 |
lF << "###"; |
| 487 |
asciiFile.addPos(item.m_pos); |
| 488 |
asciiFile.addNote(lF.str().c_str()); |
| 489 |
} |
| 490 |
lInput->seek(-4, librevenge::RVNG_SEEK_CUR); |
| 491 |
std::array<std::array<double,9>, 2> matrices; |
| 492 |
for (size_t st=0; st<2; ++st) { |
| 493 |
lF << "mat" << st << "=["; |
| 494 |
auto &matrix = matrices[st]; |
| 495 |
for (auto &d : matrix) { |
| 496 |
d=m_mainParser->readDouble(*lStream, 8); |
| 497 |
lF << d << ","; |
| 498 |
} |
| 499 |
lF << "],"; |
| 500 |
} |
| 501 |
m_state->m_idToMatrices[item.m_id]=matrices; |
| 502 |
asciiFile.addPos(item.m_pos); |
| 503 |
asciiFile.addNote(lF.str().c_str()); |
| 504 |
}); |
| 505 |
} |
| 506 |
int val=int(input->readLong(4)); |
| 507 |
if (val!=-1) |
| 508 |
f << "f0=" << val << ","; |
| 509 |
ascFile.addPos(pos); |
| 510 |
ascFile.addNote(f.str().c_str()); |
| 511 |
if (!m_mainParser->readUsed(*stream, "Matrix")) // size=144 |
| 512 |
return false; |
| 513 |
return m_mainParser->readExtendedHeader(stream, 0x48, "Matrix", |
| 514 |
[this](std::shared_ptr<Canvas5Structure::Stream> lStream, Canvas5Parser::Item const &item, std::string const &) { |
| 515 |
auto lInput=lStream->input(); |
| 516 |
libmwaw::DebugFile &asciiFile = lStream->ascii(); |
| 517 |
libmwaw::DebugStream lF; |
| 518 |
lF << "Mat" << item.m_id << ","; |
| 519 |
std::array<std::array<double,9>, 2> matrices; |
| 520 |
for (size_t st=0; st<2; ++st) { |
| 521 |
lF << "mat" << st << "=["; |
| 522 |
auto &matrix = matrices[st]; |
| 523 |
for (auto &d : matrix) { |
| 524 |
d=double(lInput->readLong(4))/65536.; |
| 525 |
lF << d << ","; |
| 526 |
} |
| 527 |
lF << "],"; |
| 528 |
} |
| 529 |
m_state->m_idToMatrices[item.m_id]=matrices; |
| 530 |
asciiFile.addPos(item.m_pos); |
| 531 |
asciiFile.addNote(lF.str().c_str()); |
| 532 |
}); |
| 533 |
} |
| 534 |
|
| 535 |
//////////////////////////////////////////////////////////// |
| 536 |
// shapes |
| 537 |
//////////////////////////////////////////////////////////// |
| 538 |
|
| 539 |
bool Canvas5Graph::findShapeDataZones(std::shared_ptr<Canvas5Structure::Stream> stream) |
| 540 |
{ |
| 541 |
if (!stream || !stream->input()) |
| 542 |
return false; |
| 543 |
m_state->m_dataStream=stream; |
| 544 |
auto input=stream->input(); |
| 545 |
m_state->m_dataStreamReverted=input->readInverted(); |
| 546 |
auto &ascFile=stream->ascii(); |
| 547 |
long pos=input->tell(); |
| 548 |
int len=int(input->readULong(4)); |
| 549 |
if ((len%20)!=0 || (long)((unsigned long)pos+4+(unsigned)len)<pos+4 || !input->checkPosition(pos+4+len)) { |
| 550 |
MWAW_DEBUG_MSG(("Canvas5Graph::findShapeDataZones: can not find zone 1\n")); |
| 551 |
return false; |
| 552 |
} |
| 553 |
ascFile.addPos(pos); |
| 554 |
ascFile.addNote("Entries(DataShap):"); |
| 555 |
|
| 556 |
libmwaw::DebugStream f; |
| 557 |
int N=len/20; |
| 558 |
for (int i=0; i<N; ++i) { |
| 559 |
pos=input->tell(); |
| 560 |
f.str(""); |
| 561 |
f << "DataShap-" << i << ":"; |
| 562 |
f << "id=" << input->readULong(4) << ","; |
| 563 |
f << "f0=" << input->readULong(4) << ","; // small number |
| 564 |
f << "sz=" << input->readULong(4) << ","; |
| 565 |
for (int j=0; j<4; ++j) { // 0 |
| 566 |
int val=int(input->readLong(2)); |
| 567 |
if (val) |
| 568 |
f << "f" << j+1 << "=" << val << ","; |
| 569 |
} |
| 570 |
ascFile.addPos(pos); |
| 571 |
ascFile.addNote(f.str().c_str()); |
| 572 |
input->seek(pos+20, librevenge::RVNG_SEEK_SET); |
| 573 |
} |
| 574 |
|
| 575 |
for (int i=0; i<N; ++i) { |
| 576 |
pos=input->tell(); |
| 577 |
f.str(""); |
| 578 |
f << "DataShap-A" << i << ":"; |
| 579 |
long zLen=long(input->readULong(4)); |
| 580 |
if ((long)((unsigned long)pos+4+(unsigned long)zLen)<pos+4 || !input->checkPosition(pos+4+zLen)) { |
| 581 |
MWAW_DEBUG_MSG(("Canvas5Graph::findShapeDataZones: can not find a zone 1 length\n")); |
| 582 |
f << "###"; |
| 583 |
ascFile.addPos(pos); |
| 584 |
ascFile.addNote(f.str().c_str()); |
| 585 |
return false; |
| 586 |
} |
| 587 |
MWAWEntry entry; |
| 588 |
entry.setBegin(pos+4); |
| 589 |
entry.setLength(zLen); |
| 590 |
m_state->m_shapeZones.push_back(entry); |
| 591 |
ascFile.addPos(pos); |
| 592 |
ascFile.addNote(f.str().c_str()); |
| 593 |
input->seek(pos+4+zLen, librevenge::RVNG_SEEK_SET); |
| 594 |
} |
| 595 |
return true; |
| 596 |
} |
| 597 |
|
| 598 |
bool Canvas5Graph::readShapes(Canvas5Structure::Stream &stream, int numShapes) |
| 599 |
{ |
| 600 |
auto input=stream.input(); |
| 601 |
long pos=input->tell(); |
| 602 |
if (!input->checkPosition(pos+4)) { |
| 603 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapes: can not find the input\n")); |
| 604 |
return false; |
| 605 |
} |
| 606 |
long len=long(input->readULong(4)); |
| 607 |
long endPos=pos+4+len; |
| 608 |
int const vers=version(); |
| 609 |
int const dataSize=vers<9 ? 60 : 96; |
| 610 |
if (endPos<pos+4 || len<dataSize*numShapes || !input->checkPosition(endPos)) { |
| 611 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapes: can not determine the zone length\n")); |
| 612 |
return false; |
| 613 |
} |
| 614 |
|
| 615 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 616 |
libmwaw::DebugStream f; |
| 617 |
f << "Entries(Shape):"; |
| 618 |
ascFile.addPos(pos); |
| 619 |
ascFile.addNote(f.str().c_str()); |
| 620 |
bool reverted=input->readInverted(); |
| 621 |
for (int i=0; i<numShapes; ++i) { |
| 622 |
pos=input->tell(); |
| 623 |
if (i<1) { |
| 624 |
ascFile.addPos(pos); |
| 625 |
ascFile.addNote("_"); |
| 626 |
input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET); |
| 627 |
continue; |
| 628 |
} |
| 629 |
Canvas5GraphInternal::Shape shape; |
| 630 |
f.str(""); |
| 631 |
f << "Shape-S" << i << ":"; |
| 632 |
float fDim[4]; |
| 633 |
for (auto &d : fDim) d=float(m_mainParser->readDouble(stream, vers<9 ? 4 : 8)); |
| 634 |
if (vers<9) |
| 635 |
shape.m_initialBox=MWAWBox2f(MWAWVec2f(fDim[1], fDim[0]),MWAWVec2f(fDim[3], fDim[2])); |
| 636 |
else |
| 637 |
shape.m_initialBox=MWAWBox2f(MWAWVec2f(fDim[0], fDim[1]),MWAWVec2f(fDim[2], fDim[3])); |
| 638 |
for (auto &d : fDim) d=float(m_mainParser->readDouble(stream, vers<9 ? 4 : 8)); |
| 639 |
if (vers<9) |
| 640 |
shape.m_bdbox=MWAWBox2f(MWAWVec2f(fDim[1], fDim[0]),MWAWVec2f(fDim[3], fDim[2])); |
| 641 |
else |
| 642 |
shape.m_bdbox=MWAWBox2f(MWAWVec2f(fDim[0], fDim[1]),MWAWVec2f(fDim[2], fDim[3])); |
| 643 |
unsigned block=unsigned(input->readULong(2)); |
| 644 |
shape.m_pos=int((block<<16)|input->readULong(2)); |
| 645 |
if (shape.m_pos==int(0xFFFFFFFF)) shape.m_pos=-1; |
| 646 |
shape.m_type=int(input->readULong(1)); |
| 647 |
if (shape.m_type==100) { // none |
| 648 |
ascFile.addPos(pos); |
| 649 |
ascFile.addNote("_"); |
| 650 |
input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET); |
| 651 |
continue; |
| 652 |
} |
| 653 |
f << "id=" << std::hex << input->readULong(4) << std::dec << ","; |
| 654 |
shape.m_values[0]=int(input->readULong(1)); |
| 655 |
for (int j=0; j<3; ++j) |
| 656 |
shape.m_flags[j]=int(input->readULong(2)); |
| 657 |
if (reverted) std::swap(shape.m_flags[1],shape.m_flags[2]); |
| 658 |
if (shape.m_flags[1]&0x60) { |
| 659 |
f << "##fl,"; |
| 660 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapes: find some unknown flags\n")); |
| 661 |
} |
| 662 |
for (int j=0; j<3; ++j) // small number, maybe parent id, child id, ??? |
| 663 |
shape.m_values[j+1]=int(input->readLong(4)); |
| 664 |
f << shape << ","; |
| 665 |
shape.m_id=i; |
| 666 |
m_state->m_idToShapeMap[i]=shape; |
| 667 |
ascFile.addPos(pos); |
| 668 |
ascFile.addNote(f.str().c_str()); |
| 669 |
input->seek(pos+dataSize, librevenge::RVNG_SEEK_SET); |
| 670 |
} |
| 671 |
if (input->tell()<endPos) |
| 672 |
ascFile.skipZone(input->tell(), endPos-1); |
| 673 |
if (&stream!=m_state->m_dataStream.get()) { |
| 674 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapes: oops, the shape data stream seems bad\n")); |
| 675 |
} |
| 676 |
else { |
| 677 |
for (auto const &it : m_state->m_idToShapeMap) { |
| 678 |
if (it.second.m_pos>=0) |
| 679 |
readShapeData(it.first, it.second); |
| 680 |
} |
| 681 |
} |
| 682 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 683 |
return true; |
| 684 |
} |
| 685 |
|
| 686 |
bool Canvas5Graph::readShapeData(int id, Canvas5GraphInternal::Shape const &shape) |
| 687 |
{ |
| 688 |
auto &stream=m_state->m_dataStream; |
| 689 |
if (shape.m_pos < 0 || !stream) { |
| 690 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: shape id=%d has not a valid position\n", id)); |
| 691 |
return false; |
| 692 |
} |
| 693 |
if ((shape.m_flags[1]&0x419f)==0 && (shape.m_flags[2]&0xfff)==0 && shape.m_type>=4 && shape.m_type<=7) |
| 694 |
return true; // sometimes m_pos is set even if there is no data |
| 695 |
size_t bl=size_t(shape.m_pos>>16); |
| 696 |
long pos=shape.m_pos&0xffff; |
| 697 |
if (bl>=m_state->m_shapeZones.size() || pos+4 > m_state->m_shapeZones[bl].length()) { |
| 698 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: can not find the block corresponding to shape id=%d\n", id)); |
| 699 |
return false; |
| 700 |
} |
| 701 |
|
| 702 |
if (m_state->m_posToShapeDataMap.find(shape.m_pos)!=m_state->m_posToShapeDataMap.end()) |
| 703 |
return true; |
| 704 |
auto const &entry=m_state->m_shapeZones[bl]; |
| 705 |
auto input=stream->input(); |
| 706 |
int const vers=version(); |
| 707 |
libmwaw::DebugFile &ascFile = stream->ascii(); |
| 708 |
libmwaw::DebugStream f; |
| 709 |
f << "DataShap-S" << id << ":"; |
| 710 |
|
| 711 |
input->seek(entry.begin()+pos, librevenge::RVNG_SEEK_SET); |
| 712 |
pos=input->tell(); |
| 713 |
int val=int(input->readULong(4)); |
| 714 |
if (val!=id) f << "dup2=" << val << ","; |
| 715 |
f << shape.getTypeName() << ","; |
| 716 |
|
| 717 |
m_state->m_posToShapeDataMap[shape.m_pos]=Canvas5GraphInternal::ShapeData(); |
| 718 |
Canvas5GraphInternal::ShapeData &data=m_state->m_posToShapeDataMap.find(shape.m_pos)->second; |
| 719 |
long len=(shape.m_flags[2]&0x1) ? long(input->readULong(4)) : 0; |
| 720 |
if (shape.m_flags[2]&0x2) f << "f2=" << long(input->readULong(4)) << ","; // find id=1??? |
| 721 |
if (shape.m_flags[2]&0x4) data.m_ids[0]=unsigned(input->readULong(4)); |
| 722 |
if (shape.m_flags[2]&0x8) f << "f8=" << long(input->readULong(4)) << ","; // never seen this one |
| 723 |
if (shape.m_flags[2]&0x10) data.m_ids[1]=unsigned(input->readULong(4)); |
| 724 |
if (shape.m_flags[2]&0x20) data.m_type = unsigned(input->readULong(4)); |
| 725 |
if (shape.m_flags[2]&0x40) f << "f40=" << long(input->readULong(4)) << ","; // never seen this one |
| 726 |
if (shape.m_flags[2]&0x80) data.m_shapeIds[0]=unsigned(input->readULong(4)); // checkme: replaced? |
| 727 |
if (shape.m_flags[2]&0x100) f << "f100=" << long(input->readULong(4)) << ","; // never seen this one |
| 728 |
if (shape.m_flags[2]&0x200) data.m_local[0]=int(input->readULong(4)); // text: id?, rectOval: roundX, arc angl1 |
| 729 |
if (shape.m_flags[2]&0x400) data.m_local[1]=int(input->readULong(4)); // roundY, angl2 |
| 730 |
if (shape.m_flags[2]&0x800) data.m_ids[2]=unsigned(input->readULong(4)); |
| 731 |
if (shape.m_flags[1]&0x1) data.m_shapeIds[1]=unsigned(input->readULong(4)); |
| 732 |
if (shape.m_flags[1]&0x2) data.m_shapeIds[2]=unsigned(input->readULong(4)); // child? |
| 733 |
if (shape.m_flags[1]&0x4) data.m_shapeIds[3]=unsigned(input->readULong(4)); // often simillar to shape1 ? |
| 734 |
if (shape.m_flags[1]&0x8) f << "g8=" << long(input->readULong(4)) << ","; // rotation? |
| 735 |
if (shape.m_flags[1]&0x10) f << "g10=" << long(input->readULong(4)) << ","; // ? |
| 736 |
// checkme: we need probably also test for f1&0x20 and f1&0x40 |
| 737 |
if (shape.m_flags[1]&0x80) f << "g80=" << long(input->readULong(4)) << ","; // ? |
| 738 |
if (shape.m_flags[1]&0x100) f << "link[id]=" << long(input->readULong(4)) << ","; // checkme: appear in v6 with id=3200 |
| 739 |
if (shape.m_flags[1]&0x4000) f << "Xobd" << long(input->readULong(4)) << ","; // appear in v6, related to object data base |
| 740 |
|
| 741 |
if (data.m_type) f << "type=" << Canvas5Structure::getString(data.m_type) << ","; |
| 742 |
f << data; |
| 743 |
|
| 744 |
long actPos=input->tell(); |
| 745 |
long endPos=actPos+len; |
| 746 |
if (endPos<actPos || endPos>entry.end()) { |
| 747 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: oops, bad length for shape id=%d\n", id)); |
| 748 |
f << "###"; |
| 749 |
ascFile.addPos(pos); |
| 750 |
ascFile.addNote(f.str().c_str()); |
| 751 |
return false; |
| 752 |
} |
| 753 |
|
| 754 |
if (len && shape.m_type!=2) |
| 755 |
ascFile.addDelimiter(input->tell(),'|'); |
| 756 |
|
| 757 |
input->pushLimit(entry.end()); |
| 758 |
|
| 759 |
data.m_stream=stream; |
| 760 |
data.m_streamReverted=input->readInverted(); |
| 761 |
data.m_entry.setBegin(input->tell()); |
| 762 |
data.m_entry.setLength(len); |
| 763 |
|
| 764 |
switch (shape.m_type) { |
| 765 |
case 2: // with type="TXT " or "TxtU" |
| 766 |
// will be parsed by sendText |
| 767 |
break; |
| 768 |
case 3: { |
| 769 |
if (len<(vers<9 ? 16 : 32)) { |
| 770 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: unexpected size for a line\n")); |
| 771 |
f << "###"; |
| 772 |
break; |
| 773 |
} |
| 774 |
f << "pts=["; |
| 775 |
for (int i=0; i<2; ++i) { |
| 776 |
float fDim[2]; |
| 777 |
for (auto &d : fDim) d=float(m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)); |
| 778 |
if (vers>=9) |
| 779 |
data.m_vertices.push_back(MWAWVec2f(fDim[0], fDim[1])); |
| 780 |
else |
| 781 |
data.m_vertices.push_back(MWAWVec2f(fDim[1], fDim[0])); |
| 782 |
f << data.m_vertices.back() << ","; |
| 783 |
} |
| 784 |
f << "];"; |
| 785 |
break; |
| 786 |
} |
| 787 |
case 4: // rect |
| 788 |
case 5: // rectOval |
| 789 |
case 6: // oval |
| 790 |
case 7: // arc |
| 791 |
if (vers>=9 && (shape.m_type==5 || shape.m_type==7) && len==16) { |
| 792 |
f << (shape.m_type==5 ? "round" : "angle") << "="; |
| 793 |
for (int i=0; i<2; ++i) { |
| 794 |
data.m_doubleValues[i]=m_mainParser->readDouble(*stream, 8); |
| 795 |
f << data.m_doubleValues[i] << (i==0 ? "x" : ","); |
| 796 |
} |
| 797 |
break; |
| 798 |
} |
| 799 |
if (len) { |
| 800 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: find unexpected length\n")); |
| 801 |
f << "###"; |
| 802 |
break; |
| 803 |
} |
| 804 |
if (shape.m_type==5) |
| 805 |
f << "round=" << float(data.m_local[0])/65536.f << "x" << float(data.m_local[1])/65536.f << ","; |
| 806 |
else if (shape.m_type==7) |
| 807 |
f << "angle=" << float(data.m_local[0])/65536.f << "->" << float(data.m_local[1])/65536.f << ","; |
| 808 |
break; |
| 809 |
case 9: // polyline |
| 810 |
case 10: { // spline |
| 811 |
if (len<8) { |
| 812 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: unexpected size for a polyline/spline\n")); |
| 813 |
f << "###"; |
| 814 |
break; |
| 815 |
} |
| 816 |
if (vers<9) |
| 817 |
input->seek(4, librevenge::RVNG_SEEK_CUR); |
| 818 |
int N=m_mainParser->readInteger(*stream, vers<9 ? 4 : 8); |
| 819 |
f << "N=" << N << ","; |
| 820 |
if (vers>=9) |
| 821 |
input->seek(8, librevenge::RVNG_SEEK_CUR); |
| 822 |
int const fieldSize=vers<9 ? 4 : 8; |
| 823 |
if (4+fieldSize+2*fieldSize*N<4+fieldSize || (len-4-fieldSize)/(2*fieldSize)<N || 4+fieldSize+2*fieldSize*N>len) { |
| 824 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData[polyline/spline]: can not read N\n")); |
| 825 |
f << "###"; |
| 826 |
break; |
| 827 |
} |
| 828 |
f << "pts=["; |
| 829 |
for (int i=0; i<N; ++i) { |
| 830 |
float fDim[2]; |
| 831 |
for (auto &d : fDim) d=float(m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)); |
| 832 |
if (vers<9) |
| 833 |
data.m_vertices.push_back(MWAWVec2f(fDim[1], fDim[0])); |
| 834 |
else |
| 835 |
data.m_vertices.push_back(MWAWVec2f(fDim[0], fDim[1])); |
| 836 |
f << data.m_vertices.back() << ","; |
| 837 |
} |
| 838 |
f << "],"; |
| 839 |
break; |
| 840 |
} |
| 841 |
case 52: { // special |
| 842 |
std::string extra; |
| 843 |
if (!readSpecialData(stream, len, data, extra)) |
| 844 |
f << "###"; |
| 845 |
f << extra; |
| 846 |
break; |
| 847 |
} |
| 848 |
case 20: // master elements ? |
| 849 |
case 99: { // group |
| 850 |
if (len<4) { |
| 851 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: unexpected size for a group\n")); |
| 852 |
f << "###"; |
| 853 |
break; |
| 854 |
} |
| 855 |
int N=int(input->readULong(4)); |
| 856 |
f << "N=" << N << ","; |
| 857 |
if (4+4*N<4 || 4+4*N>len) { |
| 858 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData[group]: can not read N\n")); |
| 859 |
f << "###"; |
| 860 |
break; |
| 861 |
} |
| 862 |
f << "id=["; |
| 863 |
for (int i=0; i<N; ++i) { |
| 864 |
data.m_children.push_back(unsigned(input->readULong(4))); |
| 865 |
f << "S" << data.m_children.back() << ","; |
| 866 |
} |
| 867 |
f << "],"; |
| 868 |
break; |
| 869 |
} |
| 870 |
default: |
| 871 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: unexpected type\n")); |
| 872 |
f << "###"; |
| 873 |
break; |
| 874 |
} |
| 875 |
ascFile.addPos(pos); |
| 876 |
ascFile.addNote(f.str().c_str()); |
| 877 |
|
| 878 |
if (len && input->tell()!=endPos) |
| 879 |
ascFile.addDelimiter(input->tell(),'|'); |
| 880 |
input->popLimit(); |
| 881 |
|
| 882 |
return true; |
| 883 |
} |
| 884 |
|
| 885 |
std::shared_ptr<Canvas5GraphInternal::PseudoShape> Canvas5Graph::readSpecialData(std::shared_ptr<Canvas5Structure::Stream> stream, long len, unsigned type, MWAWBox2f const &box, std::string &extra) |
| 886 |
{ |
| 887 |
if (!stream) |
| 888 |
return nullptr; |
| 889 |
auto input=stream->input(); |
| 890 |
|
| 891 |
auto res=std::make_shared<Canvas5GraphInternal::PseudoShape>(); |
| 892 |
Canvas5GraphInternal::ShapeData &data=res->m_data; |
| 893 |
data.m_inMainZone=false; |
| 894 |
data.m_type=type; |
| 895 |
|
| 896 |
data.m_stream=stream; |
| 897 |
data.m_streamReverted=input->readInverted(); |
| 898 |
data.m_entry.setBegin(input->tell()); |
| 899 |
data.m_entry.setLength(len); |
| 900 |
if (!readSpecialData(stream, len, data, extra)) |
| 901 |
return nullptr; |
| 902 |
auto &shape=res->m_shape; |
| 903 |
shape.m_type=52; |
| 904 |
shape.m_initialBox=shape.m_bdbox=box; |
| 905 |
return res; |
| 906 |
} |
| 907 |
|
| 908 |
bool Canvas5Graph::readSpecialData(std::shared_ptr<Canvas5Structure::Stream> stream, long len, Canvas5GraphInternal::ShapeData &data, std::string &extra) |
| 909 |
{ |
| 910 |
if (!stream) |
| 911 |
return false; |
| 912 |
auto input=stream->input(); |
| 913 |
int const vers=version(); |
| 914 |
libmwaw::DebugStream f; |
| 915 |
int val; |
| 916 |
switch (data.m_type) { |
| 917 |
case 0x43756265: // Cube |
| 918 |
if (len<(vers<9 ? 64 : 128)) { |
| 919 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: can not find the cube points\n")); |
| 920 |
return false; |
| 921 |
} |
| 922 |
for (int i=0; i<8; ++i) { // front face, back face |
| 923 |
float pts[2]; |
| 924 |
for (auto &c : pts) c=float(m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)); |
| 925 |
if (vers>=9) |
| 926 |
std::swap(pts[0],pts[1]); |
| 927 |
data.m_vertices.push_back(MWAWVec2f(pts[1],pts[0])); |
| 928 |
f << data.m_vertices.back() << ","; |
| 929 |
} |
| 930 |
break; |
| 931 |
case 0x43765465: // CvTe, will be read when we create the shape |
| 932 |
case 0x44494d4e: // DIMN, will be read when we create the shape |
| 933 |
break; |
| 934 |
case 0x4e474f4e: { // NGON |
| 935 |
if (len<(vers<9 ? 56 : 72)) { |
| 936 |
MWAW_DEBUG_MSG(("Canvas5Graph::readShapeData: can not find the NGON data\n")); |
| 937 |
return false; |
| 938 |
} |
| 939 |
val=int(input->readULong(2)); |
| 940 |
if (val&0x100) |
| 941 |
f << "smooth,"; |
| 942 |
val&=0xfeff; |
| 943 |
if (val) |
| 944 |
f << "fl=" << std::hex << val << std::hex << ","; |
| 945 |
if (vers<9) { |
| 946 |
for (int i=0; i<5; ++i) { |
| 947 |
val=int(input->readULong(2)); |
| 948 |
int const expected[]= {1,0x255, 0x6ae0, 0x2440, 0x1404 }; |
| 949 |
if (val!=expected[i]) f << "f" << i << "=" << val << ","; |
| 950 |
} |
| 951 |
for (int i=0; i<5; ++i) { |
| 952 |
val=int(input->readULong(4)); |
| 953 |
int const expected[]= {0x22e5140, 0x2232300, 0x2556af0, 0x23718c2, 0xec634 }; |
| 954 |
if (val!=expected[i]) f << "f" << i+6 << "=" << val << ","; |
| 955 |
} |
| 956 |
} |
| 957 |
else { |
| 958 |
for (int i=0; i<7; ++i) { |
| 959 |
val=int(input->readULong(2)); |
| 960 |
int const expected[]= {0x3884, 0xbfff, 0xdc80,0,0x20, 0xa000, 0xb430}; |
| 961 |
if (val!=expected[i]) f << "f" << i << "=" << val << ","; |
| 962 |
} |
| 963 |
for (int i=0; i<8; ++i) { |
| 964 |
val=int(input->readULong(2)); |
| 965 |
if (val) f << "f" << i+8 << "=" << val << ","; |
| 966 |
} |
| 967 |
} |
| 968 |
data.m_doubleValues[0]=m_mainParser->readDouble(*stream,vers<9 ? 4 : 8); |
| 969 |
f << "rad[min]=" << data.m_doubleValues[1] << ","; |
| 970 |
f << "angles=["; |
| 971 |
for (int i=0; i<2; ++i) { // 2 angles: pt0, min |
| 972 |
data.m_doubleValues[i+1]=m_mainParser->readDouble(*stream, vers<9 ? 4 : 8); |
| 973 |
f << data.m_doubleValues[i+1] << ","; |
| 974 |
} |
| 975 |
f << "],"; |
| 976 |
data.m_ngonType=int(input->readULong(4)); |
| 977 |
if (data.m_ngonType!=4) f << "type=" << data.m_ngonType << ","; |
| 978 |
data.m_specials[0]=int(input->readLong(2)); |
| 979 |
f << "N=" << data.m_specials[0] << ","; |
| 980 |
for (int i=0; i<(vers<9 ? 3 : 5); ++i) { |
| 981 |
val=int(input->readULong(2)); |
| 982 |
int const expected[]= {vers<9 ? 0x207 : 0x3830, 0, 0, 0, 0}; |
| 983 |
if (val!=expected[i]) f << "g" << i << "=" << val << ","; |
| 984 |
} |
| 985 |
break; |
| 986 |
} |
| 987 |
case 0x65666665: // effe: will be read by sendEffect |
| 988 |
case 0x45787472: // Extr: will be read by sendExtrude |
| 989 |
break; |
| 990 |
case 0x4772644d: { // GrdL |
| 991 |
if (len<4) { |
| 992 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a grid\n")); |
| 993 |
return false; |
| 994 |
} |
| 995 |
int subdiv[2]; |
| 996 |
for (auto &d : subdiv) d=int(input->readULong(2)); |
| 997 |
data.m_grid=MWAWVec2i(subdiv[0], subdiv[1]); |
| 998 |
f << "grid=" << data.m_grid << ","; |
| 999 |
break; |
| 1000 |
} |
| 1001 |
case 0x43436972: // CCir |
| 1002 |
case 0x53504952: { // SPIR |
| 1003 |
if (len<4) { |
| 1004 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a ccircle/spiral\n")); |
| 1005 |
return false; |
| 1006 |
} |
| 1007 |
for (int i=0; i<2; ++i) data.m_specials[i]=int(input->readLong(2)); |
| 1008 |
f << "N=" << data.m_specials[0] << ","; |
| 1009 |
if (data.m_specials[1]) f << "space[between]=" << data.m_specials[1] << ","; // 0: equidistant (only used by CCir) |
| 1010 |
break; |
| 1011 |
} |
| 1012 |
case 0x4d41434f: { // MACO: object from macros, never sent ? |
| 1013 |
if (len<(vers<9 ? 92 : 128)) { |
| 1014 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[MACO]: unexpected size\n")); |
| 1015 |
return false; |
| 1016 |
} |
| 1017 |
val=int(input->readLong(4)); |
| 1018 |
if (val!=2) |
| 1019 |
f << "f0=" << val << ","; |
| 1020 |
if (vers>=9) |
| 1021 |
input->seek(4, librevenge::RVNG_SEEK_CUR); |
| 1022 |
float dim[4]; |
| 1023 |
for (auto &d : dim) d=float(m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)); |
| 1024 |
if (vers<9) |
| 1025 |
f << "box=" << MWAWBox2f(MWAWVec2f(dim[1],dim[0]),MWAWVec2f(dim[3],dim[2])) << ","; |
| 1026 |
else |
| 1027 |
f << "box=" << MWAWBox2f(MWAWVec2f(dim[0],dim[1]),MWAWVec2f(dim[2],dim[3])) << ","; |
| 1028 |
for (int i=0; i<(vers<9 ? 13 : 17); ++i) { // f5=0|1 |
| 1029 |
val=int(input->readLong(4)); |
| 1030 |
if (val) |
| 1031 |
f << "f" << i+1 << "=" << val << ","; |
| 1032 |
} |
| 1033 |
|
| 1034 |
std::string sMaco; |
| 1035 |
m_imageParser->readMacroIndent(*stream, data.m_macoId, sMaco); |
| 1036 |
f << "id=[" << sMaco << "],"; |
| 1037 |
break; |
| 1038 |
} |
| 1039 |
case 0x4f4c6e6b : { // OLnk |
| 1040 |
if (len<56) { |
| 1041 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a link\n")); |
| 1042 |
return false; |
| 1043 |
} |
| 1044 |
f << "pts=["; |
| 1045 |
for (int i=0; i<4; ++i) { |
| 1046 |
float fDim[2]; |
| 1047 |
for (auto &d : fDim) d=float(input->readLong(4))/65536.f; |
| 1048 |
data.m_vertices.push_back(MWAWVec2f(fDim[1], fDim[0])); |
| 1049 |
f << data.m_vertices.back() << ","; |
| 1050 |
} |
| 1051 |
f << "],"; |
| 1052 |
for (int i=0; i<3; ++i) { // f0=small number, f1=0|5 |
| 1053 |
val=int(input->readLong(4)); |
| 1054 |
if (val) |
| 1055 |
f << "f" << i << "=" << val << ","; |
| 1056 |
} |
| 1057 |
val=int(input->readLong(2)); // find 4,5,7 |
| 1058 |
if (val) f << "f3=" << val << ","; |
| 1059 |
break; |
| 1060 |
} |
| 1061 |
case 0x706f626a: // pobj |
| 1062 |
if (len<8) { |
| 1063 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a pobj\n")); |
| 1064 |
return false; |
| 1065 |
} |
| 1066 |
for (int i=0; i<2; ++i) |
| 1067 |
data.m_specials[i]=int(input->readULong(4)); |
| 1068 |
if (data.m_specials[0]) |
| 1069 |
f << "B" << data.m_specials[1] << ":" << data.m_specials[0] << ","; |
| 1070 |
else |
| 1071 |
f << "B" << data.m_specials[1] << ","; |
| 1072 |
break; |
| 1073 |
case 0x54585420: // TEXT, only in Vkfl, will be read when we create the shape |
| 1074 |
if (data.m_inMainZone) { |
| 1075 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected text in main zone\n")); |
| 1076 |
return false; |
| 1077 |
} |
| 1078 |
break; |
| 1079 |
case 0x41474946: // AGIF: appear in v6 |
| 1080 |
if (len<12) { |
| 1081 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a AGIF\n")); |
| 1082 |
return false; |
| 1083 |
} |
| 1084 |
for (int i=0; i<3; ++i) |
| 1085 |
data.m_specials[i]=int(input->readULong(4)); |
| 1086 |
if (data.m_specials[0]!=1) |
| 1087 |
f << "AG" << data.m_specials[1] << ":" << data.m_specials[0]; |
| 1088 |
else |
| 1089 |
f << "AG" << data.m_specials[1]; |
| 1090 |
if (data.m_specials[2]!=1) |
| 1091 |
f << "[" << data.m_specials[2] << "]"; |
| 1092 |
f << ","; |
| 1093 |
break; |
| 1094 |
case 0x43574542: { // CWEB: a button with 3 potential shapes (and sound) |
| 1095 |
// checkme: find 8 times in two files, but with the same content... |
| 1096 |
// this zone is clearly related with RsrcWEBE (unparsed) |
| 1097 |
if (len<40) { |
| 1098 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[CWEB]: unexpected size\n")); |
| 1099 |
return false; |
| 1100 |
} |
| 1101 |
long pos=input->tell(); |
| 1102 |
for (int i=0; i<2; ++i) { |
| 1103 |
val=int(input->readLong(4)); |
| 1104 |
int const expected[]= {0x1261998, 1}; |
| 1105 |
if (val!=expected[i]) |
| 1106 |
f << "f" << i << "=" << val << ","; |
| 1107 |
} |
| 1108 |
f << "lengths=["; |
| 1109 |
std::vector<long> lengths; |
| 1110 |
for (int i=0; i<8; ++i) { // 0-2: image, 3-5: sound, 6-7: unsure ??? |
| 1111 |
long len1=long(input->readLong(4)); |
| 1112 |
if (!len1 && i>=5) break; |
| 1113 |
lengths.push_back(len1); |
| 1114 |
f << std::hex << len1 << std::dec << ","; |
| 1115 |
} |
| 1116 |
f << "],"; |
| 1117 |
input->seek(pos+40, librevenge::RVNG_SEEK_SET); |
| 1118 |
|
| 1119 |
libmwaw::DebugFile &ascFile = stream->ascii(); |
| 1120 |
long endPos=pos+len; |
| 1121 |
for (size_t i=0; i<6; ++i) { |
| 1122 |
if (i>=lengths.size()) |
| 1123 |
break; |
| 1124 |
long l=lengths[i]; |
| 1125 |
if (l==0) continue; |
| 1126 |
pos=input->tell(); |
| 1127 |
if (l < 0 || (long)((unsigned long)pos+(unsigned long)l)<pos || pos+l>endPos) { |
| 1128 |
extra=f.str(); |
| 1129 |
ascFile.addPos(input->tell()); |
| 1130 |
ascFile.addNote("DataShap[CWEB]:###"); |
| 1131 |
return false; |
| 1132 |
} |
| 1133 |
if (i<3) { // image |
| 1134 |
data.m_cweb[i].setBegin(pos); |
| 1135 |
data.m_cweb[i].setLength(l); |
| 1136 |
} |
| 1137 |
else { |
| 1138 |
// look like a basic snd file: see https://en.wikipedia.org/wiki/Au_file_format |
| 1139 |
ascFile.addPos(pos); |
| 1140 |
ascFile.addNote("DataShap[CWEB,snd]:##"); |
| 1141 |
} |
| 1142 |
input->seek(pos+l, librevenge::RVNG_SEEK_SET); |
| 1143 |
} |
| 1144 |
if (input->tell()!=endPos) { |
| 1145 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[CWEB]: find extra data\n")); |
| 1146 |
ascFile.addPos(input->tell()); |
| 1147 |
ascFile.addNote("DataShap:special,CWEB:###"); |
| 1148 |
} |
| 1149 |
break; |
| 1150 |
} |
| 1151 |
case 0x516b546d: // QkTm: appear in v6 |
| 1152 |
if (len!=4) { |
| 1153 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a QkTm\n")); |
| 1154 |
return false; |
| 1155 |
} |
| 1156 |
data.m_specials[0]=int(input->readULong(4)); |
| 1157 |
f << "QK" << data.m_specials[0] << ","; |
| 1158 |
break; |
| 1159 |
case 0x23476465: { // #Gde: text with column and section, appear in v6 |
| 1160 |
if (len<28) { |
| 1161 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[#Gde]: unexpected size\n")); |
| 1162 |
return false; |
| 1163 |
} |
| 1164 |
auto fl=input->readULong(4); |
| 1165 |
if (fl!=0x1771) f << "fl=" << std::hex << fl << std::dec << ","; |
| 1166 |
data.m_gdeType=int(input->readULong(4)); |
| 1167 |
if (data.m_gdeType<=0 || data.m_gdeType>=4 || (data.m_gdeType==1 && len!=(vers<9 ? 52: 60))) { |
| 1168 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[#Gde]: unexpected type0\n")); |
| 1169 |
f << "###type0=" << data.m_gdeType << "," << len << ","; |
| 1170 |
extra=f.str(); |
| 1171 |
return false; |
| 1172 |
} |
| 1173 |
char const *wh[]= {"type1","type2","section/column"}; |
| 1174 |
f << wh[data.m_gdeType-1] << ","; |
| 1175 |
switch (data.m_gdeType) { |
| 1176 |
case 0: { |
| 1177 |
float dims[2]; |
| 1178 |
for (auto &d : dims) d=float(m_mainParser->readDouble(*stream, 4)); |
| 1179 |
f << "dim=" << MWAWVec2f(dims[0], dims[1]) << ","; // 36x36 or 50x50 |
| 1180 |
for (auto &d : dims) d=float(m_mainParser->readDouble(*stream, 4)); |
| 1181 |
f << "unk=" << MWAWVec2f(dims[0], dims[1]) << ","; // 0.25x0.25.. |
| 1182 |
f << "unk1=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1183 |
break; |
| 1184 |
} |
| 1185 |
case 1: { |
| 1186 |
for (int i=0; i<3; ++i) { // f0=0|1, f1=f2=0|1 |
| 1187 |
val=int(input->readULong(4)); |
| 1188 |
int const expected[]= {0, 1, 1}; |
| 1189 |
if (val!=expected[i]) f << "f" << i << "=" << val << ","; |
| 1190 |
} |
| 1191 |
if (vers>=9) |
| 1192 |
input->seek(4, librevenge::RVNG_SEEK_CUR); |
| 1193 |
|
| 1194 |
float dims[2]; |
| 1195 |
for (auto &d : dims) d=float(m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)); |
| 1196 |
f << "dim=" << MWAWVec2f(dims[1], dims[0]) << ","; // 36x36 or 50x50 |
| 1197 |
if (vers<9) |
| 1198 |
f << "unk0=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1199 |
for (auto &d : dims) d=float(m_mainParser->readDouble(*stream, 8)); |
| 1200 |
f << "unk=" << MWAWVec2f(dims[0], dims[1]) << ","; // 0.25, 0.25 or 1x1 except when unkn0=0 |
| 1201 |
f << "unk1=" << std::hex << input->readULong(4) << std::dec << ","; |
| 1202 |
break; |
| 1203 |
} |
| 1204 |
case 2: { |
| 1205 |
val=int(input->readULong(4)); // 0|1 |
| 1206 |
if (val) f << "f0=" << val << ","; |
| 1207 |
int N=int(input->readULong(4)); |
| 1208 |
f << "N=" << N << ","; |
| 1209 |
unsigned const headerSz=vers<9 ? 28 : 36; |
| 1210 |
unsigned const dataSz=vers<9 ? 8 : 16; |
| 1211 |
if (N<0 || int((len-headerSz)/dataSz)<N || len!=long(dataSz*unsigned(N)+headerSz)) { |
| 1212 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[#Gde]: can not read the N value\n")); |
| 1213 |
f << "###"; |
| 1214 |
extra=f.str(); |
| 1215 |
return false; |
| 1216 |
} |
| 1217 |
f << "unk=["; |
| 1218 |
for (int i=0; i<N; ++i) { |
| 1219 |
val=int(input->readLong(4)); // 1|2 |
| 1220 |
if (vers>=9) |
| 1221 |
input->seek(4, librevenge::RVNG_SEEK_CUR); |
| 1222 |
f << m_mainParser->readDouble(*stream, vers<9 ? 4 : 8) << ":" << val << ","; |
| 1223 |
} |
| 1224 |
f << "],"; |
| 1225 |
f << "unk1=["; |
| 1226 |
for (int i=0; i<(vers<9 ? 3 : 5); ++i) |
| 1227 |
f << float(input->readLong(4))/65536 << ","; |
| 1228 |
f << "],"; |
| 1229 |
break; |
| 1230 |
} |
| 1231 |
case 3: |
| 1232 |
default: { |
| 1233 |
int N=int(input->readLong(4)); |
| 1234 |
f << "N=" << N << ","; |
| 1235 |
int const dataSz=vers<9 ? 100 : 120; |
| 1236 |
if (N<0 || (len-28)/dataSz<N) { |
| 1237 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[#Gde]: can not read the N value\n")); |
| 1238 |
f << "###"; |
| 1239 |
extra=f.str(); |
| 1240 |
return false; |
| 1241 |
} |
| 1242 |
libmwaw::DebugStream f2; |
| 1243 |
libmwaw::DebugFile &ascFile = stream->ascii(); |
| 1244 |
for (int i=0; i<N; ++i) { |
| 1245 |
long pos=input->tell(); |
| 1246 |
f2.str(""); |
| 1247 |
f2 << "DataShap[#Gde-S" << i << ":]"; |
| 1248 |
Canvas5GraphInternal::SectionData section; |
| 1249 |
for (int j=0; j<4; ++j) { |
| 1250 |
val=int(input->readLong(4)); |
| 1251 |
if (val) |
| 1252 |
f2 << "f" << j << "=" << val << ","; |
| 1253 |
} |
| 1254 |
float dim[4]; |
| 1255 |
for (auto &d : dim) d=float(m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)); |
| 1256 |
if (vers<9) |
| 1257 |
section.m_bdBox=MWAWBox2f(MWAWVec2f(dim[1],dim[0]),MWAWVec2f(dim[3],dim[2])); |
| 1258 |
else |
| 1259 |
section.m_bdBox=MWAWBox2f(MWAWVec2f(dim[0],dim[1]),MWAWVec2f(dim[2],dim[3])); |
| 1260 |
f2 << "box=" << section.m_bdBox << ","; |
| 1261 |
if (vers>=9) { |
| 1262 |
f2 << "unkn=" << m_mainParser->readDouble(*stream, 8) << ","; // 2 |
| 1263 |
val=int(input->readLong(4)); |
| 1264 |
if (val) |
| 1265 |
f2 << "f2=" << val << ","; |
| 1266 |
} |
| 1267 |
long actPos=input->tell(); |
| 1268 |
std::string name; |
| 1269 |
for (int j=0; j<28; ++j) { // checkme what is the bigger length |
| 1270 |
char c=char(input->readULong(1)); |
| 1271 |
if (!c) |
| 1272 |
break; |
| 1273 |
name+=c; |
| 1274 |
} |
| 1275 |
f2 << name << ","; |
| 1276 |
input->seek(actPos+28, librevenge::RVNG_SEEK_SET); |
| 1277 |
for (int j=0; j<(vers<9 ? 7 : 6); ++j) { // f11=0|1 |
| 1278 |
val=int(input->readLong(4)); |
| 1279 |
if (val==(j<3 ? 1 : 0)) continue; |
| 1280 |
if (j==0) |
| 1281 |
f2 << "writing[mode]=" << val << ","; // 2: means first rigth columns then toward left |
| 1282 |
else |
| 1283 |
f2 << "f" << j+5 << "=" << val << ","; |
| 1284 |
} |
| 1285 |
if (vers<9) { |
| 1286 |
val=int(input->readLong(4)); |
| 1287 |
if (val!=0x20000) |
| 1288 |
f2 << "g0=" << float(val)/65536; |
| 1289 |
} |
| 1290 |
section.m_numColumns=int(input->readLong(4)); |
| 1291 |
f2 << "num[columns]=" << section.m_numColumns << ","; |
| 1292 |
f2 << "id=" << input->readLong(4) << ","; |
| 1293 |
data.m_sections.push_back(section); |
| 1294 |
|
| 1295 |
ascFile.addPos(pos); |
| 1296 |
ascFile.addNote(f2.str().c_str()); |
| 1297 |
input->seek(pos+dataSz, librevenge::RVNG_SEEK_SET); |
| 1298 |
} |
| 1299 |
|
| 1300 |
long pos=input->tell(); |
| 1301 |
f2.str(""); |
| 1302 |
f2 << "DataShap[#Gde-columns]:"; |
| 1303 |
if (vers<9) { |
| 1304 |
float dim[2]; |
| 1305 |
for (auto &d : dim) d=float(input->readLong(4))/65536; |
| 1306 |
f2 << "orig=" << MWAWVec2f(dim[1],dim[0]) << ","; |
| 1307 |
} |
| 1308 |
else |
| 1309 |
input->seek(8, librevenge::RVNG_SEEK_CUR); |
| 1310 |
int N0=int(input->readLong(4)); |
| 1311 |
f2 << "num[columns]=" << N0 << ","; |
| 1312 |
int const data1Sz=vers<9 ? 8 : 16; |
| 1313 |
if (N0<0 || 28+dataSz*N+data1Sz*N0<len || (len-dataSz*N-28)/data1Sz<N0) { |
| 1314 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData[#Gde]: can not read the N0 value\n")); |
| 1315 |
f2 << "###"; |
| 1316 |
ascFile.addPos(pos); |
| 1317 |
ascFile.addNote(f2.str().c_str()); |
| 1318 |
extra=f.str(); |
| 1319 |
return false; |
| 1320 |
} |
| 1321 |
f2 << "pos=["; |
| 1322 |
for (int i=0; i<=2*N0; ++i) |
| 1323 |
f2 << m_mainParser->readDouble(*stream, vers<9 ? 4 : 8) << ","; |
| 1324 |
f2 << "],"; |
| 1325 |
ascFile.addPos(pos); |
| 1326 |
ascFile.addNote(f2.str().c_str()); |
| 1327 |
break; |
| 1328 |
} |
| 1329 |
} |
| 1330 |
break; |
| 1331 |
} |
| 1332 |
case 0x416e4766: // AnGf: appear in v7, will be parsed when we send data |
| 1333 |
break; |
| 1334 |
case 0x70636567: // pceg: appear in v7 |
| 1335 |
if (len<8) { |
| 1336 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a pceg\n")); |
| 1337 |
return false; |
| 1338 |
} |
| 1339 |
val=int(input->readULong(4)); |
| 1340 |
if (val!=0x3251999) |
| 1341 |
f << "f0=" << std::hex << val << std::dec << ","; |
| 1342 |
data.m_specials[1]=int(input->readULong(4)); |
| 1343 |
f << "PC" << data.m_specials[1] << ","; |
| 1344 |
break; |
| 1345 |
case 0x54656368: // Tech: appear in v7, will be parsed when we send data |
| 1346 |
break; |
| 1347 |
|
| 1348 |
case 0x72656750: // regP: registration mark, appear in v8 |
| 1349 |
if (len<16) { |
| 1350 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected size for a regP\n")); |
| 1351 |
return false; |
| 1352 |
} |
| 1353 |
for (int i=0; i<4; ++i) { |
| 1354 |
val=int(input->readLong(4)); |
| 1355 |
int const expected[]= {0x7df, 0x700, 1, 1}; |
| 1356 |
if (val!=expected[i]) |
| 1357 |
f << "f" << i << "=" << val << ","; |
| 1358 |
} |
| 1359 |
break; |
| 1360 |
default: |
| 1361 |
MWAW_DEBUG_MSG(("Canvas5Graph::readSpecialData: unexpected special %s\n", Canvas5Structure::getString(data.m_type).c_str())); |
| 1362 |
return false; |
| 1363 |
} |
| 1364 |
extra=f.str(); |
| 1365 |
return true; |
| 1366 |
} |
| 1367 |
|
| 1368 |
//////////////////////////////////////////////////////////// |
| 1369 |
|
| 1370 |
bool Canvas5Graph::readDeR3(std::shared_ptr<Canvas5Structure::Stream> stream, Canvas5StyleManager::StyleList &styles) |
| 1371 |
{ |
| 1372 |
if (!stream || !stream->input()) |
| 1373 |
return false; |
| 1374 |
auto input=stream->input(); |
| 1375 |
long pos=input->tell(); |
| 1376 |
int const vers=version(); |
| 1377 |
int const headerSize=vers<9 ? 124 : 160; |
| 1378 |
if (!input->checkPosition(pos+headerSize)) { |
| 1379 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3: the zone is too short 1\n")); |
| 1380 |
return false; |
| 1381 |
} |
| 1382 |
libmwaw::DebugFile &ascFile = stream->ascii(); |
| 1383 |
libmwaw::DebugStream f; |
| 1384 |
int val; |
| 1385 |
f << "Entries(DeR3):"; |
| 1386 |
for (int i=0; i<2; ++i) { |
| 1387 |
val=int(input->readLong(2)); |
| 1388 |
if (val!=(i==0 ? 2 : 0)) |
| 1389 |
f << "f" << i << "=" << val << ","; |
| 1390 |
} |
| 1391 |
unsigned name=unsigned(input->readULong(4)); |
| 1392 |
if (name!=0x44655233) { // "DeR3" |
| 1393 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3: unexcepted header\n")); |
| 1394 |
return false; |
| 1395 |
} |
| 1396 |
int nLines=0; |
| 1397 |
for (int i=0; i<4; ++i) { |
| 1398 |
val=int(input->readULong(2)); |
| 1399 |
if (val==0) continue; |
| 1400 |
if (i==2) { |
| 1401 |
nLines=val; |
| 1402 |
f << "n[lines]=" << val << ","; |
| 1403 |
} |
| 1404 |
else |
| 1405 |
f << "f" << i+2 << "=" << val << ","; |
| 1406 |
} |
| 1407 |
unsigned long lengths[7], totalLength=0; |
| 1408 |
f << "len=["; |
| 1409 |
for (auto &l : lengths) { |
| 1410 |
l=input->readULong(4); |
| 1411 |
if (totalLength+l<totalLength) { |
| 1412 |
f << "###"; |
| 1413 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3: bad lengths\n")); |
| 1414 |
ascFile.addPos(pos); |
| 1415 |
ascFile.addNote(f.str().c_str()); |
| 1416 |
return false; |
| 1417 |
} |
| 1418 |
totalLength+=l; |
| 1419 |
if (l) |
| 1420 |
f << l << ","; |
| 1421 |
else |
| 1422 |
f << "_,"; |
| 1423 |
if (long(l)<0) { |
| 1424 |
f << "###"; |
| 1425 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3: a length is bad\n")); |
| 1426 |
ascFile.addPos(pos); |
| 1427 |
ascFile.addNote(f.str().c_str()); |
| 1428 |
return false; |
| 1429 |
} |
| 1430 |
} |
| 1431 |
f << "],"; |
| 1432 |
for (int i=0; i<(vers<9 ? 2 : 6); ++i) { // g0=0|12 |
| 1433 |
val=int(input->readLong(2)); |
| 1434 |
if (val) f << "g" << i << "=" << val << ","; |
| 1435 |
} |
| 1436 |
for (int i=0; i<2; ++i) { // dim0~=1 or dim2=0-100 |
| 1437 |
double dVal=m_mainParser->readDouble(*stream, vers<9 ? 4 : 8); |
| 1438 |
if (dVal<1 || dVal>1) |
| 1439 |
f << "dim" << i << "=" << dVal << ","; |
| 1440 |
} |
| 1441 |
int nIntervs=int(input->readLong(4)); |
| 1442 |
if (nIntervs) f << "n[interv]=" << nIntervs << ","; |
| 1443 |
if (nIntervs<0 || (int(lengths[3])<nIntervs*12)) { |
| 1444 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3: bad number of tabulations\n")); |
| 1445 |
f << "###"; |
| 1446 |
nIntervs=0; |
| 1447 |
} |
| 1448 |
val=int(input->readLong(4)); |
| 1449 |
if (val!=10) f << "g2=" << val << ","; |
| 1450 |
for (int i=0; i<30; ++i) { // g2=1-6, g3=-1, g28=0-466 |
| 1451 |
val=int(input->readLong(2)); |
| 1452 |
if (val) f << "g" << i+3 << "=" << val << ","; |
| 1453 |
} |
| 1454 |
int const widthSize=vers<9 ? 4 : 8; |
| 1455 |
int const tabSize=vers<9 ? 12 : 24; |
| 1456 |
if (pos+headerSize+long(totalLength)<pos+headerSize || !input->checkPosition(pos+headerSize+long(totalLength)) || |
| 1457 |
int(lengths[0])<4*(nLines+1) || int(lengths[1])<2*(nLines+1) || int(lengths[2])<widthSize*nLines || |
| 1458 |
(lengths[3]%12)!=0 || (int(lengths[4])%tabSize)!=0) { |
| 1459 |
f << "###"; |
| 1460 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3: bad lengths\n")); |
| 1461 |
ascFile.addPos(pos); |
| 1462 |
ascFile.addNote(f.str().c_str()); |
| 1463 |
return false; |
| 1464 |
} |
| 1465 |
ascFile.addPos(pos); |
| 1466 |
ascFile.addNote(f.str().c_str()); |
| 1467 |
input->seek(pos+headerSize, librevenge::RVNG_SEEK_SET); |
| 1468 |
|
| 1469 |
if (lengths[0]) { |
| 1470 |
pos=input->tell(); |
| 1471 |
f.str(""); |
| 1472 |
f << "DeR3-line:numChar=["; |
| 1473 |
for (int i=0; i<=nLines; ++i) f << input->readULong(4) << ","; |
| 1474 |
f << "],"; |
| 1475 |
ascFile.addPos(pos); |
| 1476 |
ascFile.addNote(f.str().c_str()); |
| 1477 |
input->seek(pos+long(lengths[0]), librevenge::RVNG_SEEK_SET); |
| 1478 |
} |
| 1479 |
|
| 1480 |
if (lengths[1]) { |
| 1481 |
pos=input->tell(); |
| 1482 |
f.str(""); |
| 1483 |
f << "DeR3-flags:fl=["; |
| 1484 |
for (int i=0; i<=nLines; ++i) f << std::hex << input->readULong(2) << std::dec << ","; |
| 1485 |
f << "],"; |
| 1486 |
ascFile.addPos(pos); |
| 1487 |
ascFile.addNote(f.str().c_str()); |
| 1488 |
input->seek(pos+long(lengths[1]), librevenge::RVNG_SEEK_SET); |
| 1489 |
} |
| 1490 |
|
| 1491 |
if (lengths[2]) { |
| 1492 |
pos=input->tell(); |
| 1493 |
f.str(""); |
| 1494 |
f << "DeR3-widths:w=["; |
| 1495 |
for (int i=0; i<nLines; ++i) f << m_mainParser->readDouble(*stream, vers<9 ? 4 : 8) << ","; |
| 1496 |
f << "],"; |
| 1497 |
ascFile.addPos(pos); |
| 1498 |
ascFile.addNote(f.str().c_str()); |
| 1499 |
input->seek(pos+long(lengths[2]), librevenge::RVNG_SEEK_SET); |
| 1500 |
} |
| 1501 |
|
| 1502 |
long endPos=input->tell()+long(lengths[3]); |
| 1503 |
for (int i=0; i<int(lengths[3]/12); ++i) { |
| 1504 |
if (i>=nIntervs) |
| 1505 |
break; |
| 1506 |
pos=input->tell(); |
| 1507 |
f.str(""); |
| 1508 |
f << "DeR3-int" << i << ":"; |
| 1509 |
f << "len=" << float(input->readLong(4))/65536.f << ","; |
| 1510 |
f << "type=" << input->readLong(2) << ","; |
| 1511 |
val=int(input->readLong(2)); |
| 1512 |
if (val) f << "f1=" << val << ","; |
| 1513 |
f << "pos=" << float(input->readLong(4))/65536.f << ","; |
| 1514 |
ascFile.addPos(pos); |
| 1515 |
ascFile.addNote(f.str().c_str()); |
| 1516 |
input->seek(pos+12, librevenge::RVNG_SEEK_SET); |
| 1517 |
} |
| 1518 |
if (input->tell()!=endPos) { |
| 1519 |
ascFile.addPos(input->tell()); |
| 1520 |
ascFile.addNote("_"); |
| 1521 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1522 |
} |
| 1523 |
|
| 1524 |
for (int i=0; i<int(lengths[4])/tabSize; ++i) { |
| 1525 |
pos=input->tell(); |
| 1526 |
f.str(""); |
| 1527 |
f << "DeR3-tab" << i << ":"; |
| 1528 |
f << "pos=" << m_mainParser->readDouble(*stream, vers<9 ? 4: 8) << ","; |
| 1529 |
f << "type=" << input->readLong(2) << ","; |
| 1530 |
for (int j=0; j<(vers<9 ? 3 : 7); ++j) { |
| 1531 |
val=int(input->readLong(2)); |
| 1532 |
if (val) f << "f" << j << "=" << val << ","; |
| 1533 |
} |
| 1534 |
ascFile.addPos(pos); |
| 1535 |
ascFile.addNote(f.str().c_str()); |
| 1536 |
input->seek(pos+tabSize, librevenge::RVNG_SEEK_SET); |
| 1537 |
} |
| 1538 |
|
| 1539 |
if (lengths[5]) { |
| 1540 |
pos=input->tell(); |
| 1541 |
f.str(""); |
| 1542 |
f<< "DeR3-A"; |
| 1543 |
ascFile.addPos(pos); |
| 1544 |
ascFile.addNote(f.str().c_str()); |
| 1545 |
input->seek(pos+long(lengths[5]), librevenge::RVNG_SEEK_SET); |
| 1546 |
} |
| 1547 |
|
| 1548 |
if (!lengths[6]) return true; |
| 1549 |
|
| 1550 |
pos=input->tell(); |
| 1551 |
endPos=pos+long(lengths[6]); |
| 1552 |
f.str(""); |
| 1553 |
f<< "Entries(ParaStyl),DeR3-style:"; |
| 1554 |
|
| 1555 |
int N[2]; |
| 1556 |
f << "N=["; |
| 1557 |
for (auto &n : N) { |
| 1558 |
n=int(input->readULong(4)); |
| 1559 |
f << n << ","; |
| 1560 |
} |
| 1561 |
f << "],"; |
| 1562 |
f << "len=" << input->readULong(4) << ","; |
| 1563 |
f << "max[tabs,sz]=" << int(input->readULong(4)) << ","; |
| 1564 |
int styleSize=vers<9 ? 128 : 224; |
| 1565 |
if (lengths[6]<40 || N[0]<0 || N[1]<0 || int(lengths[6]-40)/styleSize<N[0] || |
| 1566 |
long(N[0])*styleSize+40<40 || long(N[0])*styleSize+40>long(lengths[6])) { |
| 1567 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3[G]: bad N\n")); |
| 1568 |
f << "###"; |
| 1569 |
ascFile.addPos(pos); |
| 1570 |
ascFile.addNote(f.str().c_str()); |
| 1571 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1572 |
return true; |
| 1573 |
} |
| 1574 |
ascFile.addPos(pos); |
| 1575 |
ascFile.addNote(f.str().c_str()); |
| 1576 |
|
| 1577 |
input->seek(pos+(vers<9 ? 28 : 32), librevenge::RVNG_SEEK_SET); |
| 1578 |
styles.m_paragraphs.resize(size_t(N[0])); |
| 1579 |
for (int i=0; i<N[0]; ++i) { |
| 1580 |
pos=input->tell(); |
| 1581 |
f.str(""); |
| 1582 |
f<< "ParaStyl-E" << i+1 << ":"; |
| 1583 |
ascFile.addPos(pos); |
| 1584 |
ascFile.addNote(f.str().c_str()); |
| 1585 |
m_styleManager->readParaStyle(stream, i+1, &styles); |
| 1586 |
input->seek(pos+styleSize, librevenge::RVNG_SEEK_SET); |
| 1587 |
} |
| 1588 |
|
| 1589 |
for (int t=0; t<N[1]; ++t) { |
| 1590 |
pos=input->tell(); |
| 1591 |
f.str(""); |
| 1592 |
f << "DeR3-Tab" << t+1 << ":"; |
| 1593 |
val=int(input->readULong(4)); |
| 1594 |
if (val!=1) |
| 1595 |
f << "used=" << val << ","; |
| 1596 |
int len=int(input->readULong(4)); |
| 1597 |
if (len<0 || pos+16+len > endPos) { |
| 1598 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3[G]: bad tab size\n")); |
| 1599 |
f << "###"; |
| 1600 |
ascFile.addPos(pos); |
| 1601 |
ascFile.addNote(f.str().c_str()); |
| 1602 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1603 |
return true; |
| 1604 |
} |
| 1605 |
for (int i=0; i<4; ++i) { // 0 |
| 1606 |
val=int(input->readLong(2)); |
| 1607 |
if (val) f << "f" << i << "=" << val << ","; |
| 1608 |
} |
| 1609 |
double dVal=m_mainParser->readDouble(*stream, vers<9 ? 4 : 8); |
| 1610 |
if (dVal<36 || dVal>36) |
| 1611 |
f << "dim?=" << dVal << ","; |
| 1612 |
int n=int(input->readULong(2)); |
| 1613 |
if (n) f << "N=" << n << ","; |
| 1614 |
if (n<0 || len < (vers<9 ? 0 : 24) + tabSize*n) { |
| 1615 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3[G]: the num of tab seems bad\n")); |
| 1616 |
f << "###"; |
| 1617 |
n=0; |
| 1618 |
} |
| 1619 |
for (int i=0; i<(vers<9 ? 3 : 7); ++i) { // 0 |
| 1620 |
val=int(input->readLong(2)); |
| 1621 |
if (val) f << "f" << i+4 << "=" << val << ","; |
| 1622 |
} |
| 1623 |
f << "tabs=["; |
| 1624 |
std::vector<MWAWTabStop> tabs; |
| 1625 |
tabs.resize(size_t(n)); |
| 1626 |
for (size_t i=0; i<size_t(n); ++i) { |
| 1627 |
MWAWTabStop &tab=tabs[i]; |
| 1628 |
tab.m_position=m_mainParser->readDouble(*stream, vers<9 ? 4 : 8)/72; |
| 1629 |
int type=int(input->readULong(2)); |
| 1630 |
switch (type) { |
| 1631 |
case 0: // left |
| 1632 |
break; |
| 1633 |
case 1: |
| 1634 |
tab.m_alignment=MWAWTabStop::CENTER; |
| 1635 |
break; |
| 1636 |
case 2: |
| 1637 |
tab.m_alignment=MWAWTabStop::RIGHT; |
| 1638 |
break; |
| 1639 |
case 3: |
| 1640 |
tab.m_alignment=MWAWTabStop::DECIMAL; |
| 1641 |
tab.m_decimalCharacter=','; |
| 1642 |
break; |
| 1643 |
case 4: |
| 1644 |
tab.m_alignment=MWAWTabStop::DECIMAL; |
| 1645 |
tab.m_decimalCharacter='\''; |
| 1646 |
break; |
| 1647 |
default: |
| 1648 |
MWAW_DEBUG_MSG(("Canvas5Graph::readDeR3[G]: unknown tab type\n")); |
| 1649 |
f << "###type=" << val << ","; |
| 1650 |
break; |
| 1651 |
} |
| 1652 |
f << tab; |
| 1653 |
for (int j=0; j<(vers<9 ? 3 : 7); ++j) { // v9: f2 is probably related to leader char but 0x30 mean 'a' ? |
| 1654 |
val=int(input->readLong(2)); |
| 1655 |
if (val) f << ":f" << j << "=" << val << ","; |
| 1656 |
} |
| 1657 |
f << ","; |
| 1658 |
} |
| 1659 |
f << "],"; |
| 1660 |
if (!tabs.empty()) { |
| 1661 |
for (auto ¶Id : styles.m_paragraphs) { |
| 1662 |
if (paraId.second==t+1) |
| 1663 |
paraId.first.m_tabs=tabs; |
| 1664 |
} |
| 1665 |
} |
| 1666 |
ascFile.addPos(pos); |
| 1667 |
ascFile.addNote(f.str().c_str()); |
| 1668 |
input->seek(pos+16+len, librevenge::RVNG_SEEK_SET); |
| 1669 |
} |
| 1670 |
|
| 1671 |
pos=input->tell(); |
| 1672 |
if (pos!=endPos) { // checkme: list of 0 |
| 1673 |
ascFile.addPos(pos); |
| 1674 |
ascFile.addNote("_"); |
| 1675 |
} |
| 1676 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 1677 |
return true; |
| 1678 |
} |
| 1679 |
|
| 1680 |
//////////////////////////////////////////////////////////// |
| 1681 |
// |
| 1682 |
// Low level |
| 1683 |
// |
| 1684 |
//////////////////////////////////////////////////////////// |
| 1685 |
|
| 1686 |
//////////////////////////////////////////////////////////// |
| 1687 |
// send data to the listener |
| 1688 |
//////////////////////////////////////////////////////////// |
| 1689 |
bool Canvas5Graph::sendShape(int sId) |
| 1690 |
{ |
| 1691 |
return sendShape(sId, LocalState()); |
| 1692 |
} |
| 1693 |
|
| 1694 |
bool Canvas5Graph::sendShape(int sId, Canvas5Graph::LocalState const &local) |
| 1695 |
{ |
| 1696 |
auto const &it = m_state->m_idToShapeMap.find(sId); |
| 1697 |
if (it==m_state->m_idToShapeMap.end()) { |
| 1698 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendShape: can not find the shape %d\n", sId)); |
| 1699 |
return false; |
| 1700 |
} |
| 1701 |
if (m_state->m_sendIdSet.find(sId)!=m_state->m_sendIdSet.end()) { |
| 1702 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendShape: loop detected for shape %d\n", sId)); |
| 1703 |
return false; |
| 1704 |
} |
| 1705 |
m_state->m_sendIdSet.insert(sId); |
| 1706 |
bool res=send(it->second, local); |
| 1707 |
m_state->m_sendIdSet.erase(sId); |
| 1708 |
return res; |
| 1709 |
} |
| 1710 |
|
| 1711 |
void Canvas5Graph::send(MWAWListenerPtr listener, MWAWGraphicShape const &shape, MWAWTransformation const &transform, |
| 1712 |
MWAWGraphicStyle const &style) |
| 1713 |
{ |
| 1714 |
if (!listener) |
| 1715 |
return; |
| 1716 |
MWAWGraphicShape fShape=shape; |
| 1717 |
if (!transform.isIdentity()) |
| 1718 |
fShape=fShape.transform(transform); |
| 1719 |
auto shapeBox=fShape.getBdBox(); |
| 1720 |
MWAWPosition pos(shapeBox[0], shapeBox.size(), librevenge::RVNG_POINT); |
| 1721 |
pos.m_anchorTo = MWAWPosition::Page; |
| 1722 |
listener->insertShape(pos, fShape, style); |
| 1723 |
} |
| 1724 |
|
| 1725 |
void Canvas5Graph::send(MWAWListenerPtr listener, librevenge::RVNGString const &text, MWAWVec2f const ¢er, |
| 1726 |
MWAWTransformation const &transform, MWAWFont const &font, bool addFrame) |
| 1727 |
{ |
| 1728 |
if (!listener || text.empty()) |
| 1729 |
return; |
| 1730 |
|
| 1731 |
MWAWPosition measurePos(center-MWAWVec2f(30,6), MWAWVec2f(60,12), librevenge::RVNG_POINT); |
| 1732 |
measurePos.m_anchorTo = MWAWPosition::Page; |
| 1733 |
std::shared_ptr<MWAWSubDocument> doc(new Canvas5GraphInternal::SubDocument(*this, MWAWInputStreamPtr(), text, font)); |
| 1734 |
|
| 1735 |
MWAWGraphicStyle measureStyle; |
| 1736 |
measureStyle.m_lineWidth=addFrame ? 1 : 0; |
| 1737 |
measureStyle.setSurfaceColor(MWAWColor::white()); |
| 1738 |
|
| 1739 |
MWAWTransformation transf; |
| 1740 |
float rotation=0; |
| 1741 |
MWAWVec2f shearing; |
| 1742 |
if (!transform.isIdentity() && transform.decompose(rotation,shearing,transf,center)) { |
| 1743 |
auto shapeBox=transf*MWAWBox2f(center-MWAWVec2f(30,6),center+MWAWVec2f(30,6)); |
| 1744 |
measurePos.setOrigin(shapeBox[0]); |
| 1745 |
measurePos.setSize(shapeBox[1]-shapeBox[0]); |
| 1746 |
measureStyle.m_rotate=-rotation; |
| 1747 |
} |
| 1748 |
listener->insertTextBox(measurePos, doc, measureStyle); |
| 1749 |
} |
| 1750 |
|
| 1751 |
bool Canvas5Graph::send(Canvas5GraphInternal::Shape const &shape, Canvas5Graph::LocalState const &lTransform) |
| 1752 |
{ |
| 1753 |
auto listener=m_parserState->m_graphicListener; |
| 1754 |
if (!listener) { |
| 1755 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[shape]: can not find the listener\n")); |
| 1756 |
return false; |
| 1757 |
} |
| 1758 |
int const vers=version(); |
| 1759 |
auto const &shapeIt=m_state->m_posToShapeDataMap.find(shape.m_pos); |
| 1760 |
bool hasShapeId=shapeIt!=m_state->m_posToShapeDataMap.end(); |
| 1761 |
MWAWPosition pos(shape.m_initialBox[0], shape.m_initialBox.size(), librevenge::RVNG_POINT); |
| 1762 |
pos.m_anchorTo = MWAWPosition::Page; |
| 1763 |
LocalState local(pos, lTransform.m_style); |
| 1764 |
local.m_transform=lTransform.m_transform; |
| 1765 |
if (hasShapeId && shapeIt->second.m_ids[1]) { |
| 1766 |
auto const &matIt=m_state->m_idToMatrices.find(int(shapeIt->second.m_ids[1])); |
| 1767 |
if (matIt==m_state->m_idToMatrices.end()) { |
| 1768 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[shape]: can not find the matrix %d\n", int(shapeIt->second.m_ids[1]))); |
| 1769 |
} |
| 1770 |
else |
| 1771 |
local.multiplyMatrix(matIt->second[0]); |
| 1772 |
} |
| 1773 |
if (shape.m_values[1]) |
| 1774 |
m_styleManager->updateSurfaceColor(shape.m_values[1], local.m_style); |
| 1775 |
if (shape.m_values[2]) |
| 1776 |
m_styleManager->updateLineColor(shape.m_values[2], local.m_style); |
| 1777 |
int numLines=1; |
| 1778 |
if (shape.m_values[3]) |
| 1779 |
m_styleManager->updateLineStyle(shape.m_values[3], local.m_style, numLines); |
| 1780 |
MWAWGraphicShape finalShape; |
| 1781 |
switch (shape.m_type) { |
| 1782 |
case 2: { |
| 1783 |
if (!hasShapeId || !shapeIt->second.m_stream) { |
| 1784 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[text]: can not find the text zone\n")); |
| 1785 |
return false; |
| 1786 |
} |
| 1787 |
local.m_style.m_lineWidth=0; |
| 1788 |
std::shared_ptr<MWAWSubDocument> doc(new Canvas5GraphInternal::SubDocument(*this, shapeIt->second.getStream().input(), shape, shapeIt->second)); |
| 1789 |
MWAWTransformation transf; |
| 1790 |
float rotation=0; |
| 1791 |
MWAWVec2f shearing; |
| 1792 |
if (!local.m_transform.isIdentity() && local.m_transform.decompose(rotation,shearing,transf,shape.m_initialBox.center())) { |
| 1793 |
MWAWBox2f box=transf*shape.m_initialBox; |
| 1794 |
pos.setOrigin(box[0]); |
| 1795 |
pos.setSize(box[1]-box[0]); |
| 1796 |
MWAWGraphicStyle style(local.m_style); |
| 1797 |
style.m_rotate=-rotation; |
| 1798 |
listener->insertTextBox(pos, doc, style); |
| 1799 |
} |
| 1800 |
else |
| 1801 |
listener->insertTextBox(pos, doc, local.m_style); |
| 1802 |
return true; |
| 1803 |
} |
| 1804 |
case 3: { |
| 1805 |
auto const &data=shapeIt->second; |
| 1806 |
if (data.m_vertices.size()==2) |
| 1807 |
finalShape=MWAWGraphicShape::line(data.m_vertices[0], data.m_vertices[1]); |
| 1808 |
else |
| 1809 |
finalShape=MWAWGraphicShape::line(shape.m_initialBox[0], shape.m_initialBox[1]); |
| 1810 |
break; |
| 1811 |
} |
| 1812 |
case 4: |
| 1813 |
finalShape=MWAWGraphicShape::rectangle(shape.m_initialBox); |
| 1814 |
break; |
| 1815 |
case 5: |
| 1816 |
if (!hasShapeId) { |
| 1817 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[rectOval]: can not find the oval size\n")); |
| 1818 |
return false; |
| 1819 |
} |
| 1820 |
if (vers<9) |
| 1821 |
finalShape=MWAWGraphicShape::rectangle |
| 1822 |
(shape.m_initialBox, 1/65536.f*MWAWVec2f(float(shapeIt->second.m_local[0])/2,float(shapeIt->second.m_local[1])/2)); |
| 1823 |
else |
| 1824 |
finalShape=MWAWGraphicShape::rectangle |
| 1825 |
(shape.m_initialBox, MWAWVec2f(float(shapeIt->second.m_doubleValues[0])/2,float(shapeIt->second.m_doubleValues[1])/2)); |
| 1826 |
break; |
| 1827 |
case 6: |
| 1828 |
finalShape=MWAWGraphicShape::circle(shape.m_initialBox); |
| 1829 |
break; |
| 1830 |
case 7: { // arc |
| 1831 |
if (!hasShapeId) { |
| 1832 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[arc]: can not find the angle\n")); |
| 1833 |
return false; |
| 1834 |
} |
| 1835 |
auto const &data=shapeIt->second; |
| 1836 |
float const angles[]= {vers<9 ? float(data.m_local[0])/65536 : float(180/M_PI *data.m_doubleValues[1]), |
| 1837 |
vers<9 ? float(data.m_local[1])/65536 : float(180/ M_PI *data.m_doubleValues[0]) |
| 1838 |
}; |
| 1839 |
int angle[2] = { int(90-angles[0]-angles[1]), int(90-angles[1]) }; |
| 1840 |
if (angles[0]<0) |
| 1841 |
std::swap(angle[0],angle[1]); |
| 1842 |
else if (angles[0]>=360) |
| 1843 |
angle[0]-=359; |
| 1844 |
if (angle[1]>360) { |
| 1845 |
int numLoop=int(angle[1]/360)-1; |
| 1846 |
angle[0]-=numLoop*360; |
| 1847 |
angle[1]-=numLoop*360; |
| 1848 |
while (angle[1] > 360) { |
| 1849 |
angle[0]-=360; |
| 1850 |
angle[1]-=360; |
| 1851 |
} |
| 1852 |
} |
| 1853 |
if (angle[0] < -360) { |
| 1854 |
int numLoop=int(angle[0]/360)+1; |
| 1855 |
angle[0]-=numLoop*360; |
| 1856 |
angle[1]-=numLoop*360; |
| 1857 |
while (angle[0] < -360) { |
| 1858 |
angle[0]+=360; |
| 1859 |
angle[1]+=360; |
| 1860 |
} |
| 1861 |
} |
| 1862 |
// we must compute the real bd box |
| 1863 |
float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 }; |
| 1864 |
int limitAngle[2]; |
| 1865 |
for (int i = 0; i < 2; ++i) |
| 1866 |
limitAngle[i] = (angle[i] < 0) ? int(angle[i]/90)-1 : int(angle[i]/90); |
| 1867 |
for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; ++bord) { |
| 1868 |
float ang = (bord == limitAngle[0]) ? float(angle[0]) : |
| 1869 |
(bord == limitAngle[1]+1) ? float(angle[1]) : float(90 * bord); |
| 1870 |
ang *= float(M_PI/180.); |
| 1871 |
float const actVal[2] = { std::cos(ang), -std::sin(ang)}; |
| 1872 |
if (actVal[0] < minVal[0]) minVal[0] = actVal[0]; |
| 1873 |
else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0]; |
| 1874 |
if (actVal[1] < minVal[1]) minVal[1] = actVal[1]; |
| 1875 |
else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1]; |
| 1876 |
} |
| 1877 |
MWAWBox2f circleBox=shape.m_initialBox; |
| 1878 |
// we have the shape box, we need to reconstruct the circle box |
| 1879 |
if (maxVal[0]>minVal[0] && maxVal[1]>minVal[1]) { |
| 1880 |
float const scaling[2]= { (shape.m_initialBox[1][0]-shape.m_initialBox[0][0])/(maxVal[0]-minVal[0]), |
| 1881 |
(shape.m_initialBox[1][1]-shape.m_initialBox[0][1])/(maxVal[1]-minVal[1]) |
| 1882 |
}; |
| 1883 |
float const constant[2]= { shape.m_initialBox[0][0]-minVal[0] *scaling[0], shape.m_initialBox[0][1]-minVal[1] *scaling[1]}; |
| 1884 |
circleBox=MWAWBox2f(MWAWVec2f(constant[0]-scaling[0], constant[1]-scaling[1]), |
| 1885 |
MWAWVec2f(constant[0]+scaling[0], constant[1]+scaling[1])); |
| 1886 |
} |
| 1887 |
finalShape = MWAWGraphicShape::pie(shape.m_initialBox, circleBox, MWAWVec2f(float(angle[0]), float(angle[1]))); |
| 1888 |
break; |
| 1889 |
} |
| 1890 |
case 9: { // polyline |
| 1891 |
if (!hasShapeId || shapeIt->second.m_vertices.size()<2) { |
| 1892 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[spline]: can not find the point\n")); |
| 1893 |
return false; |
| 1894 |
} |
| 1895 |
if (local.m_style.hasSurface()) |
| 1896 |
finalShape=MWAWGraphicShape::polygon(shape.m_initialBox); |
| 1897 |
else |
| 1898 |
finalShape=MWAWGraphicShape::polyline(shape.m_initialBox); |
| 1899 |
finalShape.m_vertices=shapeIt->second.m_vertices; |
| 1900 |
break; |
| 1901 |
} |
| 1902 |
case 10: { // spline |
| 1903 |
if (!hasShapeId || shapeIt->second.m_vertices.size()<2 || (shapeIt->second.m_vertices.size()%4)!=0) { |
| 1904 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[spline]: can not find the point\n")); |
| 1905 |
return false; |
| 1906 |
} |
| 1907 |
finalShape=MWAWGraphicShape::path(shape.m_initialBox); |
| 1908 |
std::vector<MWAWGraphicShape::PathData> &path=finalShape.m_path; |
| 1909 |
path.push_back(MWAWGraphicShape::PathData('M', shapeIt->second.m_vertices[0])); |
| 1910 |
for (size_t p=3; p < shapeIt->second.m_vertices.size(); p+=4) { |
| 1911 |
if (p>=4 && shapeIt->second.m_vertices[p-4]!=shapeIt->second.m_vertices[p-3]) |
| 1912 |
path.push_back(MWAWGraphicShape::PathData('M', shapeIt->second.m_vertices[p-3])); |
| 1913 |
bool hasFirstC=shapeIt->second.m_vertices[p-3]!=shapeIt->second.m_vertices[p-2]; |
| 1914 |
bool hasSecondC=shapeIt->second.m_vertices[p-1]!=shapeIt->second.m_vertices[p]; |
| 1915 |
if (!hasFirstC && !hasSecondC) |
| 1916 |
path.push_back(MWAWGraphicShape::PathData('L', shapeIt->second.m_vertices[p])); |
| 1917 |
else |
| 1918 |
path.push_back(MWAWGraphicShape::PathData('C', shapeIt->second.m_vertices[p], shapeIt->second.m_vertices[p-2], shapeIt->second.m_vertices[p-1])); |
| 1919 |
} |
| 1920 |
if (local.m_style.hasSurface()) |
| 1921 |
path.push_back(MWAWGraphicShape::PathData('Z')); |
| 1922 |
break; |
| 1923 |
} |
| 1924 |
case 52: |
| 1925 |
if (!hasShapeId) { |
| 1926 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[special]: can not find the special data\n")); |
| 1927 |
return false; |
| 1928 |
} |
| 1929 |
if (numLines!=1) { |
| 1930 |
// even if this is possible, using mutiple line on special give really weird results |
| 1931 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[special]: find a special with multi lines\n")); |
| 1932 |
m_styleManager->updateLineStyle(shape.m_values[3], local.m_style, numLines, 0); |
| 1933 |
} |
| 1934 |
return sendSpecial(listener, shape, shapeIt->second, local); |
| 1935 |
case 20: |
| 1936 |
case 99: |
| 1937 |
if (!hasShapeId) { |
| 1938 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[group]: can not find the child shape\n")); |
| 1939 |
return false; |
| 1940 |
} |
| 1941 |
if (shapeIt->second.m_children.empty()) |
| 1942 |
return true; |
| 1943 |
if (shape.m_type==99) |
| 1944 |
local.m_style=MWAWGraphicStyle::emptyStyle(); |
| 1945 |
listener->openGroup(pos); |
| 1946 |
for (auto cId : shapeIt->second.m_children) |
| 1947 |
sendShape(int(cId), local); |
| 1948 |
listener->closeGroup(); |
| 1949 |
return true; |
| 1950 |
default: |
| 1951 |
static bool first=true; |
| 1952 |
if (first) { |
| 1953 |
MWAW_DEBUG_MSG(("Canvas5Graph::send[shape]: sorry, not implemented[%d]\n", shape.m_type)); |
| 1954 |
first=false; |
| 1955 |
} |
| 1956 |
return false; |
| 1957 |
} |
| 1958 |
if (!local.m_transform.isIdentity()) { |
| 1959 |
finalShape=finalShape.transform(local.m_transform); |
| 1960 |
MWAWBox2f shapeBox=finalShape.getBdBox(); |
| 1961 |
pos=MWAWPosition(shapeBox[0], shapeBox.size(), librevenge::RVNG_POINT); |
| 1962 |
pos.m_anchorTo = MWAWPosition::Page; |
| 1963 |
} |
| 1964 |
if (shape.m_values[3]==0 || numLines==1) { |
| 1965 |
listener->insertShape(pos, finalShape, local.m_style); |
| 1966 |
return true; |
| 1967 |
} |
| 1968 |
listener->openGroup(pos); |
| 1969 |
auto style=local.m_style; |
| 1970 |
style.m_lineWidth=0; |
| 1971 |
listener->insertShape(pos, finalShape, style); |
| 1972 |
style=MWAWGraphicStyle::emptyStyle(); |
| 1973 |
if (shape.m_values[2]) |
| 1974 |
m_styleManager->updateLineColor(shape.m_values[2], style); |
| 1975 |
auto path=finalShape.getPath(true); |
| 1976 |
for (int l=0; l<numLines; ++l) { |
| 1977 |
float offset; |
| 1978 |
m_styleManager->updateLineStyle(shape.m_values[3], style, numLines, l, &offset); |
| 1979 |
MWAWBox2f decalBox; |
| 1980 |
auto decalPath=MWAWGraphicShape::offsetVertices(path, offset, decalBox); |
| 1981 |
auto decalShape=MWAWGraphicShape::path(decalBox); |
| 1982 |
decalShape.m_path=decalPath; |
| 1983 |
pos=MWAWPosition(decalBox[0], decalBox.size(), librevenge::RVNG_POINT); |
| 1984 |
pos.m_anchorTo = MWAWPosition::Page; |
| 1985 |
listener->insertShape(pos, decalShape, style); |
| 1986 |
} |
| 1987 |
listener->closeGroup(); |
| 1988 |
return true; |
| 1989 |
} |
| 1990 |
|
| 1991 |
bool Canvas5Graph::sendSpecial(MWAWListenerPtr listener, Canvas5GraphInternal::PseudoShape const &pseudoShape, LocalState const &local) |
| 1992 |
{ |
| 1993 |
return sendSpecial(listener, pseudoShape.m_shape, pseudoShape.m_data, local); |
| 1994 |
} |
| 1995 |
|
| 1996 |
bool Canvas5Graph::sendSpecial(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &shape, Canvas5GraphInternal::ShapeData const &data, |
| 1997 |
Canvas5Graph::LocalState const &local) |
| 1998 |
{ |
| 1999 |
if (!data.m_stream) |
| 2000 |
return false; |
| 2001 |
if (!listener) { |
| 2002 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: can not find the listener\n")); |
| 2003 |
return false; |
| 2004 |
} |
| 2005 |
int const vers=version(); |
| 2006 |
auto &stream=data.getStream(); |
| 2007 |
MWAWGraphicShape fShape; |
| 2008 |
auto const &box=shape.m_initialBox; |
| 2009 |
switch (data.m_type) { |
| 2010 |
case 0x43436972: { // CCir |
| 2011 |
if (data.m_specials[0]<=0 || data.m_specials[0]>20) { |
| 2012 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry, the number of circles seems bad\n")); |
| 2013 |
return false; |
| 2014 |
} |
| 2015 |
listener->openGroup(local.m_position); |
| 2016 |
MWAWVec2f center=0.5f*(box[0]+box[1]); |
| 2017 |
MWAWVec2f diag=0.5f*box.size(); |
| 2018 |
for (int i=0; i<data.m_specials[0]; ++i) { |
| 2019 |
MWAWVec2f newDiag; |
| 2020 |
if (data.m_specials[1]<=0) |
| 2021 |
newDiag=float(data.m_specials[0]-i)/float(data.m_specials[0])*diag; |
| 2022 |
else { |
| 2023 |
newDiag=diag-float(data.m_specials[1]*i)*MWAWVec2f(1,1); |
| 2024 |
for (int c=0; c<2; ++c) { |
| 2025 |
if (newDiag[c]<0) |
| 2026 |
newDiag[c]=0; |
| 2027 |
} |
| 2028 |
} |
| 2029 |
fShape=MWAWGraphicShape::circle(MWAWBox2f(center-newDiag, center+newDiag)); |
| 2030 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2031 |
} |
| 2032 |
listener->closeGroup(); |
| 2033 |
break; |
| 2034 |
} |
| 2035 |
case 0x43756265: { // Cube |
| 2036 |
if (data.m_vertices.size()!=8) { |
| 2037 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: can not find the cube vertices\n")); |
| 2038 |
return false; |
| 2039 |
} |
| 2040 |
int const faces[]= { |
| 2041 |
0, 2, 6, 4, // X==0 |
| 2042 |
1, 3, 7, 5, // X==1 |
| 2043 |
0, 1, 5, 4, // Y==0 |
| 2044 |
2, 3, 7, 6, // Y==1 |
| 2045 |
0, 1, 3, 2, // Z==0 |
| 2046 |
4, 5, 7, 6, // Z==1 |
| 2047 |
}; |
| 2048 |
listener->openGroup(local.m_position); |
| 2049 |
fShape.m_type=local.m_style.hasSurface() ? MWAWGraphicShape::Polygon : MWAWGraphicShape::Polyline; |
| 2050 |
MWAWVec2f const dir=box[1]-box[0]; |
| 2051 |
MWAWVec2f const dirs[]= {data.m_vertices[1]-data.m_vertices[0], |
| 2052 |
data.m_vertices[2]-data.m_vertices[0], |
| 2053 |
data.m_vertices[4]-data.m_vertices[0] |
| 2054 |
}; |
| 2055 |
int wh=(dirs[0][0]*dirs[2][1]-dirs[0][1]*dirs[2][0]>0) ? 0 : 1; |
| 2056 |
wh+=(dirs[1][0]*dirs[2][1]-dirs[1][1]*dirs[2][0]>0) ? 0 : 2; |
| 2057 |
if (dirs[0][0]*dirs[1][1]-dirs[0][1]*dirs[1][0]>0 && (wh==0 || wh==3)) wh=3-wh; |
| 2058 |
|
| 2059 |
for (int f=0; f<3; ++f) { |
| 2060 |
size_t face; |
| 2061 |
switch (f) { |
| 2062 |
case 0: |
| 2063 |
face=4; |
| 2064 |
break; |
| 2065 |
case 1: |
| 2066 |
face = (wh==0 || wh==1) ? 2 : 3; |
| 2067 |
break; |
| 2068 |
default: |
| 2069 |
face = (wh==0 || wh==2) ? 1 : 0; |
| 2070 |
break; |
| 2071 |
} |
| 2072 |
|
| 2073 |
MWAWBox2f shapeBox; |
| 2074 |
fShape.m_vertices.resize(4); |
| 2075 |
for (size_t p=0; p<4; ++p) { |
| 2076 |
MWAWVec2f const &pt=data.m_vertices[size_t(faces[4*face+p])]; |
| 2077 |
fShape.m_vertices[p]=box[0]+MWAWVec2f(pt[0]*dir[0], pt[1]*dir[1]); |
| 2078 |
} |
| 2079 |
fShape.m_bdBox=shapeBox; |
| 2080 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2081 |
} |
| 2082 |
listener->closeGroup(); |
| 2083 |
break; |
| 2084 |
} |
| 2085 |
case 0x43765465: // CvTe |
| 2086 |
return sendCurveText(listener, shape, data, local); |
| 2087 |
case 0x44494d4e: // DIMN |
| 2088 |
if (vers<9) |
| 2089 |
return sendDimension(listener, shape, data, local); |
| 2090 |
return sendDimension9(listener, shape, data, local); |
| 2091 |
case 0x65666665: // eff |
| 2092 |
return sendEffect(listener, shape, data, local); |
| 2093 |
case 0x45787472: // Extr: extrude |
| 2094 |
return sendExtrude(listener, shape, data, local); |
| 2095 |
case 0x4772644d: { // GrdL |
| 2096 |
listener->openGroup(local.m_position); |
| 2097 |
if (data.m_grid[0]<=0 || data.m_grid[1]<=0 || |
| 2098 |
data.m_grid[0]>100 || data.m_grid[1]>100) { |
| 2099 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial[grid]: can not find the number of rows/columns\n")); |
| 2100 |
return false; |
| 2101 |
} |
| 2102 |
MWAWVec2f dim((box[1][0]-box[0][0])/float(data.m_grid[0]), |
| 2103 |
(box[1][1]-box[0][1])/float(data.m_grid[1])); |
| 2104 |
for (int i=0; i<=data.m_grid[0]; ++i) { |
| 2105 |
float X=box[0][0]+float(i)*dim[0]; |
| 2106 |
fShape=MWAWGraphicShape::line(MWAWVec2f(X,box[0][1]), MWAWVec2f(X,box[1][1])); |
| 2107 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2108 |
} |
| 2109 |
for (int j=0; j<=data.m_grid[1]; ++j) { |
| 2110 |
float Y=box[0][1]+float(j)*dim[1]; |
| 2111 |
fShape=MWAWGraphicShape::line(MWAWVec2f(box[0][0],Y), MWAWVec2f(box[1][0],Y)); |
| 2112 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2113 |
} |
| 2114 |
listener->closeGroup(); |
| 2115 |
break; |
| 2116 |
} |
| 2117 |
case 0x4e474f4e: { // NGON |
| 2118 |
if (data.m_specials[0]<=2 || data.m_specials[0]>=50) { // find N=33 |
| 2119 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry, the number of ngon seems bad\n")); |
| 2120 |
return false; |
| 2121 |
} |
| 2122 |
int type=data.m_ngonType; |
| 2123 |
if (type<0 || type>5) { |
| 2124 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry, the ngon's seems bad, assume 4\n")); |
| 2125 |
type=4; |
| 2126 |
} |
| 2127 |
bool needGroup=type!=0 && type!=3 && type!=4; |
| 2128 |
if (needGroup) |
| 2129 |
listener->openGroup(local.m_position); |
| 2130 |
MWAWVec2f const center=0.5f*(box[0]+box[1]); |
| 2131 |
MWAWVec2f const diag=0.5f*box.size(); |
| 2132 |
double const angles[]= {M_PI/2-data.m_doubleValues[2], M_PI/2-M_PI/data.m_specials[0]}; |
| 2133 |
double const step=-2*M_PI/data.m_specials[0]; |
| 2134 |
float const rad=float(data.m_doubleValues[0]); |
| 2135 |
if (type==0 || type==1 || type==5) { // border |
| 2136 |
fShape=MWAWGraphicShape::polygon(box); |
| 2137 |
for (int i=0; i<data.m_specials[0]; ++i) { |
| 2138 |
float const angle1=float(angles[0]+i*step); |
| 2139 |
fShape.m_vertices.push_back(center+MWAWVec2f(std::cos(angle1)*diag[0], -std::sin(angle1)*diag[1])); |
| 2140 |
} |
| 2141 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2142 |
} |
| 2143 |
if (type==1 || type==4) { // outside star |
| 2144 |
fShape=MWAWGraphicShape::polygon(box); |
| 2145 |
for (int i=0; i<data.m_specials[0]; ++i) { |
| 2146 |
float const angle1=float(angles[0]+i*step); |
| 2147 |
fShape.m_vertices.push_back(center+MWAWVec2f(std::cos(angle1)*diag[0], -std::sin(angle1)*diag[1])); |
| 2148 |
float const angle2=float(angles[1]+i*step); |
| 2149 |
fShape.m_vertices.push_back(center+MWAWVec2f(rad*std::cos(angle2)*diag[0], -rad*std::sin(angle2)*diag[1])); |
| 2150 |
} |
| 2151 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2152 |
} |
| 2153 |
if (type==3) { // inside star |
| 2154 |
fShape=MWAWGraphicShape::polygon(box); |
| 2155 |
int id=0; |
| 2156 |
for (int i=0; i<data.m_specials[0]; ++i) { |
| 2157 |
float const angle1=float(angles[0]+id*step); |
| 2158 |
fShape.m_vertices.push_back(center+MWAWVec2f(std::cos(angle1)*diag[0], -std::sin(angle1)*diag[1])); |
| 2159 |
id+=(data.m_specials[0]-1+i%2)/2; |
| 2160 |
} |
| 2161 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2162 |
} |
| 2163 |
if (type==2 || type==5) { // list of segment: center->outside points |
| 2164 |
for (int i=0; i<data.m_specials[0]; ++i) { |
| 2165 |
float const angle1=float(angles[0]+i*step); |
| 2166 |
fShape=MWAWGraphicShape::line(center, center+MWAWVec2f(std::cos(angle1)*diag[0], -std::sin(angle1)*diag[1])); |
| 2167 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2168 |
} |
| 2169 |
} |
| 2170 |
if (needGroup) |
| 2171 |
listener->closeGroup(); |
| 2172 |
break; |
| 2173 |
} |
| 2174 |
case 0x4f4c6e6b : { // OLnk |
| 2175 |
if (data.m_vertices.size()<2) { |
| 2176 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry, can not find the link extremities\n")); |
| 2177 |
return false; |
| 2178 |
} |
| 2179 |
fShape=MWAWGraphicShape::line(data.m_vertices[0], data.m_vertices[1]); |
| 2180 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2181 |
break; |
| 2182 |
} |
| 2183 |
case 0x4d41434f: { // MACO |
| 2184 |
auto sIt=m_state->m_sendMACOIdSet.find(data.m_macoId); |
| 2185 |
if (sIt!=m_state->m_sendMACOIdSet.end()) { |
| 2186 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry find a loop sending MACO\n")); |
| 2187 |
break; |
| 2188 |
} |
| 2189 |
auto maco=m_imageParser->getMACO(data.m_macoId); |
| 2190 |
if (!maco) |
| 2191 |
break; |
| 2192 |
|
| 2193 |
m_state->m_sendMACOIdSet.insert(data.m_macoId); |
| 2194 |
listener->openGroup(local.m_position); |
| 2195 |
m_imageParser->send(maco, listener, shape.m_initialBox, local.m_transform); |
| 2196 |
listener->closeGroup(); |
| 2197 |
m_state->m_sendMACOIdSet.erase(data.m_macoId); |
| 2198 |
break; |
| 2199 |
} |
| 2200 |
case 0x706f626a: { // pobj |
| 2201 |
MWAWEmbeddedObject bitmap; |
| 2202 |
if (!m_imageParser->getBitmap(data.m_specials[1], bitmap)) |
| 2203 |
return false; |
| 2204 |
MWAWTransformation transf; |
| 2205 |
float rotation=0; |
| 2206 |
MWAWVec2f shearing; |
| 2207 |
if (!local.m_transform.isIdentity() && local.m_transform.decompose(rotation,shearing,transf,shape.m_initialBox.center())) { |
| 2208 |
MWAWBox2f shapeBox=transf*shape.m_initialBox; |
| 2209 |
MWAWPosition pos(shapeBox[0], shapeBox.size(), librevenge::RVNG_POINT); |
| 2210 |
pos.m_anchorTo = MWAWPosition::Page; |
| 2211 |
MWAWGraphicStyle style(local.m_style); |
| 2212 |
style.m_rotate=-rotation; |
| 2213 |
listener->insertPicture(pos, bitmap, style); |
| 2214 |
} |
| 2215 |
else |
| 2216 |
listener->insertPicture(local.m_position, bitmap, local.m_style); |
| 2217 |
break; |
| 2218 |
} |
| 2219 |
case 0x53504952: { // SPIR |
| 2220 |
if (data.m_specials[0]<=0) { |
| 2221 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry, the number of spirals seems bad\n")); |
| 2222 |
return false; |
| 2223 |
} |
| 2224 |
fShape=MWAWGraphicShape::path(box); |
| 2225 |
auto const center = box.center(); |
| 2226 |
auto const dir = 0.5f/4/float(data.m_specials[0]) * box.size(); |
| 2227 |
std::vector<MWAWGraphicShape::PathData> &path=fShape.m_path; |
| 2228 |
auto pt=center; |
| 2229 |
path.push_back(MWAWGraphicShape::PathData('M', center)); |
| 2230 |
for (int i=1; i<=4*data.m_specials[0]; ++i) { |
| 2231 |
auto nextPt=center; |
| 2232 |
nextPt[(i&1)] += ((i%4)<2 ? 1 : -1)*float(i)*dir[(i&1)]; |
| 2233 |
MWAWVec2f l; |
| 2234 |
l[1-(i&1)]=pt[1-(i&1)]; |
| 2235 |
l[(i&1)]=nextPt[(i&1)]; |
| 2236 |
path.push_back(MWAWGraphicShape::PathData('Q', nextPt, l)); |
| 2237 |
pt=nextPt; |
| 2238 |
} |
| 2239 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2240 |
break; |
| 2241 |
} |
| 2242 |
case 0x43574542: { // CWEB: ie a button with 3 state |
| 2243 |
auto input=stream.input(); |
| 2244 |
bool isSent=false; |
| 2245 |
for (auto const &e : data.m_cweb) { |
| 2246 |
if (!e.valid()) continue; |
| 2247 |
input->seek(e.begin(), librevenge::RVNG_SEEK_SET); |
| 2248 |
input->pushLimit(e.end()); |
| 2249 |
bool ok=true; |
| 2250 |
std::shared_ptr<Canvas5ImageInternal::VKFLImage> image; |
| 2251 |
if (!m_imageParser->readVKFL(data.m_stream, e.length(), image)) { |
| 2252 |
auto &ascFile=stream.ascii(); |
| 2253 |
ok=false; |
| 2254 |
ascFile.addPos(e.begin()); |
| 2255 |
ascFile.addNote("DataShap:special,image:###"); |
| 2256 |
} |
| 2257 |
else if (!isSent) { |
| 2258 |
isSent=true; |
| 2259 |
listener->openGroup(local.m_position); |
| 2260 |
m_imageParser->send(image, listener, shape.m_initialBox, local.m_transform); |
| 2261 |
listener->closeGroup(); |
| 2262 |
static bool first=true; |
| 2263 |
if (first) { |
| 2264 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecialData[button]: send only the first picture (instead of the three state pictures)\n")); |
| 2265 |
first=false; |
| 2266 |
} |
| 2267 |
} |
| 2268 |
input->popLimit(); |
| 2269 |
if (!ok) |
| 2270 |
continue; |
| 2271 |
#ifndef DEBUG |
| 2272 |
break; |
| 2273 |
#endif |
| 2274 |
} |
| 2275 |
break; |
| 2276 |
} |
| 2277 |
case 0x54585420: { // TXT : only in Vkfl |
| 2278 |
if (data.m_inMainZone) { |
| 2279 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecialData: unexpected text in main zone\n")); |
| 2280 |
return false; |
| 2281 |
} |
| 2282 |
auto lStyle=local.m_style; |
| 2283 |
lStyle.m_lineWidth=0; |
| 2284 |
std::shared_ptr<MWAWSubDocument> doc(new Canvas5GraphInternal::SubDocument(*this, stream.input(), shape, data)); |
| 2285 |
MWAWTransformation transf; |
| 2286 |
float rotation=0; |
| 2287 |
MWAWVec2f shearing; |
| 2288 |
if (!local.m_transform.isIdentity() && local.m_transform.decompose(rotation,shearing,transf,shape.m_initialBox.center())) { |
| 2289 |
MWAWBox2f shapeBox=transf*shape.m_initialBox; |
| 2290 |
MWAWPosition pos(shapeBox[0], shapeBox.size(), librevenge::RVNG_POINT); |
| 2291 |
pos.m_anchorTo = MWAWPosition::Page; |
| 2292 |
lStyle.m_rotate=-rotation; |
| 2293 |
listener->insertTextBox(pos, doc, lStyle); |
| 2294 |
} |
| 2295 |
else |
| 2296 |
listener->insertTextBox(local.m_position, doc, lStyle); |
| 2297 |
break; |
| 2298 |
} |
| 2299 |
case 0x41474946: { // AGIF appear in v6 |
| 2300 |
auto sIt=m_state->m_sendAGIFIdSet.find(data.m_specials[1]); |
| 2301 |
if (sIt!=m_state->m_sendAGIFIdSet.end()) { |
| 2302 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry find a loop sending AGIF\n")); |
| 2303 |
break; |
| 2304 |
} |
| 2305 |
auto gif=m_imageParser->getGIF(data.m_specials[1]); |
| 2306 |
if (!gif) |
| 2307 |
break; |
| 2308 |
|
| 2309 |
m_state->m_sendAGIFIdSet.insert(data.m_specials[1]); |
| 2310 |
listener->openGroup(local.m_position); |
| 2311 |
m_imageParser->send(gif, listener, shape.m_initialBox, local.m_transform); |
| 2312 |
listener->closeGroup(); |
| 2313 |
m_state->m_sendAGIFIdSet.erase(data.m_specials[1]); |
| 2314 |
break; |
| 2315 |
} |
| 2316 |
case 0x516b546d: { // QkTm |
| 2317 |
MWAWEmbeddedObject movie; |
| 2318 |
if (!m_imageParser->getQuickTime(data.m_specials[0], movie)) |
| 2319 |
return false; |
| 2320 |
static bool first=true; |
| 2321 |
if (first) { |
| 2322 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial[QkTm]: this file contains movie, there will be probably illisible\n")); |
| 2323 |
first=false; |
| 2324 |
} |
| 2325 |
MWAWTransformation transf; |
| 2326 |
float rotation=0; |
| 2327 |
MWAWVec2f shearing; |
| 2328 |
if (!local.m_transform.isIdentity() && local.m_transform.decompose(rotation,shearing,transf,shape.m_initialBox.center())) { |
| 2329 |
MWAWBox2f shapeBox=transf*shape.m_initialBox; |
| 2330 |
MWAWPosition pos(shapeBox[0], shapeBox.size(), librevenge::RVNG_POINT); |
| 2331 |
pos.m_anchorTo = MWAWPosition::Page; |
| 2332 |
MWAWGraphicStyle style(local.m_style); |
| 2333 |
style.m_rotate=-rotation; |
| 2334 |
listener->insertPicture(pos, movie, style); |
| 2335 |
} |
| 2336 |
else |
| 2337 |
listener->insertPicture(local.m_position, movie, local.m_style); |
| 2338 |
break; |
| 2339 |
} |
| 2340 |
case 0x23476465: { // #Gde: appear in v6 |
| 2341 |
if (data.m_gdeType!=3) |
| 2342 |
return true; |
| 2343 |
for (auto const § : data.m_sections) { |
| 2344 |
// add only a basic frame, todo: add also a frame to separate column |
| 2345 |
fShape=MWAWGraphicShape::rectangle(sect.m_bdBox); |
| 2346 |
MWAWGraphicStyle basicStyle; |
| 2347 |
basicStyle.m_lineColor=MWAWColor(127,127,255); |
| 2348 |
basicStyle.m_lineWidth=0.5f; |
| 2349 |
send(listener, fShape, local.m_transform, basicStyle); |
| 2350 |
} |
| 2351 |
break; |
| 2352 |
} |
| 2353 |
case 0x416e4766: // AnGf: appear in v7 |
| 2354 |
return sendGIF(listener, shape, data, local); |
| 2355 |
case 0x54656368: // Tech: appear in v7 |
| 2356 |
return sendTechnical(listener, shape, data, local); |
| 2357 |
case 0x494d534c: { // SIML: a slice mask?, appear in v8 |
| 2358 |
fShape=MWAWGraphicShape::rectangle(shape.m_initialBox); |
| 2359 |
MWAWGraphicStyle basicStyle; |
| 2360 |
basicStyle.m_lineColor=MWAWColor(250,128,114); |
| 2361 |
basicStyle.m_lineWidth=0.5f; |
| 2362 |
basicStyle.setSurfaceColor(MWAWColor(255,255,0),0.5); |
| 2363 |
send(listener, fShape, local.m_transform, basicStyle); |
| 2364 |
break; |
| 2365 |
} |
| 2366 |
case 0x72656750: { // regP: appear in v8 |
| 2367 |
listener->openGroup(local.m_position); |
| 2368 |
MWAWBox2f const &shapeBox=shape.m_initialBox; |
| 2369 |
auto const center=shapeBox.center(); |
| 2370 |
MWAWGraphicStyle basicStyle; |
| 2371 |
for (int i=0; i<3; ++i) { |
| 2372 |
switch (i) { |
| 2373 |
case 0: { |
| 2374 |
MWAWBox2f cBox=shapeBox; |
| 2375 |
cBox.resizeFromCenter(0.5f*shapeBox.size()); |
| 2376 |
fShape=MWAWGraphicShape::circle(cBox); |
| 2377 |
break; |
| 2378 |
} |
| 2379 |
case 1: |
| 2380 |
fShape=MWAWGraphicShape::line(MWAWVec2f(shapeBox[0][0],center[1]), MWAWVec2f(shapeBox[1][0],center[1])); |
| 2381 |
break; |
| 2382 |
case 2: |
| 2383 |
default: |
| 2384 |
fShape=MWAWGraphicShape::line(MWAWVec2f(center[0],shapeBox[0][1]), MWAWVec2f(center[0],shapeBox[1][1])); |
| 2385 |
break; |
| 2386 |
} |
| 2387 |
send(listener, fShape, local.m_transform, basicStyle); |
| 2388 |
} |
| 2389 |
listener->closeGroup(); |
| 2390 |
break; |
| 2391 |
} |
| 2392 |
default: |
| 2393 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendSpecial: sorry, sending %s is not implemented\n", Canvas5Structure::getString(data.m_type).c_str())); |
| 2394 |
return false; |
| 2395 |
} |
| 2396 |
return true; |
| 2397 |
} |
| 2398 |
|
| 2399 |
bool Canvas5Graph::sendText(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &/*shape*/, Canvas5GraphInternal::ShapeData const &data) |
| 2400 |
{ |
| 2401 |
if (!data.m_stream) |
| 2402 |
return false; |
| 2403 |
|
| 2404 |
if (!listener) { |
| 2405 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: can not find the listener\n")); |
| 2406 |
return false; |
| 2407 |
} |
| 2408 |
auto &stream=data.getStream(); |
| 2409 |
int const vers=version(); |
| 2410 |
libmwaw::DebugStream f; |
| 2411 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 2412 |
auto input=stream.input(); |
| 2413 |
auto entry=data.m_entry; |
| 2414 |
MWAWEntry fontEntry; |
| 2415 |
if (!data.m_inMainZone) { |
| 2416 |
if (!entry.valid() || entry.length()<16 || !input->checkPosition(entry.end())) { |
| 2417 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: can not find the text entry\n")); |
| 2418 |
return false; |
| 2419 |
} |
| 2420 |
|
| 2421 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2422 |
long pos=input->tell(); |
| 2423 |
f << "Text[zones]:"; |
| 2424 |
MWAWEntry childs[2]; |
| 2425 |
for (auto &c : childs) { |
| 2426 |
c.setBegin(entry.begin()+input->readLong(4)); |
| 2427 |
c.setLength(input->readLong(4)); |
| 2428 |
if (c.begin()<entry.begin() || c.end()>entry.end()) { |
| 2429 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: can not find the main child entry\n")); |
| 2430 |
f << "###"; |
| 2431 |
ascFile.addPos(pos); |
| 2432 |
ascFile.addNote(f.str().c_str()); |
| 2433 |
return false; |
| 2434 |
} |
| 2435 |
f << std::hex << c.begin() << "<->" << c.end() << ","; |
| 2436 |
} |
| 2437 |
ascFile.addPos(pos); |
| 2438 |
ascFile.addNote(f.str().c_str()); |
| 2439 |
entry=childs[0]; |
| 2440 |
fontEntry=childs[1]; |
| 2441 |
ascFile.addPos(fontEntry.begin()); |
| 2442 |
ascFile.addNote("Text[fonts]:"); |
| 2443 |
} |
| 2444 |
if (!entry.valid() || entry.length()<20+5*4 || !input->checkPosition(entry.end())) { |
| 2445 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: can not find the text entry\n")); |
| 2446 |
return false; |
| 2447 |
} |
| 2448 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2449 |
|
| 2450 |
long pos=input->tell(); |
| 2451 |
f.str(""); |
| 2452 |
f << "Entries(Text):"; |
| 2453 |
int val; |
| 2454 |
for (int i=0; i<7; ++i) { |
| 2455 |
val=int(input->readLong(2)); |
| 2456 |
int const expected[]= {1,0,0xc,0,0,0,1}; |
| 2457 |
if (val!=expected[i]) |
| 2458 |
f << "f" << i << "=" << val << ","; |
| 2459 |
} |
| 2460 |
val=int(input->readULong(2)); |
| 2461 |
if (val!=0x7071) f << "fl=" << std::hex << val << std::dec << ","; |
| 2462 |
val=int(input->readLong(2)); |
| 2463 |
MWAWParagraph para; |
| 2464 |
switch (val) { |
| 2465 |
case -1: |
| 2466 |
para.m_justify=MWAWParagraph::JustificationRight; |
| 2467 |
f << "right,"; |
| 2468 |
break; |
| 2469 |
case 0: // left |
| 2470 |
break; |
| 2471 |
case 1: |
| 2472 |
para.m_justify=MWAWParagraph::JustificationCenter; |
| 2473 |
f << "center,"; |
| 2474 |
break; |
| 2475 |
case 4: |
| 2476 |
para.m_justify=MWAWParagraph::JustificationFull; |
| 2477 |
f << "justify,"; |
| 2478 |
break; |
| 2479 |
default: |
| 2480 |
f << "#align=" << val << ","; |
| 2481 |
} |
| 2482 |
val=int(input->readLong(2)); |
| 2483 |
if (val) f << "f7=" << val << ","; |
| 2484 |
unsigned long lengths[5], totalLength=0; |
| 2485 |
f << "len=["; |
| 2486 |
for (auto &l : lengths) { |
| 2487 |
l=input->readULong(4); |
| 2488 |
if (totalLength+l<totalLength) { |
| 2489 |
f << "###"; |
| 2490 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: bad lengths\n")); |
| 2491 |
ascFile.addPos(pos); |
| 2492 |
ascFile.addNote(f.str().c_str()); |
| 2493 |
return false; |
| 2494 |
} |
| 2495 |
totalLength+=l; |
| 2496 |
if (l) |
| 2497 |
f << l << ","; |
| 2498 |
else |
| 2499 |
f << "_,"; |
| 2500 |
} |
| 2501 |
f << "],"; |
| 2502 |
if (pos+24+5*4+long(totalLength)<pos+24+20 || pos+24+5*4+long(totalLength)>=entry.end()) { |
| 2503 |
f << "###"; |
| 2504 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: bad lengths\n")); |
| 2505 |
ascFile.addPos(pos); |
| 2506 |
ascFile.addNote(f.str().c_str()); |
| 2507 |
return false; |
| 2508 |
} |
| 2509 |
ascFile.addPos(pos); |
| 2510 |
ascFile.addNote(f.str().c_str()); |
| 2511 |
|
| 2512 |
pos=input->tell(); |
| 2513 |
MWAWEntry textEntry; |
| 2514 |
textEntry.setBegin(pos); |
| 2515 |
textEntry.setLength(int(lengths[0])); |
| 2516 |
input->seek((lengths[0]&1) ? long(lengths[0])+1 : long(lengths[0]), librevenge::RVNG_SEEK_CUR); |
| 2517 |
|
| 2518 |
if (lengths[1]) { |
| 2519 |
ascFile.addPos(input->tell()); |
| 2520 |
ascFile.addNote("Text-Unkn:"); |
| 2521 |
input->seek(long(lengths[1]), librevenge::RVNG_SEEK_CUR); |
| 2522 |
} |
| 2523 |
bool ok=true; |
| 2524 |
if (lengths[2]<8) { |
| 2525 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: length 2 seems too short\n")); |
| 2526 |
ok=false; |
| 2527 |
} |
| 2528 |
|
| 2529 |
std::map<int,int> posToFontIdMap; |
| 2530 |
if (ok) { |
| 2531 |
pos=input->tell(); |
| 2532 |
f.str(""); |
| 2533 |
f << "Text-plc:"; |
| 2534 |
int N0=int(input->readLong(2)); |
| 2535 |
if (N0!=1) f << "f0=" << N0 << ","; |
| 2536 |
int N=int(input->readULong(2)); |
| 2537 |
f << "numPLC=" << N << ","; |
| 2538 |
if (int(lengths[2])<20+N0*8) { |
| 2539 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: length 2 seems bad\n")); |
| 2540 |
f << "###"; |
| 2541 |
} |
| 2542 |
else { |
| 2543 |
for (int i=0; i<8; ++i) { // 0 |
| 2544 |
val=int(input->readLong(2)); |
| 2545 |
if (val) f << "f" << i << "=" << val << ","; |
| 2546 |
} |
| 2547 |
f << "plcs=["; |
| 2548 |
for (int i=0; i<N0; ++i) { |
| 2549 |
int posi=int(input->readULong(4)); |
| 2550 |
int id=int(input->readULong(2)); |
| 2551 |
val=int(input->readLong(2)); // almost always 0, but find 4447|a0 ? |
| 2552 |
f << posi << ":" << id; |
| 2553 |
if (val) f << "[" << val << "]"; |
| 2554 |
f << ","; |
| 2555 |
posToFontIdMap[posi]=id; |
| 2556 |
} |
| 2557 |
f << input->readULong(4); |
| 2558 |
f << "],"; |
| 2559 |
} |
| 2560 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2561 |
ascFile.addPos(pos); |
| 2562 |
ascFile.addNote(f.str().c_str()); |
| 2563 |
input->seek(pos+long(lengths[2]), librevenge::RVNG_SEEK_SET); |
| 2564 |
} |
| 2565 |
|
| 2566 |
int const styleSz=vers<9 ? 60 : 96; |
| 2567 |
if (ok && (int(lengths[4])%styleSz)!=0) { |
| 2568 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: length 4 seems bads\n")); |
| 2569 |
ok=false; |
| 2570 |
} |
| 2571 |
|
| 2572 |
Canvas5StyleManager::StyleList styles; |
| 2573 |
if (ok) { |
| 2574 |
int N=int(lengths[4])/styleSz; |
| 2575 |
styles.m_fonts.resize(size_t(N)); |
| 2576 |
for (int n=0; n<N; ++n) { |
| 2577 |
pos=input->tell(); |
| 2578 |
m_styleManager->readCharStyle(stream, n, styles.m_fonts[size_t(n)], data.m_inMainZone); |
| 2579 |
input->seek(pos+styleSz, librevenge::RVNG_SEEK_SET); |
| 2580 |
} |
| 2581 |
} |
| 2582 |
|
| 2583 |
if (ok && (lengths[3]%16)) { |
| 2584 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: length 3 seems bads\n")); |
| 2585 |
ok=false; |
| 2586 |
} |
| 2587 |
|
| 2588 |
if (ok) { |
| 2589 |
int N=int(lengths[3]/16); |
| 2590 |
for (int n=0; n<N; ++n) { |
| 2591 |
// unsure maybe |
| 2592 |
// before v9 n*[2 double:int4 + 32 bytes] |
| 2593 |
// in v9 n*[2 double + 32 bytes] + n*[2 int] |
| 2594 |
pos=input->tell(); |
| 2595 |
f.str(""); |
| 2596 |
f << "Text-A" << n << ":"; |
| 2597 |
ascFile.addPos(pos); |
| 2598 |
ascFile.addNote(f.str().c_str()); |
| 2599 |
input->seek(pos+16, librevenge::RVNG_SEEK_SET); |
| 2600 |
} |
| 2601 |
|
| 2602 |
pos=input->tell(); |
| 2603 |
if (!readDeR3(data.m_stream, styles)) { |
| 2604 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2605 |
ok=false; |
| 2606 |
} |
| 2607 |
} |
| 2608 |
|
| 2609 |
pos=input->tell(); |
| 2610 |
input->seek(textEntry.begin(), librevenge::RVNG_SEEK_SET); |
| 2611 |
f.str(""); |
| 2612 |
f << "Text-text:"; |
| 2613 |
listener->setParagraph(para); |
| 2614 |
|
| 2615 |
int linkId=0; |
| 2616 |
bool linkIsOpen=false; |
| 2617 |
for (int n=0; n<int(lengths[0]); ++n) { |
| 2618 |
auto it=posToFontIdMap.find(n); |
| 2619 |
if (it!=posToFontIdMap.end()) { |
| 2620 |
if (it->second<0 || it->second>=int(styles.m_fonts.size())) { |
| 2621 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: can not read find the font=%d\n", it->second)); |
| 2622 |
} |
| 2623 |
else { |
| 2624 |
auto const &font=styles.m_fonts[size_t(it->second)]; |
| 2625 |
if (font.m_paragraphId>0 && size_t(font.m_paragraphId)<styles.m_paragraphs.size()) |
| 2626 |
listener->setParagraph(styles.m_paragraphs[size_t(font.m_paragraphId)].first); |
| 2627 |
listener->setFont(font.m_font); |
| 2628 |
if (font.m_linkId!=linkId) { |
| 2629 |
if (linkIsOpen) { |
| 2630 |
listener->closeLink(); |
| 2631 |
linkIsOpen=false; |
| 2632 |
} |
| 2633 |
linkId=font.m_linkId; |
| 2634 |
if (linkId) { |
| 2635 |
auto ref=m_mainParser->getTextLink(linkId); |
| 2636 |
if (!ref.empty()) { |
| 2637 |
MWAWLink link; |
| 2638 |
link.m_HRef=ref.cstr(); |
| 2639 |
listener->openLink(link); |
| 2640 |
linkIsOpen=true; |
| 2641 |
} |
| 2642 |
} |
| 2643 |
} |
| 2644 |
} |
| 2645 |
} |
| 2646 |
unsigned char c=(unsigned char)(input->readULong(1)); |
| 2647 |
f << c; |
| 2648 |
switch (c) { |
| 2649 |
case 0x9: |
| 2650 |
listener->insertTab(); |
| 2651 |
break; |
| 2652 |
case 0xd: |
| 2653 |
if (linkIsOpen) { |
| 2654 |
listener->closeLink(); |
| 2655 |
linkIsOpen=false; |
| 2656 |
} |
| 2657 |
listener->insertEOL(); |
| 2658 |
break; |
| 2659 |
default: |
| 2660 |
if (c<=0x1f) { |
| 2661 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendText: find unexpected char=%x\n", (unsigned int)(c))); |
| 2662 |
} |
| 2663 |
else |
| 2664 |
listener->insertCharacter(c); |
| 2665 |
} |
| 2666 |
} |
| 2667 |
if (linkIsOpen) |
| 2668 |
listener->closeLink(); |
| 2669 |
ascFile.addPos(textEntry.begin()); |
| 2670 |
ascFile.addNote(f.str().c_str()); |
| 2671 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2672 |
return ok; |
| 2673 |
} |
| 2674 |
|
| 2675 |
bool Canvas5Graph::sendEffect(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &shape, |
| 2676 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 2677 |
{ |
| 2678 |
if (!listener || !data.m_stream) { |
| 2679 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendEffect: can not find the listener\n")); |
| 2680 |
return false; |
| 2681 |
} |
| 2682 |
auto &stream=data.getStream(); |
| 2683 |
auto input=stream.input(); |
| 2684 |
auto const &entry=data.m_entry; |
| 2685 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 2686 |
if (!entry.valid() || entry.length()<8 || !input->checkPosition(entry.end())) { |
| 2687 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendEffect: can not find the number of zone\n")); |
| 2688 |
return false; |
| 2689 |
} |
| 2690 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2691 |
long pos=input->tell(); |
| 2692 |
libmwaw::DebugStream f; |
| 2693 |
f << "Entries(Effect):"; |
| 2694 |
for (int i=0; i<2; ++i) { |
| 2695 |
int val=int(input->readLong(i==0 ? 4 : 2)); |
| 2696 |
if (val!=1-i) f << "f" << i << "=" << val << ","; |
| 2697 |
} |
| 2698 |
int N=int(input->readULong(2)); |
| 2699 |
f << "N=" << N << ","; |
| 2700 |
ascFile.addPos(pos); |
| 2701 |
ascFile.addNote(f.str().c_str()); |
| 2702 |
|
| 2703 |
if (N>2) |
| 2704 |
listener->openGroup(local.m_position); |
| 2705 |
for (int i=0; i<N; ++i) { |
| 2706 |
pos=input->tell(); |
| 2707 |
f.str(""); |
| 2708 |
f << "Effect-" << i << ":"; |
| 2709 |
long dLen=input->readLong(4); |
| 2710 |
f << "sz=" << dLen << ","; |
| 2711 |
long endPos=pos+4+dLen; |
| 2712 |
if (endPos<pos+4 || !input->checkPosition(endPos)) { |
| 2713 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendEffect: the length seems bad\n")); |
| 2714 |
f << "###"; |
| 2715 |
ascFile.addPos(pos); |
| 2716 |
ascFile.addNote(f.str().c_str()); |
| 2717 |
break; |
| 2718 |
} |
| 2719 |
ascFile.addPos(pos); |
| 2720 |
ascFile.addNote(f.str().c_str()); |
| 2721 |
std::shared_ptr<Canvas5ImageInternal::VKFLImage> image; |
| 2722 |
if (m_imageParser->readVKFL(data.m_stream, dLen, image) && image) |
| 2723 |
m_imageParser->send(image, listener, shape.m_initialBox, local.m_transform); |
| 2724 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 2725 |
} |
| 2726 |
|
| 2727 |
if (N>2) |
| 2728 |
listener->closeGroup(); |
| 2729 |
return true; |
| 2730 |
} |
| 2731 |
|
| 2732 |
bool Canvas5Graph::sendExtrude(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &shape, |
| 2733 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 2734 |
{ |
| 2735 |
if (!listener || !data.m_stream) { |
| 2736 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendExtrude: can not find the listener\n")); |
| 2737 |
return false; |
| 2738 |
} |
| 2739 |
auto &stream=data.getStream(); |
| 2740 |
auto input=stream.input(); |
| 2741 |
auto const &entry=data.m_entry; |
| 2742 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 2743 |
if (!entry.valid() || entry.length()<1000+48 || !input->checkPosition(entry.end())) { |
| 2744 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendExtrude: can not find the text entry\n")); |
| 2745 |
return false; |
| 2746 |
} |
| 2747 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2748 |
long pos=input->tell(); |
| 2749 |
libmwaw::DebugStream f; |
| 2750 |
f << "Entries(Extrude):"; |
| 2751 |
ascFile.addPos(pos); |
| 2752 |
ascFile.addNote(f.str().c_str()); |
| 2753 |
|
| 2754 |
int val; |
| 2755 |
for (int i=0; i<25; ++i) { |
| 2756 |
// 0: width |
| 2757 |
// 1: height |
| 2758 |
// 2: width[far] |
| 2759 |
// 12: 0, w, h, w2 |
| 2760 |
// 13: w/2, h |
| 2761 |
// |
| 2762 |
|
| 2763 |
pos=input->tell(); |
| 2764 |
f.str(""); |
| 2765 |
f << "Extrude-" << i << ":"; |
| 2766 |
for (int j=0; j<5; ++j) { |
| 2767 |
val=int(input->readULong(1)); |
| 2768 |
input->seek(-1, librevenge::RVNG_SEEK_CUR); |
| 2769 |
if (val==0) { |
| 2770 |
for (int k=0; k<2; ++k) { |
| 2771 |
val=int(input->readLong(4)); |
| 2772 |
if (val) f << "f" << 2*j+k << "=" << val << ","; |
| 2773 |
} |
| 2774 |
} |
| 2775 |
else { |
| 2776 |
double value; |
| 2777 |
bool isNAN; |
| 2778 |
if (!m_mainParser->readDouble(stream, value, isNAN)) { |
| 2779 |
f << "###"; |
| 2780 |
input->seek(pos+8*(j+1), librevenge::RVNG_SEEK_SET); |
| 2781 |
} |
| 2782 |
else |
| 2783 |
f << "g" << j << "=" << value << ","; |
| 2784 |
} |
| 2785 |
} |
| 2786 |
ascFile.addPos(pos); |
| 2787 |
ascFile.addNote(f.str().c_str()); |
| 2788 |
input->seek(pos+40, librevenge::RVNG_SEEK_SET); |
| 2789 |
} |
| 2790 |
pos=input->tell(); |
| 2791 |
f.str(""); |
| 2792 |
f << "Extrude-A:"; |
| 2793 |
int N=0; |
| 2794 |
for (int i=0; i<12; ++i) { |
| 2795 |
val=int(input->readLong(4)); |
| 2796 |
if (!val) continue; |
| 2797 |
if (i==4) { |
| 2798 |
N=val; |
| 2799 |
f << "N=" << N << ","; |
| 2800 |
} |
| 2801 |
else |
| 2802 |
f << "f" << i << "=" << val << ","; |
| 2803 |
} |
| 2804 |
if (N<2 || 1048+N*24<1048 || 1048+N*24>entry.length()) { |
| 2805 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendExtrude: the number of points seems bad\n")); |
| 2806 |
f << "###"; |
| 2807 |
ascFile.addPos(pos); |
| 2808 |
ascFile.addNote(f.str().c_str()); |
| 2809 |
return false; |
| 2810 |
} |
| 2811 |
ascFile.addPos(pos); |
| 2812 |
ascFile.addNote(f.str().c_str()); |
| 2813 |
MWAWPosition const &position=local.m_position; |
| 2814 |
MWAWVec2f origin=position.origin()+0.5*position.size(); |
| 2815 |
MWAWVec2f dir=0.5*position.size(); |
| 2816 |
bool ok=true; |
| 2817 |
|
| 2818 |
std::vector<MWAWVec2f> pts; |
| 2819 |
for (int i=0; i<N; ++i) { |
| 2820 |
pos=input->tell(); |
| 2821 |
f.str(""); |
| 2822 |
f << "Extrude-B" << i << ":"; |
| 2823 |
float coords[]= {0,0}; |
| 2824 |
for (int j=0; j<2; ++j) { |
| 2825 |
double value; |
| 2826 |
bool isNAN; |
| 2827 |
if (!m_mainParser->readDouble(stream, value, isNAN) || value<-2 || value>2) { |
| 2828 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendExtrude: can not read a coordinate\n")); |
| 2829 |
f << "###"; |
| 2830 |
input->seek(pos+8*(j+1), librevenge::RVNG_SEEK_SET); |
| 2831 |
ok=false; |
| 2832 |
} |
| 2833 |
else { |
| 2834 |
coords[j]=float(value); |
| 2835 |
f << "g" << j << "=" << value << ","; |
| 2836 |
} |
| 2837 |
} |
| 2838 |
pts.push_back(origin+MWAWVec2f(coords[0]*dir[0], coords[1]*dir[1])); |
| 2839 |
for (int j=0; j<2; ++j) { |
| 2840 |
val=int(input->readLong(4)); |
| 2841 |
if (!val) continue; |
| 2842 |
f << "f" << i << "=" << val << ","; |
| 2843 |
} |
| 2844 |
ascFile.addPos(pos); |
| 2845 |
ascFile.addNote(f.str().c_str()); |
| 2846 |
input->seek(pos+24, librevenge::RVNG_SEEK_SET); |
| 2847 |
} |
| 2848 |
if (input->tell()<entry.end()) { |
| 2849 |
ascFile.addPos(input->tell()); |
| 2850 |
ascFile.addNote("Extrude-End:"); |
| 2851 |
} |
| 2852 |
if (!ok) |
| 2853 |
return false; |
| 2854 |
|
| 2855 |
// FIXME: sometimes there is multiple contours in this list of points ... |
| 2856 |
static bool first=true; |
| 2857 |
if (first) { |
| 2858 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendExtrude: sorry, sending extrude's shape is not reliable\n")); |
| 2859 |
first=false; |
| 2860 |
} |
| 2861 |
auto fShape=MWAWGraphicShape::polygon(shape.m_initialBox); |
| 2862 |
fShape.m_vertices=pts; |
| 2863 |
send(listener, fShape, local.m_transform, local.m_style); |
| 2864 |
return true; |
| 2865 |
} |
| 2866 |
|
| 2867 |
bool Canvas5Graph::sendGIF(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &shape, |
| 2868 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 2869 |
{ |
| 2870 |
if (!listener || !data.m_stream) { |
| 2871 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendGIF: can not find the listener\n")); |
| 2872 |
return false; |
| 2873 |
} |
| 2874 |
auto &stream=data.getStream(); |
| 2875 |
auto input=stream.input(); |
| 2876 |
auto const &entry=data.m_entry; |
| 2877 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 2878 |
if (!entry.valid() || entry.length()<104 || !input->checkPosition(entry.end())) { |
| 2879 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendGIF: can not find the number of zone\n")); |
| 2880 |
return false; |
| 2881 |
} |
| 2882 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2883 |
long pos=input->tell(); |
| 2884 |
libmwaw::DebugStream f; |
| 2885 |
f << "Entries(ANGF):"; |
| 2886 |
int val=int(input->readULong(4)); |
| 2887 |
if (val) f << "id=" << std::hex << val << std::dec << ","; |
| 2888 |
auto len=input->readLong(4); |
| 2889 |
if (104+len<104 || 104+len>entry.length()) { |
| 2890 |
f << "###"; |
| 2891 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendGIF: can not find the GIF length\n")); |
| 2892 |
ascFile.addPos(pos); |
| 2893 |
ascFile.addNote(f.str().c_str()); |
| 2894 |
return false; |
| 2895 |
} |
| 2896 |
ascFile.addDelimiter(input->tell(),'|'); |
| 2897 |
input->seek(pos+8+80, librevenge::RVNG_SEEK_SET); |
| 2898 |
int dim[2]; |
| 2899 |
for (auto &d : dim) |
| 2900 |
d = int(input->readLong(4)); |
| 2901 |
f << "dim=" << MWAWVec2i(dim[0],dim[1]) << ","; |
| 2902 |
val=int(input->readLong(4)); |
| 2903 |
if (val!=1) |
| 2904 |
f << "f0=" << val << ","; |
| 2905 |
val=int(input->readLong(4)); |
| 2906 |
if (val!=4) |
| 2907 |
f << "f0=" << val << ","; |
| 2908 |
ascFile.addPos(pos); |
| 2909 |
ascFile.addNote(f.str().c_str()); |
| 2910 |
|
| 2911 |
if (!len) { |
| 2912 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendGIF: can not find the GIF picture\n")); |
| 2913 |
} |
| 2914 |
else { |
| 2915 |
pos=input->tell(); |
| 2916 |
librevenge::RVNGBinaryData gif; |
| 2917 |
if (!input->readDataBlock(len, gif)) { |
| 2918 |
MWAW_DEBUG_MSG(("Canvas5Image::sendGIF: oops can not retrieve the gif\n")); |
| 2919 |
ascFile.addPos(pos); |
| 2920 |
ascFile.addNote("ANGF:###"); |
| 2921 |
return false; |
| 2922 |
} |
| 2923 |
|
| 2924 |
ascFile.skipZone(pos, pos+len-1); |
| 2925 |
#ifdef DEBUG_WITH_FILES |
| 2926 |
std::stringstream s; |
| 2927 |
static int index=0; |
| 2928 |
s << "gif" << ++index << ".gif"; |
| 2929 |
libmwaw::Debug::dumpFile(gif, s.str().c_str()); |
| 2930 |
#endif |
| 2931 |
|
| 2932 |
MWAWEmbeddedObject obj(gif, "image/gif"); |
| 2933 |
MWAWTransformation transf; |
| 2934 |
float rotation=0; |
| 2935 |
MWAWVec2f shearing; |
| 2936 |
if (!local.m_transform.isIdentity() && local.m_transform.decompose(rotation,shearing,transf,shape.m_initialBox.center())) { |
| 2937 |
MWAWBox2f shapeBox=transf*shape.m_initialBox; |
| 2938 |
MWAWPosition posi(shapeBox[0], shapeBox.size(), librevenge::RVNG_POINT); |
| 2939 |
posi.m_anchorTo = MWAWPosition::Page; |
| 2940 |
MWAWGraphicStyle style(local.m_style); |
| 2941 |
style.m_rotate=-rotation; |
| 2942 |
listener->insertPicture(posi, obj, style); |
| 2943 |
} |
| 2944 |
else |
| 2945 |
listener->insertPicture(local.m_position, obj, local.m_style); |
| 2946 |
} |
| 2947 |
|
| 2948 |
while (!input->tell()+4<entry.end()) { |
| 2949 |
// find 4 blocks with size 28 |
| 2950 |
pos=input->tell(); |
| 2951 |
len=input->readLong(4); |
| 2952 |
if (pos+len<pos+4 || pos+len>entry.end()) { |
| 2953 |
input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 2954 |
break; |
| 2955 |
} |
| 2956 |
ascFile.addPos(pos); |
| 2957 |
ascFile.addNote("ANGF-Dt:"); |
| 2958 |
input->seek(pos+len, librevenge::RVNG_SEEK_SET); |
| 2959 |
} |
| 2960 |
|
| 2961 |
pos=input->tell(); |
| 2962 |
if (pos!=entry.end()) { |
| 2963 |
MWAW_DEBUG_MSG(("Canvas5Image::sendGIF: find extra data\n")); |
| 2964 |
ascFile.addPos(pos); |
| 2965 |
ascFile.addNote("ANGF[extra]:###"); |
| 2966 |
} |
| 2967 |
return true; |
| 2968 |
} |
| 2969 |
|
| 2970 |
bool Canvas5Graph::sendTechnical(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &shape, |
| 2971 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 2972 |
{ |
| 2973 |
if (!listener || !data.m_stream) { |
| 2974 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not find the listener\n")); |
| 2975 |
return false; |
| 2976 |
} |
| 2977 |
auto &stream=data.getStream(); |
| 2978 |
auto input=stream.input(); |
| 2979 |
auto const &entry=data.m_entry; |
| 2980 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 2981 |
if (!entry.valid() || entry.length()<8 || !input->checkPosition(entry.end())) { |
| 2982 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not find the number of zone\n")); |
| 2983 |
return false; |
| 2984 |
} |
| 2985 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2986 |
long pos=input->tell(); |
| 2987 |
libmwaw::DebugStream f; |
| 2988 |
f << "Entries(Technical):"; |
| 2989 |
int N[2]; |
| 2990 |
f << "N=["; |
| 2991 |
for (auto &n : N) { |
| 2992 |
n=m_mainParser->readInteger(stream, 8); |
| 2993 |
f << n << ","; |
| 2994 |
} |
| 2995 |
|
| 2996 |
bool isGroupOpened=false; |
| 2997 |
if (N[0]>1) { |
| 2998 |
isGroupOpened=true; |
| 2999 |
listener->openGroup(local.m_position); |
| 3000 |
} |
| 3001 |
ascFile.addPos(pos); |
| 3002 |
ascFile.addNote(f.str().c_str()); |
| 3003 |
for (int poly=0; poly<N[0]; ++poly) { |
| 3004 |
f.str(""); |
| 3005 |
pos=input->tell(); |
| 3006 |
f << "Technical-T" << poly << ":"; |
| 3007 |
if (pos+8 > data.m_entry.end()) { |
| 3008 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read a spline\n")); |
| 3009 |
f << "###"; |
| 3010 |
ascFile.addPos(pos); |
| 3011 |
ascFile.addNote(f.str().c_str()); |
| 3012 |
if (isGroupOpened) |
| 3013 |
listener->closeGroup(); |
| 3014 |
return false; |
| 3015 |
} |
| 3016 |
int N1[2]; // id, num pt |
| 3017 |
f << "N=["; |
| 3018 |
for (auto &n : N1) { |
| 3019 |
double value; |
| 3020 |
bool isNan; |
| 3021 |
if (!m_mainParser->readDouble(stream, value, isNan)) { |
| 3022 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read a generic number\n")); |
| 3023 |
f << "###"; |
| 3024 |
ascFile.addPos(pos); |
| 3025 |
ascFile.addNote(f.str().c_str()); |
| 3026 |
if (isGroupOpened) |
| 3027 |
listener->closeGroup(); |
| 3028 |
return false; |
| 3029 |
} |
| 3030 |
n=int(value+0.2); |
| 3031 |
f << n << ","; |
| 3032 |
} |
| 3033 |
f << "],"; |
| 3034 |
if (N1[1]<0 || (data.m_entry.end()-pos-8)/16<N1[1] || pos+8+16*N1[1] > data.m_entry.end()) { |
| 3035 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read a sub shape\n")); |
| 3036 |
f << "###"; |
| 3037 |
ascFile.addPos(pos); |
| 3038 |
ascFile.addNote(f.str().c_str()); |
| 3039 |
if (isGroupOpened) |
| 3040 |
listener->closeGroup(); |
| 3041 |
return false; |
| 3042 |
} |
| 3043 |
|
| 3044 |
f << "pts=["; |
| 3045 |
std::vector<MWAWVec2f> points; |
| 3046 |
for (int p=0; p<N1[1]; ++p) { |
| 3047 |
double coord[2]; |
| 3048 |
for (auto &c : coord) { |
| 3049 |
bool isNan; |
| 3050 |
long actPos=input->tell(); |
| 3051 |
if (!m_mainParser->readDouble(stream, c, isNan)) { |
| 3052 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read a number\n")); |
| 3053 |
f << "###"; |
| 3054 |
input->seek(actPos+8, librevenge::RVNG_SEEK_SET); |
| 3055 |
c=0; |
| 3056 |
} |
| 3057 |
} |
| 3058 |
points.push_back(MWAWVec2f(float(coord[1]), float(coord[0]))); |
| 3059 |
f << points.back() << ","; |
| 3060 |
} |
| 3061 |
f << "],"; |
| 3062 |
|
| 3063 |
auto const orig=shape.m_initialBox[0]; |
| 3064 |
auto const dir=shape.m_initialBox.size(); |
| 3065 |
for (auto &p : points) |
| 3066 |
p=orig+MWAWVec2f(p[0]*dir[0],p[1]*dir[1]); |
| 3067 |
if (points.size()<4) { |
| 3068 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: the spline seems bad\n")); |
| 3069 |
f << "###"; |
| 3070 |
} |
| 3071 |
else { |
| 3072 |
auto finalShape=MWAWGraphicShape::path(shape.m_initialBox); |
| 3073 |
std::vector<MWAWGraphicShape::PathData> &path=finalShape.m_path; |
| 3074 |
path.push_back(MWAWGraphicShape::PathData('M', points[0])); |
| 3075 |
for (size_t p=3; p < points.size(); p+=4) { |
| 3076 |
if (p>=4 && points[p-4]!=points[p-3]) |
| 3077 |
path.push_back(MWAWGraphicShape::PathData('M', points[p-3])); |
| 3078 |
bool hasFirstC=points[p-3]!=points[p-2]; |
| 3079 |
bool hasSecondC=points[p-1]!=points[p]; |
| 3080 |
if (!hasFirstC && !hasSecondC) |
| 3081 |
path.push_back(MWAWGraphicShape::PathData('L', points[p])); |
| 3082 |
else |
| 3083 |
path.push_back(MWAWGraphicShape::PathData('C', points[p], points[p-2], points[p-1])); |
| 3084 |
} |
| 3085 |
if (local.m_style.hasSurface()) |
| 3086 |
path.push_back(MWAWGraphicShape::PathData('Z')); |
| 3087 |
send(listener, finalShape, local.m_transform, local.m_style); |
| 3088 |
} |
| 3089 |
|
| 3090 |
ascFile.addPos(pos); |
| 3091 |
ascFile.addNote(f.str().c_str()); |
| 3092 |
} |
| 3093 |
if (isGroupOpened) |
| 3094 |
listener->closeGroup(); |
| 3095 |
|
| 3096 |
pos=input->tell(); |
| 3097 |
f.str(""); |
| 3098 |
f << "Technical-A:"; |
| 3099 |
if (pos+16>entry.end()) { |
| 3100 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read the last part\n")); |
| 3101 |
f << "###"; |
| 3102 |
ascFile.addPos(pos); |
| 3103 |
ascFile.addNote(f.str().c_str()); |
| 3104 |
return false; |
| 3105 |
} |
| 3106 |
for (int i=0; i<6; ++i) { |
| 3107 |
int val=int(input->readLong(2)); |
| 3108 |
int const expected[]= {0,0,0,0,0x6ef0,1}; |
| 3109 |
if (val==expected[i]) |
| 3110 |
continue; |
| 3111 |
if (i==3) |
| 3112 |
f << "fl=" << std::hex << val << std::dec << ","; // 5X01 |
| 3113 |
else |
| 3114 |
f << "f" << i << "=" << val << ","; |
| 3115 |
} |
| 3116 |
int n=int(input->readULong(4)); |
| 3117 |
f << "N=" << n << ","; |
| 3118 |
ascFile.addPos(pos); |
| 3119 |
ascFile.addNote(f.str().c_str()); |
| 3120 |
|
| 3121 |
for (int i=0; i<n; ++i) { |
| 3122 |
pos=input->tell(); |
| 3123 |
f.str(""); |
| 3124 |
f << "Technical-A" << i << ":"; |
| 3125 |
if (pos+12>entry.end()) { |
| 3126 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read a type block\n")); |
| 3127 |
f << "###"; |
| 3128 |
ascFile.addPos(pos); |
| 3129 |
ascFile.addNote(f.str().c_str()); |
| 3130 |
return false; |
| 3131 |
} |
| 3132 |
unsigned type=unsigned(input->readULong(4)); |
| 3133 |
f << Canvas5Structure::getString(type) << ","; |
| 3134 |
int val=int(input->readLong(4)); |
| 3135 |
if (val) |
| 3136 |
f << "id=" << val << ","; |
| 3137 |
long len=input->readLong(4); |
| 3138 |
long endPos=pos+12+len; |
| 3139 |
if (endPos<pos+12 || endPos>entry.end()) { |
| 3140 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: can not read a type block\n")); |
| 3141 |
f << "###"; |
| 3142 |
ascFile.addPos(pos); |
| 3143 |
ascFile.addNote(f.str().c_str()); |
| 3144 |
return false; |
| 3145 |
} |
| 3146 |
switch (type) { |
| 3147 |
case 0x42507473: { //BPts copy of main zone of points but store with int |
| 3148 |
libmwaw::DebugStream f2; |
| 3149 |
while (input->tell()+8<endPos) { |
| 3150 |
long actPos=input->tell(); |
| 3151 |
f2.str(""); |
| 3152 |
f2 << "Technical-bPts:"; |
| 3153 |
f2 << "id=" << input->readLong(4) << ","; |
| 3154 |
int nbPts=int(input->readLong(4)); |
| 3155 |
f2 << "N=" << nbPts << ","; |
| 3156 |
if (nbPts<4 || (endPos-actPos-8)/8 < nbPts) { |
| 3157 |
input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 3158 |
break; |
| 3159 |
} |
| 3160 |
f2 << "pts=["; |
| 3161 |
for (int j=0; j<nbPts; ++j) { |
| 3162 |
float coord[2]; |
| 3163 |
for (auto &c : coord) c=float(input->readLong(4))/65536; |
| 3164 |
f2 << MWAWVec2f(coord[0],coord[1]) << ","; |
| 3165 |
} |
| 3166 |
f2 << "],"; |
| 3167 |
ascFile.addPos(actPos); |
| 3168 |
ascFile.addNote(f2.str().c_str()); |
| 3169 |
} |
| 3170 |
if (input->tell()!=endPos) { |
| 3171 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[bPts]: can not read some data\n")); |
| 3172 |
ascFile.addPos(input->tell()); |
| 3173 |
ascFile.addNote("Technical-bPts:###"); |
| 3174 |
} |
| 3175 |
break; |
| 3176 |
} |
| 3177 |
case 0x4374726c: // Ctrl |
| 3178 |
if (long(int(len/4))*4!=len || (len%4)!=0) { |
| 3179 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[Ctrl]: unexpected length\n")); |
| 3180 |
f << "###"; |
| 3181 |
break; |
| 3182 |
} |
| 3183 |
f << "val=["; // [4] or [1,2,3] |
| 3184 |
for (int j=0; j<int(len)/4; ++j) |
| 3185 |
f << input->readLong(4) << ","; |
| 3186 |
f << "],"; |
| 3187 |
break; |
| 3188 |
case 0x44697263: // Dirc |
| 3189 |
if (len!=4) { |
| 3190 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[Dirc]: unexpected length\n")); |
| 3191 |
f << "###"; |
| 3192 |
break; |
| 3193 |
} |
| 3194 |
f << "f0=" << input->readLong(4) << ","; // 4 |
| 3195 |
break; |
| 3196 |
case 0x53686450: // ShdP |
| 3197 |
if (long(int(len/4))*4!=len || (len%4)!=0) { |
| 3198 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[ShdP]: unexpected length\n")); |
| 3199 |
f << "###"; |
| 3200 |
break; |
| 3201 |
} |
| 3202 |
f << "val=["; // [2] or [2,3] |
| 3203 |
for (int j=0; j<int(len)/4; ++j) |
| 3204 |
f << input->readLong(4) << ","; |
| 3205 |
f << "],"; |
| 3206 |
break; |
| 3207 |
case 0x53796d6d: // Symm |
| 3208 |
if (len!=4) { |
| 3209 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[Symm]: unexpected length\n")); |
| 3210 |
f << "###"; |
| 3211 |
break; |
| 3212 |
} |
| 3213 |
f << "f0=" << input->readLong(4) << ","; // 0 |
| 3214 |
break; |
| 3215 |
case 0x54787450: // TxtP |
| 3216 |
if (len!=4) { |
| 3217 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[TxtP]: unexpected length\n")); |
| 3218 |
f << "###"; |
| 3219 |
break; |
| 3220 |
} |
| 3221 |
f << "f0=" << input->readLong(4) << ","; // 1 |
| 3222 |
break; |
| 3223 |
case 0x57547874: // WTxt |
| 3224 |
if (len!=4) { |
| 3225 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[WTxt]: unexpected length\n")); |
| 3226 |
f << "###"; |
| 3227 |
break; |
| 3228 |
} |
| 3229 |
f << "f0=" << input->readLong(4) << ","; // 0 |
| 3230 |
break; |
| 3231 |
case 0x6b696e64: // kind |
| 3232 |
if (len!=4) { |
| 3233 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical[kind]: unexpected length\n")); |
| 3234 |
f << "###"; |
| 3235 |
break; |
| 3236 |
} |
| 3237 |
f << input->readLong(4) << ","; |
| 3238 |
break; |
| 3239 |
default: |
| 3240 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendTechnical: unexpected type=%s\n", Canvas5Structure::getString(type).c_str())); |
| 3241 |
f << "###"; |
| 3242 |
break; |
| 3243 |
} |
| 3244 |
if (input->tell()!=endPos) { |
| 3245 |
ascFile.addDelimiter(input->tell(),'|'); |
| 3246 |
input->seek(endPos, librevenge::RVNG_SEEK_SET); |
| 3247 |
} |
| 3248 |
ascFile.addPos(pos); |
| 3249 |
ascFile.addNote(f.str().c_str()); |
| 3250 |
} |
| 3251 |
|
| 3252 |
return true; |
| 3253 |
} |
| 3254 |
|
| 3255 |
bool Canvas5Graph::sendCurveText(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &/*shape*/, |
| 3256 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 3257 |
{ |
| 3258 |
if (!listener || !data.m_stream) { |
| 3259 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendCurveText: can not find the listener\n")); |
| 3260 |
return false; |
| 3261 |
} |
| 3262 |
auto &stream=data.getStream(); |
| 3263 |
auto input=stream.input(); |
| 3264 |
int const vers=version(); |
| 3265 |
auto const &entry=data.m_entry; |
| 3266 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 3267 |
int const headerSz=vers<9 ? 176 : 344; |
| 3268 |
if (!entry.valid() || entry.length()<headerSz || !input->checkPosition(entry.end())) { |
| 3269 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendCurveText: can not find the text entry\n")); |
| 3270 |
return false; |
| 3271 |
} |
| 3272 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 3273 |
long pos=input->tell(); |
| 3274 |
libmwaw::DebugStream f; |
| 3275 |
f << "Entries(CurveTxt):"; |
| 3276 |
|
| 3277 |
input->seek(pos+(vers<9 ? 24 : 40), librevenge::RVNG_SEEK_SET); |
| 3278 |
ascFile.addDelimiter(input->tell(),'|'); |
| 3279 |
f << "unk=["; |
| 3280 |
MWAWVec2f origin=local.m_position.origin(); |
| 3281 |
for (int p=0; p<9; ++p) { // pt7: origin bdbox max, pt8 origin bdbox min |
| 3282 |
float dim[2]; |
| 3283 |
for (auto &d : dim) d=float(m_mainParser->readDouble(stream, vers<9 ? 4 : 8)); |
| 3284 |
if (vers>=9) |
| 3285 |
std::swap(dim[0],dim[1]); |
| 3286 |
f << MWAWVec2f(dim[1],dim[0]) << ","; |
| 3287 |
if (p==8) origin=MWAWVec2f(dim[1],dim[0]); // checkme: not always fine |
| 3288 |
} |
| 3289 |
f << "],"; |
| 3290 |
int N=int(input->readULong(2)), val; |
| 3291 |
f << "N=" << N << ","; |
| 3292 |
for (int i=0; i<4; ++i) { // g0: current style ? |
| 3293 |
val=int(input->readLong(2)); |
| 3294 |
if (val!=(i==0 ? 1 : 0)) |
| 3295 |
f << "g" << i << "=" << val << ","; |
| 3296 |
} |
| 3297 |
int nFonts=int(input->readULong(2)); |
| 3298 |
f << "nFonts=" << nFonts << ","; |
| 3299 |
int const fontSize=vers<9 ? 72 : 120; |
| 3300 |
int const textSize=vers<9 ? 60 : 112; |
| 3301 |
if (headerSz+nFonts*fontSize+N*textSize<0 || headerSz+nFonts*fontSize+N*textSize>entry.length()) { |
| 3302 |
f << "###"; |
| 3303 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendCurveText: N seems bad\n")); |
| 3304 |
return false; |
| 3305 |
} |
| 3306 |
input->seek(pos+headerSz, librevenge::RVNG_SEEK_SET); |
| 3307 |
ascFile.addPos(pos); |
| 3308 |
ascFile.addNote(f.str().c_str()); |
| 3309 |
|
| 3310 |
std::vector<Canvas5StyleManager::CharStyle> fonts; |
| 3311 |
fonts.resize(size_t(nFonts)); |
| 3312 |
for (size_t i=0; i<size_t(nFonts); ++i) { |
| 3313 |
pos=input->tell(); |
| 3314 |
f.str(""); |
| 3315 |
f << "CurveTxt-F" << i+1 << ":"; |
| 3316 |
for (int j=0; j<(vers<9 ? 2 : 4); ++j) { // f0: small number |
| 3317 |
val=int(input->readLong(4)); |
| 3318 |
if (val) f << "f" << j << "=" << val << ","; |
| 3319 |
} |
| 3320 |
ascFile.addPos(pos); |
| 3321 |
ascFile.addNote(f.str().c_str()); |
| 3322 |
m_styleManager->readCharStyle(stream, int(i+1), fonts[i]); |
| 3323 |
for (int j=0; j<(vers<9 ? 2 : 4); ++j) { |
| 3324 |
val=int(input->readLong(2)); |
| 3325 |
if (val) f << "f" << j+4 << "=" << val << ","; |
| 3326 |
} |
| 3327 |
} |
| 3328 |
|
| 3329 |
if (N>1) |
| 3330 |
listener->openGroup(local.m_position); |
| 3331 |
auto fontConverter=m_parserState->m_fontConverter; |
| 3332 |
MWAWGraphicStyle charStyle=MWAWGraphicStyle::emptyStyle(); |
| 3333 |
MWAWPosition charPos(local.m_position); |
| 3334 |
for (int i=0; i<N; ++i) { |
| 3335 |
pos=input->tell(); |
| 3336 |
f.str(""); |
| 3337 |
f << "CurveTxt-" << i << ":"; |
| 3338 |
int fId=int(input->readULong(2)); |
| 3339 |
f << "F" << fId+1 << ","; |
| 3340 |
MWAWFont font; |
| 3341 |
if (fId>=0 && fId<int(nFonts)) |
| 3342 |
font=fonts[size_t(fId)].m_font; |
| 3343 |
else { |
| 3344 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendCurveText: find unknow fonts\n")); |
| 3345 |
f << "###"; |
| 3346 |
} |
| 3347 |
librevenge::RVNGString text; |
| 3348 |
char c=char(input->readULong(1)); |
| 3349 |
int unicode = fontConverter->unicode(font.id(), (unsigned char)(c)); |
| 3350 |
if (unicode == -1) { |
| 3351 |
if (c < 0x20) { |
| 3352 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendCurveText: Find odd char %x\n", static_cast<unsigned int>(c))); |
| 3353 |
} |
| 3354 |
else |
| 3355 |
text.append(c); |
| 3356 |
} |
| 3357 |
else |
| 3358 |
libmwaw::appendUnicode(uint32_t(unicode), text); |
| 3359 |
if (!text.empty()) |
| 3360 |
f << text.cstr() << ","; |
| 3361 |
input->seek(1, librevenge::RVNG_SEEK_CUR); |
| 3362 |
val=int(input->readULong(4)); |
| 3363 |
if (val!=0x17c94) |
| 3364 |
f << "f0=" << val << ","; |
| 3365 |
float angle=float(m_mainParser->readDouble(stream, vers<9 ? 4 : 8)); |
| 3366 |
f << "angle=" << angle << ","; |
| 3367 |
MWAWVec2f points[5]; |
| 3368 |
f << "pts=["; |
| 3369 |
for (auto &pt : points) { // decal, then a box? |
| 3370 |
float pts[2]; |
| 3371 |
for (auto &p : pts) p=float(m_mainParser->readDouble(stream, vers<9 ? 4 : 8)); |
| 3372 |
if (vers<9) |
| 3373 |
pt= MWAWVec2f(pts[1],pts[0]); |
| 3374 |
else |
| 3375 |
pt= MWAWVec2f(pts[0],pts[1]); |
| 3376 |
f << pt << ","; |
| 3377 |
} |
| 3378 |
f << "],"; |
| 3379 |
ascFile.addPos(pos); |
| 3380 |
ascFile.addNote(f.str().c_str()); |
| 3381 |
input->seek(pos+textSize, librevenge::RVNG_SEEK_SET); |
| 3382 |
|
| 3383 |
if (text.empty()) continue; |
| 3384 |
std::shared_ptr<MWAWSubDocument> doc(new Canvas5GraphInternal::SubDocument(*this, input, text, font)); |
| 3385 |
|
| 3386 |
MWAWTransformation transf; |
| 3387 |
float rotation=0; |
| 3388 |
MWAWVec2f shearing; |
| 3389 |
if (!local.m_transform.isIdentity() && local.m_transform.decompose(rotation,shearing,transf,origin+0.5*points[2]+0.5*points[3])) { |
| 3390 |
MWAWBox2f shapeBox=transf*MWAWBox2f(origin+points[2],origin+points[3]); |
| 3391 |
charPos.setOrigin(shapeBox[0]); |
| 3392 |
charPos.setSize(shapeBox[1]-shapeBox[0]); |
| 3393 |
charStyle.m_rotate=-angle-rotation; |
| 3394 |
} |
| 3395 |
else { |
| 3396 |
charPos.setOrigin(origin+points[2]); |
| 3397 |
charPos.setSize(points[3]-points[2]); |
| 3398 |
charStyle.m_rotate=-angle; |
| 3399 |
} |
| 3400 |
listener->insertTextBox(charPos, doc, charStyle); |
| 3401 |
} |
| 3402 |
if (N>1) |
| 3403 |
listener->closeGroup(); |
| 3404 |
|
| 3405 |
pos=input->tell(); |
| 3406 |
f.str(""); |
| 3407 |
f << "CurveTxt-End:"; |
| 3408 |
ascFile.addPos(pos); |
| 3409 |
ascFile.addNote(f.str().c_str()); |
| 3410 |
return true; |
| 3411 |
} |
| 3412 |
|
| 3413 |
bool Canvas5Graph::sendDimension(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &shape, |
| 3414 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 3415 |
{ |
| 3416 |
if (!listener || !data.m_stream || version()>=9) { |
| 3417 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension: can not find the listener\n")); |
| 3418 |
return false; |
| 3419 |
} |
| 3420 |
auto &stream=data.getStream(); |
| 3421 |
auto input=stream.input(); |
| 3422 |
auto const &entry=data.m_entry; |
| 3423 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 3424 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension: can not find the shape enntry\n")); |
| 3425 |
return false; |
| 3426 |
} |
| 3427 |
|
| 3428 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 3429 |
libmwaw::DebugStream f; |
| 3430 |
f << "Entries(Dimension):"; |
| 3431 |
if (entry.length()<420) { |
| 3432 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension: the data seens too short\n")); |
| 3433 |
f << "###sz"; |
| 3434 |
ascFile.addPos(entry.begin()); |
| 3435 |
ascFile.addNote(f.str().c_str()); |
| 3436 |
return false; |
| 3437 |
} |
| 3438 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 3439 |
int type=int(input->readLong(2)); // 1-15 |
| 3440 |
if (type) f << "type=" << type << ","; |
| 3441 |
int val=int(input->readLong(2)); // 0 |
| 3442 |
if (val) f << "f0=" << val << ","; |
| 3443 |
f << "points=["; |
| 3444 |
std::vector<MWAWVec2f> pts; |
| 3445 |
for (int i=0; i<18; ++i) { |
| 3446 |
float dims[2]; |
| 3447 |
// fract type: between -2 and 2 |
| 3448 |
for (auto &d : dims) d=4*float(input->readLong(4))/65536.f/65536.f; |
| 3449 |
pts.push_back(MWAWVec2f(dims[1],dims[0])); |
| 3450 |
f << pts.back() << ","; |
| 3451 |
} |
| 3452 |
f << "],"; |
| 3453 |
ascFile.addPos(entry.begin()); |
| 3454 |
ascFile.addNote(f.str().c_str()); |
| 3455 |
|
| 3456 |
long posi=input->tell(); |
| 3457 |
f.str(""); |
| 3458 |
f << "Dimension[data1]:"; |
| 3459 |
input->seek(posi+40, librevenge::RVNG_SEEK_SET); |
| 3460 |
ascFile.addDelimiter(input->tell(),'|'); |
| 3461 |
bool arrowInside=true; |
| 3462 |
bool hasFrame=false; |
| 3463 |
for (int i=0; i<3; ++i) { |
| 3464 |
val=int(input->readLong(2)); |
| 3465 |
int const expected[]= {1,0,0}; |
| 3466 |
if (val==expected[i]) continue; |
| 3467 |
char const *wh[]= {"arrows[inside]", "text[centered]", "frame[text]"}; |
| 3468 |
if (val==0) { |
| 3469 |
if (i==0) arrowInside=false; |
| 3470 |
f << wh[i] << "=off,"; |
| 3471 |
} |
| 3472 |
else if (val==1) { |
| 3473 |
if (i==2) hasFrame=true; |
| 3474 |
f << wh[i] << "=on,"; |
| 3475 |
} |
| 3476 |
else |
| 3477 |
f << "###" << wh[i] << "=" << val << ","; |
| 3478 |
} |
| 3479 |
for (int i=0; i<5; ++i) { |
| 3480 |
val=int(input->readLong(2)); |
| 3481 |
int const expected[]= { 1, 1, 1, 0, 3}; |
| 3482 |
if (val==expected[i]) continue; |
| 3483 |
char const *wh[]= { |
| 3484 |
"leader", // none, left, right, automatic |
| 3485 |
nullptr, |
| 3486 |
"display[text]", // hori, hori/90, aligned, above, below |
| 3487 |
"what", // 1: line, 3: arc? |
| 3488 |
"precision", // X, X.X, X.XX, X.XXX, X.XXXX, X X/X |
| 3489 |
}; |
| 3490 |
if (i==3 && val==3) |
| 3491 |
f << "print[angle],"; |
| 3492 |
else if (wh[i]) |
| 3493 |
f << wh[i] << "=" << val << ","; |
| 3494 |
else |
| 3495 |
f << "f" << i << "=" << val << ","; |
| 3496 |
} |
| 3497 |
f << "tolerances=["; |
| 3498 |
for (int i=0; i<3; ++i) f << float(input->readLong(4))/65536.f << ","; |
| 3499 |
f << "],"; |
| 3500 |
val=int(input->readLong(2)); |
| 3501 |
if (val!=1) |
| 3502 |
f << "f6=" << val << ","; |
| 3503 |
librevenge::RVNGString format; |
| 3504 |
long actPos=input->tell(); |
| 3505 |
if (m_mainParser->readString(stream, format, 19)) |
| 3506 |
f << "unit=" << format.cstr() << ","; |
| 3507 |
else { |
| 3508 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension: can not read the format's name\n")); |
| 3509 |
f << "###format,"; |
| 3510 |
input->seek(actPos+20, librevenge::RVNG_SEEK_SET); |
| 3511 |
} |
| 3512 |
ascFile.addDelimiter(input->tell(), '|'); |
| 3513 |
input->seek(posi+162, librevenge::RVNG_SEEK_SET); |
| 3514 |
ascFile.addPos(posi); |
| 3515 |
ascFile.addNote(f.str().c_str()); |
| 3516 |
|
| 3517 |
posi=input->tell(); |
| 3518 |
f.str(""); |
| 3519 |
f << "Dimension-format:"; |
| 3520 |
input->seek(posi+22, librevenge::RVNG_SEEK_SET); |
| 3521 |
ascFile.addDelimiter(input->tell(), '|'); |
| 3522 |
if (m_mainParser->readString(stream, format, 19)) |
| 3523 |
f << "name=" << format.cstr() << ","; |
| 3524 |
else { |
| 3525 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension: can not read the format's name\n")); |
| 3526 |
f << "###format,"; |
| 3527 |
} |
| 3528 |
input->seek(posi+22+20, librevenge::RVNG_SEEK_SET); |
| 3529 |
ascFile.addDelimiter(input->tell(), '|'); |
| 3530 |
ascFile.addPos(posi); |
| 3531 |
ascFile.addNote(f.str().c_str()); |
| 3532 |
|
| 3533 |
MWAWVec2f bDir=shape.m_initialBox.size(); |
| 3534 |
for (auto &pt : pts) |
| 3535 |
pt=shape.m_initialBox[0]+MWAWVec2f(pt[0]*bDir[0], pt[1]*bDir[1]); |
| 3536 |
|
| 3537 |
MWAWGraphicStyle style=local.m_style; |
| 3538 |
listener->openGroup(local.m_position); |
| 3539 |
|
| 3540 |
MWAWGraphicShape fShape; |
| 3541 |
MWAWBox2f shapeBox; |
| 3542 |
|
| 3543 |
MWAWVec2f textOrigin; |
| 3544 |
librevenge::RVNGString text; |
| 3545 |
if (type==12) { // a sector instead of a line |
| 3546 |
// circle between pts[0], pts[1]->pts[2] |
| 3547 |
float angles[2]; |
| 3548 |
for (size_t i=0; i<2; ++i) { |
| 3549 |
MWAWVec2f dir=pts[i+1]-pts[0]; |
| 3550 |
angles[i]=180*std::atan2(-dir[1],dir[0])/float(M_PI); |
| 3551 |
} |
| 3552 |
if (std::isnan(angles[0]) || std::isnan(angles[1])) { |
| 3553 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension: can not compute the sector angles\n")); |
| 3554 |
} |
| 3555 |
else { |
| 3556 |
if (angles[1]<angles[0]) |
| 3557 |
std::swap(angles[0],angles[1]); |
| 3558 |
MWAWVec2f dir=pts[5]-pts[0]; |
| 3559 |
float len=std::sqrt(dir[0]*dir[0]+dir[1]*dir[1]); |
| 3560 |
MWAWBox2f circleBox(pts[0]-len*MWAWVec2f(1,1), pts[0]+len*MWAWVec2f(1,1)); |
| 3561 |
for (int st=0; st<2; ++st) { |
| 3562 |
float angle[2]; |
| 3563 |
if (arrowInside) { |
| 3564 |
if (st==1) |
| 3565 |
break; |
| 3566 |
angle[0]=angles[0]; |
| 3567 |
angle[1]=angles[1]; |
| 3568 |
} |
| 3569 |
else if (st==0) { |
| 3570 |
angle[0]=angles[0]-10; |
| 3571 |
angle[1]=angles[0]; |
| 3572 |
} |
| 3573 |
else { |
| 3574 |
angle[0]=angles[1]; |
| 3575 |
angle[1]=angles[1]+10; |
| 3576 |
} |
| 3577 |
// we must compute the real bd box |
| 3578 |
float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 }; |
| 3579 |
int limitAngle[2]; |
| 3580 |
for (int i = 0; i < 2; ++i) |
| 3581 |
limitAngle[i] = (angle[i] < 0) ? int(angle[i]/90)-1 : int(angle[i]/90); |
| 3582 |
for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; ++bord) { |
| 3583 |
float ang = (bord == limitAngle[0]) ? float(angle[0]) : |
| 3584 |
(bord == limitAngle[1]+1) ? float(angle[1]) : float(90 * bord); |
| 3585 |
ang *= float(M_PI/180.); |
| 3586 |
float const actVal[2] = { std::cos(ang), -std::sin(ang)}; |
| 3587 |
if (actVal[0] < minVal[0]) minVal[0] = actVal[0]; |
| 3588 |
else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0]; |
| 3589 |
if (actVal[1] < minVal[1]) minVal[1] = actVal[1]; |
| 3590 |
else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1]; |
| 3591 |
} |
| 3592 |
MWAWBox2f arcBox=circleBox; |
| 3593 |
// we have the shape box, we need to reconstruct the circle box |
| 3594 |
if (maxVal[0]>minVal[0] && maxVal[1]>minVal[1]) { |
| 3595 |
float scaling[2]= { (circleBox[1][0]-circleBox[0][0])/(maxVal[0]-minVal[0]), |
| 3596 |
(circleBox[1][1]-circleBox[0][1])/(maxVal[1]-minVal[1]) |
| 3597 |
}; |
| 3598 |
for (auto &s : scaling) { |
| 3599 |
if (s>1e7) |
| 3600 |
s=100; |
| 3601 |
else if (s<-1e7) |
| 3602 |
s=-100; |
| 3603 |
} |
| 3604 |
float const constant[2]= { circleBox[0][0]-minVal[0] *scaling[0], circleBox[0][1]-minVal[1] *scaling[1]}; |
| 3605 |
arcBox=MWAWBox2f(MWAWVec2f(constant[0]-scaling[0], constant[1]-scaling[1]), |
| 3606 |
MWAWVec2f(constant[0]+scaling[0], constant[1]+scaling[1])); |
| 3607 |
} |
| 3608 |
style.setSurfaceColor(MWAWColor::white(), 0); |
| 3609 |
style.m_arrows[st]=arrowInside ? MWAWGraphicStyle::Arrow::plain(): MWAWGraphicStyle::Arrow(); |
| 3610 |
style.m_arrows[1-st]=MWAWGraphicStyle::Arrow::plain(); |
| 3611 |
|
| 3612 |
fShape = MWAWGraphicShape::arc(arcBox, circleBox, MWAWVec2f(float(angle[0]), float(angle[1]))); |
| 3613 |
send(listener, fShape, local.m_transform, style); |
| 3614 |
} |
| 3615 |
} |
| 3616 |
// TODO: use format for unit, ... |
| 3617 |
textOrigin=pts[9]; |
| 3618 |
std::stringstream s; |
| 3619 |
s << std::setprecision(0) << std::fixed << angles[1]-angles[0] << " "; |
| 3620 |
text=s.str().c_str(); |
| 3621 |
libmwaw::appendUnicode(0xb0, text); |
| 3622 |
} |
| 3623 |
else if (type>12 && type<=14) { // radius/diameter inside an circle/ellipse |
| 3624 |
size_t orig=type==13 ? 0 : 4; |
| 3625 |
fShape=MWAWGraphicShape::line(pts[orig],pts[3]); |
| 3626 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 3627 |
send(listener, fShape, local.m_transform, style); |
| 3628 |
|
| 3629 |
fShape=MWAWGraphicShape::line(pts[1],pts[3]); |
| 3630 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow(); |
| 3631 |
send(listener, fShape, local.m_transform, style); |
| 3632 |
|
| 3633 |
textOrigin=pts[1]; |
| 3634 |
// TODO: use format for unit, ... |
| 3635 |
MWAWVec2f lineSz=pts[orig]-pts[3]; |
| 3636 |
std::stringstream s; |
| 3637 |
s << std::setprecision(0) << std::fixed << std::sqrt(lineSz[0]*lineSz[0]+lineSz[1]*lineSz[1]) << " pt"; |
| 3638 |
text=s.str().c_str(); |
| 3639 |
} |
| 3640 |
else if (type==15) { // four segments, no text |
| 3641 |
for (size_t i=0; i<4; ++i) { |
| 3642 |
fShape=MWAWGraphicShape::line(pts[1],pts[i+14]); |
| 3643 |
send(listener, fShape, local.m_transform, style); |
| 3644 |
} |
| 3645 |
} |
| 3646 |
else { |
| 3647 |
for (size_t i=0; i<2; ++i) { |
| 3648 |
size_t const limits[]= {4,6, 7,9 }; // outside1, outside2 |
| 3649 |
fShape=MWAWGraphicShape::line(pts[limits[2*i]],pts[limits[2*i+1]]); |
| 3650 |
send(listener, fShape, local.m_transform, style); |
| 3651 |
} |
| 3652 |
|
| 3653 |
if (arrowInside) { |
| 3654 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 3655 |
fShape=MWAWGraphicShape::line(pts[5],pts[8]); |
| 3656 |
send(listener, fShape, local.m_transform, style); |
| 3657 |
} |
| 3658 |
else { |
| 3659 |
style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain(); |
| 3660 |
for (size_t i=0; i<2; ++i) { |
| 3661 |
size_t const limits[]= {5,10, 8,11 }; // arrows1, arrows2 |
| 3662 |
fShape=MWAWGraphicShape::line(pts[limits[2*i]],pts[limits[2*i+1]]); |
| 3663 |
send(listener, fShape, local.m_transform, style); |
| 3664 |
} |
| 3665 |
} |
| 3666 |
|
| 3667 |
// sometimes there is also a line to rely pts[5/8] and the text |
| 3668 |
|
| 3669 |
textOrigin=pts[3]; |
| 3670 |
// TODO: use format for unit, ... |
| 3671 |
MWAWVec2f lineSz=pts[5]-pts[8]; |
| 3672 |
std::stringstream s; |
| 3673 |
s << std::setprecision(0) << std::fixed << std::sqrt(lineSz[0]*lineSz[0]+lineSz[1]*lineSz[1]) << " pt"; |
| 3674 |
text=s.str().c_str(); |
| 3675 |
} |
| 3676 |
// TODO: use local style to define the text's color... |
| 3677 |
if (!text.empty()) |
| 3678 |
send(listener, text, textOrigin, local.m_transform, MWAWFont(3,10), hasFrame); |
| 3679 |
|
| 3680 |
listener->closeGroup(); |
| 3681 |
return true; |
| 3682 |
} |
| 3683 |
|
| 3684 |
namespace Canvas5GraphInternal |
| 3685 |
{ |
| 3686 |
bool intersect(MWAWVec2f const &A, MWAWVec2f const &dirA, MWAWVec2f const &B, MWAWVec2f const &dirB, MWAWVec2f &pt) |
| 3687 |
{ |
| 3688 |
float cross=dirA[0]*dirB[1]-dirA[1]*dirB[0]; |
| 3689 |
if (cross>-1e-9f && cross<1e-9f) return false; |
| 3690 |
MWAWVec2f AB=B-A; |
| 3691 |
float alpha=(AB[0]*dirB[1]-AB[1]*dirB[0])/cross; |
| 3692 |
pt=A+alpha*dirA; |
| 3693 |
return true; |
| 3694 |
} |
| 3695 |
|
| 3696 |
std::vector<MWAWVec2f> intersect(MWAWBox2f const &box, MWAWVec2f const &pt, MWAWVec2f const &dir) |
| 3697 |
{ |
| 3698 |
std::vector<MWAWVec2f> res; |
| 3699 |
for (int d=0; d<2; ++d) { |
| 3700 |
for (int wh=0; wh<2; ++wh) { |
| 3701 |
MWAWVec2f pts[]= {box[0],box[1]}; |
| 3702 |
pts[1-wh][1-d]=pts[wh][1-d]; |
| 3703 |
MWAWVec2f AB=pts[1]-pts[0]; |
| 3704 |
float cross=AB[0]*dir[1]-AB[1]*dir[0]; |
| 3705 |
if (cross>-1e-9f && cross<1e-9f) continue; |
| 3706 |
MWAWVec2f AO=pt-pts[0]; |
| 3707 |
float alpha=(AO[0]*dir[1]-AO[1]*dir[0])/cross; |
| 3708 |
if (alpha<-1e-9f || alpha>1+1e-9f) continue; |
| 3709 |
if (alpha<0) |
| 3710 |
alpha=0; |
| 3711 |
else if (alpha>1) |
| 3712 |
alpha=1; |
| 3713 |
res.push_back((1-alpha)*pts[0]+alpha*pts[1]); |
| 3714 |
} |
| 3715 |
} |
| 3716 |
for (size_t i=0; i<res.size(); ++i) { |
| 3717 |
for (size_t j=i+1; j<res.size(); ++j) { |
| 3718 |
MWAWVec2f diff=res[j]-res[i]; |
| 3719 |
if (diff[0]*diff[0]+diff[1]*diff[1]>1e-8f) |
| 3720 |
continue; |
| 3721 |
std::swap(res[j],res.back()); |
| 3722 |
res.resize(res.size()-1); |
| 3723 |
--j; |
| 3724 |
} |
| 3725 |
} |
| 3726 |
if (res.size()!=2) { |
| 3727 |
MWAW_DEBUG_MSG(("Canvas5GraphInternal::intersect:: find %d intersections\n", int(res.size()))); |
| 3728 |
return std::vector<MWAWVec2f>(); |
| 3729 |
} |
| 3730 |
return res; |
| 3731 |
} |
| 3732 |
} |
| 3733 |
bool Canvas5Graph::sendDimension9(MWAWListenerPtr listener, Canvas5GraphInternal::Shape const &/*shape*/, |
| 3734 |
Canvas5GraphInternal::ShapeData const &data, Canvas5Graph::LocalState const &local) |
| 3735 |
{ |
| 3736 |
if (!listener || !data.m_stream || version()<9) { |
| 3737 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: can not find the listener\n")); |
| 3738 |
return false; |
| 3739 |
} |
| 3740 |
auto &stream=data.getStream(); |
| 3741 |
auto input=stream.input(); |
| 3742 |
auto const &entry=data.m_entry; |
| 3743 |
if (!entry.valid() || !input->checkPosition(entry.end())) { |
| 3744 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: can not find the shape enntry\n")); |
| 3745 |
return false; |
| 3746 |
} |
| 3747 |
|
| 3748 |
libmwaw::DebugFile &ascFile = stream.ascii(); |
| 3749 |
libmwaw::DebugStream f; |
| 3750 |
f << "Entries(Dimension):"; |
| 3751 |
input->seek(entry.begin(), librevenge::RVNG_SEEK_SET); |
| 3752 |
long zoneSize=input->readLong(4); |
| 3753 |
if (zoneSize<0x796 || zoneSize>entry.end()) { |
| 3754 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: can not read the zone size\n")); |
| 3755 |
f << "###sz"; |
| 3756 |
ascFile.addPos(entry.begin()); |
| 3757 |
ascFile.addNote(f.str().c_str()); |
| 3758 |
return false; |
| 3759 |
} |
| 3760 |
int val=int(input->readLong(4)); // 4 |
| 3761 |
if (val!=4) f << "f0=" << val << ","; |
| 3762 |
int type=int(input->readLong(1)); |
| 3763 |
if (type) f << "type=" << type << ","; |
| 3764 |
input->seek(1, librevenge::RVNG_SEEK_CUR); |
| 3765 |
val=int(input->readLong(4)); // 1 |
| 3766 |
if (val!=1) f << "f1=" << val << ","; |
| 3767 |
MWAWBox2f bdbox; |
| 3768 |
for (int i=0; i<2; ++i) { |
| 3769 |
float dims[2]; |
| 3770 |
// fract type: between -2 and 2 |
| 3771 |
for (auto &d : dims) d=float(m_mainParser->readDouble(stream,8)); |
| 3772 |
ascFile.addDelimiter(input->tell(),'|'); |
| 3773 |
if (i==0) |
| 3774 |
bdbox.setMin(MWAWVec2f(dims[0],dims[1])); |
| 3775 |
else |
| 3776 |
bdbox.setMax(MWAWVec2f(dims[0],dims[1])); |
| 3777 |
} |
| 3778 |
f << "box=" << bdbox << ","; |
| 3779 |
for (int i=0; i<2; ++i) { |
| 3780 |
val=int(input->readLong(4)); |
| 3781 |
if (val) |
| 3782 |
f << "f" << i << "=" << val << ","; |
| 3783 |
} |
| 3784 |
long posi=input->tell(); |
| 3785 |
int N=0; |
| 3786 |
bool finishedWithN=type!=4 && type!=7; |
| 3787 |
if (finishedWithN) { |
| 3788 |
input->seek(entry.end()-4, librevenge::RVNG_SEEK_SET); |
| 3789 |
ascFile.addDelimiter(input->tell(),'|'); |
| 3790 |
N=int(input->readULong(4)); |
| 3791 |
f << "N=" << N << ","; |
| 3792 |
input->seek(posi, librevenge::RVNG_SEEK_SET); |
| 3793 |
} |
| 3794 |
ascFile.addPos(entry.begin()); |
| 3795 |
ascFile.addNote(f.str().c_str()); |
| 3796 |
|
| 3797 |
for (int i=0; i<2; ++i) { |
| 3798 |
posi=input->tell(); |
| 3799 |
f.str(""); |
| 3800 |
f << "Dimension[" << (i==0 ? "prefix" : "suffix") << "]:"; |
| 3801 |
std::string name; |
| 3802 |
for (int j=0; j<64; ++j) { |
| 3803 |
char c=char(input->readULong(1)); |
| 3804 |
if (!c) |
| 3805 |
break; |
| 3806 |
name+=c; |
| 3807 |
} |
| 3808 |
if (!name.empty()) |
| 3809 |
f << name << ","; |
| 3810 |
input->seek(posi+64, librevenge::RVNG_SEEK_SET); |
| 3811 |
val=int(input->readLong(4)); |
| 3812 |
if (val) |
| 3813 |
f << "f0=" << val << ","; |
| 3814 |
ascFile.addPos(posi); |
| 3815 |
ascFile.addNote(f.str().c_str()); |
| 3816 |
} |
| 3817 |
for (int i=0; i<12; ++i) { |
| 3818 |
posi=input->tell(); |
| 3819 |
f.str(""); |
| 3820 |
f << "Dimension[data" << i << "]:"; |
| 3821 |
ascFile.addPos(posi); |
| 3822 |
ascFile.addNote(f.str().c_str()); |
| 3823 |
input->seek(posi+(i<11 ? 128 : 112), librevenge::RVNG_SEEK_SET); |
| 3824 |
} |
| 3825 |
|
| 3826 |
posi=input->tell(); |
| 3827 |
f.str(""); |
| 3828 |
f << "Dimension[format]:"; |
| 3829 |
int arrowType=3; |
| 3830 |
for (int i=0; i<8; ++i) { // f5=f6=3, f7=2 |
| 3831 |
val=int(input->readLong(4)); |
| 3832 |
int const expected[]= {0,0,0,0,0, 3,3,2}; |
| 3833 |
if (val==expected[i]) continue; |
| 3834 |
if (i==5) { |
| 3835 |
arrowType=val; |
| 3836 |
f << "arrow=" << val << ","; // 0-3: none, inside, outside, auto |
| 3837 |
} |
| 3838 |
else if (i==7) |
| 3839 |
f << "witness[line]=" << val << ","; // 0-2: none, short, long |
| 3840 |
else |
| 3841 |
f << "f" << i << "=" << val << ","; |
| 3842 |
} |
| 3843 |
MWAWFont font; |
| 3844 |
f << "font=["; |
| 3845 |
font.setSize(float(m_mainParser->readDouble(stream, 8))); |
| 3846 |
val=int(input->readULong(4)); // 0 |
| 3847 |
uint32_t flags = 0; |
| 3848 |
if (val&0x1) flags |= MWAWFont::boldBit; |
| 3849 |
if (val&0x2) flags |= MWAWFont::italicBit; |
| 3850 |
if (val&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple); |
| 3851 |
if (val&0x8) flags |= MWAWFont::embossBit; |
| 3852 |
if (val&0x10) flags |= MWAWFont::shadowBit; |
| 3853 |
if (val&0x80) font.setStrikeOutStyle(MWAWFont::Line::Simple); |
| 3854 |
font.setFlags(flags); |
| 3855 |
val &= 0xffffff60; |
| 3856 |
if (val) |
| 3857 |
f << "flag=" << std::hex << val << std::dec << ","; |
| 3858 |
std::string name; |
| 3859 |
for (int i=0; i<32; ++i) { |
| 3860 |
char c=char(input->readULong(1)); |
| 3861 |
if (!c) |
| 3862 |
break; |
| 3863 |
name+=c; |
| 3864 |
} |
| 3865 |
auto fontConverter=m_parserState->m_fontConverter; |
| 3866 |
std::string const family=m_mainParser->isWindowsFile() ? "CP1252" : ""; |
| 3867 |
if (!name.empty()) |
| 3868 |
font.setId(fontConverter->getId(name, family)); |
| 3869 |
f << font.getDebugString(fontConverter) << ","; |
| 3870 |
f << "],"; |
| 3871 |
input->seek(posi+76, librevenge::RVNG_SEEK_SET); |
| 3872 |
ascFile.addPos(posi); |
| 3873 |
ascFile.addNote(f.str().c_str()); |
| 3874 |
|
| 3875 |
posi=input->tell(); |
| 3876 |
f.str(""); |
| 3877 |
f << "Dimension[formatA]:"; |
| 3878 |
for (int i=0; i<7; ++i) { // f2=-1|3, f4=1, |
| 3879 |
val=int(input->readLong(4)); |
| 3880 |
if (!val) |
| 3881 |
continue; |
| 3882 |
if (i==2) // -1-20 |
| 3883 |
f << "dimension=" << val << ","; |
| 3884 |
else if (i==5) { |
| 3885 |
if (val==1) |
| 3886 |
f << "use[secondary],"; |
| 3887 |
else |
| 3888 |
f << "use[secondary]=" << val << ","; |
| 3889 |
} |
| 3890 |
else if (i==6) // 0-3 |
| 3891 |
f << "tolerance=" << val << ","; |
| 3892 |
else |
| 3893 |
f << "f" << i << "=" << val << ","; |
| 3894 |
} |
| 3895 |
f << "unkn=["; // 0.05*3 |
| 3896 |
for (int i=0; i<3; ++i) |
| 3897 |
f << m_mainParser->readDouble(stream, 8) << ","; |
| 3898 |
f << "],"; |
| 3899 |
val=int(input->readLong(4)); // 0 |
| 3900 |
if (val) |
| 3901 |
f << "f10=" << val << ","; |
| 3902 |
f << "unkn1=" << m_mainParser->readDouble(stream, 8) << ","; // 18 |
| 3903 |
for (int i=0; i<2; ++i) { |
| 3904 |
val=int(input->readLong(4)); |
| 3905 |
if (val==(i==0 ? 0 : 2)) continue; |
| 3906 |
if (i==1) |
| 3907 |
f << "digits=" << val << ","; |
| 3908 |
else |
| 3909 |
f << "g" << i << "=" << val << ","; |
| 3910 |
} |
| 3911 |
f << "displ[scaling]=" << m_mainParser->readDouble(stream, 8) << ","; // 1 |
| 3912 |
for (int i=0; i<12; ++i) { |
| 3913 |
val=int(input->readLong(4)); |
| 3914 |
if (val) |
| 3915 |
f << "g" << i+2 << "=" << val << ","; |
| 3916 |
} |
| 3917 |
ascFile.addPos(posi); |
| 3918 |
ascFile.addNote(f.str().c_str()); |
| 3919 |
|
| 3920 |
posi=input->tell(); |
| 3921 |
f.str(""); |
| 3922 |
f << "Dimension[last,type=" << type << "]:"; |
| 3923 |
if (type<1 || type>11) { |
| 3924 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: unknown type\n")); |
| 3925 |
f << "###type=" << type << ","; |
| 3926 |
ascFile.addPos(posi); |
| 3927 |
ascFile.addNote(f.str().c_str()); |
| 3928 |
return false; |
| 3929 |
} |
| 3930 |
|
| 3931 |
std::vector<MWAWVec2f> pts; |
| 3932 |
f << "unkn=["; |
| 3933 |
for (int i=0; i<((type==11||type==10) ? 2 : type==7 ? 3 : 4); ++i) { |
| 3934 |
float dim[2]; |
| 3935 |
for (auto &p : dim) p=float(m_mainParser->readDouble(stream, 8)); |
| 3936 |
pts.push_back(MWAWVec2f(dim[0], dim[1])); |
| 3937 |
f << pts.back() << ","; |
| 3938 |
} |
| 3939 |
f << "],"; |
| 3940 |
|
| 3941 |
long remain=entry.end()-input->tell()-(finishedWithN ? 4 : 0); |
| 3942 |
switch (type) { |
| 3943 |
case 1: // simple |
| 3944 |
if (remain<0) { |
| 3945 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[1]: can not read the last part\n")); |
| 3946 |
f << "###"; |
| 3947 |
ascFile.addPos(posi); |
| 3948 |
ascFile.addNote(f.str().c_str()); |
| 3949 |
return false; |
| 3950 |
} |
| 3951 |
break; |
| 3952 |
case 2: // array 1d <->|<-> |
| 3953 |
case 3: { // array 1D |
| 3954 |
if (N<0 || remain/64<N+1 || remain<64*(N+1)+(type==2 ? 4 : 0)) { |
| 3955 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[1]: can not read the last part\n")); |
| 3956 |
f << "###"; |
| 3957 |
ascFile.addPos(posi); |
| 3958 |
ascFile.addNote(f.str().c_str()); |
| 3959 |
return false; |
| 3960 |
} |
| 3961 |
f << "unk2=["; |
| 3962 |
for (int i=0; i<=N; ++i) { |
| 3963 |
f << "["; |
| 3964 |
for (int j=0; j<4; ++j) { |
| 3965 |
float dim[2]; |
| 3966 |
for (auto &p : dim) p=float(m_mainParser->readDouble(stream, 8)); |
| 3967 |
pts.push_back(MWAWVec2f(dim[0], dim[1])); |
| 3968 |
f << pts.back() << ","; |
| 3969 |
} |
| 3970 |
f << "],"; |
| 3971 |
} |
| 3972 |
f << "],"; |
| 3973 |
ascFile.addDelimiter(input->tell(),'|'); |
| 3974 |
if (type==2) { |
| 3975 |
input->seek(entry.end()-8, librevenge::RVNG_SEEK_SET); |
| 3976 |
int direction=int(input->readULong(4)); |
| 3977 |
f << "dir=" << direction << ","; // 1: hori, 2: verti, 0: all? |
| 3978 |
if (direction<0 || direction>2) { |
| 3979 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[2]: unexpected direction\n")); |
| 3980 |
f << "###"; |
| 3981 |
} |
| 3982 |
} |
| 3983 |
input->seek(entry.end(), librevenge::RVNG_SEEK_SET); |
| 3984 |
break; |
| 3985 |
} |
| 3986 |
case 4: { // perpendicular line ... |
| 3987 |
if (remain<4 || (remain%16)!=4) { |
| 3988 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[4]: can not read the last part\n")); |
| 3989 |
f << "###"; |
| 3990 |
ascFile.addPos(posi); |
| 3991 |
ascFile.addNote(f.str().c_str()); |
| 3992 |
return false; |
| 3993 |
} |
| 3994 |
val=int(input->readLong(4)); |
| 3995 |
if (val) |
| 3996 |
f << "f0=" << val << ","; |
| 3997 |
int n=int(remain/16); |
| 3998 |
f << "unk2=["; |
| 3999 |
for (int i=0; i<n; ++i) { // then the line |
| 4000 |
float dim[2]; |
| 4001 |
for (auto &p : dim) p=float(m_mainParser->readDouble(stream, 8)); |
| 4002 |
pts.push_back(MWAWVec2f(dim[0], dim[1])); |
| 4003 |
f << pts.back() << ","; |
| 4004 |
} |
| 4005 |
f << "],"; |
| 4006 |
break; |
| 4007 |
} |
| 4008 |
// case 5: side object (no data) |
| 4009 |
case 6: { // arc |
| 4010 |
if (remain!=48) { |
| 4011 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[6]: can not read the last part\n")); |
| 4012 |
f << "###"; |
| 4013 |
ascFile.addPos(posi); |
| 4014 |
ascFile.addNote(f.str().c_str()); |
| 4015 |
return false; |
| 4016 |
} |
| 4017 |
f << "unk2=["; |
| 4018 |
for (int i=0; i<3; ++i) { |
| 4019 |
float dim[2]; |
| 4020 |
for (auto &p : dim) p=float(m_mainParser->readDouble(stream, 8)); |
| 4021 |
pts.push_back(MWAWVec2f(dim[0], dim[1])); |
| 4022 |
f << pts.back() << ","; |
| 4023 |
} |
| 4024 |
f << "],"; |
| 4025 |
break; |
| 4026 |
} |
| 4027 |
case 7: // radius |
| 4028 |
if (remain!=40) { |
| 4029 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[9]: can not read the last part\n")); |
| 4030 |
f << "###"; |
| 4031 |
ascFile.addPos(posi); |
| 4032 |
ascFile.addNote(f.str().c_str()); |
| 4033 |
return false; |
| 4034 |
} |
| 4035 |
input->seek(6, librevenge::RVNG_SEEK_CUR); |
| 4036 |
f << "unk2=["; |
| 4037 |
for (int i=0; i<2; ++i) { |
| 4038 |
float dim[2]; |
| 4039 |
for (auto &p : dim) p=float(m_mainParser->readDouble(stream, 8)); |
| 4040 |
pts.push_back(MWAWVec2f(dim[0], dim[1])); |
| 4041 |
f << pts.back() << ","; |
| 4042 |
} |
| 4043 |
f << "],"; |
| 4044 |
val=int(input->readLong(2)); |
| 4045 |
if (val) |
| 4046 |
f << "f0=" << val << ","; |
| 4047 |
break; |
| 4048 |
// case 8: diameter(no data) |
| 4049 |
case 9: // cross in circle |
| 4050 |
if (remain!=20) { |
| 4051 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[9]: can not read the last part\n")); |
| 4052 |
f << "###"; |
| 4053 |
ascFile.addPos(posi); |
| 4054 |
ascFile.addNote(f.str().c_str()); |
| 4055 |
return false; |
| 4056 |
} |
| 4057 |
float dim[2]; |
| 4058 |
for (auto &p : dim) p=float(m_mainParser->readDouble(stream, 8)); |
| 4059 |
pts.push_back(MWAWVec2f(dim[0], dim[1])); |
| 4060 |
f << "unkn2=" << pts.back() << ","; // center? |
| 4061 |
val=int(input->readLong(4)); |
| 4062 |
if (val) |
| 4063 |
f << "f0=" << val << ","; |
| 4064 |
break; |
| 4065 |
// case 10: inside area |
| 4066 |
// case 11: outside area |
| 4067 |
default: |
| 4068 |
break; |
| 4069 |
} |
| 4070 |
ascFile.addPos(posi); |
| 4071 |
ascFile.addNote(f.str().c_str()); |
| 4072 |
|
| 4073 |
if (input->tell()+(finishedWithN ? 4 : 0)<entry.end()) { |
| 4074 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: find extra data\n", type)); |
| 4075 |
posi=input->tell(); |
| 4076 |
f.str(""); |
| 4077 |
f << "Dimension[end]:type=" << type << ","; |
| 4078 |
ascFile.addPos(posi); |
| 4079 |
ascFile.addNote(f.str().c_str()); |
| 4080 |
} |
| 4081 |
|
| 4082 |
MWAWGraphicShape fShape; |
| 4083 |
MWAWBox2f shapeBox; |
| 4084 |
MWAWGraphicStyle style=local.m_style; |
| 4085 |
MWAWPosition pos; |
| 4086 |
pos.m_anchorTo = MWAWPosition::Page; |
| 4087 |
|
| 4088 |
listener->openGroup(local.m_position); |
| 4089 |
switch (type) { |
| 4090 |
case 1: |
| 4091 |
case 2: |
| 4092 |
case 3: |
| 4093 |
case 4: |
| 4094 |
case 5: { |
| 4095 |
if (type>=2 && type<=3 && pts.size()<12) { |
| 4096 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, the number of points seems to small\n", type)); |
| 4097 |
break; |
| 4098 |
} |
| 4099 |
else if (type==4 && pts.size()<6) { |
| 4100 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, the number of points seems to small\n", type)); |
| 4101 |
break; |
| 4102 |
} |
| 4103 |
int num=(type==1 || type==4 || type==5) ? 1 : int(pts.size()-8)/4; |
| 4104 |
for (int n=0; n<num; ++n) { |
| 4105 |
if (n>0) { |
| 4106 |
static bool first=true; |
| 4107 |
if (first) { |
| 4108 |
first=false; |
| 4109 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: oops, do not know how to retrieve multi-dimension type=%d\n", type)); |
| 4110 |
} |
| 4111 |
#if 0 |
| 4112 |
style.m_surfaceOpacity=0; |
| 4113 |
fShape=MWAWGraphicShape::rectangle(bdbox); |
| 4114 |
send(listener, fShape, local.m_transform, style); |
| 4115 |
#endif |
| 4116 |
break; |
| 4117 |
} |
| 4118 |
MWAWVec2f v=pts[3]-pts[2]; |
| 4119 |
MWAWVec2f dir(v[1],-v[0]); |
| 4120 |
// first border |
| 4121 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow(); |
| 4122 |
for (size_t i=0; i<2; ++i) { |
| 4123 |
std::vector<MWAWVec2f> points=Canvas5GraphInternal::intersect(bdbox, pts[i], dir); |
| 4124 |
if (points.size()!=2) continue; |
| 4125 |
fShape=MWAWGraphicShape::line(points[0],points[1]); |
| 4126 |
send(listener, fShape, local.m_transform, style); |
| 4127 |
} |
| 4128 |
MWAWVec2f points[2]; |
| 4129 |
bool ok=true; |
| 4130 |
for (size_t j=0; j<2; ++j) { |
| 4131 |
if (Canvas5GraphInternal::intersect(pts[2],v, pts[j], dir, points[j])) |
| 4132 |
continue; |
| 4133 |
ok=true; |
| 4134 |
break; |
| 4135 |
} |
| 4136 |
if (!ok) continue; |
| 4137 |
// now the main arrow |
| 4138 |
MWAWVec2f u=pts[1]-pts[0]; |
| 4139 |
bool outside=arrowType==2 || (arrowType!=1 && u[0]*u[0]+u[1]*u[1]<50*50); |
| 4140 |
if (outside) { |
| 4141 |
std::vector<MWAWVec2f> points2=Canvas5GraphInternal::intersect(bdbox, points[0], points[1]-points[0]); |
| 4142 |
if (points2.size()==2) { |
| 4143 |
MWAWVec2f dir0=points[1]-points[0]; |
| 4144 |
MWAWVec2f dir1=points2[1]-points2[0]; |
| 4145 |
if (dir0[0]*dir1[0]+dir0[1]*dir1[1]<0) |
| 4146 |
std::swap(points2[0],points2[1]); |
| 4147 |
if (arrowType!=0) |
| 4148 |
style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 4149 |
for (size_t i=0; i<2; ++i) { |
| 4150 |
fShape=MWAWGraphicShape::line(points2[i],points[i]); |
| 4151 |
send(listener, fShape, local.m_transform, style); |
| 4152 |
} |
| 4153 |
} |
| 4154 |
} |
| 4155 |
else { |
| 4156 |
if (arrowType!=0) |
| 4157 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 4158 |
fShape=MWAWGraphicShape::line(points[0],points[1]); |
| 4159 |
send(listener, fShape, local.m_transform, style); |
| 4160 |
} |
| 4161 |
|
| 4162 |
// and the text |
| 4163 |
std::stringstream s; |
| 4164 |
s << std::setprecision(0) << std::fixed << std::sqrt(u[0]*u[0]+u[1]*u[1]) << " pt"; |
| 4165 |
librevenge::RVNGString text=s.str().c_str(); |
| 4166 |
|
| 4167 |
MWAWVec2f textOrigin=0.5f*(points[0]+points[1]); |
| 4168 |
send(listener, text, textOrigin, local.m_transform, font, false); |
| 4169 |
} |
| 4170 |
break; |
| 4171 |
} |
| 4172 |
case 6: { |
| 4173 |
if (pts.size()!=7) { |
| 4174 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, the number of points seems bad\n", type)); |
| 4175 |
break; |
| 4176 |
} |
| 4177 |
MWAWVec2f orig; |
| 4178 |
if (!Canvas5GraphInternal::intersect(pts[0],pts[1]-pts[0], pts[3],pts[3]-pts[2],orig)) { |
| 4179 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, can not find the origin\n", type)); |
| 4180 |
break; |
| 4181 |
} |
| 4182 |
float angles[2]; |
| 4183 |
for (size_t i=0; i<2; ++i) { |
| 4184 |
MWAWVec2f dir=pts[1+2*i]-orig; |
| 4185 |
angles[i]=std::atan2(-dir[1],dir[0]); |
| 4186 |
} |
| 4187 |
|
| 4188 |
if (std::isnan(angles[0]) || std::isnan(angles[1])) { |
| 4189 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[6]: can not compute the sector angle\n")); |
| 4190 |
} |
| 4191 |
else { |
| 4192 |
MWAWVec2f dir=pts[5]-orig; |
| 4193 |
float radius=std::sqrt(dir[0]*dir[0]+dir[1]*dir[1]); |
| 4194 |
std::swap(angles[0],angles[1]); |
| 4195 |
MWAWBox2f circleBox(MWAWVec2f(orig[0]-radius, orig[1]-radius),MWAWVec2f(orig[0]+radius, orig[1]+radius)); |
| 4196 |
|
| 4197 |
// we must compute the arc box |
| 4198 |
float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 }; |
| 4199 |
int limitAngle[2]; |
| 4200 |
for (int i = 0; i < 2; ++i) |
| 4201 |
limitAngle[i] = (angles[i] < 0) ? int(2*angles[i]/float(M_PI))-1 : int(2*angles[i]/float(M_PI)); |
| 4202 |
for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; ++bord) { |
| 4203 |
float ang = (bord == limitAngle[0]) ? float(angles[0]) : |
| 4204 |
(bord == limitAngle[1]+1) ? float(angles[1]) : float(M_PI/2*bord); |
| 4205 |
float const actVal[2] = { std::cos(ang), -std::sin(ang)}; |
| 4206 |
if (actVal[0] < minVal[0]) minVal[0] = actVal[0]; |
| 4207 |
else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0]; |
| 4208 |
if (actVal[1] < minVal[1]) minVal[1] = actVal[1]; |
| 4209 |
else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1]; |
| 4210 |
} |
| 4211 |
MWAWBox2f arcBox(MWAWVec2f(orig[0]+minVal[0]*radius, orig[1]+minVal[1]*radius),MWAWVec2f(orig[0]+maxVal[0]*radius, orig[1]+maxVal[1]*radius)); |
| 4212 |
fShape = MWAWGraphicShape::pie(arcBox, circleBox, MWAWVec2f(float(180/M_PI)*angles[0], float(180/M_PI)*angles[1])); |
| 4213 |
send(listener, fShape, local.m_transform, style); |
| 4214 |
} |
| 4215 |
// and the text |
| 4216 |
std::stringstream s; |
| 4217 |
s << std::setprecision(2) << std::fixed << float(180/M_PI)*(angles[1]-angles[0]) << " "; |
| 4218 |
librevenge::RVNGString text=s.str().c_str(); |
| 4219 |
|
| 4220 |
send(listener, text, pts[5], local.m_transform, font, false); |
| 4221 |
break; |
| 4222 |
} |
| 4223 |
case 7: { |
| 4224 |
if (pts.size()!=5) { |
| 4225 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, the number of points seems bad\n", type)); |
| 4226 |
break; |
| 4227 |
} |
| 4228 |
fShape=MWAWGraphicShape::line(pts[1],pts[2]); |
| 4229 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow(); |
| 4230 |
send(listener, fShape, local.m_transform, style); |
| 4231 |
fShape=MWAWGraphicShape::line(pts[0],pts[1]); |
| 4232 |
if (arrowType!=0) |
| 4233 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 4234 |
send(listener, fShape, local.m_transform, style); |
| 4235 |
// and the text |
| 4236 |
std::stringstream s; |
| 4237 |
MWAWVec2f dir=pts[2]-pts[0]; |
| 4238 |
s << std::setprecision(0) << std::fixed << std::sqrt(dir[0]*dir[0]+dir[1]*dir[1]) << " pt"; |
| 4239 |
librevenge::RVNGString text=s.str().c_str(); |
| 4240 |
send(listener, text, pts[1], local.m_transform, font, false); |
| 4241 |
break; |
| 4242 |
} |
| 4243 |
case 8: { |
| 4244 |
if (pts.size()!=4) { |
| 4245 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, the number of points seems bad\n", type)); |
| 4246 |
break; |
| 4247 |
} |
| 4248 |
fShape=MWAWGraphicShape::line(pts[0],pts[1]); |
| 4249 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow(); |
| 4250 |
send(listener, fShape, local.m_transform, style); |
| 4251 |
fShape=MWAWGraphicShape::line(pts[0],pts[2]); |
| 4252 |
if (arrowType!=0) |
| 4253 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain(); |
| 4254 |
send(listener, fShape, local.m_transform, style); |
| 4255 |
// and the text |
| 4256 |
std::stringstream s; |
| 4257 |
MWAWVec2f dir=pts[2]-pts[0]; |
| 4258 |
s << std::setprecision(0) << std::fixed << std::sqrt(dir[0]*dir[0]+dir[1]*dir[1]) << " pt"; |
| 4259 |
librevenge::RVNGString text=s.str().c_str(); |
| 4260 |
send(listener, text, pts[1], local.m_transform, font, false); |
| 4261 |
break; |
| 4262 |
} |
| 4263 |
case 9: // 0 is the center |
| 4264 |
if (pts.size()!=5) { |
| 4265 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9[%d]: sorry, the number of points seems bad\n", type)); |
| 4266 |
break; |
| 4267 |
} |
| 4268 |
style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow(); |
| 4269 |
fShape=MWAWGraphicShape::line(pts[1],pts[2]); |
| 4270 |
send(listener, fShape, local.m_transform, style); |
| 4271 |
fShape=MWAWGraphicShape::line(pts[3],pts[4]); |
| 4272 |
send(listener, fShape, local.m_transform, style); |
| 4273 |
break; |
| 4274 |
case 10: |
| 4275 |
case 11: { |
| 4276 |
static bool first=true; |
| 4277 |
if (first) { |
| 4278 |
first=false; |
| 4279 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: sorry, sending area dimension of type=%d is not implemented\n", type)); |
| 4280 |
} |
| 4281 |
break; |
| 4282 |
} |
| 4283 |
default: |
| 4284 |
static bool first=true; |
| 4285 |
if (first) { |
| 4286 |
first=false; |
| 4287 |
MWAW_DEBUG_MSG(("Canvas5Graph::sendDimension9: sorry, sending dimension of type=%d is not implemented\n", type)); |
| 4288 |
} |
| 4289 |
break; |
| 4290 |
} |
| 4291 |
listener->closeGroup(); |
| 4292 |
return true; |
| 4293 |
} |
| 4294 |
|
| 4295 |
//////////////////////////////////////////////////////////// |
| 4296 |
// auxilliary structure |
| 4297 |
//////////////////////////////////////////////////////////// |
| 4298 |
|
| 4299 |
void Canvas5Graph::LocalState::multiplyMatrix(std::array<double,9> const &mat) |
| 4300 |
{ |
| 4301 |
if (mat[8]>=-1e-3 && mat[8]<=1e-3) { |
| 4302 |
// checkme: this seems possible, unsure what this means ? |
| 4303 |
static bool first=true; |
| 4304 |
if (first) { |
| 4305 |
first=false; |
| 4306 |
MWAW_DEBUG_MSG(("Canvas5Graph::LocalState::multiplyMatrix: find some matrix with mat[3][3]=0\n")); |
| 4307 |
} |
| 4308 |
} |
| 4309 |
if (mat[2]<-1e-3 || mat[2]>1e-3 || mat[5]<-1e-3 || mat[5]>1e-3) { |
| 4310 |
MWAW_DEBUG_MSG(("Canvas5Graph::LocalState::multiplyMatrix: projection will be ignored\n")); |
| 4311 |
return; |
| 4312 |
} |
| 4313 |
m_transform*=MWAWTransformation(MWAWVec3f((float)mat[0],(float)mat[3],(float)mat[6]), MWAWVec3f((float)mat[1],(float)mat[4],(float)mat[7])); |
| 4314 |
} |
| 4315 |
|
| 4316 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |