Debian Codegraph @

src/lib/HanMacWrdKGraph.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 "MWAWCell.hxx"
45 #include "MWAWFont.hxx"
46 #include "MWAWFontConverter.hxx"
47 #include "MWAWGraphicEncoder.hxx"
48 #include "MWAWGraphicListener.hxx"
49 #include "MWAWGraphicShape.hxx"
50 #include "MWAWGraphicStyle.hxx"
51 #include "MWAWTextListener.hxx"
52 #include "MWAWPictMac.hxx"
53 #include "MWAWPosition.hxx"
54 #include "MWAWSubDocument.hxx"
55 #include "MWAWTable.hxx"
56
57 #include "HanMacWrdKParser.hxx"
58
59 #include "HanMacWrdKGraph.hxx"
60
61 #include "libmwaw_internal.hxx"
62
63 /** Internal: the structures of a HanMacWrdKGraph */
64 namespace HanMacWrdKGraphInternal
65 {
66 ////////////////////////////////////////
67 //! Internal: the frame header of a HanMacWrdKGraph
68 struct Frame {
69 //! constructor
70 Frame()
71 : m_type(-1)
72 , m_fileId(-1)
73 , m_fileSubId(-1)
74 , m_id(-1)
75 , m_page(0)
76 , m_pos()
77 , m_baseline(0.f)
78 , m_posFlags(0)
79 , m_style()
80 , m_borderType(0)
81 , m_inGroup(false)
82 , m_parsed(false)
83 , m_extra("")
84 {
85 }
86 Frame(Frame const &)=default;
87 //! destructor
88 virtual ~Frame();
89 //! return the frame bdbox
90 MWAWBox2f getBdBox() const
91 {
92 MWAWVec2f minPt(m_pos[0][0], m_pos[0][1]);
93 MWAWVec2f maxPt(m_pos[1][0], m_pos[1][1]);
94 for (int c=0; c<2; ++c) {
95 if (m_pos.size()[c]>=0) continue;
96 minPt[c]=m_pos[1][c];
97 maxPt[c]=m_pos[0][c];
98 }
99 return MWAWBox2f(minPt,maxPt);
100 }
101 //! operator<<
102 friend std::ostream &operator<<(std::ostream &o, Frame const &grph);
103 //! the graph type
104 int m_type;
105 //! the file id
106 long m_fileId;
107 //! the file sub id
108 long m_fileSubId;
109 //! the local id
110 int m_id;
111 //! the page
112 int m_page;
113 //! the position
114 MWAWBox2f m_pos;
115 //! the baseline
116 float m_baseline;
117 //! the graph anchor flags
118 int m_posFlags;
119 //! the style
120 MWAWGraphicStyle m_style;
121 //! the border type
122 int m_borderType;
123 //! the border default size (before using width), 0 means Top, other unknown
124 MWAWVec2f m_borders[4];
125 //! true if the frame is a child of a group
126 bool m_inGroup;
127 //! true if we have send the data
128 mutable bool m_parsed;
129 //! an extra string
130 std::string m_extra;
131 };
132
133 Frame::~Frame()
134 {
135 }
136
137 std::ostream &operator<<(std::ostream &o, Frame const &grph)
138 {
139 switch (grph.m_type) {
140 case 0: // main text
141 break;
142 case 1:
143 o << "header,";
144 break;
145 case 2:
146 o << "footer,";
147 break;
148 case 3:
149 o << "footnote[frame],";
150 break;
151 case 4:
152 o << "textbox,";
153 break;
154 case 6:
155 o << "picture,";
156 break;
157 case 8:
158 o << "basicGraphic,";
159 break;
160 case 9:
161 o << "table,";
162 break;
163 case 10:
164 o << "comments,"; // memo
165 break;
166 case 11:
167 o << "group";
168 break;
169 default:
170 o << "#type=" << grph.m_type << ",";
171 break;
172 case -1:
173 break;
174 }
175 if (grph.m_fileId > 0)
176 o << "fileId=" << std::hex << grph.m_fileId << std::dec << ",";
177 if (grph.m_id>0)
178 o << "id=" << grph.m_id << ",";
179 if (grph.m_page) o << "page=" << grph.m_page+1 << ",";
180 o << "pos=" << grph.m_pos << ",";
181 if (grph.m_baseline < 0 || grph.m_baseline>0) o << "baseline=" << grph.m_baseline << ",";
182 if (grph.m_inGroup) o << "inGroup,";
183 int flag = grph.m_posFlags;
184 if (flag & 4) o << "wrap=around,"; // else overlap
185 if (flag & 0x40) o << "lock,";
186 if (!(flag & 0x80)) o << "transparent,"; // else opaque
187 if (flag & 0x39) o << "posFlags=" << std::hex << (flag & 0x39) << std::dec << ",";
188 o << "style=[" << grph.m_style << "],";
189 if (grph.m_borderType) o << "bord[type]=" << grph.m_borderType << ",";
190 for (int i = 0; i < 4; ++i) {
191 if (grph.m_borders[i].x() > 0 || grph.m_borders[i].y() > 0)
192 o << "border" << i << "=" << grph.m_borders[i] << ",";
193 }
194 o << grph.m_extra;
195 return o;
196 }
197
198 ////////////////////////////////////////
199 //! Internal: the geometrical graph of a HanMacWrdKGraph
200 struct ShapeGraph final : public Frame {
201 //! constructor
202 explicit ShapeGraph(Frame const &orig)
203 : Frame(orig)
204 , m_shape()
205 {
206 }
207 //! destructor
208 ~ShapeGraph() final;
209 //! operator<<
210 friend std::ostream &operator<<(std::ostream &o, ShapeGraph const &graph)
211 {
212 o << graph.print() << ",";
213 o << static_cast<Frame const &>(graph);
214 return o;
215 }
216 //! return the current style
217 MWAWGraphicStyle getStyle() const
218 {
219 MWAWGraphicStyle style(m_style);
220 if (m_shape.m_type!=MWAWGraphicShape::Line)
221 style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow();
222 return style;
223 }
224 //! print local data
225 std::string print() const
226 {
227 std::stringstream s;
228 s << m_shape;
229 return s.str();
230 }
231
232 //! the shape m_shape
233 MWAWGraphicShape m_shape;
234 };
235
236 ShapeGraph::~ShapeGraph()
237 {
238 }
239
240 ////////////////////////////////////////
241 //! Internal: the footnote of a HanMacWrdKGraph
242 struct FootnoteFrame final : public Frame {
243 //! constructor
244 explicit FootnoteFrame(Frame const &orig)
245 : Frame(orig)
246 , m_textFileId(-1)
247 , m_textFileSubId(0)
248 {
249 }
250 //! destructor
251 ~FootnoteFrame() final;
252 //! operator<<
253 friend std::ostream &operator<<(std::ostream &o, FootnoteFrame const &ftn)
254 {
255 o << ftn.print();
256 o << static_cast<Frame const &>(ftn);
257 return o;
258 }
259 //! print local data
260 std::string print() const
261 {
262 std::stringstream s;
263 if (m_textFileId>0)
264 s << "textFileId=" << std::hex << m_textFileId << "[" << m_textFileSubId << std::dec << "],";
265 return s.str();
266 }
267 //! the text file id
268 long m_textFileId;
269 //! the text file subId
270 long m_textFileSubId;
271
272 };
273
274 FootnoteFrame::~FootnoteFrame()
275 {
276 }
277
278 ////////////////////////////////////////
279 //! Internal: the group of a HanMacWrdKGraph
280 struct Group final : public Frame {
281 struct Child;
282 //! constructor
283 explicit Group(Frame const &orig)
284 : Frame(orig)
285 , m_childsList()
286 {
287 }
288 //! destructor
289 ~Group() final;
290 //! operator<<
291 friend std::ostream &operator<<(std::ostream &o, Group const &group)
292 {
293 o << group.print();
294 o << static_cast<Frame const &>(group);
295 return o;
296 }
297 //! print local data
298 std::string print() const;
299 //! the list of child
300 std::vector<Child> m_childsList;
301 //! struct to store child data in HanMacWrdKGraphInternal::Group
302 struct Child {
303 //! constructor
304 Child()
305 : m_fileId(-1)
306 {
307 for (auto &val : m_values) val=0;
308 }
309 //! operator<<
310 friend std::ostream &operator<<(std::ostream &o, Child const &ch)
311 {
312 if (ch.m_fileId > 0)
313 o << "fileId=" << std::hex << ch.m_fileId << std::dec << ",";
314 for (int i = 0; i < 2; ++i) {
315 if (ch.m_values[i] == 0)
316 continue;
317 o << "f" << i << "=" << ch.m_values[i] << ",";
318 }
319 return o;
320 }
321 //! the child id
322 long m_fileId;
323 //! two values
324 int m_values[2];
325 };
326 };
327
328 Group::~Group()
329 {
330 }
331
332 std::string Group::print() const
333 {
334 std::stringstream s;
335 for (size_t i = 0; i < m_childsList.size(); ++i)
336 s << "chld" << i << "=[" << m_childsList[i] << "],";
337 return s.str();
338 }
339
340 ////////////////////////////////////////
341 //! Internal: the picture of a HanMacWrdKGraph
342 struct PictureFrame final : public Frame {
343 //! constructor
344 explicit PictureFrame(Frame const &orig)
345 : Frame(orig)
346 , m_pictureType(0)
347 , m_dim(0,0)
348 , m_borderDim(0,0)
349 {
350 for (auto &val : m_values) val=0;
351 }
352 //! destructor
353 ~PictureFrame() final;
354 //! operator<<
355 friend std::ostream &operator<<(std::ostream &o, PictureFrame const &picture)
356 {
357 o << picture.print();
358 o << static_cast<Frame const &>(picture);
359 return o;
360 }
361 //! print local data
362 std::string print() const
363 {
364 std::stringstream s;
365 if (m_pictureType) s << "type?=" << m_pictureType << ",";
366 if (m_dim[0] || m_dim[1])
367 s << "dim?=" << m_dim << ",";
368 if (m_borderDim[0] > 0 || m_borderDim[1] > 0)
369 s << "borderDim?=" << m_borderDim << ",";
370 for (int i = 0; i < 7; ++i) {
371 if (m_values[i]) s << "f" << i << "=" << m_values[i];
372 }
373 return s.str();
374 }
375
376 //! a type
377 int m_pictureType;
378 //! a dim?
379 MWAWVec2i m_dim;
380 //! the border dim?
381 MWAWVec2f m_borderDim;
382 //! some unknown int
383 int m_values[7];
384 };
385
386 PictureFrame::~PictureFrame()
387 {
388 }
389
390 ////////////////////////////////////////
391 //! a table cell in a table in HanMacWrdKGraph
392 struct TableCell final : public MWAWCell {
393 //! constructor
394 TableCell()
395 : MWAWCell()
396 , m_id(-1)
397 , m_fileId(-1)
398 , m_flags(0)
399 , m_extra("")
400 {
401 }
402 //! call when the content of a cell must be send
403 bool sendContent(MWAWListenerPtr listener, MWAWTable &table) final;
404 //! operator<<
405 friend std::ostream &operator<<(std::ostream &o, TableCell const &cell);
406 //! the cell id ( corresponding to the last data in the main zones list )
407 long m_id;
408 //! the file id
409 long m_fileId;
410 //! the cell data
411 int m_flags;
412 //! extra data
413 std::string m_extra;
414 };
415
416 std::ostream &operator<<(std::ostream &o, TableCell const &cell)
417 {
418 o << static_cast<MWAWCell const &>(cell);
419 if (cell.m_flags&0x10) o << "lock,";
420 if (cell.m_flags&0xFFE2)
421 o << "linesFlags=" << std::hex << (cell.m_flags&0xFFE2) << std::dec << ",";
422 if (cell.m_id > 0)
423 o << "cellId=" << std::hex << cell.m_id << std::dec << ",";
424 if (cell.m_fileId > 0)
425 o << "fileId=" << std::hex << cell.m_fileId << std::dec << ",";
426 o << cell.m_extra;
427 return o;
428 }
429
430 ////////////////////////////////////////
431 //! Internal: the table of a HanMacWrdKGraph
432 struct Table final : public Frame, public MWAWTable {
433 //! constructor
434 Table(Frame const &orig, HanMacWrdKGraph &parser)
435 : Frame(orig)
436 , MWAWTable(MWAWTable::CellPositionBit|MWAWTable::SizeBit)
437 , m_parser(&parser)
438 , m_rows(0)
439 , m_columns(0)
440 , m_numCells(0)
441 , m_textFileId(-1)
442 {
443 }
444 //! destructor
445 ~Table() final;
446 //! return the i^th table cell
447 TableCell *get(int i)
448 {
449 auto cell=MWAWTable::get(i);
450 return static_cast<TableCell *>(cell.get());
451 }
452 //! send a text zone
453 bool sendText(long textId, long id) const
454 {
455 return m_parser->sendText(textId, id);
456 }
457 //! operator<<
458 friend std::ostream &operator<<(std::ostream &o, Table const &table)
459 {
460 o << table.print();
461 o << static_cast<Frame const &>(table);
462 return o;
463 }
464 //! print local data
465 std::string print() const
466 {
467 std::stringstream s;
468 if (m_rows)
469 s << "nRows=" << m_rows << ",";
470 if (m_columns)
471 s << "nColumns=" << m_columns << ",";
472 if (m_numCells)
473 s << "nCells=" << m_numCells << ",";
474 if (m_textFileId>0)
475 s << "textFileId=" << std::hex << m_textFileId << std::dec << ",";
476 return s.str();
477 }
478 //! the graph parser
479 HanMacWrdKGraph *m_parser;
480 //! the number of row
481 int m_rows;
482 //! the number of columns
483 int m_columns;
484 //! the number of cells
485 int m_numCells;
486 //! the text file id
487 long m_textFileId;
488 private:
489 Table(Table const &orig) = delete;
490 Table &operator=(Table const &orig) = delete;
491 };
492
493 Table::~Table()
494 {
495 }
496
497 ////////////////////////////////////////
498 //! Internal: the textbox of a HanMacWrdKGraph
499 struct TextBox final : public Frame {
500 //! constructor
501 TextBox(Frame const &orig, bool isComment)
502 : Frame(orig)
503 , m_commentBox(isComment)
504 , m_textFileId(-1)
505 , m_linkedIdList()
506 , m_isLinked(false)
507 {
508 for (auto &d : m_dim) d = 0;
509 }
510 //! destructor
511 ~TextBox() final;
512 //! returns true if the box is linked to other textbox
513 bool isLinked() const
514 {
515 return !m_linkedIdList.empty() || m_isLinked;
516 }
517 //! add property to frame extra values
518 void addTo(MWAWGraphicStyle &style) const
519 {
520 if (m_type == 10) {
521 MWAWBorder border;
522 border.m_width=double(m_style.m_lineWidth);
523 border.m_color = m_style.m_lineColor;
524 style.setBorders(libmwaw::LeftBit|libmwaw::BottomBit|libmwaw::RightBit, border);
525 border.m_width=double(m_borders[0][1]*m_style.m_lineWidth);
526 style.setBorders(libmwaw::TopBit, border);
527 }
528 else if (m_style.hasLine()) {
529 MWAWBorder border;
530 border.m_width=double(m_style.m_lineWidth);
531 border.m_color=m_style.m_lineColor;
532 switch (m_borderType) {
533 case 0: // solid
534 break;
535 case 1:
536 border.m_type = MWAWBorder::Double;
537 break;
538 case 2:
539 border.m_type = MWAWBorder::Double;
540 border.m_widthsList.resize(3,1.);
541 border.m_widthsList[0]=2.0;
542 break;
543 case 3:
544 border.m_type = MWAWBorder::Double;
545 border.m_widthsList.resize(3,1.);
546 border.m_widthsList[2]=2.0;
547 break;
548 default:
549 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::TextBox::addTo: unexpected type\n"));
550 break;
551 }
552 style.setBorders(15, border);
553 }
554 // now the link
555 if (m_type==4 && m_isLinked) {
556 librevenge::RVNGString fName;
557 fName.sprintf("Frame%ld", m_fileId);
558 style.m_frameName=fName.cstr();
559 }
560 if (m_type==4 && !m_linkedIdList.empty()) {
561 librevenge::RVNGString fName;
562 fName.sprintf("Frame%ld", m_linkedIdList[0]);
563 style.m_frameNextName=fName.cstr();
564 }
565 if (m_style.hasSurfaceColor())
566 style.setBackgroundColor(m_style.m_surfaceColor);
567 }
568 //! operator<<
569 friend std::ostream &operator<<(std::ostream &o, TextBox const &textbox)
570 {
571 o << textbox.print();
572 o << static_cast<Frame const &>(textbox);
573 return o;
574 }
575 //! print local data
576 std::string print() const
577 {
578 std::stringstream s;
579 if (m_dim[0] > 0 || m_dim[1] > 0)
580 s << "commentsDim2=" << m_dim[0] << "x" << m_dim[1] << ",";
581 if (m_textFileId>0)
582 s << "textFileId=" << std::hex << m_textFileId << std::dec << ",";
583 if (!m_linkedIdList.empty()) {
584 s << "link[to]=[";
585 for (auto const &id : m_linkedIdList)
586 s << std::hex << id << std::dec << ",";
587 s << "],";
588 }
589 return s.str();
590 }
591
592 //! a flag to know if this is a comment textbox
593 bool m_commentBox;
594 //! the text file id
595 long m_textFileId;
596 //! two auxilliary dim for memo textbox
597 float m_dim[2];
598 //! the list of linked remaining textbox id
599 std::vector<long> m_linkedIdList;
600 //! a flag to know if this textbox is linked to a previous box
601 bool m_isLinked;
602 };
603
604 TextBox::~TextBox()
605 {
606 }
607
608 bool TableCell::sendContent(MWAWListenerPtr, MWAWTable &table)
609 {
610 if (m_id < 0)
611 return true;
612 return static_cast<Table &>(table).sendText(m_fileId, m_id);
613 }
614
615 ////////////////////////////////////////
616 //! Internal: the picture of a HanMacWrdKGraph
617 struct Picture {
618 //! constructor
619 explicit Picture(std::shared_ptr<HanMacWrdKZone> const &zone)
620 : m_zone(zone)
621 , m_fileId(-1)
622 , m_fileSubId(-1)
623 , m_parsed(false)
624 , m_extra("")
625 {
626 for (auto &pos : m_pos) pos=0;
627 }
628 //! destructor
629 ~Picture()
630 {
631 }
632 //! operator<<
633 friend std::ostream &operator<<(std::ostream &o, Picture const &pict)
634 {
635 if (pict.m_fileId >= 0)
636 o << "fileId=" << std::hex << pict.m_fileId << std::dec << ",";
637 o << pict.m_extra;
638 return o;
639 }
640 //! the main zone
641 std::shared_ptr<HanMacWrdKZone> m_zone;
642 //! the first and last position of the picture data in the zone
643 long m_pos[2];
644 //! the file id
645 long m_fileId;
646 //! the file subid
647 long m_fileSubId;
648 //! a flag to know if the picture was send to the receiver
649 mutable bool m_parsed;
650 //! extra data
651 std::string m_extra;
652 };
653
654 ////////////////////////////////////////
655 //! Internal: the pattern of a HanMacWrdKGraph
656 struct Pattern final : public MWAWGraphicStyle::Pattern {
657 //! constructor ( 4 int by patterns )
658 explicit Pattern(uint16_t const *pat=nullptr)
659 : MWAWGraphicStyle::Pattern()
660 , m_percent(0)
661 {
662 if (!pat) return;
663 m_colors[0]=MWAWColor::white();
664 m_colors[1]=MWAWColor::black();
665 m_dim=MWAWVec2i(8,8);
666 m_data.resize(8);
667 for (size_t i=0; i < 4; ++i) {
668 uint16_t val=pat[i];
669 m_data[2*i]=static_cast<unsigned char>(val>>8);
670 m_data[2*i+1]=static_cast<unsigned char>(val&0xFF);
671 }
672 int numOnes=0;
673 for (size_t j=0; j < 8; ++j) {
674 auto val=static_cast<uint8_t>(m_data[j]);
675 for (int b=0; b < 8; b++) {
676 if (val&1) ++numOnes;
677 val = uint8_t(val>>1);
678 }
679 }
680 m_percent=float(numOnes)/64.f;
681 }
682 Pattern(Pattern const &)=default;
683 Pattern &operator=(Pattern const &)=default;
684 Pattern &operator=(Pattern &&)=default;
685 //! destructor
686 ~Pattern() final;
687 //! the percentage
688 float m_percent;
689 };
690
691 Pattern::~Pattern()
692 {
693 }
694
695 ////////////////////////////////////////
696 //! Internal: the state of a HanMacWrdKGraph
697 struct State {
698 //! constructor
699 State()
700 : m_numPages(0)
701 , m_framesMap()
702 , m_picturesMap()
703 , m_colorList()
704 , m_patternList()
705 {
706 }
707 //! returns a color correspond to an id
708 bool getColor(int id, MWAWColor &col)
709 {
710 initColors();
711 if (id < 0 || id >= int(m_colorList.size())) {
712 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::State::getColor: can not find color %d\n", id));
713 return false;
714 }
715 col = m_colorList[size_t(id)];
716 return true;
717 }
718 //! returns a pattern correspond to an id
719 bool getPattern(int id, Pattern &pattern)
720 {
721 initPatterns();
722 if (id < 0 || id >= int(m_patternList.size())) {
723 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::State::getPattern: can not find pattern %d\n", id));
724 return false;
725 }
726 pattern = m_patternList[size_t(id)];
727 return true;
728 }
729
730 //! returns a color corresponding to a pattern and a color
731 static MWAWColor getColor(MWAWColor col, float pattern)
732 {
733 return MWAWColor::barycenter(pattern,col,1.f-pattern,MWAWColor::white());
734 }
735
736 //! init the color list
737 void initColors();
738 //! init the patterns' list
739 void initPatterns();
740
741 int m_numPages /* the number of pages */;
742 //! a map fileId -> frame
743 std::multimap<long, std::shared_ptr<Frame> > m_framesMap;
744 //! a map fileId -> picture
745 std::map<long, std::shared_ptr<Picture> > m_picturesMap;
746 //! a list colorId -> color
747 std::vector<MWAWColor> m_colorList;
748 //! the patterns list
749 std::vector<Pattern> m_patternList;
750 };
751
752 void State::initPatterns()
753 {
754 if (m_patternList.size()) return;
755 static uint16_t const s_pattern[4*64] = {
756 0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0x7fff, 0xffff, 0xf7ff, 0xffff, 0x7fff, 0xf7ff, 0x7fff, 0xf7ff,
757 0xffee, 0xffbb, 0xffee, 0xffbb, 0x77dd, 0x77dd, 0x77dd, 0x77dd, 0xaa55, 0xaa55, 0xaa55, 0xaa55, 0x8822, 0x8822, 0x8822, 0x8822,
758 0xaa00, 0xaa00, 0xaa00, 0xaa00, 0xaa00, 0x4400, 0xaa00, 0x1100, 0x8800, 0xaa00, 0x8800, 0xaa00, 0x8800, 0x2200, 0x8800, 0x2200,
759 0x8000, 0x0800, 0x8000, 0x0800, 0x8800, 0x0000, 0x8800, 0x0000, 0x8000, 0x0000, 0x0800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
760 0xeedd, 0xbb77, 0xeedd, 0xbb77, 0x3366, 0xcc99, 0x3366, 0xcc99, 0x1122, 0x4488, 0x1122, 0x4488, 0x8307, 0x0e1c, 0x3870, 0xe0c1,
761 0x0306, 0x0c18, 0x3060, 0xc081, 0x0102, 0x0408, 0x1020, 0x4080, 0xffff, 0x0000, 0x0000, 0x0000, 0xff00, 0x0000, 0x0000, 0x0000,
762 0x77bb, 0xddee, 0x77bb, 0xddee, 0x99cc, 0x6633, 0x99cc, 0x6633, 0x8844, 0x2211, 0x8844, 0x2211, 0xe070, 0x381c, 0x0e07, 0x83c1,
763 0xc060, 0x3018, 0x0c06, 0x0381, 0x8040, 0x2010, 0x0804, 0x0201, 0xc0c0, 0xc0c0, 0xc0c0, 0xc0c0, 0x8080, 0x8080, 0x8080, 0x8080,
764 0xffaa, 0xffaa, 0xffaa, 0xffaa, 0xe4e4, 0xe4e4, 0xe4e4, 0xe4e4, 0xffff, 0xff00, 0x00ff, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
765 0xff00, 0xff00, 0xff00, 0xff00, 0xff00, 0x0000, 0xff00, 0x0000, 0x8888, 0x8888, 0x8888, 0x8888, 0xff80, 0x8080, 0x8080, 0x8080,
766 0x4ecf, 0xfce4, 0x473f, 0xf372, 0x6006, 0x36b1, 0x8118, 0x1b63, 0x2004, 0x4002, 0x1080, 0x0801, 0x9060, 0x0609, 0x9060, 0x0609,
767 0x8814, 0x2241, 0x8800, 0xaa00, 0x2050, 0x8888, 0x8888, 0x0502, 0xaa00, 0x8000, 0x8800, 0x8000, 0x2040, 0x8000, 0x0804, 0x0200,
768 0xf0f0, 0xf0f0, 0x0f0f, 0x0f0f, 0x0077, 0x7777, 0x0077, 0x7777, 0xff88, 0x8888, 0xff88, 0x8888, 0xaa44, 0xaa11, 0xaa44, 0xaa11,
769 0x8244, 0x2810, 0x2844, 0x8201, 0x8080, 0x413e, 0x0808, 0x14e3, 0x8142, 0x2418, 0x1020, 0x4080, 0x40a0, 0x0000, 0x040a, 0x0000,
770 0x7789, 0x8f8f, 0x7798, 0xf8f8, 0xf1f8, 0x6cc6, 0x8f1f, 0x3663, 0xbf00, 0xbfbf, 0xb0b0, 0xb0b0, 0xff80, 0x8080, 0xff08, 0x0808,
771 0x1020, 0x54aa, 0xff02, 0x0408, 0x0008, 0x142a, 0x552a, 0x1408, 0x55a0, 0x4040, 0x550a, 0x0404, 0x8244, 0x3944, 0x8201, 0x0101
772 };
773
774 m_patternList.resize(64);
775 for (size_t i=0; i < 64; ++i)
776 m_patternList[i] = Pattern(&s_pattern[i*4]);
777 }
778
779 void State::initColors()
780 {
781 if (m_colorList.size()) return;
782 uint32_t const defCol[256] = {
783 0x000000, 0xffffff, 0xffffcc, 0xffff99, 0xffff66, 0xffff33, 0xffff00, 0xffccff,
784 0xffcccc, 0xffcc99, 0xffcc66, 0xffcc33, 0xffcc00, 0xff99ff, 0xff99cc, 0xff9999,
785 0xff9966, 0xff9933, 0xff9900, 0xff66ff, 0xff66cc, 0xff6699, 0xff6666, 0xff6633,
786 0xff6600, 0xff33ff, 0xff33cc, 0xff3399, 0xff3366, 0xff3333, 0xff3300, 0xff00ff,
787 0xff00cc, 0xff0099, 0xff0066, 0xff0033, 0xff0000, 0xccffff, 0xccffcc, 0xccff99,
788 0xccff66, 0xccff33, 0xccff00, 0xccccff, 0xcccccc, 0xcccc99, 0xcccc66, 0xcccc33,
789 0xcccc00, 0xcc99ff, 0xcc99cc, 0xcc9999, 0xcc9966, 0xcc9933, 0xcc9900, 0xcc66ff,
790 0xcc66cc, 0xcc6699, 0xcc6666, 0xcc6633, 0xcc6600, 0xcc33ff, 0xcc33cc, 0xcc3399,
791 0xcc3366, 0xcc3333, 0xcc3300, 0xcc00ff, 0xcc00cc, 0xcc0099, 0xcc0066, 0xcc0033,
792 0xcc0000, 0x99ffff, 0x99ffcc, 0x99ff99, 0x99ff66, 0x99ff33, 0x99ff00, 0x99ccff,
793 0x99cccc, 0x99cc99, 0x99cc66, 0x99cc33, 0x99cc00, 0x9999ff, 0x9999cc, 0x999999,
794 0x999966, 0x999933, 0x999900, 0x9966ff, 0x9966cc, 0x996699, 0x996666, 0x996633,
795 0x996600, 0x9933ff, 0x9933cc, 0x993399, 0x993366, 0x993333, 0x993300, 0x9900ff,
796 0x9900cc, 0x990099, 0x990066, 0x990033, 0x990000, 0x66ffff, 0x66ffcc, 0x66ff99,
797 0x66ff66, 0x66ff33, 0x66ff00, 0x66ccff, 0x66cccc, 0x66cc99, 0x66cc66, 0x66cc33,
798 0x66cc00, 0x6699ff, 0x6699cc, 0x669999, 0x669966, 0x669933, 0x669900, 0x6666ff,
799 0x6666cc, 0x666699, 0x666666, 0x666633, 0x666600, 0x6633ff, 0x6633cc, 0x663399,
800 0x663366, 0x663333, 0x663300, 0x6600ff, 0x6600cc, 0x660099, 0x660066, 0x660033,
801 0x660000, 0x33ffff, 0x33ffcc, 0x33ff99, 0x33ff66, 0x33ff33, 0x33ff00, 0x33ccff,
802 0x33cccc, 0x33cc99, 0x33cc66, 0x33cc33, 0x33cc00, 0x3399ff, 0x3399cc, 0x339999,
803 0x339966, 0x339933, 0x339900, 0x3366ff, 0x3366cc, 0x336699, 0x336666, 0x336633,
804 0x336600, 0x3333ff, 0x3333cc, 0x333399, 0x333366, 0x333333, 0x333300, 0x3300ff,
805 0x3300cc, 0x330099, 0x330066, 0x330033, 0x330000, 0x00ffff, 0x00ffcc, 0x00ff99,
806 0x00ff66, 0x00ff33, 0x00ff00, 0x00ccff, 0x00cccc, 0x00cc99, 0x00cc66, 0x00cc33,
807 0x00cc00, 0x0099ff, 0x0099cc, 0x009999, 0x009966, 0x009933, 0x009900, 0x0066ff,
808 0x0066cc, 0x006699, 0x006666, 0x006633, 0x006600, 0x0033ff, 0x0033cc, 0x003399,
809 0x003366, 0x003333, 0x003300, 0x0000ff, 0x0000cc, 0x000099, 0x000066, 0x000033,
810 0xee0000, 0xdd0000, 0xbb0000, 0xaa0000, 0x880000, 0x770000, 0x550000, 0x440000,
811 0x220000, 0x110000, 0x00ee00, 0x00dd00, 0x00bb00, 0x00aa00, 0x008800, 0x007700,
812 0x005500, 0x004400, 0x002200, 0x001100, 0x0000ee, 0x0000dd, 0x0000bb, 0x0000aa,
813 0x000088, 0x000077, 0x000055, 0x000044, 0x000022, 0x000011, 0xeeeeee, 0xdddddd,
814 0xbbbbbb, 0xaaaaaa, 0x888888, 0x777777, 0x555555, 0x444444, 0x222222, 0x111111,
815 };
816 m_colorList.resize(256);
817 for (size_t i = 0; i < 256; ++i)
818 m_colorList[i] = defCol[i];
819 }
820
821 ////////////////////////////////////////
822 //! Internal: the subdocument of a HanMacWrdKGraph
823 class SubDocument final : public MWAWSubDocument
824 {
825 public:
826 //! the document type
827 enum Type { Picture, FrameInFrame, Group, Text, UnformattedTable, EmptyPicture };
828 //! constructor
829 SubDocument(HanMacWrdKGraph &pars, MWAWInputStreamPtr const &input, Type type, long id, long subId=0)
830 : MWAWSubDocument(pars.m_mainParser, input, MWAWEntry())
831 , m_graphParser(&pars)
832 , m_type(type)
833 , m_id(id)
834 , m_subId(subId)
835 , m_pos()
836 {
837 }
838
839 //! constructor
840 SubDocument(HanMacWrdKGraph &pars, MWAWInputStreamPtr const &input, MWAWPosition const &pos, Type type, long id, long subId=0)
841 : MWAWSubDocument(pars.m_mainParser, input, MWAWEntry())
842 , m_graphParser(&pars)
843 , m_type(type)
844 , m_id(id)
845 , m_subId(subId)
846 , m_pos(pos)
847 {
848 }
849
850 //! destructor
851 ~SubDocument() final {}
852
853 //! operator!=
854 bool operator!=(MWAWSubDocument const &doc) const final;
855
856 //! the parser function
857 void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
858
859 protected:
860 /** the graph parser */
861 HanMacWrdKGraph *m_graphParser;
862 //! the zone type
863 Type m_type;
864 //! the zone id
865 long m_id;
866 //! the zone subId ( for table cell )
867 long m_subId;
868 //! the position in a frame
869 MWAWPosition m_pos;
870
871 private:
872 SubDocument(SubDocument const &orig) = delete;
873 SubDocument &operator=(SubDocument const &orig) = delete;
874 };
875
876 void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType /*type*/)
877 {
878 if (!listener.get()) {
879 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::SubDocument::parse: no listener\n"));
880 return;
881 }
882 if (!m_graphParser) {
883 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::SubDocument::parse: no parser\n"));
884 return;
885 }
886 long pos = m_input->tell();
887 if (listener->getType()==MWAWListener::Graphic) {
888 if (m_type!=Text) {
889 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::SubDocument::parse: unexpected type\n"));
890 return;
891 }
892 m_graphParser->sendText(m_id, m_subId, listener);
893 }
894 else {
895 switch (m_type) {
896 case FrameInFrame:
897 m_graphParser->sendFrame(m_id, m_pos);
898 break;
899 case Group:
900 m_graphParser->sendGroup(m_id, m_pos);
901 break;
902 case Picture:
903 m_graphParser->sendPicture(m_id, m_pos);
904 break;
905 case UnformattedTable:
906 m_graphParser->sendTableUnformatted(m_id);
907 break;
908 case Text:
909 m_graphParser->sendText(m_id, m_subId);
910 break;
911 case EmptyPicture:
912 m_graphParser->sendEmptyPicture(m_pos);
913 break;
914 #if !defined(__clang__)
915 default:
916 MWAW_DEBUG_MSG(("HanMacWrdKGraphInternal::SubDocument::parse: send type %d is not implemented\n", m_type));
917 break;
918 #endif
919 }
920 }
921 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
922 }
923
924 bool SubDocument::operator!=(MWAWSubDocument const &doc) const
925 {
926 if (MWAWSubDocument::operator!=(doc)) return true;
927 auto const *sDoc = dynamic_cast<SubDocument const *>(&doc);
928 if (!sDoc) return true;
929 if (m_graphParser != sDoc->m_graphParser) return true;
930 if (m_type != sDoc->m_type) return true;
931 if (m_id != sDoc->m_id) return true;
932 if (m_subId != sDoc->m_subId) return true;
933 if (m_pos != sDoc->m_pos) return true;
934 return false;
935 }
936 }
937
938 ////////////////////////////////////////////////////////////
939 // constructor/destructor, ...
940 ////////////////////////////////////////////////////////////
941 HanMacWrdKGraph::HanMacWrdKGraph(HanMacWrdKParser &parser)
942 : m_parserState(parser.getParserState())
943 , m_state(new HanMacWrdKGraphInternal::State)
944 , m_mainParser(&parser)
945 {
946 }
947
948 HanMacWrdKGraph::~HanMacWrdKGraph()
949 { }
950
951 int HanMacWrdKGraph::version() const
952 {
953 return m_parserState->m_version;
954 }
955
956 bool HanMacWrdKGraph::getColor(int colId, int patternId, MWAWColor &color) const
957 {
958 if (patternId==0) // ie. the empty pattern
959 return false;
960 if (!m_state->getColor(colId, color)) {
961 MWAW_DEBUG_MSG(("HanMacWrdKGraph::getColor: can not find color for id=%d\n", colId));
962 return false;
963 }
964 HanMacWrdKGraphInternal::Pattern pattern;
965 if (!m_state->getPattern(patternId, pattern)) {
966 MWAW_DEBUG_MSG(("HanMacWrdKGraph::getColor: can not find pattern for id=%d\n", patternId));
967 return false;
968 }
969 color = m_state->getColor(color, pattern.m_percent);
970 return true;
971 }
972
973 int HanMacWrdKGraph::numPages() const
974 {
975 if (m_state->m_numPages)
976 return m_state->m_numPages;
977 int nPages = 0;
978 for (auto const &fIt : m_state->m_framesMap) {
979 if (!fIt.second) continue;
980 int page = fIt.second->m_page+1;
981 if (page <= nPages) continue;
982 if (page >= nPages+100) continue; // a pb ?
983 nPages = page;
984 }
985 m_state->m_numPages = nPages;
986 return nPages;
987 }
988
989 bool HanMacWrdKGraph::sendText(long textId, long id, MWAWListenerPtr const &listener)
990 {
991 return m_mainParser->sendText(textId, id, listener);
992 }
993
994 std::map<long,int> HanMacWrdKGraph::getTextFrameInformations() const
995 {
996 std::map<long,int> mapIdType;
997 for (auto const &fIt : m_state->m_framesMap) {
998 if (!fIt.second) continue;
999 auto const &frame = *fIt.second;
1000 std::vector<long> listId;
1001
1002 if (frame.m_type!=3 && frame.m_type!=4 && frame.m_type != 9 && frame.m_type!=10)
1003 continue;
1004 switch (frame.m_type) {
1005 case 3:
1006 listId.push_back(static_cast<HanMacWrdKGraphInternal::FootnoteFrame const &>(frame).m_textFileId);
1007 break;
1008 case 4:
1009 case 10:
1010 listId.push_back(static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame).m_textFileId);
1011 break;
1012 case 9: {
1013 auto &table = const_cast<HanMacWrdKGraphInternal::Table &>
1014 (static_cast<HanMacWrdKGraphInternal::Table const &>(frame));
1015 for (int c=0; c < table.numCells(); ++c) {
1016 if (table.get(c))
1017 listId.push_back(table.get(c)->m_fileId);
1018 }
1019 break;
1020 }
1021 default:
1022 break;
1023 }
1024
1025 for (auto zId : listId) {
1026 if (mapIdType.find(zId) == mapIdType.end())
1027 mapIdType[zId] = frame.m_type;
1028 else if (mapIdType.find(zId)->second != frame.m_type) {
1029 MWAW_DEBUG_MSG(("HanMacWrdKGraph::getTextFrameInformations: id %lx already set\n", static_cast<long unsigned int>(zId)));
1030 }
1031 }
1032 }
1033 return mapIdType;
1034 }
1035 ////////////////////////////////////////////////////////////
1036 //
1037 // Intermediate level
1038 //
1039 ////////////////////////////////////////////////////////////
1040
1041 // a small zone: related to frame pos + data?
1042 bool HanMacWrdKGraph::readFrames(std::shared_ptr<HanMacWrdKZone> zone)
1043 {
1044 if (!zone) {
1045 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readFrames: called without any zone\n"));
1046 return false;
1047 }
1048
1049 long dataSz = zone->length();
1050 if (dataSz < 70) {
1051 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readFrames: the zone seems too short\n"));
1052 return false;
1053 }
1054
1055 MWAWInputStreamPtr input = zone->m_input;
1056 libmwaw::DebugFile &asciiFile = zone->ascii();
1057 libmwaw::DebugStream f;
1058 zone->m_parsed = true;
1059 long pos=0;
1060 input->seek(pos, librevenge::RVNG_SEEK_SET);
1061 long val;
1062 HanMacWrdKGraphInternal::Frame graph;
1063 graph.m_type = static_cast<int>(input->readULong(1));
1064 val = long(input->readULong(1));
1065 if (val) f << "#f0=" << std::hex << val << std::dec << ",";
1066 graph.m_posFlags = static_cast<int>(input->readULong(1));
1067 if (graph.m_posFlags&2) graph.m_inGroup=true;
1068 val = long(input->readULong(1));
1069 if (val) f << "#f1=" << std::hex << val << std::dec << ",";
1070 graph.m_page = static_cast<int>(input->readLong(2));
1071 float dim[4];
1072 for (float &i : dim)
1073 i = float(input->readLong(4))/65536.f;
1074 graph.m_pos = MWAWBox2f(MWAWVec2f(dim[0],dim[1]),MWAWVec2f(dim[2],dim[3]));
1075
1076 for (auto &border : graph.m_borders) { // border size, 0=Top, other unknown
1077 float bd[2];
1078 for (auto &j : bd) j = float(input->readLong(4))/65536.f;
1079 border = MWAWVec2f(bd[0],bd[1]);
1080 }
1081 MWAWGraphicStyle &style = graph.m_style;
1082 style.m_lineWidth = float(input->readLong(4))/65536.f;
1083 graph.m_borderType= static_cast<int>(input->readULong(2));
1084 if (val) f << "#g0=" << val << ","; // border type?
1085 for (int i = 0; i < 2; ++i) {
1086 auto color = static_cast<int>(input->readULong(2));
1087 MWAWColor col;
1088 if (!m_state->getColor(color, col)) {
1089 f << "#color[" << i << "]=" << color << ", pat="<<input->readULong(2) << ",";
1090 continue;
1091 }
1092 auto pattern = static_cast<int>(input->readULong(2));
1093 if (pattern==0) {
1094 if (i==0)
1095 style.m_lineOpacity=0;
1096 else
1097 style.m_surfaceOpacity=0;
1098 continue;
1099 }
1100 HanMacWrdKGraphInternal::Pattern pat;
1101 if (m_state->getPattern(pattern, pat)) {
1102 pat.m_colors[1]=col;
1103 if (!pat.getUniqueColor(col)) {
1104 pat.getAverageColor(col);
1105 if (i) style.setPattern(pat);
1106 }
1107 }
1108 else
1109 f << "#pattern[" << i << "]=" << pattern << ",";
1110 if (i==0)
1111 style.m_lineColor=col;
1112 else
1113 style.setSurfaceColor(col,1);
1114 }
1115 graph.m_id=static_cast<int>(input->readLong(2));
1116 graph.m_baseline = float(input->readLong(4))/65536.f;
1117 for (int i = 1; i < 3; ++i) {
1118 val = long(input->readULong(2));
1119 if (val) f << "#g" << i << "=" << val << ",";
1120 }
1121
1122 graph.m_extra=f.str();
1123 f.str("");
1124 f << zone->name() << "(A):PTR=" << std::hex << zone->fileBeginPos() << std::dec << "," << graph;
1125 graph.m_fileId = zone->m_id;
1126 graph.m_fileSubId = zone->m_subId;
1127
1128 asciiFile.addDelimiter(input->tell(),'|');
1129 asciiFile.addPos(pos);
1130 asciiFile.addNote(f.str().c_str());
1131 std::shared_ptr<HanMacWrdKGraphInternal::Frame> frame;
1132 switch (graph.m_type) {
1133 case 3:
1134 frame = readFootnoteFrame(zone, graph);
1135 break;
1136 case 4:
1137 case 10:
1138 frame = readTextBox(zone, graph,graph.m_type==10);
1139 break;
1140 case 6:
1141 frame = readPictureFrame(zone, graph);
1142 break;
1143 case 8:
1144 frame = readShapeGraph(zone, graph);
1145 break;
1146 case 9:
1147 frame = readTable(zone, graph);
1148 break;
1149 case 11:
1150 frame = readGroup(zone, graph);
1151 break;
1152 default:
1153 break;
1154 }
1155 if (frame)
1156 m_state->m_framesMap.insert
1157 (std::multimap<long, std::shared_ptr<HanMacWrdKGraphInternal::Frame> >::value_type
1158 (zone->m_id, frame));
1159 return true;
1160 }
1161
1162 // read a picture
1163 bool HanMacWrdKGraph::readPicture(std::shared_ptr<HanMacWrdKZone> zone)
1164 {
1165 if (!zone) {
1166 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readPicture: called without any zone\n"));
1167 return false;
1168 }
1169
1170 long dataSz = zone->length();
1171 if (dataSz < 86) {
1172 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readPicture: the zone seems too short\n"));
1173 return false;
1174 }
1175
1176 MWAWInputStreamPtr input = zone->m_input;
1177 libmwaw::DebugFile &asciiFile = zone->ascii();
1178 libmwaw::DebugStream f;
1179 zone->m_parsed = true;
1180
1181 std::shared_ptr<HanMacWrdKGraphInternal::Picture> picture(new HanMacWrdKGraphInternal::Picture(zone));
1182
1183 long pos=0;
1184 input->seek(pos, librevenge::RVNG_SEEK_SET);
1185 picture->m_fileId = long(input->readULong(4));
1186 for (int i=0; i < 39; ++i) {
1187 long val = input->readLong(2);
1188 if (val) f << "f" << i << "=" << val << ",";
1189 }
1190 auto pictSz = long(input->readULong(4));
1191 if (pictSz < 0 || pictSz+86 > dataSz) {
1192 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readPicture: problem reading the picture size\n"));
1193 return false;
1194 }
1195 picture->m_pos[0] = input->tell();
1196 picture->m_pos[1] = picture->m_pos[0]+pictSz;
1197 picture->m_extra = f.str();
1198 long fId = picture->m_fileId;
1199 if (!fId) fId = zone->m_id;
1200 picture->m_fileSubId = zone->m_subId;
1201 if (m_state->m_picturesMap.find(fId) != m_state->m_picturesMap.end())
1202 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readPicture: oops I already find a picture for %lx\n", static_cast<long unsigned int>(fId)));
1203 else
1204 m_state->m_picturesMap[fId] = picture;
1205
1206 f.str("");
1207 f << zone->name() << ":PTR=" << std::hex << zone->fileBeginPos() << std::dec << "," << *picture;
1208 f << "pictSz=" << pictSz << ",";
1209 asciiFile.addPos(pos);
1210 asciiFile.addNote(f.str().c_str());
1211
1212 asciiFile.skipZone(picture->m_pos[0], picture->m_pos[1]-1);
1213
1214 return true;
1215 }
1216
1217 ////////////////////////////////////////////////////////////
1218 // send data to a listener
1219 ////////////////////////////////////////////////////////////
1220 bool HanMacWrdKGraph::sendPicture(long pictId, MWAWPosition const &pos)
1221 {
1222 if (!m_parserState->m_textListener) return true;
1223 auto pIt = m_state->m_picturesMap.find(pictId);
1224
1225 if (pIt == m_state->m_picturesMap.end() || !pIt->second) {
1226 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendPicture: can not find the picture %lx\n", static_cast<long unsigned int>(pictId)));
1227 return false;
1228 }
1229 sendPicture(*pIt->second, pos);
1230 return true;
1231 }
1232
1233 bool HanMacWrdKGraph::sendPicture(HanMacWrdKGraphInternal::Picture const &picture, MWAWPosition const &pos)
1234 {
1235 #ifdef DEBUG_WITH_FILES
1236 bool firstTime = picture.m_parsed == false;
1237 #endif
1238 picture.m_parsed = true;
1239 if (!m_parserState->m_textListener) return true;
1240
1241 if (!picture.m_zone || picture.m_pos[0] >= picture.m_pos[1]) {
1242 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendPicture: can not find the picture\n"));
1243 return false;
1244 }
1245
1246 MWAWInputStreamPtr input = picture.m_zone->m_input;
1247
1248 librevenge::RVNGBinaryData data;
1249 input->seek(picture.m_pos[0], librevenge::RVNG_SEEK_SET);
1250 input->readDataBlock(picture.m_pos[1]-picture.m_pos[0], data);
1251 #ifdef DEBUG_WITH_FILES
1252 if (firstTime) {
1253 libmwaw::DebugStream f;
1254 static int volatile pictName = 0;
1255 f << "Pict" << ++pictName << ".pct";
1256 libmwaw::Debug::dumpFile(data, f.str().c_str());
1257 }
1258 #endif
1259 m_parserState->m_textListener->insertPicture(pos, MWAWEmbeddedObject(data, "image/pict"));
1260
1261 return true;
1262 }
1263
1264 bool HanMacWrdKGraph::sendFrame(long frameId, MWAWPosition const &lPos)
1265 {
1266 if (!m_parserState->m_textListener) return true;
1267 auto fIt=m_state->m_framesMap.find(frameId);
1268 if (fIt == m_state->m_framesMap.end() || !fIt->second) {
1269 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendFrame: can not find frame %lx\n", static_cast<long unsigned int>(frameId)));
1270 return false;
1271 }
1272 auto pos(lPos);
1273 if (pos.size()[0]<=0 || pos.size()[1]<=0)
1274 pos.setSize(fIt->second->m_pos.size());
1275 return sendFrame(*fIt->second, pos);
1276 }
1277
1278 bool HanMacWrdKGraph::sendFrame(HanMacWrdKGraphInternal::Frame const &frame, MWAWPosition const &lPos)
1279 {
1280 MWAWTextListenerPtr listener=m_parserState->m_textListener;
1281 if (!listener) return true;
1282
1283 auto pos(lPos);
1284 frame.m_parsed = true;
1285 MWAWInputStreamPtr &input= m_parserState->m_input;
1286 switch (frame.m_type) {
1287 case 3: {
1288 auto const &ftnote=static_cast<HanMacWrdKGraphInternal::FootnoteFrame const &>(frame);
1289 MWAWSubDocumentPtr subdoc
1290 (new HanMacWrdKGraphInternal::SubDocument(*this, input, HanMacWrdKGraphInternal::SubDocument::Text,
1291 ftnote.m_textFileId, ftnote.m_textFileSubId));
1292 listener->insertNote(MWAWNote(MWAWNote::FootNote),subdoc);
1293 break;
1294 }
1295 case 4:
1296 // fixme: check also for border
1297 if (frame.m_style.hasPattern()) {
1298 auto const &textbox=static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame);
1299 if (!textbox.isLinked() && m_mainParser->canSendTextAsGraphic(textbox.m_textFileId,0)) {
1300 textbox.m_parsed=true;
1301 MWAWSubDocumentPtr subdoc
1302 (new HanMacWrdKGraphInternal::SubDocument(*this, input, HanMacWrdKGraphInternal::SubDocument::Text, textbox.m_textFileId));
1303 MWAWBox2f box(MWAWVec2f(0,0),pos.size());
1304 MWAWGraphicEncoder graphicEncoder;
1305 MWAWGraphicListener graphicListener(*m_parserState, box, &graphicEncoder);
1306 graphicListener.startDocument();
1307 MWAWPosition textPos(box[0], box.size(), librevenge::RVNG_POINT);
1308 textPos.m_anchorTo=MWAWPosition::Page;
1309 graphicListener.insertTextBox(textPos, subdoc, textbox.m_style);
1310 graphicListener.endDocument();
1311 MWAWEmbeddedObject picture;
1312 if (!graphicEncoder.getBinaryResult(picture))
1313 return false;
1314 listener->insertPicture(pos, picture);
1315 return true;
1316 }
1317 }
1318 MWAW_FALLTHROUGH;
1319 case 10:
1320 return sendTextBox(static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame), pos);
1321 case 6: {
1322 auto const &pict = static_cast<HanMacWrdKGraphInternal::PictureFrame const &>(frame);
1323 if (pict.m_fileId==0) {
1324 if (pos.size()[0] <= 0 || pos.size()[1] <= 0)
1325 pos.setSize(pict.getBdBox().size());
1326
1327 MWAWPosition framePos(pos);
1328 framePos.m_anchorTo = MWAWPosition::Frame;
1329 framePos.setOrigin(MWAWVec2f(0,0));
1330
1331 MWAWSubDocumentPtr subdoc
1332 (new HanMacWrdKGraphInternal::SubDocument
1333 (*this, input, framePos, HanMacWrdKGraphInternal::SubDocument::EmptyPicture, pict.m_fileId));
1334 listener->insertTextBox(pos, subdoc);
1335 return true;
1336 }
1337 return sendPictureFrame(pict, pos);
1338 }
1339 case 8:
1340 return sendShapeGraph(static_cast<HanMacWrdKGraphInternal::ShapeGraph const &>(frame), pos);
1341 case 9: {
1342 auto &table = const_cast<HanMacWrdKGraphInternal::Table &>
1343 (static_cast<HanMacWrdKGraphInternal::Table const &>(frame));
1344 if (!table.updateTable()) {
1345 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendFrame: can not find the table structure\n"));
1346 MWAWSubDocumentPtr subdoc
1347 (new HanMacWrdKGraphInternal::SubDocument
1348 (*this, input, HanMacWrdKGraphInternal::SubDocument::UnformattedTable, frame.m_fileId));
1349 listener->insertTextBox(pos, subdoc);
1350 return true;
1351 }
1352 if (pos.m_anchorTo==MWAWPosition::Page ||
1353 (pos.m_anchorTo!=MWAWPosition::Frame && table.hasExtraLines())) {
1354 MWAWPosition framePos(pos);
1355 framePos.m_anchorTo = MWAWPosition::Frame;
1356 framePos.setOrigin(MWAWVec2f(0,0));
1357
1358 MWAWSubDocumentPtr subdoc
1359 (new HanMacWrdKGraphInternal::SubDocument
1360 (*this, input, framePos, HanMacWrdKGraphInternal::SubDocument::FrameInFrame, frame.m_fileId));
1361 pos.setSize(MWAWVec2f(-0.01f,-0.01f)); // autosize
1362 listener->insertTextBox(pos, subdoc);
1363 return true;
1364 }
1365 if (table.sendTable(listener,pos.m_anchorTo==MWAWPosition::Frame))
1366 return true;
1367 return table.sendAsText(listener);
1368 }
1369 case 11: {
1370 auto const &group=static_cast<HanMacWrdKGraphInternal::Group const &>(frame);
1371 if ((pos.m_anchorTo==MWAWPosition::Char || pos.m_anchorTo==MWAWPosition::CharBaseLine) && !canCreateGraphic(group)) {
1372 MWAWPosition framePos(pos);
1373 framePos.m_anchorTo = MWAWPosition::Frame;
1374 framePos.setOrigin(MWAWVec2f(0,0));
1375 MWAWSubDocumentPtr subdoc
1376 (new HanMacWrdKGraphInternal::SubDocument
1377 (*this, input, framePos, HanMacWrdKGraphInternal::SubDocument::Group, frame.m_fileId));
1378 listener->insertTextBox(pos, subdoc);
1379 return true;
1380 }
1381 sendGroup(group, pos);
1382 break;
1383 }
1384 default:
1385 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendFrame: sending type %d is not implemented\n", frame.m_type));
1386 break;
1387 }
1388 return false;
1389 }
1390
1391 bool HanMacWrdKGraph::sendEmptyPicture(MWAWPosition const &pos)
1392 {
1393 if (!m_parserState->m_textListener)
1394 return true;
1395 MWAWVec2f pictSz = pos.size();
1396 std::shared_ptr<MWAWPict> pict;
1397 MWAWPosition pictPos(MWAWVec2f(0,0), pictSz, librevenge::RVNG_POINT);
1398 pictPos.setRelativePosition(MWAWPosition::Frame);
1399 pictPos.setOrder(-1);
1400
1401 MWAWBox2f box=MWAWBox2f(MWAWVec2f(0,0),pictSz);
1402 MWAWPosition shapePos(MWAWVec2f(0,0),pictSz, librevenge::RVNG_POINT);
1403 shapePos.m_anchorTo=MWAWPosition::Page;
1404 MWAWGraphicEncoder graphicEncoder;
1405 MWAWGraphicListener graphicListener(*m_parserState, box, &graphicEncoder);
1406 graphicListener.startDocument();
1407 MWAWGraphicStyle defStyle;
1408 graphicListener.insertShape(shapePos, MWAWGraphicShape::rectangle(box), defStyle);
1409 graphicListener.insertShape(shapePos, MWAWGraphicShape::line(box[0],box[1]), defStyle);
1410 graphicListener.insertShape(shapePos, MWAWGraphicShape::line(MWAWVec2f(0,pictSz[1]), MWAWVec2f(pictSz[0],0)), defStyle);
1411 graphicListener.endDocument();
1412 MWAWEmbeddedObject picture;
1413 if (!graphicEncoder.getBinaryResult(picture)) return false;
1414 m_parserState->m_textListener->insertPicture(pictPos, picture);
1415 return true;
1416 }
1417
1418 bool HanMacWrdKGraph::sendPictureFrame(HanMacWrdKGraphInternal::PictureFrame const &pict, MWAWPosition const &lPos)
1419 {
1420 if (!m_parserState->m_textListener) return true;
1421 auto pos(lPos);
1422 if (pos.size()[0] <= 0 || pos.size()[1] <= 0)
1423 pos.setSize(pict.getBdBox().size());
1424 //fixme: check if we have border
1425 sendPicture(pict.m_fileId, pos);
1426 return true;
1427 }
1428
1429 bool HanMacWrdKGraph::sendTextBox(HanMacWrdKGraphInternal::TextBox const &textbox, MWAWPosition const &lPos)
1430 {
1431 if (!m_parserState->m_textListener) return true;
1432 MWAWVec2f textboxSz = textbox.getBdBox().size();
1433 auto pos(lPos);
1434 if (textbox.m_type==10) {
1435 if (textbox.m_dim[0] > textboxSz[0]) textboxSz[0]=textbox.m_dim[0];
1436 if (textbox.m_dim[1] > textboxSz[1]) textboxSz[1]=textbox.m_dim[1];
1437 pos.setSize(textboxSz);
1438 pos.setOrder(100); // put note in front
1439 }
1440 else if (pos.size()[0] <= 0 || pos.size()[1] <= 0)
1441 pos.setSize(textboxSz);
1442
1443 MWAWGraphicStyle style;
1444 textbox.addTo(style);
1445 MWAWSubDocumentPtr subdoc;
1446 if (!textbox.m_isLinked)
1447 subdoc.reset(new HanMacWrdKGraphInternal::SubDocument(*this, m_parserState->m_input, HanMacWrdKGraphInternal::SubDocument::Text, textbox.m_textFileId));
1448 m_parserState->m_textListener->insertTextBox(pos, subdoc, style);
1449
1450 return true;
1451 }
1452
1453 bool HanMacWrdKGraph::sendShapeGraph(HanMacWrdKGraphInternal::ShapeGraph const &pict, MWAWPosition const &lPos)
1454 {
1455 if (!m_parserState->m_textListener) return true;
1456 auto pos(lPos);
1457 if (pos.size()[0] <= 0 || pos.size()[1] <= 0)
1458 pos.setSize(pict.getBdBox().size());
1459 pos.setOrigin(pos.origin());
1460 pos.setSize(pos.size()+MWAWVec2f(4,4));
1461 m_parserState->m_textListener->insertShape(pos,pict.m_shape,pict.getStyle());
1462 return true;
1463 }
1464
1465 // ----- table
1466 bool HanMacWrdKGraph::sendTableUnformatted(long fId)
1467 {
1468 if (!m_parserState->m_textListener)
1469 return true;
1470 auto fIt = m_state->m_framesMap.find(fId);
1471 if (fIt == m_state->m_framesMap.end() || !fIt->second || fIt->second->m_type != 9) {
1472 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendTableUnformatted: can not find table %lx\n", static_cast<long unsigned int>(fId)));
1473 return false;
1474 }
1475 auto &table = static_cast<HanMacWrdKGraphInternal::Table &>(*fIt->second);
1476 return table.sendAsText(m_parserState->m_textListener);
1477 }
1478
1479 ////////////////////////////////////////////////////////////
1480 // low level
1481 ////////////////////////////////////////////////////////////
1482
1483 // try to read a small graphic
1484 std::shared_ptr<HanMacWrdKGraphInternal::ShapeGraph> HanMacWrdKGraph::readShapeGraph(std::shared_ptr<HanMacWrdKZone> zone, HanMacWrdKGraphInternal::Frame const &header)
1485 {
1486 std::shared_ptr<HanMacWrdKGraphInternal::ShapeGraph> graph;
1487 if (!zone) {
1488 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readShapeGraph: called without any zone\n"));
1489 return graph;
1490 }
1491
1492 MWAWInputStreamPtr input = zone->m_input;
1493 long dataSz = zone->length();
1494 long pos = input->tell();
1495 if (pos+26 > dataSz) {
1496 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readShapeGraph: the zone seems too short\n"));
1497 return graph;
1498 }
1499
1500 graph.reset(new HanMacWrdKGraphInternal::ShapeGraph(header));
1501 libmwaw::DebugFile &asciiFile = zone->ascii();
1502 libmwaw::DebugStream f;
1503 auto graphType = static_cast<int>(input->readLong(1));
1504 long val;
1505 bool ok = true;
1506 MWAWBox2f bdbox=graph->m_pos;
1507 MWAWGraphicShape &shape=graph->m_shape;
1508 shape = MWAWGraphicShape();
1509 shape.m_bdBox = shape.m_formBox = bdbox;
1510 switch (graphType) {
1511 case 0:
1512 case 3: { // lines
1513 if (pos+28 > dataSz) {
1514 f << "###";
1515 ok = false;
1516 break;
1517 }
1518 shape.m_type=MWAWGraphicShape::Line;
1519 auto arrowFlags=static_cast<int>(input->readULong(1));
1520 if (arrowFlags&1) graph->m_style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain();
1521 if (arrowFlags&2) graph->m_style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain();
1522 if (arrowFlags&0xFC) f << "#arrowsFl=" << (arrowFlags & 0xFC) << ",";
1523 for (int i = 0; i < 5; ++i) { // always 0
1524 val = input->readLong(2);
1525 if (val) f << "f" << i << "=" << val << ",";
1526 }
1527 float coord[2];
1528 for (int pt = 0; pt < 2; ++pt) {
1529 for (auto &c : coord) c = float(input->readLong(4))/65536.f;
1530 MWAWVec2f vertex=MWAWVec2f(coord[1],coord[0]);
1531 shape.m_vertices.push_back(vertex);
1532 }
1533 break;
1534 }
1535 case 1: // rectangle
1536 case 2: // circle
1537 shape.m_type = graphType==1?
1538 MWAWGraphicShape::Rectangle : MWAWGraphicShape::Circle;
1539 for (int i = 0; i < 13; ++i) { // always 0
1540 val = input->readLong(2);
1541 if (val) f << "f" << i << "=" << val << ",";
1542 }
1543 break;
1544 case 4: { // rectOval
1545 if (pos+28 > dataSz) {
1546 f << "###";
1547 ok = false;
1548 break;
1549 }
1550 for (int i = 0; i < 4; ++i) {
1551 val = input->readLong(i ? 2 : 1);
1552 if (val) f << "f" << i << "=" << val << ",";
1553 }
1554 shape.m_type=MWAWGraphicShape::Rectangle;
1555 float cornerDim = float(input->readLong(4))/65536.f;
1556 for (int c=0; c < 2; ++c) {
1557 if (2.f*cornerDim <= bdbox.size()[c])
1558 shape.m_cornerWidth[c]=cornerDim;
1559 else
1560 shape.m_cornerWidth[c]=bdbox.size()[c]/2.0f;
1561 }
1562 for (int i = 0; i < 8; ++i) {
1563 val = input->readLong(i);
1564 if (val) f << "g" << i << "=" << val << ",";
1565 }
1566 break;
1567 }
1568 case 5: { // arc
1569 val = input->readLong(2);
1570 if (val) f << "f0=" << val << ",";
1571 auto transf = static_cast<int>(input->readULong(1));
1572 float angles[2];
1573 if (transf>=0 && transf <= 3) {
1574 int decal = (transf%2) ? 4-transf : transf;
1575 angles[0] = float(-90*decal);
1576 angles[1] = float(90-90*decal);
1577 }
1578 else {
1579 f << "#transf=" << transf << ",";
1580 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readShapeGraph: find unexpected transformation for arc\n"));
1581 ok = false;
1582 break;
1583 }
1584
1585 // we must compute the real bd box: first the box on the unit circle
1586 float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 };
1587 int limitAngle[2];
1588 for (int i = 0; i < 2; ++i)
1589 limitAngle[i] = (angles[i] < 0) ? int(angles[i]/90.f)-1 : int(angles[i]/90.f);
1590 for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; ++bord) {
1591 float ang = (bord == limitAngle[0]) ? float(angles[0]) :
1592 (bord == limitAngle[1]+1) ? float(angles[1]) : float(90 * bord);
1593 ang *= float(M_PI/180.);
1594 float const actVal[2] = { std::cos(ang), -std::sin(ang)};
1595 if (actVal[0] < minVal[0]) minVal[0] = actVal[0];
1596 else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0];
1597 if (actVal[1] < minVal[1]) minVal[1] = actVal[1];
1598 else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1];
1599 }
1600 float const factor[2]= {bdbox.size()[0]/(maxVal[0]>minVal[0]?maxVal[0]-minVal[0]:0.f),
1601 bdbox.size()[1]/(maxVal[1]>minVal[1]?maxVal[1]-minVal[1]:0.f)
1602 };
1603 float const delta[2]= {bdbox[0][0]-minVal[0] *factor[0],bdbox[0][1]-minVal[1] *factor[1]};
1604 shape.m_formBox=MWAWBox2f(MWAWVec2f(delta[0]-factor[0],delta[1]-factor[1]),
1605 MWAWVec2f(delta[0]+factor[0],delta[1]+factor[1]));
1606 shape.m_type=MWAWGraphicShape::Pie;
1607 shape.m_arcAngles=MWAWVec2f(angles[0],angles[1]);
1608 for (int i = 0; i < 12; ++i) { // always 0
1609 val = input->readLong(2);
1610 if (val) f << "f" << i+1 << "=" << val << ",";
1611 }
1612 break;
1613 }
1614 case 6: { // poly
1615 for (int i = 0; i < 5; ++i) { // find f3=0|1, other 0
1616 val = input->readLong(1);
1617 if (val) f << "f" << i << "=" << val << ",";
1618 }
1619 auto numPt = static_cast<int>(input->readLong(2));
1620 if (numPt < 0 || 28+8*numPt > dataSz) {
1621 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readShapeGraph: find unexpected number of points\n"));
1622 f << "#pt=" << numPt << ",";
1623 ok = false;
1624 break;
1625 }
1626 for (int i = 0; i < 10; ++i) { //always 0
1627 val = input->readLong(2);
1628 if (val) f << "g" << i << "=" << val << ",";
1629 }
1630 shape.m_type=MWAWGraphicShape::Polygon;
1631 for (int i = 0; i < numPt; ++i) {
1632 float dim[2];
1633 for (auto &d : dim) d = float(input->readLong(4))/65536.f;
1634 MWAWVec2f vertex=MWAWVec2f(dim[1], dim[0])+bdbox[0];
1635 shape.m_vertices.push_back(vertex);
1636 }
1637 break;
1638 }
1639 default:
1640 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readShapeGraph: find unexpected graphic subType\n"));
1641 f << "###type=" << graphType << ",";
1642 ok = false;
1643 break;
1644 }
1645
1646 std::string extra = f.str();
1647 graph->m_extra += extra;
1648
1649 f.str("");
1650 f << "FrameDef(graphData):" << graph->print() << extra;
1651
1652 asciiFile.addDelimiter(input->tell(),'|');
1653 asciiFile.addPos(pos);
1654 asciiFile.addNote(f.str().c_str());
1655 if (!ok)
1656 graph.reset();
1657 return graph;
1658 }
1659
1660 // try to read the group data
1661 std::shared_ptr<HanMacWrdKGraphInternal::Group> HanMacWrdKGraph::readGroup(std::shared_ptr<HanMacWrdKZone> zone, HanMacWrdKGraphInternal::Frame const &header)
1662 {
1663 std::shared_ptr<HanMacWrdKGraphInternal::Group> group;
1664 if (!zone) {
1665 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readGroup: called without any zone\n"));
1666 return group;
1667 }
1668
1669 MWAWInputStreamPtr input = zone->m_input;
1670 long dataSz = zone->length();
1671 long pos = input->tell();
1672 if (pos+2 > dataSz) {
1673 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readGroup: the zone seems too short\n"));
1674 return group;
1675 }
1676 auto N = static_cast<int>(input->readULong(2));
1677 if (pos+2+8*N > dataSz) {
1678 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readGroup: can not read N\n"));
1679 return group;
1680 }
1681 group.reset(new HanMacWrdKGraphInternal::Group(header));
1682 libmwaw::DebugFile &asciiFile = zone->ascii();
1683 libmwaw::DebugStream f;
1684 for (int i = 0; i < N; ++i) {
1685 HanMacWrdKGraphInternal::Group::Child child;
1686 child.m_fileId = long(input->readULong(4));
1687 for (auto &val : child.m_values) // f0=4|6|8, f1=0
1688 val = static_cast<int>(input->readLong(2));
1689 group->m_childsList.push_back(child);
1690 }
1691 f << "FrameDef(groupData):" << group->print();
1692
1693 asciiFile.addPos(pos);
1694 asciiFile.addNote(f.str().c_str());
1695 return group;
1696 }
1697
1698 // try to read a picture frame
1699 std::shared_ptr<HanMacWrdKGraphInternal::PictureFrame> HanMacWrdKGraph::readPictureFrame(std::shared_ptr<HanMacWrdKZone> zone, HanMacWrdKGraphInternal::Frame const &header)
1700 {
1701 std::shared_ptr<HanMacWrdKGraphInternal::PictureFrame> picture;
1702 if (!zone) {
1703 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readPicture: called without any zone\n"));
1704 return picture;
1705 }
1706
1707 MWAWInputStreamPtr input = zone->m_input;
1708 long dataSz = zone->length();
1709 long pos = input->tell();
1710 if (pos+32 > dataSz) {
1711 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readPicture: the zone seems too short\n"));
1712 return picture;
1713 }
1714
1715 picture.reset(new HanMacWrdKGraphInternal::PictureFrame(header));
1716 libmwaw::DebugFile &asciiFile = zone->ascii();
1717 libmwaw::DebugStream f;
1718 picture->m_pictureType = static_cast<int>(input->readLong(2)); // 0 or 4 : or maybe wrapping
1719 for (int i = 0; i < 5; ++i) // always 0
1720 picture->m_values[i] = static_cast<int>(input->readLong(2));
1721 float bDim[2];
1722 for (auto &d : bDim) d = float(input->readLong(4))/65536.f;
1723 picture->m_borderDim = MWAWVec2f(bDim[0], bDim[1]);
1724 for (int i = 5; i < 7; ++i) // always 0
1725 picture->m_values[i] = static_cast<int>(input->readLong(2));
1726 int dim[2]; //0,0 or 3e,3c
1727 for (auto &d : dim) d = static_cast<int>(input->readLong(2));
1728 picture->m_dim = MWAWVec2i(dim[0], dim[1]);
1729 picture->m_fileId = long(input->readULong(4));
1730
1731 f << "FrameDef(pictureData):";
1732 if (picture->m_fileId)
1733 f << "fId=" << std::hex << picture->m_fileId << std::dec << ",";
1734 f << picture->print();
1735 asciiFile.addPos(pos);
1736 asciiFile.addNote(f.str().c_str());
1737 return picture;
1738 }
1739
1740 // try to read the footnote data
1741 std::shared_ptr<HanMacWrdKGraphInternal::FootnoteFrame> HanMacWrdKGraph::readFootnoteFrame(std::shared_ptr<HanMacWrdKZone> zone, HanMacWrdKGraphInternal::Frame const &header)
1742 {
1743 std::shared_ptr<HanMacWrdKGraphInternal::FootnoteFrame> ftn;
1744 if (!zone) {
1745 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readFootnoteFrame: called without any zone\n"));
1746 return ftn;
1747 }
1748
1749 MWAWInputStreamPtr input = zone->m_input;
1750 long dataSz = zone->length();
1751 long pos = input->tell();
1752 if (pos+24 > dataSz) {
1753 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readFootnoteFrame: the zone seems too short\n"));
1754 return ftn;
1755 }
1756
1757 ftn.reset(new HanMacWrdKGraphInternal::FootnoteFrame(header));
1758 libmwaw::DebugFile &asciiFile = zone->ascii();
1759 libmwaw::DebugStream f;
1760 for (int i = 0; i < 9; ++i) { // always 0?
1761 long val = input->readLong(2);
1762 if (val) f << "f" << i << "=" << val << ",";
1763 }
1764 ftn->m_textFileSubId = long(input->readULong(2));
1765 ftn->m_textFileId = long(input->readULong(4));
1766 std::string extra = f.str();
1767 ftn->m_extra += extra;
1768
1769 f.str("");
1770 f << "FrameDef(footnoteData):" << ftn->print() << extra;
1771 asciiFile.addPos(pos);
1772 asciiFile.addNote(f.str().c_str());
1773 return ftn;
1774 }
1775
1776 // try to read the textbox data
1777 std::shared_ptr<HanMacWrdKGraphInternal::TextBox> HanMacWrdKGraph::readTextBox(std::shared_ptr<HanMacWrdKZone> zone, HanMacWrdKGraphInternal::Frame const &header, bool isMemo)
1778 {
1779 std::shared_ptr<HanMacWrdKGraphInternal::TextBox> textbox;
1780 if (!zone) {
1781 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readTextBox: called without any zone\n"));
1782 return textbox;
1783 }
1784
1785 MWAWInputStreamPtr input = zone->m_input;
1786 long dataSz = zone->length();
1787 long pos = input->tell();
1788 int expectedSize = isMemo ? 20 : 12;
1789 if (pos+expectedSize > dataSz) {
1790 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readTextBox: the zone seems too short\n"));
1791 return textbox;
1792 }
1793
1794 textbox.reset(new HanMacWrdKGraphInternal::TextBox(header, isMemo));
1795 libmwaw::DebugFile &asciiFile = zone->ascii();
1796 libmwaw::DebugStream f;
1797 for (int i = 0; i < 3; ++i) { // 0|1,0|1,0|1,numtextbox linked
1798 auto val = static_cast<int>(input->readLong(1));
1799 if (val) f << "f" << i << "=" << val << ",";
1800 }
1801 auto numLinks=static_cast<int>(input->readLong(1));
1802 if (numLinks!=(isMemo ? 0 : 1)) f << "numLinks=" << numLinks << ",";
1803 auto fChar=long(input->readULong(4));
1804 if (fChar) f << "first[char]=" << fChar << ",";
1805 textbox->m_textFileId = long(input->readULong(4));
1806 if (isMemo) { // checkme
1807 for (int i = 0; i < 2; ++i)
1808 textbox->m_dim[1-i] = float(input->readLong(4))/65536.f;
1809 }
1810 else if (numLinks>1 && pos+12+4*(numLinks-1) <= dataSz) {
1811 for (int l=1; l<numLinks; ++l)
1812 textbox->m_linkedIdList.push_back(input->readLong(4));
1813 }
1814 textbox->m_extra=f.str();
1815 f.str("");
1816 f << "FrameDef(textboxData):";
1817 f << "fId=" << std::hex << textbox->m_textFileId << std::dec << "," << textbox->print();
1818 asciiFile.addPos(pos);
1819 asciiFile.addNote(f.str().c_str());
1820 return textbox;
1821 }
1822
1823 // try to read the table data
1824 std::shared_ptr<HanMacWrdKGraphInternal::Table> HanMacWrdKGraph::readTable(std::shared_ptr<HanMacWrdKZone> zone, HanMacWrdKGraphInternal::Frame const &header)
1825 {
1826 std::shared_ptr<HanMacWrdKGraphInternal::Table> table;
1827 if (!zone) {
1828 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readTable: called without any zone\n"));
1829 return table;
1830 }
1831
1832 MWAWInputStreamPtr input = zone->m_input;
1833 long dataSz = zone->length();
1834 long pos = input->tell();
1835 if (pos+20 > dataSz) {
1836 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readTable: the zone seems too short\n"));
1837 return table;
1838 }
1839
1840 table.reset(new HanMacWrdKGraphInternal::Table(header, *this));
1841 libmwaw::DebugFile &asciiFile = zone->ascii();
1842 libmwaw::DebugStream f, f2;
1843 long val;
1844 for (int i = 0; i < 4; ++i) {
1845 val = input->readLong(2);
1846 if (val) f << "f" << i << "=" << val << ",";
1847 }
1848 table->m_textFileId = long(input->readULong(4));
1849 table->m_rows = static_cast<int>(input->readLong(2));
1850 table->m_columns = static_cast<int>(input->readLong(2));
1851 table->m_numCells = static_cast<int>(input->readLong(2));
1852
1853 val = input->readLong(2);
1854 if (val) f << "f4=" << val << ",";
1855 std::string extra = f.str();
1856 table->m_extra += extra;
1857
1858 f.str("");
1859 f << "FrameDef(tableData):";
1860 f << "fId=" << std::hex << table->m_textFileId << std::dec << ","
1861 << table->print() << extra;
1862 asciiFile.addPos(pos);
1863 asciiFile.addNote(f.str().c_str());
1864
1865 for (int i = 0; i < table->m_numCells; ++i) {
1866 if (input->isEnd()) break;
1867 pos = input->tell();
1868 f.str("");
1869 if (pos+80 > dataSz) {
1870 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readTable: can not read cell %d\n", i));
1871 f << "FrameDef(tableCell-" << i << "):###";
1872 asciiFile.addPos(pos);
1873 asciiFile.addNote(f.str().c_str());
1874 break;
1875 }
1876 std::shared_ptr<HanMacWrdKGraphInternal::TableCell> cell(new HanMacWrdKGraphInternal::TableCell);
1877 int posi[2];
1878 for (auto &p : posi) p = static_cast<int>(input->readLong(2));
1879 cell->setPosition(MWAWVec2i(posi[1],posi[0]));
1880 int span[2];
1881 for (auto &s : span) s = static_cast<int>(input->readLong(2));
1882 if (span[0]>=1 && span[1]>=1)
1883 cell->setNumSpannedCells(MWAWVec2i(span[1], span[0]));
1884 else {
1885 MWAW_DEBUG_MSG(("HanMacWrdKGraph::readTable: can not read cell span\n"));
1886 f << "##span=" << span[1] << "x" << span[0] << ",";
1887 }
1888 float dim[2];
1889 for (auto &d : dim) d = float(input->readLong(4))/65536.f;
1890 cell->setBdSize(MWAWVec2f(dim[0], dim[1]));
1891
1892 auto color = static_cast<int>(input->readULong(2));
1893 MWAWColor backCol = MWAWColor::white();
1894 if (!m_state->getColor(color, backCol))
1895 f << "#backcolor=" << color << ",";
1896 auto pattern = static_cast<int>(input->readULong(2));
1897 HanMacWrdKGraphInternal::Pattern pat;
1898 if (pattern && m_state->getPattern(pattern, pat))
1899 cell->setBackgroundColor(m_state->getColor(backCol, pat.m_percent));
1900 else if (pattern)
1901 f << "#backPattern=" << pattern << ",";
1902
1903 cell->m_flags = static_cast<int>(input->readULong(2));
1904 if (cell->m_flags&1) cell->setVAlignment(MWAWCell::VALIGN_CENTER);
1905 switch ((cell->m_flags>>2) & 3) {
1906 case 1:
1907 cell->setExtraLine(MWAWCell::E_Line1);
1908 break;
1909 case 2:
1910 cell->setExtraLine(MWAWCell::E_Line2);
1911 break;
1912 case 3:
1913 cell->setExtraLine(MWAWCell::E_Cross);
1914 break;
1915 case 0: // none
1916 default:
1917 break;
1918 }
1919 val = input->readLong(2);
1920 if (val) f << "f2=" << val << ",";
1921
1922 static char const *what[] = {"T", "L", "B", "R"};
1923 static int const which[] = { libmwaw::TopBit, libmwaw::LeftBit, libmwaw::BottomBit, libmwaw::RightBit };
1924 for (int b = 0; b < 4; ++b) { // find _,4000,_,_,1,_, and 1,_,_,_,1,_,
1925 f2.str("");
1926 MWAWBorder border;
1927 border.m_width=double(input->readLong(4))/65536.;
1928 auto type = int(input->readLong(2));
1929 switch (type) {
1930 case 0: // solid
1931 break;
1932 case 1:
1933 border.m_type = MWAWBorder::Double;
1934 break;
1935 case 2:
1936 border.m_type = MWAWBorder::Double;
1937 border.m_widthsList.resize(3,1.);
1938 border.m_widthsList[0]=2.0;
1939 break;
1940 case 3:
1941 border.m_type = MWAWBorder::Double;
1942 border.m_widthsList.resize(3,1.);
1943 border.m_widthsList[2]=2.0;
1944 break;
1945 default:
1946 f2 << "#style=" << type << ",";
1947 break;
1948 }
1949 color = static_cast<int>(input->readULong(2));
1950 MWAWColor col = MWAWColor::black();
1951 if (!m_state->getColor(color, col))
1952 f2 << "#color=" << color << ",";
1953 pattern = static_cast<int>(input->readULong(2));
1954 if (pattern==0) border.m_style=MWAWBorder::None;
1955 else {
1956 if (!m_state->getPattern(pattern, pat)) {
1957 f2 << "#pattern=" << pattern << ",";
1958 border.m_color = col;
1959 }
1960 else
1961 border.m_color = m_state->getColor(col, pat.m_percent);
1962 }
1963 val = long(input->readULong(2));
1964 if (val) f2 << "unkn=" << val << ",";
1965
1966 cell->setBorders(which[b],border);
1967 if (cell->hasExtraLine() && b==3) {
1968 // extra line border seems to correspond to the right border
1969 MWAWBorder extraL;
1970 extraL.m_width=border.m_width;
1971 extraL.m_color=border.m_color;
1972 cell->setExtraLine(cell->extraLine(), extraL);
1973 }
1974 if (f2.str().length())
1975 f << "bord" << what[b] << "=[" << f2.str() << "],";
1976 }
1977 cell->m_fileId = long(input->readULong(4));
1978 cell->m_id = long(input->readULong(4));
1979 cell->m_extra = f.str();
1980 table->add(cell);
1981
1982 f.str("");
1983 f << "FrameDef(tableCell-" << i << "):" << *cell;
1984
1985 asciiFile.addDelimiter(input->tell(),'|');
1986 asciiFile.addPos(pos);
1987 asciiFile.addNote(f.str().c_str());
1988 input->seek(pos+80, librevenge::RVNG_SEEK_SET);
1989 }
1990
1991 return table;
1992 }
1993
1994 ////////////////////////////////////////////////////////////
1995 // group
1996 ////////////////////////////////////////////////////////////
1997 bool HanMacWrdKGraph::sendGroup(long groupId, MWAWPosition const &pos)
1998 {
1999 if (!m_parserState->m_textListener) return true;
2000 auto fIt=m_state->m_framesMap.find(groupId);
2001 if (fIt == m_state->m_framesMap.end()) {
2002 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroup: can not find group %lx\n", static_cast<long unsigned int>(groupId)));
2003 return false;
2004 }
2005 auto frame=fIt->second;
2006 if (!frame || frame->m_type!=11) {
2007 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroup: %lx seems bad\n", static_cast<long unsigned int>(groupId)));
2008 return false;
2009 }
2010 return sendGroup(static_cast<HanMacWrdKGraphInternal::Group const &>(*frame), pos);
2011 }
2012
2013 bool HanMacWrdKGraph::sendGroup(HanMacWrdKGraphInternal::Group const &group, MWAWPosition const &pos)
2014 {
2015 group.m_parsed=true;
2016 sendGroupChild(group,pos);
2017 return true;
2018 }
2019
2020 bool HanMacWrdKGraph::canCreateGraphic(HanMacWrdKGraphInternal::Group const &group)
2021 {
2022 int page = group.m_page;
2023 for (auto const &child :group.m_childsList) {
2024 long fId=child.m_fileId;
2025 auto fIt=m_state->m_framesMap.find(fId);
2026 if (fIt == m_state->m_framesMap.end() || fIt->first!=fId || !fIt->second)
2027 continue;
2028 auto const &frame=*fIt->second;
2029 if (frame.m_page!=page) return false;
2030 switch (frame.m_type) {
2031 case 4: {
2032 auto const &text=static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame);
2033 if (text.isLinked() || !m_mainParser->canSendTextAsGraphic(text.m_textFileId,0))
2034 return false;
2035 break;
2036 }
2037 case 8: // shape
2038 break;
2039 case 11:
2040 if (!canCreateGraphic(static_cast<HanMacWrdKGraphInternal::Group const &>(frame)))
2041 return false;
2042 break;
2043 default:
2044 return false;
2045 }
2046 }
2047 return true;
2048 }
2049
2050 void HanMacWrdKGraph::sendGroup(HanMacWrdKGraphInternal::Group const &group, MWAWGraphicListenerPtr &listener)
2051 {
2052 if (!listener) return;
2053 group.m_parsed=true;
2054 MWAWInputStreamPtr &input= m_parserState->m_input;
2055 for (auto const &child : group.m_childsList) {
2056 long fId=child.m_fileId;
2057 auto fIt=m_state->m_framesMap.find(fId);
2058 if (fIt == m_state->m_framesMap.end() || fIt->first!=fId || !fIt->second)
2059 continue;
2060 auto const &frame=*fIt->second;
2061 MWAWBox2f box=frame.getBdBox();
2062 MWAWPosition pictPos(box[0], box.size(), librevenge::RVNG_POINT);
2063 pictPos.m_anchorTo=MWAWPosition::Page;
2064 switch (frame.m_type) {
2065 case 4: {
2066 frame.m_parsed=true;
2067 auto const &textbox=static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame);
2068 MWAWSubDocumentPtr subdoc
2069 (new HanMacWrdKGraphInternal::SubDocument(*this, input, HanMacWrdKGraphInternal::SubDocument::Text, textbox.m_textFileId));
2070 listener->insertTextBox(pictPos, subdoc, textbox.m_style);
2071 break;
2072 }
2073 case 8: {
2074 frame.m_parsed=true;
2075 auto const &shape=static_cast<HanMacWrdKGraphInternal::ShapeGraph const &>(frame);
2076 listener->insertShape(pictPos, shape.m_shape, shape.getStyle());
2077 break;
2078 }
2079 case 11:
2080 sendGroup(static_cast<HanMacWrdKGraphInternal::Group const &>(frame), listener);
2081 break;
2082 default:
2083 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroup: unexpected type %d\n", frame.m_type));
2084 break;
2085 }
2086 }
2087 }
2088
2089 void HanMacWrdKGraph::sendGroupChild(HanMacWrdKGraphInternal::Group const &group, MWAWPosition const &pos)
2090 {
2091 MWAWTextListenerPtr listener=m_parserState->m_textListener;
2092 if (!listener) {
2093 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroupChild: can not find the listeners\n"));
2094 return;
2095 }
2096 size_t numChilds=group.m_childsList.size(), childNotSent=0;
2097 if (!numChilds) return;
2098
2099 int numDataToMerge=0;
2100 MWAWBox2f partialBdBox;
2101 MWAWPosition partialPos(pos);
2102 MWAWInputStreamPtr &input= m_parserState->m_input;
2103 for (size_t c=0; c<numChilds; ++c) {
2104 long fId=group.m_childsList[c].m_fileId;
2105 auto fIt=m_state->m_framesMap.find(fId);
2106 if (fIt == m_state->m_framesMap.end() || fIt->first!=fId || !fIt->second) {
2107 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroupChild: can not find child %lx\n", static_cast<long unsigned int>(fId)));
2108 continue;
2109 }
2110 HanMacWrdKGraphInternal::Frame const &frame=*fIt->second;
2111 bool canMerge=false;
2112 if (frame.m_page==group.m_page) {
2113 switch (frame.m_type) {
2114 case 4: {
2115 auto const &text=static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame);
2116 canMerge=!text.isLinked()&&m_mainParser->canSendTextAsGraphic(text.m_textFileId,0);
2117 break;
2118 }
2119 case 8: // shape
2120 canMerge = true;
2121 break;
2122 case 11:
2123 canMerge = canCreateGraphic(static_cast<HanMacWrdKGraphInternal::Group const &>(frame));
2124 break;
2125 default:
2126 break;
2127 }
2128 }
2129 bool isLast=false;
2130 if (canMerge) {
2131 MWAWBox2f box=frame.getBdBox();
2132 if (numDataToMerge == 0)
2133 partialBdBox=box;
2134 else
2135 partialBdBox=partialBdBox.getUnion(box);
2136 ++numDataToMerge;
2137 if (c+1 < numChilds)
2138 continue;
2139 isLast=true;
2140 }
2141
2142 if (numDataToMerge>1) {
2143 partialBdBox.extend(3);
2144 MWAWGraphicEncoder graphicEncoder;
2145 MWAWGraphicListenerPtr graphicListener(new MWAWGraphicListener(*m_parserState, partialBdBox, &graphicEncoder));
2146 graphicListener->startDocument();
2147 size_t lastChild = isLast ? c : c-1;
2148 for (size_t ch=childNotSent; ch <= lastChild; ++ch) {
2149 long localFId=group.m_childsList[ch].m_fileId;
2150 fIt=m_state->m_framesMap.find(localFId);
2151 if (fIt == m_state->m_framesMap.end() || fIt->first!=localFId || !fIt->second)
2152 continue;
2153 HanMacWrdKGraphInternal::Frame const &child=*fIt->second;
2154 MWAWBox2f box=child.getBdBox();
2155 MWAWPosition pictPos(box[0], box.size(), librevenge::RVNG_POINT);
2156 pictPos.m_anchorTo=MWAWPosition::Page;
2157 switch (child.m_type) {
2158 case 4: {
2159 child.m_parsed=true;
2160 auto const &textbox=static_cast<HanMacWrdKGraphInternal::TextBox const &>(child);
2161 MWAWSubDocumentPtr subdoc
2162 (new HanMacWrdKGraphInternal::SubDocument(*this, input, HanMacWrdKGraphInternal::SubDocument::Text, textbox.m_textFileId));
2163 graphicListener->insertTextBox(pictPos, subdoc, textbox.m_style);
2164 break;
2165 }
2166 case 8: {
2167 child.m_parsed=true;
2168 auto const &shape=static_cast<HanMacWrdKGraphInternal::ShapeGraph const &>(child);
2169 graphicListener->insertShape(pictPos, shape.m_shape, shape.getStyle());
2170 break;
2171 }
2172 case 11:
2173 sendGroup(static_cast<HanMacWrdKGraphInternal::Group const &>(child), graphicListener);
2174 break;
2175 default:
2176 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroupChild: unexpected type %d\n", child.m_type));
2177 break;
2178 }
2179 }
2180 graphicListener->endDocument();
2181 MWAWEmbeddedObject picture;
2182 if (graphicEncoder.getBinaryResult(picture)) {
2183 partialPos.setOrigin(pos.origin()+partialBdBox[0]-group.m_pos[0]);
2184 partialPos.setSize(partialBdBox.size());
2185 listener->insertPicture(partialPos, picture);
2186 if (isLast)
2187 break;
2188 childNotSent=c;
2189 }
2190 }
2191
2192 // time to send back the data
2193 for (; childNotSent <= c; ++childNotSent) {
2194 long localFId=group.m_childsList[childNotSent].m_fileId;
2195 fIt=m_state->m_framesMap.find(localFId);
2196 if (fIt != m_state->m_framesMap.end() && fIt->first==localFId && fIt->second) {
2197 auto const &childFrame=*fIt->second;
2198 MWAWPosition fPos(pos);
2199 fPos.setOrigin(childFrame.m_pos[0]-group.m_pos[0]+pos.origin());
2200 fPos.setSize(childFrame.m_pos.size());
2201 sendFrame(childFrame, fPos);
2202 continue;
2203 }
2204 MWAW_DEBUG_MSG(("HanMacWrdKGraph::sendGroupChild: can not find child %lx\n", static_cast<long unsigned int>(localFId)));
2205 }
2206 numDataToMerge=0;
2207 }
2208 }
2209
2210 void HanMacWrdKGraph::prepareStructures()
2211 {
2212 for (auto const &fIt : m_state->m_framesMap) {
2213 if (!fIt.second) continue;
2214 HanMacWrdKGraphInternal::Frame const &frame = *fIt.second;
2215 if (frame.m_type==11 && !frame.m_inGroup) {
2216 std::multimap<long, long> seens;
2217 checkGroupStructures(fIt.first, frame.m_fileSubId, seens, false);
2218 }
2219 if (frame.m_type==4) {
2220 auto text=static_cast<HanMacWrdKGraphInternal::TextBox const &>(frame);
2221 size_t numLink=text.m_linkedIdList.size();
2222 for (size_t l=0; l < numLink; ++l) {
2223 auto fIt2=m_state->m_framesMap.find(text.m_linkedIdList[l]);
2224 if (fIt2==m_state->m_framesMap.end() || fIt2->first!=text.m_linkedIdList[l] || !fIt2->second || fIt2->second->m_type!=4) {
2225 MWAW_DEBUG_MSG(("HanMacWrdKGraph::prepareStructures: can not find frame %lx\n", static_cast<long unsigned int>(text.m_linkedIdList[l])));
2226 text.m_linkedIdList.resize(l);
2227 break;
2228 }
2229 auto &follow=static_cast<HanMacWrdKGraphInternal::TextBox &>(*fIt2->second);
2230 follow.m_isLinked=true;
2231 if (l+1!=numLink)
2232 follow.m_linkedIdList.push_back(text.m_linkedIdList[l+1]);
2233 }
2234 }
2235 }
2236 }
2237
2238 bool HanMacWrdKGraph::checkGroupStructures(long fileId, long fileSubId, std::multimap<long, long> &seens, bool inGroup)
2239 {
2240 auto it=seens.lower_bound(fileId);
2241 while (it!=seens.end() && it->first==fileId) {
2242 if (it->second != fileSubId)
2243 continue;
2244 MWAW_DEBUG_MSG(("HanMacWrdKGraph::checkGroupStructures: zone %ld[%ld] already find\n", fileId, fileSubId));
2245 return false;
2246 }
2247 seens.insert(std::multimap<long, long>::value_type(fileId, fileSubId));
2248 auto fIt = m_state->m_framesMap.lower_bound(fileId);
2249 for (; fIt != m_state->m_framesMap.end(); ++fIt) {
2250 if (fIt->first!=fileId) break;
2251 if (!fIt->second) continue;
2252 auto &frame = *fIt->second;
2253 frame.m_inGroup=inGroup;
2254 if (frame.m_fileSubId != fileSubId) continue;
2255 if (frame.m_type==11) {
2256 auto &group=static_cast<HanMacWrdKGraphInternal::Group &>(frame);
2257 for (size_t c=0; c < group.m_childsList.size(); ++c) {
2258 if (checkGroupStructures(group.m_childsList[c].m_fileId, 0, seens, true))
2259 continue;
2260 group.m_childsList.resize(c);
2261 break;
2262 }
2263 }
2264 return true;
2265 }
2266 MWAW_DEBUG_MSG(("HanMacWrdKGraph::checkGroupStructures: can not find zone %ld[%ld]\n", fileId, fileSubId));
2267 return true;
2268 }
2269
2270 ////////////////////////////////////////////////////////////
2271 // send data
2272 ////////////////////////////////////////////////////////////
2273 bool HanMacWrdKGraph::sendPageGraphics(std::vector<long> const &doNotSendIds)
2274 {
2275 std::set<long> notSend;
2276 for (auto const &id : doNotSendIds)
2277 notSend.insert(id);
2278 for (auto const &fIt : m_state->m_framesMap) {
2279 if (notSend.find(fIt.first) != notSend.end() || !fIt.second) continue;
2280 auto const &frame = *fIt.second;
2281 if (frame.m_parsed || frame.m_type==3 || frame.m_inGroup)
2282 continue;
2283 MWAWPosition pos(frame.m_pos[0],frame.m_pos.size(),librevenge::RVNG_POINT);
2284 pos.setRelativePosition(MWAWPosition::Page);
2285 pos.setPage(frame.m_page+1);
2286 sendFrame(frame, pos);
2287 }
2288 return true;
2289 }
2290
2291 void HanMacWrdKGraph::flushExtra()
2292 {
2293 for (auto const &fIt : m_state->m_framesMap) {
2294 if (!fIt.second) continue;
2295 auto const &frame = *fIt.second;
2296 if (frame.m_parsed || frame.m_type==3)
2297 continue;
2298 MWAWPosition pos(MWAWVec2f(0,0),MWAWVec2f(0,0),librevenge::RVNG_POINT);
2299 pos.setRelativePosition(MWAWPosition::Char);
2300 sendFrame(frame, pos);
2301 }
2302 for (auto const &pIt : m_state->m_picturesMap) {
2303 if (!pIt.second) continue;
2304 auto const &picture = *pIt.second;
2305 if (picture.m_parsed)
2306 continue;
2307 MWAWPosition pos(MWAWVec2f(0,0),MWAWVec2f(100,100),librevenge::RVNG_POINT);
2308 pos.setRelativePosition(MWAWPosition::Char);
2309 sendPicture(picture, pos);
2310 }
2311 }
2312 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: