| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | /* libwps |
| 3 | * Version: MPL 2.0 / LGPLv2.1+ |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * Major Contributor(s): |
| 10 | * Copyright (C) 2006, 2007 Andrew Ziem |
| 11 | * Copyright (C) 2004 Marc Maurer ([email protected]) |
| 12 | * Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 13 | * |
| 14 | * For minor contributions see the git repository. |
| 15 | * |
| 16 | * Alternatively, the contents of this file may be used under the terms |
| 17 | * of the GNU Lesser General Public License Version 2.1 or later |
| 18 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 19 | * applicable instead of those above. |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | |
| 25 | #include <cmath> |
| 26 | #include <sstream> |
| 27 | #include <limits> |
| 28 | #include <map> |
| 29 | #include <stack> |
| 30 | |
| 31 | #include <librevenge-stream/librevenge-stream.h> |
| 32 | |
| 33 | #include "libwps_internal.h" |
| 34 | #include "libwps_tools_win.h" |
| 35 | |
| 36 | #include "WKSContentListener.h" |
| 37 | #include "WKSSubDocument.h" |
| 38 | |
| 39 | #include "WPSEntry.h" |
| 40 | #include "WPSFont.h" |
| 41 | #include "WPSGraphicShape.h" |
| 42 | #include "WPSGraphicStyle.h" |
| 43 | #include "WPSOLEObject.h" |
| 44 | #include "WPSParagraph.h" |
| 45 | #include "WPSPosition.h" |
| 46 | #include "WPSStream.h" |
| 47 | |
| 48 | #include "Quattro.h" |
| 49 | |
| 50 | #include "QuattroGraph.h" |
| 51 | |
| 52 | namespace QuattroGraphInternal |
| 53 | { |
| 54 | //! a dialog header |
| 55 | struct Dialog |
| 56 | { |
| 57 | //! constructor |
| 58 | explicit Dialog() |
| 59 | : m_cellBox() |
| 60 | { |
| 61 | for (auto &f : m_flags1) f=0; |
| 62 | for (auto &f : m_flags2) f=0; |
| 63 | } |
| 64 | //! operator<< |
| 65 | friend std::ostream &operator<<(std::ostream &o, Dialog const &gr); |
| 66 | //! the cell's position |
| 67 | WPSBox2i m_cellBox; |
| 68 | //! some flags |
| 69 | int m_flags1[5]; |
| 70 | //! final flag |
| 71 | int m_flags2[9]; |
| 72 | }; |
| 73 | |
| 74 | std::ostream &operator<<(std::ostream &o, Dialog const &dlg) |
| 75 | { |
| 76 | if (dlg.m_cellBox!=WPSBox2i()) o << "cellBox=" << dlg.m_cellBox << ","; |
| 77 | o << "fl1=["; |
| 78 | for (auto f : dlg.m_flags1) |
| 79 | { |
| 80 | if (f) |
| 81 | o << std::hex << f << std::dec << ","; |
| 82 | else |
| 83 | o << "_,"; |
| 84 | } |
| 85 | o << "],"; |
| 86 | o << "fl2=["; |
| 87 | for (auto f : dlg.m_flags2) |
| 88 | { |
| 89 | if (f) |
| 90 | o << std::hex << f << std::dec << ","; |
| 91 | else |
| 92 | o << "_,"; |
| 93 | } |
| 94 | o << "],"; |
| 95 | return o; |
| 96 | } |
| 97 | |
| 98 | //! a shape header of a QuattroGraph |
| 99 | struct ShapeHeader |
| 100 | { |
| 101 | //! constructor |
| 102 | ShapeHeader() |
| 103 | : m_type(0) |
| 104 | , m_box() |
| 105 | , m_id(0) |
| 106 | , m_style() |
| 107 | , m_extra() |
| 108 | { |
| 109 | for (auto &f : m_flags) f=0; |
| 110 | for (auto &v : m_values) v=0; |
| 111 | for (auto &v : m_values2) v=0; |
| 112 | } |
| 113 | //! destructor |
| 114 | virtual ~ShapeHeader(); |
| 115 | //! returns true if the shape is a textbox |
| 116 | virtual bool isTextbox() const |
| 117 | { |
| 118 | return false; |
| 119 | } |
| 120 | //! operator<< |
| 121 | friend std::ostream &operator<<(std::ostream &o, ShapeHeader const &sh); |
| 122 | //! the type |
| 123 | int m_type; |
| 124 | //! the bdbox |
| 125 | WPSBox2i m_box; |
| 126 | //! an id? |
| 127 | int m_id; |
| 128 | //! the graphic style |
| 129 | WPSGraphicStyle m_style; |
| 130 | //! optional values |
| 131 | int m_values[5]; |
| 132 | //! some flags |
| 133 | int m_flags[14]; |
| 134 | |
| 135 | // |
| 136 | // style |
| 137 | // |
| 138 | |
| 139 | //! style values |
| 140 | int m_values2[4]; |
| 141 | //! error message |
| 142 | std::string m_extra; |
| 143 | }; |
| 144 | |
| 145 | ShapeHeader::~ShapeHeader() |
| 146 | { |
| 147 | } |
| 148 | |
| 149 | std::ostream &operator<<(std::ostream &o, ShapeHeader const &sh) |
| 150 | { |
| 151 | o << "type=" << sh.m_type << ","; |
| 152 | o << "box=" << sh.m_box << ","; |
| 153 | if (sh.m_id) o << "id=" << sh.m_id << ","; |
| 154 | o << sh.m_style << ","; |
| 155 | int wh=0; |
| 156 | for (auto v : sh.m_values) |
| 157 | { |
| 158 | if (v) o << "f" << wh << "=" << v << ","; |
| 159 | ++wh; |
| 160 | } |
| 161 | o << "unkn["; |
| 162 | for (auto f : sh.m_flags) |
| 163 | { |
| 164 | if (f) |
| 165 | o << std::hex << f << std::dec << ","; |
| 166 | else |
| 167 | o << ","; |
| 168 | } |
| 169 | o << "],"; |
| 170 | wh=0; |
| 171 | for (auto v : sh.m_values2) |
| 172 | { |
| 173 | if (v) o << "g" << wh << "=" << v << ","; |
| 174 | ++wh; |
| 175 | } |
| 176 | o << sh.m_extra << ","; |
| 177 | return o; |
| 178 | } |
| 179 | |
| 180 | //! Internal: a shape of a QuattroGraph |
| 181 | struct Shape final : public ShapeHeader |
| 182 | { |
| 183 | //! constructor |
| 184 | Shape() |
| 185 | : ShapeHeader() |
| 186 | , m_shape() |
| 187 | { |
| 188 | } |
| 189 | //! destructor |
| 190 | ~Shape() final; |
| 191 | //! the graphic shape |
| 192 | WPSGraphicShape m_shape; |
| 193 | }; |
| 194 | |
| 195 | Shape::~Shape() |
| 196 | { |
| 197 | } |
| 198 | |
| 199 | //! Internal: a shape of a QuattroGraph |
| 200 | struct Textbox final : public ShapeHeader |
| 201 | { |
| 202 | //! constructor |
| 203 | Textbox() |
| 204 | : ShapeHeader() |
| 205 | , m_entry() |
| 206 | , m_font() |
| 207 | , m_paragraph() |
| 208 | { |
| 209 | } |
| 210 | //! destructor |
| 211 | ~Textbox() final; |
| 212 | //! returns true |
| 213 | bool isTextbox() const final |
| 214 | { |
| 215 | return true; |
| 216 | } |
| 217 | //! the text entry |
| 218 | WPSEntry m_entry; |
| 219 | //! the font |
| 220 | WPSFont m_font; |
| 221 | //! the paragraph style |
| 222 | WPSParagraph m_paragraph; |
| 223 | }; |
| 224 | |
| 225 | Textbox::~Textbox() |
| 226 | { |
| 227 | } |
| 228 | |
| 229 | //! Internal: a graph of a QuattroGraph |
| 230 | struct Graph |
| 231 | { |
| 232 | //! the posible type |
| 233 | enum Type { Button, Chart, Frame, OLE/* or bitmap */, Image, Shape, Textbox, Unknown }; |
| 234 | //! constructor |
| 235 | explicit Graph(std::shared_ptr<WPSStream> const &stream, Type type=Unknown) |
| 236 | : m_type(type) |
| 237 | , m_size() |
| 238 | , m_cellBox() |
| 239 | , m_cellBoxDecal() |
| 240 | , m_label() |
| 241 | , m_ole() |
| 242 | , m_linkName() |
| 243 | , m_shape() |
| 244 | , m_textbox() |
| 245 | , m_stream(stream) |
| 246 | { |
| 247 | for (auto &f : m_flags1) f=0; |
| 248 | for (auto &f : m_flags2) f=0; |
| 249 | for (auto &v : m_values) v=0; |
| 250 | } |
| 251 | //! operator<< |
| 252 | friend std::ostream &operator<<(std::ostream &o, Graph const &gr); |
| 253 | //! the type |
| 254 | Type m_type; |
| 255 | //! the size |
| 256 | Vec2f m_size; |
| 257 | //! the cell's position |
| 258 | WPSBox2i m_cellBox; |
| 259 | //! the decal position(LT, RB) |
| 260 | WPSBox2f m_cellBoxDecal; |
| 261 | //! some flags |
| 262 | int m_flags1[4]; |
| 263 | //! final flag |
| 264 | int m_flags2[7]; |
| 265 | //! some values |
| 266 | int m_values[5]; |
| 267 | |
| 268 | //! the label(button) |
| 269 | librevenge::RVNGString m_label; |
| 270 | |
| 271 | //! the OLE's data |
| 272 | WPSEmbeddedObject m_ole; |
| 273 | //! the OLE's link name |
| 274 | librevenge::RVNGString m_linkName; |
| 275 | |
| 276 | //! the graphic shape |
| 277 | std::shared_ptr<QuattroGraphInternal::Shape> m_shape; |
| 278 | //! the textbox |
| 279 | std::shared_ptr<QuattroGraphInternal::Textbox> m_textbox; |
| 280 | |
| 281 | //! the main stream |
| 282 | std::shared_ptr<WPSStream> m_stream; |
| 283 | }; |
| 284 | |
| 285 | std::ostream &operator<<(std::ostream &o, Graph const &gr) |
| 286 | { |
| 287 | if (gr.m_size!=Vec2f()) o << "size=" << gr.m_size << ","; |
| 288 | if (gr.m_cellBox!=WPSBox2i()) o << "cellBox=" << gr.m_cellBox << ","; |
| 289 | if (gr.m_cellBoxDecal!=WPSBox2f()) o << "cellBox[decal]=" << gr.m_cellBoxDecal << ","; |
| 290 | o << "fl1=["; |
| 291 | for (auto f : gr.m_flags1) |
| 292 | { |
| 293 | if (f) |
| 294 | o << std::hex << f << std::dec << ","; |
| 295 | else |
| 296 | o << "_,"; |
| 297 | } |
| 298 | o << "],"; |
| 299 | o << "fl2=["; |
| 300 | for (auto f : gr.m_flags2) |
| 301 | { |
| 302 | if (f) |
| 303 | o << std::hex << f << std::dec << ","; |
| 304 | else |
| 305 | o << "_,"; |
| 306 | } |
| 307 | o << "],"; |
| 308 | for (int i=0; i<5; ++i) |
| 309 | { |
| 310 | if (gr.m_values[i]) |
| 311 | o << "f" << i << "=" << gr.m_values[i] << ","; |
| 312 | } |
| 313 | return o; |
| 314 | } |
| 315 | |
| 316 | //! the state of QuattroGraph |
| 317 | struct State |
| 318 | { |
| 319 | //! constructor |
| 320 | State() |
| 321 | : m_version(-1) |
| 322 | , m_actualSheet(-1) |
| 323 | , m_sheetIdToGraphMap() |
| 324 | , m_actualGraph() |
| 325 | , m_linkNameToObjectMap() |
| 326 | { |
| 327 | } |
| 328 | //! store a graph |
| 329 | void storeGraph(std::shared_ptr<Graph> graph) |
| 330 | { |
| 331 | if (!graph) |
| 332 | { |
| 333 | WPS_DEBUG_MSG(("QuattroGraphInternal::storeGraph: no graph\n")); |
| 334 | return; |
| 335 | } |
| 336 | m_actualGraph=graph; |
| 337 | if (m_actualSheet<0) |
| 338 | { |
| 339 | WPS_DEBUG_MSG(("QuattroGraphInternal::storeGraph: can not find the current sheet\n")); |
| 340 | return; |
| 341 | } |
| 342 | m_sheetIdToGraphMap.insert(std::multimap<int, std::shared_ptr<Graph> >::value_type(m_actualSheet, graph)); |
| 343 | } |
| 344 | //! returns the pattern corresponding to a pattern id between 0 and 24 |
| 345 | static bool getPattern(int id, WPSGraphicStyle::Pattern &pattern); |
| 346 | //! the file version |
| 347 | int m_version; |
| 348 | //! the actual sheet id |
| 349 | int m_actualSheet; |
| 350 | //! a multimap sheetId to graph |
| 351 | std::multimap<int, std::shared_ptr<Graph> > m_sheetIdToGraphMap; |
| 352 | //! the actual graph |
| 353 | std::shared_ptr<Graph> m_actualGraph; |
| 354 | //! a map link name to object |
| 355 | std::map<librevenge::RVNGString,WPSEmbeddedObject> m_linkNameToObjectMap; |
| 356 | }; |
| 357 | |
| 358 | bool State::getPattern(int id, WPSGraphicStyle::Pattern &pat) |
| 359 | { |
| 360 | if (id<0 || id>24) |
| 361 | { |
| 362 | WPS_DEBUG_MSG(("QuattroInternal::State::getPattern(): unknown pattern id: %d\n",id)); |
| 363 | return false; |
| 364 | } |
| 365 | static const uint16_t patterns[]= |
| 366 | { |
| 367 | 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000, 0x00ff, 0x0000, 0x00ff, 0x0000, 0x0101, 0x0101, 0x0101, 0x0101, // 0-3 |
| 368 | 0x8844, 0x2211, 0x8844, 0x2211, 0x8811, 0x2244, 0x8811, 0x2244, 0xff01, 0x0101, 0x0101, 0x0101, 0x040a, 0x11a0, 0x40a0, 0x110a, // 4-7 |
| 369 | 0x44aa, 0x1100, 0x44aa, 0x1100, 0xffff, 0x0000, 0xffff, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0x060c, 0x1830, 0x60c0, 0x8103, // 8-9 |
| 370 | 0xc060, 0x3018, 0x0c06, 0x0381, 0xc864, 0x3219, 0x8c46, 0x2391, 0xff11, 0xff11, 0xff11, 0xff11, 0xcccc, 0x3333, 0xcccc, 0x3333, |
| 371 | 0xcc33, 0xcc33, 0xcc33, 0xcc33, 0x0110, 0x0110, 0x0110, 0x0110, 0x1144, 0x1144, 0x1144, 0x1144, 0x070e, 0x9ee9, 0xe070, 0xb99b, |
| 372 | 0x0101, 0x01ff, 0x1010, 0x10ff, 0x4080, 0x0103, 0x8448, 0x3020, 0x2011, 0x0204, 0x0811, 0x8040, 0x00aa, 0x00aa, 0x00aa, 0x00aa, |
| 373 | 0xaa55, 0xaa55, 0xaa55, 0xaa55 |
| 374 | }; |
| 375 | pat.m_dim=Vec2i(8,8); |
| 376 | uint16_t const *ptr=&patterns[4*id]; |
| 377 | pat.m_data.resize(8); |
| 378 | for (size_t i=0; i < 8; i+=2) |
| 379 | { |
| 380 | uint16_t val=*(ptr++); |
| 381 | pat.m_data[i]=static_cast<unsigned char>((val>>8) & 0xFF); |
| 382 | pat.m_data[i+1]=static_cast<unsigned char>(val & 0xFF); |
| 383 | } |
| 384 | return true; |
| 385 | } |
| 386 | |
| 387 | //! Internal: the subdocument of a QuattroGraphInternal |
| 388 | class SubDocument final : public WKSSubDocument |
| 389 | { |
| 390 | public: |
| 391 | //! constructor for a textbox document |
| 392 | SubDocument(QuattroGraph &graphParser, std::shared_ptr<Textbox> const &textbox, std::shared_ptr<WPSStream> const &stream) |
| 393 | : WKSSubDocument(RVNGInputStreamPtr(), &graphParser.m_mainParser) |
| 394 | , m_graphParser(graphParser) |
| 395 | , m_textbox(textbox) |
| 396 | , m_stream(stream) |
| 397 | , m_text() {} |
| 398 | //! constructor for a text entry |
| 399 | SubDocument(QuattroGraph &graphParser, librevenge::RVNGString const &text) |
| 400 | : WKSSubDocument(RVNGInputStreamPtr(), &graphParser.m_mainParser) |
| 401 | , m_graphParser(graphParser) |
| 402 | , m_textbox() |
| 403 | , m_stream() |
| 404 | , m_text(text) {} |
| 405 | //! destructor |
| 406 | ~SubDocument() final {} |
| 407 | |
| 408 | //! operator== |
| 409 | bool operator==(std::shared_ptr<WPSSubDocument> const &doc) const final |
| 410 | { |
| 411 | if (!doc || !WKSSubDocument::operator==(doc)) |
| 412 | return false; |
| 413 | auto const *sDoc = dynamic_cast<SubDocument const *>(doc.get()); |
| 414 | if (!sDoc) return false; |
| 415 | if (&m_graphParser != &sDoc->m_graphParser) return false; |
| 416 | if (m_textbox.get() != sDoc->m_textbox.get()) return false; |
| 417 | if (m_stream.get() != sDoc->m_stream.get()) return false; |
| 418 | return m_text == sDoc->m_text; |
| 419 | } |
| 420 | |
| 421 | //! the parser function |
| 422 | void parse(std::shared_ptr<WKSContentListener> &listener, libwps::SubDocumentType subDocumentType) final; |
| 423 | //! the graph parser |
| 424 | QuattroGraph &m_graphParser; |
| 425 | //! the textbox data |
| 426 | std::shared_ptr<Textbox> m_textbox; |
| 427 | //! the file stream |
| 428 | std::shared_ptr<WPSStream> m_stream; |
| 429 | //! the main text |
| 430 | librevenge::RVNGString m_text; |
| 431 | }; |
| 432 | |
| 433 | void SubDocument::parse(std::shared_ptr<WKSContentListener> &listener, libwps::SubDocumentType) |
| 434 | { |
| 435 | if (!listener.get()) |
| 436 | { |
| 437 | WPS_DEBUG_MSG(("QuattroGraphInternal::SubDocument::parse: no listener\n")); |
| 438 | return; |
| 439 | } |
| 440 | if (!dynamic_cast<WKSContentListener *>(listener.get())) |
| 441 | { |
| 442 | WPS_DEBUG_MSG(("QuattroGraphInternal::SubDocument::parse: bad listener\n")); |
| 443 | return; |
| 444 | } |
| 445 | if (m_textbox && m_stream) |
| 446 | { |
| 447 | auto input=m_stream->m_input; |
| 448 | long actPos=input->tell(); |
| 449 | m_graphParser.send(*m_textbox, m_stream); |
| 450 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 451 | return; |
| 452 | } |
| 453 | WPSParagraph para; |
| 454 | para.m_justify=libwps::JustificationCenter; |
| 455 | listener->setParagraph(para); |
| 456 | if (!m_text.empty()) |
| 457 | listener->insertUnicodeString(m_text); |
| 458 | } |
| 459 | |
| 460 | } |
| 461 | |
| 462 | // constructor, destructor |
| 463 | QuattroGraph::QuattroGraph(QuattroParser &parser) |
| 464 | : m_listener() |
| 465 | , m_mainParser(parser) |
| 466 | , m_state(new QuattroGraphInternal::State()) |
| 467 | { |
| 468 | } |
| 469 | |
| 470 | QuattroGraph::~QuattroGraph() |
| 471 | { |
| 472 | } |
| 473 | |
| 474 | void QuattroGraph::cleanState() |
| 475 | { |
| 476 | m_state.reset(new QuattroGraphInternal::State()); |
| 477 | } |
| 478 | |
| 479 | void QuattroGraph::updateState() |
| 480 | { |
| 481 | } |
| 482 | |
| 483 | int QuattroGraph::version() const |
| 484 | { |
| 485 | if (m_state->m_version<0) |
| 486 | m_state->m_version=m_mainParser.version(); |
| 487 | return m_state->m_version; |
| 488 | } |
| 489 | |
| 490 | void QuattroGraph::storeObjects(std::map<librevenge::RVNGString,WPSEmbeddedObject> const &nameToObjectMap) |
| 491 | { |
| 492 | m_state->m_linkNameToObjectMap=nameToObjectMap; |
| 493 | } |
| 494 | |
| 495 | std::vector<Vec2i> QuattroGraph::getGraphicCellsInSheet(int sheetId) const |
| 496 | { |
| 497 | std::vector<Vec2i> list; |
| 498 | auto it=m_state->m_sheetIdToGraphMap.find(sheetId); |
| 499 | while (it!=m_state->m_sheetIdToGraphMap.end() && it->first==sheetId) |
| 500 | { |
| 501 | auto const &graph=it++->second; |
| 502 | if (graph && graph->m_type!=graph->Shape && graph->m_type!=graph->Textbox) |
| 503 | list.push_back(graph->m_cellBox[0]); |
| 504 | } |
| 505 | return list; |
| 506 | } |
| 507 | |
| 508 | //////////////////////////////////////////////////////////// |
| 509 | // low level |
| 510 | |
| 511 | //////////////////////////////////////////////////////////// |
| 512 | // zones |
| 513 | //////////////////////////////////////////////////////////// |
| 514 | bool QuattroGraph::readHeader(QuattroGraphInternal::Graph &header, std::shared_ptr<WPSStream> stream, long endPos) |
| 515 | { |
| 516 | auto input=stream->m_input; |
| 517 | long pos = input->tell(); |
| 518 | if (endPos-pos<49) |
| 519 | { |
| 520 | WPS_DEBUG_MSG(("QuattroGraph::readHeader: the zone is too short\n")); |
| 521 | return false; |
| 522 | } |
| 523 | for (auto &fl : header.m_flags1) fl=int(libwps::readU16(input)); |
| 524 | int dim[4]; |
| 525 | for (auto &d: dim) d=libwps::readU16(input); |
| 526 | header.m_cellBox=WPSBox2i(Vec2i(dim[0],dim[1]),Vec2i(dim[2],dim[3])); |
| 527 | float fDim[4]; |
| 528 | for (auto &d: fDim) d=float(libwps::read16(input))/20.f; |
| 529 | header.m_cellBoxDecal=WPSBox2f(Vec2f(fDim[0],fDim[1]),Vec2f(fDim[2],fDim[3])); |
| 530 | for (int i=0; i<2; ++i) fDim[i]=float(libwps::read32(input))/20.f; |
| 531 | header.m_size=Vec2f(fDim[0],fDim[1]); |
| 532 | for (auto &fl : header.m_flags2) fl=int(libwps::readU8(input)); |
| 533 | for (auto &v : header.m_values) v=int(libwps::read16(input)); |
| 534 | return true; |
| 535 | } |
| 536 | |
| 537 | bool QuattroGraph::readShapeHeader(QuattroGraphInternal::ShapeHeader &shape, std::shared_ptr<WPSStream> stream, long endPos) |
| 538 | { |
| 539 | int const vers=version(); |
| 540 | auto input=stream->m_input; |
| 541 | long pos = input->tell(); |
| 542 | int const endSize=15+(vers==1003 ? 3 : 0); |
| 543 | if (endPos-pos<42+(vers==1003 ? 4 : 0)) |
| 544 | { |
| 545 | WPS_DEBUG_MSG(("QuattroGraph::readShapeHeader: the zone is too short\n")); |
| 546 | return false; |
| 547 | } |
| 548 | libwps::DebugStream f; |
| 549 | shape.m_type=int(libwps::readU16(input)); // v1: 6f, v2: 73, v3: 9e |
| 550 | int wFl=0; |
| 551 | for (int i=0; i<4; ++i) |
| 552 | shape.m_flags[wFl++]=int(libwps::readU16(input)); |
| 553 | int dim[4]; |
| 554 | for (auto &d: dim) d=int(libwps::read16(input)); |
| 555 | shape.m_box=WPSBox2i(Vec2i(dim[0],dim[1]),Vec2i(dim[2],dim[3])); |
| 556 | for (int i=0; i<(vers>=1003 ? 7 : 5); ++i) |
| 557 | shape.m_flags[wFl++]=int(libwps::readU16(input)); |
| 558 | shape.m_id=int(libwps::readU16(input)); |
| 559 | auto &style=shape.m_style; |
| 560 | WPSColor surfaceColor[2]; |
| 561 | unsigned char col[4]; |
| 562 | for (auto &c : col) c=libwps::readU8(input); |
| 563 | surfaceColor[0]=WPSColor(col[0],col[1],col[2]); |
| 564 | for (auto &c : col) c=libwps::readU8(input); |
| 565 | style.m_lineColor=WPSColor(col[0],col[1],col[2]); |
| 566 | shape.m_flags[wFl++]=int(libwps::readU16(input)); |
| 567 | int hasData[2]; |
| 568 | for (auto &d : hasData) d=int(libwps::readU8(input)); |
| 569 | if (hasData[0]==1 && endPos-input->tell()>=3+endSize) |
| 570 | { |
| 571 | shape.m_values[0]=int(libwps::read8(input)); |
| 572 | shape.m_values[1]=int(libwps::read16(input)); |
| 573 | } |
| 574 | else if (hasData[0]) |
| 575 | { |
| 576 | WPS_DEBUG_MSG(("QuattroGraph::readShapeHeader: find unexpected data0 %d\n", hasData[0])); |
| 577 | return false; |
| 578 | } |
| 579 | if (hasData[1]==1 && endPos-input->tell()>=6+endSize) |
| 580 | { |
| 581 | for (int i=0; i<3; ++i) |
| 582 | shape.m_values[i+2]=int(libwps::read16(input)); |
| 583 | } |
| 584 | else if (hasData[1]) |
| 585 | { |
| 586 | WPS_DEBUG_MSG(("QuattroGraph::readShapeHeader: find unexpected data1 %d\n", hasData[1])); |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | // end data |
| 591 | shape.m_values2[0]=int(libwps::readU8(input)); |
| 592 | if (vers>=1003) |
| 593 | { |
| 594 | for (int i=0; i<2; ++i) |
| 595 | { |
| 596 | int val=i==1 ? int(libwps::read8(input)) : int(libwps::read16(input)); |
| 597 | shape.m_values2[1+i]=val; |
| 598 | } |
| 599 | } |
| 600 | int patternId=int(libwps::readU16(input)); // 154: solid |
| 601 | int lineStyle=int(libwps::readU16(input)); |
| 602 | switch (lineStyle) |
| 603 | { |
| 604 | case 1: // solid |
| 605 | break; |
| 606 | case 2: // dash |
| 607 | style.m_lineDashWidth.push_back(float(4)); |
| 608 | style.m_lineDashWidth.push_back(float(1)); |
| 609 | break; |
| 610 | case 3: // dots |
| 611 | style.m_lineDashWidth.resize(2,float(1)); |
| 612 | break; |
| 613 | case 4: // dash/dots |
| 614 | style.m_lineDashWidth.resize(4,float(1)); |
| 615 | style.m_lineDashWidth[0]=float(4); |
| 616 | break; |
| 617 | case 5: // |
| 618 | style.m_lineDashWidth.resize(6,float(1)); |
| 619 | style.m_lineDashWidth[0]=float(4); |
| 620 | break; |
| 621 | case 6: // empty |
| 622 | style.m_lineWidth=0; |
| 623 | break; |
| 624 | default: |
| 625 | WPS_DEBUG_MSG(("QuattroGraph::readShapeHeader: find unknown line style\n")); |
| 626 | f << "line[style]=##" << lineStyle << ","; |
| 627 | break; |
| 628 | } |
| 629 | for (auto &c : col) c=libwps::readU8(input); |
| 630 | surfaceColor[1]=WPSColor(col[0],col[1],col[2]); |
| 631 | int lineWidth=int(libwps::readU16(input)); |
| 632 | if (style.m_lineWidth>0) style.m_lineWidth=float(lineWidth); |
| 633 | // 0: none, 1: pattern, 5: gradient(wb3), 1001: bitmap |
| 634 | int fillType=int(libwps::readU16(input)); |
| 635 | shape.m_values2[3]=int(libwps::readU16(input)); |
| 636 | bool isTextbox=shape.isTextbox(); |
| 637 | if (fillType==0) |
| 638 | { |
| 639 | WPSGraphicStyle::Pattern pattern; |
| 640 | if (patternId==0) // none |
| 641 | ; |
| 642 | else if (patternId==1) |
| 643 | { |
| 644 | if (isTextbox) |
| 645 | style.setBackgroundColor(surfaceColor[1]); |
| 646 | else |
| 647 | style.setSurfaceColor(surfaceColor[1]); |
| 648 | } |
| 649 | else if (patternId==154) |
| 650 | { |
| 651 | if (isTextbox) |
| 652 | style.setBackgroundColor(surfaceColor[0]); |
| 653 | else |
| 654 | style.setSurfaceColor(surfaceColor[0]); |
| 655 | } |
| 656 | else if (m_state->getPattern(patternId, pattern)) |
| 657 | { |
| 658 | for (int i=0; i<2; ++i) |
| 659 | pattern.m_colors[i]=surfaceColor[i]; |
| 660 | if (isTextbox) |
| 661 | { |
| 662 | WPSColor finalColor; |
| 663 | if (pattern.getAverageColor(finalColor)) |
| 664 | style.setBackgroundColor(finalColor); |
| 665 | } |
| 666 | else |
| 667 | style.setPattern(pattern); |
| 668 | } |
| 669 | else |
| 670 | f << "###pat[id]=" << patternId << ","; |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | if (!readFillData(shape.m_style, fillType, stream, endPos)) |
| 675 | return false; |
| 676 | if (fillType>=1 && fillType<=6) |
| 677 | { |
| 678 | f << "gradient=" << fillType << ","; |
| 679 | if (isTextbox) |
| 680 | style.setBackgroundColor(WPSColor::barycenter(0.5f, surfaceColor[0], 0.5f, surfaceColor[1])); |
| 681 | else |
| 682 | { |
| 683 | style.m_gradientType=fillType<=4 ? WPSGraphicStyle::G_Linear : WPSGraphicStyle::G_Axial; |
| 684 | style.m_gradientStopList.clear(); |
| 685 | style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(0.0, surfaceColor[1])); |
| 686 | style.m_gradientStopList.push_back(WPSGraphicStyle::GradientStop(1.0, surfaceColor[0])); |
| 687 | int const rot[]= {0, 90, -90, 0, 180, 90, 0}; |
| 688 | style.m_gradientAngle=float(rot[fillType]); |
| 689 | } |
| 690 | } |
| 691 | else |
| 692 | { |
| 693 | if (!surfaceColor[0].isBlack()) f << "surf[col0]=" << surfaceColor[0] << ","; |
| 694 | if (!surfaceColor[1].isWhite()) f << "surf[col1]=" << surfaceColor[1] << ","; |
| 695 | f << "fill[type]=" << fillType << ","; |
| 696 | f << "pat[id]=" << patternId << ","; |
| 697 | if ((fillType&0xfff)==1) |
| 698 | { |
| 699 | f << "###bitmap[" << std::hex << fillType << std::dec << "],"; |
| 700 | f << "crop[type]=" << (fillType>>12) << ","; |
| 701 | stream->m_ascii.addDelimiter(input->tell(),'|'); |
| 702 | shape.m_extra=f.str(); |
| 703 | WPS_DEBUG_MSG(("QuattroGraph::readShapeHeader: find a bitmap, unimplemented!!!\n")); |
| 704 | return false; |
| 705 | } |
| 706 | f << "###fill[type]=" << std::hex << fillType << std::dec << ","; |
| 707 | WPS_DEBUG_MSG(("QuattroGraph::readShapeHeader: unexpected fill type %d\n", fillType)); |
| 708 | } |
| 709 | } |
| 710 | shape.m_extra=f.str(); |
| 711 | return true; |
| 712 | } |
| 713 | |
| 714 | bool QuattroGraph::readFillData(WPSGraphicStyle &/*style*/, int fillType, std::shared_ptr<WPSStream> stream, long endPos) |
| 715 | { |
| 716 | if (fillType==0) return true; |
| 717 | RVNGInputStreamPtr input = stream->m_input; |
| 718 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 719 | libwps::DebugStream f; |
| 720 | long pos = input->tell(); |
| 721 | if (fillType<0) |
| 722 | { |
| 723 | WPS_DEBUG_MSG(("QuattroGraph::readFillData: unexpected fillType\n")); |
| 724 | return false; |
| 725 | } |
| 726 | if (pos+4>endPos || libwps::readU16(input)!=0x2e4) |
| 727 | { |
| 728 | WPS_DEBUG_MSG(("QuattroGraph::readFillData: the zone length seems bad\n")); |
| 729 | return false; |
| 730 | } |
| 731 | f << "Entries(FillData)[" << std::hex << fillType << std::dec << ":"; |
| 732 | int dSz=int(libwps::readU16(input)); |
| 733 | if (pos+4+dSz>endPos) |
| 734 | { |
| 735 | WPS_DEBUG_MSG(("QuattroGraph::readFillData: can not read the data size\n")); |
| 736 | return false; |
| 737 | } |
| 738 | if (dSz) |
| 739 | { |
| 740 | ascFile.addDelimiter(input->tell(),'|'); |
| 741 | input->seek(pos+4+dSz, librevenge::RVNG_SEEK_SET); |
| 742 | } |
| 743 | ascFile.addPos(pos); |
| 744 | ascFile.addNote(f.str().c_str()); |
| 745 | if ((fillType&0xf000)==0 || (fillType&0xfff)!=1) |
| 746 | return true; |
| 747 | pos=input->tell(); |
| 748 | if (pos+68>endPos) |
| 749 | { |
| 750 | WPS_DEBUG_MSG(("QuattroGraph::readFillData: can not read the bitmap name\n")); |
| 751 | return false; |
| 752 | } |
| 753 | f.str(""); |
| 754 | f << "FillData[bitmap]:"; |
| 755 | int val=int(libwps::readU16(input)); |
| 756 | if (val!=10) f << "f0=" << val << ","; |
| 757 | val=int(libwps::readU16(input)); |
| 758 | if (val) f << "crop[type]=" << val << ","; |
| 759 | librevenge::RVNGString name; |
| 760 | if (!m_mainParser.readCString(stream,name,64)) |
| 761 | f << "###name,"; |
| 762 | else |
| 763 | f << name.cstr() << ","; |
| 764 | input->seek(pos+68, librevenge::RVNG_SEEK_SET); |
| 765 | ascFile.addPos(pos); |
| 766 | ascFile.addNote(f.str().c_str()); |
| 767 | |
| 768 | pos=input->tell(); |
| 769 | if (pos+10>endPos) |
| 770 | { |
| 771 | WPS_DEBUG_MSG(("QuattroGraph::readFillData: can not read the bitmap data\n")); |
| 772 | return false; |
| 773 | } |
| 774 | f.str(""); |
| 775 | f << "FillData[extra]:"; |
| 776 | val=int(libwps::readU16(input)); |
| 777 | if (val!=0x4000) f << "f0=" << val << ","; |
| 778 | val=int(libwps::readU16(input)); |
| 779 | if (val!=0x1c93) f << "f1=" << std::hex << val << std::dec << ","; |
| 780 | int dim[2]; |
| 781 | for (auto &d:dim) d=int(libwps::readU16(input)); |
| 782 | f << "dim=" << Vec2i(dim[0],dim[1]) << ","; |
| 783 | ascFile.addPos(pos); |
| 784 | ascFile.addNote(f.str().c_str()); |
| 785 | |
| 786 | return true; |
| 787 | } |
| 788 | |
| 789 | bool QuattroGraph::readBeginEnd(std::shared_ptr<WPSStream> stream, int sheetId) |
| 790 | { |
| 791 | RVNGInputStreamPtr input = stream->m_input; |
| 792 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 793 | libwps::DebugStream f; |
| 794 | long pos = input->tell(); |
| 795 | auto type = int(libwps::readU16(input)&0x7fff); |
| 796 | |
| 797 | if (type != 0x321 && type != 0x322) |
| 798 | { |
| 799 | WPS_DEBUG_MSG(("QuattroGraph::readBeginEnd: not a begin/end zone\n")); |
| 800 | return false; |
| 801 | } |
| 802 | auto sz = long(libwps::readU16(input)); |
| 803 | int const expectedSize=(type==0x321 ? 0 : 2); |
| 804 | m_state->m_actualGraph.reset(); |
| 805 | m_state->m_actualSheet=type==0x321 ? sheetId : -1; |
| 806 | if (sz!=expectedSize) |
| 807 | { |
| 808 | WPS_DEBUG_MSG(("QuattroGraph::readBeginEnd: size seems very bad\n")); |
| 809 | f << "###"; |
| 810 | ascFile.addPos(pos); |
| 811 | ascFile.addNote(f.str().c_str()); |
| 812 | return true; |
| 813 | } |
| 814 | if (type==0x322) // always 0 |
| 815 | { |
| 816 | auto val=int(libwps::read16(input)); |
| 817 | if (val) f << "f0=" << val << ","; |
| 818 | } |
| 819 | ascFile.addPos(pos); |
| 820 | ascFile.addNote(f.str().c_str()); |
| 821 | return true; |
| 822 | } |
| 823 | |
| 824 | bool QuattroGraph::readFrame(std::shared_ptr<WPSStream> stream) |
| 825 | { |
| 826 | RVNGInputStreamPtr input = stream->m_input; |
| 827 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 828 | libwps::DebugStream f; |
| 829 | long pos = input->tell(); |
| 830 | auto type = int(libwps::readU16(input)&0x7fff); |
| 831 | |
| 832 | if (type != 0x385) |
| 833 | { |
| 834 | WPS_DEBUG_MSG(("QuattroGraph::readFrame: not a frame zone\n")); |
| 835 | return false; |
| 836 | } |
| 837 | auto sz = long(libwps::readU16(input)); |
| 838 | long endPos=pos+4+sz; |
| 839 | auto frame=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::Frame); |
| 840 | m_state->m_actualGraph.reset(); |
| 841 | if (sz<57 || !readHeader(*frame,stream,endPos)) |
| 842 | { |
| 843 | if (sz) |
| 844 | { |
| 845 | WPS_DEBUG_MSG(("QuattroGraph::readFrame: size seems very bad\n")); |
| 846 | f << "###"; |
| 847 | } |
| 848 | ascFile.addPos(pos); |
| 849 | ascFile.addNote(f.str().c_str()); |
| 850 | return true; |
| 851 | } |
| 852 | f << *frame; |
| 853 | m_state->storeGraph(frame); |
| 854 | auto sSz=int(libwps::readU16(input)); |
| 855 | librevenge::RVNGString text; |
| 856 | if (input->tell()+sSz+6>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 857 | { |
| 858 | WPS_DEBUG_MSG(("QuattroGraph::readFrame: can not read string1\n")); |
| 859 | f << "##sSz,"; |
| 860 | ascFile.addPos(pos); |
| 861 | ascFile.addNote(f.str().c_str()); |
| 862 | return true; |
| 863 | } |
| 864 | f << "name=" << text.cstr() << ","; |
| 865 | for (int i=0; i<3; ++i) // g0=1, g2=2001 |
| 866 | { |
| 867 | auto val=int(libwps::readU16(input)); |
| 868 | if (val) |
| 869 | f << "g" << i << "=" << std::hex << val << std::dec << ","; |
| 870 | } |
| 871 | if (input->tell()!=endPos) |
| 872 | { |
| 873 | ascFile.addDelimiter(input->tell(),'|'); |
| 874 | WPS_DEBUG_MSG(("QuattroGraph::readFrame: find extra data\n")); |
| 875 | f << "##extra,"; |
| 876 | } |
| 877 | ascFile.addPos(pos); |
| 878 | ascFile.addNote(f.str().c_str()); |
| 879 | return true; |
| 880 | } |
| 881 | |
| 882 | bool QuattroGraph::readFrameOLE(std::shared_ptr<WPSStream> stream) |
| 883 | { |
| 884 | RVNGInputStreamPtr input = stream->m_input; |
| 885 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 886 | libwps::DebugStream f; |
| 887 | long pos = input->tell(); |
| 888 | auto type = int(libwps::readU16(input)&0x7fff); |
| 889 | |
| 890 | if (type != 0x381) |
| 891 | { |
| 892 | WPS_DEBUG_MSG(("QuattroGraph::readFrameOLE: not a frame zone\n")); |
| 893 | return false; |
| 894 | } |
| 895 | auto sz = long(libwps::readU16(input)); |
| 896 | long endPos=pos+4+sz; |
| 897 | auto frame=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::OLE); |
| 898 | m_state->m_actualGraph.reset(); |
| 899 | if (sz<59 || !readHeader(*frame,stream,endPos)) |
| 900 | { |
| 901 | if (sz) |
| 902 | { |
| 903 | WPS_DEBUG_MSG(("QuattroGraph::readFrameOLE: size seems very bad\n")); |
| 904 | f << "###"; |
| 905 | } |
| 906 | ascFile.addPos(pos); |
| 907 | ascFile.addNote(f.str().c_str()); |
| 908 | return true; |
| 909 | } |
| 910 | f << *frame; |
| 911 | m_state->storeGraph(frame); |
| 912 | auto sSz=int(libwps::readU16(input)); |
| 913 | librevenge::RVNGString text; |
| 914 | if (input->tell()+sSz+4>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 915 | { |
| 916 | WPS_DEBUG_MSG(("QuattroGraph::readFrameOLE: can not read string1\n")); |
| 917 | f << "##sSz,"; |
| 918 | ascFile.addPos(pos); |
| 919 | ascFile.addNote(f.str().c_str()); |
| 920 | return true; |
| 921 | } |
| 922 | frame->m_linkName=text; |
| 923 | f << "name=" << text.cstr() << ","; |
| 924 | for (int i=0; i<4; ++i) // g0=11, g2=d00, g4=7500 |
| 925 | { |
| 926 | auto val=int(libwps::readU16(input)); |
| 927 | if (val) |
| 928 | f << "g" << i << "=" << std::hex << val << std::dec << ","; |
| 929 | } |
| 930 | if (input->tell()!=endPos) |
| 931 | { |
| 932 | ascFile.addDelimiter(input->tell(),'|'); |
| 933 | WPS_DEBUG_MSG(("QuattroGraph::readFrameOLE: find extra data\n")); |
| 934 | f << "##extra,"; |
| 935 | } |
| 936 | ascFile.addPos(pos); |
| 937 | ascFile.addNote(f.str().c_str()); |
| 938 | return true; |
| 939 | } |
| 940 | |
| 941 | bool QuattroGraph::readOLEData(std::shared_ptr<WPSStream> stream) |
| 942 | { |
| 943 | RVNGInputStreamPtr input = stream->m_input; |
| 944 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 945 | libwps::DebugStream f; |
| 946 | long pos = input->tell(); |
| 947 | auto type = int(libwps::readU16(input)&0x7fff); |
| 948 | |
| 949 | if (type != 0x38b) |
| 950 | { |
| 951 | WPS_DEBUG_MSG(("QuattroGraph::readOLEData: not a OLE zone\n")); |
| 952 | return false; |
| 953 | } |
| 954 | auto sz = long(libwps::readU16(input)); |
| 955 | long endPos=sz<0xFF00 ? pos+4+sz : stream->m_eof; |
| 956 | if (sz<38) |
| 957 | { |
| 958 | if (sz) |
| 959 | { |
| 960 | WPS_DEBUG_MSG(("QuattroGraph::readOLEData: size seems very bad\n")); |
| 961 | f << "###"; |
| 962 | } |
| 963 | ascFile.addPos(pos); |
| 964 | ascFile.addNote(f.str().c_str()); |
| 965 | return true; |
| 966 | } |
| 967 | auto frame=m_state->m_actualGraph; |
| 968 | if (frame && frame->m_type!=frame->Frame) |
| 969 | frame.reset(); |
| 970 | if (frame) |
| 971 | frame->m_type=frame->OLE; |
| 972 | else |
| 973 | { |
| 974 | WPS_DEBUG_MSG(("QuattroGraph::readOLEData: can not find current frame\n")); |
| 975 | } |
| 976 | for (int i=0; i<5; ++i) |
| 977 | { |
| 978 | int val=int(libwps::readU16(input)); |
| 979 | int const expected[]= {0x1a,0x8068,0x2001,0,0}; |
| 980 | if (val!=expected[i]) |
| 981 | f << "f" << i << "=" << std::hex << val << std::dec << ","; |
| 982 | } |
| 983 | long actPos=input->tell(); |
| 984 | auto sSz=int(libwps::readU16(input)); |
| 985 | librevenge::RVNGString text; |
| 986 | if (actPos+2+sSz+12+1+12>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 987 | { |
| 988 | WPS_DEBUG_MSG(("QuattroGraph::readOLEData: can not read the name\n")); |
| 989 | f << "##sSz,"; |
| 990 | ascFile.addPos(pos); |
| 991 | ascFile.addNote(f.str().c_str()); |
| 992 | return true; |
| 993 | } |
| 994 | f << "name=" << text.cstr() << ","; |
| 995 | input->seek(actPos+2+sSz, librevenge::RVNG_SEEK_SET); |
| 996 | ascFile.addPos(pos); |
| 997 | ascFile.addNote(f.str().c_str()); |
| 998 | |
| 999 | pos=input->tell(); |
| 1000 | WPSEmbeddedObject dummyObject; |
| 1001 | if (!WPSOLEObject::readOLE(stream, frame ? frame->m_ole : dummyObject,endPos)) |
| 1002 | input->seek(pos, librevenge::RVNG_SEEK_SET); |
| 1003 | if (input->tell()!=endPos) |
| 1004 | { |
| 1005 | WPS_DEBUG_MSG(("QuattroGraph::readOLEData: find extra data\n")); |
| 1006 | ascFile.addPos(input->tell()); |
| 1007 | ascFile.addNote("Object:###extra"); |
| 1008 | } |
| 1009 | return true; |
| 1010 | } |
| 1011 | |
| 1012 | bool QuattroGraph::readButton(std::shared_ptr<WPSStream> stream) |
| 1013 | { |
| 1014 | RVNGInputStreamPtr input = stream->m_input; |
| 1015 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1016 | libwps::DebugStream f; |
| 1017 | long pos = input->tell(); |
| 1018 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1019 | |
| 1020 | if (type != 0x386) |
| 1021 | { |
| 1022 | WPS_DEBUG_MSG(("QuattroGraph::readButton: not a button zone\n")); |
| 1023 | return false; |
| 1024 | } |
| 1025 | auto sz = long(libwps::readU16(input)); |
| 1026 | long endPos=pos+4+sz; |
| 1027 | m_state->m_actualGraph.reset(); |
| 1028 | auto button=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::Button); |
| 1029 | if (sz<67 || !readHeader(*button,stream,endPos)) |
| 1030 | { |
| 1031 | if (sz) |
| 1032 | { |
| 1033 | WPS_DEBUG_MSG(("QuattroGraph::readButton: size seems very bad\n")); |
| 1034 | f << "###"; |
| 1035 | } |
| 1036 | ascFile.addPos(pos); |
| 1037 | ascFile.addNote(f.str().c_str()); |
| 1038 | return true; |
| 1039 | } |
| 1040 | f << *button; // fl1=[7f|81,0x8063,0x2000,0]; |
| 1041 | ascFile.addPos(pos); |
| 1042 | ascFile.addNote(f.str().c_str()); |
| 1043 | |
| 1044 | pos=input->tell(); |
| 1045 | f.str(""); |
| 1046 | f << "Object-A:"; |
| 1047 | auto sSz=int(libwps::readU16(input)); |
| 1048 | librevenge::RVNGString text; |
| 1049 | if (pos+2+sSz>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1050 | { |
| 1051 | WPS_DEBUG_MSG(("QuattroGraph::readButton: can not read string1 bad\n")); |
| 1052 | f << "##sSz,"; |
| 1053 | ascFile.addPos(pos); |
| 1054 | ascFile.addNote(f.str().c_str()); |
| 1055 | return true; |
| 1056 | } |
| 1057 | input->seek(pos+2+sSz, librevenge::RVNG_SEEK_SET); |
| 1058 | f << "name=" << text.cstr() << ","; |
| 1059 | for (int i=0; i<5; ++i) |
| 1060 | { |
| 1061 | auto val=int(libwps::readU16(input)); |
| 1062 | if (val) f << "f" << i << "=" << val << ","; |
| 1063 | } |
| 1064 | auto val=int(libwps::readU8(input)); |
| 1065 | if (val) f << "f5=" << val << ","; |
| 1066 | ascFile.addPos(pos); |
| 1067 | ascFile.addNote(f.str().c_str()); |
| 1068 | pos=input->tell(); |
| 1069 | f.str(""); |
| 1070 | f << "Object-B:"; |
| 1071 | auto dType=int(libwps::readU8(input)); |
| 1072 | if (dType==1) f << "complex,"; |
| 1073 | else if (dType) |
| 1074 | { |
| 1075 | WPS_DEBUG_MSG(("QuattroGraph::readButton: find unknown type\n")); |
| 1076 | f << "##dType=" << dType << ","; |
| 1077 | } |
| 1078 | for (int st=0; st<2; ++st) |
| 1079 | { |
| 1080 | sSz=int(libwps::readU16(input)); |
| 1081 | if (pos+2+sSz>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1082 | { |
| 1083 | WPS_DEBUG_MSG(("QuattroGraph::readButton: can not read string2 bad\n")); |
| 1084 | f << "##sSz,"; |
| 1085 | ascFile.addPos(pos); |
| 1086 | ascFile.addNote(f.str().c_str()); |
| 1087 | return true; |
| 1088 | } |
| 1089 | if (text.empty()) continue; |
| 1090 | f << (st==0 ? "macros" : "label") << "=" << text.cstr() << ","; |
| 1091 | if (st==1) |
| 1092 | button->m_label=text; |
| 1093 | } |
| 1094 | if (dType==0) |
| 1095 | { |
| 1096 | if (input->tell()!=endPos) |
| 1097 | { |
| 1098 | WPS_DEBUG_MSG(("QuattroGraph::readButton: find extra data\n")); |
| 1099 | f << "##extra,"; |
| 1100 | ascFile.addDelimiter(input->tell(),'|'); |
| 1101 | } |
| 1102 | m_state->storeGraph(button); |
| 1103 | } |
| 1104 | ascFile.addPos(pos); |
| 1105 | ascFile.addNote(f.str().c_str()); |
| 1106 | |
| 1107 | if (dType && input->tell()!=endPos) |
| 1108 | { |
| 1109 | ascFile.addPos(input->tell()); |
| 1110 | ascFile.addNote("Object-C:"); |
| 1111 | } |
| 1112 | return true; |
| 1113 | } |
| 1114 | |
| 1115 | bool QuattroGraph::readImage(std::shared_ptr<WPSStream> stream) |
| 1116 | { |
| 1117 | RVNGInputStreamPtr input = stream->m_input; |
| 1118 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1119 | libwps::DebugStream f; |
| 1120 | long pos = input->tell(); |
| 1121 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1122 | |
| 1123 | if (type != 0x382) |
| 1124 | { |
| 1125 | WPS_DEBUG_MSG(("QuattroGraph::readImage: unknown id\n")); |
| 1126 | return false; |
| 1127 | } |
| 1128 | auto sz = long(libwps::readU16(input)); |
| 1129 | long endPos=pos+4+sz; |
| 1130 | auto zone382=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::Image); |
| 1131 | m_state->m_actualGraph.reset(); |
| 1132 | if (sz<53 || !readHeader(*zone382,stream,endPos)) |
| 1133 | { |
| 1134 | if (sz) |
| 1135 | { |
| 1136 | WPS_DEBUG_MSG(("QuattroGraph::readImage: size seems very bad\n")); |
| 1137 | f << "###"; |
| 1138 | } |
| 1139 | ascFile.addPos(pos); |
| 1140 | ascFile.addNote(f.str().c_str()); |
| 1141 | return true; |
| 1142 | } |
| 1143 | f << *zone382; |
| 1144 | auto sSz=int(libwps::readU16(input)); |
| 1145 | librevenge::RVNGString text; |
| 1146 | if (input->tell()+sSz+2>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1147 | { |
| 1148 | WPS_DEBUG_MSG(("QuattroGraph::readImage: can not read string1\n")); |
| 1149 | f << "##sSz,"; |
| 1150 | ascFile.addPos(pos); |
| 1151 | ascFile.addNote(f.str().c_str()); |
| 1152 | return true; |
| 1153 | } |
| 1154 | f << text.cstr() << ","; // find Bitmap5, followed by |
| 1155 | // 20000000070001000080000000ffffff0000000100000000070064e96729a1e87328af2b0700628597334100 |
| 1156 | // c767040064e96729b7e87328af2b04008bce67354800 |
| 1157 | // c7670500673575ce0400 |
| 1158 | // 2d002d00: a picture dimension ? |
| 1159 | // eb010000: the gif's size |
| 1160 | // the gif |
| 1161 | if (input->tell()!=endPos) |
| 1162 | { |
| 1163 | ascFile.addDelimiter(input->tell(),'|'); |
| 1164 | } |
| 1165 | static bool first=true; |
| 1166 | if (first) |
| 1167 | { |
| 1168 | first=false; |
| 1169 | WPS_DEBUG_MSG(("QuattroGraph::readImage: this file contains a zone 382, there will not be recovered\n")); |
| 1170 | } |
| 1171 | ascFile.addPos(pos); |
| 1172 | ascFile.addNote(f.str().c_str()); |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
| 1176 | bool QuattroGraph::readBitmap(std::shared_ptr<WPSStream> stream) |
| 1177 | { |
| 1178 | RVNGInputStreamPtr input = stream->m_input; |
| 1179 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1180 | libwps::DebugStream f; |
| 1181 | long pos = input->tell(); |
| 1182 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1183 | |
| 1184 | if (type != 0x383) |
| 1185 | { |
| 1186 | WPS_DEBUG_MSG(("QuattroGraph::readBitmap: unknown id\n")); |
| 1187 | return false; |
| 1188 | } |
| 1189 | auto sz = long(libwps::readU16(input)); |
| 1190 | long endPos=pos+4+sz; |
| 1191 | auto bitmap=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::OLE); |
| 1192 | m_state->m_actualGraph.reset(); |
| 1193 | if (sz<67 || !readHeader(*bitmap,stream,endPos)) |
| 1194 | { |
| 1195 | if (sz) |
| 1196 | { |
| 1197 | WPS_DEBUG_MSG(("QuattroGraph::readBitmap: size seems very bad\n")); |
| 1198 | f << "###"; |
| 1199 | } |
| 1200 | ascFile.addPos(pos); |
| 1201 | ascFile.addNote(f.str().c_str()); |
| 1202 | return true; |
| 1203 | } |
| 1204 | f << *bitmap; |
| 1205 | auto sSz=int(libwps::readU16(input)); |
| 1206 | librevenge::RVNGString text; |
| 1207 | if (input->tell()+sSz+16>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1208 | { |
| 1209 | WPS_DEBUG_MSG(("QuattroGraph::readBitmap: can not read string1\n")); |
| 1210 | f << "##sSz,"; |
| 1211 | ascFile.addPos(pos); |
| 1212 | ascFile.addNote(f.str().c_str()); |
| 1213 | return true; |
| 1214 | } |
| 1215 | f << text.cstr() << ","; |
| 1216 | f << "unkn=["; |
| 1217 | for (int i=0; i<8; ++i) |
| 1218 | { |
| 1219 | auto val=int(libwps::readU16(input)); |
| 1220 | if (val) |
| 1221 | f << std::hex << val << std::dec << ","; |
| 1222 | else |
| 1223 | f << "_,"; |
| 1224 | } |
| 1225 | f << "],"; |
| 1226 | ascFile.addPos(pos); |
| 1227 | ascFile.addNote(f.str().c_str()); |
| 1228 | |
| 1229 | WPSEmbeddedObject object; |
| 1230 | pos=input->tell(); |
| 1231 | if (!WPSOLEObject::readWMF(stream, bitmap->m_ole, endPos)) |
| 1232 | { |
| 1233 | WPS_DEBUG_MSG(("QuattroGraph::readBitmap: can not find the wmf file\n")); |
| 1234 | ascFile.addPos(pos); |
| 1235 | ascFile.addNote("Object:###"); |
| 1236 | } |
| 1237 | else |
| 1238 | m_state->storeGraph(bitmap); |
| 1239 | |
| 1240 | return true; |
| 1241 | } |
| 1242 | |
| 1243 | bool QuattroGraph::readChart(std::shared_ptr<WPSStream> stream) |
| 1244 | { |
| 1245 | RVNGInputStreamPtr input = stream->m_input; |
| 1246 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1247 | libwps::DebugStream f; |
| 1248 | long pos = input->tell(); |
| 1249 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1250 | |
| 1251 | if (type != 0x384) |
| 1252 | { |
| 1253 | WPS_DEBUG_MSG(("QuattroGraph::readChart: unknown id\n")); |
| 1254 | return false; |
| 1255 | } |
| 1256 | auto sz = long(libwps::readU16(input)); |
| 1257 | long endPos=pos+4+sz; |
| 1258 | auto chart=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::Chart); |
| 1259 | m_state->m_actualGraph.reset(); |
| 1260 | if (sz<57 || !readHeader(*chart,stream,endPos)) |
| 1261 | { |
| 1262 | if (sz) |
| 1263 | { |
| 1264 | WPS_DEBUG_MSG(("QuattroGraph::readChart: size seems very bad\n")); |
| 1265 | f << "###"; |
| 1266 | } |
| 1267 | ascFile.addPos(pos); |
| 1268 | ascFile.addNote(f.str().c_str()); |
| 1269 | return true; |
| 1270 | } |
| 1271 | f << *chart; |
| 1272 | auto sSz=int(libwps::readU16(input)); |
| 1273 | librevenge::RVNGString text; |
| 1274 | if (input->tell()+sSz+6>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1275 | { |
| 1276 | WPS_DEBUG_MSG(("QuattroGraph::readChart: can not read string1\n")); |
| 1277 | f << "##sSz,"; |
| 1278 | ascFile.addPos(pos); |
| 1279 | ascFile.addNote(f.str().c_str()); |
| 1280 | return true; |
| 1281 | } |
| 1282 | f << text.cstr() << ","; // find Inserted1-21 |
| 1283 | for (int i=0; i<2; ++i) // f0=1|30 |
| 1284 | { |
| 1285 | auto val=int(libwps::read16(input)); |
| 1286 | if (val) f << "f" << i << "=" << val << ","; |
| 1287 | } |
| 1288 | sSz=int(libwps::readU16(input)); |
| 1289 | if (input->tell()+sSz>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1290 | { |
| 1291 | WPS_DEBUG_MSG(("QuattroGraph::readChart: can not read string1\n")); |
| 1292 | f << "##sSz2,"; |
| 1293 | ascFile.addPos(pos); |
| 1294 | ascFile.addNote(f.str().c_str()); |
| 1295 | return true; |
| 1296 | } |
| 1297 | f << "name=" << text.cstr() << ","; |
| 1298 | if (input->tell()!=endPos) |
| 1299 | { |
| 1300 | WPS_DEBUG_MSG(("QuattroGraph::readChart: find extra data\n")); |
| 1301 | f << "##extra,"; |
| 1302 | ascFile.addDelimiter(input->tell(),'|'); |
| 1303 | } |
| 1304 | static bool first=true; |
| 1305 | if (first) |
| 1306 | { |
| 1307 | first=false; |
| 1308 | WPS_DEBUG_MSG(("QuattroGraph::readChart: this file contains some charts, there will not be recovered\n")); |
| 1309 | } |
| 1310 | ascFile.addPos(pos); |
| 1311 | ascFile.addNote(f.str().c_str()); |
| 1312 | return true; |
| 1313 | } |
| 1314 | |
| 1315 | //////////////////////////////////////////////////////////// |
| 1316 | // shape, line, ... |
| 1317 | //////////////////////////////////////////////////////////// |
| 1318 | bool QuattroGraph::readShape(std::shared_ptr<WPSStream> stream) |
| 1319 | { |
| 1320 | RVNGInputStreamPtr input = stream->m_input; |
| 1321 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1322 | libwps::DebugStream f; |
| 1323 | long pos = input->tell(); |
| 1324 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1325 | |
| 1326 | if (type != 0x4d3) |
| 1327 | { |
| 1328 | WPS_DEBUG_MSG(("QuattroGraph::readShape: not a shape zone\n")); |
| 1329 | return false; |
| 1330 | } |
| 1331 | auto sz = long(libwps::readU16(input)); |
| 1332 | long endPos=pos+4+sz; |
| 1333 | auto shape=std::make_shared<QuattroGraphInternal::Graph>(stream,QuattroGraphInternal::Graph::Shape); |
| 1334 | m_state->m_actualGraph.reset(); |
| 1335 | if (sz<59 || !readHeader(*shape,stream,endPos)) |
| 1336 | { |
| 1337 | if (sz) |
| 1338 | { |
| 1339 | WPS_DEBUG_MSG(("QuattroGraph::readShape: size seems very bad\n")); |
| 1340 | f << "###"; |
| 1341 | } |
| 1342 | ascFile.addPos(pos); |
| 1343 | ascFile.addNote(f.str().c_str()); |
| 1344 | return true; |
| 1345 | } |
| 1346 | f << *shape; |
| 1347 | auto sSz=int(libwps::readU16(input)); |
| 1348 | librevenge::RVNGString text; |
| 1349 | if (input->tell()+sSz+8>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1350 | { |
| 1351 | WPS_DEBUG_MSG(("QuattroGraph::readShape: can not read string1\n")); |
| 1352 | f << "##sSz,"; |
| 1353 | ascFile.addPos(pos); |
| 1354 | ascFile.addNote(f.str().c_str()); |
| 1355 | return true; |
| 1356 | } |
| 1357 | shape->m_linkName=text; |
| 1358 | f << "name=" << text.cstr() << ","; |
| 1359 | for (int i=0; i<4; ++i) // f2=1b(oval) 37(line),41(rect), 56(rect oval), 58(arrow) |
| 1360 | { |
| 1361 | int val=int(libwps::read16(input)); |
| 1362 | int const expected[]= {0x20,0,0,0x2001}; |
| 1363 | if (val!=expected[i]) |
| 1364 | f << "f" << i << "=" << val << ","; |
| 1365 | } |
| 1366 | m_state->storeGraph(shape); |
| 1367 | if (input->tell()!=endPos) |
| 1368 | { |
| 1369 | ascFile.addDelimiter(input->tell(),'|'); |
| 1370 | f << "##extra,"; |
| 1371 | WPS_DEBUG_MSG(("QuattroGraph::readShape: find extra data\n")); |
| 1372 | } |
| 1373 | ascFile.addPos(pos); |
| 1374 | ascFile.addNote(f.str().c_str()); |
| 1375 | return true; |
| 1376 | } |
| 1377 | |
| 1378 | bool QuattroGraph::readLine(std::shared_ptr<WPSStream> stream) |
| 1379 | { |
| 1380 | RVNGInputStreamPtr input = stream->m_input; |
| 1381 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1382 | libwps::DebugStream f; |
| 1383 | long pos = input->tell(); |
| 1384 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1385 | if (type!=0x35a && type!=0x37b) |
| 1386 | { |
| 1387 | WPS_DEBUG_MSG(("QuattroGraph::readLine: not a line zone\n")); |
| 1388 | return false; |
| 1389 | } |
| 1390 | auto parent=m_state->m_actualGraph; |
| 1391 | m_state->m_actualGraph.reset(); |
| 1392 | auto sz = long(libwps::readU16(input)); |
| 1393 | long endPos=pos+4+sz; |
| 1394 | auto shape=std::make_shared<QuattroGraphInternal::Shape>(); |
| 1395 | if (sz<58 || !readShapeHeader(*shape, stream, endPos-1) || input->tell()+1>endPos) |
| 1396 | { |
| 1397 | if (sz) |
| 1398 | { |
| 1399 | WPS_DEBUG_MSG(("QuattroGraph::readLine: the size seems very bad\n")); |
| 1400 | f << shape << ","; |
| 1401 | f << "###"; |
| 1402 | } |
| 1403 | ascFile.addPos(pos); |
| 1404 | ascFile.addNote(f.str().c_str()); |
| 1405 | return true; |
| 1406 | } |
| 1407 | f << *shape << ","; |
| 1408 | ascFile.addPos(pos); |
| 1409 | ascFile.addNote(f.str().c_str()); |
| 1410 | |
| 1411 | pos=input->tell(); |
| 1412 | f.str(""); |
| 1413 | f << "GrLine:"; |
| 1414 | int val=int(libwps::readU8(input)); |
| 1415 | f << "type=" << val << ","; |
| 1416 | if (input->tell()!=endPos) |
| 1417 | { |
| 1418 | ascFile.addDelimiter(input->tell(),'|'); |
| 1419 | f << "##extra,"; |
| 1420 | WPS_DEBUG_MSG(("QuattroGraph::readLine: find extra data\n")); |
| 1421 | } |
| 1422 | shape->m_style.m_arrows[1]=type==0x37b; |
| 1423 | switch (val&3) |
| 1424 | { |
| 1425 | case 1: |
| 1426 | shape->m_shape=WPSGraphicShape::line(Vec2f(float(shape->m_box[1][0]),float(shape->m_box[0][1])), |
| 1427 | Vec2f(float(shape->m_box[0][0]),float(shape->m_box[1][1]))); |
| 1428 | break; |
| 1429 | case 2: |
| 1430 | shape->m_shape=WPSGraphicShape::line(Vec2f(shape->m_box[1]),Vec2f(shape->m_box[0])); |
| 1431 | break; |
| 1432 | case 3: |
| 1433 | shape->m_shape=WPSGraphicShape::line(Vec2f(float(shape->m_box[0][0]),float(shape->m_box[1][1])), |
| 1434 | Vec2f(float(shape->m_box[1][0]),float(shape->m_box[0][1]))); |
| 1435 | break; |
| 1436 | case 0: |
| 1437 | default: |
| 1438 | shape->m_shape=WPSGraphicShape::line(Vec2f(shape->m_box[0]),Vec2f(shape->m_box[1])); |
| 1439 | break; |
| 1440 | } |
| 1441 | if (parent && parent->m_type==parent->Shape) |
| 1442 | parent->m_shape=shape; |
| 1443 | |
| 1444 | ascFile.addPos(pos); |
| 1445 | ascFile.addNote(f.str().c_str()); |
| 1446 | return true; |
| 1447 | } |
| 1448 | |
| 1449 | bool QuattroGraph::readRect(std::shared_ptr<WPSStream> stream) |
| 1450 | { |
| 1451 | RVNGInputStreamPtr input = stream->m_input; |
| 1452 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1453 | libwps::DebugStream f; |
| 1454 | long pos = input->tell(); |
| 1455 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1456 | |
| 1457 | auto parent=m_state->m_actualGraph; |
| 1458 | m_state->m_actualGraph.reset(); |
| 1459 | if (type!=0x33e && type!=0x364 && type!=0x379) |
| 1460 | { |
| 1461 | WPS_DEBUG_MSG(("QuattroGraph::readRect: not a rect zone\n")); |
| 1462 | return false; |
| 1463 | } |
| 1464 | auto sz = long(libwps::readU16(input)); |
| 1465 | long endPos=pos+4+sz; |
| 1466 | auto shape=std::make_shared<QuattroGraphInternal::Shape>(); |
| 1467 | if (sz<57 || !readShapeHeader(*shape, stream, endPos)) |
| 1468 | { |
| 1469 | if (sz) |
| 1470 | { |
| 1471 | WPS_DEBUG_MSG(("QuattroGraph::readRect: the size seems very bad\n")); |
| 1472 | f << *shape << ","; |
| 1473 | f << "###"; |
| 1474 | } |
| 1475 | ascFile.addPos(pos); |
| 1476 | ascFile.addNote(f.str().c_str()); |
| 1477 | return true; |
| 1478 | } |
| 1479 | f << *shape << ","; |
| 1480 | switch (type) |
| 1481 | { |
| 1482 | case 0x33e: |
| 1483 | shape->m_shape=WPSGraphicShape::circle(WPSBox2f(shape->m_box)); |
| 1484 | break; |
| 1485 | case 0x364: |
| 1486 | shape->m_shape=WPSGraphicShape::rectangle(WPSBox2f(shape->m_box)); |
| 1487 | break; |
| 1488 | default: |
| 1489 | case 0x379: |
| 1490 | shape->m_shape=WPSGraphicShape::rectangle(WPSBox2f(shape->m_box), Vec2f(20,20)); |
| 1491 | break; |
| 1492 | } |
| 1493 | if (parent && parent->m_type==parent->Shape) |
| 1494 | parent->m_shape=shape; |
| 1495 | if (input->tell()!=endPos) |
| 1496 | { |
| 1497 | ascFile.addDelimiter(input->tell(),'|'); |
| 1498 | f << "##extra,"; |
| 1499 | WPS_DEBUG_MSG(("QuattroGraph::readRect: find extra data\n")); |
| 1500 | } |
| 1501 | ascFile.addPos(pos); |
| 1502 | ascFile.addNote(f.str().c_str()); |
| 1503 | return true; |
| 1504 | } |
| 1505 | |
| 1506 | bool QuattroGraph::readPolygon(std::shared_ptr<WPSStream> stream) |
| 1507 | { |
| 1508 | RVNGInputStreamPtr input = stream->m_input; |
| 1509 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1510 | libwps::DebugStream f; |
| 1511 | long pos = input->tell(); |
| 1512 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1513 | if (type!=0x35b && type!=0x35c && type!=0x37c && type!=0x388) |
| 1514 | { |
| 1515 | WPS_DEBUG_MSG(("QuattroGraph::readPolygon: not a polygon zone\n")); |
| 1516 | return false; |
| 1517 | } |
| 1518 | auto parent=m_state->m_actualGraph; |
| 1519 | m_state->m_actualGraph.reset(); |
| 1520 | auto sz = long(libwps::readU16(input)); |
| 1521 | long endPos=pos+4+sz; |
| 1522 | auto shape=std::make_shared<QuattroGraphInternal::Shape>(); |
| 1523 | if (sz<57 || !readShapeHeader(*shape, stream, endPos-6) || input->tell()+6>endPos) |
| 1524 | { |
| 1525 | if (sz) |
| 1526 | { |
| 1527 | WPS_DEBUG_MSG(("QuattroGraph::readPolygon: the size seems very bad\n")); |
| 1528 | f << *shape << ","; |
| 1529 | f << "###"; |
| 1530 | } |
| 1531 | ascFile.addPos(pos); |
| 1532 | ascFile.addNote(f.str().c_str()); |
| 1533 | return true; |
| 1534 | } |
| 1535 | f << *shape << ","; |
| 1536 | ascFile.addPos(pos); |
| 1537 | ascFile.addNote(f.str().c_str()); |
| 1538 | |
| 1539 | pos=input->tell(); |
| 1540 | f.str(""); |
| 1541 | f << "GrPolygon:"; |
| 1542 | int N=int(libwps::readU16(input)); |
| 1543 | if ((endPos-pos-2)/4!=N+1) |
| 1544 | { |
| 1545 | WPS_DEBUG_MSG(("QuattroGraph::readPolygon: the number of points seems very bad\n")); |
| 1546 | f << "###N=" << N << ","; |
| 1547 | ascFile.addPos(pos); |
| 1548 | ascFile.addNote(f.str().c_str()); |
| 1549 | return true; |
| 1550 | } |
| 1551 | if (type==0x35c || type==0x37c) // FIXME |
| 1552 | shape->m_shape=WPSGraphicShape::polyline(WPSBox2f(shape->m_box)); |
| 1553 | else |
| 1554 | shape->m_shape=WPSGraphicShape::polygon(WPSBox2f(shape->m_box)); |
| 1555 | f << "pts=["; |
| 1556 | for (int i=0; i<=N; ++i) |
| 1557 | { |
| 1558 | int pt[2]; |
| 1559 | for (auto &p : pt) p=int(libwps::read16(input)); |
| 1560 | shape->m_shape.m_vertices.push_back(Vec2f(float(pt[0]),float(pt[1]))); |
| 1561 | f << shape->m_shape.m_vertices.back() << ","; |
| 1562 | } |
| 1563 | f << "],"; |
| 1564 | if (parent && parent->m_type==parent->Shape) |
| 1565 | parent->m_shape=shape; |
| 1566 | ascFile.addPos(pos); |
| 1567 | ascFile.addNote(f.str().c_str()); |
| 1568 | return true; |
| 1569 | } |
| 1570 | |
| 1571 | bool QuattroGraph::readTextBox(std::shared_ptr<WPSStream> stream) |
| 1572 | { |
| 1573 | RVNGInputStreamPtr input = stream->m_input; |
| 1574 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1575 | libwps::DebugStream f; |
| 1576 | long pos = input->tell(); |
| 1577 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1578 | |
| 1579 | if (type!=0x36f) |
| 1580 | { |
| 1581 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: not a text box zone\n")); |
| 1582 | return false; |
| 1583 | } |
| 1584 | auto parent=m_state->m_actualGraph; |
| 1585 | m_state->m_actualGraph.reset(); |
| 1586 | auto sz = long(libwps::readU16(input)); |
| 1587 | long endPos=pos+4+sz; |
| 1588 | auto textbox=std::make_shared<QuattroGraphInternal::Textbox>(); |
| 1589 | if (sz<57 || !readShapeHeader(*textbox, stream, endPos-3) || input->tell()+3>endPos) |
| 1590 | { |
| 1591 | if (sz) |
| 1592 | { |
| 1593 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: the size seems very bad\n")); |
| 1594 | f << *textbox << ","; |
| 1595 | f << "###"; |
| 1596 | } |
| 1597 | ascFile.addPos(pos); |
| 1598 | ascFile.addNote(f.str().c_str()); |
| 1599 | return true; |
| 1600 | } |
| 1601 | f << *textbox << ","; |
| 1602 | ascFile.addPos(pos); |
| 1603 | ascFile.addNote(f.str().c_str()); |
| 1604 | |
| 1605 | pos=input->tell(); |
| 1606 | f.str(""); |
| 1607 | f << "GrTextBox[text]:"; |
| 1608 | int val=int(libwps::readU8(input)); |
| 1609 | if (val) f << "f0=" << std::hex << val << std::dec << ","; |
| 1610 | int N=int(libwps::readU16(input)); |
| 1611 | if (pos+3+N+10>endPos) |
| 1612 | { |
| 1613 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: can not read the text zone\n")); |
| 1614 | f << "###"; |
| 1615 | ascFile.addPos(pos); |
| 1616 | ascFile.addNote(f.str().c_str()); |
| 1617 | return true; |
| 1618 | } |
| 1619 | textbox->m_entry.setBegin(pos+3); |
| 1620 | textbox->m_entry.setLength(N); |
| 1621 | std::string text; |
| 1622 | for (int i=0; i<N; ++i) text+=char(libwps::readU8(input)); |
| 1623 | f << text; |
| 1624 | ascFile.addPos(pos); |
| 1625 | ascFile.addNote(f.str().c_str()); |
| 1626 | |
| 1627 | pos=input->tell(); |
| 1628 | f.str(""); |
| 1629 | f << "GrTextBox[format]:"; |
| 1630 | if (pos+80>endPos) |
| 1631 | { |
| 1632 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: can not read the format zone\n")); |
| 1633 | f << "###"; |
| 1634 | ascFile.addPos(pos); |
| 1635 | ascFile.addNote(f.str().c_str()); |
| 1636 | return true; |
| 1637 | } |
| 1638 | auto &font = textbox->m_font;; |
| 1639 | font.m_size=double(libwps::readU16(input)); |
| 1640 | int flags=int(libwps::readU16(input)); |
| 1641 | uint32_t attributes = 0; |
| 1642 | if (flags & 1) attributes |= WPS_BOLD_BIT; |
| 1643 | if (flags & 2) attributes |= WPS_ITALICS_BIT; |
| 1644 | if (flags & 4) attributes |= WPS_UNDERLINE_BIT; |
| 1645 | if (flags & 0x20) attributes |= WPS_STRIKEOUT_BIT; |
| 1646 | font.m_attributes=attributes; |
| 1647 | flags&=0xffd8; |
| 1648 | if (flags) |
| 1649 | f << "#font[flag]=" << std::hex << flags << std::dec << ","; |
| 1650 | librevenge::RVNGString name; |
| 1651 | if (!m_mainParser.readCString(stream, name, 32)) |
| 1652 | f << "###name,"; |
| 1653 | else |
| 1654 | font.m_name=name; |
| 1655 | input->seek(pos+35, librevenge::RVNG_SEEK_SET); |
| 1656 | val=int(libwps::readU8(input)); // 0|5|8|58|ff |
| 1657 | if (val) f << "f0=" << std::hex << val << std::dec << ","; |
| 1658 | unsigned char col[4]; |
| 1659 | WPSColor colors[2]; |
| 1660 | for (auto &color : colors) |
| 1661 | { |
| 1662 | for (auto &c : col) c=libwps::readU8(input); |
| 1663 | color=WPSColor(col[0],col[1],col[2]); |
| 1664 | } |
| 1665 | int fillType=int(libwps::readU16(input)); |
| 1666 | if (fillType==0) |
| 1667 | { |
| 1668 | font.m_color=colors[0]; |
| 1669 | } |
| 1670 | else if (fillType>=1 && fillType<=6) |
| 1671 | font.m_color=WPSColor::barycenter(0.5f, colors[0], 0.5f, colors[1]); |
| 1672 | else if ((fillType&0x8060)==0x8060) |
| 1673 | { |
| 1674 | font.m_color=colors[0]; |
| 1675 | f << "#3d[effect]=" << (fillType&0x7f9f) << ","; |
| 1676 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: find unimplemented 3d color\n")); |
| 1677 | } |
| 1678 | else |
| 1679 | { |
| 1680 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: find unimplemented fillType color\n")); |
| 1681 | f << "###fill[type]=" << std::hex << fillType << std::dec << ","; |
| 1682 | } |
| 1683 | f << font; |
| 1684 | val=int(libwps::read16(input)); |
| 1685 | if (val) f << "f1=" << val << ","; |
| 1686 | val=int(libwps::read16(input)); |
| 1687 | if (val) f << "box[width]=" << val << ","; // maybe type |
| 1688 | val=int(libwps::read16(input)); |
| 1689 | switch (val) |
| 1690 | { |
| 1691 | case 0: // left |
| 1692 | break; |
| 1693 | case 1: |
| 1694 | textbox->m_paragraph.m_justify=libwps::JustificationCenter; |
| 1695 | f << "center,"; |
| 1696 | break; |
| 1697 | case 2: |
| 1698 | textbox->m_paragraph.m_justify=libwps::JustificationRight; |
| 1699 | f << "right,"; |
| 1700 | break; |
| 1701 | default: |
| 1702 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: unknown alignment\n")); |
| 1703 | f << "###align=" << val << ","; |
| 1704 | break; |
| 1705 | } |
| 1706 | for (int i=0; i<4; ++i) // f3=1, f2=small number, f3=-1,f4=-1 |
| 1707 | { |
| 1708 | val=int(libwps::read16(input)); |
| 1709 | if (!val) continue; |
| 1710 | f << "f" << i+2 << "=" << val << ","; |
| 1711 | } |
| 1712 | val=int(libwps::read16(input)); |
| 1713 | if (val!=300) f << "tab[width]=" << float(val)/10.f << ","; // unsure about the unit 300=1inch, 390=1,3125 inch |
| 1714 | val=int(libwps::read16(input)); |
| 1715 | if (val) f << "g1=" << val << ","; |
| 1716 | int sSz=int(libwps::readU16(input)); |
| 1717 | if (input->tell()+sSz+14>endPos) |
| 1718 | { |
| 1719 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: can not read the last string\n")); |
| 1720 | f << "###"; |
| 1721 | ascFile.addPos(pos); |
| 1722 | ascFile.addNote(f.str().c_str()); |
| 1723 | return true; |
| 1724 | } |
| 1725 | text=""; |
| 1726 | for (int i=0; i<sSz; ++i) text+=char(libwps::readU8(input)); |
| 1727 | if (!text.empty()) f << text << ","; |
| 1728 | for (int i=0; i<7; ++i) // h0=0|2|1d,h3=0|2, h5=0|16a, h6=0|922c |
| 1729 | { |
| 1730 | val=int(libwps::read16(input)); |
| 1731 | if (val) f << "h" << i << "=" << val << ","; |
| 1732 | } |
| 1733 | long actPos=input->tell(); |
| 1734 | if (fillType && !readFillData(textbox->m_style, fillType, stream, endPos)) |
| 1735 | input->seek(actPos, librevenge::RVNG_SEEK_SET); |
| 1736 | if (input->tell()!=endPos) |
| 1737 | { |
| 1738 | ascFile.addDelimiter(input->tell(),'|'); |
| 1739 | f << "##extra,"; |
| 1740 | WPS_DEBUG_MSG(("QuattroGraph::readTextBox: find extra data\n")); |
| 1741 | } |
| 1742 | if (parent && parent->m_type==parent->Shape) |
| 1743 | { |
| 1744 | parent->m_type=parent->Textbox; |
| 1745 | parent->m_textbox=textbox; |
| 1746 | } |
| 1747 | ascFile.addPos(pos); |
| 1748 | ascFile.addNote(f.str().c_str()); |
| 1749 | return true; |
| 1750 | } |
| 1751 | //////////////////////////////////////////////////////////// |
| 1752 | // dialog |
| 1753 | //////////////////////////////////////////////////////////// |
| 1754 | bool QuattroGraph::readHeader(QuattroGraphInternal::Dialog &header, std::shared_ptr<WPSStream> stream, long endPos) |
| 1755 | { |
| 1756 | auto input=stream->m_input; |
| 1757 | long pos = input->tell(); |
| 1758 | if (endPos-pos<22) |
| 1759 | { |
| 1760 | WPS_DEBUG_MSG(("QuattroGraph::readHeader: the zone is too short\n")); |
| 1761 | return false; |
| 1762 | } |
| 1763 | for (auto &fl : header.m_flags1) fl=int(libwps::readU16(input)); |
| 1764 | int dim[4]; |
| 1765 | for (auto &d: dim) d=libwps::readU16(input); |
| 1766 | header.m_cellBox=WPSBox2i(Vec2i(dim[0],dim[1]),Vec2i(dim[2],dim[3])); |
| 1767 | for (auto &fl : header.m_flags2) fl=int(libwps::readU8(input)); |
| 1768 | return true; |
| 1769 | } |
| 1770 | |
| 1771 | bool QuattroGraph::readDialog(std::shared_ptr<WPSStream> stream) |
| 1772 | { |
| 1773 | RVNGInputStreamPtr input = stream->m_input; |
| 1774 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1775 | libwps::DebugStream f; |
| 1776 | long pos = input->tell(); |
| 1777 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1778 | |
| 1779 | if (type != 0x35e) |
| 1780 | { |
| 1781 | WPS_DEBUG_MSG(("QuattroGraph::readDialog: unknown id\n")); |
| 1782 | return false; |
| 1783 | } |
| 1784 | auto sz = long(libwps::readU16(input)); |
| 1785 | long endPos=pos+4+sz; |
| 1786 | QuattroGraphInternal::Dialog dialog; |
| 1787 | if (sz<65 || !readHeader(dialog,stream,endPos)) |
| 1788 | { |
| 1789 | if (sz) |
| 1790 | { |
| 1791 | WPS_DEBUG_MSG(("QuattroGraph::readDialog: size seems very bad\n")); |
| 1792 | f << "###"; |
| 1793 | } |
| 1794 | ascFile.addPos(pos); |
| 1795 | ascFile.addNote(f.str().c_str()); |
| 1796 | return true; |
| 1797 | } |
| 1798 | f << dialog << ","; |
| 1799 | int val; |
| 1800 | for (int i=0; i<3; ++i) // f1=0|-256, f2=-1 |
| 1801 | { |
| 1802 | val=int(libwps::read16(input)); |
| 1803 | if (val) |
| 1804 | f << "f" << i << "=" << val <<","; |
| 1805 | } |
| 1806 | for (int i=0; i<3; ++i) // 0 |
| 1807 | { |
| 1808 | val=int(libwps::read16(input)); |
| 1809 | if (val) |
| 1810 | f << "f" << i+4 << "=" << val <<","; |
| 1811 | } |
| 1812 | val=int(libwps::readU16(input)); |
| 1813 | if (val!=0x100) |
| 1814 | f << "f7=" << std::hex << val << std::dec << ","; |
| 1815 | auto sSz=int(libwps::readU16(input)); |
| 1816 | librevenge::RVNGString text; |
| 1817 | if (input->tell()+sSz+7+15>endPos || !m_mainParser.readCString(stream,text,sSz)) |
| 1818 | { |
| 1819 | WPS_DEBUG_MSG(("QuattroGraph::readDialog: can not read string1\n")); |
| 1820 | f << "##sSz,"; |
| 1821 | ascFile.addPos(pos); |
| 1822 | ascFile.addNote(f.str().c_str()); |
| 1823 | return true; |
| 1824 | } |
| 1825 | f << text.cstr() << ","; // find Dialog1... |
| 1826 | val=int(libwps::readU8(input)); |
| 1827 | if (val!=0x1) |
| 1828 | f << "f9=" << val << ","; |
| 1829 | sSz=int(libwps::readU16(input)); |
| 1830 | if (sSz<4 || input->tell()+sSz+15>endPos || (sz>4 && !m_mainParser.readCString(stream,text,sSz-4))) |
| 1831 | { |
| 1832 | WPS_DEBUG_MSG(("QuattroGraph::readDialog: can not read string1\n")); |
| 1833 | f << "##sSz2,"; |
| 1834 | ascFile.addPos(pos); |
| 1835 | ascFile.addNote(f.str().c_str()); |
| 1836 | return true; |
| 1837 | } |
| 1838 | if (!text.empty()) // find Enter ... |
| 1839 | f << text.cstr() << ","; |
| 1840 | for (int i=0; i<2; ++i) // 0 |
| 1841 | { |
| 1842 | val=int(libwps::read16(input)); |
| 1843 | if (!val) continue; |
| 1844 | f << "g" << i << "=" << val << ","; |
| 1845 | } |
| 1846 | if (input->tell()!=endPos) // then some flags |
| 1847 | ascFile.addDelimiter(input->tell(),'|'); |
| 1848 | static bool first=true; |
| 1849 | if (first) |
| 1850 | { |
| 1851 | first=false; |
| 1852 | WPS_DEBUG_MSG(("QuattroGraph::readDialog: this file contains some dialogs, there will not be recovered\n")); |
| 1853 | } |
| 1854 | ascFile.addPos(pos); |
| 1855 | ascFile.addNote(f.str().c_str()); |
| 1856 | return true; |
| 1857 | } |
| 1858 | |
| 1859 | bool QuattroGraph::readDialogUnknown(std::shared_ptr<WPSStream> stream) |
| 1860 | { |
| 1861 | RVNGInputStreamPtr input = stream->m_input; |
| 1862 | libwps::DebugFile &ascFile=stream->m_ascii; |
| 1863 | libwps::DebugStream f; |
| 1864 | long pos = input->tell(); |
| 1865 | auto type = int(libwps::readU16(input)&0x7fff); |
| 1866 | |
| 1867 | if (type<0x330 || type>0x380) |
| 1868 | { |
| 1869 | WPS_DEBUG_MSG(("QuattroGraph::readDialogUnknown: unknown id\n")); |
| 1870 | return false; |
| 1871 | } |
| 1872 | auto sz = long(libwps::readU16(input)); |
| 1873 | long endPos=pos+4+sz; |
| 1874 | QuattroGraphInternal::Dialog dialog; |
| 1875 | if (sz<38 || !readHeader(dialog,stream,endPos)) |
| 1876 | { |
| 1877 | if (sz) |
| 1878 | { |
| 1879 | WPS_DEBUG_MSG(("QuattroGraph::readDialogUnknown: size seems very bad\n")); |
| 1880 | f << "###"; |
| 1881 | } |
| 1882 | ascFile.addPos(pos); |
| 1883 | ascFile.addNote(f.str().c_str()); |
| 1884 | return true; |
| 1885 | } |
| 1886 | if (dialog.m_flags2[8]&0x80) |
| 1887 | { |
| 1888 | f << "select,"; |
| 1889 | dialog.m_flags2[8]&=0x7f; |
| 1890 | } |
| 1891 | f << dialog << ","; |
| 1892 | auto fl=int(libwps::readU8(input)); // [0128][08ac] |
| 1893 | if (fl&1) f << "has[frame],"; |
| 1894 | fl &= 0xfe; |
| 1895 | if (fl) f << "flag=" << std::hex << fl << std::dec << ","; |
| 1896 | auto id=int(libwps::readU16(input)); |
| 1897 | f << "id=" << id << ","; |
| 1898 | unsigned char col[3]; |
| 1899 | for (auto &c : col) c=libwps::readU8(input); |
| 1900 | f << "col=" << WPSColor(col[0],col[1],col[2]) << ","; |
| 1901 | f << "fl3=["; |
| 1902 | for (int i=0; i<5; ++i) // 0 |
| 1903 | { |
| 1904 | auto val=int(libwps::readU8(input)); |
| 1905 | if (val) |
| 1906 | f << std::hex << val << std::dec << ","; |
| 1907 | else |
| 1908 | f << "_,"; |
| 1909 | } |
| 1910 | f << "],"; |
| 1911 | if (input->tell()!=endPos) // then some flags |
| 1912 | ascFile.addDelimiter(input->tell(),'|'); |
| 1913 | ascFile.addPos(pos); |
| 1914 | ascFile.addNote(f.str().c_str()); |
| 1915 | return true; |
| 1916 | } |
| 1917 | |
| 1918 | //////////////////////////////////////////////////////////// |
| 1919 | // send data |
| 1920 | //////////////////////////////////////////////////////////// |
| 1921 | bool QuattroGraph::sendGraphics(int sheetId, Vec2i const &cell) const |
| 1922 | { |
| 1923 | if (!m_listener) |
| 1924 | { |
| 1925 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphics: can not find the listener\n")); |
| 1926 | return false; |
| 1927 | } |
| 1928 | auto it=m_state->m_sheetIdToGraphMap.find(sheetId); |
| 1929 | bool find=false; |
| 1930 | while (it!=m_state->m_sheetIdToGraphMap.end() && it->first==sheetId) |
| 1931 | { |
| 1932 | auto const &graph=it++->second; |
| 1933 | if (!graph || graph->m_cellBox[0]!=cell) continue; |
| 1934 | sendGraphic(*graph); |
| 1935 | find=true; |
| 1936 | } |
| 1937 | if (!find) |
| 1938 | { |
| 1939 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphics: sorry, can not find any graph\n")); |
| 1940 | } |
| 1941 | return find; |
| 1942 | } |
| 1943 | |
| 1944 | bool QuattroGraph::sendPageGraphics(int sheetId) const |
| 1945 | { |
| 1946 | for (auto it=m_state->m_sheetIdToGraphMap.lower_bound(sheetId); it!=m_state->m_sheetIdToGraphMap.upper_bound(sheetId); ++it) |
| 1947 | { |
| 1948 | auto const &graph=it->second; |
| 1949 | if (!graph) continue; |
| 1950 | if (graph->m_type==graph->Shape) |
| 1951 | sendShape(*graph, sheetId); |
| 1952 | if (graph->m_type==graph->Textbox) |
| 1953 | sendTextbox(*graph, sheetId); |
| 1954 | } |
| 1955 | return true; |
| 1956 | } |
| 1957 | |
| 1958 | bool QuattroGraph::sendGraphic(QuattroGraphInternal::Graph const &graph) const |
| 1959 | { |
| 1960 | if (!m_listener) |
| 1961 | { |
| 1962 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphic: can not find the listener\n")); |
| 1963 | return false; |
| 1964 | } |
| 1965 | WPSPosition pos(graph.m_cellBoxDecal[0], graph.m_size, librevenge::RVNG_POINT); |
| 1966 | pos.m_anchorTo = WPSPosition::Cell; |
| 1967 | pos.m_anchorCellName = libwps::getCellName(graph.m_cellBox[1]+Vec2i(1,1)).c_str(); |
| 1968 | if (graph.m_type==graph.OLE) |
| 1969 | { |
| 1970 | if (!graph.m_linkName.empty()) |
| 1971 | { |
| 1972 | auto it=m_state->m_linkNameToObjectMap.find(graph.m_linkName); |
| 1973 | if (it==m_state->m_linkNameToObjectMap.end() || it->second.isEmpty()) |
| 1974 | { |
| 1975 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphic: can not find ole %s\n", graph.m_linkName.cstr())); |
| 1976 | } |
| 1977 | else |
| 1978 | m_listener->insertObject(pos, it->second); |
| 1979 | } |
| 1980 | else if (graph.m_ole.isEmpty()) |
| 1981 | { |
| 1982 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphic: find an empty ole\n")); |
| 1983 | } |
| 1984 | else |
| 1985 | m_listener->insertObject(pos, graph.m_ole); |
| 1986 | return true; |
| 1987 | } |
| 1988 | if (graph.m_type==graph.Button) |
| 1989 | { |
| 1990 | if (graph.m_label.empty()) |
| 1991 | { |
| 1992 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphic: find an empty label\n")); |
| 1993 | } |
| 1994 | else |
| 1995 | { |
| 1996 | WPSGraphicStyle style; |
| 1997 | style.setBackgroundColor(WPSColor(128,128,128)); |
| 1998 | auto doc=std::make_shared<QuattroGraphInternal::SubDocument>(const_cast<QuattroGraph &>(*this),graph.m_label); |
| 1999 | m_listener->insertTextBox(pos, doc, style); |
| 2000 | } |
| 2001 | return true; |
| 2002 | } |
| 2003 | static bool first=true; |
| 2004 | if (first) |
| 2005 | { |
| 2006 | first=false; |
| 2007 | WPS_DEBUG_MSG(("QuattroGraph::sendGraphic: sorry, unexpected graph type\n")); |
| 2008 | } |
| 2009 | return true; |
| 2010 | } |
| 2011 | |
| 2012 | bool QuattroGraph::sendShape(QuattroGraphInternal::Graph const &graph, int sheetId) const |
| 2013 | { |
| 2014 | if (!m_listener) |
| 2015 | { |
| 2016 | WPS_DEBUG_MSG(("QuattroGraph::sendShape: can not find the listener\n")); |
| 2017 | return false; |
| 2018 | } |
| 2019 | if (graph.m_type!=graph.Shape || !graph.m_shape) |
| 2020 | { |
| 2021 | WPS_DEBUG_MSG(("QuattroGraph::sendShape: can not find the shape\n")); |
| 2022 | return false; |
| 2023 | } |
| 2024 | auto const &shape=*graph.m_shape; |
| 2025 | WPSPosition pos(graph.m_cellBoxDecal[0]+m_mainParser.getCellPosition(sheetId, graph.m_cellBox[0]), graph.m_size, librevenge::RVNG_POINT); |
| 2026 | pos.m_anchorTo = WPSPosition::Page; |
| 2027 | auto gShape=shape.m_shape; |
| 2028 | auto bdBoxSize=gShape.getBdBox().size(); |
| 2029 | gShape.scale(Vec2f(bdBoxSize[0]>0 ? float(graph.m_size[0])/bdBoxSize[0] : 1.f, bdBoxSize[1]>0 ? float(graph.m_size[1])/bdBoxSize[1] : 1.f)); |
| 2030 | m_listener->insertPicture(pos, gShape, shape.m_style); |
| 2031 | return true; |
| 2032 | } |
| 2033 | |
| 2034 | bool QuattroGraph::sendTextbox(QuattroGraphInternal::Graph const &graph, int sheetId) const |
| 2035 | { |
| 2036 | if (!m_listener) |
| 2037 | { |
| 2038 | WPS_DEBUG_MSG(("QuattroGraph::sendTextbox: can not find the listener\n")); |
| 2039 | return false; |
| 2040 | } |
| 2041 | if (graph.m_type!=graph.Textbox || !graph.m_textbox) |
| 2042 | { |
| 2043 | WPS_DEBUG_MSG(("QuattroGraph::sendTextbox: can not find the textbox\n")); |
| 2044 | return false; |
| 2045 | } |
| 2046 | auto const &textbox=*graph.m_textbox; |
| 2047 | WPSPosition pos(graph.m_cellBoxDecal[0]+m_mainParser.getCellPosition(sheetId, graph.m_cellBox[0]), graph.m_size, librevenge::RVNG_POINT); |
| 2048 | pos.m_anchorTo = WPSPosition::Page; |
| 2049 | auto doc=std::make_shared<QuattroGraphInternal::SubDocument>(const_cast<QuattroGraph &>(*this),graph.m_textbox, graph.m_stream); |
| 2050 | m_listener->insertTextBox(pos, doc, textbox.m_style); |
| 2051 | return true; |
| 2052 | } |
| 2053 | |
| 2054 | bool QuattroGraph::send(QuattroGraphInternal::Textbox const &textbox, std::shared_ptr<WPSStream> stream) const |
| 2055 | { |
| 2056 | if (!m_listener) |
| 2057 | { |
| 2058 | WPS_DEBUG_MSG(("QuattroGraph::send: can not find the listener\n")); |
| 2059 | return false; |
| 2060 | } |
| 2061 | if (!stream || !textbox.m_entry.valid()) |
| 2062 | { |
| 2063 | WPS_DEBUG_MSG(("QuattroGraph::send: can not find the file stream\n")); |
| 2064 | return false; |
| 2065 | } |
| 2066 | m_listener->setFont(textbox.m_font); |
| 2067 | m_listener->setParagraph(textbox.m_paragraph); |
| 2068 | auto input=stream->m_input; |
| 2069 | input->seek(textbox.m_entry.begin(), librevenge::RVNG_SEEK_SET); |
| 2070 | auto fontType = m_mainParser.getDefaultFontType(); |
| 2071 | std::string text; |
| 2072 | for (long l=0; l<=textbox.m_entry.length(); ++l) |
| 2073 | { |
| 2074 | auto c=l==textbox.m_entry.length() ? '\0' : char(libwps::readU8(input)); |
| 2075 | if ((c==0 || c==0x9 || c==0xd) && !text.empty()) |
| 2076 | { |
| 2077 | m_listener->insertUnicodeString(libwps_tools_win::Font::unicodeString(text, fontType)); |
| 2078 | text.clear(); |
| 2079 | } |
| 2080 | if (l==textbox.m_entry.length()) break; |
| 2081 | if (c==0xd) |
| 2082 | m_listener->insertEOL(); |
| 2083 | else if (c==0x9) |
| 2084 | m_listener->insertTab(); |
| 2085 | else if (c) |
| 2086 | text.push_back(c); |
| 2087 | } |
| 2088 | return true; |
| 2089 | } |
| 2090 | |
| 2091 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |