Debian Codegraph @

src/lib/FullWrtText.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 <iomanip>
35 #include <iostream>
36 #include <limits>
37 #include <map>
38 #include <set>
39 #include <sstream>
40
41 #include <librevenge/librevenge.h>
42
43 #include "MWAWCell.hxx"
44 #include "MWAWTextListener.hxx"
45 #include "MWAWFont.hxx"
46 #include "MWAWFontConverter.hxx"
47 #include "MWAWParagraph.hxx"
48 #include "MWAWSection.hxx"
49 #include "MWAWTable.hxx"
50
51 #include "FullWrtParser.hxx"
52 #include "FullWrtStruct.hxx"
53
54 #include "FullWrtText.hxx"
55
56 #define DEBUGII 0
57
58 /** Internal: the structures of a FullWrtText */
59 namespace FullWrtTextInternal
60 {
61 /** Internal: class to store a para modifier with appear in docInfo */
62 struct ParaModifier {
63 //! constructor
64 ParaModifier()
65 : m_beforeSpacing(0)
66 , m_afterSpacing(0)
67 , m_extra("")
68 {
69 }
70 //! operator<<
71 friend std::ostream &operator<<(std::ostream &o, ParaModifier const &p)
72 {
73 if (p.m_beforeSpacing<0)
74 o << "befSpacing=" << -p.m_beforeSpacing << "pt,";
75 else if (p.m_beforeSpacing>0)
76 o << "befSpacing=" << p.m_beforeSpacing << "%,";
77 if (p.m_afterSpacing<0)
78 o << "aftSpacing=" << -p.m_afterSpacing << "pt,";
79 else if (p.m_afterSpacing>0)
80 o << "aftSpacing=" << p.m_afterSpacing << "%,";
81 o << p.m_extra;
82 return o;
83 }
84 //! the before spacing ( negative in point, positive in percent )
85 float m_beforeSpacing;
86 //! the after spacing ( negative in point, positive in percent )
87 float m_afterSpacing;
88 //! some extra data
89 std::string m_extra;
90 };
91
92 /** Internal: class to store a font/para modifier with appear in text data */
93 struct DataModifier {
94 //! constructor
95 DataModifier()
96 : m_color(MWAWColor::black())
97 , m_extra("")
98 {
99 for (auto &data : m_data) data=0xFFFF;
100 }
101 //! returns the superscript value ( negative in pt, position in li)
102 float getSuper() const
103 {
104 return float(int32_t((m_data[0]<<16)|m_data[1]))/65536.f;
105 }
106 //! returns the sub value ( negative in pt, position in li)
107 float getSub() const
108 {
109 return float(int32_t((m_data[2]<<16)|m_data[3]))/65536.f;
110 }
111 //! returns the border id
112 int getBorderId() const
113 {
114 return m_data[2]==0xFFFF?0:m_data[2];
115 }
116 //! returns the document extra id
117 int getDocParaId() const
118 {
119 return m_data[3];
120 }
121 //! operator<<
122 friend std::ostream &operator<<(std::ostream &o, DataModifier const &m)
123 {
124 if (!m.m_color.isBlack())
125 o << "col=" << m.m_color << ",";
126 if (m.m_data[1]!=0xFFFF)
127 o << "sup=" << m.getSuper() << ",";
128 if (m.m_data[3]!=0xFFFF)
129 o << "subs=" << m.getSub() << ",";
130 for (int i=0; i<2; i++) {
131 if (m.m_data[i] != 0xFFFF)
132 o << "f" << i << "=" << std::hex << m.m_data[i] << std::dec << ",";
133 }
134 if (m.m_data[2] && m.m_data[2]<20)
135 o << "bordId=" << m.m_data[2] << ",";
136 if (m.m_data[3] && m.m_data[3]<20)
137 o << "paraId=" << m.m_data[3] << ",";
138 o << m.m_extra;
139 return o;
140 }
141 //! the color
142 MWAWColor m_color;
143 //! the data
144 int m_data[4];
145 //! extra data
146 std::string m_extra;
147 };
148
149 struct Zone;
150
151 /** Internal: class to store an item state */
152 struct Item {
153 /** the different type of id */
154 enum Type { Father=0, Child, Next, Prev, Main };
155 /** constructor */
156 Item()
157 : m_level(0)
158 , m_index(1)
159 , m_collapsed(false)
160 , m_hidden(false)
161 , m_childList()
162 , m_hiddenZone()
163 , m_extra("")
164 {
165 for (auto &structId : m_structId) structId=0;
166 }
167 //! return a value which can be used to represent the label(changme)
168 std::string label() const
169 {
170 if (m_level <= 0) return "";
171 std::stringstream s;
172 s << m_index << ". ";
173 return s.str();
174 }
175 //! operator<<
176 friend std::ostream &operator<<(std::ostream &o, Item const &it)
177 {
178 if (it.m_hidden) o << "hidden,";
179 if (it.m_collapsed) o << "collapsed,";
180 if (it.m_level) o << "level=" << it.m_level << ",";
181 if (it.m_index!=1) o << "index=" << it.m_index << ",";
182 char const *wh[5]= {"father", "child", "next", "prev", "main"};
183 o << "zId=[";
184 for (int i = 0; i < 5; i++) {
185 if (it.m_structId[i]) o << wh[i] << "=" << it.m_structId[i] << ",";
186 }
187 o << "],";
188 o << it.m_extra;
189 return o;
190 }
191 //! the level
192 int m_level;
193 //! the actual index
194 int m_index;
195 //! true if the item is hidden
196 bool m_collapsed;
197 //! true if the item is hidden
198 bool m_hidden;
199 //! the list of childlist
200 std::vector<int> m_childList;
201 //! the hidden item zone
202 std::shared_ptr<Zone> m_hiddenZone;
203 //! the item id in text struct zone ( father, child, next, prev, main )
204 int m_structId[5];
205 //! extra data
206 std::string m_extra;
207 };
208
209 /** Internal: class to store a font and it state */
210 struct Font {
211 /** constructor */
212 Font()
213 : m_font()
214 , m_modifier()
215 , m_defModifier(true)
216 , m_item()
217 {
218 for (auto &state : m_state) state=false;
219 }
220 /** update the font using the modifier */
221 void update();
222 /** the font */
223 MWAWFont m_font;
224 /** the rendering state */
225 bool m_state[128];
226 /** the modifier data */
227 DataModifier m_modifier;
228 /** a flag to know if the data modifier is default */
229 bool m_defModifier;
230 /** the index */
231 Item m_item;
232 };
233
234 void Font::update()
235 {
236 if (m_state[9])
237 m_font.setColor(m_modifier.m_color);
238 else
239 m_font.setColor(MWAWColor(0,0,0));
240 if (m_state[0xa]) {
241 if (m_defModifier)
242 m_font.set(MWAWFont::Script::super100());
243 else {
244 float sup = m_modifier.getSuper();
245 if (sup < 0)
246 m_font.set(MWAWFont::Script(float(-sup),librevenge::RVNG_POINT));
247 else
248 m_font.set(MWAWFont::Script(float(sup*100.f),librevenge::RVNG_PERCENT));
249 }
250 }
251 else if (m_state[0xb]) {
252 if (m_defModifier)
253 m_font.set(MWAWFont::Script::sub100());
254 else {
255 float sub = m_modifier.getSub();
256 if (sub < 0)
257 m_font.set(MWAWFont::Script(float(sub),librevenge::RVNG_POINT));
258 else
259 m_font.set(MWAWFont::Script(float(-sub*100.f),librevenge::RVNG_PERCENT));
260 }
261 }
262 else
263 m_font.set(MWAWFont::Script());
264 }
265
266 /** Internal: class to store the LineHeader */
267 struct LineHeader {
268 /** Constructor */
269 LineHeader()
270 : m_numChar(0)
271 , m_font()
272 , m_fontSet(false)
273 , m_height(-1.0)
274 , m_prevHeight(-1.0)
275 , m_textIndent(0)
276 , m_extra("")
277 {
278 }
279 //! try to find the line height using m_height or m_prevHeight
280 float height() const
281 {
282 if (m_height > 0) return m_height;
283 return m_prevHeight;
284 }
285 //! operator<<
286 friend std::ostream &operator<<(std::ostream &o, LineHeader const &line)
287 {
288 o << "numC=" << line.m_numChar << ",";
289 if (line.m_fontSet)
290 o << "font=[fId=" << line.m_font.id()
291 << ",fSize=" << line.m_font.size() << "],";
292 if (line.m_height > 0) o << "height=" << line.m_height << ",";
293 if (line.m_textIndent.isSet()) o << "textIndent=" << *line.m_textIndent << ",";
294 o << line.m_extra;
295 return o;
296 }
297 /** the number of char */
298 int m_numChar;
299 /** the font */
300 MWAWFont m_font;
301 /** a flag to know if the font is set */
302 bool m_fontSet;
303 /** the line height in point ( if known) */
304 float m_height;
305 /** the previous line height in point ( if known) */
306 float m_prevHeight;
307 /** the text indent in inches ( if known) */
308 MWAWVariable<double> m_textIndent;
309 /** extra data */
310 std::string m_extra;
311 };
312 /** Internal: class to store a ColumnInfo */
313 struct ColumnInfo {
314 ColumnInfo()
315 : m_column(0)
316 , m_box()
317 , m_beginPos(1)
318 {
319 }
320
321 //! operator<<
322 friend std::ostream &operator<<(std::ostream &o, ColumnInfo const &c)
323 {
324 if (c.m_column > 0) o << "col=" << c.m_column+1 << ",";
325 o << c.m_box << ",";
326 if (c.m_beginPos > 1) o << "textPos=" << c.m_beginPos << ",";
327 return o;
328 }
329 //! the column number
330 int m_column;
331 //! the bdbox
332 MWAWBox2i m_box;
333 //! the first data
334 int m_beginPos;
335 };
336
337 struct PageInfo {
338 PageInfo()
339 : m_page(-1)
340 , m_columns()
341 {
342 }
343
344 //! returns true if the page has same color position
345 bool isSimilar(PageInfo const &p) const
346 {
347 size_t numColumns = m_columns.size();
348 if (numColumns != p.m_columns.size())
349 return false;
350 for (size_t c = 0; c < numColumns; c++) {
351 if (m_columns[c].m_box[0].x() != p.m_columns[c].m_box[0].x())
352 return false;
353 if (m_columns[c].m_box[1].x() != p.m_columns[c].m_box[1].x())
354 return false;
355 }
356 return true;
357 }
358
359 //! return a section
360 MWAWSection getSection() const
361 {
362 MWAWSection sec;
363 size_t numC = m_columns.size();
364 if (numC <= 1)
365 return sec;
366 sec.m_columns.resize(numC);
367 for (size_t c=0; c < numC; c++) {
368 MWAWSection::Column &col=sec.m_columns[c];
369 int prevPos= c ? (m_columns[c].m_box[0].x()+m_columns[c-1].m_box[1].x())/2 :
370 m_columns[c].m_box[0].x();
371 int nextPos= c+1!=numC ? (m_columns[c+1].m_box[0].x()+m_columns[c].m_box[1].x())/2 :
372 m_columns[c].m_box[1].x();
373 col.m_width = double(nextPos-prevPos);
374 col.m_widthUnit = librevenge::RVNG_POINT;
375 col.m_margins[libmwaw::Left]=double(m_columns[c].m_box[0].x()-prevPos)/72.;
376 col.m_margins[libmwaw::Right]=double(nextPos-m_columns[c].m_box[1].x())/72.;
377 }
378 return sec;
379 }
380 //! the pages
381 int m_page;
382 //! the columns
383 std::vector<ColumnInfo> m_columns;
384 };
385
386 /** Internal: class to store a text zone */
387 struct Zone {
388 //! the zone type
389 enum ZoneType { Normal, Main, CollapsedItem };
390 //! constructor
391 Zone()
392 : m_zone()
393 , m_box()
394 , m_begin(-1)
395 , m_end(-1)
396 , m_zoneType(Normal)
397 , m_pagesInfo()
398 , m_extra("")
399 {
400 for (auto &fl : m_flags) fl=0;
401 for (auto &p : m_pages) p=0;
402 }
403 //! operator<<
404 friend std::ostream &operator<<(std::ostream &o, Zone const &z)
405 {
406 switch (z.m_zoneType) {
407 case Zone::Normal:
408 break;
409 case Zone::Main:
410 o << "Main,";
411 break;
412 case Zone::CollapsedItem:
413 o << "Collapsed[item],";
414 break;
415 #if !defined(__clang__)
416 default:
417 o << "#type=" << z.m_zoneType << ",";
418 break;
419 #endif
420 }
421 if (z.m_zone) o << *z.m_zone << ",";
422 if (z.m_pages[0]) o << "firstP=" << z.m_pages[0] << ",";
423 if (z.m_pages[1] && z.m_pages[1] != z.m_pages[0])
424 o << "lastP=" << z.m_pages[1] << ",";
425 o << "Box=" << z.m_box << ",";
426 for (int i = 0; i < 2; i++) {
427 if (z.m_flags[i])
428 o << "fl" << i << "=" << z.m_flags[i] << ",";
429 }
430 if (z.m_end!=z.m_begin)
431 o << "sz=" << std::hex << z.m_end-z.m_begin << std::dec << ",";
432 if (z.m_extra.length())
433 o << "extra=[" << z.m_extra << "],";
434 return o;
435 }
436 //! return the col/page break
437 std::vector<int> getBreaksPosition() const
438 {
439 int prevPos = 0;
440 std::vector<int> res;
441 for (auto const &page : m_pagesInfo) {
442 for (auto const &column : page.m_columns) {
443 int pos = column.m_beginPos;
444 if (pos < prevPos) {
445 MWAW_DEBUG_MSG(("FullWrtTextInternal::Zone::getBreaksPosition pos go back\n"));
446 break;
447 }
448 res.push_back(pos);
449 prevPos = pos;
450 }
451 }
452 return res;
453 }
454 //! the main zone
455 FullWrtStruct::EntryPtr m_zone;
456 //! the bdbox
457 MWAWBox2f m_box;
458
459 //! the beginning of the text data
460 long m_begin;
461 //! the end of the text data
462 long m_end;
463 //! the zone type
464 ZoneType m_zoneType;
465 //! the zone flags, header|footer, normal|extra
466 int m_flags[2];
467 //! the pages
468 int m_pages[2];
469 //! the pages info
470 std::vector<PageInfo> m_pagesInfo;
471 //! the extra data ( for debugging )
472 std::string m_extra;
473 };
474
475 /** Internal: class to store the paragraph properties */
476 struct Paragraph final : public MWAWParagraph {
477 //! Constructor
478 Paragraph()
479 : MWAWParagraph()
480 , m_align(0)
481 , m_interSpacing(1.)
482 , m_interSpacingUnit(librevenge::RVNG_PERCENT)
483 , m_dim(0,0)
484 , m_border()
485 , m_isTable(false)
486 , m_tableBorderId(0)
487 , m_tableFlags()
488 , m_actCol(-1)
489 , m_isSent(false)
490 {
491 for (auto &space : m_befAftSpacings) space=0;
492 }
493 Paragraph(Paragraph const &)=default;
494 //! destructor
495 ~Paragraph() final;
496 //! operator<<
497 friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind)
498 {
499 if (ind.m_isTable) o << "table,";
500 if (ind.m_tableBorderId) o << "borderId[table]=" << ind.m_tableBorderId << ",";
501 if (ind.m_align) o << "align=" << ind.m_align << ",";
502 if (ind.m_dim[0]>0 || ind.m_dim[1]>0) o << "dim=" << ind.m_dim << ",";
503 o << static_cast<MWAWParagraph const &>(ind);
504 return o;
505 }
506
507 //! returns true if this is a table
508 bool isTable() const
509 {
510 return m_isTable;
511 }
512
513 //! set the align type
514 void setAlign(int align)
515 {
516 m_align = align;
517 m_isSent = false;
518 }
519 //! set the interline spacing
520 void setInterlineSpacing(double spacing, librevenge::RVNGUnit unit)
521 {
522 m_interSpacing = spacing;
523 m_interSpacingUnit = unit;
524 m_isSent = false;
525 }
526 //! set the before/after spacing ( negative in point, positive in percent )
527 void setSpacings(double spacing, bool before)
528 {
529 m_befAftSpacings[before ? 0 : 1] = spacing;
530 m_isSent = false;
531 }
532 //! set the border type
533 void setBorder(FullWrtStruct::Border const &border)
534 {
535 m_border = border;
536 m_isSent = false;
537 }
538
539 //! update the paragraph data from a ruler
540 void updateFromRuler(Paragraph const &ruler)
541 {
542 MWAWParagraph::operator=(ruler);
543 m_isTable = ruler.m_isTable;
544 m_tableBorderId = ruler.m_tableBorderId;
545 m_tableFlags = ruler.m_tableFlags;
546 m_dim = ruler.m_dim;
547 m_isSent = false;
548 }
549 //! returns the table dimension in points
550 bool getTableDimensions(std::vector<float> &dim) const
551 {
552 size_t numTabs = m_tabs->size();
553 if ((numTabs%2) != 1 || numTabs != m_tableFlags.size()) {
554 MWAW_DEBUG_MSG(("FullWrtTextInternal::Paragraph:getTableDimensions: unexpected number of tabs\n"));
555 return false;
556 }
557 if (m_dim[0] <= 0) {
558 MWAW_DEBUG_MSG(("FullWrtTextInternal::Paragraph:getTableDimensions: can not determine line width\n"));
559 return false;
560 }
561 std::vector<double> limits;
562 limits.push_back(*m_margins[1]);
563 for (size_t i=1; i < numTabs; i+=2) {
564 if (m_tableFlags[i] != 4) {
565 MWAW_DEBUG_MSG(("FullWrtTextInternal::Paragraph:getTableDimensions: find unexpected tables flags\n"));
566 return false;
567 }
568 limits.push_back((*m_tabs)[i].m_position);
569 }
570 limits.push_back(double(m_dim[0])-*m_margins[2]);
571 dim.resize(limits.size()-1);
572 for (size_t i=0; i < dim.size(); i++)
573 dim[i] = 72.f*float(limits[i+1]-limits[i]);
574 return true;
575 }
576 //! update the paragraph data to be sent to a listener
577 MWAWParagraph updateToSent() const
578 {
579 m_isSent = true;
580 MWAWParagraph res = *this;
581 if (m_interSpacing>0)
582 res.setInterline(m_interSpacing, m_interSpacingUnit);
583 for (int i = 0; i < 2; i++) {
584 if (m_befAftSpacings[i] <= 0)
585 res.m_spacings[i+1]=(-m_befAftSpacings[i])/72.0;
586 else // ok suppose line of height 9
587 res.m_spacings[i+1]=(m_befAftSpacings[i])*9.0/72.0;
588 }
589 if (!m_border.m_backColor.isWhite())
590 res.m_backgroundColor = m_border.m_backColor;
591
592 if (m_isTable && m_actCol >= 0) {
593 if (2*m_actCol < int(m_tableFlags.size())) {
594 switch (m_tableFlags[size_t(2*m_actCol)]) {
595 case 0:
596 res.m_justify = MWAWParagraph::JustificationLeft;
597 break;
598 case 1:
599 res.m_justify = MWAWParagraph::JustificationCenter;
600 break;
601 case 2:
602 case 5:
603 res.m_justify = MWAWParagraph::JustificationFull;
604 break;
605 case 3:
606 res.m_justify = MWAWParagraph::JustificationRight;
607 break;
608 case 6:
609 res.m_justify = MWAWParagraph::JustificationFullAllLines;
610 break;
611 default:
612 break;
613 }
614 }
615 res.m_tabs->resize(0);
616 m_actCol=-1;
617 return res;
618 }
619 switch (m_align) {
620 case 0:
621 res.m_justify = MWAWParagraph::JustificationLeft;
622 break;
623 case 1:
624 res.m_justify = MWAWParagraph::JustificationCenter;
625 break;
626 case 2:
627 res.m_justify = MWAWParagraph::JustificationFull;
628 break;
629 case 3:
630 res.m_justify = MWAWParagraph::JustificationRight;
631 break;
632 default:
633 break;
634 }
635 res.m_borders = m_border.getParagraphBorders();
636 return res;
637 }
638
639 //! the align value
640 int m_align;
641 //! the spacing
642 double m_interSpacing;
643 //! the spacing unit
644 librevenge::RVNGUnit m_interSpacingUnit;
645 //! the before/after spacing ( negative in point, positive in percent)
646 double m_befAftSpacings[2];
647 //! the zone dimension
648 MWAWVec2f m_dim;
649 //! the actual border
650 FullWrtStruct::Border m_border;
651 //! a flag to know if this is a table
652 bool m_isTable;
653 //! the table border id
654 int m_tableBorderId;
655 //! the list of table limit
656 std::vector<int> m_tableFlags;
657 //! the index of the actual column to send
658 mutable int m_actCol;
659 //! a flag to know if the parser is send or not
660 mutable bool m_isSent;
661 };
662
663 Paragraph::~Paragraph()
664 {
665 }
666
667 ////////////////////////////////////////
668 //! Internal: the state of a FullWrtText
669 struct State {
670 //! constructor
671 State()
672 : m_version(-1)
673 , m_entryMap()
674 , m_paragraphMap()
675 , m_itemMap()
676 , m_dataModMap()
677 , m_paragraphModList()
678 , m_mainZones()
679 , m_numPages(1)
680 , m_actualPage(0)
681 {
682 }
683
684 //! the file version
685 mutable int m_version;
686
687 //! zoneId -> entry
688 std::multimap<int, std::shared_ptr<Zone> > m_entryMap;
689 //! rulerId -> ruler
690 std::map<int, Paragraph> m_paragraphMap;
691 //! itemId -> item
692 std::map<int, Item> m_itemMap;
693 //! modId -> font/paragraph modifier
694 std::map<int, DataModifier> m_dataModMap;
695 //! a list of paragraph modifier
696 std::vector<ParaModifier> m_paragraphModList;
697
698 //! the main zone index
699 std::vector<int> m_mainZones;
700
701 int m_numPages /* the number of pages */, m_actualPage /* the actual page */;
702 };
703 }
704
705 ////////////////////////////////////////////////////////////
706 // constructor/destructor, ...
707 ////////////////////////////////////////////////////////////
708 FullWrtText::FullWrtText(FullWrtParser &parser)
709 : m_parserState(parser.getParserState())
710 , m_state(new FullWrtTextInternal::State)
711 , m_mainParser(&parser)
712 {
713 }
714
715 FullWrtText::~FullWrtText()
716 {
717 }
718
719 int FullWrtText::version() const
720 {
721 if (m_state->m_version < 0)
722 m_state->m_version = m_parserState->m_version;
723 return m_state->m_version;
724 }
725
726 int FullWrtText::numPages() const
727 {
728 return m_state->m_numPages;
729 }
730
731 ////////////////////////////////////////////////////////////
732 // Intermediate level
733 ////////////////////////////////////////////////////////////
734 void FullWrtText::send(std::shared_ptr<FullWrtTextInternal::Zone> zone, int numChar,
735 FullWrtTextInternal::Font &font, FullWrtTextInternal::Paragraph &ruler,
736 std::string &str)
737 {
738 MWAWTextListenerPtr listener=m_parserState->m_textListener;
739 if (!listener) return;
740 MWAWInputStreamPtr input = zone->m_zone->m_input;
741 long pos = input->tell();
742 long endPos = pos+numChar;
743 bool nextIsChar = false;
744 bool fCharSent = false, lastEOL=false, fontSet = false, checkModifier = false;
745
746 libmwaw::DebugStream f;
747 for (int i = 0; i < numChar; i++) {
748 long actPos = input->tell();
749 if (actPos >= endPos)
750 break;
751 auto val = static_cast<int>(input->readULong(1));
752 bool done = false;
753 int id=-1;
754 if (nextIsChar)
755 nextIsChar = false;
756 else {
757 done = true;
758 uint32_t fFlags = font.m_font.flags();
759 bool on = false;
760 if (val >= 0x80)
761 on=font.m_state[val-0x80]=!font.m_state[val-0x80];
762 std::string onString(on?"":"/");
763 switch (val) {
764 case 0:
765 val=' ';
766 done = false;
767 break; // space
768 case 0x80:
769 f << "[" << onString << "80]";
770 break; // often found by pair consecutively : selection ?
771 case 0x81:
772 f << "[" << onString << "81]";
773 break; // often found by pair around a " " a ","...
774 case 0x82:
775 f << "[" << onString << "82]";
776 break; // find one time around a first capital letter I
777 case 0x83:
778 f << "[" << onString << "b]";
779 fFlags ^= MWAWFont::boldBit;
780 font.m_font.setFlags(fFlags);
781 fontSet=false;
782 break;
783 case 0x84:
784 f << "[" << onString << "i]";
785 fFlags ^= MWAWFont::italicBit;
786 font.m_font.setFlags(fFlags);
787 fontSet=false;
788 break;
789 case 0x86:
790 f << "[" << onString << "outline]";
791 fFlags ^= MWAWFont::outlineBit;
792 font.m_font.setFlags(fFlags);
793 fontSet=false;
794 break;
795 case 0x87:
796 f << "[" << onString << "shadow]";
797 fFlags ^= MWAWFont::shadowBit;
798 font.m_font.setFlags(fFlags);
799 fontSet=false;
800 break;
801 case 0x88:
802 f << "[" << onString << "smallcap]";
803 fFlags ^= MWAWFont::smallCapsBit;
804 font.m_font.setFlags(fFlags);
805 fontSet=false;
806 break;
807 case 0x89:
808 f << "[" << onString << "color]";
809 checkModifier=true;
810 break;
811 case 0x8a:
812 f << "[" << onString << "super]";
813 checkModifier=true;
814 break;
815 case 0x8b: // subs
816 f << "[" << onString << "sub]";
817 checkModifier=true;
818 break;
819 case 0x8c:
820 f << "[" << onString << "strike]";
821 if (on)
822 font.m_font.setStrikeOutStyle(MWAWFont::Line::Simple);
823 else
824 font.m_font.setStrikeOutStyle(MWAWFont::Line::None);
825 fontSet=false;
826 break;
827 case 0x90: // condensed
828 case 0x91: // expand
829 f << "[" << onString << (val==0x90?"condensed":"expand") << "]";
830 font.m_font.setDeltaLetterSpacing
831 (float((font.m_state[0x10]?-1:0)+(font.m_state[0x11]?1:0)));
832 fontSet=false;
833 break;
834 case 0x85: // normal underline
835 case 0x8e: // word underline
836 case 0x8f: // double
837 case 0x92: { // dot
838 switch (val) {
839 case 0x85:
840 f << "[" << onString << "underline]";
841 break;
842 case 0x8e:
843 f << "[" << onString << "underline:word]";
844 break;
845 case 0x8f:
846 f << "[" << onString << "underline:double]";
847 break;
848 default:
849 case 0x92:
850 f << "[" << onString << "underline:dot]";
851 break;
852 }
853 if (font.m_state[0x12])
854 font.m_font.setUnderlineStyle(MWAWFont::Line::Dot);
855 else if (font.m_state[0x5]||font.m_state[0xe]|| font.m_state[0xf])
856 font.m_font.setUnderlineStyle(MWAWFont::Line::Simple);
857 else
858 font.m_font.setUnderlineStyle(MWAWFont::Line::None);
859 if (font.m_state[0xf])
860 font.m_font.setUnderlineType(MWAWFont::Line::Double);
861 if (font.m_state[0xe])
862 font.m_font.setUnderlineWordFlag(true);
863 fontSet=false;
864 break;
865 }
866 case 0x93:
867 f << "[" << onString << "overline]";
868 if (on)
869 font.m_font.setOverlineStyle(MWAWFont::Line::Simple);
870 else
871 font.m_font.setOverlineStyle(MWAWFont::Line::None);
872 fontSet=false;
873 break;
874 case 0x94:
875 f << "[" << onString << "allCaps]";
876 fFlags ^= MWAWFont::uppercaseBit;
877 font.m_font.setFlags(fFlags);
878 fontSet=false;
879 break;
880 case 0x95:
881 f << "[" << onString << "lowercase]";
882 fFlags ^= MWAWFont::lowercaseBit;
883 font.m_font.setFlags(fFlags);
884 fontSet=false;
885 break;
886 case 0xa7: // fixme appear also as tabs separator
887 f << "[tab]";
888 listener->insertTab();
889 break;
890 case 0xac:
891 // we must wait sending font/ruler then we will send the data
892 done = false;
893 break;
894 case 0xae: // insecable-
895 f << "-";
896 val=0x2011;
897 done = false;
898 break;
899 case 0xb2:
900 if (actPos+1 > endPos) {
901 MWAW_DEBUG_MSG(("FullWrtText::send: can not find font size!!!!\n"));
902 f << "[##fSz]";
903 break;
904 }
905 font.m_font.setSize(float(input->readULong(1)));
906 f << "[fSz=" << font.m_font.size() << "]";
907 fontSet=false;
908 break;
909 case 0xb3:
910 nextIsChar = true;
911 break;
912 case 0xc1:
913 if (actPos+2 > endPos) {
914 MWAW_DEBUG_MSG(("FullWrtText::send: can not find font id!!!!\n"));
915 f << "[##fId]";
916 break;
917 }
918 font.m_font.setId(static_cast<int>(input->readULong(2)));
919 f << "[fId=" << font.m_font.size() << "]";
920 fontSet = false;
921 break;
922 case 0xc7: // item id
923 if (actPos+2 > endPos) {
924 MWAW_DEBUG_MSG(("FullWrtText::send: can not find item id!!!!\n"));
925 f << "[##item]";
926 break;
927 }
928 if (font.m_item.m_collapsed && font.m_item.m_childList.size()) {
929 if (!lastEOL)
930 listener->insertEOL(false);
931 auto hFont = font;
932 auto hRuler = ruler;
933 for (auto item : font.m_item.m_childList)
934 sendHiddenItem(item, hFont, hRuler);
935 fontSet = false;
936 ruler.m_isSent=false;
937 lastEOL=false;
938 }
939 id = static_cast<int>(input->readULong(2));
940 if (m_state->m_itemMap.find(id) == m_state->m_itemMap.end()) {
941 MWAW_DEBUG_MSG(("FullWrtText::send: can not find item id!!!!\n"));
942 font.m_item = FullWrtTextInternal::Item();
943 f << "[#itemId=" << id << "]";
944 }
945 else {
946 font.m_item =m_state->m_itemMap.find(id)->second;
947 f << "[item:" << font.m_item << ",id=" << id << "]";
948 }
949 break;
950 case 0xcb: { // space/and or color
951 if (actPos+2 > endPos) {
952 MWAW_DEBUG_MSG(("FullWrtText::send: can not read data modifier!!!!\n"));
953 f << "[##dMod]";
954 break;
955 }
956 id = static_cast<int>(input->readULong(2));
957 if (m_state->m_dataModMap.find(id) == m_state->m_dataModMap.end()) {
958 font.m_modifier=FullWrtTextInternal::DataModifier();
959 font.m_defModifier=true;
960 f << "[#modifier=" << id << "]";
961 }
962 else {
963 font.m_modifier=m_state->m_dataModMap.find(id)->second;
964 f << "[modifier=" << font.m_modifier << "]";
965 font.m_defModifier=false;
966 }
967
968 // can be a paragraph modifier
969 if (fCharSent) break;
970 int pId = font.m_modifier.getDocParaId();
971 if (pId >= 0 && pId < int(m_state->m_paragraphModList.size())) {
972 auto const &paraMod = m_state->m_paragraphModList[size_t(pId)];
973 ruler.setSpacings(double(paraMod.m_beforeSpacing), true);
974 ruler.setSpacings(double(paraMod.m_afterSpacing), false);
975 ruler.setBorder(FullWrtStruct::Border());
976 checkModifier = true;
977 }
978 int bId = font.m_modifier.getBorderId();
979 FullWrtStruct::Border border;
980 if (m_mainParser->getBorder(bId, border)) {
981 ruler.setBorder(border);
982 checkModifier = true;
983 }
984 break;
985 }
986 case 0xd2:
987 case 0xd3:
988 case 0xd5:
989 case 0xdc:
990 case 0xe1:
991 case 0xe2:
992 case 0xe4:
993 if (actPos+2 > endPos) {
994 MWAW_DEBUG_MSG(("FullWrtText::send: can not an id for %x!!!!\n", static_cast<unsigned int>(val)));
995 f << "[#" << std::hex << val << std::dec << "]";
996 break;
997 }
998 id = static_cast<int>(input->readULong(2));
999 done = false; // we must wait sending font/ruler then we will send the data
1000 switch (val) {
1001 case 0xd2:
1002 f << "[noteId=" << id << "]";
1003 break;
1004 case 0xd3:
1005 f << "[footnoteId=" << id << "]";
1006 break;
1007 case 0xd5:
1008 f << "[endnoteId=" << id << "]";
1009 break;
1010 case 0xdc:
1011 f << "[graphId=" << id << "]";
1012 break;
1013 case 0xe1: // reference field
1014 done=true;
1015 f << "[refDefId=" << id << "]";
1016 break;
1017 case 0xe2:
1018 f << "[refId=" << id << "]";
1019 break;
1020 case 0xe4:
1021 f << "[variableId=" << id << "]";
1022 break;
1023 default:
1024 break;
1025 }
1026 break;
1027 case 0xa0: // potential hypen break
1028 f << "[hyp]";
1029 if (actPos+1==endPos) {
1030 val = '-';
1031 done = false;
1032 }
1033 break;
1034 case 0x98: // soft break
1035 f << "\\n";
1036 done = false;
1037 break;
1038 case 0x96: // field end
1039 f << "[FEnd]";
1040 break;
1041 case 0x9b: // align
1042 case 0x9c:
1043 ruler.setAlign(ruler.m_align^(val-0x9a));
1044 f << "[" << onString << "align" << (val-0x9b) << "]";
1045 break;
1046 case 0x9d: // justication
1047 case 0x9e:
1048 case 0x9f: {
1049 double justify=1.0+double(val-0x9d)/2.0;
1050 ruler.setInterlineSpacing(justify, librevenge::RVNG_PERCENT);
1051 f << "[just=" << 100*justify << "%]";
1052 break;
1053 }
1054 case 0xa4:
1055 f << "emptyItem?,";
1056 break;
1057 case 0xa8:
1058 f << "\\n";
1059 done = false;
1060 break;
1061 case 0xab: // begin of line
1062 f << "\\{";
1063 break;
1064 case 0xc6: { // ruler id
1065 if (actPos+2 > endPos) {
1066 MWAW_DEBUG_MSG(("FullWrtText::send: can find rulerId!!!!\n"));
1067 f << "[##rulerId]";
1068 break;
1069 }
1070 id = int(input->readULong(2));
1071 f << "[P" << id << "]";
1072
1073 auto it=m_state->m_paragraphMap.find(id);
1074 if (it==m_state->m_paragraphMap.end()) {
1075 MWAW_DEBUG_MSG(("FullWrtText::send: can not find paragraph with id=%d\n", id));
1076 break;
1077 }
1078 ruler.updateFromRuler(it->second);
1079 // do not add a break line for a simple ruler
1080 if (i<=1)
1081 lastEOL=true;
1082 break;
1083 }
1084 case 0xe8: // justification
1085 if (actPos+4 > endPos) {
1086 MWAW_DEBUG_MSG(("FullWrtText::send: can not find justify!!!!\n"));
1087 f << "[#justWithType]";
1088 }
1089 else {
1090 auto just = static_cast<int>(input->readLong(2));
1091 if (just < 0)
1092 ruler.setInterlineSpacing(-just, librevenge::RVNG_POINT);
1093 f << "[just=" << just << ",";
1094 f << "typ?=" << static_cast<int>(input->readLong(2)) << "]";
1095 }
1096 break; // ok
1097 case 0x8d: // unknown
1098 case 0x97:
1099 case 0x9a:
1100 case 0xa1:
1101 case 0xa9:
1102 case 0xaa:
1103 f << "[" << onString << std::hex << val << std::dec << "]";
1104 break;
1105 case 0xca: // unknown
1106 case 0xcd:
1107 case 0xd0: // header
1108 case 0xd1: // footer ?
1109 case 0xd4: // contents
1110 case 0xd6: // biblio
1111 case 0xd7: // entry
1112 case 0xd9:
1113 case 0xda:
1114 case 0xe5: // contents/index data
1115 if (actPos+2 > endPos) {
1116 MWAW_DEBUG_MSG(("FullWrtText::send: can find id for %x data!!!!\n", static_cast<unsigned int>(val)));
1117 f << "[##" << std::hex << val << std::dec << "]";
1118 break;
1119 }
1120 id = static_cast<int>(input->readULong(2));
1121 if (val==0xd0) f << "[headerId=" << id << "]";
1122 else if (val==0xd1) f << "[footerId=" << id << "]";
1123 else f << "[" << std::hex << val << std::dec << "Id=" << val << "]";
1124 break;
1125 case 0xe9:
1126 if (actPos+4 > endPos) {
1127 MWAW_DEBUG_MSG(("FullWrtText::send: can not find id/val for fe9!!!!\n"));
1128 f << "[#e9]";
1129 break;
1130 }
1131 id = int(input->readULong(2));
1132 f << "[e9=" << id << ":" << input->readULong(2) << "]";
1133 break;
1134 default:
1135 done = false;
1136 break;
1137 }
1138 }
1139 if (checkModifier && (!done || input->tell() == endPos)) {
1140 font.update();
1141 fontSet = false;
1142 }
1143 if (done)
1144 continue;
1145
1146 if (!fCharSent && !ruler.m_isSent)
1147 listener->setParagraph(ruler.updateToSent());
1148 if (!fontSet) {
1149 listener->setFont(font.m_font);
1150 fontSet = true;
1151 }
1152 fCharSent = true;
1153 lastEOL = false;
1154 // now, we can try to send the data
1155 if (id >= 0 || val==0xa8 || val==0x98 || val==0xac) {
1156 done = true;
1157 switch (val) {
1158 case 0x98:
1159 listener->insertEOL(true);
1160 break;
1161 case 0xa8:
1162 lastEOL = true;
1163 listener->insertEOL();
1164 break;
1165 case 0xac: {
1166 std::string label=font.m_item.label();
1167 if (label.length())
1168 listener->insertUnicodeString(librevenge::RVNGString(label.c_str()));
1169 break;
1170 }
1171 case 0xd2:
1172 m_mainParser->sendText(id, libmwaw::DOC_COMMENT_ANNOTATION);
1173 break;
1174 case 0xd3:
1175 m_mainParser->sendText(id, libmwaw::DOC_NOTE, MWAWNote::FootNote);
1176 break;
1177 case 0xd5:
1178 m_mainParser->sendText(id, libmwaw::DOC_NOTE, MWAWNote::EndNote);
1179 break;
1180 case 0xdc:
1181 m_mainParser->sendGraphic(id);
1182 break;
1183 case 0xe2:
1184 m_mainParser->sendReference(id);
1185 break;
1186 case 0xe4:
1187 m_mainParser->sendVariable(id);
1188 break;
1189 default:
1190 done = false;
1191 break;
1192 }
1193 }
1194 if (done)
1195 continue;
1196 if (val >= 256)
1197 listener->insertUnicode(static_cast<uint32_t>(val));
1198 else {
1199 i += listener->insertCharacter
1200 (static_cast<unsigned char>(val), input, input->tell()+(numChar-1-i));
1201 if (val <= 0x1f)
1202 f << "#[" << std::hex << val << "]";
1203 else
1204 f << char(val);
1205 }
1206 }
1207 if (!fCharSent && !ruler.m_isSent)
1208 listener->setParagraph(ruler.updateToSent());
1209 if (!lastEOL)
1210 listener->insertEOL(false);
1211 str=f.str();
1212 }
1213
1214 bool FullWrtText::sendTable(std::shared_ptr<FullWrtTextInternal::Zone> zone, FullWrtTextInternal::LineHeader const &lHeader,
1215 FullWrtTextInternal::Font &font, FullWrtTextInternal::Paragraph &ruler, std::string &str)
1216 {
1217 std::vector<float> dim;
1218 if (!ruler.getTableDimensions(dim))
1219 return false;
1220 float height=lHeader.height();
1221 if (height <= 0) {
1222 MWAW_DEBUG_MSG(("FullWrtText::sendTable: can not find table height\n"));
1223 return false;
1224 }
1225
1226 size_t numCols = dim.size();
1227 MWAWTextListenerPtr listener=m_parserState->m_textListener;
1228 if (!listener) return false;
1229
1230 MWAWInputStreamPtr input = zone->m_zone->m_input;
1231 long pos = input->tell();
1232 long endPos=pos+lHeader.m_numChar;
1233 std::vector<long> cellPos;
1234 cellPos.push_back(pos);
1235 for (int i = 0; i < lHeader.m_numChar; i++) {
1236 long actPos = input->tell();
1237 if (input->isEnd())
1238 break;
1239 auto c = static_cast<int>(input->readULong(1));
1240 if (c==0xa7) {
1241 cellPos.push_back(actPos);
1242 cellPos.push_back(actPos+1);
1243 }
1244 // special case: an item implies a column shift
1245 if (c==0xac) {
1246 cellPos.push_back(actPos+1);
1247 cellPos.push_back(actPos+1);
1248 }
1249 }
1250 cellPos.push_back(endPos);
1251
1252 size_t numFind=cellPos.size()/2;
1253 if (numCols < numFind) {
1254 if (numCols+1==numFind) {
1255 // happens one type at the end of file: bug or normal end table?
1256 MWAW_DEBUG_MSG(("FullWrtText::sendTable: find a spurious column break in last line position\n"));
1257 cellPos.resize(2*numCols);
1258 }
1259 else {
1260 MWAW_DEBUG_MSG(("FullWrtText::sendTable: find too many columns\n"));
1261 return false;
1262 }
1263 }
1264
1265 // ok, we have the limit of the text, let works...
1266 libmwaw::DebugStream f;
1267 MWAWTable table(MWAWTable::TableDimBit);
1268 table.setColsSize(dim);
1269 listener->openTable(table);
1270 listener->openTableRow(-height, librevenge::RVNG_POINT);
1271
1272 MWAWBorder outBorder, vBorder;
1273 FullWrtStruct::Border border;
1274 if (m_mainParser->getBorder(ruler.m_tableBorderId, border)) {
1275 outBorder=FullWrtStruct::Border::getBorder(border.m_type[0]);
1276 vBorder=FullWrtStruct::Border::getBorder(border.m_type[2]);
1277 outBorder.m_color=vBorder.m_color=border.m_color[0];
1278 }
1279 else {
1280 MWAW_DEBUG_MSG(("FullWrtText::sendTable: can not find border=%d\n",ruler.m_tableBorderId));
1281 outBorder.m_width=vBorder.m_width=0;
1282 }
1283 for (size_t col = 0; col < numCols; col++) {
1284 MWAWCell cell;
1285 MWAWVec2i cellPosition(MWAWVec2i(0,static_cast<int>(col)));
1286 cell.setPosition(cellPosition);
1287 if (ruler.m_tableBorderId) {
1288 cell.setBorders(0xf, outBorder);
1289 if (col > 0)
1290 cell.setBorders(libmwaw::LeftBit, vBorder);
1291 if (col+1 < numCols)
1292 cell.setBorders(libmwaw::RightBit, vBorder);
1293 }
1294 listener->openTableCell(cell);
1295
1296 if (col < numFind) {
1297 if (cellPos[2*col+1]>cellPos[2*col]) {
1298 std::string string;
1299 input->seek(cellPos[2*col], librevenge::RVNG_SEEK_SET);
1300 ruler.m_actCol=int(col);
1301 ruler.m_isSent=false;
1302 send(zone, int(cellPos[2*col+1]-cellPos[2*col]), font, ruler, string);
1303 f << string;
1304 }
1305 }
1306 if (col+1 != numCols)
1307 f << "[col]";
1308 listener->closeTableCell();
1309 }
1310 listener->closeTableRow();
1311 listener->closeTable();
1312 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1313 str=f.str();
1314 return true;
1315 }
1316
1317 bool FullWrtText::readLineHeader(std::shared_ptr<FullWrtTextInternal::Zone> zone, FullWrtTextInternal::LineHeader &lHeader)
1318 {
1319 lHeader = FullWrtTextInternal::LineHeader();
1320
1321 MWAWInputStreamPtr input = zone->m_zone->m_input;
1322 libmwaw::DebugStream f;
1323 long pos = input->tell();
1324
1325 auto type = static_cast<int>(input->readULong(2));
1326 int lengthSz = 1;
1327 if (type & 0x8000)
1328 lengthSz = 2;
1329
1330 lHeader.m_numChar = static_cast<int>(input->readULong(lengthSz));
1331 if ((lengthSz==1 && (lHeader.m_numChar & 0x80)) ||
1332 pos+2+lHeader.m_numChar > zone->m_end) {
1333 input->seek(pos, librevenge::RVNG_SEEK_SET);
1334 return false;
1335 }
1336
1337 int val;
1338 if (type & 0x4000) {
1339 f << "f0=[";
1340 lHeader.m_height = float(input->readLong(4))/256.f;
1341 val = static_cast<int>(input->readLong(2)); // 0 or -1
1342 if (val == -1) f << "*,";
1343 else if (val) f << "unkn2=" << val << ",";
1344 val = static_cast<int>(input->readLong(2)); // small number between 20 and -20?
1345 if (val) f << "N1=" << float(val)/256.0f << ",";
1346 val = static_cast<int>(input->readLong(2));
1347 if (val)
1348 lHeader.m_textIndent = double(val)/72.;
1349 f << "w=" << static_cast<int>(input->readLong(2)) << ",";
1350 f << "],";
1351 }
1352 if (type & 0x2000) {
1353 // small number between 1 and 4
1354 f << "f1=" << static_cast<int>(input->readLong(1)) << ",";
1355 }
1356 if (type & 0x1000) {
1357 // small number between 1 and 2
1358 f << "f2=" << static_cast<int>(input->readLong(1)) << ",";
1359 }
1360 if (type & 0x800) {
1361 // small number between 1 and 2
1362 f << "f3=" << static_cast<int>(input->readLong(1)) << ",";
1363 }
1364 if (type & 0x400) {
1365 // small number 1
1366 f << "f4=" << static_cast<int>(input->readLong(1)) << ",";
1367 }
1368 if (type & 0x200) {
1369 // small int between 0 and 0x4f : ident ?
1370 f << "f5=" << static_cast<int>(input->readLong(2)) << ",";
1371 }
1372 if (type & 0x100) {
1373 // small int between 0 and 0xb0 : ident ?
1374 f << "f6=" << static_cast<int>(input->readLong(2)) << ",";
1375 }
1376 if (type & 0x80) {
1377 // small int between 0 and 0x5b : ident ?
1378 f << "f7=" << static_cast<int>(input->readLong(2)) << ",";
1379 }
1380 if (type & 0x40) {
1381 // small int between 0 and 0xcf : link to rulerid in data struct?
1382 val = static_cast<int>(input->readLong(2));
1383 if (val)
1384 f << "P" << val << ",";
1385 }
1386 if (type & 0x20) {
1387 /* first small number:
1388 0|10|80|81, 0|1|2|4|10,
1389 last small number 0|1|...|7|e|10|11|20|21|23|40|41
1390 &1 line continue ?
1391 &2 new page ?
1392 */
1393 f << "f9=[";
1394 for (int i = 0; i < 4; i++) {
1395 val = static_cast<int>(input->readULong(1));
1396 if (val) f << std::hex << val << std::dec << ",";
1397 else f << "_,";
1398 }
1399 f << "],";
1400 }
1401 if (type & 0x10) {
1402 auto fId = static_cast<int>(input->readLong(2));
1403 auto fSz = float(input->readULong(2));
1404 lHeader.m_fontSet = true;
1405 lHeader.m_font.setId(fId);
1406 lHeader.m_font.setSize(fSz);
1407 f << "id=" << fId << ",";
1408 f << "sz=" << fSz << ",";
1409 // negative: point, positive li
1410 f << "justify=" << float(input->readLong(4))/65336.f << ",";
1411 }
1412 if (type & 0x8) { // font flag ?
1413 val = static_cast<int>(input->readULong(2));
1414 f << "fa=" << std::hex << val << std::dec << ",";
1415 }
1416 if (type & 0x4) {
1417 MWAW_DEBUG_MSG(("FullWrtText::readLineHeader: find unknown size flags!!!!\n"));
1418 f << "[#fl&4]";
1419 // we do not know the size of this field, let try with 2
1420 input->seek(2, librevenge::RVNG_SEEK_CUR);
1421 }
1422 if (type & 0x2) { // 0 or 2
1423 val = static_cast<int>(input->readULong(2));
1424 f << "fb=" << val << ",";
1425 }
1426 if (type & 0x1) { // small number between 1 and 1b
1427 val = static_cast<int>(input->readLong(2));
1428 f << "nRows?=" << val << ",";
1429 }
1430 lHeader.m_extra = f.str();
1431 return true;
1432 }
1433
1434 bool FullWrtText::send(std::shared_ptr<FullWrtTextInternal::Zone> zone, MWAWColor fontColor)
1435 {
1436 MWAWTextListenerPtr listener=m_parserState->m_textListener;
1437 if (!listener) {
1438 MWAW_DEBUG_MSG(("FullWrtText::send can not find the listener\n"));
1439 return false;
1440 }
1441 MWAWInputStreamPtr input = zone->m_zone->m_input;
1442 libmwaw::DebugFile &ascii = zone->m_zone->getAsciiFile();
1443 libmwaw::DebugStream f;
1444
1445 zone->m_zone->setParsed(true);
1446
1447 long pos = zone->m_begin;
1448 input->seek(pos, librevenge::RVNG_SEEK_SET);
1449 int num=1;
1450 FullWrtTextInternal::Font font;
1451 font.m_font=MWAWFont(3,12);
1452 font.m_font.setColor(fontColor);
1453 FullWrtTextInternal::Paragraph ruler;
1454 if (zone->m_zone->m_fileType==0x11 || zone->m_zone->m_fileType==0x12)
1455 ruler.setAlign(1);
1456
1457 auto listBreaks = zone->getBreaksPosition();
1458 auto numBreaks = int(listBreaks.size());
1459 auto nPages = int(zone->m_pagesInfo.size());
1460 int actBreak = numBreaks, actBreakPos = -1;
1461 if (numBreaks) {
1462 actBreak = 0;
1463 actBreakPos = listBreaks[size_t(actBreak)];
1464 }
1465 int actPage = 0, actCol = 0, numCol=1;
1466 listener->setParagraph(ruler);
1467 float prevHeight = -1;
1468 while (1) {
1469 pos = input->tell();
1470 bool sendData = false;
1471 f.str("");
1472 f << "TextData-a[" << num << "]:";
1473 while (num==actBreakPos) {
1474 if (num != 1) sendData = true;
1475 if (actCol < numCol-1 && numCol > 1) {
1476 listener->insertBreak(MWAWTextListener::ColumnBreak);
1477 actCol++;
1478 }
1479 else if (actPage >= nPages) {
1480 MWAW_DEBUG_MSG(("FullWrtText::send can not find the page information\n"));
1481 }
1482 else {
1483 auto const &page = zone->m_pagesInfo[size_t(actPage)];
1484 if (sendData) {
1485 if (zone->m_zoneType == FullWrtTextInternal::Zone::Main)
1486 m_mainParser->newPage(++m_state->m_actualPage);
1487 else if (numCol > 1)
1488 listener->insertBreak(MWAWTextListener::ColumnBreak);
1489 }
1490 actCol = 0;
1491
1492 if (!actPage || !page.isSimilar(zone->m_pagesInfo[size_t(actPage-1)])) {
1493 auto section = page.getSection();
1494 libmwaw::SubDocumentType subdocType;
1495 int numC = section.numColumns();
1496 if (listener->isSubDocumentOpened(subdocType) && numC <=1
1497 && subdocType != libmwaw::DOC_TEXT_BOX)
1498 ;
1499 else {
1500 if (listener->isSectionOpened())
1501 listener->closeSection();
1502
1503 listener->openSection(section);
1504 numCol = numC;
1505 }
1506 }
1507
1508 actPage++;
1509 }
1510
1511 if (num != 1) f << "break,";
1512 sendData = true;
1513 // update numbreaks
1514 if (++actBreak < numBreaks)
1515 actBreakPos = listBreaks[size_t(actBreak)];
1516 else
1517 actBreakPos = -1;
1518 }
1519 num++;
1520 FullWrtTextInternal::LineHeader lHeader;
1521 if (!readLineHeader(zone, lHeader)) {
1522 input->seek(pos, librevenge::RVNG_SEEK_SET);
1523 break;
1524 }
1525 f << lHeader;
1526 // update prevHeight
1527 lHeader.m_prevHeight = prevHeight;
1528 prevHeight = lHeader.height();
1529
1530 if (lHeader.m_fontSet) {
1531 font.m_font.setId(lHeader.m_font.id());
1532 font.m_font.setSize(lHeader.m_font.size());
1533 }
1534 long debPos=input->tell();
1535 if (lHeader.m_numChar)
1536 ascii.addDelimiter(debPos,'|');
1537 long lastPos = debPos+lHeader.m_numChar;
1538 std::string str;
1539 if (!ruler.isTable() || !sendTable(zone, lHeader, font, ruler, str)) {
1540 str="";
1541 input->seek(debPos, librevenge::RVNG_SEEK_SET);
1542 send(zone, lHeader.m_numChar, font, ruler, str);
1543 }
1544 f << str;
1545 input->seek(lastPos, librevenge::RVNG_SEEK_SET);
1546
1547 ascii.addPos(pos);
1548 ascii.addNote(f.str().c_str());
1549
1550 if (long(input->tell()) >= zone->m_end)
1551 break;
1552 }
1553 return true;
1554 }
1555
1556 bool FullWrtText::sendHiddenItem(int id, FullWrtTextInternal::Font &font, FullWrtTextInternal::Paragraph &ruler)
1557 {
1558 MWAWTextListenerPtr listener=m_parserState->m_textListener;
1559 if (!listener) {
1560 MWAW_DEBUG_MSG(("FullWrtText::sendHiddenItem can not find the listener\n"));
1561 return false;
1562 }
1563 if (m_state->m_itemMap.find(id)==m_state->m_itemMap.end()) {
1564 MWAW_DEBUG_MSG(("FullWrtText::sendHiddenItem: can not find item %d\n", id));
1565 return false;
1566 }
1567 auto &item = m_state->m_itemMap.find(id)->second;
1568 if (!item.m_hidden) {
1569 MWAW_DEBUG_MSG(("FullWrtText::sendHiddenItem: item %d is not hidden\n", id));
1570 return false;
1571 }
1572 // avoid loop if pb
1573 font.m_item=FullWrtTextInternal::Item(); // no previous item
1574 item.m_hidden = false; // item is send
1575
1576 std::shared_ptr<FullWrtTextInternal::Zone> zone=item.m_hiddenZone;
1577 if (!zone) {
1578 MWAW_DEBUG_MSG(("FullWrtText::sendHiddenItem can not find the hidden zone\n"));
1579 return false;
1580 }
1581 MWAWInputStreamPtr input = zone->m_zone->m_input;
1582 libmwaw::DebugFile &ascii = zone->m_zone->getAsciiFile();
1583 libmwaw::DebugStream f;
1584 long pos = zone->m_begin;
1585 input->seek(pos, librevenge::RVNG_SEEK_SET);
1586
1587 f << "ItemData[Collapsed]:";
1588 auto val = static_cast<int>(input->readULong(1)); // alway 40 ?
1589 if (val != 0x40)
1590 f << "#type=" << val << ",";
1591 val = static_cast<int>(input->readULong(1)); // find number between 3 and 7, a unique id ?
1592 if (val) f << "id=" << val << ",";
1593 val = static_cast<int>(input->readULong(2)); // number between 2 and 48
1594 if (val) f << "f0=" << val << ",";
1595 for (int i = 0; i < 4; i++) { // f1=3, f2=0|c0, f3=1, f4=0|1
1596 val = static_cast<int>(input->readULong(1));
1597 if (val) f << "f" << i+1 << "=" << std::hex << val << std::dec << ",";
1598 }
1599 for (int i = 0; i < 3; i++) { // g0=0, g1=1, g2=0
1600 val = static_cast<int>(input->readLong(2));
1601 if (val) f << "g" << i << "=" << val << ",";
1602 }
1603 val = static_cast<int>(input->readLong(1)); // always 0?
1604 if (val) f << "g3=" << val << ",";
1605 font.m_font.setSize(float(input->readULong(1)));
1606 font.m_font.setId(static_cast<int>(input->readULong(2)));
1607 for (int i = 0; i < 2; i++) { //g4=5|6|45, g5=0
1608 val = static_cast<int>(input->readULong(1));
1609 if (val) f << "g" << 4+i << "=" << std::hex << val << std::dec << ",";
1610 }
1611 for (int i = 0; i < 3; i++) { // always 0 or color?
1612 val = static_cast<int>(input->readLong(2));
1613 if (val) f << "h" << i << "=" << std::hex << val << std::dec << ",";
1614 }
1615 for (int i = 0; i < 5; i++) {
1616 val = static_cast<int>(input->readULong(2));
1617 MWAWColor col;
1618 if (FullWrtStruct::getColor(val, col)) f << "col" << i << "=" << col << ",";
1619 }
1620 for (int i = 0; i < 2; i++) { // h3=id?, h4=id?
1621 val = static_cast<int>(input->readLong(2));
1622 if (val) f << "h" << i+3 << "=" << std::hex << val << std::dec << ",";
1623 }
1624 input->seek(4, librevenge::RVNG_SEEK_CUR); // skip size...
1625 auto numChar=int(zone->m_end-(pos+44));
1626 if (numChar)
1627 ascii.addDelimiter(pos+44,'|');
1628 listener->setParagraph(ruler);
1629 std::string str;
1630 send(zone, numChar, font, ruler, str);
1631 f << str;
1632
1633 ascii.addPos(pos);
1634 ascii.addNote(f.str().c_str());
1635
1636 for (auto child : item.m_childList)
1637 sendHiddenItem(child, font, ruler);
1638 return true;
1639 }
1640
1641 ////////////////////////////////////////////////////////////
1642 // read the text data
1643 bool FullWrtText::readTextData(FullWrtStruct::EntryPtr zone)
1644 {
1645 MWAWInputStreamPtr input = zone->m_input;
1646 libmwaw::DebugFile &ascii = zone->getAsciiFile();
1647 int vers = version();
1648
1649 long pos = zone->begin();
1650 input->seek(pos, librevenge::RVNG_SEEK_SET);
1651
1652 bool knownZone = (zone->m_fileType >= 0xa && zone->m_fileType <= 0x14) || (zone->m_fileType == 0x18);
1653
1654 auto header = static_cast<int>(input->readULong(2));
1655 bool hasHeader = false;
1656 if (!knownZone && (header&0xFC00)) return false;
1657
1658 std::shared_ptr<FullWrtTextInternal::Zone> text(new FullWrtTextInternal::Zone);
1659 text->m_zoneType = (zone->m_fileType==0xa) ?
1660 FullWrtTextInternal::Zone::Main : FullWrtTextInternal::Zone::Normal;
1661 text->m_zone = zone;
1662
1663 int val;
1664 if (!header) { // maybe the main zone
1665 bool ok = true;
1666 // find f0 in [1,270], f1 in [1,d2]
1667 for (int i = 0; i < 2 && ok ; i++) {
1668 val = static_cast<int>(input->readLong(2));
1669 if (val <= 0 || (!i && val >= 0x800) || (i && val >= 0x200))
1670 ok = false;
1671 }
1672 for (int i = 0; i < 2 && ok; i++) {
1673 val = static_cast<int>(input->readULong(1));
1674 if (val>1) ok=false;
1675 }
1676 val = ok ? static_cast<int>(input->readLong(1)) : 0;
1677 if (val && !knownZone)
1678 ok=false;
1679 val = ok ? static_cast<int>(input->readLong(1)) : 0;
1680 if (val < 1 || val > 20)
1681 ok=false;
1682 if (!ok) { // force to try as attachment
1683 header = 1;
1684 input->seek(pos+2, librevenge::RVNG_SEEK_SET);
1685 }
1686 else if (!knownZone)
1687 text->m_zoneType = FullWrtTextInternal::Zone::Main;
1688 }
1689 if (header) { // attachement
1690 hasHeader = true;
1691 for (int i = 0; i < 2; i++) {
1692 val = static_cast<int>(input->readLong(2));
1693 if (val <= 0 || val > 2) return false;
1694 }
1695 val = static_cast<int>(input->readLong(vers==1 ? 1 : 2));
1696 if (val < 0 || val > 4) return false;
1697 if (vers==2) {
1698 if (val== 0) return false;
1699 val = static_cast<int>(input->readLong(2));
1700 if (val) return false;
1701 }
1702 if (!knownZone)
1703 text->m_zoneType = FullWrtTextInternal::Zone::Main;
1704 }
1705 input->seek(pos, librevenge::RVNG_SEEK_SET);
1706 libmwaw::DebugStream f;
1707 if (hasHeader) {
1708 //find 8, 1c, 71, 76, 8a, 99, 9d, c6, c9, ce, f3, f4
1709 f << "N0=" << static_cast<int>(input->readLong(2)) << ",";
1710 for (int i = 0; i < 2; i++) { // f0=f1=1 ? f2=1/2
1711 val = static_cast<int>(input->readLong(2));
1712 if (val != 1) f << "f" << i << "=" << val << ",";
1713 }
1714 val = static_cast<int>(input->readLong(vers==1 ? 1 : 2));
1715 if (val != 1) f << "f2=" << val << ",";
1716 if (vers == 1) {
1717 ascii.addDelimiter(input->tell(),'|');
1718 input->seek(59, librevenge::RVNG_SEEK_CUR);
1719 ascii.addDelimiter(input->tell(),'|');
1720 }
1721 }
1722 val = static_cast<int>(input->readLong(2)); // always 0 ?
1723 if (val) f << "f3=" << val << ",";
1724
1725 /* N[0] related to number line ? N[1] between 1 and 5e */
1726 int N[2];
1727 for (int i = 0; i < 2; i++) {
1728 N[i] = static_cast<int>(input->readLong(2));
1729 if (N[i])
1730 f << "N" << i+1 << "=" << std::hex << N[i] << std::dec << ",";
1731 }
1732 // two flag header/footer : 0|1, normal/other: 0|1?
1733 for (int i = 0; i < 2; i++) {
1734 text->m_flags[i] = static_cast<int>(input->readLong(1));
1735 if (text->m_flags[i])
1736 f << "fl" << i << "=" << text->m_flags[i] << ",";
1737 }
1738 for (int i=0; i < 2; i++) { // f4=0|27, f5=small number 1/2/f
1739 val = static_cast<int>(input->readLong(1));
1740 if (val!=1) f << "f" << i+4 << "=" << val << ",";
1741 }
1742
1743 // between 1 and 202 ( very similar to dim[2]
1744 auto dimUnk = static_cast<int>(input->readLong(2));
1745 // two flags 0|ce|fa, 0
1746 for (int i = 3; i < 5; i++) {
1747 val = static_cast<int>(input->readLong(1));
1748 if (val)
1749 f << "fl" << i << "=" << val << ",";
1750 }
1751 // between 8 and 58
1752 f << "N3=" << static_cast<int>(input->readLong(2)) << ",";
1753 int dim[4]; // box with almost always y1=y0+1?
1754 for (auto &d : dim) d=static_cast<int>(input->readLong(2));
1755 if (dimUnk != dim[2]) f << "dimUnk=" << dimUnk << ",";
1756
1757 text->m_box=MWAWBox2f(MWAWVec2f(float(dim[0]),float(dim[1])),MWAWVec2f(float(dim[2]),float(dim[3])));
1758 text->m_pages[1] = static_cast<int>(input->readLong(2));
1759 if (text->m_pages[1] == 16000) text->m_pages[1] = 0;
1760 text->m_pages[0] = static_cast<int>(input->readLong(2));
1761 if (text->m_pages[0] == 16000) text->m_pages[0] = text->m_pages[1];
1762
1763 for (int i = 0; i < 2; i++) { // 1, 2 or 16000=infty?
1764 val = static_cast<int>(input->readLong(2));
1765 if (val) f << "g" << i << "=" << val << ",";
1766 }
1767
1768 text->m_extra = f.str();
1769 f.str("");
1770 f << "Entries(TextData):";
1771 f << *text;
1772 ascii.addPos(pos);
1773 ascii.addNote(f.str().c_str());
1774 if (long(input->tell()) >= zone->end())
1775 return false;
1776
1777 text->m_begin = input->tell();
1778 #if DEBUGII
1779 int numLines=0;
1780 #endif
1781 while (1) {
1782 pos = input->tell();
1783 if (pos+2 >= zone->end()) break;
1784 auto type = static_cast<int>(input->readULong(2));
1785 if (input->isEnd()) {
1786 MWAW_DEBUG_MSG(("FullWrtText::readTextData: internal problem, unexpected EOS!!!\n"));
1787 return false;
1788 }
1789 int lengthSz = 1;
1790 if (type & 0x8000)
1791 lengthSz = 2;
1792 auto numChar = static_cast<int>(input->readULong(lengthSz));
1793 if ((lengthSz==1 && (numChar & 0x80)) ||
1794 long(input->tell()+numChar) > zone->end()) {
1795 input->seek(pos, librevenge::RVNG_SEEK_SET);
1796 break;
1797 }
1798 #if DEBUGII
1799 numLines++;
1800 #endif
1801 int sz = 0;
1802 if (type & 0x4000) sz+=12;
1803 if (type & 0x2000) sz+=1;
1804 if (type & 0x1000) sz+=1;
1805 if (type & 0x800) sz+=1;
1806 if (type & 0x400) sz+=1;
1807 if (type & 0x200) sz+=2;
1808 if (type & 0x100) sz+=2;
1809 if (type & 0x80) sz+=2;
1810 if (type & 0x40) sz+=2;
1811 if (type & 0x20) sz+=4;
1812 if (type & 0x10) sz+=8;
1813 if (type & 0x8) sz+=2;
1814 if (type & 0x4) {
1815 MWAW_DEBUG_MSG(("FullWrtText::readTextData: find unknown size flags!!!!\n"));
1816 sz+=2;
1817 }
1818 if (type & 0x2) sz+=2;
1819 if (type & 0x1) sz+=2;
1820 if (numChar || sz)
1821 input->seek(numChar+sz, librevenge::RVNG_SEEK_CUR);
1822 }
1823 #if DEBUGII
1824 std::cout << "FIND:N=" << numLines << " [" << N[0] << "]\n";
1825 #endif
1826 pos = text->m_end = input->tell();
1827 // ok, we can insert the data
1828 auto it = m_state->m_entryMap.find(zone->id());
1829 if (it != m_state->m_entryMap.end()) {
1830 MWAW_DEBUG_MSG(("FullWrtText::readTextData: entry %d already exists\n", zone->id()));
1831 }
1832 m_state->m_entryMap.insert
1833 (std::multimap<int, std::shared_ptr<FullWrtTextInternal::Zone> >::value_type(zone->id(), text));
1834
1835 f.str("");
1836 f << "TextData-b:";
1837 val = static_cast<int>(input->readULong(2));
1838 if (val || static_cast<int>(input->readULong(1)) != 0xFF) {
1839 f << "##";
1840 ascii.addPos(pos);
1841 ascii.addNote(f.str().c_str());
1842 return true;
1843 }
1844
1845 f << "numCols=" << static_cast<int>(input->readLong(2)) << ",";
1846 ascii.addPos(pos);
1847 ascii.addNote(f.str().c_str());
1848 int actPage = 0;
1849 while (1) {
1850 pos = input->tell();
1851 if (pos >= zone->end()) break;
1852 val = static_cast<int>(input->readULong(2));
1853 int sz = 0;
1854 if ((val%50)==30) {
1855 int num = val/50;
1856 sz = 32+num*52;
1857
1858 input->seek(9, librevenge::RVNG_SEEK_CUR);
1859
1860 if (pos+sz > zone->end()) {
1861 input->seek(pos, librevenge::RVNG_SEEK_SET);
1862 break;
1863 }
1864
1865 FullWrtTextInternal::PageInfo page;
1866 page.m_page = actPage++;
1867
1868 ascii.addPos(pos);
1869 ascii.addNote("TextData-c[ColH]");
1870
1871 pos+=32;
1872 input->seek(pos, librevenge::RVNG_SEEK_SET);
1873 for (int i = 0; i < num; i++) {
1874 pos = input->tell();
1875 f.str("");
1876 f << "TextData-c[ColDef]:";
1877 FullWrtTextInternal::ColumnInfo col;
1878 col.m_column = i;
1879 col.m_beginPos = static_cast<int>(input->readLong(2));
1880 for (auto &d : dim) d = static_cast<int>(input->readLong(2));
1881 col.m_box = MWAWBox2i(MWAWVec2i(dim[0],dim[2]), MWAWVec2i(dim[1], dim[3]));
1882 f << col;
1883 page.m_columns.push_back(col);
1884
1885 ascii.addDelimiter(input->tell(),'|');
1886 ascii.addPos(pos);
1887 ascii.addNote(f.str().c_str());
1888 input->seek(pos+52, librevenge::RVNG_SEEK_SET);
1889 }
1890 text->m_pagesInfo.push_back(page);
1891 continue;
1892 }
1893
1894 // ok, probably link to a col field, but...
1895 // let try to correct
1896 int high = (val>>8);
1897 if (high==0x21)
1898 sz = 42;
1899 else if (high==0x61||high==0x63) {
1900 input->seek(12, librevenge::RVNG_SEEK_CUR);
1901 auto numData = static_cast<int>(input->readULong(2));
1902 if (!numData) break;
1903 sz = 26+9*numData;
1904 }
1905 else if (high==0xe1) {
1906 input->seek(14, librevenge::RVNG_SEEK_CUR);
1907 auto numData = static_cast<int>(input->readULong(2));
1908 if (!numData) break;
1909 sz = 30+9*numData;
1910 }
1911 else if (high==0 && (val%50)!=30)
1912 sz=26;
1913 if (sz == 0 || pos+sz > zone->end()) {
1914 input->seek(pos, librevenge::RVNG_SEEK_SET);
1915 break;
1916 }
1917
1918 ascii.addPos(pos);
1919 ascii.addNote("TextData-d:");
1920 input->seek(pos+sz, librevenge::RVNG_SEEK_SET);
1921 }
1922
1923 if (input->tell() < zone->end()) {
1924 ascii.addPos(input->tell());
1925 ascii.addNote("TextData-d:");
1926 }
1927
1928 return true;
1929 }
1930
1931 ////////////////////////////////////////////////////////////
1932 //
1933 // Low level
1934 //
1935 ////////////////////////////////////////////////////////////
1936 bool FullWrtText::readItem(FullWrtStruct::EntryPtr zone, int id, bool hidden)
1937 {
1938 MWAWInputStreamPtr input = zone->m_input;
1939 libmwaw::DebugFile &ascii = zone->getAsciiFile();
1940 libmwaw::DebugStream f;
1941 long pos = input->tell();
1942 if (pos+25 > zone->end())
1943 return false;
1944
1945 FullWrtTextInternal::Item item;
1946 item.m_hidden = hidden;
1947 int val;
1948 int numOk = 0, numBad = 0;
1949 int numZone = m_mainParser->getNumDocZoneStruct();
1950 for (int i = 0; i < 4; i++) {
1951 val = static_cast<int>(input->readLong(2));
1952 if (val < 0 || val >= numZone) {
1953 numBad++;
1954 f << "#id" << i << "=" << val << ",";
1955 continue;
1956 }
1957 item.m_structId[i]=val;
1958 if (val) numOk++;
1959 }
1960 val = static_cast<int>(input->readLong(2));
1961 if (val > 0) {
1962 item.m_index=val;
1963 numOk++;
1964 }
1965 else {
1966 f << "#index=" << val << ",";
1967 numBad++;
1968 }
1969 for (int i = 0; i < 2; i++) { // f1=[1-4]:listId?,f2=0
1970 val = static_cast<int>(input->readLong(2));
1971 if (!val) continue;
1972 if (val < -100||val > 100) {
1973 numBad++;
1974 f << "#";
1975 }
1976 else
1977 numOk++;
1978 f << "f" << i << "=" << std::hex << val << std::dec << ",";
1979 }
1980 if (numBad > numOk) {
1981 input->seek(pos, librevenge::RVNG_SEEK_SET);
1982 return false;
1983 }
1984 val = static_cast<int>(input->readULong(1)); // 68 or e8
1985 if (val!=0x68)
1986 f << "fl=" << std::hex << val << std::dec << ",";
1987 item.m_level = static_cast<int>(input->readLong(2));
1988 val = static_cast<int>(input->readULong(1)); // always 0
1989 if (val)
1990 f << "fl1=" << val << ",";
1991 item.m_structId[FullWrtTextInternal::Item::Main] = static_cast<int>(input->readLong(2));
1992 if (id > 0 && id != item.m_structId[FullWrtTextInternal::Item::Main]) {
1993 numBad+=3;
1994 f << "###id,";
1995 }
1996 for (int i = 1; i < 3; i++) { // always 0 ?
1997 val = static_cast<int>(input->readLong(2));
1998 if (!val) continue;
1999 if (i > 1 && (val < -100 || val > 100)) {
2000 f << "#";
2001 numBad++;
2002 }
2003 else
2004 numOk++;
2005 f << "g" << i << "=" << std::hex << val << std::dec << ",";
2006 }
2007 if (numBad >= numOk) {
2008 input->seek(pos, librevenge::RVNG_SEEK_SET);
2009 return false;
2010 }
2011 val = static_cast<int>(input->readULong(1)); // always 0
2012 if (val)
2013 f << "fl2=" << val << ",";
2014 item.m_extra=f.str();
2015 f.str("");
2016 f << "Entries(ItemData):" << item;
2017 ascii.addPos(pos);
2018 ascii.addNote(f.str().c_str());
2019 bool set = false;
2020 if (id < 0) ;
2021 else if (m_state->m_itemMap.find(id) == m_state->m_itemMap.end()) {
2022 m_state->m_itemMap.insert
2023 (std::map<int,FullWrtTextInternal::Item>::value_type(id,item));
2024 set=true;
2025 }
2026 else {
2027 MWAW_DEBUG_MSG(("FullWrtText::readItem: id %d already exists\n", id));
2028 }
2029
2030 if (!hidden)
2031 return true;
2032
2033 pos = input->tell();
2034 if (pos+44 > zone->end() || input->readULong(1)!=0x40) {
2035 MWAW_DEBUG_MSG(("FullWrtText::readItem: can not find hidden data\n"));
2036 input->seek(pos, librevenge::RVNG_SEEK_SET);
2037 return true;
2038 }
2039 input->seek(pos+42, librevenge::RVNG_SEEK_SET);
2040 auto sz = static_cast<int>(input->readULong(2));
2041 if (pos+44+sz > zone->end()) {
2042 MWAW_DEBUG_MSG(("FullWrtText::readItem: find bad data size\n"));
2043 input->seek(pos, librevenge::RVNG_SEEK_SET);
2044 return true;
2045 }
2046
2047 if (set && m_state->m_itemMap.find(id) != m_state->m_itemMap.end()) {
2048 auto &theItem = m_state->m_itemMap.find(id)->second;
2049 theItem.m_hiddenZone.reset(new FullWrtTextInternal::Zone);
2050 theItem.m_hiddenZone->m_zone = zone;
2051 theItem.m_hiddenZone->m_zoneType = FullWrtTextInternal::Zone::CollapsedItem;
2052 theItem.m_hiddenZone->m_begin = pos;
2053 theItem.m_hiddenZone->m_end = pos+44+sz;
2054 }
2055
2056 if (sz)
2057 input->seek(sz, librevenge::RVNG_SEEK_CUR);
2058 return true;
2059 }
2060
2061 ////////////////////////////////////////////////////////////
2062 // read a style
2063 bool FullWrtText::readStyle(FullWrtStruct::EntryPtr zone)
2064 {
2065 MWAWInputStreamPtr input = zone->m_input;
2066 libmwaw::DebugFile &ascii = zone->getAsciiFile();
2067 libmwaw::DebugStream f;
2068 long pos=input->tell();
2069
2070 auto sz = int(input->readLong(2));
2071 if (sz < 4 || sz >= 0x100) return false;
2072 if (pos+2+sz> zone->end()) return false;
2073 f.str("");
2074 f << "Entries(Style):";
2075 for (int i=0; i<2; ++i) { //f0: small number, f1: number between 0 and 1c: flag?
2076 auto val=static_cast<int>(input->readLong(2));
2077 if (val) f << "f" << i << "=" << val << ",";
2078 }
2079 if (sz==4) {
2080 ascii.addPos(pos);
2081 ascii.addNote(f.str().c_str());
2082 return true;
2083 }
2084 if (sz!=0x46) {
2085 f << "###";
2086 MWAW_DEBUG_MSG(("FullWrtText::readStyle: style length seems odd\n"));
2087 input->seek(pos+2+sz, librevenge::RVNG_SEEK_SET);
2088 ascii.addPos(pos);
2089 ascii.addNote(f.str().c_str());
2090 return true;
2091 }
2092 auto nSz=static_cast<int>(input->readULong(1));
2093 if (!nSz || nSz>0x1f) {
2094 f << "###";
2095 MWAW_DEBUG_MSG(("FullWrtText::readStyle: style name length seems odd\n"));
2096 input->seek(pos+2+sz, librevenge::RVNG_SEEK_SET);
2097 ascii.addPos(pos);
2098 ascii.addNote(f.str().c_str());
2099 return true;
2100 }
2101 std::string name("");
2102 for (int c=0; c<nSz; ++c)
2103 name += char(input->readLong(1));
2104 f << name << ",";
2105 input->seek(pos+38, librevenge::RVNG_SEEK_SET);
2106 ascii.addDelimiter(input->tell(),'|');
2107 ascii.addPos(pos);
2108 ascii.addNote(f.str().c_str());
2109 input->seek(pos+2+sz, librevenge::RVNG_SEEK_SET);
2110 return true;
2111 }
2112
2113 ////////////////////////////////////////////////////////////
2114 // read the paragraph data
2115 bool FullWrtText::readParagraphTabs(FullWrtStruct::EntryPtr zone, int id)
2116 {
2117 MWAWInputStreamPtr input = zone->m_input;
2118 libmwaw::DebugFile &ascii = zone->getAsciiFile();
2119 libmwaw::DebugStream f;
2120 int const vers = version();
2121 const int dataSz = vers==1 ? 14 : 10;
2122 const int headerSz = vers==1 ? 24 : 30;
2123 long pos = input->tell();
2124 input->seek(pos, librevenge::RVNG_SEEK_SET);
2125 auto sz = long(input->readULong(4));
2126 if (sz<24 || pos+4+sz > zone->end()) {
2127 input->seek(pos, librevenge::RVNG_SEEK_SET);
2128 return false;
2129 }
2130
2131 f.str("");
2132 f << "Entries(Ruler):";
2133 if (id >= 0) f << "P" << id << ",";
2134 int val;
2135 for (int i = 0; i < 2; i++) { // find f0 in 0 c0, f1=0|2
2136 val = static_cast<int>(input->readULong(1));
2137 if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
2138 }
2139 for (int i = 0; i < 2; i++) { // find f0=0|1|2: align ?, f1=0-7
2140 val = static_cast<int>(input->readULong(2));
2141 if (val) f << "f" << i << "=" << val << ",";
2142 }
2143 FullWrtTextInternal::Paragraph para;
2144 float dim[2];
2145 for (float &i : dim) // dim0: height?, dim1:width
2146 i = float(input->readULong(2))/72.f;
2147 para.m_dim=MWAWVec2f(dim[1],dim[0]);
2148 double margins[3];
2149 char const *margNames[] = { "left", "right", "first" };
2150 for (int i = 0; i < 3; i++) {
2151 margins[i] = double(input->readLong(4))/65536./72.0;
2152 if (margins[i] < 0 || margins[i] > 0)
2153 f << "margins[" << margNames[i] << "]=" << margins[i] << ",";
2154 }
2155 para.m_margins[0] = margins[2]-margins[0];
2156 para.m_margins[1] = margins[0];
2157 if (margins[1] < double(dim[1]))
2158 para.m_margins[2]=double(dim[1])-margins[1];
2159 ascii.addDelimiter(input->tell(), '|');
2160
2161 input->seek(vers==1 ? pos+27 : pos+26, librevenge::RVNG_SEEK_SET);
2162 auto N = static_cast<int>(input->readULong(1));
2163 if (headerSz+dataSz*N != sz) {
2164 input->seek(pos, librevenge::RVNG_SEEK_SET);
2165 return false;
2166 }
2167 f << "N=" << N << ",";
2168 if (vers==2) {
2169 for (int i=0; i < 3; i++) {
2170 val = static_cast<int>(input->readULong(1));
2171 if (val) f << "g" << i << "=" << val << ",";
2172 }
2173 if (input->readULong(4)) {
2174 para.m_isTable = true;
2175 f << "table,";
2176 }
2177 input->seek(pos+4+30, librevenge::RVNG_SEEK_SET);
2178 }
2179 ascii.addPos(pos);
2180 ascii.addNote(f.str().c_str());
2181 for (int i = 0; i < N; i++) {
2182 pos = input->tell();
2183 f.str("");
2184 f << "Ruler:Tabs-" << i << ":";
2185 MWAWTabStop tab;
2186 val = static_cast<int>(input->readULong(1));
2187 switch (val>>5) {
2188 case 0:
2189 break;
2190 case 1:
2191 tab.m_alignment = MWAWTabStop::CENTER;
2192 break;
2193 case 2:
2194 tab.m_alignment = MWAWTabStop::RIGHT;
2195 break;
2196 case 3:
2197 tab.m_alignment = MWAWTabStop::DECIMAL;
2198 break;
2199 case 4:
2200 f << "end[table],";
2201 break;
2202 case 5:
2203 f << "justify[table],";
2204 break;
2205 case 6:
2206 f << "justifyAll[table],";
2207 break;
2208 // 4: tableend, 5: justify(begintable), 6: justifyall(begin table)
2209 default:
2210 f << "##tab[type]=" << (val>>5) << ",";
2211 break;
2212 }
2213 para.m_tableFlags.push_back(val>>5);
2214 if (val & 0x1F) f << "#type=" << std::hex << (val & 0x1F) << std::dec << ",";
2215 val = static_cast<int>(input->readULong(1));
2216 if (val) {
2217 int unicode= m_parserState->m_fontConverter->unicode(3, static_cast<unsigned char>(val));
2218 if (unicode==-1)
2219 tab.m_decimalCharacter = uint16_t(val);
2220 else
2221 tab.m_decimalCharacter = uint16_t(unicode);
2222 }
2223 tab.m_position = double(input->readLong(4))/65536./72.;
2224 val = static_cast<int>(input->readLong(2));
2225 if (val) f << "repeat=" << val/256.;
2226
2227 val = static_cast<int>(input->readULong(1));
2228 switch (val) {
2229 case 0x1: // fixme: . or dotted
2230 tab.m_leaderCharacter = '.';
2231 break;
2232 case 0x20: // space, ie. none
2233 case 0:
2234 break;
2235 default: {
2236 int unicode= m_parserState->m_fontConverter->unicode(3, static_cast<unsigned char>(val));
2237 if (unicode==-1)
2238 tab.m_leaderCharacter = uint16_t(val);
2239 else
2240 tab.m_leaderCharacter = uint16_t(unicode);
2241 break;
2242 }
2243 }
2244 val = static_cast<int>(input->readULong(1));
2245 if (val) f << "#f2=" << std::hex << val << std::dec << ",";
2246 f << tab;
2247 para.m_tabs->push_back(tab);
2248 ascii.addPos(pos);
2249 ascii.addNote(f.str().c_str());
2250 input->seek(pos+dataSz, librevenge::RVNG_SEEK_SET);
2251 }
2252 if (para.m_isTable) {
2253 pos = input->tell();
2254 sz = input->readLong(4);
2255 f.str("");
2256 f << "Ruler[Table:end]:";
2257 if (sz==0x24 && pos+4+sz <= zone->end()) {
2258 for (int i=0; i<11; ++i) { // always 0
2259 val=static_cast<int>(input->readLong(2));
2260 if (val)
2261 f << "f" << i << "=" << val << ",";
2262 }
2263 para.m_tableBorderId=static_cast<int>(input->readLong(2));
2264 if (para.m_tableBorderId)
2265 f << "B" << para.m_tableBorderId-1 << ",";
2266 ascii.addDelimiter(input->tell(), '|');
2267 input->seek(pos+4+0x24, librevenge::RVNG_SEEK_SET);
2268 }
2269 else {
2270 MWAW_DEBUG_MSG(("FullWrtText::readParagraphTabs: can not find table data\n"));
2271 f << "###";
2272 input->seek(pos, librevenge::RVNG_SEEK_SET);
2273 }
2274 ascii.addPos(pos);
2275 ascii.addNote(f.str().c_str());
2276 }
2277 if (id < 0) ;
2278 else if (m_state->m_paragraphMap.find(id) == m_state->m_paragraphMap.end())
2279 m_state->m_paragraphMap.insert
2280 (std::map<int,FullWrtTextInternal::Paragraph>::value_type(id,para));
2281 else {
2282 MWAW_DEBUG_MSG(("FullWrtText::readParagraphTabs: id %d already exists\n", id));
2283 }
2284 return true;
2285 }
2286
2287 /* read font/para modifier in text */
2288 bool FullWrtText::readDataMod(FullWrtStruct::EntryPtr zone, int id)
2289 {
2290 MWAWInputStreamPtr input = zone->m_input;
2291 libmwaw::DebugFile &ascii = zone->getAsciiFile();
2292 libmwaw::DebugStream f;
2293
2294 long pos = input->tell();
2295 input->seek(pos, librevenge::RVNG_SEEK_SET);
2296 if (pos+10 > zone->end()) {
2297 input->seek(pos, librevenge::RVNG_SEEK_SET);
2298 return false;
2299 }
2300 FullWrtTextInternal::DataModifier mod;
2301 auto val = int(input->readULong(2));
2302 MWAWColor col;
2303 if (FullWrtStruct::getColor(val, col))
2304 mod.m_color = col;
2305 else if (val != 0xFFFF)
2306 f << "#col=" << std::hex << val << std::dec << ",";
2307 for (auto &data : mod.m_data) data = int(input->readULong(2));
2308 mod.m_extra = f.str();
2309 f.str("");
2310 f << "Entries(DataMod):" << mod;
2311 if (m_state->m_dataModMap.find(id) == m_state->m_dataModMap.end())
2312 m_state->m_dataModMap.insert
2313 (std::map<int, FullWrtTextInternal::DataModifier>::value_type(id, mod));
2314 else {
2315 MWAW_DEBUG_MSG(("FullWrtText::readDataMod: Oops id %d already find\n", id));
2316 }
2317 ascii.addPos(pos);
2318 ascii.addNote(f.str().c_str());
2319 return true;
2320 }
2321
2322 /* read para modifier in doc info */
2323 bool FullWrtText::readParaModDocInfo(FullWrtStruct::EntryPtr zone)
2324 {
2325 MWAWInputStreamPtr input = zone->m_input;
2326 libmwaw::DebugFile &asciiFile = zone->getAsciiFile();
2327 libmwaw::DebugStream f;
2328 long pos = input->tell();
2329 if (input->readULong(4)!=0x65787472 || input->readULong(1)) {
2330 input->seek(pos, librevenge::RVNG_SEEK_SET);
2331 return false;
2332 }
2333
2334 long blckSz = input->readLong(4);
2335 long endData = pos+9+blckSz;
2336 int num = static_cast<int>(input->readULong(2)), val;
2337 int const fSz = 18;
2338 f << "Entries(ParaMod):N=" << num << ",";
2339 if (blckSz < 2 || blckSz != 2 + num*fSz || endData > zone->end()) {
2340 MWAW_DEBUG_MSG(("FullWrtText::readParaModDocInfo::readCitationDocInfo: problem reading the data block or the number of data\n"));
2341 f << "###";
2342 asciiFile.addPos(pos);
2343 asciiFile.addNote(f.str().c_str());
2344 if (endData <= zone->end()) {
2345 input->seek(endData, librevenge::RVNG_SEEK_SET);
2346 return true;
2347 }
2348 input->seek(pos, librevenge::RVNG_SEEK_SET);
2349 return false;
2350 }
2351
2352 asciiFile.addPos(pos);
2353 asciiFile.addNote(f.str().c_str());
2354
2355 m_state->m_paragraphModList.push_back(FullWrtTextInternal::ParaModifier());
2356 for (int i = 0; i < num; i++) {
2357 f.str("");
2358 pos = input->tell();
2359 FullWrtTextInternal::ParaModifier mod;
2360 for (int j = 0; j < 2; j++) {
2361 val = int(input->readLong(2));
2362 if (val==-1)
2363 continue;
2364 if (j==0)
2365 mod.m_beforeSpacing = float(val)/256.f;
2366 else
2367 mod.m_afterSpacing = float(val)/256.f;
2368 }
2369 for (int j = 0; j < 3; j++) { // always ffff
2370 val = static_cast<int>(input->readLong(2));
2371 if (val != -1)
2372 f << "f" << j << "=" << val << ",";
2373 }
2374 for (int j = 0; j < 4; j++) { // always 0
2375 val = static_cast<int>(input->readLong(2));
2376 if (val)
2377 f << "f" << j+3 << "=" << val << ",";
2378 }
2379 mod.m_extra = f.str();
2380 m_state->m_paragraphModList.push_back(mod);
2381 f.str("");
2382 f << "ParaMod-" << i << ":" << mod;
2383 asciiFile.addPos(pos);
2384 asciiFile.addNote(f.str().c_str());
2385 input->seek(pos+fSz, librevenge::RVNG_SEEK_SET);
2386 }
2387 return true;
2388 }
2389
2390 ////////////////////////////////////////////////////////////
2391 // read the column data
2392 bool FullWrtText::readColumns(FullWrtStruct::EntryPtr zone)
2393 {
2394 MWAWInputStreamPtr input = zone->m_input;
2395 libmwaw::DebugFile &ascii = zone->getAsciiFile();
2396 libmwaw::DebugStream f;
2397
2398 long pos = input->tell();
2399 input->seek(pos, librevenge::RVNG_SEEK_SET);
2400 auto sz = long(input->readULong(4));
2401 if (sz<34 || pos+4+sz > zone->end() || !input->checkPosition(zone->end())) {
2402 input->seek(pos, librevenge::RVNG_SEEK_SET);
2403 return false;
2404 }
2405
2406 input->seek(13, librevenge::RVNG_SEEK_CUR);
2407 auto N = static_cast<int>(input->readULong(1));
2408 if (24+10*N != sz) {
2409 input->seek(pos, librevenge::RVNG_SEEK_SET);
2410 return false;
2411 }
2412 f.str("");
2413 f << "Entries(Columns):" << N;
2414 ascii.addPos(pos);
2415 ascii.addNote(f.str().c_str());
2416 input->seek(pos+4+24, librevenge::RVNG_SEEK_SET);
2417 for (int i = 0; i < N; i++) {
2418 pos = input->tell();
2419 f.str("");
2420 f << "Columns-" << i << ":";
2421 int dim[2]; // checkme: pos as float?
2422 dim[0] = static_cast<int>(input->readLong(2));
2423 auto val = long(input->readULong(2));
2424 if (val) f << "f0=" << std::hex << val << std::dec << ",";
2425 dim[1] = static_cast<int>(input->readLong(2));
2426 f << "pos=" << dim[0] << "<->" << dim[1] << ",";
2427 val = long(input->readULong(2));
2428 if (val) f << "f1=" << std::hex << val << std::dec << ",";
2429 ascii.addDelimiter(input->tell(),'|');
2430 ascii.addPos(pos);
2431 ascii.addNote(f.str().c_str());
2432 input->seek(pos+10, librevenge::RVNG_SEEK_SET);
2433 }
2434 return true;
2435 }
2436
2437 ////////////////////////////////////////////////////////////
2438 //! send data to the listener
2439 bool FullWrtText::sendMainText()
2440 {
2441 if (m_state->m_mainZones.empty()) {
2442 MWAW_DEBUG_MSG(("FullWrtText::sendMainText: can not find main zone\n"));
2443 return false;
2444 }
2445 if (!m_parserState->m_textListener) return true;
2446 for (auto id : m_state->m_mainZones) {
2447 auto it = m_state->m_entryMap.find(id);
2448 if (it == m_state->m_entryMap.end() || !it->second) {
2449 MWAW_DEBUG_MSG(("FullWrtText::sendMainText: can not find main zone: internal problem\n"));
2450 continue;
2451 }
2452 m_mainParser->newPage(++m_state->m_actualPage);
2453 send(it->second);
2454 }
2455 return true;
2456 }
2457
2458 int FullWrtText::getHeaderFooterId(bool header, int page, int &numSimilar) const
2459 {
2460 int type=header ? 0x11 : 0x12;
2461 if (m_state->m_mainZones.empty()) {
2462 numSimilar=1;
2463 if (m_state->m_numPages>page)
2464 numSimilar=m_state->m_numPages-page+1;
2465 return -1;
2466 }
2467 int nextPage=-1;
2468 int res=-1;
2469 for (auto const &it : m_state->m_entryMap) {
2470 int id=it.first;
2471 auto zone=it.second;
2472 if (!zone || !zone->m_zone || zone->m_zone->m_fileType!=type ||
2473 zone->m_pages[0]<page)
2474 continue;
2475 if (zone->m_pages[1]>=page)
2476 res = id;
2477 else if (nextPage==-1 || zone->m_pages[0]<nextPage)
2478 nextPage=zone->m_pages[0];
2479 }
2480 if (nextPage==-1) nextPage=m_state->m_numPages+1;
2481 numSimilar=nextPage-page;
2482 if (numSimilar<=0) numSimilar=1;
2483 return res;
2484 }
2485
2486 bool FullWrtText::send(int zId, MWAWColor fontColor)
2487 {
2488 auto it = m_state->m_entryMap.find(zId);
2489 if (it == m_state->m_entryMap.end() || !it->second) {
2490 MWAW_DEBUG_MSG(("FullWrtText::send: can not find zone: %d\n", zId));
2491 return false;
2492 }
2493 send(it->second, fontColor);
2494 return true;
2495 }
2496
2497 void FullWrtText::flushExtra()
2498 {
2499 for (auto const &it : m_state->m_entryMap) {
2500 std::shared_ptr<FullWrtTextInternal::Zone> const &zone = it.second;
2501 if (!zone || !zone->m_zone || zone->m_zone->isParsed())
2502 continue;
2503 send(zone);
2504 }
2505 }
2506
2507 void FullWrtText::sortZones()
2508 {
2509 int numZones = 0, totalNumPages = 0;
2510 std::vector<int> pagesLimits;
2511 for (auto const &it : m_state->m_entryMap) {
2512 auto const &zone = it.second;
2513 if (!zone || !zone->m_zone || zone->m_zoneType != FullWrtTextInternal::Zone::Main)
2514 continue;
2515 int fPage = zone->m_pages[0], lPage = zone->m_pages[1];
2516 if (lPage < fPage) {
2517 MWAW_DEBUG_MSG(("FullWrtText::sortZones: last page is inferior to firstPage\n"));
2518 lPage = fPage;
2519 }
2520 int pos = 0;
2521 while (pos < numZones) {
2522 if (fPage < pagesLimits[size_t(2*pos)])
2523 break;
2524 if (fPage == pagesLimits[size_t(2*pos)] && lPage <= pagesLimits[size_t(2*pos+1)])
2525 break;
2526 pos++;
2527 }
2528 pagesLimits.resize(size_t(2*numZones+2));
2529 m_state->m_mainZones.resize(size_t(numZones+1));
2530 for (int i = numZones-1; i > pos-1; i--) {
2531 pagesLimits[size_t(2*i+2)]=pagesLimits[size_t(2*i)];
2532 pagesLimits[size_t(2*i+3)]=pagesLimits[size_t(2*i+1)];
2533 m_state->m_mainZones[size_t(i+1)]=m_state->m_mainZones[size_t(i)];
2534 }
2535 m_state->m_mainZones[size_t(pos)] = zone->m_zone->id();
2536 pagesLimits[size_t(2*pos)] = fPage;
2537 pagesLimits[size_t(2*pos+1)] = lPage;
2538 numZones++;
2539 int nPages = (lPage-fPage)+1;
2540 if (nPages < int(zone->m_pagesInfo.size())) {
2541 MWAW_DEBUG_MSG(("FullWrtText::sortZones: pages limit seems odd!!!\n"));
2542 nPages = int(zone->m_pagesInfo.size());
2543 }
2544 totalNumPages += nPages;
2545 }
2546 m_state->m_numPages = totalNumPages;
2547 }
2548
2549 void FullWrtText::createItemStructures()
2550 {
2551 for (auto it=m_state->m_itemMap.begin(); it != m_state->m_itemMap.end(); ++it) {
2552 auto &item = it->second;
2553 int childId=item.m_structId[FullWrtTextInternal::Item::Child];
2554 int id=item.m_structId[FullWrtTextInternal::Item::Main];
2555 if (childId<=0)
2556 continue;
2557 int prevId=0;
2558 std::set<int> seens;
2559 while (childId>0) {
2560 if (seens.find(childId)!=seens.end()) {
2561 MWAW_DEBUG_MSG(("FullWrtText::createItemStructures:find loop\n"));
2562 break;
2563 }
2564 seens.insert(childId);
2565 auto it2=m_state->m_itemMap.find(childId);
2566 if (it2==m_state->m_itemMap.end()) {
2567 MWAW_DEBUG_MSG(("FullWrtText::createItemStructures: can not find child: %d\n", childId));
2568 break;
2569 }
2570 FullWrtTextInternal::Item const &child = it2->second;
2571 if (child.m_structId[FullWrtTextInternal::Item::Father] != id ||
2572 child.m_structId[FullWrtTextInternal::Item::Prev] != prevId) {
2573 MWAW_DEBUG_MSG(("FullWrtText::createItemStructures: find unexpected child %d\n", childId));
2574 break;
2575 }
2576 item.m_childList.push_back(childId);
2577 if (child.m_hidden) item.m_collapsed=true;
2578 prevId=childId;
2579 childId=child.m_structId[FullWrtTextInternal::Item::Next];
2580 }
2581 }
2582 }
2583
2584 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: