Debian Codegraph @

src/lib/SpringBoardParser.cxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #include <cmath>
35 #include <iomanip>
36 #include <iostream>
37 #include <limits>
38 #include <sstream>
39 #include <utility>
40
41 #include <librevenge/librevenge.h>
42
43 #include "MWAWGraphicListener.hxx"
44 #include "MWAWGraphicShape.hxx"
45 #include "MWAWGraphicStyle.hxx"
46 #include "MWAWHeader.hxx"
47 #include "MWAWParagraph.hxx"
48 #include "MWAWPictBitmap.hxx"
49 #include "MWAWPictData.hxx"
50 #include "MWAWPosition.hxx"
51 #include "MWAWSection.hxx"
52 #include "MWAWSubDocument.hxx"
53
54 #include "SpringBoardParser.hxx"
55
56 /** Internal: the structures of a SpringBoardParser */
57 namespace SpringBoardParserInternal
58 {
59 //! Internal: a structure used to store the frame property in SpringBoardParserInternal
60 struct Frame {
61 //! constructor
62 Frame()
63 : m_type(-1)
64 , m_style(MWAWGraphicStyle::emptyStyle())
65 , m_numSubZones(0)
66 , m_numColumns(1)
67 , m_columnBoxes()
68 {
69 }
70 //! the frame type: 0: layout, 1: text, 2: graphic
71 int m_type;
72 //! the frame style
73 MWAWGraphicStyle m_style;
74 //! the number of sub zone (for a text frame)
75 int m_numSubZones;
76 //! the external and the internal box
77 MWAWBox2i m_boxes[2];
78 //! the number of columns: for a text frame
79 int m_numColumns;
80 //! the child box: one by column for text and layout
81 std::vector<MWAWBox2i> m_columnBoxes;
82 };
83
84 //! Internal: a structure used to store a link in SpringBoardParserInternal
85 struct Link {
86 //! constructor
87 Link()
88 : m_font()
89 {
90 for (auto &lnk : m_links)
91 lnk=std::make_pair(-1,-1);
92 }
93 //! returns true if the link stores somme text
94 bool hasText() const
95 {
96 for (auto const &entry : m_texts) {
97 if (entry.valid()) return true;
98 }
99 return false;
100 }
101 //! the font
102 MWAWFont m_font;
103 //! the top and bottom text
104 MWAWEntry m_texts[2];
105 //! the next and previous link
106 std::pair<int,int> m_links[2];
107 };
108 //! Internal: a structure used to store the shape data in SpringBoardParserInternal
109 struct Shape {
110 //! a paragraph contained in a SpringBoardParserInternal::Shape
111 struct Paragraph {
112 //! constructor
113 Paragraph()
114 : m_numChars(0)
115 , m_firstChar(0)
116 , m_newColumn(false)
117 , m_numCharStyles(0)
118 , m_textZoneId(-1)
119 , m_paragraphStyle(-1)
120 , m_charEntry()
121 {
122 }
123 //! the number of character
124 int m_numChars;
125 //! the first character
126 int m_firstChar;
127 //! a flag to know if we need to change column: USEME
128 bool m_newColumn;
129 //! the number of character style
130 int m_numCharStyles;
131 //! the text zone id
132 int m_textZoneId;
133 //! the paragraph style
134 int m_paragraphStyle;
135 //! the character style zone
136 MWAWEntry m_charEntry;
137 };
138 //! constructor
139 Shape()
140 : m_type(0)
141 , m_paragraphs()
142 , m_pictEntry()
143 {
144 }
145 //! the shape type: 0: layout, 1: text, 2: graphic
146 int m_type;
147 //! the list of paragraph
148 std::vector<Paragraph> m_paragraphs;
149 //! the picture entry: graphic only
150 MWAWEntry m_pictEntry;
151 };
152
153 ////////////////////////////////////////
154 //! Internal: the Header/Footer of a SpringBoardParser
155 struct HeaderFooter {
156 //! constructor
157 HeaderFooter()
158 : m_position(0)
159 , m_type(0)
160 , m_pageNumber(0)
161 , m_font()
162 {
163 }
164 //! the header/footer position 1: TC, TR, TL, BC, BR, BL, FacingT, FacingB
165 int m_position;
166 //! the numbering type: 0: numeric, 1/2: small/big roman, 3/4: small/big alpha, 5-7: full minu,MAJU,Title, 8: none
167 int m_type;
168 //! the first page numbering
169 int m_pageNumber;
170 //! the font
171 MWAWFont m_font;
172 //! the prefix/postfix zones string
173 MWAWEntry m_zones[2];
174 };
175
176 ////////////////////////////////////////
177 //! Internal: the state of a SpringBoardParser
178 struct State {
179 //! constructor
180 State()
181 : m_numPages(1)
182 , m_entriesListMap()
183 , m_entries2ListMap()
184 , m_pageIdToDimensionMap()
185 , m_pageIdToHeaderFooterMap()
186 , m_idToFrameMap()
187 , m_idToShapeMap()
188 , m_idToLinkMap()
189 , m_idToTextEntriesMap()
190 , m_idToParagraphMap()
191
192 , m_parsedZonesMap()
193 {
194 }
195
196 //! returns the name of a data zone
197 std::string getDataZoneName(int id) const
198 {
199 char const *wh[]= {"Doc", "Page", "FramStyle", "FramLink", nullptr,
200 nullptr, nullptr, nullptr, "ParaStyle", "Text"
201 };
202 if (id>=0 && id<10 && wh[id])
203 return wh[id];
204 std::stringstream s;
205 s << "List" << id;
206 return s.str();
207 }
208 //! the number of pages
209 int m_numPages;
210 //! a map zone id to list's entry
211 std::map<int, MWAWEntry> m_entriesListMap;
212 //! a map id to the last zone entries
213 std::map<int, MWAWEntry> m_entries2ListMap;
214 //! the map pageId to page dimension
215 std::map<int, MWAWBox2i> m_pageIdToDimensionMap;
216 //! the map pageId to header footer
217 std::map<int, HeaderFooter> m_pageIdToHeaderFooterMap;
218 //! the map (page,id) to frame map
219 std::map<std::pair<int,int>, Frame> m_idToFrameMap;
220 //! the map (page,id) to shape map
221 std::map<std::pair<int,int>, Shape> m_idToShapeMap;
222 //! the map (page,id) to link map
223 std::map<std::pair<int,int>, Link> m_idToLinkMap;
224 //! the map id to text entries
225 std::map<int, MWAWEntry> m_idToTextEntriesMap;
226 //! the map id to paragraph
227 std::map<int, MWAWParagraph> m_idToParagraphMap;
228
229 //! the list of parsed zone
230 std::map<long,long> m_parsedZonesMap;
231 };
232
233 ////////////////////////////////////////
234 //! Internal: the subdocument of a SpringBoardParser
235 class SubDocument final : public MWAWSubDocument
236 {
237 public:
238 //! constructor knowning the header/footer id
239 SubDocument(SpringBoardParser &pars, MWAWInputStreamPtr const &input, int hfId)
240 : MWAWSubDocument(&pars, input, MWAWEntry())
241 , m_hfId(hfId)
242 , m_linkId({-1,-1})
243 , m_linkTop(true)
244 , m_pageId({-1,-1})
245 , m_minParagraph(-1)
246 , m_maxParagraph(-1)
247 {
248 }
249
250 //! constructor corresponding to a layout/textbox shape
251 SubDocument(SpringBoardParser &pars, MWAWInputStreamPtr const &input, std::pair<int,int> const &pageId,
252 std::pair<int,int> const &paras= {-1,-1})
253 : MWAWSubDocument(&pars, input, MWAWEntry())
254 , m_hfId(-1)
255 , m_linkId({-1,-1})
256 , m_linkTop(true)
257 , m_pageId(pageId)
258 , m_minParagraph(paras.first)
259 , m_maxParagraph(paras.second)
260 {
261 }
262 //! constructor corresponding to a link shape
263 SubDocument(SpringBoardParser &pars, MWAWInputStreamPtr const &input, std::pair<int,int> const &linkId,
264 bool isTop)
265 : MWAWSubDocument(&pars, input, MWAWEntry())
266 , m_hfId(-1)
267 , m_linkId(linkId)
268 , m_linkTop(isTop)
269 , m_pageId({-1,-1})
270 , m_minParagraph(-1)
271 , m_maxParagraph(-1)
272 {
273 }
274 //! destructor
275 ~SubDocument() final {}
276
277 //! operator!=
278 bool operator!=(MWAWSubDocument const &doc) const final
279 {
280 if (MWAWSubDocument::operator!=(doc)) return true;
281 auto const *sDoc = dynamic_cast<SubDocument const *>(&doc);
282 if (!sDoc) return true;
283 if (sDoc->m_hfId != m_hfId) return true;
284 if (sDoc->m_linkId != m_linkId) return true;
285 if (sDoc->m_linkTop != m_linkTop) return true;
286 if (sDoc->m_pageId != m_pageId) return true;
287 if (sDoc->m_minParagraph != m_minParagraph) return true;
288 if (sDoc->m_maxParagraph != m_maxParagraph) return true;
289 return false;
290 }
291
292 //! the parser function
293 void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
294
295 protected:
296 //! the header/footer zone id
297 int m_hfId;
298 //! the text link id
299 std::pair<int,int> m_linkId;
300 //! a flag to know if we need to send the top or the bottom text
301 bool m_linkTop;
302 //! the text page id
303 std::pair<int,int> m_pageId;
304 //! the minimum and maximum paragraph
305 int m_minParagraph, m_maxParagraph;
306 private:
307 SubDocument(SubDocument const &orig) = delete;
308 SubDocument &operator=(SubDocument const &orig) = delete;
309 };
310
311 void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType)
312 {
313 if (!listener || !listener->canWriteText()) {
314 MWAW_DEBUG_MSG(("SpringBoardParserInternal::SubDocument::parse: no listener\n"));
315 return;
316 }
317 auto parser=dynamic_cast<SpringBoardParser *>(m_parser);
318 if (!parser) {
319 MWAW_DEBUG_MSG(("SpringBoardParserInternal::SubDocument::parse: no parser\n"));
320 return;
321 }
322 long pos = m_input->tell();
323 if (m_hfId>=0)
324 parser->sendHeaderFooter(m_hfId);
325 else if (m_linkId.first != -1)
326 parser->sendLinkShape(m_linkId, m_linkTop);
327 else
328 parser->sendTextShape(m_pageId, m_minParagraph, m_maxParagraph);
329 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
330 }
331
332
333 }
334
335 ////////////////////////////////////////////////////////////
336 // constructor/destructor, ...
337 ////////////////////////////////////////////////////////////
338 SpringBoardParser::SpringBoardParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
339 : MWAWGraphicParser(input, rsrcParser, header)
340 , m_state(new SpringBoardParserInternal::State)
341 {
342 setAsciiName("main-1");
343
344 getPageSpan().setMargins(0.1);
345 }
346
347 SpringBoardParser::~SpringBoardParser()
348 {
349 }
350
351 bool SpringBoardParser::isPositionValid(long pos) const
352 {
353 MWAWEntry entry;
354 entry.setBegin(pos);
355 entry.setLength(0);
356 return isEntryValid(entry);
357 }
358
359 bool SpringBoardParser::isEntryValid(MWAWEntry const &entry) const
360 {
361 auto input=const_cast<SpringBoardParser *>(this)->getInput();
362 if (!input || entry.begin()<0x80 || !input->checkPosition(entry.end()))
363 return false;
364 auto it=m_state->m_parsedZonesMap.upper_bound(entry.begin());
365 if (it!=m_state->m_parsedZonesMap.begin())
366 --it;
367 while (it!=m_state->m_parsedZonesMap.end()) {
368 if (it->first>=entry.end())
369 return true;
370 if (it->second>entry.begin())
371 return false;
372 ++it;
373 }
374 return true;
375 }
376
377 ////////////////////////////////////////////////////////////
378 // the parser
379 ////////////////////////////////////////////////////////////
380 void SpringBoardParser::parse(librevenge::RVNGDrawingInterface *docInterface)
381 {
382 if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException());
383 bool ok = false;
384 try {
385 // create the asciiFile
386 ascii().setStream(getInput());
387 ascii().open(asciiName());
388 checkHeader(nullptr);
389 ok = createZones();
390 if (ok) {
391 createDocument(docInterface);
392
393 auto listener=getGraphicListener();
394 if (!listener)
395 ok=false;
396 else {
397 for (int pg=0; pg<m_state->m_numPages; ++pg) {
398 if (pg)
399 listener->insertBreak(MWAWListener::PageBreak);
400 auto fIt=m_state->m_idToFrameMap.lower_bound(std::make_pair(pg+1, -1));
401 while (fIt!=m_state->m_idToFrameMap.end() && fIt->first.first==pg+1)
402 sendFrame(fIt++->first);
403 }
404 }
405 }
406 ascii().reset();
407 }
408 catch (...) {
409 MWAW_DEBUG_MSG(("SpringBoardParser::parse: exception catched when parsing\n"));
410 ok = false;
411 }
412
413 resetGraphicListener();
414 if (!ok) throw(libmwaw::ParseException());
415 }
416
417 ////////////////////////////////////////////////////////////
418 // create the document
419 ////////////////////////////////////////////////////////////
420 void SpringBoardParser::createDocument(librevenge::RVNGDrawingInterface *documentInterface)
421 {
422 if (!documentInterface) return;
423 if (getGraphicListener()) {
424 MWAW_DEBUG_MSG(("SpringBoardParser::createDocument: listener already exist\n"));
425 return;
426 }
427
428 // create the page list
429 int numPages=std::max<int>(1,m_state->m_numPages);
430 auto fIt=m_state->m_idToFrameMap.rbegin();
431 if (fIt!=m_state->m_idToFrameMap.rend()) {
432 if (fIt->first.first>numPages) {
433 MWAW_DEBUG_MSG(("SpringBoardParser::createDocument: oops, find some frame which are on unknown page\n"));
434 }
435 else if (fIt->first.first<numPages && fIt->first.first>1)
436 numPages=fIt->first.first;
437 }
438 // FIXME: we must also look if we find some page numbering with pageId>numPages
439 m_state->m_numPages=numPages;
440 std::vector<MWAWPageSpan> pageList;
441 MWAWPageSpan ps;
442 for (int pg=1; pg<=numPages; ++pg) {
443 ps=getPageSpan();
444 auto dimIt=m_state->m_pageIdToDimensionMap.find(pg);
445 if (dimIt!=m_state->m_pageIdToDimensionMap.end()) {
446 auto const &sz=dimIt->second[1];
447 if (sz[0]>0 && sz[1]>0) {
448 ps.setFormWidth(double(sz[0])/72);
449 ps.setFormLength(double(sz[1])/72);
450 }
451 }
452 // FIXME: look like a header/footer in page N is also replicated as header/footer for page N+1, N+2, ...
453 auto hfIt=m_state->m_pageIdToHeaderFooterMap.find(pg);
454 if (hfIt!=m_state->m_pageIdToHeaderFooterMap.end()) {
455 auto const &hf=hfIt->second;
456 if (hf.m_type>0 && hf.m_type<=8) {
457 MWAWHeaderFooter hF((hf.m_type<=3 || hf.m_type==7) ? MWAWHeaderFooter::HEADER : MWAWHeaderFooter::FOOTER,
458 MWAWHeaderFooter::ALL);
459 auto subdoc=std::make_shared<SpringBoardParserInternal::SubDocument>(*this, getInput(), pg);
460 hF.m_subDocument=subdoc;
461 ps.setHeaderFooter(hF);
462 }
463 else {
464 MWAW_DEBUG_MSG(("SpringBoardParser::createDocument: oops, find unknown hf type=%d\n", hf.m_type));
465 }
466 }
467 pageList.push_back(ps);
468 }
469
470 MWAWGraphicListenerPtr listen(new MWAWGraphicListener(*getParserState(), pageList, documentInterface));
471 setGraphicListener(listen);
472 listen->startDocument();
473 }
474
475
476 ////////////////////////////////////////////////////////////
477 //
478 // Intermediate level
479 //
480 ////////////////////////////////////////////////////////////
481 bool SpringBoardParser::createZones()
482 {
483 MWAWInputStreamPtr input = getInput();
484 input->seek(4, librevenge::RVNG_SEEK_SET);
485
486 libmwaw::DebugStream f;
487 f << "limits=[";
488 for (int i=0; i<2; ++i) {
489 long ptr=long(input->readULong(4));
490 f << std::hex << ptr << std::dec << ",";
491 if (ptr<0x80 || !input->checkPosition(ptr)) {
492 MWAW_DEBUG_MSG(("SpringBoardParser::createZones: find bad limits\n"));
493 f << "###";
494 ascii().addPos(0);
495 ascii().addNote(f.str().c_str());
496 return false;
497 }
498 ascii().addPos(ptr);
499 ascii().addNote(i==0 ? "[A]" : "[B]");
500 }
501 f << "],";
502
503 int val;
504 MWAWEntry entry;
505 entry.setBegin(long(input->readULong(4)));
506 entry.setLength(long(input->readULong(4)));
507 if (entry.valid()) {
508 f << "pagNumb=" << std::hex << entry.begin() << "<->" << entry.end() << std::dec << ",";
509 if (!isEntryValid(entry)) {
510 MWAW_DEBUG_MSG(("SpringBoardParser::createZones: find bad entries for page numbering\n"));
511 f << "###";
512 return false;
513 }
514 m_state->m_parsedZonesMap[entry.begin()]=entry.end();
515 long actPos=input->tell();
516 parsePageNumbering(entry);
517 input->seek(actPos, librevenge::RVNG_SEEK_SET);
518 }
519 for (int i=0; i<10; ++i) {
520 entry.setBegin(long(input->readULong(4)));
521 entry.setLength(long(input->readULong(2)));
522 if (!entry.valid())
523 continue;
524 char const *wh[]= {
525 "doc", "page", "framstyle", "framlink", nullptr,
526 nullptr, nullptr, nullptr, "parastyle", "text"
527 };
528 if (wh[i])
529 f << wh[i] << "=" << std::hex << entry.begin() << "<->" << entry.end() << std::dec << ",";
530 else
531 f << "list" << i << "=" << std::hex << entry.begin() << "<->" << entry.end() << std::dec << ",";
532 if (!isEntryValid(entry)) {
533 MWAW_DEBUG_MSG(("SpringBoardParser::createZones: find bad entries %d\n", i));
534 f << "###";
535 ascii().addPos(0);
536 ascii().addNote(f.str().c_str());
537 return false;
538 }
539 m_state->m_parsedZonesMap[entry.begin()]=entry.end();
540 m_state->m_entriesListMap[i]=entry;
541 }
542 for (int i=0; i<3; ++i) {
543 val=int(input->readLong(2));
544 if (val)
545 f << "f" << i+4 << "=" << val << ",";
546 }
547 for (int i=0; i<3; ++i) {
548 entry.setBegin(long(input->readULong(4)));
549 entry.setLength(long(input->readULong(4)));
550 if (!entry.valid())
551 continue;
552 f << (i==0 ? "shape" : i==1 ? "txtPos" : "frame") << "=" << std::hex << entry.begin() << "<->" << entry.end() << std::dec << ",";
553 if (!isEntryValid(entry)) {
554 MWAW_DEBUG_MSG(("SpringBoardParser::createZones: find bad entries %d\n", i));
555 f << "###";
556 ascii().addPos(0);
557 ascii().addNote(f.str().c_str());
558 return false;
559 }
560 m_state->m_parsedZonesMap[entry.begin()]=entry.end();
561 m_state->m_entries2ListMap[i]=entry;
562 }
563 for (int i=0; i<3; ++i) {
564 val=int(input->readLong(2));
565 if (val)
566 f << "g" << i << "=" << val << ",";
567 }
568 val=int(input->readULong(4)); // 0 or 68ad08
569 if (val)
570 f << "unkn=" << std::hex << val << std::dec << ",";
571 for (int i=0; i<3; ++i) { // g3=0|8
572 val=int(input->readLong(2));
573 if (val)
574 f << "g" << i+3 << "=" << val << ",";
575 }
576 f << "num[shapes]=" << input->readLong(2) << ",";
577 ascii().addPos(0);
578 ascii().addNote(f.str().c_str());
579
580 for (auto const &it : m_state->m_entriesListMap)
581 parseDataList(it.first, it.second);
582
583 for (auto const &it : m_state->m_entries2ListMap)
584 parseLastZone(it.first, it.second);
585 return true;
586 }
587
588 bool SpringBoardParser::readFont(MWAWFont &font, int szFieldSize)
589 {
590 font=MWAWFont();
591 MWAWInputStreamPtr input = getInput();
592 if (!input)
593 return false;
594 long pos=input->tell();
595 if ((szFieldSize!=1 && szFieldSize!=2) || !input->checkPosition(pos+4+szFieldSize)) {
596 MWAW_DEBUG_MSG(("SpringBoardParser::readFont: the zone seems bad\n"));
597 return false;
598 }
599
600 libmwaw::DebugStream f;
601 font.setId(int(input->readULong(2)));
602 int val=int(input->readULong(2));
603 uint32_t flags=0;
604 if (val&0x1) flags |= MWAWFont::boldBit;
605 if (val&0x2) flags |= MWAWFont::italicBit;
606 if (val&0x4) {
607 font.setUnderlineStyle(MWAWFont::Line::Simple);
608 if (val&0x80)
609 f << "underline[char],";
610 if (val&0x100)
611 f << "underline[word],";
612 // &0x8000 all
613 val&=0x7e7f;
614 }
615 if (val&0x8) flags |= MWAWFont::embossBit;
616 if (val&0x10) flags |= MWAWFont::shadowBit;
617 if (val&0x20)
618 font.set(MWAWFont::Script::super100());
619 if (val&0x40)
620 font.set(MWAWFont::Script::sub100());
621 if ((val&0x600)==0x600) {
622 flags |= MWAWFont::reverseVideoBit;
623 f << "pat[inverse]=" << ((val&0x7800)>>11) << ","; // FIXME use pattern
624 val &= 0x81ff;
625 }
626 if (val&0xff80) f << "font[fl]=#" << std::hex << (val&0xff80) << std::dec << ",";
627 font.setSize(float(input->readLong(szFieldSize)));
628 font.setFlags(flags);
629 font.m_extra=f.str();
630 return true;
631 }
632
633 bool SpringBoardParser::parsePageNumbering(MWAWEntry const &entry)
634 {
635 MWAWInputStreamPtr input = getInput();
636 if (!input)
637 return false;
638 if (!entry.valid() || (entry.length()%98)!=0 || !input->checkPosition(entry.end())) {
639 MWAW_DEBUG_MSG(("SpringBoardParser::parsePageNumbering: find unvalid entry\n"));
640 return false;
641 }
642 ascii().addPos(entry.end());
643 ascii().addNote("_");
644
645 libmwaw::DebugStream f;
646 f << "Entries(PagNumbering):";
647 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
648 ascii().addPos(entry.begin());
649 ascii().addNote(f.str().c_str());
650 int N=int(entry.length()/98);
651 int val;
652 for (int i=0; i<N; ++i) {
653 long pos=input->tell();
654 f.str("");
655 f << "PagNumbering-" << i << ":";
656 int pg=int(input->readLong(2));
657 f << "page=" << pg << ",";
658 SpringBoardParserInternal::HeaderFooter hf;
659 hf.m_type=int(input->readLong(2));
660 if (hf.m_type) f << "number[format]=" << hf.m_type << ",";
661 hf.m_pageNumber=int(input->readLong(2));
662 if (hf.m_pageNumber!=pg) f << "page[number]=" << hf.m_pageNumber << ",";
663 hf.m_position=int(input->readLong(2));
664 f << "pos=" << hf.m_position << ",";
665
666 readFont(hf.m_font, 2);
667 f << hf.m_font.getDebugString(getFontConverter()) << ",";
668 for (int j=0; j<2; ++j) {
669 long actPos=input->tell();
670 int cLen=int(input->readULong(1));
671 if (cLen>40) {
672 MWAW_DEBUG_MSG(("SpringBoardParser::parsePageNumbering: can not read a string\n"));
673 f << "###cLen" << j << "=" << cLen << ",";
674 cLen=0;
675 }
676 hf.m_zones[j].setBegin(actPos+1);
677 hf.m_zones[j].setLength(cLen);
678 std::string text;
679 for (int c=0; c<cLen; ++c)
680 text+=char(input->readULong(1));
681 f << text << ",";
682 input->seek(actPos+40, librevenge::RVNG_SEEK_SET);
683 }
684 for (int j=0; j<2; ++j) {
685 val=int(input->readLong(2));
686 if (val!=(j==0 ? 50 : 90))
687 f << "from[" << (j==0 ? "bottom" : "right") << "]=" << val << ",";
688 }
689 if (m_state->m_pageIdToHeaderFooterMap.count(pg)) {
690 f << "###dup";
691 MWAW_DEBUG_MSG(("SpringBoardParser::parsePageNumbering: an header/footer already exists for the page %d\n", pg));
692 }
693 else
694 m_state->m_pageIdToHeaderFooterMap[pg]=hf;
695 ascii().addPos(pos);
696 ascii().addNote(f.str().c_str());
697 input->seek(pos+98, librevenge::RVNG_SEEK_SET);
698 }
699 return true;
700 }
701
702 bool SpringBoardParser::parseDataList(int id, MWAWEntry const &entry)
703 {
704 MWAWInputStreamPtr input = getInput();
705 if (!input)
706 return false;
707 if (id<0 || id>=10 || !entry.valid() || !input->checkPosition(entry.end())) {
708 MWAW_DEBUG_MSG(("SpringBoardParser::parseDataList: find unvalid entry for id=%d\n", id));
709 return false;
710 }
711 ascii().addPos(entry.end());
712 ascii().addNote("_");
713
714 libmwaw::DebugStream f;
715 std::string const what=m_state->getDataZoneName(id);
716 f << "Entries(" << what << "):";
717 if ((entry.length()%16)!=0) {
718 f << "###";
719 MWAW_DEBUG_MSG(("SpringBoardParser::parseDataList: find unexpected size for zone %s\n", what.c_str()));
720 ascii().addPos(entry.begin());
721 ascii().addNote(f.str().c_str());
722 return false;
723 }
724
725 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
726 int num=int(entry.length()/16);
727 std::map<int, std::pair<MWAWVec2i,MWAWEntry> > listZones;
728 for (int st=0; st<num; ++st) {
729 long pos=input->tell();
730 f.str("");
731 if (st==0)
732 f << "Entries(" << what << "):";
733 else
734 f << what << "[st=" << st << "]:";
735 int firstId=int(input->readLong(4));
736 if (firstId)
737 f << "id[first]=" << firstId << ",";
738 MWAWEntry data;
739 data.setBegin(long(input->readULong(4)));
740 data.setLength(long(input->readULong(4)));
741 f << "zone=" << std::hex << data.begin() << "x" << data.end() << std::dec << ",";
742 int nextId=int(input->readLong(4));
743 f << "next[id]=" << nextId << ",";
744 if (!isEntryValid(data)) {
745 f << "###";
746 MWAW_DEBUG_MSG(("SpringBoardParser::parseDataList: find unexpected zone for zone %s\n", what.c_str()));
747 return false;
748 }
749 m_state->m_parsedZonesMap[entry.begin()]=entry.end();
750 listZones[st]=std::make_pair(MWAWVec2i(firstId,nextId), data);
751 ascii().addPos(pos);
752 ascii().addNote(f.str().c_str());
753 }
754 for (auto const &it : listZones) {
755 MWAWEntry data;
756 MWAWVec2i indices;
757 std::tie(indices,data)=it.second;
758 if (id==8)
759 parseParagraphStyle(data, indices);
760 else
761 parseData(id, data, indices);
762 }
763 return true;
764 }
765
766 bool SpringBoardParser::parseData(int id, MWAWEntry const &entry, MWAWVec2i const &indices)
767 {
768 MWAWInputStreamPtr input = getInput();
769 if (!input)
770 return false;
771 if (id<0 || id>=10 || !entry.valid() || !input->checkPosition(entry.end())) {
772 MWAW_DEBUG_MSG(("SpringBoardParser::parseData: find unvalid entry for id=%d\n", id));
773 return false;
774 }
775
776 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
777 long pos=input->tell();
778 ascii().addPos(entry.end());
779 ascii().addNote("_");
780
781 libmwaw::DebugStream f;
782 std::string const what=m_state->getDataZoneName(id);
783 int const expectedSize[]= {6, 10, 26, 182, -1,
784 -1, -1, -1, -1, 512
785 };
786 if (expectedSize[id]<=0) {
787 f << what << "[header,index=" << indices << "]:";
788 ascii().addPos(pos);
789 ascii().addNote(f.str().c_str());
790 return true;
791 }
792 if (indices[1]<indices[0] || indices[1]-indices[0]<entry.length()/expectedSize[id]) {
793 MWAW_DEBUG_MSG(("SpringBoardParser::parseData: find unexpected length for data zone %s\n", what.c_str()));
794 ascii().addPos(pos);
795 ascii().addNote("###");
796 return false;
797 }
798 for (int i=indices[0]; i<indices[1]; ++i) {
799 pos=input->tell();
800 f.str("");
801 f << what << "-dt" << i << "]:";
802 int val;
803 switch (id) {
804 case 0: { // Doc
805 for (int j=0; j<3; ++j) {
806 val=int(input->readLong(2));
807 if (val==1)
808 continue;
809 if (j==2) {
810 m_state->m_numPages=val;
811 f << "num[pages]=" << val << ",";
812 }
813 else
814 f << "num" << j << "=" << val << ",";
815 }
816 break;
817 }
818 case 1: { // Page
819 for (int j=0; j<5; ++j) {
820 val=int(input->readLong(2));
821 int const expected[]= {0,0,0,0,-1};
822 if (val==expected[j])
823 continue;
824 if (j==0)
825 f << "page=" << val << ",";
826 else if (j==3)
827 f << "first[shape]=" << val << ",";
828 else
829 f << "f" << j << "=" << val << ",";
830 }
831 break;
832 }
833 case 2: { // FrameStyle
834 SpringBoardParserInternal::Frame frame;
835 int pageId=int(input->readLong(1));
836 f << "page[id]=" << pageId << ",";
837 val=int(input->readULong(1));
838 frame.m_type=val&3;
839 f << "type=" << frame.m_type << ",";
840 if (val&0x80) f << "crop[image],";
841 val&=0x7c;
842 // checkme what means type+0x10: multicolumn?
843 f << "fl=" << std::hex << val << std::dec << ","; // 0: layout, 1: text, 2: graphic
844 val=int(input->readULong(1));
845 if (val==0x40)
846 f << "crop[image],"; // checkme
847 else if (val)
848 f << "f0=" << val << ",";
849 auto &style=frame.m_style;
850 int bStyle=int(input->readLong(1));
851 f << "border[style]=" << bStyle << ","; // 0: single, 1: double, 2: 2,1,1, 3: 1,1,2, 4: 1,1,2,1,1, 5: dashed, 6; dotted, 7: big dotted
852 style.m_lineWidth=float(input->readLong(1));
853 if (style.m_lineWidth>0) {
854 f << "line[width]=" << style.m_lineWidth << ",";
855 if (bStyle>=1 && bStyle<=4)
856 style.m_lineWidth*=2;
857 else if (bStyle==5)
858 style.m_lineDashWidth= {10,10};
859 else if (bStyle>=6 && bStyle<=7)
860 style.m_lineDashWidth= {2,2};
861 }
862 val=int(input->readLong(1));
863 if (val!=1) f << "line[pat]=" << val << ",";
864 int page=int(input->readLong(2));
865 f << "page=" << page << ",";
866 for (int j=0; j<5; ++j) { // f5=0|b, f6=0|12, f7=0|100
867 val=int(input->readLong(2));
868 if (!val)
869 continue;
870 if (j==1) {
871 frame.m_numSubZones=val;
872 f << "num[subZones]=" << val << ",";
873 }
874 else if (j==4)
875 f << "gray[scale]=" << val << ",";
876 else
877 f << "f" << j+3 << "=" << val << ",";
878 }
879 for (int j=0; j<2; ++j) {
880 val=int(input->readLong(2));
881 if (val==-1)
882 continue;
883 f << "g" << j << "=" << val << ",";
884 }
885 val=int(input->readLong(4));
886 if (val!=-1) f << "next=F" << val << ",";
887 auto index=std::make_pair(page, pageId);
888 if (m_state->m_idToFrameMap.count(index)==0)
889 m_state->m_idToFrameMap[index]=frame;
890 else {
891 MWAW_DEBUG_MSG(("SpringBoardParser::parseData: find a duplicated frame with id=%dx%d\n", page, pageId));
892 f << "###dup,";
893 }
894 break;
895 }
896 case 3: { // frame header/footer link
897 SpringBoardParserInternal::Link link;
898 f << "unkn=" << std::hex << input->readLong(2) << std::dec << ",";
899 val=int(input->readULong(2));
900 if (val!=1)
901 f << "f0=" << val << ",";
902 readFont(link.m_font, 2);
903 f << link.m_font.getDebugString(getFontConverter()) << ",";
904
905 for (int j=0; j<2; ++j) {
906 long actPos=input->tell();
907 int cLen=int(input->readULong(1));
908 if (cLen>80) {
909 MWAW_DEBUG_MSG(("SpringBoardParser::parseData: can not read a string\n"));
910 f << "###cLen" << j << "=" << cLen << ",";
911 cLen=0;
912 }
913 link.m_texts[j].setBegin(actPos+1);
914 link.m_texts[j].setLength(cLen);
915 std::string text;
916 for (int c=0; c<cLen; ++c) text+=char(input->readULong(1));
917 if (!text.empty())
918 f << (j==0 ? "top" : "bottom") << "[text]=" << text << ",";
919 input->seek(actPos+80, librevenge::RVNG_SEEK_SET);
920 }
921 std::pair<int,int> index;
922 for (int j=0; j<3; ++j) {
923 int pageId[2];
924 for (auto &w : pageId) w=int(input->readLong(2));
925 if (pageId[0]==-1 && pageId[1]==-1) continue;
926 char const *wh[]= {"id", "prev[id]", "next[id]"};
927 if (j==0)
928 index=std::make_pair(pageId[0], pageId[1]);
929 else
930 link.m_links[j-1]=std::make_pair(pageId[0], pageId[1]);
931 f << wh[j] << "=" << MWAWVec2i(pageId[0], pageId[1]) << ",";
932 }
933 if (m_state->m_idToLinkMap.count(index)==0)
934 m_state->m_idToLinkMap[index]=link;
935 else {
936 MWAW_DEBUG_MSG(("SpringBoardParser::parseData: find a duplicated link with id=%dx%d\n", index.first, index.second));
937 f << "###dup,";
938 }
939 break;
940 }
941 // 8: paragraph style, already done
942 case 9: { // Text
943 if (m_state->m_idToTextEntriesMap.count(i)) {
944 MWAW_DEBUG_MSG(("SpringBoardParser::parseData: a text entry with id=%d already exists\n", i));
945 }
946 else {
947 MWAWEntry textEntry;
948 textEntry.setBegin(pos);
949 textEntry.setLength(512);
950 m_state->m_idToTextEntriesMap[i]=textEntry;
951 }
952 std::string text;
953 for (int j=0; j<512; ++j) {
954 char c=char(input->readULong(1));
955 if (!c)
956 break;
957 text+=c;
958 }
959 f << text << ",";
960 break;
961 }
962 default:
963 break;
964 }
965 input->seek(pos+expectedSize[id], librevenge::RVNG_SEEK_SET);
966 ascii().addPos(pos);
967 ascii().addNote(f.str().c_str());
968 }
969 return true;
970 }
971
972 bool SpringBoardParser::parseParagraphStyle(MWAWEntry const &entry, MWAWVec2i const &indices)
973 {
974 MWAWInputStreamPtr input = getInput();
975 if (!input)
976 return false;
977 int const N=indices[1]-indices[0];
978 if (!entry.valid() || !input->checkPosition(entry.end()) || N<0 || entry.length()<4*N) {
979 MWAW_DEBUG_MSG(("SpringBoardParser::parseParagraphStyle: find invalid entry\n"));
980 return false;
981 }
982 ascii().addPos(entry.end());
983 ascii().addNote("_");
984
985 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
986 long pos=input->tell();
987 libmwaw::DebugStream f;
988 f << "ParaStyle[" << N << "]:zones=[";
989 std::map<int, long> ptrs;
990 for (int i=indices[0]; i<indices[1]; ++i) {
991 long ptr=long(input->readULong(4));
992 f << std::hex << ptr << std::dec << ",";
993 if (ptr>=entry.begin()+4*N && ptr+16<=entry.end())
994 ptrs[i]=ptr;
995 else {
996 f << "###";
997 MWAW_DEBUG_MSG(("SpringBoardParser::parseParagraphStyle: find bad ptr\n"));
998 }
999 }
1000 f << "],";
1001 ascii().addPos(pos);
1002 ascii().addNote(f.str().c_str());
1003 int val;
1004 for (auto const &it : ptrs) {
1005 f.str("");
1006 f << "ParaStyle-P" << it.first << ":";
1007 MWAWParagraph para;
1008 for (int i=0; i<4; ++i) {
1009 val=int(input->readULong(1));
1010 if (val==(i==3 ? 1 : 0)) continue;
1011 if (i==0) {
1012 switch (val) {
1013 case 1:
1014 para.m_justify = MWAWParagraph::JustificationCenter;
1015 break;
1016 case 2:
1017 para.m_justify = MWAWParagraph::JustificationRight;
1018 break;
1019 case 3:
1020 para.m_justify = MWAWParagraph::JustificationFull;
1021 break;
1022 default:
1023 MWAW_DEBUG_MSG(("SpringBoardParser::parseParagraphStyle: find unknown justification\n"));
1024 f << "###align=" << val << ","; // 1: center, 2:right, 3: justify?
1025 break;
1026 }
1027 }
1028 else if (i==1 || i==2)
1029 para.m_spacings[i]=12*float(val)/72; // in percent, so asume font size=12
1030 else
1031 f << "f0=" << val << ",";
1032 }
1033 para.m_marginsUnit=librevenge::RVNG_POINT;
1034 for (int i=0; i<5; ++i) {
1035 val=int(input->readULong(2));
1036 int const expected[]= {1,0,0,0,0};
1037 if (val==expected[i])
1038 continue;
1039 if (i==1) {
1040 if (val&0x8000)
1041 para.m_spacings[2]=12*float(val&0x7fff)/72;
1042 else
1043 para.setInterline(1+float(val), librevenge::RVNG_PERCENT);
1044 }
1045 else if (i>=2 && i<=4)
1046 para.m_margins[i-2]=float(val);
1047 else
1048 f << "f" << i+1 << "=" << val << ","; // 8: related to char style
1049 }
1050 int nTabs=int(input->readULong(2));
1051 if (nTabs) {
1052 if (pos+16+4*nTabs>entry.end()) {
1053 f << "###nTabs=" << nTabs << ",";
1054 MWAW_DEBUG_MSG(("SpringBoardParser::parseParagraphStyle: the number of tabs seems bad\n"));
1055 nTabs=0;
1056 }
1057 for (int i=0; i<nTabs; ++i) {
1058 MWAWTabStop tab;
1059 char c=char(input->readLong(1));
1060 if (c>=0x20 && c<0x7f)
1061 tab.m_leaderCharacter=uint16_t(c);
1062 else {
1063 static bool first=true;
1064 if (first) {
1065 MWAW_DEBUG_MSG(("SpringBoardParser::parseParagraphStyle: find unexpected leader characters\n"));
1066 first=false;
1067 }
1068 f << "###tab" << i << "=" << int(c) << ",";
1069 }
1070 input->seek(1, librevenge::RVNG_SEEK_CUR);
1071 tab.m_position=float(input->readLong(2))/72;
1072 }
1073 }
1074 f << para;
1075 if (m_state->m_idToParagraphMap.count(it.first)) {
1076 MWAW_DEBUG_MSG(("SpringBoardParser::parseParagraphStyle: oops a paragraph with id=%d already exists\n", it.first));
1077 f << "###dup";
1078 }
1079 else
1080 m_state->m_idToParagraphMap[it.first]=para;
1081 ascii().addPos(it.second);
1082 ascii().addNote(f.str().c_str());
1083 }
1084 return true;
1085 }
1086
1087 bool SpringBoardParser::parseLastZone(int id, MWAWEntry const &entry)
1088 {
1089 MWAWInputStreamPtr input = getInput();
1090 if (!input)
1091 return false;
1092 if (id<0 || id>=3 || !entry.valid() || !input->checkPosition(entry.end())) {
1093 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: find invalid entry for id=%d\n", id));
1094 return false;
1095 }
1096 ascii().addPos(entry.end());
1097 ascii().addNote("_");
1098
1099 libmwaw::DebugStream f, f2;
1100 char const *wh[]= {"Shape", "TxtPos", "Frame"};
1101 std::string const what(wh[id]);
1102 f << "Entries(" << what << "):";
1103 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1104 switch (id) {
1105 case 0: {
1106 if ((entry.length()%8)!=0) {
1107 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: unexpected size\n"));
1108 f << "###";
1109 break;
1110 }
1111 int N=int(entry.length()/8);
1112 std::map<std::pair<int,int>,long> idToPtrs;
1113 for (int i=0; i<N; ++i) {
1114 long pos=input->tell();
1115 f2.str("");
1116 f2 << what << "-" << i << ":";
1117 long beg=long(input->readULong(4));
1118 f2 << "pos=" << std::hex << beg << std::dec << ",";
1119 int pg=int(input->readLong(2));
1120 int pgId=int(input->readLong(2));
1121 if (!isPositionValid(beg) || !input->checkPosition(beg+4)) {
1122 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: a shape position seems bad\n"));
1123 f2 << "###";
1124 }
1125 else
1126 idToPtrs[std::make_pair(pg,pgId)]=beg;
1127 f2 << "page=" << pg << ",";
1128 f2 << "id=" << pgId << ",";
1129 ascii().addPos(pos);
1130 ascii().addNote(f2.str().c_str());
1131 }
1132 for (auto const &it : idToPtrs)
1133 parseShape(it.second, it.first);
1134 break;
1135 }
1136 case 1: { // checkme maybe link
1137 if ((entry.length()%6)!=0) {
1138 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: unexpected size\n"));
1139 f << "###";
1140 break;
1141 }
1142 int N=int(entry.length()/6);
1143 f << "unkn=[";
1144 for (int i=0; i<N; ++i) {
1145 int val=int(input->readLong(4));
1146 f << "last[char]=" << input->readLong(2);
1147 if (val!=-1)
1148 f << ":" << val;
1149 f << ",";
1150 }
1151 f << "],";
1152 break;
1153 }
1154 case 2: { // a list of pages
1155 f << "list,";
1156 if (entry.length()<2) {
1157 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: unexpected size\n"));
1158 f << "###";
1159 break;
1160 }
1161 int N=int(input->readLong(2));
1162 f << "N=" << N << ",";
1163 if (2+8*N>entry.length()) {
1164 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: unexpected N\n"));
1165 f << "###";
1166 break;
1167 }
1168 std::map<int,long> positions;
1169 for (int i=0; i<N; ++i) {
1170 long pos=input->tell();
1171 f2.str("");
1172 f2 << what << "-" << i << "[list]:";
1173 int pg=int(input->readLong(2));
1174 f2 << "page=" << pg << ",";
1175 int val=int(input->readLong(2));
1176 if (val!=pg) f2 << "page2=" << val << ",";
1177 long beg=long(input->readULong(4));
1178 f2 << "pos=" << std::hex << beg << std::dec << ",";
1179 if (beg<entry.begin() || beg>=entry.end()) {
1180 MWAW_DEBUG_MSG(("SpringBoardParser::parseLastZone: a position seems bad\n"));
1181 f2 << "###";
1182 }
1183 else
1184 positions[pg]=beg;
1185 ascii().addPos(pos);
1186 ascii().addNote(f2.str().c_str());
1187 }
1188 for (auto const &it : positions)
1189 parseFrames(it.first, it.second);
1190 break;
1191 }
1192 default:
1193 break;
1194 }
1195 ascii().addPos(entry.begin());
1196 ascii().addNote(f.str().c_str());
1197 return true;
1198 }
1199
1200 bool SpringBoardParser::parseShape(long begPos, std::pair<int,int> const &pageId)
1201 {
1202 MWAWInputStreamPtr input = getInput();
1203 if (!input)
1204 return false;
1205 if (begPos<0x80 || !input->checkPosition(begPos+4)) {
1206 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: the begin position seems bad\n"));
1207 return false;
1208 }
1209 input->seek(begPos, librevenge::RVNG_SEEK_SET);
1210 int type=-1;
1211 auto const fIt=m_state->m_idToFrameMap.find(pageId);
1212 if (fIt==m_state->m_idToFrameMap.end()) {
1213 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: can not find the shape %d-%d\n", pageId.first, pageId.second));
1214 }
1215 else
1216 type=fIt->second.m_type;
1217 SpringBoardParserInternal::Shape shape;
1218 shape.m_type=type;
1219
1220 libmwaw::DebugStream f;
1221 f << "Shape-" << pageId.first << "x" << pageId.second << "[type=" << type << "]:";
1222 input->seek(begPos, librevenge::RVNG_SEEK_SET);
1223 bool asciiUpdated=false;
1224 switch (type) {
1225 case 0:
1226 case 1: {
1227 int N=int(input->readULong(4));
1228 f << "N=" << N << ",";
1229 if (N<0 || N+1>(input->size()-begPos)/4 || !isPositionValid(begPos+4+4*N)) {
1230 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: can not read the number of shapes\n"));
1231 f << "###";
1232 N=0;
1233 }
1234 std::vector<long> listPtrs;
1235 for (int i=0; i<N; ++i) listPtrs.push_back(long(input->readULong(4)));
1236 ascii().addPos(begPos);
1237 ascii().addNote(f.str().c_str());
1238 asciiUpdated=true;
1239
1240 for (long ptr : listPtrs) {
1241 if (!isPositionValid(ptr) || !input->checkPosition(ptr+24)) {
1242 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: a text pointer seems bad\n"));
1243 if (ptr>0)
1244 break;
1245 continue;
1246 }
1247 f.str("");
1248 f << "Shape-" << pageId.first << "x" << pageId.second << ":text,";
1249 SpringBoardParserInternal::Shape::Paragraph para;
1250 input->seek(ptr, librevenge::RVNG_SEEK_SET);
1251 int val=int(input->readULong(2));
1252 if (val&0x8000) {
1253 para.m_newColumn=true;
1254 f << "new[column],";
1255 val &= 0x7fff;
1256 }
1257 if (val)
1258 f << "fl=" << std::hex << val << std::dec << ",";
1259 para.m_numChars=int(input->readULong(2));
1260 f << "num[char]=" << para.m_numChars << ",";
1261 for (int i=0; i<2; ++i) {
1262 val=int(input->readLong(2));
1263 if (!val) continue;
1264 if (i==0) {
1265 para.m_firstChar=val;
1266 f << "first[char]=" << val << ",";
1267 }
1268 else
1269 f << "y[pos]=" << val << ",";
1270 }
1271 val=int(input->readLong(4));
1272 if (val!=ptr) f << "ptr=" << std::hex << val << std::dec << ",";
1273 para.m_numCharStyles=int(input->readLong(4));
1274 f << "num[style]=" << para.m_numCharStyles << ",";
1275 para.m_paragraphStyle=int(input->readLong(4));
1276 f << "para[style]=" << para.m_paragraphStyle << ",";
1277 para.m_textZoneId=int(input->readLong(4));
1278 if (para.m_textZoneId!=-1)
1279 f << "text[id]=" << para.m_textZoneId << ",";
1280 if (ptr+24+10*para.m_numCharStyles<ptr+24 || (input->size()-24-ptr)/10<para.m_numCharStyles ||
1281 !input->checkPosition(ptr+24+10*para.m_numCharStyles)) {
1282 f << "###";
1283 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: the number of style seems bad\n"));
1284 para.m_numCharStyles=0;
1285 }
1286 para.m_charEntry.setBegin(input->tell());
1287 para.m_charEntry.setLength(10*para.m_numCharStyles);
1288 shape.m_paragraphs.push_back(para);
1289 ascii().addPos(ptr);
1290 ascii().addNote(f.str().c_str());
1291 }
1292 break;
1293 }
1294 case 2: {
1295 int val=int(input->readULong(4));
1296 if (val)
1297 f << "f0=" << val << ",";
1298 long len=long(input->readULong(4));
1299 f << "len=" << len << ",";
1300 if ((len && len<10) || begPos+12+len<begPos+12 || !input->checkPosition(begPos+12+len)) {
1301 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: can not read the picture length\n"));
1302 f << "###";
1303 break;
1304 }
1305 shape.m_pictEntry.setBegin(begPos+12);
1306 shape.m_pictEntry.setLength(len);
1307 val=int(input->readULong(4));
1308 if (val)
1309 f << "f1=" << val << ",";
1310 break;
1311 }
1312 default:
1313 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: find unknown type of shapes\n"));
1314 f << "###";
1315 break;
1316 }
1317 if (m_state->m_idToShapeMap.count(pageId)) {
1318 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: find a duplicated shape %d:%d\n", pageId.first, pageId.second));
1319 f << "###";
1320 }
1321 else
1322 m_state->m_idToShapeMap[pageId]=shape;
1323 if (!asciiUpdated) {
1324 ascii().addPos(begPos);
1325 ascii().addNote(f.str().c_str());
1326 }
1327 return true;
1328 }
1329
1330 bool SpringBoardParser::parseFrames(int page, long begPos)
1331 {
1332 MWAWInputStreamPtr input = getInput();
1333 if (!input)
1334 return false;
1335 if (begPos<0x80 || !input->checkPosition(begPos+14)) {
1336 MWAW_DEBUG_MSG(("SpringBoardParser::parseFrames: the begin position seems bad\n"));
1337 return false;
1338 }
1339 libmwaw::DebugStream f;
1340 f << "Entries(Frame):page=" << page << ",";
1341 input->seek(begPos, librevenge::RVNG_SEEK_SET);
1342 int val;
1343 for (int i=0; i<2; ++i) { // f0=0|-4|10
1344 val=int(input->readLong(2));
1345 if (val!=i)
1346 f << "f" << i << "=" << val << ",";
1347 }
1348 int dim[4];
1349 for (auto &d : dim) d=int(input->readLong(2));
1350 MWAWBox2i dimension=MWAWBox2i(MWAWVec2i(dim[1], dim[0]),MWAWVec2i(dim[3], dim[2]));
1351 f << "box=" << dimension << ",";
1352 if (m_state->m_pageIdToDimensionMap.count(page)) {
1353 f << "###dupl,";
1354 MWAW_DEBUG_MSG(("SpringBoardParser::parseFrames: the page %d dimension is already set\n", page));
1355 }
1356 else
1357 m_state->m_pageIdToDimensionMap[page]=dimension;
1358 int N=int(input->readULong(2));
1359 f << "N=" << N << ",";
1360 if (!input->checkPosition(begPos+14+N*28)) {
1361 MWAW_DEBUG_MSG(("SpringBoardParser::parseFrames: can not read N\n"));
1362 f << "###";
1363 ascii().addPos(begPos);
1364 ascii().addNote(f.str().c_str());
1365 return false;
1366 }
1367 ascii().addPos(begPos);
1368 ascii().addNote(f.str().c_str());
1369
1370 SpringBoardParserInternal::Frame dummy;
1371 for (int i=0; i<N; ++i) {
1372 long pos=input->tell();
1373 f.str("");
1374 int id=int(input->readLong(1));
1375 f << "Frame-" << page << "x" << id << ":";
1376 auto fIt=m_state->m_idToFrameMap.find(std::make_pair(page,id));
1377 auto &frame=fIt!=m_state->m_idToFrameMap.end() ? fIt->second : dummy;
1378 if (fIt==m_state->m_idToFrameMap.end() && (page!=0 || id!=0)) { // 0x0 seems to be the default layout
1379 MWAW_DEBUG_MSG(("SpringBoardParser::parseFrames: can not find frame %dx%d\n", page, id));
1380 }
1381 val=int(input->readLong(1));
1382 switch (val) {
1383 case 0:
1384 f << "layout,";
1385 break;
1386 case 1:
1387 f << "text,";
1388 break;
1389 case 2:
1390 f << "graphics,";
1391 break;
1392 default:
1393 MWAW_DEBUG_MSG(("SpringBoardParser::parseFrames: find unknown frame type\n"));
1394 f << "###type=" << val << ",";
1395 break;
1396 }
1397 for (int st=0; st<2; ++st) {
1398 for (auto &d : dim) d=int(input->readLong(2));
1399 frame.m_boxes[st]=MWAWBox2i(MWAWVec2i(dim[1], dim[0]),MWAWVec2i(dim[3], dim[2]));
1400 if (st==0)
1401 f << "box=" << frame.m_boxes[0] << ",";
1402 else if (frame.m_boxes[0]!=frame.m_boxes[1])
1403 f << "box[internal]=" << frame.m_boxes[1] << ",";
1404 }
1405 for (int j=0; j<4; ++j) {
1406 val=int(input->readLong(2));
1407 if (val==0) continue;
1408 f << "f" << j << "=" << val << ",";
1409 }
1410 frame.m_numColumns=int(input->readULong(2));
1411 if (frame.m_numColumns!=1)
1412 f << "N[col]=" << frame.m_numColumns << ",";
1413 if (!input->checkPosition(pos+28+frame.m_numColumns*10)) {
1414 MWAW_DEBUG_MSG(("SpringBoardParser::parseFrames: find unexpected subzone N\n"));
1415 f << "###";
1416 ascii().addPos(pos);
1417 ascii().addNote(f.str().c_str());
1418 return false;
1419 }
1420 ascii().addPos(pos);
1421 ascii().addNote(f.str().c_str());
1422
1423 for (int col=0; col<frame.m_numColumns; ++col) {
1424 pos=input->tell();
1425 f.str("");
1426 f << "Frame-" << page << "x" << id << "[" << col << "]:";
1427 val=int(input->readULong(1));
1428 if (val)
1429 f << "f0=" << val << ",";
1430 val=int(input->readULong(1));
1431 if (val!=1)
1432 f << "col=" << val << ",";
1433 for (auto &d : dim) d=int(input->readLong(2));
1434 // checkme can we have some non increasing columns ?
1435 frame.m_columnBoxes.push_back(MWAWBox2i(MWAWVec2i(dim[1], dim[0]),MWAWVec2i(dim[3], dim[2])));
1436 f << "box=" << frame.m_columnBoxes.back() << ",";
1437 ascii().addPos(pos);
1438 ascii().addNote(f.str().c_str());
1439 }
1440 }
1441 return true;
1442 }
1443
1444 ////////////////////////////////////////////////////////////
1445 // send shapes
1446 ////////////////////////////////////////////////////////////
1447 bool SpringBoardParser::sendFrame(std::pair<int,int> const &pageId)
1448 {
1449 auto input=getInput();
1450 auto listener=getGraphicListener();
1451 if (!input || !listener) {
1452 MWAW_DEBUG_MSG(("SpringBoardParser::sendFrame: can not find the listener\n"));
1453 return false;
1454 }
1455 auto fIt=m_state->m_idToFrameMap.find(pageId);
1456 if (fIt==m_state->m_idToFrameMap.end()) {
1457 MWAW_DEBUG_MSG(("SpringBoardParser::sendFrame: can not find any frame for %d:%d\n", pageId.first, pageId.second));
1458 return false;
1459 }
1460 auto lIt=m_state->m_idToLinkMap.find(pageId);
1461 int whichBox = (lIt!=m_state->m_idToLinkMap.end() && lIt->second.hasText()) ? 1 : 0;
1462 SpringBoardParserInternal::Frame const &frame=fIt->second;
1463 MWAWPosition pos(MWAWVec2f(frame.m_boxes[whichBox][0]), MWAWVec2f(frame.m_boxes[whichBox].size()), librevenge::RVNG_POINT);
1464 pos.setRelativePosition(MWAWPosition::Page);
1465
1466 auto sIt=m_state->m_idToShapeMap.find(pageId);
1467 if (sIt==m_state->m_idToShapeMap.end()) {
1468 MWAW_DEBUG_MSG(("SpringBoardParser::sendFrame: can not find any shape for %d:%d\n", pageId.first, pageId.second));
1469 auto gShape=MWAWGraphicShape::rectangle(MWAWBox2f(frame.m_boxes[whichBox]));
1470 listener->insertShape(pos, gShape, frame.m_style);
1471 return false;
1472 }
1473
1474 if (whichBox==1) {
1475 auto const &link=lIt->second;
1476 for (int p=0; p<2; ++p) {
1477 if (!link.m_texts[p].valid())
1478 continue;
1479 int limits[]= {p==0 ? frame.m_boxes[0][0][1] : frame.m_boxes[1][1][1],
1480 p==0 ? frame.m_boxes[1][0][1] : frame.m_boxes[0][1][1]
1481 };
1482 MWAWPosition posL(MWAWVec2f((float)frame.m_boxes[0][0][0],(float)limits[0]),
1483 MWAWVec2f((float)frame.m_boxes[0].size()[0],float(limits[1]-limits[0])), librevenge::RVNG_POINT);
1484 posL.setRelativePosition(MWAWPosition::Page);
1485 auto subdoc=std::make_shared<SpringBoardParserInternal::SubDocument>(*this, getInput(), pageId, p==0);
1486 listener->insertTextBox(posL, subdoc, MWAWGraphicStyle::emptyStyle());
1487 }
1488 }
1489 SpringBoardParserInternal::Shape const &shape=sIt->second;
1490 switch (shape.m_type) {
1491 case 0: { // layout
1492 auto subdoc=std::make_shared<SpringBoardParserInternal::SubDocument>(*this, getInput(), pageId);
1493 listener->insertTextBox(pos, subdoc, frame.m_style);
1494 return true;
1495 }
1496 case 1: { // text zone
1497 size_t numCols=frame.m_columnBoxes.size();
1498 std::vector<int> paraLimits;
1499 paraLimits.push_back(0);
1500 for (size_t p=0; p<shape.m_paragraphs.size(); ++p) {
1501 if (shape.m_paragraphs[p].m_newColumn)
1502 paraLimits.push_back(int(p));
1503 }
1504 if (paraLimits.size()>numCols)
1505 paraLimits.resize(numCols);
1506
1507 for (size_t c=0; c<std::max<size_t>(1,numCols); ++c) {
1508 MWAWPosition posi;
1509 if (numCols) {
1510 posi.setUnit(librevenge::RVNG_POINT);
1511 posi.setOrigin(MWAWVec2f(frame.m_boxes[whichBox][0]+frame.m_columnBoxes[c][0]));
1512 posi.setSize(MWAWVec2f(frame.m_columnBoxes[c].size()));
1513 posi.setRelativePosition(MWAWPosition::Page);
1514 }
1515 int limits[]= {0,-1}; // ie. all
1516 if (c+1<paraLimits.size()) {
1517 limits[0]=paraLimits[c];
1518 limits[1]=paraLimits[c+1]-1;
1519 }
1520 else if (c<paraLimits.size()) {
1521 limits[0]=paraLimits[c];
1522 limits[1]=-1; // ie. to last paragraph
1523 }
1524 else if (c)
1525 limits[0]=int(paraLimits.size()); // ie. nothing to retrieve
1526 auto subdoc=std::make_shared<SpringBoardParserInternal::SubDocument>(*this, getInput(), pageId, std::make_pair(limits[0], limits[1]));
1527 listener->insertTextBox(numCols==0 ? pos : posi, subdoc, frame.m_style);
1528 }
1529 return true;
1530 }
1531 case 2: {
1532 if (!shape.m_pictEntry.valid())
1533 break;
1534 input->seek(shape.m_pictEntry.begin(), librevenge::RVNG_SEEK_SET);
1535 std::shared_ptr<MWAWPict> pict(MWAWPictData::get(input, int(shape.m_pictEntry.length())));
1536 MWAWEmbeddedObject image;
1537 if (pict && pict->getBinary(image) && !image.m_dataList.empty()) {
1538 #ifdef DEBUG_WITH_FILES
1539 static int volatile pictName = 0;
1540 libmwaw::DebugStream f2;
1541 f2 << "PICT-" << ++pictName << ".pct";
1542 libmwaw::Debug::dumpFile(image.m_dataList[0], f2.str().c_str());
1543 ascii().skipZone(shape.m_pictEntry.begin(), shape.m_pictEntry.end()-1);
1544 #endif
1545 listener->insertPicture(pos, image, frame.m_style);
1546 return true;
1547 }
1548 else {
1549 MWAW_DEBUG_MSG(("SpringBoardParser::parseShape: sorry, can not retrieve a picture\n"));
1550 }
1551 break;
1552 }
1553 default:
1554 break;
1555 }
1556 auto gShape=MWAWGraphicShape::rectangle(MWAWBox2f(frame.m_boxes[0]));
1557 listener->insertShape(pos, gShape, frame.m_style);
1558 return true;
1559 }
1560
1561 bool SpringBoardParser::sendLinkShape(std::pair<int,int> const &linkId, bool isTop)
1562 {
1563 auto input=getInput();
1564 auto listener=getGraphicListener();
1565 if (!input || !listener) {
1566 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextLink: can not find the listener\n"));
1567 return false;
1568 }
1569 auto lIt=m_state->m_idToLinkMap.find(linkId);
1570 if (lIt==m_state->m_idToLinkMap.end()) {
1571 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextLink: can not find any link for %d:%d\n", linkId.first, linkId.second));
1572 return false;
1573 }
1574 SpringBoardParserInternal::Link const &link=lIt->second;
1575 listener->setFont(link.m_font);
1576
1577 MWAWEntry const &entry=link.m_texts[isTop ? 0 : 1];
1578 if (!entry.valid()) {
1579 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextLink: can not find text for link for %d:%d\n", linkId.first, linkId.second));
1580 return false;
1581 }
1582 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1583 for (long i=0; i<entry.length(); ++i) {
1584 unsigned char c=(unsigned char)(input->readLong(1));
1585 if (c == 0x9)
1586 listener->insertTab();
1587 else if (c == 0xd)
1588 listener->insertEOL();
1589 else if (c<0x1f) {
1590 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextLink: find bad character %d\n", int(c)));
1591 }
1592 else
1593 listener->insertCharacter(c);
1594 }
1595 return true;
1596 }
1597
1598 bool SpringBoardParser::sendTextShape(std::pair<int,int> const &pageId, int minParagraph, int maxParagraph)
1599 {
1600 auto input=getInput();
1601 auto listener=getGraphicListener();
1602 if (!input || !listener) {
1603 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: can not find the listener\n"));
1604 return false;
1605 }
1606 auto sIt=m_state->m_idToShapeMap.find(pageId);
1607 if (sIt==m_state->m_idToShapeMap.end()) {
1608 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: can not find any shape for %d:%d\n", pageId.first, pageId.second));
1609 return false;
1610 }
1611 SpringBoardParserInternal::Shape const &shape=sIt->second;
1612 if (shape.m_paragraphs.empty() || minParagraph>=int(shape.m_paragraphs.size()))
1613 return true;
1614 if (minParagraph<0) minParagraph=0;
1615 if (maxParagraph<minParagraph || maxParagraph>=int(shape.m_paragraphs.size()))
1616 maxParagraph=int(shape.m_paragraphs.size()-1);
1617 int textZoneId=-1;
1618 for (int p=0; p<minParagraph; ++p) {
1619 auto const &para = shape.m_paragraphs[size_t(p)];
1620 if (para.m_textZoneId!=-1)
1621 textZoneId=para.m_textZoneId;
1622 }
1623 for (int p=minParagraph; p<=maxParagraph; ++p) {
1624 auto const &para = shape.m_paragraphs[size_t(p)];
1625 auto const &pIt=m_state->m_idToParagraphMap.find(para.m_paragraphStyle);
1626 if (pIt==m_state->m_idToParagraphMap.end()) {
1627 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: unknown paragraph=%d\n", para.m_paragraphStyle));
1628 }
1629 else
1630 listener->setParagraph(pIt->second);
1631 if (para.m_textZoneId!=-1)
1632 textZoneId=para.m_textZoneId;
1633 if (textZoneId==-1)
1634 continue;
1635 auto const &tIt=m_state->m_idToTextEntriesMap.find(textZoneId);
1636 if (tIt==m_state->m_idToTextEntriesMap.end() || !tIt->second.valid()) {
1637 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: unknown text id=%d\n", textZoneId));
1638 continue;
1639 }
1640
1641 // now retrieve the font styles
1642 input->seek(para.m_charEntry.begin(), librevenge::RVNG_SEEK_SET);
1643 std::map<int, MWAWFont> posToCharMap;
1644 int cPos=0;
1645 libmwaw::DebugStream f;
1646 for (int i=0; i<para.m_numCharStyles; ++i) {
1647 long pos=input->tell();
1648 f.str("");
1649 f << "Shape-char[" << i << "]:";
1650 f << "cPos=" << cPos << ",";
1651 int newPos=cPos+int(input->readLong(2));
1652 MWAWFont font;
1653 readFont(font,1);
1654 int val=int(input->readLong(2));
1655 if (val) {
1656 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: unknown styles=%d\n", val));
1657 f << "#f0=" << val << ",";
1658 }
1659 val=int(input->readLong(1));
1660 if (val>=0 && val<63)
1661 font.setDeltaLetterSpacing(float(val));
1662 else {
1663 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: unexpected char spacing=%d\n", val));
1664 f << "##char[spacing]=" << val << ",";
1665 }
1666 f << font.getDebugString(getFontConverter()) << ",";
1667 input->seek(pos+10, librevenge::RVNG_SEEK_SET);
1668 posToCharMap[cPos]=font;
1669 cPos=newPos;
1670 ascii().addPos(pos);
1671 ascii().addNote(f.str().c_str());
1672 }
1673
1674 MWAWEntry const textZone=tIt->second;
1675 input->seek(textZone.begin()+para.m_firstChar, librevenge::RVNG_SEEK_SET);
1676 for (int l=0; l<para.m_numChars; ++l) {
1677 auto cIt=posToCharMap.find(l);
1678 if (cIt!=posToCharMap.end())
1679 listener->setFont(cIt->second);
1680 unsigned char c=(unsigned char)(input->readLong(1));
1681 if (c == 0x9)
1682 listener->insertTab();
1683 else if (c == 0xd)
1684 listener->insertEOL();
1685 else if (c<0x1f) {
1686 MWAW_DEBUG_MSG(("SpringBoardParser::sendTextShape: find bad character %d\n", int(c)));
1687 }
1688 else
1689 listener->insertCharacter(c);
1690 }
1691 }
1692 return true;
1693 }
1694
1695 bool SpringBoardParser::sendHeaderFooter(int hfId)
1696 {
1697 auto input=getInput();
1698 auto listener=getGraphicListener();
1699 if (!input || !listener) {
1700 MWAW_DEBUG_MSG(("SpringBoardParser::sendHeaderFooter: can not find the listener\n"));
1701 return false;
1702 }
1703 auto hfIt=m_state->m_pageIdToHeaderFooterMap.find(hfId);
1704 if (hfIt==m_state->m_pageIdToHeaderFooterMap.end()) {
1705 MWAW_DEBUG_MSG(("SpringBoardParser::sendHeaderFooter: can not find the header footer for id=%d\n", hfId));
1706 return false;
1707 }
1708 auto const &hf=hfIt->second;
1709 listener->setFont(hf.m_font);
1710 MWAWParagraph para; // FIXME: this does nothing, find another way to send center and right header/footer
1711 if (hf.m_type==1 || hf.m_type==4)
1712 para.m_justify = MWAWParagraph::JustificationCenter;
1713 else if (hf.m_type==2 || hf.m_type==5)
1714 para.m_justify = MWAWParagraph::JustificationRight;
1715 listener->setParagraph(para);
1716 if (hf.m_zones[0].valid()) { // prefix
1717 input->seek(hf.m_zones[0].begin(), librevenge::RVNG_SEEK_SET);
1718 for (long l=0; l<hf.m_zones[0].length(); ++l) {
1719 unsigned char c=(unsigned char)(input->readLong(1));
1720 if (c == 0x9)
1721 listener->insertTab();
1722 else if (c == 0xd)
1723 listener->insertEOL();
1724 else if (c<0x1f) {
1725 MWAW_DEBUG_MSG(("SpringBoardParser::sendHeaderFooter: find bad character %d\n", int(c)));
1726 }
1727 else
1728 listener->insertCharacter(c);
1729 }
1730 }
1731 MWAWField pageNumber(MWAWField::PageNumber);
1732 switch (hf.m_type) {
1733 case 1:
1734 pageNumber.m_numberingType=libmwaw::LOWERCASE_ROMAN;
1735 break;
1736 case 2:
1737 pageNumber.m_numberingType=libmwaw::UPPERCASE_ROMAN;
1738 break;
1739 case 3:
1740 pageNumber.m_numberingType=libmwaw::LOWERCASE;
1741 break;
1742 case 4:
1743 pageNumber.m_numberingType=libmwaw::UPPERCASE;
1744 break;
1745 default: // also 5-7 full number minuscule, majuscule, title
1746 break;
1747 }
1748 if (pageNumber.m_type!=8)
1749 listener->insertField(pageNumber);
1750 if (hf.m_zones[1].valid()) { // suffix
1751 input->seek(hf.m_zones[1].begin(), librevenge::RVNG_SEEK_SET);
1752 for (long l=0; l<hf.m_zones[1].length(); ++l) {
1753 unsigned char c=(unsigned char)(input->readLong(1));
1754 if (c == 0x9)
1755 listener->insertTab();
1756 else if (c == 0xd)
1757 listener->insertEOL();
1758 else if (c<0x1f) {
1759 MWAW_DEBUG_MSG(("SpringBoardParser::sendHeaderFooter: find bad character %d\n", int(c)));
1760 }
1761 else
1762 listener->insertCharacter(c);
1763 }
1764 }
1765 return true;
1766 }
1767
1768
1769 ////////////////////////////////////////////////////////////
1770 // read shapes
1771 ////////////////////////////////////////////////////////////
1772
1773 ////////////////////////////////////////////////////////////
1774 // read the header
1775 ////////////////////////////////////////////////////////////
1776 bool SpringBoardParser::checkHeader(MWAWHeader *header, bool strict)
1777 {
1778 *m_state = SpringBoardParserInternal::State();
1779 MWAWInputStreamPtr input = getInput();
1780 if (!input || !input->hasDataFork() || !input->checkPosition(128))
1781 return false;
1782
1783 libmwaw::DebugStream f;
1784 f << "FileHeader:";
1785 input->seek(0, librevenge::RVNG_SEEK_SET);
1786 if (input->readULong(2)!=0xcd90)
1787 return false;
1788 for (int i=0; i<2; ++i) {
1789 int val=int(input->readLong(1));
1790 if (val==i) continue;
1791 if (i==0)
1792 f << "rev" << val << ","; // look like a counter (modulo 10)
1793 else
1794 f << "f" << i << "=" << val << ",";
1795 }
1796 if ((input->readULong(2)&0xff00)!=0) return false;
1797
1798 if (strict) {
1799 input->seek(20, librevenge::RVNG_SEEK_SET);
1800 for (int i=0; i<10; ++i) {
1801 long beg=long(input->readULong(4));
1802 long len=long(input->readULong(2));
1803 if (!len)
1804 continue;
1805 if (beg<=0 || beg+len<=0 || !input->checkPosition(beg+len)) {
1806 MWAW_DEBUG_MSG(("SpringBoardParser::checkHeader: find unexpected position: %d\n", int(i)));
1807 f << "###";
1808 ascii().addPos(0);
1809 ascii().addNote(f.str().c_str());
1810
1811 return false;
1812 }
1813 }
1814 }
1815
1816 ascii().addPos(0);
1817 ascii().addNote(f.str().c_str());
1818 if (header)
1819 header->reset(MWAWDocument::MWAW_T_SPRINGBOARD_PUBLISHER, 2, MWAWDocument::MWAW_K_DRAW);
1820 input->seek(4, librevenge::RVNG_SEEK_SET);
1821
1822 return true;
1823 }
1824
1825 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: