Debian Codegraph @

src/lib/WriteNowText.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 <sstream>
39
40 #include <librevenge/librevenge.h>
41
42 #include "MWAWCell.hxx"
43 #include "MWAWTextListener.hxx"
44 #include "MWAWFont.hxx"
45 #include "MWAWFontConverter.hxx"
46 #include "MWAWParagraph.hxx"
47 #include "MWAWPictMac.hxx"
48 #include "MWAWPosition.hxx"
49 #include "MWAWSection.hxx"
50 #include "MWAWTable.hxx"
51
52 #include "WriteNowParser.hxx"
53 #include "WriteNowEntry.hxx"
54
55 #include "WriteNowText.hxx"
56
57 /** Internal: the structures of a WriteNowText */
58 namespace WriteNowTextInternal
59 {
60 ////////////////////////////////////////
61 //! Internal: the fonts
62 struct Font {
63 //! the constructor
64 Font()
65 : m_font()
66 {
67 for (auto &fl : m_flags) fl = 0;
68 for (auto &id : m_styleId) id = -1;
69 }
70 //! operator<<
71 friend std::ostream &operator<<(std::ostream &o, Font const &font)
72 {
73 for (int i = 0; i < 3; i++) {
74 if (!font.m_flags[i]) continue;
75 o << "ft" << i << "=";
76 if (i == 0) o << std::hex;
77 o << font.m_flags[i] << std::dec << ",";
78 }
79 if (font.m_styleId[0] >= 0) o << "id[charStyle]=" << font.m_styleId[0] << ",";
80 if (font.m_styleId[1] >= 0) o << "id[rulerStyle]=" << font.m_styleId[1] << ",";
81 return o;
82 }
83
84 //! the font
85 MWAWFont m_font;
86 //! the char/ruler style id
87 int m_styleId[2];
88 //! some unknown flag
89 int m_flags[3];
90 };
91
92 /** Internal: class to store the paragraph properties */
93 struct Paragraph final : public MWAWParagraph {
94 //! constructor
95 Paragraph()
96 : MWAWParagraph()
97 {
98 m_marginsUnit = librevenge::RVNG_POINT;
99 for (auto &val : m_values) val=0;
100 }
101 Paragraph(Paragraph const &)=default;
102 Paragraph &operator=(Paragraph const &)=default;
103 Paragraph &operator=(Paragraph &&)=default;
104 //! destructor
105 ~Paragraph() final;
106 //! operator<<
107 friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind)
108 {
109 o << static_cast<MWAWParagraph const &>(ind);
110 for (int i = 0; i < 8; i++) {
111 if (!ind.m_values[i]) continue;
112 o << "fR" << i << "=" << ind.m_values[i] << ",";
113 }
114 return o;
115 }
116 //! some unknown value
117 int m_values[8];
118 };
119
120 Paragraph::~Paragraph()
121 {
122 }
123
124 /** Internal: class to store a style */
125 struct Style {
126 Style() : m_name(""), m_nextId(-1), m_font(), m_paragraph()
127 {
128 for (auto &val : m_values) val=0;
129 for (auto &fl : m_flags) fl=0;
130 }
131
132 //! operator<<
133 friend std::ostream &operator<<(std::ostream &o, Style const &st)
134 {
135 if (st.m_name.length()) o << st.m_name << ",";
136 if (st.m_nextId >= 0) o << "nextId?=" << st.m_nextId << ",";
137 for (int i = 0; i < 12; i++) {
138 if (st.m_values[i])
139 o << "f" << i << "=" << st.m_values[i] << ",";
140 }
141 o << "flags=[" << std::hex;
142 for (auto fl : st.m_flags) {
143 if (fl)
144 o << fl << ",";
145 else
146 o << "_,";
147 }
148 o << "]," << std::dec;
149 return o;
150 }
151
152 /** the style name */
153 std::string m_name;
154 /** the next style ? */
155 int m_nextId;
156 /** the font properties */
157 Font m_font;
158 /** the paragraph properties */
159 Paragraph m_paragraph;
160 /** some unknown value */
161 int m_values[12];
162 /** some unknown flags */
163 int m_flags[6];
164 };
165
166 ////////////////////////////////////////
167 //! Internal: the token of a WriteNowText
168 struct Token {
169 Token()
170 : m_graphicZone(-1)
171 , m_box()
172 , m_error("")
173 {
174 for (auto &val : m_values) val=0;
175 }
176
177 //! operator<<
178 friend std::ostream &operator<<(std::ostream &o, Token const &tkn)
179 {
180 o << "bdbox=" << tkn.m_box << ",";
181 if (tkn.m_graphicZone >= 0) o << "zId=" << tkn.m_graphicZone << ",";
182 MWAWVec2i tknSize = tkn.m_box.size();
183 for (int i = 0; i < 2; i++) {
184 if (tknSize == tkn.m_pos[i]) continue;
185 o << "pos" << i << "=" << tkn.m_pos[i] << ",";
186 }
187 for (int i = 0; i < 19; i++) {
188 if (!tkn.m_values[i]) continue;
189 if (tkn.m_values[i]>0 && (tkn.m_values[i]&0xF000))
190 o << "f" << i << "=0x" << std::hex << tkn.m_values[i] << std::dec << ",";
191 else
192 o << "f" << i << "=" << tkn.m_values[i] << ",";
193 }
194 if (tkn.m_error.length()) o << tkn.m_error << ",";
195 return o;
196 }
197
198 //! the graphic zone id
199 int m_graphicZone;
200
201 //! the bdbox
202 MWAWBox2i m_box;
203
204 //! two positions ( seen relative to the RB point)
205 MWAWVec2i m_pos[2];
206
207 //! some unknown values
208 int m_values[19];
209
210 /** the parsing errors */
211 std::string m_error;
212 };
213
214 ////////////////////////////////////////
215 //! Internal: the table of a WriteNowText
216 struct TableData {
217 //! constructor
218 TableData()
219 : m_type(-1)
220 , m_box()
221 , m_color(MWAWColor::white())
222 , m_error("")
223 {
224 for (auto &val : m_values) val=0;
225 for (auto &fl : m_flags) fl=0;
226 }
227
228 //! update a cell
229 void updateCell(MWAWCell &cell) const
230 {
231 // as the cells can overlap a little, we build a new box
232 cell.setBdBox(MWAWBox2f(MWAWVec2f(m_box.min()), MWAWVec2f(m_box.max()-MWAWVec2i(1,1))));
233 cell.setBackgroundColor(m_color);
234 for (int i=0; i<4; i++) {
235 MWAWBorder border;
236 switch (m_flags[i]&0x7f) {
237 case 1:
238 break;
239 case 3:
240 border.m_width=2;
241 break;
242 case 5:
243 border.m_type=MWAWBorder::Double;
244 break;
245 case 0x11:
246 border.m_style=MWAWBorder::Dot;
247 break;
248 // 21: ?
249 case 0x61:
250 border.m_width=0.5;
251 break;
252 case 0:
253 default:
254 border.m_width=0;
255 break;
256 }
257
258 if (!border.isEmpty()) {
259 static int const wh[4]= { libmwaw::TopBit, libmwaw::RightBit, libmwaw::BottomBit, libmwaw::LeftBit };
260 cell.setBorders(wh[i], border);
261 }
262 }
263 }
264 //! operator<<
265 friend std::ostream &operator<<(std::ostream &o, TableData const &table)
266 {
267 switch (table.m_type) {
268 case -1:
269 break;
270 case 0:
271 o << "end,";
272 break;
273 case 1:
274 o << "def,";
275 break;
276 case 2:
277 o << "cell,";
278 break;
279 default:
280 o << "type=#" << table.m_type << ",";
281 break;
282 }
283 if (table.m_box.size()[0] || table.m_box.size()[1])
284 o << table.m_box << ",";
285 if (!table.m_color.isWhite())
286 o << "color=" << table.m_color << ",";
287 for (int i = 0; i < 4; i++) {
288 static char const *wh[4]= {"T", "R", "B", "L"};
289 if (table.m_flags[i]&0xFF00)
290 o << "#bFlags" << wh[i] << "[high]=" << (table.m_flags[i]>>8) << ",";
291 // flags&0x80 : duplicated?
292 int fl=table.m_flags[i]&0x7F;
293 if (fl==1) continue; // normal
294 o << "bFlags" << wh[i] << "=";
295 switch (fl) {
296 case 0:
297 o << "none,";
298 break;
299 case 3:
300 o << "w=2,";
301 break;
302 case 5:
303 o << "double,";
304 break;
305 case 0x11:
306 o << "dots,";
307 break;
308 // 21: ?
309 case 0x61: // in fact always 0xe1?
310 o << "w=0.5,";
311 break;
312 default:
313 o << "#" << std::hex << fl << std::dec << ",";
314 break;
315 }
316 }
317 if (table.m_values[0]==1) o << "selected,";
318 else if (table.m_values[0]) o << "#selected=" << table.m_values[0] << ",";
319 for (int i = 1; i < 10; i++) {
320 if (!table.m_values[i]) continue;
321 o << "f" << i << "=" << table.m_values[i] << ",";
322 }
323 if (table.m_error.length()) o << table.m_error << ",";
324 return o;
325 }
326
327 //! the type
328 int m_type;
329
330 //! the bdbox
331 MWAWBox2i m_box;
332
333 //! the background color
334 MWAWColor m_color;
335
336 //! some unknown flags : T, R, B, L
337 int m_flags[4];
338 //! some unknown values
339 int m_values[10];
340
341 /** the parsing errors */
342 std::string m_error;
343 };
344
345 ////////////////////////////////////////
346 //! Internal: structure used to store the content structure
347 struct ContentZone {
348 ContentZone()
349 : m_type(-1)
350 , m_value(0)
351 {
352 for (auto &pos : m_pos) pos=-1;
353 }
354
355 //! operator<<
356 friend std::ostream &operator<<(std::ostream &o, ContentZone const &z);
357
358 /** the type 0 : text,
359 1<->7 : a char flag
360 8<->f : a zone
361 10 : used to store a break
362 */
363 int m_type;
364 //! the begin and the end pos
365 long m_pos[2];
366 //! a value
367 int m_value;
368 };
369
370 std::ostream &operator<<(std::ostream &o, ContentZone const &z)
371 {
372 switch (z.m_type) {
373 case 0:
374 o << "text,";
375 break;
376
377 case 3:
378 o << "[hyphen],";
379 break;
380 case 4:
381 o << "[footnote],";
382 break;
383 case 5:
384 o << "[header],";
385 break;
386 case 6:
387 o << "[footer],";
388 break;
389 case 9:
390 if (z.m_value<0) o << "sub[fontMod],";
391 else if (z.m_value>0) o << "super[fontMod],";
392 else o << "normal[fontMod],";
393 break;
394 case 0xa: {
395 switch (z.m_value) {
396 case 0:
397 o << "table[end],";
398 break;
399 case 1:
400 o << "table[header],";
401 break;
402 case 2:
403 o << "table[zone],";
404 break;
405 default:
406 o << "table[#" << int(z.m_value>>4) << "#],";
407 break;
408 }
409 break;
410 }
411 case 0xb:
412 o << "decimal[" << char(z.m_value) << "],";
413 break;
414 case 0xc:
415 o << "ruler,";
416 break;
417 case 0xd: {
418 switch (z.m_value) {
419 case 0:
420 o << "page[field],";
421 break;
422 case 1:
423 o << "date[field],";
424 break;
425 case 2:
426 o << "time[field],";
427 break;
428 case 3:
429 o << "note[field],";
430 break;
431 default:
432 o << "#field=" << z.m_value <<",";
433 break;
434 }
435 break;
436 }
437 case 0xe:
438 o << "token,";
439 break;
440 case 0xf:
441 o << "font,";
442 break;
443 case 0x10:
444 o << "break,";
445 break;
446 default:
447 o << "type=#" << z.m_type << ",";
448 break;
449 }
450 return o;
451 }
452
453 ////////////////////////////////////////
454 //! Internal: structure used to store the content structure
455 struct ContentZones {
456 ContentZones()
457 : m_entry()
458 , m_id(-1)
459 , m_type(0)
460 , m_zonesList()
461 , m_textCalledTypesList()
462 , m_footnoteList()
463 , m_sent(false)
464 {
465 }
466 /** returns true if the entry corresponds to a page/column break */
467 bool hasPageColumnBreak() const
468 {
469 return m_type == 0 && (m_entry.m_val[0] >> 4) == 7;
470 }
471 int getNumberOfZonesWithType(int type) const
472 {
473 int res = 0;
474 for (auto const &zone : m_zonesList)
475 if (zone.m_type == type) res++;
476 return res;
477 }
478 //! the general zone
479 WriteNowEntry m_entry;
480 //! the zone id
481 int m_id;
482 //! the zone type : 0 : main, 1 header/footer, 2 footnote,
483 int m_type;
484 //! the list of zone
485 std::vector<ContentZone> m_zonesList;
486 //! the list of type of text zone called by this zone
487 std::vector<int> m_textCalledTypesList;
488 //! a list to retrieve the footnote content
489 std::vector<std::shared_ptr<ContentZones> > m_footnoteList;
490 //! true if this zone was sent to the listener
491 mutable bool m_sent;
492 };
493
494
495 ////////////////////////////////////////
496 //! Internal: the cell of a WriteNowText
497 struct Cell final : public MWAWCell {
498 //! constructor
499 explicit Cell(WriteNowText &parser)
500 : MWAWCell()
501 , m_parser(parser)
502 , m_zonesList()
503 , m_footnoteList()
504 {
505 }
506
507 //! send the content
508 bool sendContent(MWAWListenerPtr, MWAWTable &) final;
509 //! the text parser
510 WriteNowText &m_parser;
511 //! the list of zone
512 std::vector<ContentZone> m_zonesList;
513 //! a list to retrieve the footnote content
514 std::vector<std::shared_ptr<ContentZones> > m_footnoteList;
515 };
516
517 ////////////////////////////////////////
518 ////////////////////////////////////////
519 struct Table final : public MWAWTable {
520 //! constructor
521 Table()
522 : MWAWTable()
523 {
524 }
525 //! destructor
526 ~Table() final;
527 //! return a cell corresponding to id
528 Cell *get(int id)
529 {
530 if (id < 0 || id >= numCells()) {
531 MWAW_DEBUG_MSG(("WriteNowTextInternal::Table::get: cell %d does not exists\n",id));
532 return nullptr;
533 }
534 return static_cast<Cell *>(MWAWTable::get(id).get());
535 }
536 };
537
538 Table::~Table()
539 {
540 }
541
542 ////////////////////////////////////////
543 //! Internal: structure used to store the content structure
544 struct Zone {
545 //! constructor
546 Zone()
547 : m_zones()
548 {
549 }
550
551 //! a zones
552 std::vector<std::shared_ptr<ContentZones> > m_zones;
553 };
554
555 ////////////////////////////////////////
556 //! Internal: the state of a WriteNowText
557 struct State {
558 //! constructor
559 State()
560 : m_version(-1)
561 , m_numColumns(1)
562 , m_numPages(1)
563 , m_actualPage(1)
564 , m_paragraph()
565 , m_header()
566 , m_footer()
567 , m_localFIdMap()
568 , m_styleMap()
569 , m_styleList()
570 , m_contentMap()
571 {
572 }
573
574 //! return a paragraph corresponding to 0:body, 1: header/footer, 2: footnote
575 Paragraph getDefaultParagraph(int type) const
576 {
577 int styleId = type == 0 ? 0 : type==1 ? 3 : type==2 ? 2 : -1;
578 if (styleId >= 0 && styleId < int(m_styleList.size()))
579 return m_styleList[size_t(styleId)].m_paragraph;
580 Paragraph res;
581 if (m_version>=0 && m_version <= 2 && type==0) {
582 res.m_margins[1] = 90.0;
583 res.m_margins[2] = 60.0-28.0;
584 static double const defPos[2] = {1.5,5.5};
585 for (double i : defPos) {
586 MWAWTabStop defTab;
587 defTab.m_position=i;
588 res.m_tabs->push_back(defTab);
589 }
590 }
591 if (type==1)
592 res.m_justify = MWAWParagraph::JustificationCenter;
593 if (type==2) res.m_margins[0] = 10;
594 return res;
595 }
596
597
598 //! return a mac font id corresponding to a local id
599 int getFontId(int localId) const
600 {
601 if (m_localFIdMap.find(localId)==m_localFIdMap.end())
602 return localId;
603 return m_localFIdMap.find(localId)->second;
604 }
605 //! return the content corresponding to a pos
606 std::shared_ptr<ContentZones> getContentZone(long pos) const
607 {
608 auto it = m_contentMap.find(pos);
609 if (it == m_contentMap.end())
610 return std::shared_ptr<ContentZones>();
611 return it->second;
612 }
613
614 //! the file version
615 mutable int m_version;
616 //! the number of column
617 int m_numColumns;
618
619 int m_numPages /* the number of pages */, m_actualPage /* the actual page */;
620 /** the paragraph properties */
621 Paragraph m_paragraph;
622 //! the header and the footer
623 std::shared_ptr<ContentZones> m_header, m_footer;
624 //! a map local fontId->fontId
625 std::map<int, int> m_localFIdMap;
626 //! the style indirection table
627 std::map<int, int> m_styleMap;
628 //! the list of styles (body, footer, footnote, header, table )
629 std::vector<Style> m_styleList;
630
631 //! the three main zone ( text, footnote, header/footer)
632 Zone m_mainZones[3];
633
634 //! the list of contentZones
635 std::map<long, std::shared_ptr<ContentZones> > m_contentMap;
636 };
637
638 bool Cell::sendContent(MWAWListenerPtr, MWAWTable &)
639 {
640 /** as a cell can be arbitrary cutted in small part,
641 we must retrieve the last ruler */
642 Paragraph ruler = m_parser.m_state->m_paragraph;
643 m_parser.send(m_zonesList, m_footnoteList, ruler);
644 return true;
645 }
646
647 }
648
649 ////////////////////////////////////////////////////////////
650 // constructor/destructor, ...
651 ////////////////////////////////////////////////////////////
652 WriteNowText::WriteNowText(WriteNowParser &parser)
653 : m_parserState(parser.getParserState())
654 , m_state(new WriteNowTextInternal::State)
655 , m_entryManager(parser.m_entryManager)
656 , m_mainParser(&parser)
657 {
658 }
659
660 WriteNowText::~WriteNowText()
661 { }
662
663 int WriteNowText::version() const
664 {
665 if (m_state->m_version < 0)
666 m_state->m_version = m_parserState->m_version;
667 return m_state->m_version;
668 }
669
670 int WriteNowText::numPages() const
671 {
672 int nCol, width;
673 m_state->m_actualPage = m_state->m_numPages = 1;
674 m_mainParser->getColumnInfo(nCol, width);
675 m_state->m_numColumns = nCol;
676 if (nCol >= 2) return 1;
677
678 if (m_state->m_mainZones[0].m_zones.size()==0 ||
679 m_state->m_mainZones[0].m_zones[0]->m_type != 0) {
680 m_state->m_numPages = 1;
681 return 1;
682 }
683 auto mainContent = m_state->m_mainZones[0].m_zones[0];
684 int nPages = 1+mainContent->getNumberOfZonesWithType(0x10);
685 m_state->m_numPages = nPages;
686 return nPages;
687 }
688
689 WriteNowEntry WriteNowText::getHeader() const
690 {
691 if (!m_state->m_header)
692 return WriteNowEntry();
693 return m_state->m_header->m_entry;
694 }
695
696 WriteNowEntry WriteNowText::getFooter() const
697 {
698 if (!m_state->m_footer)
699 return WriteNowEntry();
700 return m_state->m_footer->m_entry;
701 }
702
703 ////////////////////////////////////////////////////////////
704 // Intermediate level
705 ////////////////////////////////////////////////////////////
706 ////////////////////////////////////////////////////////////
707 // try to find the different zone
708 ////////////////////////////////////////////////////////////
709 bool WriteNowText::createZones()
710 {
711 auto iter = m_entryManager->m_typeMap.find("FontZone");
712 if (iter != m_entryManager->m_typeMap.end())
713 readFontNames(*iter->second);
714
715 iter = m_entryManager->m_typeMap.find("StylZone");
716 if (iter != m_entryManager->m_typeMap.end())
717 readStyles(*iter->second);
718
719 // the text zone
720 iter = m_entryManager->m_typeMap.find("TextZone");
721 int numData = 0;
722 std::vector<WriteNowEntry> listData[3];
723 while (iter != m_entryManager->m_typeMap.end()) {
724 if (iter->first != "TextZone")
725 break;
726 int id = iter->second->id();
727 if (id < 0 || id > 2) {
728 MWAW_DEBUG_MSG(("WriteNowText::createZones: find odd zone type:%d\n",id));
729 ++iter;
730 continue;
731 }
732 parseZone(*iter->second, listData[id]);
733 ++iter;
734 }
735
736 // update the number of columns
737 int nCol, width;
738 m_mainParser->getColumnInfo(nCol, width);
739 m_state->m_numColumns = nCol;
740
741 std::map<long, std::shared_ptr<WriteNowTextInternal::ContentZones> > listDone;
742 /** we can now create the content zone and type them */
743 for (int z = 2; z >= 0; z--) {
744 for (auto &data : listData[z]) {
745 auto it = listDone.find(data.begin());
746 if (it != listDone.end()) {
747 m_state->m_mainZones[z].m_zones.push_back(it->second);
748 continue;
749 }
750
751 // ok we must create the data
752 data.setId(numData++);
753 std::shared_ptr<WriteNowTextInternal::ContentZones> zone;
754 if (m_entryManager->add(data))
755 zone = parseContent(m_entryManager->m_posMap.find(data.begin())->second);
756 if (zone) {
757 zone->m_type = z;
758 m_state->m_mainZones[z].m_zones.push_back(zone);
759 listDone[data.begin()] = zone;
760 }
761 }
762 }
763 /* we can now recreate a zone 0 which contains all the main content zone*/
764 auto &mainZone = m_state->m_mainZones[0];
765 std::vector<std::shared_ptr<WriteNowTextInternal::ContentZones> > headerFooterList;
766 std::vector<int> calledTypesList;
767
768 std::shared_ptr<WriteNowTextInternal::ContentZones> zone0(new WriteNowTextInternal::ContentZones);
769 zone0->m_id = -1;
770 zone0->m_type = 0;
771 for (auto const &content : mainZone.m_zones) {
772 switch (content->m_type) {
773 case 0:
774 break;
775 case 1:
776 headerFooterList.push_back(content);
777 break;
778 case 2:
779 zone0->m_footnoteList.push_back(content);
780 break;
781 default:
782 MWAW_DEBUG_MSG(("WriteNowText::createZones: find odd zone type(II):%d\n",content->m_type));
783 break;
784 }
785 if (content->m_type != 0)
786 continue;
787 if (content->hasPageColumnBreak()) {
788 WriteNowTextInternal::ContentZone breakF;
789 breakF.m_type=0x10;
790 zone0->m_zonesList.push_back(breakF);
791 }
792 zone0->m_zonesList.insert(zone0->m_zonesList.end(),
793 content->m_zonesList.begin(),
794 content->m_zonesList.end());
795 calledTypesList.insert(calledTypesList.end(),
796 content->m_textCalledTypesList.begin(),
797 content->m_textCalledTypesList.end());
798 }
799 mainZone.m_zones.resize(0);
800 mainZone.m_zones.push_back(zone0);
801 /* try to create the footnote and the header link */
802 int numHeaderFooter = 0; // header+footer
803
804 auto content = mainZone.m_zones[0];
805 if (content->m_type != 0) return false;
806
807 for (auto called : calledTypesList) {
808 if (called < 5 || called > 6) {
809 MWAW_DEBUG_MSG(("WriteNowText::createZones: unknown content %d\n", called));
810 continue;
811 }
812 int number = numHeaderFooter++;
813 if (number >= int(headerFooterList.size())) {
814 MWAW_DEBUG_MSG(("WriteNowText::createZones: can not find zone for type:%d\n", called));
815 continue;
816 }
817 if (called == 5) {
818 if (m_state->m_header)
819 MWAW_DEBUG_MSG(("WriteNowText::createZones: header is already defined\n"));
820 else
821 m_state->m_header = headerFooterList[size_t(number)];
822 }
823 else { // 6
824 if (m_state->m_footer)
825 MWAW_DEBUG_MSG(("WriteNowText::createZones: footer is already defined\n"));
826 else
827 m_state->m_footer = headerFooterList[size_t(number)];
828 }
829 }
830
831 return true;
832 }
833
834 ////////////////////////////////////////////////////////////
835 // try to parse a text data zone
836 ////////////////////////////////////////////////////////////
837 std::shared_ptr<WriteNowTextInternal::ContentZones> WriteNowText::parseContent(WriteNowEntry const &entry)
838 {
839 int vers = version();
840
841 if (m_state->getContentZone(entry.begin())) {
842 MWAW_DEBUG_MSG(("WriteNowText::parseContent: textContent is already parsed\n"));
843 return m_state->getContentZone(entry.begin());
844 }
845
846 if (!entry.valid()) {
847 MWAW_DEBUG_MSG(("WriteNowText::parseContent: text zone size is invalid\n"));
848 return std::shared_ptr<WriteNowTextInternal::ContentZones>();
849 }
850
851 MWAWInputStreamPtr &input= m_parserState->m_input;
852 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
853 libmwaw::DebugStream f;
854 f << "Entries(TextData)[" << entry.id() << "]:";
855 // print the text zone data
856 f << std::hex << "txtZone=[" << std::hex << entry.m_val[0] << std::dec
857 <<",h=" << entry.m_val[1] << "],";
858 std::shared_ptr<WriteNowTextInternal::ContentZones> text;
859 if (vers >= 3) {
860 if (entry.length() < 16) {
861 MWAW_DEBUG_MSG(("WriteNowText::parseContent: text zone size is too short\n"));
862 return text;
863 }
864 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
865 if (input->readLong(4) != entry.length()) {
866 MWAW_DEBUG_MSG(("WriteNowText::parseContent: bad begin of last zone\n"));
867 return text;
868 }
869
870 text.reset(new WriteNowTextInternal::ContentZones);
871 text->m_entry = entry;
872 text->m_id = entry.id();
873
874 // in 1/3 files, ptr0=begin.pos()+(flag<<15: rev?), but not in other files :-~
875 long val;
876 for (int i=0; i < 2; i++) {
877 val = long(input->readULong(4));
878 if (!val) continue;
879 f << "ptr" << i << "=" << std::hex << (val&0x7FFF) << std::dec;
880 if (val>>15)
881 f << "[" << std::hex << (val>>15) << std::dec << "],";
882 else
883 f << ",";
884 }
885 for (int i = 0; i < 2; i++) {
886 val = input->readLong(2);
887 f << "f" << i << "=" << val << ",";
888 }
889 }
890 else {
891 if (entry.length() < 2) {
892 MWAW_DEBUG_MSG(("WriteNowText::parseContent: text zone size is too short\n"));
893 return text;
894 }
895 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
896 if (int(input->readULong(2))+2 != entry.length()) {
897 MWAW_DEBUG_MSG(("WriteNowText::parseContent: bad begin of last zone\n"));
898 return text;
899 }
900
901 text.reset(new WriteNowTextInternal::ContentZones);
902 text->m_entry = entry;
903 text->m_id = entry.id();
904 }
905 ascFile.addPos(entry.begin());
906 ascFile.addNote(f.str().c_str());
907
908 while (long(input->tell()) < entry.end()) {
909 long pos = input->tell();
910 WriteNowTextInternal::ContentZone zone;
911 auto c = static_cast<int>(input->readULong(1));
912 if (c == 0xf0) {
913 MWAW_DEBUG_MSG(("WriteNowText::parseContent: find 0xf0 entry\n"));
914 ascFile.addPos(pos);
915 ascFile.addNote("TextData:##");
916 return text;
917 }
918 int type = 0;
919 if ((c & 0xf0)==0xf0) type = (c & 0xf);
920 zone.m_pos[0] = (type < 8) ? pos : pos+1;
921 zone.m_type = type;
922 if (type == 0) { // text entry
923 while (long(input->tell()) != entry.end()) {
924 c = static_cast<int>(input->readULong(1));
925 if (c == 0xf0) continue;
926 if ((c&0xf0)==0xf0) {
927 input->seek(-1, librevenge::RVNG_SEEK_CUR);
928 break;
929 }
930 }
931 zone.m_pos[1] = input->tell();
932 }
933 else if (type >= 8) {
934 bool firstSeen = false;
935 int numChar = 0;
936 zone.m_pos[1] = entry.end();
937 while (long(input->tell()) != entry.end()) {
938 if (input->isEnd() || input->tell() > entry.end()) {
939 MWAW_DEBUG_MSG(("WriteNowText::parseContent: can not read end of text\n"));
940 ascFile.addPos(pos);
941 ascFile.addNote("TextData:##");
942 return text;
943 }
944 c = static_cast<int>(input->readULong(1));
945 if (c==0xf7) {
946 zone.m_pos[1] = long(input->tell())-1;
947 break;
948 }
949
950 if (c==0xf0)
951 c = int(0xf0 | (input->readULong(1) & 0xf));
952 numChar++;
953 if (!firstSeen) {
954 zone.m_value = c;
955 firstSeen = true;
956 }
957 }
958 if ((type == 0xb || type == 0xd) && numChar != 1) {
959 MWAW_DEBUG_MSG(("WriteNowText::parseContent: find odd size for type %x entry\n", static_cast<unsigned int>(type)));
960 ascFile.addPos(pos);
961 ascFile.addNote("TextData:##");
962
963 continue;
964 }
965 }
966 else
967 zone.m_pos[1] = pos+1;
968
969 text->m_zonesList.push_back(zone);
970 if (type >= 5 && type <= 6) // header footer
971 text->m_textCalledTypesList.push_back(type);
972
973 f.str("");
974 f << "TextData-" << text->m_id << ":" << zone;
975 ascFile.addPos(pos);
976 ascFile.addNote(f.str().c_str());
977 }
978
979 entry.setParsed(true);
980 ascFile.addPos(entry.end());
981 ascFile.addNote("_");
982
983 m_state->m_contentMap[entry.begin()] = text;
984 if (long(input->tell()) != entry.end()) {
985 MWAW_DEBUG_MSG(("WriteNowText::parseContent: go after entry end\n"));
986 }
987
988 return text;
989 }
990
991 ////////////////////////////////////////////////////////////
992 // try to parse a list of content zones
993 ////////////////////////////////////////////////////////////
994 bool WriteNowText::parseZone(WriteNowEntry const &entry, std::vector<WriteNowEntry> &listData)
995 {
996 listData.resize(0);
997 int vers = version();
998 int dataSz = 16, headerSz = 16, lengthSz=4;
999 if (vers <= 2) {
1000 dataSz = 6;
1001 headerSz = lengthSz = 2;
1002 }
1003 MWAWInputStreamPtr &input= m_parserState->m_input;
1004 if (!entry.valid() || entry.length() < headerSz
1005 || (entry.length()%dataSz) !=(headerSz%dataSz) || !input->checkPosition(entry.end())) {
1006 MWAW_DEBUG_MSG(("WriteNowText::parseZone: text zone size is invalid\n"));
1007 return false;
1008 }
1009
1010 long endPos = entry.end();
1011 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1012 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1013 auto sz = long(input->readULong(lengthSz));
1014 if (vers>2 && sz != entry.length()) {
1015 MWAW_DEBUG_MSG(("WriteNowText::parseZone: bad begin of last zone\n"));
1016 return false;
1017 }
1018
1019 libmwaw::DebugStream f;
1020 f << "Entries(TextZone)[";
1021 switch (entry.id()) {
1022 case 0:
1023 f << "main";
1024 break;
1025 case 1:
1026 f << "header/footer";
1027 break;
1028 case 2:
1029 f << "note";
1030 break;
1031 default:
1032 f << entry.id() << "#";
1033 break;
1034 }
1035 f << "]:";
1036 long val;
1037 if (vers > 2) {
1038 /* seems very simillar that the 2 "ptr" in parseContent:
1039 sometimes ptr0=begin.pos()+some flag, sometimes not :-~ */
1040 f << "ptr?=" << std::hex << input->readULong(4) << std::dec << ",";
1041 f << "ptr2?=" << std::hex << input->readULong(4) << std::dec << ",";
1042 for (int i = 0; i < 2; i++) {
1043 val = input->readLong(2);
1044 f << "f" << i << "=" << val << ",";
1045 }
1046 }
1047 auto numElts = int((entry.length()-headerSz)/dataSz);
1048 for (int elt=0; elt<numElts; elt++) {
1049 f << "entry" << elt << "=[";
1050 auto flags = static_cast<int>(input->readULong(1));
1051 /* find
1052 40 44 45 : header ?
1053 60 61 64 65 : text ?
1054 70 74 7c : text + new page ?
1055 c0 c4 e0 e4 : empty
1056
1057 header: 86: even, a6 even|odd, c6|odd ?
1058 */
1059 f << "fl=" << std::hex << flags << std::dec << ",";
1060 for (int i = 0; i < 3; i++) {
1061 val = long(input->readULong(1));
1062 if (!i && val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1063 if (vers <= 2) break;
1064 }
1065
1066 WriteNowEntry zEntry;
1067 zEntry.setBegin(long(input->readULong(vers <= 2 ? 2 : 4)));
1068 if (vers > 2) zEntry.setLength(long(input->readULong(4)));
1069 else if (zEntry.begin() &&
1070 m_mainParser->checkIfPositionValid(zEntry.begin())) {
1071 long actPos = input->tell();
1072 input->seek(zEntry.begin(), librevenge::RVNG_SEEK_SET);
1073 zEntry.setLength(long(input->readULong(2))+2);
1074 input->seek(actPos, librevenge::RVNG_SEEK_SET);
1075 }
1076 zEntry.setType("TextData");
1077 zEntry.m_fileType = 4;
1078 zEntry.m_val[0] = flags;
1079 zEntry.m_val[1] = static_cast<int>(input->readLong(lengthSz));
1080
1081 if (zEntry.begin() == 0 && zEntry.length()==0) f << "_" << ",";
1082 else {
1083 bool ok = true;
1084 if (zEntry.end() > endPos) {
1085 if (!m_mainParser->checkIfPositionValid(zEntry.end())) {
1086 f << "#";
1087 MWAW_DEBUG_MSG(("WriteNowText::parseZone: odd pointer for text zone %d\n", elt));
1088 ok = false;
1089 }
1090 else
1091 endPos = zEntry.end();
1092 }
1093 if (ok) {
1094 listData.push_back(zEntry);
1095 f << "pos=" << std::hex << zEntry.begin() << std::dec << ",";
1096 }
1097 }
1098 f << "h=" << zEntry.m_val[1] << "],";
1099 }
1100
1101 entry.setParsed(true);
1102 ascFile.addPos(entry.begin());
1103 ascFile.addNote(f.str().c_str());
1104 ascFile.addPos(entry.end());
1105 ascFile.addNote("_");
1106 return true;
1107 }
1108
1109 ////////////////////////////////////////////////////////////
1110 //
1111 // Low level
1112 //
1113 ////////////////////////////////////////////////////////////
1114
1115 ////////////////////////////////////////////////////////////
1116 // the fonts names
1117 ////////////////////////////////////////////////////////////
1118 bool WriteNowText::readFontNames(WriteNowEntry const &entry)
1119 {
1120 if (!entry.valid() || entry.length() < 0x10) {
1121 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: zone size is invalid\n"));
1122 return false;
1123 }
1124
1125 MWAWInputStreamPtr &input= m_parserState->m_input;
1126 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1127 if (input->readLong(4) != entry.length()) {
1128 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: bad begin of last zone\n"));
1129 return false;
1130 }
1131 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1132 libmwaw::DebugStream f;
1133 f << "Entries(Fonts):";
1134 f << "ptr?=" << std::hex << input->readULong(4) << std::dec << ",";
1135 f << "ptr2?=" << std::hex << input->readULong(4) << std::dec << ",";
1136 long pos, val;
1137 for (int i = 0; i < 3; i++) { // 6, 0, 0
1138 val = input->readLong(2);
1139 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1140 }
1141 auto N=static_cast<int>(input->readULong(2));
1142 f << "N=" << N << ",";
1143 for (int i = 0; i < 2; i++) { // 0
1144 val = input->readLong(2);
1145 if (val) f << "g" << i << "=" << val << ",";
1146 }
1147 if (long(input->tell())+N*8 > entry.end()) {
1148 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: the zone is too short\n"));
1149 return false;
1150 }
1151 ascFile.addPos(entry.begin());
1152 ascFile.addNote(f.str().c_str());
1153 std::vector<long> defPos;
1154 for (int n = 0; n < N; n++) {
1155 pos = input->tell();
1156 f.str("");
1157 f << "Fonts[" << n << "]:";
1158 auto type = static_cast<int>(input->readULong(1));
1159 switch (type) {
1160 case 0:
1161 f << "def,";
1162 break;
1163 default:
1164 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: find unknown type %d\n", type));
1165 f << "#type=" << type << ",";
1166 break;
1167 }
1168 for (int i = 0; i < 3; i++) { // always 0
1169 val = input->readLong(1);
1170 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1171 }
1172 val = long(input->readULong(4));
1173 defPos.push_back(pos+val);
1174 // fixme: used this to read the data...
1175 f << "defPos=" << std::hex << pos+val << std::dec << ",";
1176 ascFile.addPos(pos);
1177 ascFile.addNote(f.str().c_str());
1178 }
1179
1180 for (int n = 0; n < N; n++) {
1181 pos = defPos[size_t(n)];
1182 if (pos == entry.end()) continue;
1183 if (pos+13 > entry.end()) {
1184 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: can not read entry : %d\n", n));
1185 continue;
1186 }
1187
1188 input->seek(pos, librevenge::RVNG_SEEK_SET);
1189 f.str("");
1190 f << "FontsData[" << n << "]:";
1191 val = input->readLong(2);
1192 f << "fId(local)=" << val << ","; // almost always local fid
1193 val = input->readLong(2);
1194 if (val) f << "unkn=" << val << ",";
1195 f << "ptr?=" << std::hex << input->readULong(4) << std::dec << ",";
1196 for (int i = 0; i < 2; i++) { // always 0
1197 val = input->readLong(2);
1198 if (val) f << "f" << i << "=" << val << ",";
1199 }
1200 auto sz = static_cast<int>(input->readULong(1));
1201 if (pos+13+sz > entry.end()) {
1202 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: can not read entry name : %d\n", n));
1203 return false;
1204 }
1205
1206 bool ok = true;
1207 std::string name("");
1208 for (int i = 0; i < sz; i++) {
1209 auto ch = char(input->readULong(1));
1210 if (ch == '\0') {
1211 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: pb with name field %d\n", n));
1212 ok = false;
1213 break;
1214 }
1215 else if (ch & 0x80) {
1216 static bool first = true;
1217 if (first) {
1218 MWAW_DEBUG_MSG(("WriteNowText::readFontNames: find odd font\n"));
1219 first = false;
1220 }
1221 ok = false;
1222 }
1223 name += ch;
1224 }
1225 f << name << ",";
1226 if (name.length() && ok)
1227 m_state->m_localFIdMap[n]= m_parserState->m_fontConverter->getId(name);
1228 ascFile.addPos(pos);
1229 ascFile.addNote(f.str().c_str());
1230 }
1231
1232 entry.setParsed(true);
1233 ascFile.addPos(entry.end());
1234 ascFile.addNote("_");
1235 return true;
1236 }
1237
1238 ////////////////////////////////////////////////////////////
1239 // the fonts properties
1240 ////////////////////////////////////////////////////////////
1241 bool WriteNowText::readFont(MWAWInputStream &input, bool inStyle, WriteNowTextInternal::Font &font)
1242 {
1243 font = WriteNowTextInternal::Font();
1244 int vers = version();
1245 libmwaw::DebugStream f;
1246
1247 long pos = input.tell();
1248 int expectedLength = vers <= 2 ? 4 : 14;
1249 input.seek(expectedLength, librevenge::RVNG_SEEK_CUR);
1250 if (pos+expectedLength != long(input.tell())) {
1251 MWAW_DEBUG_MSG(("WriteNowText::readFont: zone is too short \n"));
1252 return false;
1253 }
1254 input.seek(pos, librevenge::RVNG_SEEK_SET);
1255
1256 font.m_font.setId(m_state->getFontId(static_cast<int>(input.readULong(2))));
1257 font.m_font.setSize(float(input.readULong(vers <= 2 ? 1 : 2)));
1258 auto flag = int(input.readULong(1));
1259 uint32_t flags=0;
1260 if (flag&0x1) flags |= MWAWFont::boldBit;
1261 if (flag&0x2) flags |= MWAWFont::italicBit;
1262 if (flag&0x4) font.m_font.setUnderlineStyle(MWAWFont::Line::Simple);
1263 if (flag&0x8) flags |= MWAWFont::embossBit;
1264 if (flag&0x10) flags |= MWAWFont::shadowBit;
1265 if (flag&0x20) font.m_font.setDeltaLetterSpacing(-1);
1266 if (flag&0x40) font.m_font.setDeltaLetterSpacing(1);
1267 if (flag&0x80) f << "#flag0[0x80],";
1268
1269 if (vers <= 2) {
1270 font.m_font.setFlags(flags);
1271 font.m_font.m_extra = f.str();
1272 return true;
1273 }
1274 flag = static_cast<int>(input.readULong(1));
1275 if (flag&0x80) font.m_font.setStrikeOutStyle(MWAWFont::Line::Simple);
1276 if (flag&0x7f) f << "#flag1=" << std::hex << (flag&0x7f) << std::dec << ",";
1277
1278 flag = static_cast<int>(input.readULong(1));
1279 if (flag&0x2) {
1280 font.m_font.setUnderlineStyle(MWAWFont::Line::Simple);
1281 font.m_font.setUnderlineType(MWAWFont::Line::Double);
1282 }
1283 if (flag&0x4) {
1284 font.m_font.setUnderlineStyle(MWAWFont::Line::Simple);
1285 font.m_font.setUnderlineWidth(2.0);
1286 }
1287 if (flag&0x8) {
1288 font.m_font.setUnderlineStyle(MWAWFont::Line::Simple);
1289 font.m_font.setUnderlineColor(MWAWColor(0xb0,0xb0,0xb0));
1290 }
1291 if (flag&0x10) {
1292 font.m_font.setUnderlineStyle(MWAWFont::Line::Wave);
1293 f << "underline[charcoal],";
1294 }
1295 if (flag&0x20) font.m_font.setUnderlineStyle(MWAWFont::Line::Dash);
1296 if (flag&0x40) font.m_font.setUnderlineStyle(MWAWFont::Line::Dot);
1297 if (flag&0x81) f << "#flag2=" << std::hex << (flag&0x81) << std::dec << ",";
1298
1299 auto color = static_cast<int>(input.readULong(1)); // fixme find color map
1300 if (color) {
1301 MWAWColor col;
1302 if (m_mainParser->getColor(color,col))
1303 font.m_font.setColor(col);
1304 else
1305 f << "#colorId=" << color << ",";
1306 }
1307 auto heightDecal = static_cast<int>(input.readLong(2));
1308 if (heightDecal)
1309 font.m_font.set(MWAWFont::Script(float(heightDecal), librevenge::RVNG_POINT));
1310
1311 font.m_font.setFlags(flags);
1312 font.m_font.m_extra = f.str();
1313
1314 int act = 0;
1315 if (inStyle) {
1316 font.m_flags[act++] = static_cast<int>(input.readULong(4));
1317 font.m_flags[act++] = static_cast<int>(input.readLong(2));
1318 }
1319 else {
1320 font.m_flags[act++] = static_cast<int>(input.readLong(1)); // 5: note def, 6: note pos ?
1321 font.m_styleId[0] = static_cast<int>(input.readULong(1))-1;
1322 font.m_styleId[1] = static_cast<int>(input.readULong(1))-1;
1323 font.m_flags[act++] = static_cast<int>(input.readLong(1)); // alway 0
1324 }
1325 return true;
1326 }
1327
1328 ////////////////////////////////////////////////////////////
1329 // the paragraphs properties
1330 ////////////////////////////////////////////////////////////
1331 bool WriteNowText::readParagraph(MWAWInputStream &input, WriteNowTextInternal::Paragraph &ruler)
1332 {
1333 libmwaw::DebugStream f;
1334 int vers = version();
1335 ruler = WriteNowTextInternal::Paragraph();
1336 long pos = input.tell();
1337 int expectedLength = vers <= 2 ? 8 : 16;
1338 input.seek(expectedLength, librevenge::RVNG_SEEK_CUR);
1339 if (pos+expectedLength != long(input.tell())) {
1340 MWAW_DEBUG_MSG(("WriteNowText::readParagraph: zone is too short: %ld\n",
1341 long(input.tell()) - pos));
1342 return false;
1343 }
1344 input.seek(pos, librevenge::RVNG_SEEK_SET);
1345 int actVal = 0;
1346 /* small number, 0, small number < 3 */
1347 if (vers >= 3) {
1348 for (int i = 0; i < 2; i++)
1349 ruler.m_values[actVal++] = static_cast<int>(input.readULong(1));
1350 }
1351 ruler.m_margins[1]=static_cast<int>(input.readLong(2));
1352 ruler.m_margins[2]=static_cast<int>(input.readLong(2));
1353 ruler.m_margins[0]=static_cast<int>(input.readLong(2));
1354 *(ruler.m_margins[0])-=ruler.m_margins[1].get();
1355 int height = 0;
1356 if (vers >= 3) {
1357 height=static_cast<int>(input.readLong(2));
1358 for (int i = 0; i < 3; i++)
1359 ruler.m_values[actVal++] = static_cast<int>(input.readULong(2));
1360 }
1361 auto flag = static_cast<int>(input.readULong(1));
1362 switch (flag & 3) {
1363 case 0:
1364 break; // left
1365 case 1:
1366 ruler.m_justify = MWAWParagraph::JustificationFull;
1367 break;
1368 case 2:
1369 ruler.m_justify = MWAWParagraph::JustificationCenter;
1370 break;
1371 case 3:
1372 ruler.m_justify = MWAWParagraph::JustificationRight;
1373 break;
1374 default:
1375 break;
1376 }
1377 bool interlineFixed = (flag & 0x80);
1378 ruler.m_values[actVal++] = (flag & 0x7c);
1379 if (vers <= 2)
1380 height=static_cast<int>(input.readULong(1));
1381 else
1382 ruler.m_values[actVal++] = static_cast<int>(input.readULong(1)); // always 0
1383 ruler.m_tabs->resize(0);
1384 if (!input.isEnd()) {
1385 int previousVal = 0;
1386 int tab = 0;
1387 while (!input.isEnd()) {
1388 MWAWTabStop newTab;
1389 auto newVal = static_cast<int>(input.readULong(2));
1390 if (tab && newVal < previousVal) {
1391 MWAW_DEBUG_MSG(("WriteNowText::readParagraph: find bad tab pos\n"));
1392 f << "#tab[" << tab << ",";
1393 input.seek(-1, librevenge::RVNG_SEEK_CUR);
1394 break;
1395 }
1396 previousVal = newVal;
1397 ++tab;
1398 newTab.m_position = (newVal>>2)/72.;
1399 switch (newVal & 3) {
1400 case 0:
1401 break;
1402 case 1:
1403 newTab.m_alignment = MWAWTabStop::CENTER;
1404 break;
1405 case 2:
1406 newTab.m_alignment = MWAWTabStop::RIGHT;
1407 break;
1408 case 3:
1409 newTab.m_alignment = MWAWTabStop::DECIMAL;
1410 break;
1411 default:
1412 break;
1413 }
1414 ruler.m_tabs->push_back(newTab);
1415 }
1416 }
1417 if (version() <= 2) // distance from right
1418 ruler.m_margins[2] = int(72.0*m_mainParser->getPageWidth())-ruler.m_margins[2].get();
1419 *(ruler.m_margins[2]) -= 28.;
1420 if (ruler.m_margins[2].get() < 0) ruler.m_margins[2]=0;
1421 if (!interlineFixed && height>=0)
1422 ruler.setInterline(height,librevenge::RVNG_POINT,MWAWParagraph::AtLeast);
1423 else if (height>0)
1424 ruler.setInterline(height,librevenge::RVNG_POINT);
1425 else
1426 f << "##interline=" << height << "pt,";
1427 ruler.m_extra = f.str();
1428 return true;
1429 }
1430
1431 void WriteNowText::setProperty(WriteNowTextInternal::Paragraph const &ruler)
1432 {
1433 m_state->m_paragraph = ruler;
1434 if (!m_parserState->m_textListener) return;
1435 m_parserState->m_textListener->setParagraph(ruler);
1436 }
1437
1438 ////////////////////////////////////////////////////////////
1439 // the style properties ?
1440 ////////////////////////////////////////////////////////////
1441 bool WriteNowText::readStyles(WriteNowEntry const &entry)
1442 {
1443 m_state->m_styleList.resize(0);
1444 m_state->m_styleMap.clear();
1445
1446 if (!entry.valid() || entry.length() < 0x10) {
1447 MWAW_DEBUG_MSG(("WriteNowText::readStyles: zone size is invalid\n"));
1448 return false;
1449 }
1450
1451 MWAWInputStreamPtr &input= m_parserState->m_input;
1452 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1453 if (input->readLong(4) != entry.length()) {
1454 MWAW_DEBUG_MSG(("WriteNowText::readStyles: bad begin of last zone\n"));
1455 return false;
1456 }
1457 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1458 libmwaw::DebugStream f;
1459 f << "Entries(Styles):";
1460 f << "ptr?=" << std::hex << input->readULong(4) << std::dec << ",";
1461 f << "ptr2?=" << std::hex << input->readULong(4) << std::dec << ",";
1462 long pos, val;
1463 for (int i = 0; i < 3; i++) { // 5, 0|100, 0
1464 val = input->readLong(2);
1465 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1466 }
1467 auto N=static_cast<int>(input->readULong(2));
1468 f << "N=" << N << ",";
1469 for (int i = 0; i < 2; i++) { // 0
1470 val = input->readLong(2);
1471 if (val) f << "g" << i << "=" << val << ",";
1472 }
1473 if (long(input->tell())+N*8 > entry.end()) {
1474 MWAW_DEBUG_MSG(("WriteNowText::readStyles: the zone is too short\n"));
1475 return false;
1476 }
1477 ascFile.addPos(entry.begin());
1478 ascFile.addNote(f.str().c_str());
1479 std::vector<long> defPos;
1480 std::map<long, int> seenMap;
1481 for (int n = 0; n < N; n++) {
1482 pos = input->tell();
1483 f.str("");
1484 f << "Styles[" << n << "]:";
1485 auto type = static_cast<int>(input->readULong(1));
1486 switch (type) {
1487 case 0:
1488 f << "def[named],";
1489 break;
1490 case 2:
1491 f << "def,";
1492 break;
1493 case 4:
1494 f << "user?[named],";
1495 break;
1496 case 0x80:
1497 f << "none,";
1498 break;
1499 default:
1500 MWAW_DEBUG_MSG(("WriteNowText::readStyles: find unknown type %d\n", type));
1501 f << "#type=" << type << ",";
1502 break;
1503 }
1504 for (int i = 0; i < 3; i++) { // always 0
1505 val = input->readLong(1);
1506 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1507 }
1508 val = long(input->readULong(4));
1509 if (type != 0x80 && pos+val != entry.end()) {
1510 auto seenIt = seenMap.find(pos+val);
1511 int id = 0;
1512 if (seenIt != seenMap.end())
1513 id = seenIt->second;
1514 else {
1515 id = int(defPos.size());
1516 defPos.push_back(pos+val);
1517 seenMap[pos+val] = id;
1518 }
1519 m_state->m_styleMap[n] = id;
1520 f << "style" << id << ",";
1521 }
1522 ascFile.addPos(pos);
1523 ascFile.addNote(f.str().c_str());
1524 }
1525
1526 for (size_t n = 0; n < defPos.size(); n++) {
1527 pos = defPos[n];
1528 if (pos+34 > entry.end()) {
1529 MWAW_DEBUG_MSG(("WriteNowText::readStyles: can not read entry : %ld\n", long(n)));
1530 return false;
1531 }
1532
1533 WriteNowTextInternal::Style style;
1534 input->seek(pos, librevenge::RVNG_SEEK_SET);
1535 f.str("");
1536 auto type = static_cast<int>(input->readULong(1));
1537 style.m_values[0] = int(type>>4);// find 1, 2 or 3
1538 style.m_values[1] = int(type&0xF); // always 0 ?
1539
1540 /* f2: 0 or 0x30, 35, 36, 37, 38, 4d, 53
1541 f3: small number : maybe a previous id?
1542 */
1543 for (int i = 2; i < 4; i++)
1544 style.m_values[i] = static_cast<int>(input->readULong(1));
1545 style.m_nextId = static_cast<int>(input->readLong(1))-1; // almost always n+1, so...
1546 /* f4: almost always 0, but one time f4=nextId
1547 f5-f9: always=0
1548 */
1549 for (int i = 4; i < 6; i++)
1550 style.m_values[i] = static_cast<int>(input->readULong(1));
1551 for (int i = 6; i < 9; i++) // always 0
1552 style.m_values[i] = static_cast<int>(input->readLong(2));
1553 for (auto &fl : style.m_flags) fl=static_cast<int>(input->readULong(2));
1554 for (int i = 9; i < 11; i++) // always 0
1555 style.m_values[i] = static_cast<int>(input->readLong(2));
1556 int relPos[3];
1557 for (auto &rPos : relPos) rPos = static_cast<int>(input->readULong(2));
1558 style.m_values[11] = static_cast<int>(input->readULong(2)); // another pos ?
1559 if (relPos[0]) { // style name
1560 input->seek(pos+relPos[0], librevenge::RVNG_SEEK_SET);
1561 auto sz = static_cast<int>(input->readULong(1));
1562 if (!sz || pos+relPos[0]+1+sz > entry.end()) {
1563 MWAW_DEBUG_MSG(("WriteNowText::readStyles: can not read name for entry : %ld\n", long(n)));
1564 f << "name[length],";
1565 }
1566 else {
1567 std::string name("");
1568 for (int i = 0; i < sz; i++) name+=char(input->readLong(1));
1569 style.m_name = name;
1570 // maybe followed by an integer
1571 }
1572 }
1573 std::string error = f.str();
1574 f.str("");
1575 f << "StylesData[" << n << ":header]:" << style << ",";
1576 if (error.length()) f << "#errors[" << error << "],";
1577 ascFile.addPos(pos);
1578 ascFile.addNote(f.str().c_str());
1579 if (relPos[1]) { // font ?
1580 f.str("");
1581 f << "StylesData[" << n << ":font]:";
1582 input->seek(pos+relPos[1], librevenge::RVNG_SEEK_SET);
1583 input->pushLimit(relPos[2] ? pos+relPos[2] : entry.end());
1584
1585 WriteNowTextInternal::Font font;
1586 if (readFont(*input, true, font)) {
1587 style.m_font = font;
1588 f << font.m_font.getDebugString(m_parserState->m_fontConverter) << font;
1589 }
1590 else
1591 f << "#";
1592
1593 input->popLimit();
1594 ascFile.addPos(pos+relPos[1]);
1595 ascFile.addNote(f.str().c_str());
1596 }
1597 if (relPos[2]) {
1598 f.str("");
1599 f << "StylesData[" << n << ":ruler]:";
1600 input->seek(pos+relPos[2], librevenge::RVNG_SEEK_SET);
1601 auto sz = static_cast<int>(input->readULong(2));
1602 input->pushLimit(pos+relPos[2]+sz);
1603 WriteNowTextInternal::Paragraph ruler;
1604 if (readParagraph(*input, ruler)) {
1605 style.m_paragraph = ruler;
1606 f << ruler;
1607 }
1608 else
1609 f << "#";
1610 input->popLimit();
1611 ascFile.addPos(pos+relPos[2]);
1612 ascFile.addNote(f.str().c_str());
1613 }
1614 m_state->m_styleList.push_back(style);
1615 }
1616
1617 entry.setParsed(true);
1618 ascFile.addPos(entry.end());
1619 ascFile.addNote("_");
1620 return true;
1621 }
1622
1623 ////////////////////////////////////////////////////////////
1624 // zone which corresponds to the token
1625 ////////////////////////////////////////////////////////////
1626 bool WriteNowText::readToken(MWAWInputStream &input, WriteNowTextInternal::Token &token)
1627 {
1628 token=WriteNowTextInternal::Token();
1629
1630 long pos = input.tell();
1631 input.seek(pos+54, librevenge::RVNG_SEEK_SET);
1632 if (pos+54 != long(input.tell())) {
1633 MWAW_DEBUG_MSG(("WriteNowText::readToken: zone is too short \n"));
1634 return false;
1635 }
1636 input.seek(pos, librevenge::RVNG_SEEK_SET);
1637 int dim[4];
1638 for (auto &d : dim) d = static_cast<int>(input.readLong(2));
1639 token.m_box = MWAWBox2i(MWAWVec2i(dim[1], dim[0]), MWAWVec2i(dim[3], dim[2]));
1640 int actVal = 0;
1641 for (auto &st : token.m_pos) {
1642 auto dim0 = static_cast<int>(input.readLong(2));
1643 token.m_values[actVal++] = static_cast<int>(input.readLong(2)); // always 0
1644 token.m_values[actVal++] = static_cast<int>(input.readLong(2)); // always 0
1645 auto dim1 = static_cast<int>(input.readLong(2));
1646 st = MWAWVec2i(dim1, -dim0);
1647 }
1648 /*
1649 f0/f2: 0 or 1 ( very similar)
1650 f1/f3 : 0 or big number
1651 f8=1, f9=14
1652 other 0
1653 */
1654 for (int i = 0; i < 14; i++)
1655 token.m_values[actVal++] = static_cast<int>(input.readULong(2));
1656 token.m_graphicZone = static_cast<int>(input.readLong(2));
1657 return true;
1658 }
1659
1660 bool WriteNowText::readTokenV2(MWAWInputStream &input, WriteNowTextInternal::Token &token)
1661 {
1662 token=WriteNowTextInternal::Token();
1663
1664 long actPos = input.tell();
1665 int dim[2];
1666 for (auto &d : dim) d = static_cast<int>(input.readLong(2));
1667 MWAWVec2i box(dim[1], dim[0]);
1668 token.m_box=MWAWBox2i(MWAWVec2i(0,0), box);
1669 // we need to get the size, so...
1670 while (!input.isEnd())
1671 input.seek(0x100, librevenge::RVNG_SEEK_CUR);
1672 long endPos = input.tell();
1673 long sz = endPos-actPos-4;
1674 if (sz <= 0) return false;
1675 input.seek(actPos+4, librevenge::RVNG_SEEK_SET);
1676 MWAWInputStreamPtr ip(&input,MWAW_shared_ptr_noop_deleter<MWAWInputStream>());
1677 std::shared_ptr<MWAWPict> pict(MWAWPictData::get(ip, static_cast<int>(sz)));
1678 if (!pict) {
1679 MWAW_DEBUG_MSG(("WriteNowParser::readTokenV2: can not read the picture\n"));
1680 return false;
1681 }
1682 if (!m_parserState->m_textListener) return true;
1683
1684 MWAWPosition pictPos;
1685 if (box.x() > 0 && box.y() > 0) {
1686 pictPos=MWAWPosition(MWAWVec2f(0,0),MWAWVec2f(box), librevenge::RVNG_POINT);
1687 pictPos.setNaturalSize(pict->getBdBox().size());
1688 }
1689 else
1690 pictPos=MWAWPosition(MWAWVec2f(0,0),pict->getBdBox().size(), librevenge::RVNG_POINT);
1691 pictPos.setRelativePosition(MWAWPosition::Char);
1692
1693 MWAWEmbeddedObject picture;
1694 if (pict->getBinary(picture))
1695 m_parserState->m_textListener->insertPicture(pictPos, picture);
1696
1697 return true;
1698 }
1699
1700 ////////////////////////////////////////////////////////////
1701 // zone which corresponds to the table
1702 ////////////////////////////////////////////////////////////
1703 bool WriteNowText::readTable(MWAWInputStream &input, WriteNowTextInternal::TableData &table)
1704 {
1705 table=WriteNowTextInternal::TableData();
1706 long pos = input.tell();
1707
1708 table.m_type = static_cast<int>(input.readULong(1));
1709 if (input.isEnd()) {
1710 if (table.m_type!=0) {
1711 MWAW_DEBUG_MSG(("WriteNowText::readTable: find a zone will 0 size\n"));
1712 return false;
1713 }
1714 return true;
1715 }
1716 input.seek(pos+28, librevenge::RVNG_SEEK_SET);
1717 if (pos+28 != long(input.tell())) {
1718 MWAW_DEBUG_MSG(("WriteNowText::readTable: zone is too short \n"));
1719 return false;
1720 }
1721 input.seek(pos+1, librevenge::RVNG_SEEK_SET);
1722 int actVal = 0;
1723 table.m_values[actVal++] = static_cast<int>(input.readLong(1));
1724 table.m_values[actVal++] = static_cast<int>(input.readLong(1));
1725 auto backColor = static_cast<int>(input.readULong(1));
1726 MWAWColor col;
1727 if (m_mainParser->getColor(backColor,col))
1728 table.m_color = col;
1729 else {
1730 MWAW_DEBUG_MSG(("WriteNowText::readTable: can not read backgroundColor: %d\n", backColor));
1731 }
1732 for (int &flag : table.m_flags) {
1733 flag = static_cast<int>(input.readULong(1)); // 0x80, 0x81, 5, 0 : border flag ?
1734 table.m_values[actVal++] = static_cast<int>(input.readLong(1)); // always 0 ?
1735 }
1736 for (int i = 0; i < 3; i++)
1737 table.m_values[actVal++] = static_cast<int>(input.readLong(2)); // alway 0
1738 int dim[4];
1739 for (auto &d : dim) d = static_cast<int>(input.readLong(2));
1740 table.m_box = MWAWBox2i(MWAWVec2i(dim[1], dim[0]), MWAWVec2i(dim[3], dim[2]));
1741 table.m_values[actVal++] = static_cast<int>(input.readLong(2));
1742
1743 return true;
1744 }
1745
1746 ////////////////////////////////////////////////////////////
1747 // send data to the listener
1748 bool WriteNowText::send(WriteNowEntry const &entry)
1749 {
1750 std::shared_ptr<WriteNowTextInternal::ContentZones> text(m_state->getContentZone(entry.begin()));
1751 if (!text) {
1752 MWAW_DEBUG_MSG(("WriteNowText::send: can not find entry\n"));
1753 return false;
1754 }
1755 auto ruler=m_state->getDefaultParagraph(text->m_type);
1756 text->m_sent = true;
1757 return send(text->m_zonesList, text->m_footnoteList, ruler);
1758 }
1759
1760 bool WriteNowText::send(std::vector<WriteNowTextInternal::ContentZone> &listZones,
1761 std::vector<std::shared_ptr<WriteNowTextInternal::ContentZones> > &footnoteList,
1762 WriteNowTextInternal::Paragraph &ruler)
1763 {
1764 MWAWTextListenerPtr listener=m_parserState->m_textListener;
1765 if (!listener) {
1766 MWAW_DEBUG_MSG(("WriteNowText::send: can not find the listener\n"));
1767 return false;
1768 }
1769 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1770 libmwaw::DebugStream f;
1771 int vers = version();
1772 MWAWFont actFont(3,12); // default geneva 12pt
1773 listener->setFont(actFont);
1774 int extraDecal = 0; // for v2
1775 bool rulerSet = false;
1776 int numLineTabs = 0, actTabs = 0, numFootnote = 0;
1777
1778 std::shared_ptr<WriteNowTextInternal::Table> table;
1779 std::shared_ptr<WriteNowTextInternal::Cell> cell;
1780
1781 MWAWInputStreamPtr &input= m_parserState->m_input;
1782 for (auto const &zone : listZones) {
1783 if (table && cell) {
1784 bool done = true;
1785 switch (zone.m_type) {
1786 case 0xa:
1787 done = false;
1788 break;
1789 case 4:
1790 if (numFootnote < int(footnoteList.size())) {
1791 cell->m_footnoteList.push_back(footnoteList[size_t(numFootnote)]);
1792 numFootnote++;
1793 }
1794 cell->m_zonesList.push_back(zone);
1795 break;
1796 case 0x10:
1797 MWAW_DEBUG_MSG(("WriteNowText::send: find a page/column break in table(ignored)\n"));
1798 break;
1799 default:
1800 cell->m_zonesList.push_back(zone);
1801 break;
1802 }
1803 if (done)
1804 continue;
1805 }
1806 else if (table && zone.m_type != 0xa) {
1807 static bool first=true;
1808 if (first) {
1809 first = false;
1810 MWAW_DEBUG_MSG(("WriteNowText::send: find some data in table but outside cell\n"));
1811 }
1812 }
1813 switch (zone.m_type) {
1814 case 4:
1815 if (numFootnote < int(footnoteList.size())) {
1816 m_mainParser->sendFootnote(footnoteList[size_t(numFootnote)]->m_entry);
1817 numFootnote++;
1818 }
1819 else {
1820 MWAW_DEBUG_MSG(("WriteNowText::send: can not find footnote:%d\n", numFootnote));
1821 }
1822 break;
1823 case 0xd:
1824 switch (zone.m_value) {
1825 case 0:
1826 listener->insertField(MWAWField(MWAWField::PageNumber));
1827 break;
1828 case 1: {
1829 MWAWField date(MWAWField::Date);
1830 date.m_DTFormat = "%a, %b %d, %Y";
1831 listener->insertField(date);
1832 break;
1833 }
1834 case 2: {
1835 MWAWField time(MWAWField::Time);
1836 time.m_DTFormat="%H:%M";
1837 listener->insertField(time);
1838 break;
1839 }
1840 case 3: // note field : ok
1841 default:
1842 break;
1843 }
1844 break;
1845 case 0x10:
1846 if (m_state->m_numColumns <= 1 && ++m_state->m_actualPage <= m_state->m_numPages)
1847 m_mainParser->newPage(m_state->m_actualPage);
1848 else if (m_state->m_numColumns > 1 && listener)
1849 listener->insertBreak(MWAWTextListener::ColumnBreak);
1850 break;
1851 default:
1852 break;
1853 }
1854
1855 if ((zone.m_type>0 && zone.m_type < 8) || zone.m_type == 0xd || zone.m_type == 0x10)
1856 continue;
1857
1858 librevenge::RVNGBinaryData data;
1859 input->seek(zone.m_pos[0],librevenge::RVNG_SEEK_SET); //000a2f
1860 while (int(input->tell()) < zone.m_pos[1]) {
1861 auto ch = static_cast<int>(input->readULong(1));
1862 if (ch == 0xf0) {
1863 ch = static_cast<int>(input->readULong(1));
1864 if (ch & 0xf0) {
1865 MWAW_DEBUG_MSG(("WriteNowText::send: find odd 0xF0 following\n"));
1866 continue;
1867 }
1868 data.append(static_cast<unsigned char>(0xf0 | ch));
1869 }
1870 else
1871 data.append(static_cast<unsigned char>(ch));
1872 }
1873
1874 f.str("");
1875 if (zone.m_type == 0) {
1876 auto sz = long(data.size());
1877 const unsigned char *buffer = data.getDataBuffer();
1878 if (!buffer && sz) {
1879 MWAW_DEBUG_MSG(("WriteNowText::send: can find data buffer\n"));
1880 sz = 0;
1881 }
1882 if (sz && !rulerSet) {
1883 setProperty(ruler);
1884 numLineTabs = int(ruler.m_tabs->size());
1885 rulerSet = true;
1886 }
1887 for (long i = 0; i < sz; i++) {
1888 unsigned char c = *(buffer++);
1889 f << c;
1890 switch (c) {
1891 case 0x9:
1892 if (actTabs++ < numLineTabs)
1893 listener->insertTab();
1894 else
1895 listener->insertChar(' ');
1896 break;
1897 case 0xd:
1898 // this is marks the end of a paragraph
1899 listener->insertEOL();
1900 setProperty(ruler);
1901 actTabs = 0;
1902 break;
1903 default:
1904 listener->insertCharacter(c);
1905 break;
1906 }
1907 }
1908 ascFile.addPos(zone.m_pos[0]);
1909 ascFile.addNote(f.str().c_str());
1910 continue;
1911 }
1912 MWAWInputStreamPtr dataInput;
1913 if (data.size())
1914 dataInput=MWAWInputStream::get(data, false);
1915 switch (zone.m_type) {
1916 case 0x9: { // only in v2
1917 extraDecal = zone.m_value;
1918 MWAWFont font(actFont);
1919 if (extraDecal > 0) font.set(MWAWFont::Script::super100());
1920 else if (extraDecal < 0) font.set(MWAWFont::Script::sub100());
1921 listener->setFont(font);
1922 break;
1923 }
1924 case 0xa: { // only in writenow 4.0 : related to a table ?
1925 if (!dataInput) break;
1926 WriteNowTextInternal::TableData tableData;
1927 if (readTable(*dataInput, tableData)) {
1928 f << tableData;
1929
1930 bool needSendTable = false;
1931 bool needCreateCell = false;
1932 switch (zone.m_value) {
1933 case 0:
1934 if (table)
1935 needSendTable = true;
1936 else {
1937 MWAW_DEBUG_MSG(("WriteNowText::send: Find odd end of table\n"));
1938 }
1939 break;
1940 case 1:
1941 if (!table)
1942 table.reset(new WriteNowTextInternal::Table);
1943 else {
1944 MWAW_DEBUG_MSG(("WriteNowText::send: Find a table in a table\n"));
1945 }
1946 break;
1947 case 2:
1948 if (table)
1949 needCreateCell = true;
1950 else {
1951 MWAW_DEBUG_MSG(("WriteNowText::send: Find cell outside a table\n"));
1952 }
1953 break;
1954 default:
1955 break;
1956 }
1957
1958 if (needSendTable) {
1959 if (table) {
1960 if (!table->sendTable(listener))
1961 table->sendAsText(listener);
1962 }
1963 else {
1964 MWAW_DEBUG_MSG(("WriteNowText::send: can not find the cell to send...\n"));
1965 }
1966 table.reset();
1967 }
1968 if (needCreateCell) {
1969 cell.reset(new WriteNowTextInternal::Cell(*this));
1970 tableData.updateCell(*cell);
1971 table->add(cell);
1972 }
1973 }
1974 else
1975 f << "#";
1976 break;
1977 }
1978 case 0xb: {
1979 // this seems to define the leader than add a tab
1980 if (actTabs++ < numLineTabs)
1981 listener->insertTab();
1982 else
1983 listener->insertChar(' ');
1984 break;
1985 }
1986 case 0xc: {
1987 if (!dataInput) break;
1988 WriteNowTextInternal::Paragraph newParagraph;
1989 if (readParagraph(*dataInput, newParagraph)) {
1990 ruler = newParagraph;
1991 numLineTabs = int(ruler.m_tabs->size());
1992 setProperty(ruler);
1993 rulerSet = true;
1994 f << ruler;
1995 }
1996 else
1997 f << "#";
1998 break;
1999 }
2000 case 0xe: {
2001 if (!dataInput) break;
2002 WriteNowTextInternal::Token token;
2003 if (vers >= 3) {
2004 if (readToken(*dataInput, token)) {
2005 m_mainParser->sendGraphic(token.m_graphicZone, token.m_box);
2006 f << token;
2007 }
2008 else
2009 f << "#";
2010 }
2011 else {
2012 if (readTokenV2(*dataInput, token))
2013 f << token;
2014 else
2015 f << "#";
2016 }
2017 break;
2018 }
2019 case 0xf: {
2020 if (!dataInput) break;
2021 WriteNowTextInternal::Font font;
2022 if (readFont(*dataInput, false, font)) {
2023 actFont=font.m_font;
2024 f << font.m_font.getDebugString(m_parserState->m_fontConverter) << font;
2025 if (extraDecal > 0) font.m_font.set(MWAWFont::Script::super100());
2026 else if (extraDecal < 0) font.m_font.set(MWAWFont::Script::sub100());
2027 listener->setFont(font.m_font);
2028 }
2029 else
2030 f << "#";
2031 break;
2032 }
2033 default:
2034 MWAW_DEBUG_MSG(("WriteNowText::send: find keyword %x\n",static_cast<unsigned int>(zone.m_type)));
2035 break;
2036 }
2037
2038 ascFile.addPos(zone.m_pos[0]-1);
2039 ascFile.addNote(f.str().c_str());
2040 }
2041
2042 if (table) {
2043 MWAW_DEBUG_MSG(("WriteNowText::send: a table is not closed\n"));
2044 if (!table->sendTable(listener))
2045 table->sendAsText(listener);
2046 }
2047
2048 return true;
2049 }
2050
2051 void WriteNowText::sendZone(int id)
2052 {
2053 MWAWTextListenerPtr listener=m_parserState->m_textListener;
2054 if (!listener) {
2055 MWAW_DEBUG_MSG(("WriteNowText::sendZone: can not find the listener\n"));
2056 return;
2057 }
2058 if (id < 0 || id >= 3) {
2059 MWAW_DEBUG_MSG(("WriteNowText::sendZone: called with id=%d\n",id));
2060 return;
2061 }
2062 if (id == 0) {
2063 int nCol, width=0;
2064 m_mainParser->getColumnInfo(nCol, width);
2065 if (m_state->m_numColumns > 1) {
2066 if (width <= 0)
2067 width = int((72.0*m_mainParser->getPageWidth())/m_state->m_numColumns);
2068 if (listener->isSectionOpened())
2069 listener->closeSection();
2070 MWAWSection sec;
2071 sec.setColumns(m_state->m_numColumns, double(width), librevenge::RVNG_POINT);
2072 listener->openSection(sec);
2073 }
2074 }
2075 auto &mZone = m_state->m_mainZones[id];
2076 auto ruler=m_state->getDefaultParagraph(id);
2077 if (id==0)
2078 listener->setParagraph(ruler);
2079 for (auto &zone : mZone.m_zones) {
2080 if (zone->m_sent) continue;
2081 if (id == 0 && zone->m_type) continue;
2082 if (id) ruler=m_state->getDefaultParagraph(id);
2083 send(zone->m_zonesList, zone->m_footnoteList, ruler);
2084 zone->m_sent = true;
2085 }
2086 }
2087
2088 void WriteNowText::flushExtra()
2089 {
2090 for (int z = 0; z < 3; z++) {
2091 if (z == 1) continue;
2092 sendZone(z);
2093 }
2094 }
2095
2096 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: