Debian Codegraph @

src/lib/ClarisWksGraph.cxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #include <cmath>
35 #include <iomanip>
36 #include <iostream>
37 #include <limits>
38 #include <map>
39 #include <set>
40 #include <sstream>
41
42 #include <librevenge/librevenge.h>
43
44 #include "MWAWFont.hxx"
45 #include "MWAWGraphicEncoder.hxx"
46 #include "MWAWGraphicListener.hxx"
47 #include "MWAWGraphicShape.hxx"
48 #include "MWAWGraphicStyle.hxx"
49 #include "MWAWListener.hxx"
50 #include "MWAWParser.hxx"
51 #include "MWAWPictBitmap.hxx"
52 #include "MWAWPictMac.hxx"
53 #include "MWAWPosition.hxx"
54 #include "MWAWPresentationListener.hxx"
55 #include "MWAWSpreadsheetEncoder.hxx"
56 #include "MWAWSpreadsheetListener.hxx"
57 #include "MWAWSubDocument.hxx"
58
59 #include "ClarisWksDocument.hxx"
60 #include "ClarisWksStruct.hxx"
61 #include "ClarisWksStyleManager.hxx"
62
63 #include "ClarisWksGraph.hxx"
64
65 #include "libmwaw_internal.hxx"
66
67 /** Internal: the structures of a ClarisWksGraph */
68 namespace ClarisWksGraphInternal
69 {
70 //! Internal: the structure used to a point of a ClarisWksGraph
71 struct CurvePoint {
72 explicit CurvePoint(MWAWVec2f point=MWAWVec2f())
73 : m_pos(point)
74 , m_type(1)
75 {
76 for (auto &ctrl : m_controlPoints) ctrl = point;
77 }
78 //! operator<<
79 friend std::ostream &operator<<(std::ostream &o, CurvePoint const &pt)
80 {
81 o << pt.m_pos;
82 if (pt.m_pos != pt.m_controlPoints[0])
83 o << ":prev=" << pt.m_controlPoints[0];
84 if (pt.m_pos != pt.m_controlPoints[1])
85 o << ":next=" << pt.m_controlPoints[1];
86 switch (pt.m_type) {
87 case 0:
88 o << ":point2";
89 break;
90 case 1:
91 break;
92 case 2:
93 o << ":spline";
94 break;
95 case 3:
96 o << ":spline2";
97 break;
98 default:
99 o << ":#type=" << pt.m_type;
100 }
101 return o;
102 }
103 //! the main position
104 MWAWVec2f m_pos;
105 //! the control point: previous, next
106 MWAWVec2f m_controlPoints[2];
107 //! the point type
108 int m_type;
109 };
110
111 //! Internal: the structure used to store a style of a ClarisWksGraph
112 struct Style final : public MWAWGraphicStyle {
113 //! constructor
114 Style()
115 : MWAWGraphicStyle()
116 , m_wrapping(0)
117 , m_surfacePatternType(0)
118 {
119 }
120 Style(Style const &)=default;
121 //! destructor
122 ~Style() final;
123 //! returns the wrapping
124 MWAWPosition::Wrapping getWrapping() const
125 {
126 switch (m_wrapping&3) {
127 case 0:
128 return MWAWPosition::WBackground;
129 case 1:
130 case 2:
131 return MWAWPosition::WDynamic;
132 default:
133 break;
134 }
135 return MWAWPosition::WNone;
136 }
137 //! operator<<
138 friend std::ostream &operator<<(std::ostream &o, Style const &st)
139 {
140 o << static_cast<MWAWGraphicStyle const &>(st);
141 switch (st.m_wrapping & 3) {
142 case 0:
143 o << "wrap=none,";
144 break; // RunThrough
145 case 1:
146 o << "wrap=regular,";
147 break; // Page Wrap
148 case 2:
149 o << "wrap=irregular,";
150 break; // Optimal page Wrap
151 default:
152 o << "#wrap=3,";
153 break;
154 }
155 switch (st.m_surfacePatternType) {
156 case 0:
157 break; // pattern
158 case 1:
159 o << "wallPattern,";
160 break;
161 default:
162 o << "pattType=" << st.m_surfacePatternType << ",";
163 }
164 return o;
165 }
166 //! the wrap type
167 int m_wrapping;
168 //! the surface pattern type
169 int m_surfacePatternType;
170 };
171
172 Style::~Style()
173 {
174 }
175
176 //! Internal: the generic structure used to store a zone of a ClarisWksGraph
177 struct Zone {
178 //! the list of types
179 enum Type { T_Zone, T_Zone2, T_Shape, T_Picture, T_Chart, T_DataBox, T_Unknown,
180 /* basic subtype */
181 T_Line, T_Rect, T_RectOval, T_Oval, T_Arc, T_Poly,
182 /* picture subtype */
183 T_Pict, T_QTim, T_Movie
184 };
185 //! constructor
186 Zone()
187 : m_zoneType(0)
188 , m_page(-1)
189 , m_box()
190 , m_ordering(-1)
191 , m_style() {}
192 Zone(Zone const &)=default;
193 //! destructor
194 virtual ~Zone();
195 //! operator<<
196 friend std::ostream &operator<<(std::ostream &o, Zone const &zone)
197 {
198 if (zone.m_page >= 0) o << "pg=" << zone.m_page << ",";
199 o << "box=" << zone.m_box << ",";
200 if (zone.m_ordering>0) o << "ordering=" << zone.m_ordering << ",";
201 switch (zone.m_zoneType&0xF) {
202 case 0:
203 break;
204 case 4:
205 o << "header/footer,";
206 break;
207 case 0xa:
208 o << "master,";
209 break;
210 default:
211 o << "zoneType=" << (zone.m_zoneType&0xF) << ",";
212 break;
213 }
214 if (zone.m_zoneType&0x20)
215 o << "zoneType[0x20],";
216 zone.print(o);
217 o << "style=[" << zone.m_style << "],";
218 return o;
219 }
220 //! return the zone bdbox
221 MWAWBox2f getBdBox() const
222 {
223 MWAWVec2f minPt(m_box[0][0], m_box[0][1]);
224 MWAWVec2f maxPt(m_box[1][0], m_box[1][1]);
225 for (int c=0; c<2; ++c) {
226 if (m_box.size()[c]>=0) continue;
227 minPt[c]=m_box[1][c];
228 maxPt[c]=m_box[0][c];
229 }
230 return MWAWBox2f(minPt,maxPt);
231 }
232 //! return the main type
233 virtual Type getType() const
234 {
235 return T_Unknown;
236 }
237 //! return the subtype
238 virtual Type getSubType() const
239 {
240 return T_Unknown;
241 }
242 //! return the number of data to define this zone in the file
243 virtual int getNumData(int /*version*/) const
244 {
245 return 0;
246 }
247 //! print the data contains
248 virtual void print(std::ostream &) const { }
249 //! return a child corresponding to this zone
250 virtual ClarisWksStruct::DSET::Child getChild() const
251 {
252 ClarisWksStruct::DSET::Child child;
253 child.m_box = m_box;
254 return child;
255 }
256 //! returns the id of the reference zone
257 virtual int getZoneId() const
258 {
259 return 0;
260 }
261 //! returns true if the zone can be send using a graphic listener (partial check)
262 virtual bool canBeSendAsGraphic() const
263 {
264 ClarisWksGraphInternal::Zone::Type type=getType();
265 return type==ClarisWksGraphInternal::Zone::T_Zone || type==ClarisWksGraphInternal::Zone::T_Shape ||
266 type==ClarisWksGraphInternal::Zone::T_DataBox || type==ClarisWksGraphInternal::Zone::T_Chart ||
267 type==ClarisWksGraphInternal::Zone::T_Unknown;
268 }
269 //! the zone type
270 int m_zoneType;
271 //! the page (checkme: or frame linked )
272 int m_page;
273 //! the bdbox
274 MWAWBox2f m_box;
275 //! the ordering
276 int m_ordering;
277 //! the style
278 Style m_style;
279 };
280
281 Zone::~Zone()
282 {
283 }
284 //! Internal: small class to store a basic graphic zone of a ClarisWksGraph
285 struct ZoneShape final : public Zone {
286 //! constructor
287 ZoneShape(Zone const &z, Type type)
288 : Zone(z)
289 , m_type(type)
290 , m_shape()
291 , m_rotate(0)
292 {
293 }
294 //! destructor
295 ~ZoneShape() final;
296 //! print the data
297 void print(std::ostream &o) const final
298 {
299 o << m_shape;
300 if (m_rotate) o << "rot=" << m_rotate << ",";
301 }
302 //! return the main type
303 Type getType() const final
304 {
305 return T_Shape;
306 }
307 //! return the sub type
308 Type getSubType() const final
309 {
310 return m_type;
311 }
312 //! return the number of data
313 int getNumData(int /*version*/) const final
314 {
315 if (m_shape.m_type == MWAWGraphicShape::Polygon) return 1;
316 return 0;
317 }
318 //! return a child corresponding to this zone
319 ClarisWksStruct::DSET::Child getChild() const final
320 {
321 ClarisWksStruct::DSET::Child child;
322 child.m_box = m_box;
323 child.m_type = ClarisWksStruct::DSET::C_Graphic;
324 return child;
325 }
326
327 //! the sub type
328 Type m_type;
329 //! the shape
330 MWAWGraphicShape m_shape;
331 //! the rotation
332 int m_rotate;
333 };
334
335 ZoneShape::~ZoneShape()
336 {
337 }
338
339 //! Internal: the structure used to store a PICT or a MOVIE
340 struct ZonePict final : public Zone {
341 //! constructor
342 ZonePict(Zone const &z, Type type)
343 : Zone(z)
344 , m_type(type)
345 {
346 }
347 //! destructor
348 ~ZonePict() final;
349 //! print the data
350 void print(std::ostream &o) const final
351 {
352 switch (m_type) {
353 case T_Pict:
354 o << "PICTURE,";
355 break;
356 case T_QTim:
357 o << "QTIME,";
358 break;
359 case T_Movie:
360 o << "MOVIE,";
361 break;
362 case T_Zone:
363 case T_Zone2:
364 case T_Shape:
365 case T_Picture:
366 case T_Chart:
367 case T_DataBox:
368 case T_Line:
369 case T_Rect:
370 case T_RectOval:
371 case T_Oval:
372 case T_Arc:
373 case T_Poly:
374 case T_Unknown:
375 #if !defined(__clang__)
376 default:
377 #endif
378 o << "##type=" << m_type << ",";
379 break;
380 }
381 }
382 //! return the main type T_Picture
383 Type getType() const final
384 {
385 return T_Picture;
386 }
387 //! return the sub type
388 Type getSubType() const final
389 {
390 return m_type;
391 }
392 //! return the number of data in a file
393 int getNumData(int /*version*/) const final
394 {
395 return 2;
396 }
397 //! return a child corresponding to this zone
398 ClarisWksStruct::DSET::Child getChild() const final
399 {
400 ClarisWksStruct::DSET::Child child;
401 child.m_box = m_box;
402 child.m_type = ClarisWksStruct::DSET::C_Graphic;
403 return child;
404 }
405
406 //! the sub type
407 Type m_type;
408 //! the picture entry followed by a ps entry or ole entry ( if defined)
409 MWAWEntry m_entries[2];
410 };
411
412 ZonePict::~ZonePict()
413 {
414 }
415
416 //! Internal: structure to store a bitmap of a ClarisWksGraph
417 struct Bitmap final : public ClarisWksStruct::DSET {
418 //! constructor
419 explicit Bitmap(ClarisWksStruct::DSET const &dset = ClarisWksStruct::DSET()) :
420 DSET(dset), m_numBytesPerPixel(0), m_bitmapSize(0,0), m_bitmapRowSize(0), m_entry(), m_colorMap()
421 {
422 }
423 //! destructor
424 ~Bitmap() final;
425 //! operator<<
426 friend std::ostream &operator<<(std::ostream &o, Bitmap const &bt)
427 {
428 o << static_cast<ClarisWksStruct::DSET const &>(bt);
429 if (bt.m_numBytesPerPixel > 0) o << "type=" << bt.m_numBytesPerPixel << ",";
430 else if (bt.m_numBytesPerPixel < 0) o << "type=1/" << (-bt.m_numBytesPerPixel) << ",";
431 return o;
432 }
433
434 //! the number of bite by pixel
435 int m_numBytesPerPixel;
436 //! the bitmap size
437 MWAWVec2i m_bitmapSize;
438 //! the bitmap row size in the file ( with potential alignment)
439 int m_bitmapRowSize;
440 //! the bitmap entry
441 MWAWEntry m_entry;
442 //! the color map
443 std::vector<MWAWColor> m_colorMap;
444 };
445
446 Bitmap::~Bitmap()
447 {
448 }
449
450 //! Internal: structure to store a link to a zone of a ClarisWksGraph
451 struct ZoneZone final : public Zone {
452 //! constructor
453 ZoneZone(Zone const &z, Type fileType)
454 : Zone(z)
455 , m_subType(fileType)
456 , m_id(-1)
457 , m_subId(-1)
458 , m_frameId(-1)
459 , m_frameSubId(-1)
460 , m_frameLast(true)
461 , m_styleId(-1)
462 , m_wrappingSep(5)
463 {
464 for (auto &fl : m_flags) fl = 0;
465 }
466 //! destructor
467 ~ZoneZone() final;
468 //! print the zone
469 void print(std::ostream &o) const final
470 {
471 if (m_subType==T_Zone2) {
472 o << "ZONE2" << ",";
473 return;
474 }
475 o << "ZONE, id=" << m_id << ",";
476 if (m_subId > 0) o << "subId=" << m_subId << ",";
477 if (m_styleId >= 0) o << "styleId=" << m_styleId << ",";
478 if (m_wrappingSep != 5) o << "wrappingSep=" << m_wrappingSep << ",";
479 for (int i = 0; i < 9; i++) {
480 if (m_flags[i]) o << "fl" << i << "=" << m_flags[i] << ",";
481 }
482 }
483 //! return the main type Zone
484 Type getType() const final
485 {
486 return T_Zone;
487 }
488 //! return the sub type Zone
489 Type getSubType() const final
490 {
491 return m_subType;
492 }
493 //! return the number of data to define this zone in the file
494 int getNumData(int /*version*/) const final
495 {
496 return m_subType==T_Zone ? 0 : 1;
497 }
498 //! returns true if the zone can be send using a graphic listener (partial check)
499 bool canBeSendAsGraphic() const final
500 {
501 return !isLinked();
502 }
503 //! returns the id of the reference zone
504 int getZoneId() const final
505 {
506 return m_id;
507 }
508 /** check if we need to send the frame is linked to another frame */
509 bool isLinked() const
510 {
511 return m_frameId>=0 && m_frameSubId>=0;
512 }
513 /** add the frame name if needed */
514 bool addFrameName(MWAWGraphicStyle &style) const
515 {
516 if (!isLinked()) return false;
517 if (m_frameSubId>0) {
518 librevenge::RVNGString fName;
519 fName.sprintf("Frame%d-%d", m_frameId, m_frameSubId);
520 style.m_frameName=fName.cstr();
521 }
522 if (!m_frameLast) {
523 librevenge::RVNGString fName;
524 fName.sprintf("Frame%d-%d", m_frameId, m_frameSubId+1);
525 style.m_frameNextName=fName.cstr();
526 }
527 return true;
528 }
529
530 //! return a child corresponding to this zone
531 ClarisWksStruct::DSET::Child getChild() const final
532 {
533 ClarisWksStruct::DSET::Child child;
534 child.m_box = m_box;
535 child.m_id = m_id;
536 child.m_type = ClarisWksStruct::DSET::C_Zone;
537 return child;
538 }
539
540 //! the file type ( zone or zone2 )
541 Type m_subType;
542 //! the zoneId
543 int m_id;
544 //! the zoneSubId: can be page/column/frame linked number
545 int m_subId;
546 //! the frame id (for a linked frame)
547 int m_frameId;
548 //! the frame sub id (for a linked frame)
549 int m_frameSubId;
550 //! true if this is the last frame of a frame zone
551 bool m_frameLast;
552 //! the style id
553 int m_styleId;
554 //! the wrapping separator
555 int m_wrappingSep;
556 //! flag
557 int m_flags[9];
558 };
559
560 ZoneZone::~ZoneZone()
561 {
562 }
563
564 //! Internal: structure used to store a chart zone of a ClarisWksGraph
565 struct Chart final : public Zone {
566 //! construtor
567 explicit Chart(Zone const &z) : Zone(z)
568 {
569 }
570 //! destructor
571 ~Chart() final;
572 //! print the zone
573 void print(std::ostream &o) const final
574 {
575 o << "CHART,";
576 }
577 //! return the main type
578 Type getType() const final
579 {
580 return T_Chart;
581 }
582 //! return the sub type
583 Type getSubType() const final
584 {
585 return T_Chart;
586 }
587 //! return the number of data
588 int getNumData(int version) const final
589 {
590 return version==1 ? 1 : 2;
591 }
592 //! return a child corresponding to this zone
593 ClarisWksStruct::DSET::Child getChild() const final
594 {
595 ClarisWksStruct::DSET::Child child;
596 child.m_box = m_box;
597 child.m_type = ClarisWksStruct::DSET::C_Graphic;
598 return child;
599 }
600 };
601
602 Chart::~Chart()
603 {
604 }
605
606 //! Internal: structure used to store an unknown zone of a ClarisWksGraph
607 struct ZoneUnknown final : public Zone {
608 //! construtor
609 explicit ZoneUnknown(Zone const &z)
610 : Zone(z)
611 , m_type(T_Unknown)
612 , m_typeId(-1)
613 {
614 }
615 //! destructor
616 ~ZoneUnknown() final;
617 //! print the zone
618 void print(std::ostream &o) const final
619 {
620 switch (m_type) {
621 case T_DataBox:
622 o << "BOX(database),";
623 break;
624 case T_Chart:
625 case T_Zone:
626 case T_Zone2:
627 case T_Shape:
628 case T_Picture:
629 case T_Line:
630 case T_Rect:
631 case T_RectOval:
632 case T_Oval:
633 case T_Arc:
634 case T_Poly:
635 case T_Unknown:
636 case T_Pict:
637 case T_QTim:
638 case T_Movie:
639 #if !defined(__clang__)
640 default:
641 #endif
642 o << "##type=" << m_typeId << ",";
643 break;
644 }
645 }
646 //! return the main type
647 Type getType() const final
648 {
649 return m_type;
650 }
651 //! return the sub type
652 Type getSubType() const final
653 {
654 return m_type;
655 }
656 //! return the number of data
657 int getNumData(int /*version*/) const final
658 {
659 return 0;
660 }
661 //! return a child corresponding to this zone
662 ClarisWksStruct::DSET::Child getChild() const final
663 {
664 ClarisWksStruct::DSET::Child child;
665 child.m_box = m_box;
666 child.m_type = ClarisWksStruct::DSET::C_Graphic;
667 return child;
668 }
669
670 //! the sub type
671 Type m_type;
672 //! type number
673 int m_typeId;
674 };
675
676 ZoneUnknown::~ZoneUnknown()
677 {
678 }
679 ////////////////////////////////////////
680 //! Internal: class which stores a group of graphics, ...
681 struct Group final : public ClarisWksStruct::DSET {
682 //! constructor
683 explicit Group(ClarisWksStruct::DSET const &dset = ClarisWksStruct::DSET())
684 : ClarisWksStruct::DSET(dset)
685 , m_zones()
686 , m_hasMainZone(false)
687 , m_zonesToSend()
688 {
689 m_page=0;
690 }
691 //! destructor
692 ~Group() final;
693 //! operator<<
694 friend std::ostream &operator<<(std::ostream &o, Group const &doc)
695 {
696 o << static_cast<ClarisWksStruct::DSET const &>(doc);
697 return o;
698 }
699 /** remove a child from a list.
700
701 Normally, this function is not called, so optimizing it is not usefull
702 */
703 void removeChild(int cId, bool normalChild) final
704 {
705 DSET::removeChild(cId, normalChild);
706 for (auto it=m_zones.begin(); it!=m_zones.end(); ++it) {
707 auto child = *it;
708 if (!child || child->getType() != ClarisWksGraphInternal::Zone::T_Zone)
709 continue;
710 auto &childZone = static_cast<ClarisWksGraphInternal::ZoneZone &>(*child);
711 if (childZone.m_id != cId) continue;
712 m_zones.erase(it);
713 return;
714 }
715 MWAW_DEBUG_MSG(("ClarisWksGraphInternal::Group can not detach %d\n", cId));
716 }
717
718 /** the list of child zones */
719 std::vector<std::shared_ptr<Zone> > m_zones;
720
721 //! a flag to know if this zone contains or no the call to zone 1
722 bool m_hasMainZone;
723 //! the list of block to send
724 std::vector<std::shared_ptr<Zone> > m_zonesToSend;
725 };
726
727 Group::~Group()
728 {
729 }
730
731 ////////////////////////////////////////
732 //! Internal: the state of a ClarisWksGraph
733 struct State {
734 //! constructor
735 State()
736 : m_numPages(0)
737 , m_pageDimensions(0,0)
738 , m_masterId(-1)
739 , m_groupMap()
740 , m_bitmapMap()
741 , m_databaseMap()
742 , m_frameId(0)
743 , m_positionsComputed(false)
744 , m_ordering(0) { }
745 /** returns a new ordering.
746
747 \note: the shapes seem to appear in increasing ordering, so we can use this function.
748 */
749 int getOrdering() const
750 {
751 return ++m_ordering;
752 }
753 //! the number of pages
754 int m_numPages;
755 //! the page dimension if known (in point)
756 MWAWVec2f m_pageDimensions;
757 //! the master group id ( in a draw file )
758 int m_masterId;
759 //! a map zoneId -> group
760 std::map<int, std::shared_ptr<Group> > m_groupMap;
761 //! a map zoneId -> group
762 std::map<int, std::shared_ptr<Bitmap> > m_bitmapMap;
763 //! a map zoneId -> zone
764 std::map<int, std::shared_ptr<ZonePict> > m_databaseMap;
765 //! a int used to defined linked frame
766 int m_frameId;
767 //! true if the ClarisWksGraph::computePositions was called
768 bool m_positionsComputed;
769 //! the last ordering used
770 mutable int m_ordering;
771 };
772
773 ////////////////////////////////////////
774 //! Internal: the subdocument of a ClarisWksGraph
775 class SubDocument final : public MWAWSubDocument
776 {
777 public:
778 SubDocument(ClarisWksGraph &pars, MWAWInputStreamPtr const &input, int zoneId, MWAWPosition const &pos=MWAWPosition())
779 : MWAWSubDocument(pars.m_mainParser, input, MWAWEntry())
780 , m_graphParser(&pars)
781 , m_id(zoneId)
782 , m_position(pos) {}
783
784 //! destructor
785 ~SubDocument() final {}
786
787 //! operator!=
788 bool operator!=(MWAWSubDocument const &doc) const final
789 {
790 if (MWAWSubDocument::operator!=(doc)) return true;
791 auto const *sDoc = dynamic_cast<SubDocument const *>(&doc);
792 if (!sDoc) return true;
793 if (m_graphParser != sDoc->m_graphParser) return true;
794 if (m_id != sDoc->m_id) return true;
795 return false;
796 }
797
798 //! the parser function
799 void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
800 /** the graph parser */
801 ClarisWksGraph *m_graphParser;
802
803 protected:
804 //! the subdocument id
805 int m_id;
806 //! the position if known
807 MWAWPosition m_position;
808 private:
809 SubDocument(SubDocument const &orig) = default;
810 SubDocument &operator=(SubDocument const &orig) = default;
811 };
812
813 void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type)
814 {
815 if (!listener || (type==libmwaw::DOC_TEXT_BOX && !listener->canWriteText())) {
816 MWAW_DEBUG_MSG(("ClarisWksGraphInternal::SubDocument::parse: no listener\n"));
817 return;
818 }
819 if (!m_graphParser) {
820 MWAW_DEBUG_MSG(("ClarisWksGraphInternal::SubDocument::parse: no graph parser\n"));
821 return;
822 }
823 long pos = m_input->tell();
824 m_graphParser->askToSend(m_id,listener,m_position);
825 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
826 }
827
828 }
829
830 ////////////////////////////////////////////////////////////
831 // constructor/destructor, ...
832 ////////////////////////////////////////////////////////////
833 ClarisWksGraph::ClarisWksGraph(ClarisWksDocument &document)
834 : m_document(document)
835 , m_parserState(document.m_parserState)
836 , m_state(new ClarisWksGraphInternal::State)
837 , m_mainParser(&document.getMainParser())
838 {
839 }
840
841 ClarisWksGraph::~ClarisWksGraph()
842 { }
843
844 int ClarisWksGraph::version() const
845 {
846 return m_parserState->m_version;
847 }
848
849 void ClarisWksGraph::computePositions() const
850 {
851 if (m_state->m_positionsComputed) return;
852 m_state->m_positionsComputed=true;
853 for (auto const &iter : m_state->m_groupMap) {
854 auto group = iter.second;
855 if (!group) continue;
856 updateGroup(*group);
857 }
858 }
859
860 int ClarisWksGraph::numPages() const
861 {
862 if (m_state->m_numPages>0) return m_state->m_numPages;
863 computePositions();
864
865 int nPages = 1;
866 for (auto const &iter : m_state->m_groupMap) {
867 auto group = iter.second;
868 if (!group) continue;
869 int lastPage=group->getMaximumPage();
870 if (lastPage>nPages) nPages=lastPage;
871 }
872 m_state->m_numPages=nPages;
873 return nPages;
874 }
875
876 bool ClarisWksGraph::getPageDimension(MWAWVec2f &dim) const
877 {
878 dim=m_state->m_pageDimensions;
879 return dim[0]>0 && dim[1]>0;
880 }
881
882 void ClarisWksGraph::askToSend(int number, MWAWListenerPtr listener, MWAWPosition const &pos)
883 {
884 m_document.sendZone(number, listener, pos);
885 }
886
887 ////////////////////////////////////////////////////////////
888 // Intermediate level
889 ////////////////////////////////////////////////////////////
890 bool ClarisWksGraph::getSurfaceColor(ClarisWksGraphInternal::Style const &style, MWAWColor &col) const
891 {
892 if (!style.hasSurfaceColor())
893 return false;
894 col = style.m_surfaceColor;
895 return true;
896 }
897
898 ////////////////////////////////////////////////////////////
899 // a group of data mainly graphic
900 ////////////////////////////////////////////////////////////
901 std::shared_ptr<ClarisWksStruct::DSET> ClarisWksGraph::readGroupZone
902 (ClarisWksStruct::DSET const &zone, MWAWEntry const &entry, bool &complete)
903 {
904 complete = false;
905 if (!entry.valid() || zone.m_fileType != 0)
906 return std::shared_ptr<ClarisWksStruct::DSET>();
907 long pos = entry.begin();
908 MWAWInputStreamPtr &input= m_parserState->m_input;
909 input->seek(pos+8+16, librevenge::RVNG_SEEK_SET); // avoid header+8 generic number
910 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
911 libmwaw::DebugStream f;
912 std::shared_ptr<ClarisWksGraphInternal::Group> group(new ClarisWksGraphInternal::Group(zone));
913
914 f << "Entries(GroupDef):" << *group << ",";
915 auto val = static_cast<int>(input->readLong(2)); // a small int between 0 and 3
916 switch (val) {
917 case 0:
918 break; // normal
919 case 3:
920 f << "database/spreadsheet,";
921 break;
922 default:
923 f << "#type?=" << val << ",";
924 break;
925 }
926 val = static_cast<int>(input->readLong(2)); // a small number between 0 and 1e8
927 if (val) f << "f1=" << val << ",";
928
929 ascFile.addDelimiter(input->tell(), '|');
930 ascFile.addPos(pos);
931 ascFile.addNote(f.str().c_str());
932
933 // read the last part
934 long data0Length = zone.m_dataSz;
935 long N = zone.m_numData;
936 if (entry.length() -8-12 != data0Length*N + zone.m_headerSz) {
937 if (data0Length == 0 && N) {
938 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupZone: can not find definition size\n"));
939 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
940 return std::shared_ptr<ClarisWksStruct::DSET>();
941 }
942
943 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupZone: unexpected size for zone definition, try to continue\n"));
944 }
945
946 long beginDefGroup = entry.end()-N*data0Length;
947 if (long(input->tell())+42 <= beginDefGroup) {
948 input->seek(beginDefGroup-42, librevenge::RVNG_SEEK_SET);
949 pos = input->tell();
950 if (!readGroupUnknown(*group, 42, -1)) {
951 ascFile.addPos(pos);
952 ascFile.addNote("GroupDef(Head-###)");
953 }
954 }
955
956 input->seek(beginDefGroup, librevenge::RVNG_SEEK_SET);
957
958 for (long i = 0; i < N; i++) {
959 pos = input->tell();
960 MWAWEntry gEntry;
961 gEntry.setBegin(pos);
962 gEntry.setLength(data0Length);
963 auto def = readGroupDef(gEntry);
964 group->m_zones.push_back(def);
965
966 if (!def) {
967 f.str("");
968 f << "GroupDef#";
969 ascFile.addPos(pos);
970 ascFile.addNote(f.str().c_str());
971 }
972 input->seek(gEntry.end(), librevenge::RVNG_SEEK_SET);
973 }
974
975 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
976
977 if (readGroupData(*group, entry.begin())) {
978 // fixme: do something here
979 }
980
981 group->m_childs.resize(group->m_zones.size());
982 for (size_t i = 0; i < group->m_zones.size(); ++i) {
983 if (!group->m_zones[i]) continue;
984 group->m_childs[size_t(i)] = group->m_zones[i]->getChild();
985 }
986
987 if (m_state->m_groupMap.find(group->m_id) != m_state->m_groupMap.end()) {
988 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupZone: zone %d already exists!!!\n", group->m_id));
989 }
990 else
991 m_state->m_groupMap[group->m_id] = group;
992
993 return group;
994 }
995
996 ////////////////////////////////////////////////////////////
997 // read a bitmap zone
998 ////////////////////////////////////////////////////////////
999 std::shared_ptr<ClarisWksStruct::DSET> ClarisWksGraph::readBitmapZone
1000 (ClarisWksStruct::DSET const &zone, MWAWEntry const &entry, bool &complete)
1001 {
1002 complete = false;
1003 if (!entry.valid() || zone.m_fileType != 4)
1004 return std::shared_ptr<ClarisWksStruct::DSET>();
1005 long pos = entry.begin();
1006 MWAWInputStreamPtr &input= m_parserState->m_input;
1007 input->seek(pos+8+16, librevenge::RVNG_SEEK_SET); // avoid header+8 generic number
1008 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1009 libmwaw::DebugStream f;
1010 std::shared_ptr<ClarisWksGraphInternal::Bitmap> bitmap(new ClarisWksGraphInternal::Bitmap(zone));
1011
1012 f << "Entries(BitmapDef):" << *bitmap << ",";
1013
1014 ascFile.addDelimiter(input->tell(), '|');
1015
1016 // read the last part
1017 long data0Length = zone.m_dataSz;
1018 long N = zone.m_numData;
1019 if (entry.length() -8-12 != data0Length*N + zone.m_headerSz) {
1020 if (data0Length == 0 && N) {
1021 ascFile.addPos(pos);
1022 ascFile.addNote(f.str().c_str());
1023
1024 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapZone: can not find definition size\n"));
1025 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
1026 return std::shared_ptr<ClarisWksStruct::DSET>();
1027 }
1028
1029 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapZone: unexpected size for zone definition, try to continue\n"));
1030 }
1031
1032 bool sizeSet=false;
1033 int sizePos = (version() == 1) ? 0: 88;
1034 if (sizePos && pos+sizePos+4+N*data0Length < entry.end()) {
1035 input->seek(pos+sizePos, librevenge::RVNG_SEEK_SET);
1036 ascFile.addDelimiter(pos+sizePos,'[');
1037 int dim[2]; // ( we must add 2 to add the border )
1038 for (auto &d : dim) d = static_cast<int>(input->readLong(2));
1039 f << "sz=" << dim[1] << "x" << dim[0] << ",";
1040 if (dim[0] > 0 && dim[1] > 0) {
1041 bitmap->m_bitmapSize = MWAWVec2i(dim[1]+2, dim[0]+2);
1042 sizeSet = true;
1043 }
1044 ascFile.addDelimiter(input->tell(),']');
1045 }
1046 ascFile.addPos(pos);
1047 ascFile.addNote(f.str().c_str());
1048
1049 /** the end of this block is very simillar to a bitmapdef, excepted
1050 maybe the first integer .... */
1051 if (long(input->tell())+(N+1)*data0Length <= entry.end())
1052 N++;
1053
1054 input->seek(entry.end()-N*data0Length, librevenge::RVNG_SEEK_SET);
1055
1056 for (long i = 0; i < N; i++) {
1057 pos = input->tell();
1058 MWAWEntry gEntry;
1059 gEntry.setBegin(pos);
1060 gEntry.setLength(data0Length);
1061 f.str("");
1062 f << "BitmapDef-" << i << ":";
1063 auto val = long(input->readULong(4));
1064 if (val) {
1065 if (i == 0)
1066 f << "unkn=" << val << ",";
1067 else
1068 f << "ptr=" << std::hex << val << std::dec << ",";
1069 }
1070 // f0 : 0 true color, if not number of bytes
1071 for (int j = 0; j < 3; j++) {
1072 val = static_cast<int>(input->readLong(2));
1073 if (val) f << "f" << j << "=" << val << ",";
1074 }
1075 int dim[2]; // ( we must add 2 to add the border )
1076 for (int &d : dim) d = static_cast<int>(input->readLong(2));
1077 if (i == N-1 && !sizeSet)
1078 bitmap->m_bitmapSize = MWAWVec2i(dim[0]+2, dim[1]+2);
1079
1080 f << "dim?=" << dim[0] << "x" << dim[1] << ",";
1081 for (int j = 3; j < 6; j++) {
1082 val = static_cast<int>(input->readLong(2));
1083 if ((j != 5 && val!=1) || (j==5 && val)) // always 1, 1, 0
1084 f << "f" << j << "=" << val << ",";
1085 }
1086 if (long(input->tell()) != gEntry.end())
1087 ascFile.addDelimiter(input->tell(), '|');
1088 ascFile.addPos(pos);
1089 ascFile.addNote(f.str().c_str());
1090 input->seek(gEntry.end(), librevenge::RVNG_SEEK_SET);
1091 }
1092
1093 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
1094 pos = entry.end();
1095 bool ok = readBitmapColorMap(bitmap->m_colorMap);
1096 if (ok) {
1097 pos = input->tell();
1098 ok = readBitmapData(*bitmap);
1099 }
1100 if (!ok)
1101 input->seek(pos, librevenge::RVNG_SEEK_SET);
1102
1103 // fixme: in general followed by another zone
1104 bitmap->m_otherChilds.push_back(bitmap->m_id+1);
1105
1106 if (m_state->m_bitmapMap.find(bitmap->m_id) != m_state->m_bitmapMap.end()) {
1107 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupZone: zone %d already exists!!!\n", bitmap->m_id));
1108 }
1109 else
1110 m_state->m_bitmapMap[bitmap->m_id] = bitmap;
1111
1112 return bitmap;
1113 }
1114
1115 bool ClarisWksGraph::readDatabasePictZone()
1116 {
1117 if (!m_parserState) {
1118 MWAW_DEBUG_MSG(("ClarisWksGraph::readDatabasePictZone: can not find the parser state\n"));
1119 return false;
1120 }
1121 MWAWInputStreamPtr input = m_parserState->m_input;
1122 long pos = input->tell();
1123 auto endPos = long(input->readULong(4));
1124 if (endPos<pos || !input->checkPosition(endPos)) {
1125 input->seek(pos, librevenge::RVNG_SEEK_SET);
1126 MWAW_DEBUG_MSG(("ClarisWksGraph::readDatabasePictZone: unexpected size\n"));
1127 return false;
1128 }
1129 libmwaw::DebugFile &ascFile=m_parserState->m_asciiFile;
1130 libmwaw::DebugStream f;
1131
1132 if (pos+4 == endPos) {
1133 ascFile.addPos(pos);
1134 ascFile.addNote("Nop");
1135 return true;
1136 }
1137
1138 ascFile.addPos(pos);
1139 ascFile.addNote(f.str().c_str());
1140
1141 input->pushLimit(endPos);
1142
1143 pos=input->tell();
1144 long firstPos=pos+0x200-(pos%0x200);
1145 if (firstPos!=pos) {
1146 ascFile.skipZone(pos, firstPos-1);
1147 input->seek(firstPos, librevenge::RVNG_SEEK_SET);
1148 }
1149
1150 bool ok=true;
1151 for (int i=0; i<2 && ok; ++i) {
1152 pos=input->tell();
1153 // unsure, find 0000000c0000ffff000000080000|0001, so maybe simply two zones of size 16
1154 ok=ClarisWksStruct::readStructZone(*m_parserState, "DataPict", false);
1155 if (!ok)
1156 input->seek(pos, librevenge::RVNG_SEEK_SET);
1157 }
1158 struct PictEntry {
1159 PictEntry()
1160 {
1161 for (auto &v : m_pos) v=-1;
1162 }
1163 long m_pos[3];
1164 };
1165 std::vector<PictEntry> pictEntryList;
1166 if (ok) {
1167 f.str("");
1168 f << "DataPict(I):";
1169 pos = input->tell();
1170 auto sz = long(input->readULong(4));
1171 f << "sz?=" << sz << ",";
1172 auto N=int(input->readULong(2));
1173 f << "N=" << N << ",";
1174 if (pos+16+28*N+4>endPos) {
1175 MWAW_DEBUG_MSG(("ClarisWksGraph::readDatabasePictZone: the number of zones seems bad\n"));
1176 f << "###N,";
1177 N=0;
1178 ok=false;
1179 }
1180 for (int i=0; i<5; ++i) {
1181 auto val=int(input->readLong(2));
1182 int const expected[] = {-1,0,8,0,2};
1183 if (val!=expected[i])
1184 f << "f" << i << "=" << val << ",";
1185 }
1186 ascFile.addPos(pos);
1187 ascFile.addNote(f.str().c_str());
1188 for (int i=0; i<N; ++i) {
1189 pos = input->tell();
1190 f.str("");
1191 f << "DataPict(I" << i << "):";
1192 PictEntry data;
1193 data.m_pos[0]=long(input->readULong(4));
1194 f << "dSz=" << data.m_pos[0] << ",";
1195 for (int j=0; j<8; ++j) {
1196 auto val=int(input->readLong(2));
1197 int const expected[] = {0,0x14,1,-1,0,8,0,1}; // some struct?
1198 if (val!=expected[j])
1199 f << "f" << i << "=" << val << ",";
1200 }
1201 for (int j=0; j<2; ++j) data.m_pos[j+1]=long(input->readULong(4));
1202 f << "zone=" << data.m_pos[1] << "x" << data.m_pos[2] << ",";
1203 if (data.m_pos[1]<1 || data.m_pos[2]<data.m_pos[1] || (endPos-firstPos)/0x200 < data.m_pos[2]+1
1204 || data.m_pos[0]>0x200*(data.m_pos[2]+1-data.m_pos[1])) {
1205 MWAW_DEBUG_MSG(("ClarisWksGraph::readDatabasePictZone: the %d zone seems bad\n", i));
1206 f << "###";
1207 pictEntryList.push_back(PictEntry());
1208 }
1209 else
1210 pictEntryList.push_back(data);
1211 input->seek(pos+28, librevenge::RVNG_SEEK_SET);
1212 ascFile.addPos(pos);
1213 ascFile.addNote(f.str().c_str());
1214 }
1215 if (ok) {
1216 pos = input->tell();
1217 f.str("");
1218 f << "DataPict(I_):";
1219 auto val=int(input->readLong(4));
1220 if (val!=0x200)
1221 f << "f0=" << val << ",";
1222 ascFile.addPos(pos);
1223 ascFile.addNote(f.str().c_str());
1224 pos=input->tell();
1225 long newPos=pos+0x200-(pos%0x200);
1226 if (newPos!=pos) {
1227 ascFile.skipZone(pos, newPos-1);
1228 input->seek(newPos, librevenge::RVNG_SEEK_SET);
1229 }
1230 }
1231 }
1232 for (size_t i=0; i<pictEntryList.size(); ++i) {
1233 auto const &entry = pictEntryList[i];
1234 if (entry.m_pos[0]<=0) continue;
1235 long begDataPos=firstPos+entry.m_pos[1]*0x200;
1236 input->seek(begDataPos, librevenge::RVNG_SEEK_SET);
1237 long endDataPos=begDataPos+entry.m_pos[0];
1238 unsigned long type=input->readULong(4);
1239 std::shared_ptr<ClarisWksGraphInternal::ZonePict> pict;
1240 input->seek(-4, librevenge::RVNG_SEEK_CUR);
1241 if (type==0x5154494d) {
1242 pict.reset(new ClarisWksGraphInternal::ZonePict(ClarisWksGraphInternal::Zone(), ClarisWksGraphInternal::Zone::T_QTim));
1243 ok=readQTimeData(pict);
1244 }
1245 else {
1246 pict.reset(new ClarisWksGraphInternal::ZonePict(ClarisWksGraphInternal::Zone(), ClarisWksGraphInternal::Zone::T_Pict));
1247 ok=readPictData(pict);
1248 }
1249 if (ok && pict)
1250 m_state->m_databaseMap[int(i)] = pict;
1251 if (ok) {
1252 pos=input->tell();
1253 auto pictSz=long(input->readULong(4));
1254 if (pictSz<0 || pictSz>endDataPos-pos-4)
1255 input->seek(pos, librevenge::RVNG_SEEK_SET);
1256 else if (!pictSz) {
1257 ascFile.addPos(pos);
1258 ascFile.addNote("Nop");
1259 }
1260 else {
1261 ascFile.addPos(pos);
1262 ascFile.addNote("PictData[unkn]");
1263 input->seek(pos+4+pictSz, librevenge::RVNG_SEEK_SET);
1264 }
1265 }
1266 if (input->tell()!=endDataPos) {
1267 ascFile.addPos(input->tell());
1268 ascFile.addNote("DataPict[data]:###extra");
1269 MWAW_DEBUG_MSG(("ClarisWksGraph::readDatabasePictZone: find extra picture data\n"));
1270 input->seek(endDataPos, librevenge::RVNG_SEEK_SET);
1271 }
1272 long endZonePos = firstPos+(entry.m_pos[2]+1)*0x200;
1273 if (ok && input->tell()!=endZonePos) {
1274 ascFile.skipZone(input->tell(), endZonePos-1);
1275 input->seek(endZonePos, librevenge::RVNG_SEEK_SET);
1276 }
1277 }
1278
1279 input->popLimit();
1280 pos=input->tell();
1281 if (pos<endPos) {
1282 MWAW_DEBUG_MSG(("ClarisWksGraph::readDatabasePictZone: find extra data\n"));
1283 ascFile.addPos(pos);
1284 ascFile.addNote("DataPict:##extra");
1285 }
1286 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1287 return true;
1288 }
1289
1290 ////////////////////////////////////////////////////////////
1291 // definition of an element of a group
1292 ////////////////////////////////////////////////////////////
1293 void ClarisWksGraph::findMasterPage() const
1294 {
1295 // master page does not seems to exist in v1-v2 documents
1296 if (m_parserState->m_kind != MWAWDocument::MWAW_K_DRAW || version() <= 3)
1297 return;
1298 auto main=m_document.getZone(1);
1299 if (m_state->m_groupMap.find(1)== m_state->m_groupMap.end())
1300 return;
1301 auto mainGroup=m_state->m_groupMap.find(1)->second;
1302 if (!main || !mainGroup)
1303 return;
1304 // search for the master block
1305 int masterBlockId=-1;
1306 MWAWVec2f pageDim(0,0);
1307 for (auto const &zone : mainGroup->m_zones) {
1308 if (!zone || zone->getType()!=ClarisWksGraphInternal::Zone::T_Zone ||
1309 (zone->m_zoneType&0xF)!=0xa)
1310 continue;
1311 if (masterBlockId!=-1) {
1312 MWAW_DEBUG_MSG(("ClarisWksGraph::findMasterPage: a master block is already found\n"));
1313 return;
1314 }
1315 MWAWBox2f box=zone->getBdBox();
1316 if (box[0][0]<=0 && box[0][0]>=0 && box[0][1]<=0 && box[0][1]>=0)
1317 pageDim=box.size();
1318 else {
1319 MWAW_DEBUG_MSG(("ClarisWksGraph::findMasterPage: the page dimension seems odd\n"));
1320 }
1321 masterBlockId=static_cast<ClarisWksGraphInternal::ZoneZone const &>(*zone).m_id;
1322 }
1323 if (masterBlockId==-1) return;
1324 m_state->m_pageDimensions=pageDim;
1325 auto master=m_document.getZone(masterBlockId);
1326 if (!master || master->m_fathersList.size()!=1 || *master->m_fathersList.begin()!=1 ||
1327 m_state->m_groupMap.find(masterBlockId)==m_state->m_groupMap.end() || !m_state->m_groupMap.find(masterBlockId)->second) {
1328 MWAW_DEBUG_MSG(("ClarisWksGraph::findMasterPage: can not find the master zone\n"));
1329 return;
1330 }
1331 m_state->m_masterId=masterBlockId;
1332 master->m_position=ClarisWksStruct::DSET::P_GraphicMaster;
1333 }
1334
1335 ////////////////////////////////////////////////////////////
1336 // definition of an element of a group
1337 ////////////////////////////////////////////////////////////
1338 std::shared_ptr<ClarisWksGraphInternal::Zone> ClarisWksGraph::readGroupDef(MWAWEntry const &entry)
1339 {
1340 std::shared_ptr<ClarisWksGraphInternal::Zone> res;
1341 if (entry.length() < 32) {
1342 if (version() > 1 || entry.length() < 30) {
1343 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: sz is too short!!!\n"));
1344 return res;
1345 }
1346 }
1347 long pos = entry.begin();
1348 MWAWInputStreamPtr &input= m_parserState->m_input;
1349 input->seek(pos, librevenge::RVNG_SEEK_SET);
1350 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1351 libmwaw::DebugStream f;
1352 f << "GroupDef:";
1353
1354 ClarisWksGraphInternal::Zone zone;
1355 auto &style = zone.m_style;
1356
1357 auto typeId = static_cast<int>(input->readULong(1));
1358 auto type = ClarisWksGraphInternal::Zone::T_Unknown;
1359 int const vers=version();
1360 switch (vers) {
1361 case 1:
1362 switch (typeId) {
1363 case 1:
1364 type = ClarisWksGraphInternal::Zone::T_Zone;
1365 break;
1366 case 4:
1367 type = ClarisWksGraphInternal::Zone::T_Line;
1368 break;
1369 case 5:
1370 type = ClarisWksGraphInternal::Zone::T_Rect;
1371 break;
1372 case 6:
1373 type = ClarisWksGraphInternal::Zone::T_RectOval;
1374 break;
1375 case 7:
1376 type = ClarisWksGraphInternal::Zone::T_Oval;
1377 break;
1378 case 8:
1379 type = ClarisWksGraphInternal::Zone::T_Arc;
1380 break;
1381 case 9:
1382 type = ClarisWksGraphInternal::Zone::T_Poly;
1383 break;
1384 case 11:
1385 type = ClarisWksGraphInternal::Zone::T_Pict;
1386 break;
1387 case 12:
1388 type = ClarisWksGraphInternal::Zone::T_Chart;
1389 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: find some chart, not implemented!\n"));
1390 break;
1391 case 13:
1392 type = ClarisWksGraphInternal::Zone::T_DataBox;
1393 break;
1394 default:
1395 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: find unknown type=%d!!!\n", typeId));
1396 f << "###typeId=" << typeId << ",";
1397 break;
1398 }
1399 break;
1400 default:
1401 switch (typeId) {
1402 case 1:
1403 type = ClarisWksGraphInternal::Zone::T_Zone;
1404 break;
1405 case 2:
1406 type = ClarisWksGraphInternal::Zone::T_Line;
1407 break;
1408 case 3:
1409 type = ClarisWksGraphInternal::Zone::T_Rect;
1410 break;
1411 case 4:
1412 type = ClarisWksGraphInternal::Zone::T_RectOval;
1413 break;
1414 case 5:
1415 type = ClarisWksGraphInternal::Zone::T_Oval;
1416 break;
1417 case 6:
1418 type = ClarisWksGraphInternal::Zone::T_Arc;
1419 break;
1420 case 7:
1421 type = ClarisWksGraphInternal::Zone::T_Poly;
1422 break;
1423 case 8:
1424 type = ClarisWksGraphInternal::Zone::T_Pict;
1425 break;
1426 case 9:
1427 type = ClarisWksGraphInternal::Zone::T_Chart;
1428 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: find some chart, not implemented!\n"));
1429 break;
1430 case 10:
1431 type = ClarisWksGraphInternal::Zone::T_DataBox;
1432 break;
1433 case 11: // old method to define a textbox ?
1434 type = ClarisWksGraphInternal::Zone::T_Zone2;
1435 break;
1436 case 14:
1437 type = ClarisWksGraphInternal::Zone::T_Movie;
1438 break;
1439 case 18:
1440 type = ClarisWksGraphInternal::Zone::T_QTim;
1441 break;
1442 #if !defined(__clang__)
1443 default:
1444 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: find unknown type=%d!!!\n", typeId));
1445 f << "###typeId=" << typeId << ",";
1446 break;
1447 #endif
1448 }
1449 break;
1450 }
1451 auto val = static_cast<int>(input->readULong(1));
1452 style.m_wrapping = (val & 3);
1453 if (vers > 1)
1454 style.m_surfacePatternType = (val >> 2);
1455 else if (val>>2)
1456 f << "g0=" << (val>>2) << ",";
1457 zone.m_zoneType = static_cast<int>(input->readULong(1));
1458 if (zone.m_zoneType & 0x40) style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain();
1459 if (zone.m_zoneType & 0x80) style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain();
1460 zone.m_zoneType &= 0x3F;
1461 val = static_cast<int>(input->readULong(1));
1462 if (val) f << "f0=" << val << ",";
1463
1464 float dim[4];
1465 for (auto &d : dim) {
1466 d = float(input->readLong(4))/256.f;
1467 if (d < -100) f << "##dim?,";
1468 }
1469 zone.m_box = MWAWBox2f(MWAWVec2f(dim[1], dim[0]), MWAWVec2f(dim[3], dim[2]));
1470 style.m_lineWidth = float(input->readLong(1));
1471 val = static_cast<int>(input->readULong(1));
1472 if (val) f << "f1=" << val << ",";
1473 for (int j = 0; j < 2; j++) {
1474 auto col = static_cast<int>(input->readULong(1));
1475 MWAWColor color;
1476 if (!m_document.getStyleManager()->getColor(col, color)) {
1477 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: unknown color!!!\n"));
1478 f << "###col" << j << "=" << col << ",";
1479 }
1480 else if (j==0)
1481 style.m_lineColor=color;
1482 else
1483 style.setSurfaceColor(color);
1484 }
1485
1486 for (int j = 0; j < 2; j++) {
1487 if (vers > 1) {
1488 val = static_cast<int>(input->readULong(1)); // probably also related to surface
1489 if (val) f << "pat" << j << "[high]=" << val << ",";
1490 }
1491 auto pat = static_cast<int>(input->readULong(1));
1492 if (j==1 && style.m_surfacePatternType) {
1493 if (style.m_surfacePatternType==1) { // wall paper
1494 if (!m_document.getStyleManager()->updateWallPaper(pat, style))
1495 f << "##wallId=" << pat << ",";
1496 }
1497 else { // find one time 2 associtated with a picture
1498 f << "###surf[patternType]=" << style.m_surfacePatternType << ",";
1499 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: unknown surface pattern type!!!\n"));
1500 }
1501 continue;
1502 }
1503 if (j==1 && (zone.m_zoneType & 0x10)) {
1504 f << "hasGrad,";
1505 zone.m_zoneType &= 0xEF;
1506 m_document.getStyleManager()->updateGradient(pat, style);
1507 continue;
1508 }
1509 if (pat==1) {
1510 if (j==0) style.m_lineOpacity=0;
1511 else style.m_surfaceOpacity=0;
1512 continue;
1513 }
1514 MWAWGraphicStyle::Pattern pattern;
1515 float percent;
1516 if (!m_document.getStyleManager()->getPattern(pat,pattern,percent)) {
1517 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupDef: unknown pattern!!!\n"));
1518 f << "###pat" << j << "=" << pat << ",";
1519 }
1520 pattern.m_colors[1]=j==0 ? style.m_lineColor : style.m_surfaceColor;
1521 MWAWColor color;
1522 if (!pattern.getUniqueColor(color)) {
1523 pattern.getAverageColor(color);
1524 if (j==1) style.setPattern(pattern);
1525 }
1526 if (j==0)
1527 style.m_lineColor=color;
1528 else
1529 style.m_surfaceColor=color;
1530 }
1531 // checkme: look like an ordering, minimal value corresponding to front, actually unused
1532 zone.m_ordering = static_cast<int>(input->readLong(2));
1533
1534 switch (type) {
1535 case ClarisWksGraphInternal::Zone::T_Zone: {
1536 int nFlags = 0;
1537 auto z = std::make_shared<ClarisWksGraphInternal::ZoneZone>(zone, type);
1538 res = z;
1539 z->m_flags[nFlags++] = static_cast<int>(input->readLong(2));
1540 z->m_id = static_cast<int>(input->readULong(2));
1541
1542 auto numRemains = int(entry.end()-long(input->tell()));
1543 numRemains/=2;
1544 // v1-2:3 v4-v5:6 v6:8
1545 if (numRemains > 8) numRemains = 8;
1546 for (int j = 0; j < numRemains; j++) {
1547 val = static_cast<int>(input->readLong(2));
1548 switch (j) {
1549 case 1:
1550 z->m_subId = val;
1551 break;
1552 case 2:
1553 z->m_wrappingSep = val;
1554 break;
1555 case 3: // checkme
1556 z->m_styleId = val;
1557 break;
1558 default:
1559 z->m_flags[nFlags++] = val;
1560 break;
1561 }
1562 }
1563 break;
1564 }
1565 case ClarisWksGraphInternal::Zone::T_Zone2: { // checkme: read the end of the zone
1566 auto z = std::make_shared<ClarisWksGraphInternal::ZoneZone>(zone, type);
1567 res = z;
1568 break;
1569 }
1570 case ClarisWksGraphInternal::Zone::T_Pict:
1571 case ClarisWksGraphInternal::Zone::T_QTim:
1572 case ClarisWksGraphInternal::Zone::T_Movie:
1573 res.reset(new ClarisWksGraphInternal::ZonePict(zone, type));
1574 break;
1575 case ClarisWksGraphInternal::Zone::T_Line:
1576 case ClarisWksGraphInternal::Zone::T_Rect:
1577 case ClarisWksGraphInternal::Zone::T_RectOval:
1578 case ClarisWksGraphInternal::Zone::T_Oval:
1579 case ClarisWksGraphInternal::Zone::T_Arc:
1580 case ClarisWksGraphInternal::Zone::T_Poly: {
1581 auto z = std::make_shared<ClarisWksGraphInternal::ZoneShape>(zone, type);
1582 res = z;
1583 readShape(entry, *z);
1584 break;
1585 }
1586 case ClarisWksGraphInternal::Zone::T_Chart:
1587 res.reset(new ClarisWksGraphInternal::Chart(zone));
1588 break;
1589 case ClarisWksGraphInternal::Zone::T_DataBox:
1590 case ClarisWksGraphInternal::Zone::T_Shape:
1591 case ClarisWksGraphInternal::Zone::T_Picture:
1592 case ClarisWksGraphInternal::Zone::T_Unknown:
1593 #if !defined(__clang__)
1594 default:
1595 #endif
1596 {
1597 auto z = std::make_shared<ClarisWksGraphInternal::ZoneUnknown>(zone);
1598 res = z;
1599 z->m_type = type;
1600 z->m_typeId = typeId;
1601 break;
1602 }
1603 }
1604
1605 f << *res;
1606
1607 long actPos = input->tell();
1608 if (actPos != entry.begin() && actPos != entry.end())
1609 ascFile.addDelimiter(input->tell(),'|');
1610 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
1611
1612 ascFile.addPos(entry.begin());
1613 ascFile.addNote(f.str().c_str());
1614 return res;
1615 }
1616
1617 ////////////////////////////////////////////////////////////
1618 //
1619 // Intermediate level
1620 //
1621 ////////////////////////////////////////////////////////////
1622
1623 ////////////////////////////////////////////////////////////
1624 // extra data associated to some group's element
1625 ////////////////////////////////////////////////////////////
1626 bool ClarisWksGraph::readGroupData(ClarisWksGraphInternal::Group &group, long beginGroupPos)
1627 {
1628 // bool complete = false;
1629 if (!readGroupHeader(group)) {
1630 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: unexpected graphic1\n"));
1631 return false;
1632 }
1633
1634 MWAWInputStreamPtr &input= m_parserState->m_input;
1635
1636 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1637 libmwaw::DebugStream f;
1638 int const vers = version();
1639 long pos, sz;
1640 int numError = 0;
1641 for (auto const &z : group.m_zones) {
1642 int numZoneExpected = z ? z->getNumData(vers) : 0;
1643
1644 if (numZoneExpected) {
1645 pos = input->tell();
1646 sz = long(input->readULong(4));
1647 f.str("");
1648 if (sz == 0) {
1649 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: find a nop zone for type: %d\n",
1650 z->getSubType()));
1651 ascFile.addPos(pos);
1652 ascFile.addNote("GroupDef-before:###");
1653 if (!numError++) {
1654 ascFile.addPos(beginGroupPos);
1655 ascFile.addNote("###");
1656 }
1657 else {
1658 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: too many errors, zone parsing STOPS\n"));
1659 return false;
1660 }
1661 pos = input->tell();
1662 sz = long(input->readULong(4));
1663 }
1664 input->seek(pos, librevenge::RVNG_SEEK_SET);
1665 bool parsed = true;
1666 switch (z->getSubType()) {
1667 case ClarisWksGraphInternal::Zone::T_QTim:
1668 if (!readQTimeData(z))
1669 return false;
1670 break;
1671 case ClarisWksGraphInternal::Zone::T_Movie:
1672 // FIXME: pict ( containing movie ) + ??? +
1673 case ClarisWksGraphInternal::Zone::T_Pict:
1674 if (!readPictData(z))
1675 return false;
1676 break;
1677 case ClarisWksGraphInternal::Zone::T_Poly:
1678 if (z->getNumData(vers) && !readPolygonData(z))
1679 return false;
1680 break;
1681 case ClarisWksGraphInternal::Zone::T_Zone2: {
1682 auto *child=dynamic_cast<ClarisWksGraphInternal::ZoneZone *>(z.get());
1683 if (!child) {
1684 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: can not retrieve the zone for type 11\n"));
1685 parsed=false;
1686 break;
1687 }
1688 if (!input->checkPosition(pos+4+sz) || sz< 0x1a) {
1689 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: the size of the 11 zone seems bad\n"));
1690 parsed=false;
1691 break;
1692 }
1693 if (vers!=2) {
1694 // checkme: only find in v2, so may cause problem for other version
1695 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: called on a type 11 zone\n"));
1696 }
1697 input->seek(pos+4, librevenge::RVNG_SEEK_SET);
1698 f.str("");
1699 f << "Entries(Zone2Data):";
1700 int val;
1701 for (int j=0; j<2; ++j) { // f0=2, f1=1
1702 val=static_cast<int>(input->readULong(1));
1703 if (val) f << "f" << j << "=" << val << ",";
1704 }
1705 val=static_cast<int>(input->readULong(2)); // 6e
1706 if (val) f << "f2=" << val << ",";
1707 f << "ids=[";
1708 for (int j=0; j<2; ++j)
1709 f << input->readULong(4) << ",";;
1710 f << "],";
1711 val=static_cast<int>(input->readULong(2)); // always 0
1712 if (val) f << "f3=" << val << ",";
1713 child->m_id=static_cast<int>(input->readULong(2));
1714 f << "child=" << child->m_id << ",";
1715 ascFile.addDelimiter(input->tell(),'|');
1716 ascFile.addPos(pos);
1717 ascFile.addNote(f.str().c_str());
1718 input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET);
1719 break;
1720 }
1721 case ClarisWksGraphInternal::Zone::T_Chart:
1722 if (!readChartData(z))
1723 return false;
1724 break;
1725 case ClarisWksGraphInternal::Zone::T_Line:
1726 case ClarisWksGraphInternal::Zone::T_Rect:
1727 case ClarisWksGraphInternal::Zone::T_RectOval:
1728 case ClarisWksGraphInternal::Zone::T_Oval:
1729 case ClarisWksGraphInternal::Zone::T_Arc:
1730 case ClarisWksGraphInternal::Zone::T_Zone:
1731 case ClarisWksGraphInternal::Zone::T_Shape:
1732 case ClarisWksGraphInternal::Zone::T_Picture:
1733 case ClarisWksGraphInternal::Zone::T_DataBox:
1734 case ClarisWksGraphInternal::Zone::T_Unknown:
1735 #if !defined(__clang__)
1736 default:
1737 #endif
1738 parsed = false;
1739 break;
1740 }
1741
1742 if (!parsed) {
1743 if (!input->checkPosition(pos+4+sz)) {
1744 input->seek(pos, librevenge::RVNG_SEEK_SET);
1745 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: find a odd zone for type: %d\n",
1746 z->getSubType()));
1747 return false;
1748 }
1749 f.str("");
1750 f << "Entries(UnknownDATA)-" << z->getSubType();
1751 ascFile.addPos(pos);
1752 ascFile.addNote(f.str().c_str());
1753 input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET);
1754 if (numZoneExpected==2) {
1755 pos = input->tell();
1756 sz = long(input->readULong(4));
1757 if (sz) {
1758 input->seek(pos, librevenge::RVNG_SEEK_SET);
1759 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: two zones is not implemented for zone: %d\n",
1760 z->getSubType()));
1761 return false;
1762 }
1763 ascFile.addPos(pos);
1764 ascFile.addNote("NOP");
1765 }
1766 }
1767 }
1768 if (vers>=6) {
1769 pos = input->tell();
1770 sz = long(input->readULong(4));
1771 if (sz == 0) {
1772 ascFile.addPos(pos);
1773 ascFile.addNote("Nop");
1774 continue;
1775 }
1776 else if (numZoneExpected) {
1777 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: find not null entry for a end of zone: %d\n", z->getSubType()));
1778 ascFile.addPos(pos);
1779 ascFile.addNote("GroupDef[##extra2]");
1780 }
1781 input->seek(pos, librevenge::RVNG_SEEK_SET);
1782 }
1783 }
1784
1785 if (input->isEnd())
1786 return true;
1787 // sanity check: normaly no zero except maybe for the last zone
1788 pos=input->tell();
1789 sz=long(input->readULong(4));
1790 int numUnparsed=0;
1791 while (input->checkPosition(pos+4+sz)) {
1792 // this can happens at the end of the file (and it is normal)
1793 if (!input->checkPosition(pos+4+sz+10))
1794 break;
1795 static bool isFirst=true;
1796 if (isFirst) {
1797 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: find some extra block\n"));
1798 isFirst=false;
1799 }
1800 input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET);
1801 f.str("");
1802 f << "GroupDef[end-" << numUnparsed++ << "]: ###";
1803 ascFile.addPos(pos);
1804 ascFile.addNote(f.str().c_str());
1805 pos=input->tell();
1806 sz=long(input->readULong(4));
1807 }
1808 input->seek(pos, librevenge::RVNG_SEEK_SET);
1809
1810 return true;
1811 }
1812
1813 ////////////////////////////////////////////////////////////
1814 //
1815 // Low level
1816 //
1817 ////////////////////////////////////////////////////////////
1818 bool ClarisWksGraph::readShape(MWAWEntry const &entry, ClarisWksGraphInternal::ZoneShape &zone)
1819 {
1820 MWAWInputStreamPtr &input= m_parserState->m_input;
1821 long actPos = input->tell();
1822 auto remainBytes = int(entry.end()-actPos);
1823 if (remainBytes < 0)
1824 return false;
1825
1826 MWAWVec2f pictSz=zone.getBdBox().size();
1827 MWAWBox2f box(MWAWVec2f(0,0), pictSz);
1828 MWAWGraphicShape &shape=zone.m_shape;
1829 shape.m_bdBox=shape.m_formBox=box;
1830 libmwaw::DebugStream f;
1831 switch (zone.getSubType()) {
1832 case ClarisWksGraphInternal::Zone::T_Line: {
1833 int yDeb=(zone.m_zoneType&1)?1:0;
1834 shape = MWAWGraphicShape::line(MWAWVec2f(zone.m_box[0][0],zone.m_box[yDeb][1]),
1835 MWAWVec2f(zone.m_box[1][0],zone.m_box[1-yDeb][1]));
1836 break;
1837 }
1838 case ClarisWksGraphInternal::Zone::T_Rect:
1839 shape.m_type = MWAWGraphicShape::Rectangle;
1840 break;
1841 case ClarisWksGraphInternal::Zone::T_Oval:
1842 shape.m_type = MWAWGraphicShape::Circle;
1843 break;
1844 case ClarisWksGraphInternal::Zone::T_Poly:
1845 shape.m_type = MWAWGraphicShape::Polygon;
1846 break; // value are defined in next zone
1847 case ClarisWksGraphInternal::Zone::T_Arc: {
1848 if (remainBytes < 4) {
1849 MWAW_DEBUG_MSG(("ClarisWksGraph::readSimpleGraphicZone: arc zone is too short\n"));
1850 return false;
1851 }
1852 int fileAngle[2];
1853 for (int &fAngle : fileAngle) fAngle = static_cast<int>(input->readLong(2));
1854 auto val=static_cast<int>(input->readLong(1));
1855 if (val==1) f<< "show[axis],";
1856 else if (val) f << "#show[axis]=" << val << ",";
1857 int angle[2] = { 90-fileAngle[0]-fileAngle[1], 90-fileAngle[0] };
1858 if (angle[1]>360) {
1859 int numLoop=int(angle[1]/360)-1;
1860 angle[0]-=numLoop*360;
1861 angle[1]-=numLoop*360;
1862 while (angle[1] > 360) {
1863 angle[0]-=360;
1864 angle[1]-=360;
1865 }
1866 }
1867 if (angle[0] < -360) {
1868 int numLoop=int(angle[0]/360)+1;
1869 angle[0]-=numLoop*360;
1870 angle[1]-=numLoop*360;
1871 while (angle[0] < -360) {
1872 angle[0]+=360;
1873 angle[1]+=360;
1874 }
1875 }
1876 MWAWVec2f center = box.center();
1877 MWAWVec2f axis = 0.5f*MWAWVec2f(box.size());
1878 // we must compute the real bd box
1879 float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 };
1880 int limitAngle[2];
1881 for (int i = 0; i < 2; i++)
1882 limitAngle[i] = (angle[i] < 0) ? int(angle[i]/90)-1 : int(angle[i]/90);
1883 for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; bord++) {
1884 float ang = (bord == limitAngle[0]) ? float(angle[0]) :
1885 (bord == limitAngle[1]+1) ? float(angle[1]) : float(90 * bord);
1886 ang *= float(M_PI/180.);
1887 float const actVal[2] = { axis[0] *std::cos(ang), -axis[1] *std::sin(ang)};
1888 if (actVal[0] < minVal[0]) minVal[0] = actVal[0];
1889 else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0];
1890 if (actVal[1] < minVal[1]) minVal[1] = actVal[1];
1891 else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1];
1892 }
1893 MWAWBox2f realBox(MWAWVec2f(center[0]+minVal[0],center[1]+minVal[1]),
1894 MWAWVec2f(center[0]+maxVal[0],center[1]+maxVal[1]));
1895 zone.m_box=MWAWBox2f(MWAWVec2f(zone.m_box[0])+realBox[0],MWAWVec2f(zone.m_box[0])+realBox[1]);
1896 shape = MWAWGraphicShape::pie(realBox, box, MWAWVec2f(float(angle[0]),float(angle[1])));
1897 break;
1898 }
1899 case ClarisWksGraphInternal::Zone::T_RectOval: {
1900 shape.m_type = MWAWGraphicShape::Rectangle;
1901 if (remainBytes < 8) {
1902 MWAW_DEBUG_MSG(("ClarisWksGraph::readSimpleGraphicZone: arc zone is too short\n"));
1903 return false;
1904 }
1905 for (int i = 0; i < 2; i++) {
1906 float dim=float(input->readLong(2))/2.0f;
1907 shape.m_cornerWidth[i]=(2.f*dim <= pictSz[i]) ? dim : pictSz[i]/2.f;
1908 auto val = static_cast<int>(input->readULong(2));
1909 if (val) f << "rRect" << i << "=" << val << ",";
1910 }
1911 break;
1912 }
1913 case ClarisWksGraphInternal::Zone::T_Zone:
1914 case ClarisWksGraphInternal::Zone::T_Zone2:
1915 case ClarisWksGraphInternal::Zone::T_Shape:
1916 case ClarisWksGraphInternal::Zone::T_Picture:
1917 case ClarisWksGraphInternal::Zone::T_Chart:
1918 case ClarisWksGraphInternal::Zone::T_DataBox:
1919 case ClarisWksGraphInternal::Zone::T_Unknown:
1920 case ClarisWksGraphInternal::Zone::T_Pict:
1921 case ClarisWksGraphInternal::Zone::T_QTim:
1922 case ClarisWksGraphInternal::Zone::T_Movie:
1923 #if !defined(__clang__)
1924 default:
1925 #endif
1926 MWAW_DEBUG_MSG(("ClarisWksGraph::readSimpleGraphicZone: unknown type\n"));
1927 return false;
1928 }
1929
1930 int const vers=version();
1931 long nextToRead = entry.end()+(vers==6 ? -6 : vers>=4 ? -2 : 0);
1932 auto numRemain = int(nextToRead-input->tell());
1933 numRemain /= 2;
1934 for (int i = 0; i < numRemain; i++) {
1935 auto val = static_cast<int>(input->readLong(2));
1936 if (val) f << "g" << i << "=" << val << ",";
1937 }
1938 if (vers>=4 && input->tell() <= nextToRead) {
1939 input->seek(nextToRead, librevenge::RVNG_SEEK_SET);
1940 zone.m_rotate=static_cast<int>(input->readLong(2));
1941 if (zone.m_rotate) {
1942 shape=shape.rotate(float(-zone.m_rotate), shape.m_bdBox.center());
1943 MWAWVec2f orig=zone.m_box[0]+shape.m_bdBox[0];
1944 shape.translate(-1.f*shape.m_bdBox[0]);
1945 zone.m_box=MWAWBox2f(orig, orig+shape.m_bdBox.size());
1946 }
1947 if (vers==6) {
1948 for (int i=0; i < 2; i++) { // always 0
1949 auto val = static_cast<int>(input->readLong(2));
1950 if (val) f << "h" << i << "=" << val << ",";
1951 }
1952 }
1953 }
1954 shape.m_extra=f.str();
1955 return true;
1956 }
1957
1958 bool ClarisWksGraph::readGroupHeader(ClarisWksGraphInternal::Group &group)
1959 {
1960 MWAWInputStreamPtr &input= m_parserState->m_input;
1961 long pos = input->tell();
1962 // int const vers=version();
1963 ClarisWksStruct::Struct header;
1964 if (!header.readHeader(input,false)) {
1965 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupHeader: can not read the header\n"));
1966 return false;
1967 }
1968 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1969 libmwaw::DebugStream f;
1970 if (header.m_size==0) {
1971 ascFile.addPos(pos);
1972 ascFile.addNote("Nop");
1973 return true;
1974 }
1975 f << "GroupDef(Header):" << header;
1976 if (header.m_headerSize) {
1977 ascFile.addDelimiter(input->tell(),'|');
1978 input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR);
1979 }
1980 ascFile.addPos(pos);
1981 ascFile.addNote(f.str().c_str());
1982
1983 for (long i = 0; i < header.m_numData; i++) {
1984 pos = input->tell();
1985 if (readGroupUnknown(group, int(header.m_dataSize), int(i)))
1986 continue;
1987 ascFile.addPos(pos);
1988 ascFile.addNote("GroupDef(Head-###)");
1989 input->seek(pos+header.m_dataSize, librevenge::RVNG_SEEK_SET);
1990 }
1991
1992 int const numHeaders= header.m_numData==0 ? 1 : int(header.m_numData);
1993 for (int i = 0; i < numHeaders; i++) {
1994 pos = input->tell();
1995 std::vector<int> res;
1996 /** not frequent but we can find a list of int16 as
1997 00320060 00480060 0048ffe9 013a0173 01ba0173 01ea02a0
1998 01f8ffe7 02080295 020c012c 02140218 02ae01c1
1999 02ca02c9-02cc02c6-02400000
2000 03f801e6
2001 8002e3ff e0010000 ee02e6ff */
2002 bool ok = ClarisWksStruct::readIntZone(*m_parserState, "GroupDef", false, 2, res);
2003 f.str("");
2004 f << "[GroupDef(data" << i << ")]";
2005 if (ok) {
2006 ascFile.addPos(pos);
2007 ascFile.addNote(f.str().c_str());
2008 continue;
2009 }
2010 input->seek(pos, librevenge::RVNG_SEEK_SET);
2011 f << "###";
2012 ascFile.addPos(pos);
2013 ascFile.addNote(f.str().c_str());
2014 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupHeader: can not find data for %d\n", i));
2015 return true;
2016 }
2017 // normally, this is often followed by another list of nop/list of int zone (but not always...)
2018 for (long i = 0; i < header.m_numData; i++) {
2019 pos = input->tell();
2020 auto sz=long(input->readULong(4));
2021 f.str("");
2022 f << "[GroupDef(dataB" << i << ")]:";
2023 if (!sz) {
2024 ascFile.addPos(pos);
2025 ascFile.addNote(f.str().c_str());
2026 continue;
2027 }
2028 if (sz>12) { // test if this is a list of int
2029 input->seek(pos+10, librevenge::RVNG_SEEK_SET);
2030 if (input->readLong(2)==2) {
2031 std::vector<int> res;
2032 input->seek(pos, librevenge::RVNG_SEEK_SET);
2033 if (sz>12 && ClarisWksStruct::readIntZone(*m_parserState, "GroupDef", false, 2, res)) {
2034 ascFile.addPos(pos);
2035 ascFile.addNote(f.str().c_str());
2036 continue;
2037 }
2038 }
2039 }
2040 input->seek(pos, librevenge::RVNG_SEEK_SET);
2041 if (i!=0) {
2042 f << "###";
2043 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupHeader: find some data for a dataB zone\n"));
2044 }
2045 break;
2046 }
2047
2048 return true;
2049 }
2050
2051 bool ClarisWksGraph::readGroupUnknown(ClarisWksGraphInternal::Group &group, int zoneSz, int id)
2052 {
2053 MWAWInputStreamPtr &input= m_parserState->m_input;
2054 long pos = input->tell();
2055 input->seek(pos+zoneSz, librevenge::RVNG_SEEK_SET);
2056 if (input->tell() != pos+zoneSz) {
2057 input->seek(pos, librevenge::RVNG_SEEK_SET);
2058 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupUnknown: zone is too short\n"));
2059 return false;
2060 }
2061 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2062 libmwaw::DebugStream f;
2063 f << "GroupDef(Head-";
2064 if (id >= 0) f << id << "):";
2065 else f << "_" << "):";
2066 if (zoneSz < 42) {
2067 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupUnknown: zone is too short\n"));
2068 f << "###";
2069 ascFile.addPos(pos);
2070 ascFile.addNote(f.str().c_str());
2071 return true;
2072 }
2073
2074 input->seek(pos, librevenge::RVNG_SEEK_SET);
2075 auto type = static_cast<int>(input->readLong(2)); // find -1, 0, 3
2076 if (type) f << "f0=" << type << ",";
2077 for (int i = 0; i < 6; i++) {
2078 /** find f1=8|9|f|14|15|2a|40|73|e9, f2=0|d4, f5=0|80, f6=0|33 */
2079 auto val = long(input->readULong(1));
2080 if (val) f << "f" << i+1 << "=" << std::hex << val << std::dec << ",";
2081 }
2082 std::vector<int16_t> values16; // some values can be small or little endian, so...
2083 std::vector<int32_t> values32;
2084 for (int i = 0; i < 2; i++)
2085 values32.push_back(static_cast<int32_t>(input->readLong(4)));
2086 // now two small number also in big or small endian
2087 for (int i = 0; i < 2; i++)
2088 values16.push_back(static_cast<int16_t>(input->readLong(2)));
2089 // a very big number
2090 values32.push_back(static_cast<int32_t>(input->readLong(4)));
2091 m_document.checkOrdering(values16, values32);
2092
2093 MWAWVec2i dim(static_cast<int>(values32[0]),static_cast<int>(values32[1]));
2094 if (id < 0)
2095 group.m_pageDimension=MWAWVec2f(dim);
2096 if (dim[0] || dim[1]) f << "dim=" << dim << ",";
2097 if (values16[0]!=1 || values16[1]!=1)
2098 f << "pages[num]=" << values16[0] << "x" << values16[1] << ",";
2099 if (values32[2])
2100 f << "g0=" << std::hex << values32[2] << std::dec << ",";
2101
2102 if (input->tell() != pos+zoneSz) {
2103 ascFile.addDelimiter(input->tell(), '|');
2104 input->seek(pos+zoneSz, librevenge::RVNG_SEEK_SET);
2105 }
2106 ascFile.addPos(pos);
2107 ascFile.addNote(f.str().c_str());
2108 return true;
2109 }
2110
2111 ////////////////////////////////////////////////////////////
2112 // read the polygon vertices
2113 ////////////////////////////////////////////////////////////
2114 bool ClarisWksGraph::readPolygonData(std::shared_ptr<ClarisWksGraphInternal::Zone> zone)
2115 {
2116 if (!zone || zone->getType() != ClarisWksGraphInternal::Zone::T_Shape)
2117 return false;
2118 auto *bZone = static_cast<ClarisWksGraphInternal::ZoneShape *>(zone.get());
2119 MWAWGraphicShape &shape = bZone->m_shape;
2120 if (shape.m_type!=MWAWGraphicShape::Polygon)
2121 return false;
2122 MWAWInputStreamPtr &input= m_parserState->m_input;
2123 long pos = input->tell();
2124 ClarisWksStruct::Struct header;
2125 if (!header.readHeader(input,false)) {
2126 MWAW_DEBUG_MSG(("ClarisWksGraph::readPolygonData: can not read the header\n"));
2127 return false;
2128 }
2129 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2130 libmwaw::DebugStream f;
2131 if (header.m_size==0) {
2132 ascFile.addPos(pos);
2133 ascFile.addNote("Nop");
2134 return true;
2135 }
2136 long endPos = pos+4+header.m_size;
2137 f << "Entries(PolygonData):" << header;
2138 if (header.m_headerSize) {
2139 ascFile.addDelimiter(input->tell(),'|');
2140 input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR);
2141 }
2142 ascFile.addPos(pos);
2143 ascFile.addNote(f.str().c_str());
2144
2145 bool isSpline=false;
2146 std::vector<ClarisWksGraphInternal::CurvePoint> vertices;
2147 for (long i = 0; i < header.m_numData; i++) {
2148 pos = input->tell();
2149 f.str("");
2150 f << "PolygonData-" << i << ":";
2151 float position[2];
2152 for (float &posi : position) posi = float(input->readLong(4))/256.f;
2153 ClarisWksGraphInternal::CurvePoint point(MWAWVec2f(position[1], position[0]));
2154 if (header.m_dataSize >= 26) {
2155 for (auto &controlPoint : point.m_controlPoints) {
2156 float ctrlPos[2];
2157 for (auto &ctrl : ctrlPos) ctrl = float(input->readLong(4))/256.f;
2158 controlPoint = MWAWVec2f(ctrlPos[1], ctrlPos[0]);
2159 }
2160 auto fl = static_cast<int>(input->readULong(2));
2161 point.m_type = (fl>>14);
2162 f << point << ",";
2163 if (fl&0x3FFF)
2164 f << "unkn=" << std::hex << int(fl&0x3FFF) << std::dec << ",";
2165 }
2166 else
2167 f << point << ",";
2168 if (point.m_type >= 2) isSpline=true;
2169 vertices.push_back(point);
2170
2171 ascFile.addPos(pos);
2172 ascFile.addNote(f.str().c_str());
2173
2174 input->seek(pos+header.m_dataSize, librevenge::RVNG_SEEK_SET);
2175 }
2176 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2177 if (!isSpline) {
2178 // if (zone.m_zoneType & 1) : we must close the polygon ?
2179 for (auto const &vertex : vertices)
2180 shape.m_vertices.push_back(vertex.m_pos);
2181 return true;
2182 }
2183 shape.m_type = MWAWGraphicShape::Path;
2184 MWAWVec2f prevPoint, pt1;
2185 bool hasPrevPoint = false;
2186 for (size_t i = 0; i < vertices.size(); ++i) {
2187 auto const &pt = vertices[i];
2188 if (pt.m_type >= 2) pt1 = pt.m_controlPoints[0];
2189 else pt1 = pt.m_pos;
2190 char type = hasPrevPoint ? 'C' : i==0 ? 'M' : pt.m_type<2 ? 'L' : 'S';
2191 shape.m_path.push_back(MWAWGraphicShape::PathData(type, pt.m_pos, hasPrevPoint ? prevPoint : pt1, pt1));
2192 hasPrevPoint = pt.m_type >= 2;
2193 if (hasPrevPoint) prevPoint = pt.m_controlPoints[1];
2194 }
2195
2196 return true;
2197 }
2198
2199 ////////////////////////////////////////////////////////////
2200 // read some chart
2201 ////////////////////////////////////////////////////////////
2202 bool ClarisWksGraph::readChartData(std::shared_ptr<ClarisWksGraphInternal::Zone> zone)
2203 {
2204 if (!zone || zone->getSubType() != ClarisWksGraphInternal::Zone::T_Chart)
2205 return false;
2206
2207 MWAWInputStreamPtr input = m_parserState->m_input;
2208 long pos = input->tell();
2209 ClarisWksStruct::Struct header;
2210 if (!header.readHeader(input,true) || header.m_size==0 || header.m_dataSize<16) {
2211 MWAW_DEBUG_MSG(("ClarisWksGraph::readChartData: can not read the header\n"));
2212 return false;
2213 }
2214 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2215 libmwaw::DebugStream f;
2216 long endPos=pos+4+header.m_size;
2217 f << "Entries(ChartData):" << header;
2218 if (header.m_headerSize) {
2219 ascFile.addDelimiter(input->tell(),'|');
2220 input->seek(header.m_headerSize, librevenge::RVNG_SEEK_CUR);
2221 }
2222 ascFile.addPos(pos);
2223 ascFile.addNote(f.str().c_str());
2224
2225 for (long i = 0; i < header.m_numData; i++) {
2226 pos=input->tell();
2227 f.str("");
2228 f << "ChartData-" << i << ":";
2229
2230 input->seek(pos+header.m_dataSize, librevenge::RVNG_SEEK_SET);
2231 ascFile.addPos(pos);
2232 ascFile.addNote(f.str().c_str());
2233 }
2234 input->seek(endPos,librevenge::RVNG_SEEK_SET);
2235 if (version()==1)
2236 return true;
2237 std::vector<std::string> names;
2238 if (!m_document.readStringList("ChartData", false, names)) {
2239 MWAW_DEBUG_MSG(("ClarisWksGraph::readGroupData: find unexpected second zone\n"));
2240 input->seek(endPos,librevenge::RVNG_SEEK_SET);
2241 return false;
2242 }
2243 return true;
2244 }
2245
2246 ////////////////////////////////////////////////////////////
2247 // read some picture
2248 ////////////////////////////////////////////////////////////
2249 bool ClarisWksGraph::readPictData(std::shared_ptr<ClarisWksGraphInternal::Zone> zone)
2250 {
2251 if (!zone || (zone->getSubType() != ClarisWksGraphInternal::Zone::T_Pict &&
2252 zone->getSubType() != ClarisWksGraphInternal::Zone::T_Movie))
2253 return false;
2254 auto *pZone =
2255 static_cast<ClarisWksGraphInternal::ZonePict *>(zone.get());
2256 MWAWInputStreamPtr &input= m_parserState->m_input;
2257 long pos = input->tell();
2258 if (!readPICT(*pZone)) {
2259 MWAW_DEBUG_MSG(("ClarisWksGraph::readPictData: find a odd pict\n"));
2260 input->seek(pos, librevenge::RVNG_SEEK_SET);
2261 return false;
2262 }
2263 pos = input->tell();
2264 auto sz = long(input->readULong(4));
2265 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2266 if (!input->checkPosition(pos+4+sz)) {
2267 input->seek(pos, librevenge::RVNG_SEEK_SET);
2268 ascFile.addPos(pos);
2269 ascFile.addNote("###");
2270 MWAW_DEBUG_MSG(("ClarisWksGraph::readPictData: find a end zone for graphic\n"));
2271 return false;
2272 }
2273 if (sz == 0) {
2274 ascFile.addPos(pos);
2275 ascFile.addNote("Nop");
2276 return true;
2277 }
2278
2279 // fixme: use readPS for a mac file and readOLE for a pc file
2280 input->seek(pos, librevenge::RVNG_SEEK_SET);
2281 if (readPS(*pZone))
2282 return true;
2283
2284 input->seek(pos, librevenge::RVNG_SEEK_SET);
2285 if (readOLE(*pZone))
2286 return true;
2287
2288 MWAW_DEBUG_MSG(("ClarisWksGraph::readPictData: unknown data file\n"));
2289 #ifdef DEBUG_WITH_FILES
2290 if (1) {
2291 librevenge::RVNGBinaryData file;
2292 input->seek(pos+4, librevenge::RVNG_SEEK_SET);
2293 input->readDataBlock(sz, file);
2294 static int volatile pictName = 0;
2295 libmwaw::DebugStream f;
2296 f << "DATA-" << ++pictName;
2297 libmwaw::Debug::dumpFile(file, f.str().c_str());
2298 }
2299 #endif
2300 ascFile.addPos(pos);
2301 if (zone->getSubType() == ClarisWksGraphInternal::Zone::T_Movie)
2302 ascFile.addNote("Entries(MovieData2):#"); // find filesignature: ALMC...
2303 else
2304 ascFile.addNote("Entries(PictData2):#");
2305 ascFile.skipZone(pos+4, pos+4+sz-1);
2306
2307 input->seek(pos+4+sz, librevenge::RVNG_SEEK_SET);
2308 return true;
2309 }
2310
2311 bool ClarisWksGraph::readPICT(ClarisWksGraphInternal::ZonePict &zone)
2312 {
2313 MWAWInputStreamPtr &input= m_parserState->m_input;
2314 long pos = input->tell();
2315 auto sz = long(input->readULong(4));
2316 long endPos = pos+4+sz;
2317 if (sz < 12 || !input->checkPosition(endPos)) {
2318 MWAW_DEBUG_MSG(("ClarisWksGraph::readPict: file is too short\n"));
2319 return false;
2320 }
2321 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2322 libmwaw::DebugStream f;
2323 f << "Entries(Graphic):";
2324
2325 MWAWBox2f box;
2326 auto res = MWAWPictData::check(input, static_cast<int>(sz), box);
2327 if (res == MWAWPict::MWAW_R_BAD) {
2328 MWAW_DEBUG_MSG(("ClarisWksGraph::readPict: can not find the picture\n"));
2329 input->seek(pos, librevenge::RVNG_SEEK_SET);
2330 f << "###";
2331 ascFile.addPos(pos);
2332 ascFile.addNote(f.str().c_str());
2333
2334 return false;
2335 }
2336
2337 zone.m_entries[0].setBegin(pos+4);
2338 zone.m_entries[0].setEnd(endPos);
2339 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2340 ascFile.addPos(pos);
2341 ascFile.addNote(f.str().c_str());
2342
2343 return true;
2344 }
2345
2346 bool ClarisWksGraph::readPS(ClarisWksGraphInternal::ZonePict &zone)
2347 {
2348 MWAWInputStreamPtr &input= m_parserState->m_input;
2349 long pos = input->tell();
2350 auto sz = long(input->readULong(4));
2351 auto header = long(input->readULong(4));
2352 if (header != 0x25215053L) {
2353 return false;
2354 }
2355 long endPos = pos+4+sz;
2356 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2357 if (long(input->tell()) != endPos) {
2358 return false;
2359 }
2360 zone.m_entries[1].setBegin(pos+4);
2361 zone.m_entries[1].setEnd(endPos);
2362 zone.m_entries[1].setType("PS");
2363 #ifdef DEBUG_WITH_FILES
2364 if (1) {
2365 librevenge::RVNGBinaryData file;
2366 input->seek(pos+4, librevenge::RVNG_SEEK_SET);
2367 input->readDataBlock(sz, file);
2368 static int volatile pictName = 0;
2369 libmwaw::DebugStream f;
2370 f << "PostScript-" << ++pictName << ".ps";
2371 libmwaw::Debug::dumpFile(file, f.str().c_str());
2372 }
2373 #endif
2374
2375 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2376 libmwaw::DebugStream f;
2377 f << "Entries(PostScript):";
2378 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2379 ascFile.addPos(pos);
2380 ascFile.addNote(f.str().c_str());
2381 ascFile.skipZone(pos+4, endPos-1);
2382
2383 return true;
2384 }
2385
2386 bool ClarisWksGraph::readOLE(ClarisWksGraphInternal::ZonePict &zone)
2387 {
2388 MWAWInputStreamPtr &input= m_parserState->m_input;
2389 long pos = input->tell();
2390 auto sz = long(input->readULong(4));
2391 long val = input->readLong(4);
2392 if (sz <= 24 || val != 0 || input->readULong(4) != 0x1000000)
2393 return false;
2394 long endPos = pos+4+sz;
2395 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2396 if (long(input->tell()) != endPos)
2397 return false;
2398 input->seek(pos+12, librevenge::RVNG_SEEK_SET);
2399 // now a dim in little endian
2400 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2401 libmwaw::DebugStream f;
2402 f << "Entries(OLE):";
2403 int dim[4];
2404 for (auto &d : dim) d = static_cast<int>(static_cast<int32_t>(MWAWInputStream::readULong(input->input().get(), 4, 0, true)));
2405 if (dim[0] >= dim[2] || dim[1] >= dim[3]) return false;
2406 f << "dim=" << dim[1] << "x" << dim[0] << "<->" << dim[3] << "x" << dim[2] << ",";
2407 zone.m_entries[1].setBegin(pos+28);
2408 zone.m_entries[1].setEnd(endPos);
2409 zone.m_entries[1].setType("OLE");
2410 #ifdef DEBUG_WITH_FILES
2411 if (1) {
2412 librevenge::RVNGBinaryData file;
2413 input->seek(pos+28, librevenge::RVNG_SEEK_SET);
2414 input->readDataBlock(sz-24, file);
2415 static int volatile pictName = 0;
2416 libmwaw::DebugStream f2;
2417 f2 << "OLE-" << ++pictName;
2418 libmwaw::Debug::dumpFile(file, f2.str().c_str());
2419 }
2420 #endif
2421
2422 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2423 ascFile.addPos(pos);
2424 ascFile.addNote(f.str().c_str());
2425 ascFile.skipZone(pos+28, endPos-1);
2426
2427 return true;
2428 }
2429
2430 ////////////////////////////////////////////////////////////
2431 // read Qtime picture
2432 ////////////////////////////////////////////////////////////
2433 bool ClarisWksGraph::readQTimeData(std::shared_ptr<ClarisWksGraphInternal::Zone> zone)
2434 {
2435 if (!zone || zone->getSubType() != ClarisWksGraphInternal::Zone::T_QTim)
2436 return false;
2437 auto *pZone =
2438 static_cast<ClarisWksGraphInternal::ZonePict *>(zone.get());
2439 MWAWInputStreamPtr &input= m_parserState->m_input;
2440 long pos = input->tell();
2441 bool ok = true;
2442 std::string name("");
2443 for (int i = 0; i < 4; i++) {
2444 auto c = char(input->readULong(1));
2445 if (c == 0) ok = false;
2446 name += c;
2447 }
2448 if (!ok) {
2449 MWAW_DEBUG_MSG(("ClarisWksGraph::readQTimeData: find a odd qtim zone\n"));
2450 input->seek(pos, librevenge::RVNG_SEEK_SET);
2451 return false;
2452 }
2453 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2454 libmwaw::DebugStream f;
2455 f << "Entries(QTIM):"<< name << ":";
2456 for (int i = 0; i < 2; i++) f << "f" << i << "=" << input->readULong(2) << ",";
2457 ascFile.addPos(pos);
2458 ascFile.addNote(f.str().c_str());
2459
2460 pos = input->tell();
2461 if (!readNamedPict(*pZone)) {
2462 MWAW_DEBUG_MSG(("ClarisWksGraph::readQTimeData: find a odd named pict\n"));
2463 input->seek(pos, librevenge::RVNG_SEEK_SET);
2464 return false;
2465 }
2466 return true;
2467 }
2468
2469 bool ClarisWksGraph::readNamedPict(ClarisWksGraphInternal::ZonePict &zone)
2470 {
2471 MWAWInputStreamPtr &input= m_parserState->m_input;
2472 long pos = input->tell();
2473 std::string name("");
2474 for (int i = 0; i < 4; i++) {
2475 auto c = char(input->readULong(1));
2476 if (c < ' ' || c > 'z') {
2477 MWAW_DEBUG_MSG(("ClarisWksGraph::readNamedPict: can not find the name\n"));
2478 return false;
2479 }
2480 name+=c;
2481 }
2482 auto sz = long(input->readULong(4));
2483 long endPos = pos+8+sz;
2484 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2485 if (long(input->tell()) != endPos || !sz) {
2486 MWAW_DEBUG_MSG(("ClarisWksGraph::readNamedPict: file is too short\n"));
2487 return false;
2488 }
2489
2490 zone.m_entries[0].setBegin(pos+8);
2491 zone.m_entries[0].setEnd(endPos);
2492
2493 #ifdef DEBUG_WITH_FILES
2494 if (1) {
2495 librevenge::RVNGBinaryData file;
2496 input->seek(pos+8, librevenge::RVNG_SEEK_SET);
2497 input->readDataBlock(sz, file);
2498 static int volatile pictName = 0;
2499 libmwaw::DebugStream f;
2500 f << "PICT2-" << ++pictName << "." << name;
2501 libmwaw::Debug::dumpFile(file, f.str().c_str());
2502 }
2503 #endif
2504
2505 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2506 libmwaw::DebugStream f;
2507 f << "Entries(" << name << "):";
2508 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2509 ascFile.addPos(pos);
2510 ascFile.addNote(f.str().c_str());
2511 ascFile.skipZone(pos+8, endPos-1);
2512
2513 return true;
2514 }
2515
2516 ////////////////////////////////////////////////////////////
2517 // read bitmap picture
2518 ////////////////////////////////////////////////////////////
2519 bool ClarisWksGraph::readBitmapColorMap(std::vector<MWAWColor> &cMap)
2520 {
2521 cMap.resize(0);
2522 MWAWInputStreamPtr &input= m_parserState->m_input;
2523 long pos = input->tell();
2524 auto sz = long(input->readULong(4));
2525 long endPos = pos+4+sz;
2526 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2527 if (!sz) {
2528 ascFile.addPos(pos);
2529 ascFile.addNote("Nop");
2530 return true;
2531 }
2532 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2533 if (long(input->tell()) != endPos) {
2534 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapColorMap: file is too short\n"));
2535 return false;
2536 }
2537
2538 input->seek(pos+4, librevenge::RVNG_SEEK_SET);
2539 libmwaw::DebugStream f;
2540 f << "Entries(BitmapColor):";
2541 f << "unkn=" << input->readLong(4) << ",";
2542 auto maxColor = static_cast<int>(input->readLong(4));
2543 if (sz != 8+8*(long(maxColor)+1)) {
2544 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapColorMap: sz is odd\n"));
2545 return false;
2546 }
2547 cMap.resize(size_t(maxColor+1));
2548 for (int i = 0; i <= maxColor; i++) {
2549 auto id = static_cast<int>(input->readULong(2));
2550 if (id != i) {
2551 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapColorMap: find odd index : %d\n", i));
2552 return false;
2553 }
2554 unsigned char col[3];
2555 for (auto &c : col) c = static_cast<unsigned char>(input->readULong(2)>>8);
2556 cMap[size_t(i)] = MWAWColor(col[0], col[1], col[2]);
2557 }
2558
2559 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2560 ascFile.addPos(pos);
2561 ascFile.addNote(f.str().c_str());
2562
2563 return true;
2564 }
2565
2566 bool ClarisWksGraph::readBitmapData(ClarisWksGraphInternal::Bitmap &zone)
2567 {
2568 MWAWInputStreamPtr &input= m_parserState->m_input;
2569 long pos = input->tell();
2570 auto sz = long(input->readULong(4));
2571 long endPos = pos+4+sz;
2572 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2573 if (long(input->tell()) != endPos || !sz) {
2574 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapData: file is too short\n"));
2575 return false;
2576 }
2577
2578 long numPixels = zone.m_bitmapSize[0]*zone.m_bitmapSize[1];
2579 if (numPixels<=0) {
2580 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapData: unexpected empty size\n"));
2581 return false;
2582 }
2583
2584 auto numBytesPerPixel = int(sz/numPixels);
2585 int bitmapRowSize=zone.m_bitmapSize[0]*numBytesPerPixel;
2586 if (sz < numPixels) {
2587 int nHalfPixel=(zone.m_bitmapSize[0]+1)/2;
2588 for (int align=1; align <= 4; align*=2) {
2589 int diffToAlign=align==1 ? 0 : align-(nHalfPixel%align);
2590 if (diffToAlign==align) continue;
2591 if (sz == (nHalfPixel+diffToAlign)*zone.m_bitmapSize[1]) {
2592 bitmapRowSize=(nHalfPixel+diffToAlign);
2593 numBytesPerPixel=-2;
2594 break;
2595 }
2596 }
2597 }
2598 else if (sz > numBytesPerPixel*numPixels) {
2599 // check for different row alignment: 2 and 4
2600 for (int align=2; align <= 4; align*=2) {
2601 int diffToAlign=align-(zone.m_bitmapSize[0]%align);
2602 if (diffToAlign==align) continue;
2603 numPixels = (zone.m_bitmapSize[0]+diffToAlign)*zone.m_bitmapSize[1];
2604 if (numPixels<=0) continue;
2605 numBytesPerPixel = int(sz/numPixels);
2606 if (sz == numBytesPerPixel*numPixels) {
2607 bitmapRowSize=(zone.m_bitmapSize[0]+diffToAlign)*numBytesPerPixel;
2608 break;
2609 }
2610 }
2611 }
2612
2613 if (sz != bitmapRowSize*zone.m_bitmapSize[1]) {
2614 MWAW_DEBUG_MSG(("ClarisWksGraph::readBitmapData: unexpected size\n"));
2615 return false;
2616 }
2617 zone.m_numBytesPerPixel = numBytesPerPixel;
2618 zone.m_bitmapRowSize = bitmapRowSize;
2619 zone.m_entry.setBegin(pos+4);
2620 zone.m_entry.setEnd(endPos);
2621 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
2622 libmwaw::DebugStream f;
2623 f << "Entries(BitmapData):[" << numBytesPerPixel << "]";
2624 ascFile.addPos(pos);
2625 ascFile.addNote(f.str().c_str());
2626 ascFile.skipZone(pos+4, endPos-1);
2627
2628 return true;
2629 }
2630
2631 ////////////////////////////////////////////////////////////
2632 // update the group information
2633 ////////////////////////////////////////////////////////////
2634 void ClarisWksGraph::updateGroup(ClarisWksGraphInternal::Group &group) const
2635 {
2636 if (!group.m_zonesToSend.empty())
2637 return;
2638
2639 /* update the list of zone to be send (ie. remove remaining header/footer zone in not footer zone )
2640 + create a map to find linked zone: list of zone sharing the same text zone
2641 */
2642 bool isHeaderFooterBlock=group.isHeaderFooter() || group.m_position==ClarisWksStruct::DSET::P_SlideMaster;
2643 std::map<int, std::map<int, size_t> > idSIdCIdMap;
2644 for (size_t g = 0; g < group.m_zones.size(); g++) {
2645 auto child = group.m_zones[g];
2646 if (!child) continue;
2647 if (child->getType() == ClarisWksGraphInternal::Zone::T_Zone) {
2648 auto const &childZone = static_cast<ClarisWksGraphInternal::ZoneZone &>(*child);
2649 int zId = childZone.m_id;
2650 std::shared_ptr<ClarisWksStruct::DSET> zone=m_document.getZone(zId);
2651 if (!zone)
2652 continue;
2653 if (!isHeaderFooterBlock && zone->isHeaderFooter())
2654 continue;
2655 if (zId==1) {
2656 group.m_hasMainZone = true;
2657 continue;
2658 }
2659 if (idSIdCIdMap.find(zId)==idSIdCIdMap.end())
2660 idSIdCIdMap.insert(std::map<int, std::map<int, size_t> >::value_type(zId, std::map<int, size_t>()));
2661 auto &sIdCIdMap=idSIdCIdMap.find(zId)->second;
2662 if (sIdCIdMap.find(childZone.m_subId)!=sIdCIdMap.end()) {
2663 MWAW_DEBUG_MSG(("ClarisWksGraph::updateGroup: zone %d already find with subId %d\n",
2664 zId, childZone.m_subId));
2665 }
2666 else
2667 sIdCIdMap[childZone.m_subId]=g;
2668 }
2669 group.m_zonesToSend.push_back(child);
2670 if (g>=group.m_childs.size()) {
2671 MWAW_DEBUG_MSG(("ClarisWksGraph::updateGroup: the zones list is not in correspondance with the childs list\n"));
2672 continue;
2673 }
2674 child->m_box = group.m_childs[g].m_box;
2675 child->m_page = group.m_childs[g].m_page;
2676 }
2677 // update the linked frame data, ie. zone->m_frame*
2678 for (auto const &it : idSIdCIdMap) {
2679 auto const &sIdCIdMap=it.second;
2680 if (sIdCIdMap.size()<=1) continue;
2681 int frameId=m_state->m_frameId++;
2682 int frameSubId=0;
2683 for (auto cIt=sIdCIdMap.begin(); cIt!=sIdCIdMap.end();) {
2684 auto *child = static_cast<ClarisWksGraphInternal::ZoneZone *>(group.m_zones[cIt++->second].get());
2685 child->m_frameId=frameId;
2686 child->m_frameSubId=frameSubId++;
2687 child->m_frameLast=cIt==sIdCIdMap.end();
2688 }
2689 }
2690 }
2691
2692 ////////////////////////////////////////////////////////////
2693 // send data to the listener
2694 ////////////////////////////////////////////////////////////
2695 bool ClarisWksGraph::sendGroupChild(std::vector<std::shared_ptr<ClarisWksGraphInternal::Zone> > const &lChild, MWAWListenerPtr listener, MWAWVec2f const &leftTop)
2696 {
2697 if (!listener) {
2698 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroupChild: can not find the listener!!!\n"));
2699 return false;
2700 }
2701 for (auto const &child : lChild) {
2702 if (!child) continue;
2703 MWAWBox2f box=child->getBdBox();
2704 box=MWAWBox2f(box[0]+leftTop, box[1]+leftTop);
2705 auto type=child->getType();
2706 MWAWPosition pos(box[0], box.size(), librevenge::RVNG_POINT);
2707 pos.m_anchorTo=MWAWPosition::Page;
2708 if (type==ClarisWksGraphInternal::Zone::T_Zone) {
2709 int zId=child->getZoneId();
2710 auto dset=m_document.getZone(zId);
2711 if (!dset) continue;
2712 if (dset->m_fileType==4) {
2713 sendBitmap(zId, listener, pos);
2714 continue;
2715 }
2716 std::shared_ptr<MWAWSubDocument> doc(new ClarisWksGraphInternal::SubDocument(*this, m_parserState->m_input, zId));
2717 if (dset->m_fileType==1) // text box
2718 listener->insertTextBox(pos, doc, child->m_style);
2719 else if (dset->m_fileType==2 || dset->m_fileType==6) { // spreadsheet/table
2720 bool createFrame=listener->openFrame(pos, child->m_style);
2721 m_document.sendZone(zId, listener, pos);
2722 if (createFrame)
2723 listener->closeFrame();
2724 return true;
2725 }
2726 else if (dset->m_fileType==0) {
2727 if (listener->getType()==MWAWListener::Graphic)
2728 static_cast<MWAWGraphicListener *>(listener.get())->insertGroup(box, doc);
2729 else if (listener->getType()==MWAWListener::Presentation)
2730 static_cast<MWAWPresentationListener *>(listener.get())->insertGroup(box, doc);
2731 else {
2732 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroupChild: do not known how to send a group data!!!\n"));
2733 }
2734 }
2735 else {
2736 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroupChild: find unexpected zone type!!!\n"));
2737 }
2738 continue;
2739 }
2740 else if (type==ClarisWksGraphInternal::Zone::T_Shape) {
2741 auto const &shape=static_cast<ClarisWksGraphInternal::ZoneShape const &>(*child);
2742 MWAWGraphicStyle style(shape.m_style);
2743 if (shape.m_shape.m_type!=MWAWGraphicShape::Line)
2744 style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow();
2745 listener->insertShape(pos, shape.m_shape, style);
2746 }
2747 else if (type!=ClarisWksGraphInternal::Zone::T_DataBox) {
2748 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroupChild: find unexpected type!!!\n"));
2749 }
2750 }
2751 return true;
2752 }
2753
2754 bool ClarisWksGraph::sendPageChild(ClarisWksGraphInternal::Group &group)
2755 {
2756 group.m_parsed=true;
2757 MWAWListenerPtr listener=m_parserState->getMainListener();
2758 if (!listener) {
2759 MWAW_DEBUG_MSG(("ClarisWksGraph::sendPageChild: can not find the listener\n"));
2760 return false;
2761 }
2762 updateGroup(group);
2763 MWAWVec2f leftTop=72.0f*m_document.getPageLeftTop();
2764
2765 for (auto const &child : group.m_zonesToSend) {
2766 if (!child || child->m_page<=0) continue;
2767 if (child->getType() == ClarisWksGraphInternal::Zone::T_Zone) {
2768 auto dset=m_document.getZone(child->getZoneId());
2769 if (dset && dset->m_position==ClarisWksStruct::DSET::P_Main)
2770 continue;
2771 }
2772 MWAWBox2f const &box=child->m_box;
2773 MWAWPosition pos(box[0]+leftTop, box.size(), librevenge::RVNG_POINT);
2774 pos.setRelativePosition(MWAWPosition::Page);
2775 pos.setPage(child->m_page);
2776 pos.m_wrapping = child->m_style.getWrapping();
2777 pos.setOrder(-m_state->getOrdering());
2778 sendGroupChild(child, pos);
2779 }
2780 return true;
2781 }
2782
2783 bool ClarisWksGraph::sendGroup(ClarisWksGraphInternal::Group &group, MWAWPosition const &position)
2784 {
2785 group.m_parsed=true;
2786 MWAWListenerPtr listener=m_parserState->getMainListener();
2787 if (!listener) {
2788 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroup: can not find the listener\n"));
2789 return false;
2790 }
2791 updateGroup(group);
2792 bool isSlide=group.isSlide() || group.m_position == ClarisWksStruct::DSET::P_GraphicMaster;
2793 bool mainGroup = group.m_position == ClarisWksStruct::DSET::P_Main || isSlide;
2794 MWAWVec2f leftTop(0,0);
2795 float textHeight = 0.0;
2796 if (mainGroup)
2797 leftTop = 72.0f*m_document.getPageLeftTop();
2798 textHeight = 72.0f*float(m_mainParser->getFormLength());
2799
2800 libmwaw::SubDocumentType inDocType;
2801 if (!listener->isSubDocumentOpened(inDocType))
2802 inDocType = libmwaw::DOC_NONE;
2803 MWAWPosition::AnchorTo suggestedAnchor = MWAWPosition::Char;
2804 if (isSlide)
2805 suggestedAnchor = MWAWPosition::Page;
2806 else {
2807 switch (inDocType) {
2808 case libmwaw::DOC_TEXT_BOX:
2809 suggestedAnchor=MWAWPosition::Char;
2810 break;
2811 case libmwaw::DOC_CHART:
2812 case libmwaw::DOC_CHART_ZONE:
2813 case libmwaw::DOC_HEADER_FOOTER:
2814 case libmwaw::DOC_NOTE:
2815 suggestedAnchor=MWAWPosition::Frame;
2816 break;
2817 case libmwaw::DOC_SHEET:
2818 case libmwaw::DOC_TABLE:
2819 case libmwaw::DOC_COMMENT_ANNOTATION:
2820 suggestedAnchor=MWAWPosition::Char;
2821 break;
2822 case libmwaw::DOC_GRAPHIC_GROUP:
2823 suggestedAnchor=MWAWPosition::Page;
2824 break;
2825 #if !defined(__clang__)
2826 default:
2827 #endif
2828 case libmwaw::DOC_NONE:
2829 suggestedAnchor= mainGroup ? MWAWPosition::Page : MWAWPosition::Char;
2830 break;
2831 }
2832 }
2833 #if 0
2834 // CHECKME
2835 if (0 && position.m_anchorTo==MWAWPosition::Unknown) {
2836 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroup: position is not set\n"));
2837 }
2838 #endif
2839 if (!mainGroup && canSendAsGraphic(group)) {
2840 MWAWBox2f box=group.m_box;
2841 MWAWGraphicEncoder graphicEncoder;
2842 MWAWGraphicListenerPtr graphicListener(new MWAWGraphicListener(*m_parserState, box, &graphicEncoder));
2843 graphicListener->startDocument();
2844 sendGroupChild(group.m_zonesToSend, graphicListener, leftTop);
2845 graphicListener->endDocument();
2846 MWAWEmbeddedObject picture;
2847 if (!graphicEncoder.getBinaryResult(picture))
2848 return true;
2849 MWAWPosition pos(position);
2850 //pos.setOrigin(box[0]);
2851 if (pos.size()[0]<=0 || pos.size()[1]<=0)
2852 pos.setSize(box.size());
2853 pos.m_wrapping = MWAWPosition::WBackground;
2854 if (pos.m_anchorTo==MWAWPosition::Unknown) {
2855 pos=MWAWPosition(box[0], box.size(), librevenge::RVNG_POINT);
2856 pos.setRelativePosition(suggestedAnchor);
2857 if (suggestedAnchor == MWAWPosition::Page) {
2858 int pg = group.m_page > 0 ? group.m_page : 1;
2859 MWAWVec2f orig = pos.origin()+leftTop;
2860 pos.setPagePos(pg, orig);
2861 }
2862 else if (suggestedAnchor == MWAWPosition::Char)
2863 pos.setOrigin(MWAWVec2f(0,0));
2864 }
2865 listener->insertPicture(pos, picture);
2866 return true;
2867 }
2868 if (group.m_zonesToSend.size() > 1 &&
2869 (position.m_anchorTo==MWAWPosition::Char ||
2870 position.m_anchorTo==MWAWPosition::CharBaseLine)) {
2871 // we need to a frame, ...
2872 MWAWPosition lPos;
2873 lPos.m_anchorTo=MWAWPosition::Paragraph;
2874 MWAWSubDocumentPtr doc(new ClarisWksGraphInternal::SubDocument(*this, m_parserState->m_input, group.m_id, lPos));
2875 MWAWGraphicStyle style(MWAWGraphicStyle::emptyStyle());
2876 style.m_backgroundOpacity=0;
2877 MWAWPosition pos(position);
2878 pos.m_wrapping=MWAWPosition::WForeground;
2879 listener->insertTextBox(pos, doc, style);
2880 return true;
2881 }
2882
2883 /* first sort the different zone: ie. we must first send the page block, then the main zone */
2884 std::vector<std::shared_ptr<ClarisWksGraphInternal::Zone> > listJobs[2];
2885 for (auto const &child : group.m_zonesToSend) {
2886 if (!child) continue;
2887 if (position.m_anchorTo==MWAWPosition::Unknown && suggestedAnchor == MWAWPosition::Page) {
2888 MWAWVec2f RB = MWAWVec2f(child->m_box[1])+leftTop;
2889 if (RB[1] >= textHeight || listener->isSectionOpened()) {
2890 listJobs[1].push_back(child);
2891 continue;
2892 }
2893 }
2894 if (child->getType() == ClarisWksGraphInternal::Zone::T_Zone) {
2895 std::shared_ptr<ClarisWksStruct::DSET> dset=m_document.getZone(child->getZoneId());
2896 if (dset && dset->m_position==ClarisWksStruct::DSET::P_Main) {
2897 listJobs[1].push_back(child);
2898 continue;
2899 }
2900 }
2901 listJobs[0].push_back(child);
2902 }
2903 for (int st = 0; st < 2; st++) {
2904 if (st == 1) {
2905 if (group.m_hasMainZone)
2906 m_document.sendZone(1);
2907 suggestedAnchor = MWAWPosition::Page;
2908 }
2909 size_t numJobs=listJobs[st].size();
2910 for (size_t g = 0; g < numJobs; g++) {
2911 MWAWBox2f box;
2912 std::vector<std::shared_ptr<ClarisWksGraphInternal::Zone> > groupList;
2913 int page = 0;
2914 size_t lastOk=g;
2915
2916 if (st==0 && !mainGroup) {
2917 for (size_t h = g; h < numJobs; ++h) {
2918 auto child = listJobs[st][h];
2919 if (!child) continue;
2920 if (groupList.empty()) page=child->m_page;
2921 else if (page != child->m_page) break;
2922 if (!child->canBeSendAsGraphic()) break;
2923 if (child->getType()==ClarisWksGraphInternal::Zone::T_Zone &&
2924 !m_document.canSendZoneAsGraphic(child->getZoneId()))
2925 break;
2926 if (groupList.empty())
2927 box=child->m_box;
2928 else
2929 box=box.getUnion(child->m_box);
2930 groupList.push_back(child);
2931 lastOk=h;
2932 }
2933 }
2934 if (groupList.empty()) {
2935 auto child = listJobs[st][g];
2936 if (!child) continue;
2937 groupList.push_back(child);
2938 }
2939 if (groupList.size()<= 1) {
2940 if (!groupList[0]) continue;
2941 box = groupList[0]->m_box;
2942 page = groupList[0]->m_page;
2943 }
2944 MWAWPosition pos(position);
2945 pos.setOrder(-m_state->getOrdering());
2946 pos.setOrigin(box[0]);
2947 pos.setSize(box.size());
2948 pos.setUnit(librevenge::RVNG_POINT);
2949 pos.m_wrapping = MWAWPosition::WBackground;
2950 if (pos.m_anchorTo==MWAWPosition::Unknown) {
2951 pos=MWAWPosition(box[0], box.size(), librevenge::RVNG_POINT);
2952 pos.setRelativePosition(suggestedAnchor);
2953 if (suggestedAnchor == MWAWPosition::Page) {
2954 int pg = page > 0 ? page : 1;
2955 MWAWVec2f orig = pos.origin()+leftTop;
2956 pos.setPagePos(pg, orig);
2957 }
2958 else if (st==1 || suggestedAnchor == MWAWPosition::Char)
2959 pos.setOrigin(MWAWVec2f(0,0));
2960 }
2961 else if (isSlide && pos.m_anchorTo==MWAWPosition::Page) {
2962 int pg = page > 0 ? page : 1;
2963 MWAWVec2f orig = pos.origin()+leftTop;
2964 pos.setPagePos(pg, orig);
2965 }
2966 // groupList can not be empty
2967 if (groupList.size() <= 1) {
2968 libmwaw::SubDocumentType subDocType;
2969 if (pos.m_anchorTo==MWAWPosition::Paragraph && group.m_position == ClarisWksStruct::DSET::P_Frame &&
2970 groupList[0]->getType()!=ClarisWksGraphInternal::Zone::T_Zone && listener->isSubDocumentOpened(subDocType))
2971 pos.m_anchorTo=MWAWPosition::Frame;
2972 sendGroupChild(groupList[0], pos);
2973 continue;
2974 }
2975 g=lastOk;
2976
2977 MWAWGraphicEncoder graphicEncoder;
2978 MWAWGraphicListenerPtr graphicListener(new MWAWGraphicListener(*m_parserState, box, &graphicEncoder));
2979 graphicListener->startDocument();
2980 sendGroupChild(groupList, graphicListener, leftTop);
2981 graphicListener->endDocument();
2982 MWAWEmbeddedObject picture;
2983 if (graphicEncoder.getBinaryResult(picture)) {
2984 MWAWGraphicStyle style(MWAWGraphicStyle::emptyStyle());
2985 style.m_backgroundOpacity=0;
2986 listener->insertPicture(pos, picture, style);
2987 }
2988 }
2989 }
2990 return true;
2991 }
2992
2993 bool ClarisWksGraph::sendGroupChild(std::shared_ptr<ClarisWksGraphInternal::Zone> child, MWAWPosition pos)
2994 {
2995 if (!child) return false;
2996 MWAWListenerPtr listener=m_parserState->getMainListener();
2997 if (!listener) {
2998 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroupChild: can not find the listener\n"));
2999 return false;
3000 }
3001 auto const &cStyle = child->m_style;
3002 pos.m_wrapping=cStyle.getWrapping();
3003 auto type = child->getType();
3004 if (type==ClarisWksGraphInternal::Zone::T_Picture)
3005 return sendPicture(static_cast<ClarisWksGraphInternal::ZonePict &>(*child), pos);
3006 if (type==ClarisWksGraphInternal::Zone::T_Shape)
3007 return sendShape(static_cast<ClarisWksGraphInternal::ZoneShape &>(*child), pos);
3008 if (type==ClarisWksGraphInternal::Zone::T_DataBox || type==ClarisWksGraphInternal::Zone::T_Chart ||
3009 type==ClarisWksGraphInternal::Zone::T_Unknown)
3010 return true;
3011 if (type!=ClarisWksGraphInternal::Zone::T_Zone) {
3012 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroupChild: find unknown zone\n"));
3013 return false;
3014 }
3015
3016 auto const &childZone = static_cast<ClarisWksGraphInternal::ZoneZone &>(*child);
3017 int zId = childZone.m_id;
3018 auto dset=m_document.getZone(zId);
3019 // if this is a group, try to send it as a picture
3020 bool isLinked=childZone.isLinked();
3021 bool isGroup = dset && dset->m_fileType==0;
3022 if (!isLinked && isGroup && canSendGroupAsGraphic(zId))
3023 return sendGroup(zId, MWAWListenerPtr(), pos);
3024 if (!isLinked && dset && dset->m_fileType==4)
3025 return sendBitmap(zId, MWAWListenerPtr(), pos);
3026 if (!isLinked && (cStyle.hasPattern() || cStyle.hasGradient()) &&
3027 (dset && dset->m_fileType==1) && m_document.canSendZoneAsGraphic(zId)) {
3028 MWAWBox2f box=MWAWBox2f(MWAWVec2f(0,0), childZone.m_box.size());
3029 MWAWGraphicEncoder graphicEncoder;
3030 MWAWGraphicListener graphicListener(*m_parserState, box, &graphicEncoder);
3031 graphicListener.startDocument();
3032 std::shared_ptr<MWAWSubDocument> doc(new ClarisWksGraphInternal::SubDocument(*this, m_parserState->m_input, zId));
3033 MWAWPosition textPos(box[0], box.size(), librevenge::RVNG_POINT);
3034 textPos.m_anchorTo=MWAWPosition::Page;
3035 textPos.m_wrapping=pos.m_wrapping;
3036 graphicListener.insertTextBox(textPos, doc, cStyle);
3037 graphicListener.endDocument();
3038 MWAWEmbeddedObject picture;
3039 if (graphicEncoder.getBinaryResult(picture))
3040 listener->insertPicture(pos, picture);
3041 return true;
3042 }
3043 // now check if we need to create a frame
3044 auto cPos=dset ? dset->m_position : ClarisWksStruct::DSET::P_Unknown;
3045 bool createFrame=
3046 cPos == ClarisWksStruct::DSET::P_Frame || cPos == ClarisWksStruct::DSET::P_Table ||
3047 (cPos == ClarisWksStruct::DSET::P_Unknown && pos.m_anchorTo == MWAWPosition::Page &&
3048 (!dset || dset->m_fileType!=2));
3049 if (!isLinked && childZone.m_subId) {
3050 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroup: find odd subs zone\n"));
3051 return false;
3052 }
3053 MWAWGraphicStyle style=MWAWGraphicStyle::emptyStyle();
3054 if (dset && dset->m_fileType==1) { // checkme: use style for textbox
3055 MWAWColor color;
3056 if (cStyle.hasSurfaceColor() && getSurfaceColor(cStyle, color))
3057 style.setBackgroundColor(color);
3058 else
3059 style.m_backgroundOpacity=0;
3060 if (cStyle.hasLine()) {
3061 MWAWBorder border;
3062 border.m_color=cStyle.m_lineColor;
3063 style.setBorders(15, border);
3064 // extend the frame to add border
3065 auto extend = float(cStyle.m_lineWidth*0.85f);
3066 pos.setOrigin(pos.origin()-MWAWVec2f(extend,extend));
3067 pos.setSize(pos.size()+2.0f*MWAWVec2f(extend,extend));
3068 }
3069 }
3070 else
3071 style.m_backgroundOpacity=0;
3072 bool isPresentation=listener->getType()==MWAWListener::Presentation;
3073 if ((createFrame && !isPresentation) ||
3074 (isPresentation && dset && dset->m_fileType==1)) {
3075 childZone.addFrameName(style);
3076 std::shared_ptr<MWAWSubDocument> doc;
3077 if (!isLinked || childZone.m_subId==0) {
3078 MWAWPosition childPos;
3079 childPos.setUnit(librevenge::RVNG_POINT);
3080 if (dset && dset->m_fileType==0) {
3081 childPos.setRelativePosition(MWAWPosition::Paragraph);
3082 pos.m_wrapping=MWAWPosition::WBackground;
3083 style.m_backgroundOpacity=0;
3084 }
3085 doc.reset(new ClarisWksGraphInternal::SubDocument(*this, m_parserState->m_input, zId, childPos));
3086 }
3087 if (!isLinked && dset && dset->m_fileType==1 && pos.size()[1]>0) // use min-height for text
3088 pos.setSize(MWAWVec2f(pos.size()[0],-pos.size()[1]));
3089 listener->insertTextBox(pos, doc, style);
3090 return true;
3091 }
3092 if (dset && dset->m_fileType==2) { // spreadsheet
3093 MWAWBox2f box=MWAWBox2f(MWAWVec2f(0,0), childZone.m_box.size());
3094 MWAWSpreadsheetEncoder spreadsheetEncoder;
3095 auto *spreadsheetListener=new MWAWSpreadsheetListener(*m_parserState, box, &spreadsheetEncoder);
3096 MWAWListenerPtr sheetListener(spreadsheetListener);
3097 spreadsheetListener->startDocument();
3098 m_document.sendZone(zId, sheetListener);
3099 spreadsheetListener->endDocument();
3100 MWAWEmbeddedObject object;
3101 if (spreadsheetEncoder.getBinaryResult(object))
3102 listener->insertPicture(pos, object);
3103 return true;
3104 }
3105 if (isPresentation && dset && dset->m_fileType==6) { // table
3106 createFrame=listener->openFrame(pos, style);
3107 m_document.sendZone(zId, listener, pos);
3108 if (createFrame)
3109 listener->closeFrame();
3110 return true;
3111 }
3112 if (isPresentation && createFrame) {
3113 std::shared_ptr<MWAWSubDocument> doc(new ClarisWksGraphInternal::SubDocument(*this, m_parserState->m_input, zId));
3114 static_cast<MWAWPresentationListener *>(listener.get())->insertGroup(childZone.m_box, doc);
3115 return true;
3116 }
3117 return m_document.sendZone(zId, listener, pos);
3118 }
3119
3120 ////////////////////////////////////////////////////////////
3121 // basic shape, bitmap, pict
3122 ////////////////////////////////////////////////////////////
3123 bool ClarisWksGraph::sendShape(ClarisWksGraphInternal::ZoneShape const &pict, MWAWPosition pos)
3124 {
3125 MWAWListenerPtr listener=m_parserState->getMainListener();
3126 if (!listener) return true;
3127 if (pos.size()[0] < 0 || pos.size()[1] < 0)
3128 pos.setSize(pict.getBdBox().size());
3129
3130 MWAWGraphicStyle pStyle(pict.m_style);
3131 if (pict.m_shape.m_type!=MWAWGraphicShape::Line)
3132 pStyle.m_arrows[0]=pStyle.m_arrows[1]=MWAWGraphicStyle::Arrow();
3133 pos.setOrigin(pos.origin()-MWAWVec2f(2,2));
3134 pos.setSize(pos.size()+MWAWVec2f(4,4));
3135 listener->insertShape(pos, pict.m_shape, pStyle);
3136 return true;
3137 }
3138
3139 bool ClarisWksGraph::canSendBitmapAsGraphic(int number) const
3140 {
3141 if (m_parserState->m_kind == MWAWDocument::MWAW_K_PRESENTATION)
3142 return false;
3143 auto iter = m_state->m_bitmapMap.find(number);
3144 if (iter == m_state->m_bitmapMap.end() || !iter->second) {
3145 MWAW_DEBUG_MSG(("ClarisWksGraph::canSendBitmapAsGraphic: can not find bitmap %d\n", number));
3146 return false;
3147 }
3148 return true;
3149 }
3150
3151 bool ClarisWksGraph::sendDatabasePictZone(int pictId, MWAWListenerPtr listener, MWAWPosition const &pos)
3152 {
3153 auto iter = m_state->m_databaseMap.find(pictId);
3154 if (iter == m_state->m_databaseMap.end() || !iter->second) {
3155 MWAW_DEBUG_MSG(("ClarisWksGraph::sendDatabasePictZone: can not find zone %d\n", pictId));
3156 return false;
3157 }
3158 if (!listener)
3159 listener=m_parserState->getMainListener();
3160 if (!listener) {
3161 MWAW_DEBUG_MSG(("ClarisWksGraph::sendDatabasePictZone: can not find a listener\n"));
3162 return false;
3163 }
3164 return sendPicture(*iter->second, pos);
3165 }
3166
3167 bool ClarisWksGraph::sendBitmap(int number, MWAWListenerPtr listener, MWAWPosition const &pos)
3168 {
3169 auto iter = m_state->m_bitmapMap.find(number);
3170 if (iter == m_state->m_bitmapMap.end() || !iter->second) {
3171 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: can not find bitmap %d\n", number));
3172 return false;
3173 }
3174 if (!listener)
3175 listener=m_parserState->getMainListener();
3176 if (!listener) {
3177 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: can not find a listener\n"));
3178 return false;
3179 }
3180 return sendBitmap(*iter->second, *listener, pos);
3181 }
3182
3183 bool ClarisWksGraph::sendBitmap(ClarisWksGraphInternal::Bitmap &bitmap, MWAWListener &listener, MWAWPosition pos)
3184 {
3185 bitmap.m_parsed=true;
3186 if (!bitmap.m_entry.valid() || !bitmap.m_numBytesPerPixel)
3187 return false;
3188 int bytesPerPixel = bitmap.m_numBytesPerPixel;
3189 if (bytesPerPixel<0 && (bytesPerPixel!=-2 && bytesPerPixel!=-4)) {
3190 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: unknown group of color\n"));
3191 return false;
3192 }
3193 auto numColors = int(bitmap.m_colorMap.size());
3194 std::shared_ptr<MWAWPictBitmap> bmap;
3195
3196 MWAWPictBitmapIndexed *bmapIndexed = nullptr;
3197 MWAWPictBitmapColor *bmapColor = nullptr;
3198 bool indexed = false;
3199 if (numColors > 2) {
3200 bmapIndexed = new MWAWPictBitmapIndexed(bitmap.m_bitmapSize);
3201 bmapIndexed->setColors(bitmap.m_colorMap);
3202 bmap.reset(bmapIndexed);
3203 indexed = true;
3204 }
3205 else {
3206 if (bytesPerPixel<0) {
3207 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: unexpected mode for compressed bitmap. Bitmap ignored.\n"));
3208 return false;
3209 }
3210 bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_bitmapSize)));
3211 }
3212
3213 bool const isCompressed = bytesPerPixel<0;
3214 int const numColorByData= isCompressed ? -bytesPerPixel : 1;
3215 long const colorMask= !isCompressed ? 0 : numColorByData==2 ? 0xF : 0x3;
3216 int const numColorBytes = isCompressed ? 8/numColorByData : 8*bytesPerPixel;
3217 //! let go
3218 MWAWInputStreamPtr &input= m_parserState->m_input;
3219 input->seek(bitmap.m_entry.begin(), librevenge::RVNG_SEEK_SET);
3220 for (int r = 0; r < bitmap.m_bitmapSize[1]; r++) {
3221 long rPos=input->tell();
3222 int numRead=0;
3223 long read=0;
3224 for (int c = 0; c < bitmap.m_bitmapSize[0]; c++) {
3225 if (numRead==0) {
3226 read=long(input->readULong(isCompressed ? 1 : bytesPerPixel));
3227 numRead=numColorByData;
3228 }
3229 --numRead;
3230 long val=!isCompressed ? read : (read>>(numColorBytes*numRead))&colorMask;
3231 if (indexed) {
3232 bmapIndexed->set(c,r,static_cast<int>(val));
3233 continue;
3234 }
3235 switch (bytesPerPixel) {
3236 case 1:
3237 bmapColor->set(c,r, MWAWColor(static_cast<unsigned char>(val),static_cast<unsigned char>(val),static_cast<unsigned char>(val)));
3238 break;
3239 case 2: // rgb compressed ?
3240 bmapColor->set(c,r, MWAWColor(static_cast<unsigned char>(((val>>10)&0x1F) << 3),static_cast<unsigned char>(((val>>5)&0x1F) << 3),static_cast<unsigned char>(((val>>0)&0x1F) << 3)));
3241 break;
3242 case 4:
3243 bmapColor->set(c,r, MWAWColor(static_cast<uint32_t>(val)|0xFF000000)); // checkme
3244 break;
3245 default: {
3246 static bool first = true;
3247 if (first) {
3248 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: unknown data size\n"));
3249 first = false;
3250 }
3251 break;
3252 }
3253 }
3254 }
3255 input->seek(rPos+bitmap.m_bitmapRowSize, librevenge::RVNG_SEEK_SET);
3256 }
3257
3258 MWAWEmbeddedObject picture;
3259 if (!bmap->getBinary(picture)) return false;
3260 if (pos.size()[0] <= 0 || pos.size()[1] <= 0) {
3261 pos.m_anchorTo=MWAWPosition::Char;
3262 if (m_parserState->m_kind==MWAWDocument::MWAW_K_PAINT)// fixme
3263 pos.setSize(MWAWVec2f(0.9f*float(m_mainParser->getPageWidth()),
3264 0.9f*float(m_mainParser->getPageLength())));
3265 else {
3266 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: can not find bitmap size\n"));
3267 pos.setSize(MWAWVec2f(70,70));
3268 }
3269 }
3270 if (pos.m_anchorTo==MWAWPosition::Unknown) {
3271 MWAW_DEBUG_MSG(("ClarisWksGraph::sendBitmap: anchor is not set, revert to char\n"));
3272 pos.m_anchorTo=MWAWPosition::Char;
3273 }
3274 listener.insertPicture(pos, picture);
3275 return true;
3276 }
3277
3278 bool ClarisWksGraph::sendPicture(ClarisWksGraphInternal::ZonePict &pict, MWAWPosition pos)
3279 {
3280 bool send = false;
3281 bool posOk = pos.size()[0] > 0 && pos.size()[1] > 0;
3282 MWAWInputStreamPtr &input= m_parserState->m_input;
3283 MWAWListenerPtr listener=m_parserState->getMainListener();
3284 for (auto const &entry : pict.m_entries) {
3285 if (!entry.valid())
3286 continue;
3287 if (!posOk) {
3288 MWAWVec2f sz=pict.m_box.size();
3289 // recheck that all is ok now
3290 if (sz[0]<0) sz[0]=0;
3291 if (sz[1]<0) sz[1]=0;
3292 pos.setSize(sz);
3293 }
3294 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
3295
3296 switch (pict.getSubType()) {
3297 case ClarisWksGraphInternal::Zone::T_Movie:
3298 case ClarisWksGraphInternal::Zone::T_Pict: {
3299 std::shared_ptr<MWAWPict> thePict(MWAWPictData::get(input, static_cast<int>(entry.length())));
3300 if (thePict) {
3301 if (!send && listener) {
3302 MWAWEmbeddedObject picture;
3303 if (thePict->getBinary(picture))
3304 listener->insertPicture(pos, picture);
3305 }
3306 send = true;
3307 }
3308 break;
3309 }
3310 case ClarisWksGraphInternal::Zone::T_Line:
3311 case ClarisWksGraphInternal::Zone::T_Rect:
3312 case ClarisWksGraphInternal::Zone::T_RectOval:
3313 case ClarisWksGraphInternal::Zone::T_Oval:
3314 case ClarisWksGraphInternal::Zone::T_Arc:
3315 case ClarisWksGraphInternal::Zone::T_Poly:
3316 case ClarisWksGraphInternal::Zone::T_Zone:
3317 case ClarisWksGraphInternal::Zone::T_Zone2:
3318 case ClarisWksGraphInternal::Zone::T_Shape:
3319 case ClarisWksGraphInternal::Zone::T_Picture:
3320 case ClarisWksGraphInternal::Zone::T_Chart:
3321 case ClarisWksGraphInternal::Zone::T_DataBox:
3322 case ClarisWksGraphInternal::Zone::T_Unknown:
3323 case ClarisWksGraphInternal::Zone::T_QTim:
3324 #if !defined(__clang__)
3325 default:
3326 #endif
3327 if (!send && listener) {
3328 librevenge::RVNGBinaryData data;
3329 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
3330 input->readDataBlock(entry.length(), data);
3331 listener->insertPicture(pos, MWAWEmbeddedObject(data, "image/pict"));
3332 }
3333 send = true;
3334 break;
3335 }
3336
3337 #ifdef DEBUG_WITH_FILES
3338 m_parserState->m_asciiFile.skipZone(entry.begin(), entry.end()-1);
3339 librevenge::RVNGBinaryData file;
3340 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
3341 input->readDataBlock(entry.length(), file);
3342 static int volatile pictName = 0;
3343 libmwaw::DebugStream f;
3344 f << "PICT-" << ++pictName;
3345 libmwaw::Debug::dumpFile(file, f.str().c_str());
3346 #endif
3347 }
3348 return send;
3349 }
3350
3351 ////////////////////////////////////////////////////////////
3352 // interface send function
3353 ////////////////////////////////////////////////////////////
3354 bool ClarisWksGraph::canSendGroupAsGraphic(int number) const
3355 {
3356 auto iter = m_state->m_groupMap.find(number);
3357 if (iter == m_state->m_groupMap.end() || !iter->second)
3358 return false;
3359 return canSendAsGraphic(*iter->second);
3360 }
3361
3362 bool ClarisWksGraph::canSendAsGraphic(ClarisWksGraphInternal::Group &group) const
3363 {
3364 if (m_parserState->m_kind == MWAWDocument::MWAW_K_PRESENTATION)
3365 return false;
3366 updateGroup(group);
3367 if ((group.m_position != ClarisWksStruct::DSET::P_Frame && group.m_position != ClarisWksStruct::DSET::P_Unknown)
3368 || group.m_page <= 0)
3369 return false;
3370 size_t numZones = group.m_zonesToSend.size();
3371 for (size_t g = 0; g < numZones; g++) {
3372 auto child = group.m_zonesToSend[g];
3373 if (!child) continue;
3374 if (!child->canBeSendAsGraphic()) return false;
3375 if (child->getType()==ClarisWksGraphInternal::Zone::T_Zone &&
3376 !m_document.canSendZoneAsGraphic(child->getZoneId()))
3377 return false;
3378 }
3379 return true;
3380 }
3381
3382 bool ClarisWksGraph::sendMaster(int pg)
3383 {
3384 if (m_parserState->m_kind != MWAWDocument::MWAW_K_DRAW || m_state->m_masterId<=0)
3385 return true;
3386 auto iter = m_state->m_groupMap.find(m_state->m_masterId);
3387 if (iter == m_state->m_groupMap.end() || !iter->second) {
3388 MWAW_DEBUG_MSG(("ClarisWksGraph::sendMaster: can not find the group %d\n", m_state->m_masterId));
3389 return false;
3390 }
3391 auto group = iter->second;
3392 group->m_parsed=true;
3393 // time to update the child page
3394 for (auto &zone : group->m_zones) {
3395 std::shared_ptr<ClarisWksGraphInternal::Zone> child = zone;
3396 if (!child) continue;
3397 if (child->getType() == ClarisWksGraphInternal::Zone::T_Zone) {
3398 auto dset=m_document.getZone(child->getZoneId());
3399 if (dset && dset->isHeaderFooter()) {
3400 zone.reset();
3401 MWAW_DEBUG_MSG(("ClarisWksGraph::sendMaster: remove some header footer from master\n"));
3402 continue;
3403 }
3404 }
3405 child->m_page = pg+1;
3406 }
3407 return sendPageChild(*group);
3408 }
3409
3410 bool ClarisWksGraph::sendPageGraphics(int groupId)
3411 {
3412 auto iter = m_state->m_groupMap.find(groupId);
3413 if (iter == m_state->m_groupMap.end() || !iter->second) {
3414 MWAW_DEBUG_MSG(("ClarisWksGraph::sendPageGraphics: can not find the group %d\n", groupId));
3415 return false;
3416 }
3417 auto group = iter->second;
3418 if (group->m_position==ClarisWksStruct::DSET::P_GraphicMaster) return true;
3419 group->m_parsed=true;
3420 return sendPageChild(*group);
3421 }
3422
3423 bool ClarisWksGraph::sendGroup(int number, MWAWListenerPtr listener, MWAWPosition const &position)
3424 {
3425 auto iter = m_state->m_groupMap.find(number);
3426 if (iter == m_state->m_groupMap.end() || !iter->second)
3427 return false;
3428 auto group = iter->second;
3429 group->m_parsed=true;
3430 if (listener && (listener->getType()==MWAWListener::Graphic || listener->getType()==MWAWListener::Presentation)) {
3431 MWAWVec2f leftTop(0,0);
3432 if (group->isSlide())
3433 leftTop = 72.0f*m_document.getPageLeftTop();
3434 return sendGroupChild(group->m_zonesToSend, listener, leftTop);
3435 }
3436 if (!m_parserState->getMainListener()) {
3437 MWAW_DEBUG_MSG(("ClarisWksGraph::sendGroup: can not find the listener\n"));
3438 return false;
3439 }
3440 return sendGroup(*group, position);
3441 }
3442
3443 void ClarisWksGraph::flushExtra()
3444 {
3445 std::shared_ptr<MWAWListener> listener=m_parserState->getMainListener();
3446 if (!listener) return;
3447 for (auto const &iter : m_state->m_groupMap) {
3448 auto const &zone = iter.second;
3449 // can be some footer print on the last page or an unused header/footer
3450 if (!zone || zone->m_parsed || zone->isHeaderFooter())
3451 continue;
3452 static bool first=true;
3453 if (first) {
3454 MWAW_DEBUG_MSG(("ClarisWksGraph::flushExtra: find some extra graph %d\n", zone->m_id));
3455 first=false;
3456 }
3457 listener->insertEOL();
3458 MWAWPosition pos(MWAWVec2f(0,0),MWAWVec2f(0,0),librevenge::RVNG_POINT);
3459 pos.setRelativePosition(MWAWPosition::Char);
3460 sendGroup(iter.first, MWAWListenerPtr(), pos);
3461 }
3462 }
3463
3464 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: