Debian Codegraph @

src/lib/MacDraft5Parser.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 <set>
39 #include <sstream>
40 #include <stack>
41
42 #include <librevenge/librevenge.h>
43
44 #include "MWAWFontConverter.hxx"
45 #include "MWAWGraphicListener.hxx"
46 #include "MWAWGraphicShape.hxx"
47 #include "MWAWGraphicStyle.hxx"
48 #include "MWAWHeader.hxx"
49 #include "MWAWParagraph.hxx"
50 #include "MWAWPictBitmap.hxx"
51 #include "MWAWPictData.hxx"
52 #include "MWAWPrinter.hxx"
53 #include "MWAWPosition.hxx"
54 #include "MWAWRSRCParser.hxx"
55 #include "MWAWSubDocument.hxx"
56
57 #include "MacDraft5StyleManager.hxx"
58
59 #include "MacDraft5Parser.hxx"
60
61 /** Internal: the structures of a MacDraft5Parser */
62 namespace MacDraft5ParserInternal
63 {
64 //! generic class used to store shape in MWAWDraftParser
65 struct Shape {
66 //! the different shape
67 enum Type { Basic, Bitmap, Group, Text, QuotationSurface, Unknown };
68
69 //! constructor
70 Shape()
71 : m_type(Unknown)
72 , m_fileType(0)
73 , m_box()
74 , m_origin()
75 , m_style()
76 , m_shape()
77 , m_otherStyleList()
78 , m_otherShapeList()
79 , m_isLine(false)
80 , m_id(-1)
81 , m_parentId(-1)
82 , m_modifierId(-1)
83 , m_nameId(-1)
84 , m_posToFontMap()
85 , m_paragraph()
86 , m_textEntry()
87 , m_childList()
88 , m_bitmapIdList()
89 , m_bitmapDimensionList()
90 , m_isSent(false)
91 {
92 }
93
94 //! return the shape bdbox
95 MWAWBox2f getBdBox() const
96 {
97 return m_type==Basic ? m_shape.getBdBox() : m_box;
98 }
99 //! translate a shape
100 void translate(MWAWVec2f const &dir)
101 {
102 if (m_type==Basic)
103 m_shape.translate(dir);
104 m_box=MWAWBox2f(m_box[0]+dir, m_box[1]+dir);
105 m_origin=m_origin+dir;
106 }
107 //! transform a shape
108 void transform(float rotate, bool flipX, MWAWVec2f const &center)
109 {
110 if (rotate<0 || rotate>0) {
111 if (m_type==Basic) {
112 m_shape=m_shape.rotate(rotate, center);
113 m_box=m_shape.getBdBox();
114 }
115 else if (m_type!=Bitmap) {
116 m_style.m_rotate+=rotate;
117 float angle=rotate*float(M_PI/180.);
118 m_box=rotateBox(m_box, angle, center);
119 MWAWVec2f decal=center-MWAWVec2f(std::cos(angle)*center[0]-std::sin(angle)*center[1],
120 std::sin(angle)*center[0]+std::cos(angle)*center[1]);
121 m_origin=MWAWVec2f(std::cos(angle)*m_origin[0]-std::sin(angle)*m_origin[1],
122 std::sin(angle)*m_origin[0]+std::cos(angle)*m_origin[1])+decal;
123 }
124 }
125 if (flipX) {
126 if (m_type==Basic) {
127 m_shape.scale(MWAWVec2f(-1,1));
128 m_shape.translate(MWAWVec2f(2*center[0],0));
129 }
130 m_style.m_flip[0]=!m_style.m_flip[0];
131 m_box=MWAWBox2f(MWAWVec2f(2*center[0]-m_box[1][0],m_box[0][1]), MWAWVec2f(2*center[0]-m_box[0][0],m_box[1][1]));
132 m_origin=MWAWVec2f(2*center[0]-m_origin[0],m_origin[1]);
133 }
134 }
135 //! returns the rotation of a box
136 static MWAWBox2f rotateBox(MWAWBox2f const &box, float angle, MWAWVec2f const &center)
137 {
138 MWAWVec2f decal=center-MWAWVec2f(std::cos(angle)*center[0]-std::sin(angle)*center[1],
139 std::sin(angle)*center[0]+std::cos(angle)*center[1]);
140 MWAWBox2f fBox;
141 for (int i=0; i < 4; ++i) {
142 MWAWVec2f pt=MWAWVec2f(box[i%2][0],box[i/2][1]);
143 pt = MWAWVec2f(std::cos(angle)*pt[0]-std::sin(angle)*pt[1],
144 std::sin(angle)*pt[0]+std::cos(angle)*pt[1])+decal;
145 if (i==0) fBox=MWAWBox2f(pt,pt);
146 else fBox=fBox.getUnion(MWAWBox2f(pt,pt));
147 }
148
149 return fBox;
150 }
151
152 //! the graphic type
153 Type m_type;
154 //! the file type
155 int m_fileType;
156 //! the shape bdbox
157 MWAWBox2f m_box;
158 //! the shape origin
159 MWAWVec2f m_origin;
160 //! the graphic style
161 MWAWGraphicStyle m_style;
162 //! the graphic shape ( for basic geometric form )
163 MWAWGraphicShape m_shape;
164 //! the other graphic style ( for complex basic geometric form )
165 std::vector<MWAWGraphicStyle> m_otherStyleList;
166 //! other graphic shapes ( for complex basic geometric form )
167 std::vector<MWAWGraphicShape> m_otherShapeList;
168 //! flag to know if the shape is a line
169 bool m_isLine;
170 //! the shape id
171 long m_id;
172 //! the parent id
173 long m_parentId;
174 //! the modifier id
175 long m_modifierId;
176 //! the name id
177 long m_nameId;
178 //! the font ( for a text box)
179 std::map<long,MWAWFont> m_posToFontMap;
180 //! the paragraph ( for a text box)
181 MWAWParagraph m_paragraph;
182 //! the textbox entry (main text)
183 MWAWEntry m_textEntry;
184 //! the child list id ( for a group )
185 std::vector<int> m_childList;
186 //! the list of bitmap id ( for a bitmap)
187 std::vector<int> m_bitmapIdList;
188 //! the list of bitmap dimension ( for a bitmap)
189 std::vector<MWAWBox2i> m_bitmapDimensionList;
190 //! a flag used to know if the object is sent to the listener or not
191 mutable bool m_isSent;
192 };
193
194 //! Internal and low level: a class used to store layout definition of a MacDraf5Parser
195 struct Layout {
196 //! constructor
197 explicit Layout(int id)
198 : m_id(id)
199 , m_entry()
200 , m_N(0)
201 , m_objectId(0)
202 , m_name("")
203 , m_shapeList()
204 , m_rootList()
205 , m_idToShapePosMap()
206 , m_extra("")
207 {
208 }
209 //! returns true if the layout contains no shape
210 bool isEmpty() const
211 {
212 return m_shapeList.empty();
213 }
214 //! returns a child corresponding to an id
215 std::shared_ptr<Shape> findShape(long id, bool normallyExist=true) const
216 {
217 if (!id) return std::shared_ptr<Shape>();
218 if (m_idToShapePosMap.find(id)==m_idToShapePosMap.end()) {
219 if (normallyExist) {
220 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::find shape: can not find shape %lx\n", static_cast<unsigned long>(id)));
221 }
222 return std::shared_ptr<Shape>();
223 }
224 return m_shapeList[m_idToShapePosMap.find(id)->second];
225 }
226 //! try to check/update the parent relations are compatible with group childs, no loop exist, ...
227 void updateRelations();
228 //! operator<<
229 friend std::ostream &operator<<(std::ostream &o, Layout const &lay)
230 {
231 o << lay.m_name.cstr() << ",";
232 o << std::hex << lay.m_entry.begin() << "<->" << lay.m_entry.end() << std::dec << "[" << lay.m_N << "],";
233 o << lay.m_extra;
234 return o;
235 }
236 //! the layout id
237 int m_id;
238 //! the layout position in the data fork
239 MWAWEntry m_entry;
240 //! the number of elements
241 int m_N;
242 //! the object number
243 int m_objectId;
244 //! the layout name
245 librevenge::RVNGString m_name;
246 //! the shapes list
247 std::vector<std::shared_ptr<Shape> > m_shapeList;
248 //! the root position list
249 std::vector<size_t> m_rootList;
250 //! a map id to position in shapeList
251 std::map<long, size_t> m_idToShapePosMap;
252 //! extra data
253 std::string m_extra;
254 };
255
256 void Layout::updateRelations()
257 {
258 // first check that all id are filled are that there are no duplicated id
259 std::stack<size_t> badPosStack;
260 for (size_t i=0; i<m_shapeList.size(); ++i) {
261 if (!m_shapeList[i]) continue;
262 long id=m_shapeList[i]->m_id;
263 if (!id)
264 badPosStack.push(i);
265 else if (m_idToShapePosMap.find(id)==m_idToShapePosMap.end())
266 m_idToShapePosMap[id]=i;
267 else
268 badPosStack.push(i);
269 }
270 if (!badPosStack.empty()) {
271 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::updateRelations: find some bad id\n"));
272 long newId= m_idToShapePosMap.empty() ? 1000 : m_idToShapePosMap.rbegin()->first;
273 while (!badPosStack.empty()) {
274 size_t pos=badPosStack.top();
275 badPosStack.pop();
276 m_shapeList[pos]->m_id=++newId;
277 m_idToShapePosMap[newId]=pos;
278 }
279 }
280 // create the parent list and the root list
281 std::map<long, long> idToParentMap;
282 m_rootList.clear();
283 size_t numShapes=0;
284 for (size_t i=0; i<m_shapeList.size(); ++i) {
285 if (!m_shapeList[i]) continue;
286 ++numShapes;
287 if (!m_shapeList[i]->m_parentId) {
288 m_rootList.push_back(i);
289 continue;
290 }
291 idToParentMap[m_shapeList[i]->m_id]=m_shapeList[i]->m_parentId;
292 }
293 // now check if all group child is correct and remove bad child
294 for (auto const &shape : m_shapeList) {
295 if (!shape) continue;
296 long id=shape->m_id;
297 for (auto &childId : shape->m_childList) {
298 if (idToParentMap.find(childId)!=idToParentMap.end() &&
299 idToParentMap.find(childId)->second==id)
300 continue;
301 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::updateRelations: %lx is not a child of %lx\n", static_cast<unsigned long>(childId), static_cast<unsigned long>(id)));
302 childId=0;
303 }
304 }
305 // check for loop
306 std::set<size_t> seens;
307 std::stack<size_t> toCheck;
308 for (auto id : m_rootList) toCheck.push(id);
309
310 while (true) {
311 size_t posToCheck=0; // to make clang happy
312 if (!toCheck.empty()) {
313 posToCheck=toCheck.top();
314 toCheck.pop();
315 }
316 else if (seens.size()==numShapes)
317 break;
318 else {
319 bool ok=false;
320 for (size_t i=0; i<m_shapeList.size(); ++i) {
321 if (!m_shapeList[i] || seens.find(i)!=seens.end())
322 continue;
323 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::updateRelations: find unexpected root %d\n", static_cast<int>(i)));
324 posToCheck=i;
325 m_rootList.push_back(i);
326 m_shapeList[i]->m_parentId=0;
327 ok=true;
328 break;
329 }
330 if (!ok)
331 break;
332 }
333 if (seens.find(posToCheck)!=seens.end()) {
334 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::updateRelations: oops, %d is already seens\n", static_cast<int>(posToCheck)));
335 continue;
336 }
337 seens.insert(posToCheck);
338 if (!m_shapeList[posToCheck]) {
339 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::updateRelations: oops, can not find shape %d\n", static_cast<int>(posToCheck)));
340 continue;
341 }
342 Shape &shape=*m_shapeList[posToCheck];
343 for (auto &id : shape.m_childList) {
344 if (id==0) continue;
345 if (m_idToShapePosMap.find(id)==m_idToShapePosMap.end() ||
346 seens.find(m_idToShapePosMap.find(id)->second)!=seens.end()) {
347 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::Layout::updateRelations: find loop for child %lx\n", static_cast<unsigned long>(id)));
348 id=0;
349 continue;
350 }
351 toCheck.push(m_idToShapePosMap.find(id)->second);
352 }
353 }
354 }
355
356 //! Internal and low level: a image of a library used in MacDraf5Parser
357 struct Image {
358 //! constructor
359 Image()
360 : m_id(0)
361 , m_name("")
362 , m_extra("")
363 {
364 }
365 //! operator<<
366 friend std::ostream &operator<<(std::ostream &o, Image const &im)
367 {
368 o << im.m_name.cstr() << ",";
369 o << std::hex << im.m_id << std::dec << ",";
370 o << im.m_extra;
371 return o;
372 }
373
374 //! the first shape id ( in general a group )
375 long m_id;
376 //! the image name
377 librevenge::RVNGString m_name;
378 //! extra data
379 std::string m_extra;
380 };
381
382 ////////////////////////////////////////
383 //! Internal: the state of a MacDraft5Parser
384 struct State {
385 //! constructor
386 State()
387 : m_version(0)
388 , m_isLibrary(false)
389 , m_origin(0,0)
390 , m_layoutList()
391 , m_imageList()
392 {
393 }
394 //! the file version
395 int m_version;
396 //! flag to know if we read a library
397 bool m_isLibrary;
398 //! the origin of the picture
399 MWAWVec2f m_origin;
400 //! the layer list
401 std::vector<std::shared_ptr<Layout> > m_layoutList;
402 //! the image list
403 std::vector<std::shared_ptr<Image> > m_imageList;
404 };
405
406 ////////////////////////////////////////
407 //! Internal: the subdocument of a MacDraft5Parser
408 class SubDocument final : public MWAWSubDocument
409 {
410 public:
411 SubDocument(MacDraft5Parser &pars, MWAWInputStreamPtr const &input, int layoutId, long zoneId)
412 : MWAWSubDocument(&pars, input, MWAWEntry())
413 , m_layoutId(layoutId)
414 , m_id(zoneId)
415 {
416 }
417
418 //! destructor
419 ~SubDocument() final {}
420
421 //! operator!=
422 bool operator!=(MWAWSubDocument const &doc) const final
423 {
424 if (MWAWSubDocument::operator!=(doc)) return true;
425 auto const *sDoc = dynamic_cast<SubDocument const *>(&doc);
426 if (!sDoc) return true;
427 if (m_id != sDoc->m_id) return true;
428 if (m_layoutId != sDoc->m_layoutId) return true;
429 return false;
430 }
431
432 //! the parser function
433 void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
434
435 protected:
436 //! the layout id
437 int m_layoutId;
438 //! the subdocument id
439 long m_id;
440 private:
441 SubDocument(SubDocument const &orig) = delete;
442 SubDocument &operator=(SubDocument const &orig) = delete;
443 };
444
445 void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType)
446 {
447 if (!listener || !listener->canWriteText()) {
448 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::SubDocument::parse: no listener\n"));
449 return;
450 }
451 auto *parser=dynamic_cast<MacDraft5Parser *>(m_parser);
452 if (!parser) {
453 MWAW_DEBUG_MSG(("MacDraft5ParserInternal::SubDocument::parse: no parser\n"));
454 return;
455 }
456 long pos = m_input->tell();
457 parser->sendText(m_layoutId, m_id);
458 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
459 }
460
461 }
462
463 ////////////////////////////////////////////////////////////
464 // constructor/destructor, ...
465 ////////////////////////////////////////////////////////////
466 MacDraft5Parser::MacDraft5Parser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
467 : MWAWGraphicParser(input, rsrcParser, header)
468 , m_styleManager()
469 , m_state()
470 {
471 init();
472 }
473
474 MacDraft5Parser::~MacDraft5Parser()
475 {
476 }
477
478 void MacDraft5Parser::init()
479 {
480 resetGraphicListener();
481 setAsciiName("main-1");
482
483 m_state.reset(new MacDraft5ParserInternal::State);
484 m_styleManager.reset(new MacDraft5StyleManager(*this));
485
486 getPageSpan().setMargins(0.1);
487 }
488
489 ////////////////////////////////////////////////////////////
490 // the parser
491 ////////////////////////////////////////////////////////////
492 void MacDraft5Parser::parse(librevenge::RVNGDrawingInterface *docInterface)
493 {
494 if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException());
495 bool ok = false;
496 try {
497 // create the asciiFile
498 ascii().setStream(getInput());
499 ascii().open(asciiName());
500 checkHeader(nullptr);
501 ok = createZones();
502 if (ok) {
503 createDocument(docInterface);
504
505 if (!m_state->m_imageList.empty()) {
506 MWAWListenerPtr listener=getGraphicListener();
507 for (size_t i=0; i<m_state->m_imageList.size(); ++i) {
508 if (i && listener)
509 listener->insertBreak(MWAWListener::PageBreak);
510 if (m_state->m_imageList[i])
511 send(*m_state->m_imageList[i]);
512 }
513 }
514 else {
515 for (auto const &layout : m_state->m_layoutList) {
516 if (layout)
517 send(*layout);
518 }
519 }
520 }
521 ascii().reset();
522 }
523 catch (...) {
524 MWAW_DEBUG_MSG(("MacDraft5Parser::parse: exception catched when parsing\n"));
525 ok = false;
526 }
527
528 resetGraphicListener();
529 if (!ok) throw(libmwaw::ParseException());
530 }
531
532 ////////////////////////////////////////////////////////////
533 // create the document
534 ////////////////////////////////////////////////////////////
535 void MacDraft5Parser::createDocument(librevenge::RVNGDrawingInterface *documentInterface)
536 {
537 if (!documentInterface) return;
538 if (getGraphicListener()) {
539 MWAW_DEBUG_MSG(("MacDraft5Parser::createDocument: listener already exist\n"));
540 return;
541 }
542
543 // create the page list
544 MWAWPageSpan ps(getPageSpan());
545 ps.setPageSpan(1);
546 std::vector<MWAWPageSpan> pageList;
547 if (m_state->m_imageList.empty())
548 pageList.push_back(ps);
549 else {
550 for (auto const &image : m_state->m_imageList) {
551 MWAWPageSpan page(ps);
552 if (image)
553 page.setPageName(image->m_name);
554 pageList.push_back(page);
555 }
556 }
557 MWAWGraphicListenerPtr listen(new MWAWGraphicListener(*getParserState(), pageList, documentInterface));
558 setGraphicListener(listen);
559 listen->startDocument();
560 }
561
562 ////////////////////////////////////////////////////////////
563 //
564 // Intermediate level
565 //
566 ////////////////////////////////////////////////////////////
567 bool MacDraft5Parser::createZones()
568 {
569 MWAWInputStreamPtr input = getInput();
570 if ((m_state->m_isLibrary && !readLibraryHeader()) ||
571 (!m_state->m_isLibrary && !readDocHeader()))
572 return false;
573 long pos=input->tell();
574 m_styleManager->readResources();
575 m_styleManager->readBitmapZones();
576
577 long dataEnd=m_styleManager->getEndDataPosition();
578 if (dataEnd>0)
579 input->pushLimit(dataEnd);
580 input->seek(pos, librevenge::RVNG_SEEK_SET);
581 long lastPosSeen=pos;
582 if (m_state->m_layoutList.empty()) {
583 if (!m_state->m_isLibrary) {
584 MWAW_DEBUG_MSG(("MacDraft5Parser::createZones: the layout is empty, try to continue\n"));
585 }
586
587 while (!input->isEnd()) {
588 pos=input->tell();
589 std::shared_ptr<MacDraft5ParserInternal::Layout> layout(new MacDraft5ParserInternal::Layout(static_cast<int>(m_state->m_layoutList.size())));
590 layout->m_entry.setBegin(pos);
591 if (dataEnd>0)
592 layout->m_entry.setEnd(dataEnd);
593 else
594 layout->m_entry.setEnd(input->size());
595 if (!readLayout(*layout))
596 break;
597 m_state->m_layoutList.push_back(layout);
598 lastPosSeen=pos=input->tell();
599 if (input->isEnd())
600 break;
601 // check if there is another layout
602 long newN=static_cast<int>(input->readULong(4));
603 if (newN<=0 || pos+newN*10>layout->m_entry.end() ||
604 (!m_state->m_isLibrary && pos+130>=layout->m_entry.end()))
605 break;
606 input->seek(-4, librevenge::RVNG_SEEK_CUR);
607 }
608 }
609 else {
610 for (auto const &layout : m_state->m_layoutList) {
611 if (!layout || !layout->m_entry.valid())
612 continue;
613 if (layout->m_entry.end()>lastPosSeen)
614 lastPosSeen=layout->m_entry.end();
615 readLayout(*layout);
616 }
617 }
618 input->seek(lastPosSeen, librevenge::RVNG_SEEK_SET);
619 if (!m_state->m_isLibrary)
620 readDocFooter();
621 else
622 readLibraryFooter();
623
624
625 if (input->isEnd()) {
626 if (dataEnd>0)
627 input->popLimit();
628 return true;
629 }
630
631 MWAW_DEBUG_MSG(("MacDraft5Parser::createZones: find some extra zone\n"));
632 ascii().addPos(input->tell());
633 ascii().addNote("Entries(Extra):###");
634 if (dataEnd>0)
635 input->popLimit();
636
637 if (!m_state->m_imageList.empty())
638 return true;
639 // ok, check that we have read some shape
640 for (auto const &layout : m_state->m_layoutList) {
641 if (layout && !layout->isEmpty())
642 return true;
643 }
644 return false;
645 }
646
647 ////////////////////////////////////////////////////////////
648 // read the header
649 ////////////////////////////////////////////////////////////
650 bool MacDraft5Parser::checkHeader(MWAWHeader *header, bool strict)
651 {
652 *m_state = MacDraft5ParserInternal::State();
653 MWAWInputStreamPtr input = getInput();
654 if (!input || !input->hasDataFork() || !input->checkPosition(0x100))
655 return false;
656
657 libmwaw::DebugStream f;
658 f << "FileHeader:";
659 input->seek(0, librevenge::RVNG_SEEK_SET);
660 for (int i=0; i<3; ++i) {
661 auto val=static_cast<int>(input->readULong(2));
662 int const expected[3]= {0x4d44, 0x4443, 0x3230};
663 if (val==expected[i]) continue;
664 m_state->m_isLibrary=true;
665 f << "f" << i << "=" << std::hex << val << std::dec << ",";
666 }
667 if (input->readULong(2)!=6 || !readPrintInfo())
668 return false;
669 if (strict && m_state->m_isLibrary) {
670 bool ok=false;
671 MWAWRSRCParserPtr rsrcParser = getRSRCParser();
672 if (rsrcParser) {
673 auto const &entryMap = rsrcParser->getEntriesMap();
674 auto it=entryMap.find("vers");
675 while (it!=entryMap.end() && it->first=="vers") {
676 MWAWRSRCParser::Version vers;
677 if (rsrcParser->parseVers(it++->second, vers) &&
678 vers.m_string.compare(0,8,"MacDraft")==0) {
679 ok=true;
680 break;
681 }
682 }
683 }
684 if (!ok) {
685 // normally only ok for v5 file, so v4 library without rsrc file will not be read...
686 long pos=input->tell();
687 input->seek(-8, librevenge::RVNG_SEEK_END);
688 std::string name("");
689 for (int i=0; i<8; ++i) name+=char(input->readULong(1));
690 if (name!="RBALRPH ") return false;
691 input->seek(pos, librevenge::RVNG_SEEK_SET);
692 }
693 }
694 int const vers=4;
695 ascii().addPos(0);
696 ascii().addNote(f.str().c_str());
697 setVersion(vers);
698 m_state->m_version=vers;
699 if (header)
700 header->reset(MWAWDocument::MWAW_T_MACDRAFT, vers, MWAWDocument::MWAW_K_DRAW);
701
702 return true;
703 }
704
705 ////////////////////////////////////////////////////////////
706 // try to read the document header zone
707 ////////////////////////////////////////////////////////////
708 bool MacDraft5Parser::readDocHeader()
709 {
710 MWAWInputStreamPtr input = getInput();
711 long pos=input->tell();
712 long endPos=pos+114+6*28;
713 if (!input->checkPosition(endPos)) {
714 MWAW_DEBUG_MSG(("MacDraft5Parser::readDocHeader: file seems too short\n"));
715 return false;
716 }
717 libmwaw::DebugStream f;
718 f << "Entries(DocHeader):";
719 int dim[4];
720 for (auto &d : dim) d=static_cast<int>(input->readLong(2));
721 // checkme
722 m_state->m_origin=MWAWVec2f(float(dim[1]), float(dim[0]));
723 f << "windows[dim]=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
724 int val;
725 for (int i=0; i<3; ++i) { // f0=0|-1|2e60, f1=0|b, f2=16|3b|86, f3=1|2, f4=1|2
726 val=static_cast<int>(input->readLong(2));
727 if (val) f << "f" << i << "=" << val << ",";
728 }
729 int nPages[2];
730 for (auto &n : nPages) n=static_cast<int>(input->readLong(2));
731 if (nPages[0]>0 && nPages[0]<20 && nPages[1]>0 && nPages[1]<20) {
732 if (nPages[1]!=1)
733 getPageSpan().setFormWidth(nPages[1]*getPageSpan().getFormWidth());
734 if (nPages[0]!=1)
735 getPageSpan().setFormLength(nPages[0]*getPageSpan().getFormLength());
736 }
737 else {
738 MWAW_DEBUG_MSG(("MacDraft5Parser::readDocHeader: the number of pages seems bad\n"));
739 f << "###";
740 }
741 if (MWAWVec2i(nPages[1],nPages[0])!=MWAWVec2i(1,1))
742 f << "numPages=" << MWAWVec2i(nPages[1],nPages[0]) << ",";
743 for (int i=0; i<2; ++i) { // fl0=0|4, fl1=0|1|4
744 val=static_cast<int>(input->readLong(1));
745 if (val) f << "fl" << i << "=" << val << ",";
746 }
747 for (int i=0; i<7; ++i) { // f5=0|2|3, f6=0|1, f7=1, f8=f9=1c|48 (res?), f10=6-10, f11=2|3
748 val=static_cast<int>(input->readLong(2));
749 if (val) f << "f" << i+5 << "=" << val << ",";
750 }
751 ascii().addPos(pos);
752 ascii().addNote(f.str().c_str());
753 for (int i=0; i<2; ++i) {
754 pos=input->tell();
755 f.str("");
756 f << "DocHeader-A" << i << ":"; // first dim in inch?, second metric?
757 val=static_cast<int>(input->readLong(2)); // 0|1
758 if (val!=i) f << "#id=" << val << ",";
759 f << "dim=[";
760 for (int j=0; j<5; ++j) f << float(input->readLong(4))/65536.f << ",";
761 f << "],";
762 for (int j=0; j<4; ++j) {
763 val=static_cast<int>(input->readLong(2));
764 int const expected[4]= {0,100,0,100};
765 if (val!=expected[j]) f << "f" << j << "=" << val << ",";
766 }
767 f << "dim2=[";
768 for (int j=0; j<3; ++j) f << float(input->readLong(4))/65536.f << ",";
769 f << "],";
770 ascii().addPos(pos);
771 ascii().addNote(f.str().c_str());
772 input->seek(pos+42, librevenge::RVNG_SEEK_SET);
773 }
774 for (int i=0; i<6; ++i) {
775 pos=input->tell();
776 f.str("");
777 f << "DocHeader-B" << i << ":";
778 ascii().addPos(pos);
779 ascii().addNote(f.str().c_str());
780 input->seek(pos+28, librevenge::RVNG_SEEK_SET);
781 }
782 pos=input->tell();
783 f.str("");
784 f << "DocHeader-C0:";
785 for (int i=0; i<2; ++i) {
786 float fVal=float(input->readLong(4))/65536.f;
787 if (fVal<0 || fVal>0)
788 f << "d" << i << "=" << fVal << ",";
789 }
790 for (int i=0; i<4; ++i) { // f1=f2=0|1
791 val=static_cast<int>(input->readLong(2));
792 int const expected[4]= {0x1e, 0, 0, 1};
793 if (val!=expected[i]) f << "f" << i << "=" << val << ",";
794 }
795 for (int i=0; i<4; ++i) { // fl0=0|2, fl2=0|80
796 val=static_cast<int>(input->readULong(1));
797 int const expected[4]= {2, 1, 0, 0};
798 if (val!=expected[i]) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
799 }
800 for (int i=0; i<5; ++i) { // f4=2|1f, f5=0|1|15|7d1 fId?, f6=b|c fSz?, f7=0|fc
801 val=static_cast<int>(input->readLong(2));
802 int const expected[5]= {0x2, 0, 12, 0,0};
803 if (val!=expected[i]) f << "f" << i+4 << "=" << val << ",";
804 }
805 for (int i=0; i<4; ++i) { // fl5=1|2, fl6=0|2f, fl7=0|3c
806 val=static_cast<int>(input->readULong(1));
807 int const expected[4]= {0xfd, 1, 0, 0};
808 if (val!=expected[i]) f << "fl" << i+4 << "=" << std::hex << val << std::dec << ",";
809 }
810 for (int i=0; i<4; ++i) { // f9=0|11,f10=0|1
811 val=static_cast<int>(input->readLong(2));
812 int const expected[4]= {0,0,1,1};
813 if (val!=expected[i]) f << "f" << i+9 << "=" << val << ",";
814 }
815 float fVal=float(input->readLong(4))/65536.f; // ~9
816 if (fVal<0 || fVal>0)
817 f << "d3=" << fVal << ",";
818 val=static_cast<int>(input->readLong(2)); // 3|e|d
819 if (val) f << "f13=" << val << ",";
820 for (int i=0; i<2; ++i) { // fl8=1, fl9=0|1
821 val=static_cast<int>(input->readULong(1));
822 if (val) f << "fl" << i+8 << "=" << std::hex << val << std::dec << ",";
823 }
824 ascii().addPos(pos);
825 ascii().addNote(f.str().c_str());
826
827 pos=input->tell();
828 f.str("");
829 f << "DocHeader-C1:";
830 val=static_cast<int>(input->readLong(2)); // 0|1
831 if (val) f << "f0=" << val << ",";
832 int coord[2];
833 for (auto &c : coord) c=static_cast<int>(input->readLong(2));
834 if (coord[0]||coord[1]) f << "dim=" << MWAWVec2i(coord[1],coord[0]) << ",";
835 for (int i=0; i<4; ++i) { // always 0
836 val=static_cast<int>(input->readULong(2));
837 if (val) f << "f" << i+1 << "=" << val << ",";
838 }
839 for (int i=0; i<4; ++i) { // fl0=1, fl1=0|1, fl2=0|1
840 val=static_cast<int>(input->readULong(1));
841 if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
842 }
843 for (int i=0; i<3; ++i) { // f6=0|6e, f7=1
844 val=static_cast<int>(input->readULong(2));
845 if (val) f << "f" << i+5 << "=" << val << ",";
846 }
847 for (int i=0; i<2; ++i) { // fl4=0|1|60|82,fl5=0|68|6e
848 val=static_cast<int>(input->readULong(1));
849 if (val) f << "fl" << i+4 << "=" << std::hex << val << std::dec << ",";
850 }
851 f << "dim1=" << float(input->readLong(4))/65536.f << ","; // 7|19
852 for (int i=0; i<2; ++i) {
853 val=static_cast<int>(input->readULong(1));
854 static int const expected[2]= {2,1};
855 if (val!=expected[i])
856 f << "fl" << i+6 << "=" << std::hex << val << std::dec << ",";
857 }
858 for (int i=0; i<2; ++i) // 7,7|19,19
859 f << "dim" << i+2 << "=" << float(input->readLong(4))/65536.f << ",";
860 for (int i=0; i<2; ++i) { // fl9=0|ea|3c
861 val=static_cast<int>(input->readULong(1));
862 static int const expected[2]= {2,0};
863 if (val!=expected[i])
864 f << "fl" << i+8 << "=" << std::hex << val << std::dec << ",";
865 }
866
867 ascii().addPos(pos);
868 ascii().addNote(f.str().c_str());
869 input->seek(pos+42, librevenge::RVNG_SEEK_SET);
870 return true;
871 }
872
873 bool MacDraft5Parser::readDocFooter()
874 {
875 MWAWInputStreamPtr input = getInput();
876 if (input->isEnd())
877 return false;
878 long pos=input->tell();
879 long endPos=pos+128;
880 if (!input->checkPosition(endPos)) {
881 input->seek(pos,librevenge::RVNG_SEEK_SET);
882 return false;
883 }
884
885 for (int i=0; i<4; ++i) {
886 pos=input->tell();
887 libmwaw::DebugStream f;
888 if (i==0)
889 f << "Entries(DocFooter):";
890 else
891 f << "DocFooter-" << i << ":";
892 auto sSz=static_cast<int>(input->readULong(1));
893 if (sSz>31) {
894 MWAW_DEBUG_MSG(("MacDraft5Parser::readDocFooter: string size seems bad\n"));
895 f << "#sSz=" << sSz << ",";
896 sSz=0;
897 }
898 std::string name("");
899 for (int c=0; c<sSz; ++c) name+=char(input->readULong(1));
900 f << name << ",";
901 ascii().addPos(pos);
902 ascii().addNote(f.str().c_str());
903 input->seek(pos+32,librevenge::RVNG_SEEK_SET);
904 }
905 return true;
906 }
907
908 bool MacDraft5Parser::readLibraryHeader()
909 {
910 MWAWInputStreamPtr input = getInput();
911 long pos=input->tell();
912 long endPos=pos+22;
913 if (!input->checkPosition(endPos+4)) {
914 MWAW_DEBUG_MSG(("MacDraft5Parser::readLibraryHeader: file seems too short\n"));
915 return false;
916 }
917 libmwaw::DebugStream f;
918 f << "Entries(LibHeader):";
919 int val;
920 for (int i=0; i<2; ++i) { // f0=-1|0|4, f1=0|e4
921 val=static_cast<int>(input->readLong(2));
922 if (val) f << "f" << i << "=" << val << ",";
923 }
924 int dim[4];
925 for (auto &d : dim) d=static_cast<int>(input->readLong(2));
926 f << "dim=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
927 for (int i=0; i<5; ++i) { // f2=5|6, f3=f2+2
928 val=static_cast<int>(input->readLong(2));
929 if (val) f << "f" << i+2 << "=" << val << ",";
930 }
931 ascii().addPos(pos);
932 ascii().addNote(f.str().c_str());
933
934 input->seek(endPos, librevenge::RVNG_SEEK_SET);
935
936 return true;
937 }
938
939 bool MacDraft5Parser::readLibraryFooter()
940 {
941 MWAWInputStreamPtr input = getInput();
942 if (input->isEnd())
943 return false;
944 long pos=input->tell();
945 auto fSz=long(input->readULong(4));
946 long endPos=pos+4+fSz;
947 if (!fSz || !input->checkPosition(endPos)|| fSz<30 || (fSz%34)<30 || (fSz%34)>31) {
948 input->seek(pos,librevenge::RVNG_SEEK_SET);
949 MWAW_DEBUG_MSG(("MacDraft5Parser::readLibraryFooter: the zone size seems bad\n"));
950 return false;
951 }
952
953 libmwaw::DebugStream f;
954 f << "Entries(LibFooter):";
955 int val;
956 for (int i=0; i<3; ++i) { // always 0
957 val=static_cast<int>(input->readLong(2));
958 if (val) f << "f" << i << "=" << val << ",";
959 }
960 auto N=static_cast<int>(input->readULong(2));
961 if (30+34*N!=fSz && 31+34*N!=fSz) {
962 MWAW_DEBUG_MSG(("MacDraft5Parser::readLibFooter:N seems bad\n"));
963 f << "##N=" << N << ",";
964 if (30+34*N>fSz)
965 N=int((fSz-30)/34);
966 }
967 val=static_cast<int>(input->readLong(2)); // always 0 ?
968 if (val) f << "f3=" << val << ",";
969 val=static_cast<int>(input->readLong(2)); // always c
970 if (val!=34) f << "#fSz=" << val << ",";
971 long dataSz=input->readLong(4);
972 if (dataSz && dataSz!=34*N) {
973 MWAW_DEBUG_MSG(("MacDraft5Parser::readLibFooter:dataSize seems bad\n"));
974 f << "##dataSz=" << dataSz << ",";
975 }
976 for (int i=0; i<7; ++i) {
977 val=static_cast<int>(input->readLong(2));
978 static int const expected[]= {0,0x22,0,4,0,0,0};
979 if (val!=expected[i]) f << "f" << i+4 << "=" << val << ",";
980 }
981
982 ascii().addPos(pos);
983 ascii().addNote(f.str().c_str());
984
985 for (long i=0; i<N; ++i) {
986 pos=input->tell();
987 f.str("");
988 std::shared_ptr<MacDraft5ParserInternal::Image> image(new MacDraft5ParserInternal::Image);
989 image->m_id=long(input->readULong(4));
990 auto sSz=static_cast<int>(input->readULong(1));
991 if (sSz>25) {
992 MWAW_DEBUG_MSG(("MacDraft5Parser::readLibFooter:stringSize seems bad\n"));
993 f << "##sSz=" << sSz << ",";
994 sSz=0;
995 }
996 for (int c=0; c<sSz; ++c) {
997 auto ch=char(input->readULong(1));
998 if (ch==0) break;
999 int unicode= getParserState()->m_fontConverter->unicode(3, static_cast<unsigned char>(ch));
1000 if (unicode==-1)
1001 image->m_name.append(ch);
1002 else
1003 libmwaw::appendUnicode(static_cast<uint32_t>(unicode), image->m_name);
1004 }
1005 input->seek(pos+30, librevenge::RVNG_SEEK_SET);
1006 val=static_cast<int>(input->readLong(2)); // constant in a zone: 6|d
1007 if (val) f << "f0=" << val << ",";
1008 val=static_cast<int>(input->readLong(2)); // 0|1
1009 if (val) f << "f1=" << val << ",";
1010 image->m_extra=f.str();
1011 f.str("");
1012 f << "LibFooter-" << i << ":" << *image;
1013 m_state->m_imageList.push_back(image);
1014 ascii().addPos(pos);
1015 ascii().addNote(f.str().c_str());
1016 }
1017 input->seek(endPos,librevenge::RVNG_SEEK_SET);
1018 return true;
1019 }
1020
1021 ////////////////////////////////////////////////////////////
1022 // read an object
1023 ////////////////////////////////////////////////////////////
1024 bool MacDraft5Parser::readObject(MacDraft5ParserInternal::Layout &layout)
1025 {
1026 MWAWInputStreamPtr input = getInput();
1027 if (input->isEnd())
1028 return false;
1029 long pos=input->tell();
1030 auto fSz=long(input->readULong(2));
1031 if (fSz>=0x25 && (fSz%6)==1) {
1032 input->seek(pos,librevenge::RVNG_SEEK_SET);
1033 MacDraft5ParserInternal::Shape falseShape;
1034 if (readModifier(falseShape)) {
1035 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unexpected modifier\n"));
1036 return true;
1037 }
1038 }
1039 long endPos=pos+2+fSz;
1040 if (fSz<0x2e || !input->checkPosition(endPos)) {
1041 input->seek(pos,librevenge::RVNG_SEEK_SET);
1042 return false;
1043 }
1044 input->seek(pos+2,librevenge::RVNG_SEEK_SET);
1045 libmwaw::DebugStream f;
1046 f << "Entries(Object):";
1047 std::shared_ptr<MacDraft5ParserInternal::Shape> shape(new MacDraft5ParserInternal::Shape);
1048 MWAWGraphicStyle &style=shape->m_style;
1049 shape->m_id=long(input->readULong(4));
1050 if (shape->m_id<=1) {
1051 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: id seems bad\n"));
1052 f << "###";
1053 }
1054 f << "id=" << std::hex << shape->m_id << std::dec << ",";
1055 auto val=static_cast<int>(input->readULong(1)); // 0|80
1056 if (val) f << "type[h]=" << std::hex << val << std::dec << ",";
1057 shape->m_fileType=static_cast<int>(input->readULong(1)); //[0-6][0-b]
1058 switch (shape->m_fileType) {
1059 case 1:
1060 f << "line[single],";
1061 break;
1062 case 3:
1063 f << "poly1,";
1064 break;
1065 case 4:
1066 f << "poly2,";
1067 break;
1068 case 0x9: // orig=center
1069 case 0xa: // orig=corner
1070 f << "rectangle,";
1071 break;
1072 case 0xb:
1073 f << "rectOval,";
1074 break;
1075 case 0x14:
1076 f << "circle,";
1077 break;
1078 case 0x15:
1079 f << "arc1,";
1080 break;
1081 case 0x16:
1082 f << "arc2,";
1083 break;
1084 case 0x17: // checkme
1085 f << "arc3,";
1086 break;
1087 case 0x18:
1088 f << "circle[cent&rad],";
1089 break;
1090 case 0x1e:
1091 f << "spline1,";
1092 break;
1093 case 0x1f:
1094 f << "spline2,";
1095 break;
1096 case 0x28:
1097 f << "textbox,";
1098 break;
1099 case 0x30:
1100 f << "bitmap,";
1101 break;
1102 case 0x33:
1103 f << "group1,";
1104 break;
1105 case 0x35:
1106 f << "group2,";
1107 break;
1108 case 0x51:
1109 f << "quotation[h],";
1110 break;
1111 case 0x52:
1112 f << "quotation[v],";
1113 break;
1114 case 0x53:
1115 f << "quotation[d],";
1116 break;
1117 case 0x54:
1118 f << "quotation[para],";
1119 break;
1120 case 0x55: // circle center
1121 f << "quotation[circleC],";
1122 break;
1123 case 0x56: // circle diameter
1124 f << "quotation[circleD],";
1125 break;
1126 case 0x57: // axis
1127 f << "quotation[axis],";
1128 break;
1129 case 0x58: // angle
1130 f << "quotation[angle],";
1131 break;
1132 case 0x5e:
1133 f << "correspondance[quot/parent],";
1134 break;
1135 case 0x63:
1136 f << "quotation[surf],";
1137 break;
1138 case 0x64:
1139 f << "line[para],";
1140 break;
1141 case 0x65:
1142 f << "poly[para],";
1143 break;
1144 default:
1145 f << "type=" << std::hex << shape->m_fileType << std::dec << ",";
1146 }
1147 shape->m_parentId=long(input->readULong(4));
1148 if (shape->m_parentId)
1149 f << "id[parent]=" << std::hex << shape->m_parentId << std::dec << ",";
1150 int rotation = -static_cast<int>(input->readLong(2));
1151 style.m_rotate=float(rotation);
1152 if (rotation) f << "rotate=" << rotation << ",";
1153 val=static_cast<int>(input->readLong(2)); // 0|2|13b3|2222
1154 if (val) f << "f0=" << val << ",";
1155 shape->m_modifierId=long(input->readULong(4));
1156 if (shape->m_modifierId)
1157 f << "modifier[id]=" << std::hex << shape->m_modifierId << std::dec << ",";
1158 val=static_cast<int>(input->readULong(1));
1159 if (val) // alway 0?
1160 f << "f1=" << val << ",";
1161 val=static_cast<int>(input->readULong(1));
1162 if (val!=1) {
1163 f << "width[line]=" << val << ",";
1164 style.m_lineWidth=float(val);
1165 }
1166 val=static_cast<int>(input->readULong(1));
1167 if (val!=2) // alway 2?
1168 f << "f2=" << val << ",";
1169 auto lineType=static_cast<int>(input->readULong(1));
1170 // FIXME: storeme...
1171 auto dashId=static_cast<int>(input->readULong(1));
1172 if (dashId&0x80) {
1173 switch ((dashId>>4)&0x7) {
1174 case 0:
1175 f << "hairline,";
1176 style.m_lineWidth=0.02f;
1177 break;
1178 case 1:
1179 f << "width[line]=" << 0.5 << ",";
1180 style.m_lineWidth=0.5f;
1181 break;
1182 case 2:
1183 f << "width[line]=" << 0.75 << ",";
1184 style.m_lineWidth=0.75f;
1185 break;
1186 default:
1187 f <<"###width[line]=" << ((dashId>>4)&0x7) << ",";
1188 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown line width\n"));
1189 break;
1190 }
1191 }
1192 else if (dashId&0x70) {
1193 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown dash[high]\n"));
1194 f << "##dash[high]=" << (dashId>>4) << ",";
1195 }
1196 auto arrowId=static_cast<int>(input->readULong(1)); // low|end
1197
1198 auto colId=static_cast<int>(input->readULong(2)); // 0-78
1199 f << m_styleManager->updateLineStyle(lineType, colId, (dashId&0xf), style);
1200
1201 float coord[2];
1202 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1203 shape->m_origin=MWAWVec2f(coord[1],coord[0]);
1204 f << "pos=" << shape->m_origin << ",";
1205
1206 val=static_cast<int>(input->readULong(2)); // [02][0134][04][01]
1207 if (val&1) f << "selected,";
1208 if (val&8) f << "lock,";
1209 val &= 0xFFF6;
1210 if (val) f << "fl1=" << std::hex << val << std::dec << ",";
1211 shape->m_nameId=long(input->readULong(4));
1212 if (shape->m_nameId)
1213 f << "id[name]=" << std::hex << shape->m_nameId << std::dec << ",";
1214 switch (shape->m_fileType) {
1215 case 1: { // line
1216 if (fSz!=0x3e && fSz!=0x50) {
1217 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown line size\n"));
1218 f << "##fSz,";
1219 break;
1220 }
1221 val=static_cast<int>(input->readLong(2));
1222 if (val) f << "angle[def]=" << val << ",";
1223 MWAWVec2f listPts[2];
1224 for (int i=0; i<2; ++i) {
1225 val=static_cast<int>(input->readULong(1));
1226 if (val!=1-i) f << "g" << i << "=" << val << ",";
1227 val=static_cast<int>(input->readULong(1));
1228 if (val!=0x81) f << "fl" << 2+i << "=" << std::hex << val << std::dec << ",";
1229 float pt[2];
1230 for (auto &p : pt) p=float(input->readLong(4))/65536.f;
1231 listPts[i]=MWAWVec2f(pt[1],pt[0]);
1232 f << "pt" << i << "=" << listPts[i] << ",";
1233 }
1234 f << m_styleManager->updateArrows(arrowId&0xf, (arrowId>>4)&0xf, style);
1235 shape->m_type=MacDraft5ParserInternal::Shape::Basic;
1236 shape->m_shape=MWAWGraphicShape::line(listPts[0], listPts[1]);
1237 shape->m_isLine=true;
1238 rotation=0;
1239 if (fSz==0x3e) break;
1240 for (int i=0; i<9; ++i) { // always 0
1241 val=static_cast<int>(input->readLong(2));
1242 if (val) f << "g" << i+2 << "=" << val << ",";
1243 }
1244 break;
1245 }
1246 case 3:
1247 case 4: // poly
1248 case 0x9: // rect1
1249 case 0xa: // rect2
1250 case 0xb: // rectOval : rect + corner
1251 case 0x14: // circle
1252 case 0x15: // arc1
1253 case 0x16: // arc2
1254 case 0x17: // arc3
1255 case 0x18: // circle[radius,oval]
1256 case 0x1e: // spline1
1257 case 0x1f: { // spline2
1258 int expectedSz=0;
1259 size_t nbPts=0;
1260 int nodeHeaderSz=0;
1261 int expectedNodeType=0;
1262 switch (shape->m_fileType) {
1263 case 3:
1264 case 4:
1265 if (fSz<48) {
1266 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown size\n"));
1267 f << "##fSz,";
1268 break;
1269 }
1270 expectedSz=-1;
1271 nodeHeaderSz=2;
1272 expectedNodeType=0x81;
1273 break;
1274 case 9:
1275 case 0xa:
1276 expectedSz=0x54;
1277 nbPts=4;
1278 nodeHeaderSz=2;
1279 expectedNodeType=0x81;
1280 break;
1281 case 0xb:
1282 expectedSz=0x60;
1283 nbPts=4;
1284 nodeHeaderSz=2;
1285 expectedNodeType=0x80;
1286 break;
1287 case 0x14:
1288 expectedSz=0x5a;
1289 nbPts=3;
1290 nodeHeaderSz=2;
1291 expectedNodeType=0x81;
1292 break;
1293 case 0x15:
1294 case 0x17:
1295 expectedSz=0x62;
1296 nbPts=3;
1297 nodeHeaderSz=2;
1298 expectedNodeType=0x81;
1299 break;
1300 case 0x16:
1301 expectedSz=0x66;
1302 nbPts=3;
1303 nodeHeaderSz=2;
1304 expectedNodeType=0x81;
1305 break;
1306 case 0x18:
1307 expectedSz=0x40;
1308 nbPts=2;
1309 break;
1310 case 0x1e:
1311 case 0x1f:
1312 if (fSz<58) {
1313 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown size\n"));
1314 f << "##fSz,";
1315 break;
1316 }
1317 expectedSz=-1;
1318 break;
1319 default:
1320 break;
1321 }
1322 if (expectedSz>=0 && fSz!=expectedSz) {
1323 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown size\n"));
1324 f << "##fSz,";
1325 break;
1326 }
1327 shape->m_type=MacDraft5ParserInternal::Shape::Basic;
1328 val=static_cast<int>(input->readULong(1));
1329 if (val) // alway 2?
1330 f << "f3=" << val << ",";
1331 auto surfType=static_cast<int>(input->readULong(1));
1332 colId=static_cast<int>(input->readULong(2)); // 0-78
1333 f << m_styleManager->updateSurfaceStyle(surfType, colId, style);
1334 if (shape->m_fileType==3 || shape->m_fileType==4) {
1335 val=static_cast<int>(input->readULong(1));
1336 if (val==1) f << "closed,";
1337 else if (val) f << "##orig[pos]=" << val << ",";
1338 val=static_cast<int>(input->readULong(1)); // always 0
1339 if (val) f << "g0=" << val << ",";
1340 nbPts=size_t(input->readULong(2));
1341 if (fSz<48+10*static_cast<int>(nbPts)) {
1342 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: the number of points seems bad\n"));
1343 f << "##N=" << nbPts << ",";
1344 break;
1345 }
1346 }
1347 else if (shape->m_fileType==0x14) {
1348 val=static_cast<int>(input->readULong(1)); // 0-2
1349 if (val) f << "orig[pos]=" << val << ",";
1350 val=static_cast<int>(input->readULong(1)); // always 0
1351 if (val) f << "g0=" << val << ",";
1352 val=static_cast<int>(input->readULong(2));
1353 if (val!=0x181) f << "g1=" << std::hex << val << std::dec << ",";
1354 float pt[3];
1355 for (auto &p : pt) p=float(input->readLong(4))/65536.f;
1356 MWAWVec2f center(pt[1],pt[0]), radius(pt[2],pt[2]);
1357 f << "center=" << center << ",radius=" << pt[2] << ",";
1358 shape->m_shape=MWAWGraphicShape::circle(MWAWBox2f(center-radius, center+radius));
1359 shape->m_origin=center;
1360 }
1361 else if (shape->m_fileType==0x15||shape->m_fileType==0x16||shape->m_fileType==0x17) {
1362 val=static_cast<int>(input->readULong(1)); // 0-2
1363 if (val) f << "orig[pos]=" << val << ",";
1364 val=static_cast<int>(input->readULong(1)); // always 0
1365 if (val) f << "g0=" << val << ",";
1366 val=static_cast<int>(input->readULong(2));
1367 if (val!=0x181) f << "g1=" << std::hex << val << std::dec << ",";
1368 int numData=shape->m_fileType==0x16 ? 4 : 3;
1369 float pt[4];
1370 for (int i=0; i<numData; ++i) pt[i]=float(input->readLong(4))/65536.f;
1371 MWAWVec2f center(pt[1],pt[0]), radius(pt[2],numData==4 ? pt[3] : pt[2]);
1372 f << "center=" << center << ",radius=" << radius << ",";
1373 float fileAngle[2];
1374 for (auto &angle : fileAngle) angle=float(input->readLong(4))/65536.f;
1375 f << "angle=" << fileAngle[0] << "x" << fileAngle[1] << ",";
1376 float angle[2] = { 90-fileAngle[0], 90-fileAngle[1] };
1377 if (angle[1]>360) {
1378 int numLoop=int(angle[1]/360)-1;
1379 angle[0]-=float(numLoop*360);
1380 angle[1]-=float(numLoop*360);
1381 while (angle[1] > 360) {
1382 angle[0]-=360;
1383 angle[1]-=360;
1384 }
1385 }
1386 if (angle[0] < -360) {
1387 int numLoop=int(angle[0]/360)+1;
1388 angle[0]-=float(numLoop*360);
1389 angle[1]-=float(numLoop*360);
1390 while (angle[0] < -360) {
1391 angle[0]+=360;
1392 angle[1]+=360;
1393 }
1394 }
1395 MWAWBox2f box=MWAWBox2f(center-radius, center+radius);
1396 // we must compute the real bd box
1397 float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 };
1398 int limitAngle[2];
1399 for (int i = 0; i < 2; i++)
1400 limitAngle[i] = (angle[i] < 0) ? int(angle[i]/90)-1 : int(angle[i]/90);
1401 for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; bord++) {
1402 float ang = (bord == limitAngle[0]) ? float(angle[0]) :
1403 (bord == limitAngle[1]+1) ? float(angle[1]) : float(90 * bord);
1404 ang *= float(M_PI/180.);
1405 float const actVal[2] = { radius[0] *std::cos(ang), -radius[1] *std::sin(ang)};
1406 if (actVal[0] < minVal[0]) minVal[0] = actVal[0];
1407 else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0];
1408 if (actVal[1] < minVal[1]) minVal[1] = actVal[1];
1409 else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1];
1410 }
1411 MWAWBox2f realBox(MWAWVec2f(center[0]+minVal[0],center[1]+minVal[1]),
1412 MWAWVec2f(center[0]+maxVal[0],center[1]+maxVal[1]));
1413 rotation=0;
1414 // we must compute the real bd box
1415 if (!style.hasSurface())
1416 shape->m_shape=MWAWGraphicShape::arc(realBox, box, MWAWVec2f(angle[0],angle[1]));
1417 else
1418 shape->m_shape=MWAWGraphicShape::pie(realBox, box, MWAWVec2f(angle[0],angle[1]));
1419 }
1420 else if (shape->m_fileType==0x18) {
1421 val=static_cast<int>(input->readULong(1)); // 0-1
1422 if (val) f << "orig[pos]=" << val << ",";
1423 val=static_cast<int>(input->readULong(1)); // always 0
1424 if (val) f << "g1=" << val << ",";
1425 val=static_cast<int>(input->readULong(2)); // always 0
1426 if (val) f << "g2=" << val << ",";
1427 }
1428 else if (shape->m_fileType==0x1e || shape->m_fileType==0x1f) {
1429 val=static_cast<int>(input->readULong(1));
1430 if (val==1) f << "closed,";
1431 else if (val) f << "##orig[pos]=" << val << ",";
1432 val=static_cast<int>(input->readULong(1)); // always 0
1433 if (val) f << "g0=" << val << ",";
1434 nbPts=size_t(input->readULong(2));
1435 if (fSz<48+30*static_cast<int>(nbPts)+10) {
1436 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: the number of points seems bad\n"));
1437 f << "##N=" << nbPts << ",";
1438 break;
1439 }
1440
1441 f << "points=[";
1442 std::vector<MWAWGraphicShape::PathData> path;
1443 MWAWVec2f prevPoint[2];
1444 for (size_t i=0; i<=nbPts; ++i) {
1445 MWAWVec2f points[3];
1446 int nCoord=(i==nbPts) ? 1 : 3;
1447 for (int j=0; j<nCoord; ++j) {
1448 libmwaw::DebugStream f2;
1449 val=static_cast<int>(input->readULong(1));
1450 if (val!=((i||j)?0:1)) f2 << "h0=" << val << ",";
1451 val=static_cast<int>(input->readULong(1));
1452 if (val!=(j==0 ? 0x81 : 0)) f2 << "fl=" << std::hex << val << std::dec << ",";
1453 for (auto &c : coord) c=float(input->readLong(4))/65536;
1454 points[j]=MWAWVec2f(coord[1],coord[0]);
1455 f << points[j];
1456 if (!f2.str().empty()) f << "[" << f2.str() << "]";
1457 if (j+1==nCoord) f << ",";
1458 else f << ":";
1459 }
1460 // checkme
1461 char pType = i==0 ? 'M' : 'C';
1462 path.push_back(MWAWGraphicShape::PathData(pType, points[0], (i==0) ? points[0] : prevPoint[0],
1463 (i==0) ? points[0] : prevPoint[1]));
1464 prevPoint[0]=points[1];
1465 prevPoint[1]=points[2];
1466 }
1467 f << "],";
1468 shape->m_shape.m_type=MWAWGraphicShape::Path;
1469 shape->m_shape.m_path=path;
1470 rotation=0;
1471 break;
1472 }
1473 std::vector<MWAWVec2f> listPts;
1474 listPts.resize(nbPts);
1475 f << "pts=[";
1476 for (size_t i=0; i<nbPts; ++i) {
1477 libmwaw::DebugStream f2;
1478 if (nodeHeaderSz==2) {
1479 val=static_cast<int>(input->readULong(1));
1480 if (val!=(i?0:1)) f2 << "h0=" << val << ",";
1481 val=static_cast<int>(input->readULong(1));
1482 if (val!=expectedNodeType) f2 << "fl=" << std::hex << val << std::dec << ",";
1483 }
1484 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1485 listPts[i]=MWAWVec2f(coord[1],coord[0]);
1486 f << listPts[i];
1487 if (!f2.str().empty())
1488 f << ":[" << f2.str() << "],";
1489 else
1490 f << ",";
1491 }
1492 f << "],";
1493 MWAWVec2f corner(0,0);
1494 if (shape->m_fileType==0xb) {
1495 val=static_cast<int>(input->readULong(1)); // 1-3
1496 if (val!=1) f << "orig[pos]=" << val << ",";
1497 val=static_cast<int>(input->readULong(1)); // always 0
1498 if (val) f << "h4=" << val << ",";
1499 val=static_cast<int>(input->readULong(2)); // always 4
1500 if (val!=4) f << "h5=" << val << ",";
1501 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1502 corner=MWAWVec2f(coord[1]/2.f,coord[0]/2.f);
1503 f << "corner=" << corner << ",";
1504 }
1505 switch (shape->m_fileType) {
1506 case 0x9:
1507 case 0xa:
1508 if (!rotation) {
1509 shape->m_shape=MWAWGraphicShape::rectangle(MWAWBox2f(listPts[0], listPts[2]), corner);
1510 break;
1511 }
1512 MWAW_FALLTHROUGH;
1513 case 0x3:
1514 case 0x4: {
1515 rotation=0;
1516 shape->m_shape.m_type = MWAWGraphicShape::Polygon;
1517 std::vector<MWAWVec2f> &vertices=shape->m_shape.m_vertices;
1518 MWAWBox2f box;
1519 for (size_t i=0; i<nbPts; ++i) {
1520 vertices.push_back(listPts[i]);
1521 if (i==0)
1522 box=MWAWBox2f(listPts[i], listPts[i]);
1523 else
1524 box=box.getUnion(MWAWBox2f(listPts[i], listPts[i]));
1525 }
1526 shape->m_shape.m_bdBox=shape->m_shape.m_formBox=box;
1527 break;
1528 }
1529 case 0xb:
1530 shape->m_shape=MWAWGraphicShape::rectangle(MWAWBox2f(listPts[0], listPts[2]), corner);
1531 if (rotation) shape->m_origin=0.5f*(listPts[0]+listPts[2]);
1532 break;
1533 case 0x14: // already done
1534 case 0x15:
1535 case 0x16:
1536 case 0x17:
1537 break;
1538 case 0x18:
1539 listPts[1]=MWAWVec2f(listPts[1][1],listPts[1][0]);
1540 shape->m_shape=MWAWGraphicShape::circle(MWAWBox2f(listPts[0]-listPts[1], listPts[0]+listPts[1]));
1541 break;
1542 default: {
1543 static bool first=true;
1544 f << "###";
1545 if (first) {
1546 first=false;
1547 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: oops can not store a shape\n"));
1548 }
1549 break;
1550 }
1551 }
1552 break;
1553 }
1554 case 0x28: { // text
1555 if (fSz!=0x64) {
1556 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown text size\n"));
1557 f << "##fSz,";
1558 break;
1559 }
1560 val=static_cast<int>(input->readULong(1));
1561 if (val) // alway 0?
1562 f << "f3=" << val << ",";
1563 auto surfType=static_cast<int>(input->readULong(1));
1564 colId=static_cast<int>(input->readULong(2)); // 0-78
1565 f << m_styleManager->updateSurfaceStyle(surfType, colId, style);
1566
1567 for (int i=0; i<2; ++i) { // g0=0|1
1568 val=static_cast<int>(input->readULong(1));
1569 if (val) f << "g" << i << "=" << std::hex << val << std::dec << ",";
1570 }
1571 f << "ids?=["; // two big number, unsure
1572 for (int i=0; i<2; ++i) f << std::hex << input->readULong(4) << std::dec << ",";
1573 f << "],";
1574 val=static_cast<int>(input->readLong(2));// 0|-1
1575 if (val) f << "g2=" << val << ",";
1576 val=static_cast<int>(input->readLong(1));
1577 switch (val) {
1578 case -3:
1579 break;
1580 case -2:
1581 shape->m_paragraph.setInterline(1.5, librevenge::RVNG_PERCENT);
1582 f << "interline=150%,";
1583 break;
1584 case -1:
1585 shape->m_paragraph.setInterline(2., librevenge::RVNG_PERCENT);
1586 f << "interline=200%,";
1587 break;
1588 default:
1589 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown interline\n"));
1590 f << "##interline=" << val << ",";
1591 break;
1592 }
1593 for (int i=0; i<2; ++i) {
1594 val=static_cast<int>(input->readULong(1)); // always 0
1595 if (val) f << "g" << i+3 << "=" << std::hex << val << std::dec << ",";
1596 }
1597 val=static_cast<int>(input->readLong(1));
1598 switch (val) {
1599 case 0: // left
1600 break;
1601 case 1:
1602 shape->m_paragraph.m_justify = MWAWParagraph::JustificationCenter;
1603 f << "align=center,";
1604 break;
1605 case -1:
1606 shape->m_paragraph.m_justify = MWAWParagraph::JustificationRight;
1607 f << "align=right,";
1608 break;
1609 default:
1610 MWAW_DEBUG_MSG(("MacDrawParser::readText: find unknown align\n"));
1611 f << "#align=" << val << ",";
1612 }
1613 MWAWVec2f listPts[4];
1614 f << "pts=[";
1615 int n=0;
1616 for (auto &point : listPts) {
1617 libmwaw::DebugStream f2;
1618 val=static_cast<int>(input->readULong(1));
1619 if (val!=(n++?0:1)) f2 << "h0=" << val << ",";
1620 val=static_cast<int>(input->readULong(1));
1621 if (val) f2 << "fl=" << std::hex << val << std::dec << ",";
1622 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1623 point=MWAWVec2f(coord[1],coord[0]);
1624 f << point;
1625 if (!f2.str().empty())
1626 f << ":[" << f2.str() << "],";
1627 else
1628 f << ",";
1629 }
1630 f << "],";
1631 shape->m_type=MacDraft5ParserInternal::Shape::Text;
1632 if (rotation) {
1633 MWAWBox2f bdbox;
1634 MWAWVec2f center=0.5f*(listPts[0]+listPts[2]);
1635 for (int i=0; i<4; ++i) {
1636 MWAWVec2f point=libmwaw::rotatePointAroundCenter(listPts[i], center, float(-rotation));
1637 if (i==0)
1638 bdbox=MWAWBox2f(point,point);
1639 else
1640 bdbox=bdbox.getUnion(MWAWBox2f(point,point));
1641 }
1642 shape->m_box=bdbox;
1643 rotation=0;
1644 }
1645 else
1646 shape->m_box=MWAWBox2f(listPts[0],listPts[2]);
1647 break;
1648 }
1649 case 0x30: { // bitmap
1650 if (fSz!=0x5e) {
1651 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown bitmap size\n"));
1652 f << "##fSz,";
1653 break;
1654 }
1655 for (int i=0; i<2; ++i) { // always 0
1656 val=static_cast<int>(input->readLong(2));
1657 if (val) f << "g" << i << "=" << val << ",";
1658 }
1659 MWAWVec2f listPts[4];
1660 f << "pts=[";
1661 int n=0;
1662 for (auto &point : listPts) {
1663 libmwaw::DebugStream f2;
1664 val=static_cast<int>(input->readULong(1));
1665 if (val!=(n++?0:1)) f2 << "h0=" << val << ",";
1666 val=static_cast<int>(input->readULong(1));
1667 if (val) f2 << "fl=" << std::hex << val << std::dec << ",";
1668 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1669 point=MWAWVec2f(coord[1],coord[0]);
1670 f << point;
1671 if (!f2.str().empty())
1672 f << ":[" << f2.str() << "],";
1673 else
1674 f << ",";
1675 }
1676 f << "],";
1677 int dim[4];
1678 for (auto &d : dim) d=static_cast<int>(input->readLong(2));
1679 shape->m_bitmapDimensionList.push_back(MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])));
1680 f << "dim=" << shape->m_bitmapDimensionList.back() << ",";
1681 shape->m_bitmapIdList.push_back(static_cast<int>(input->readULong(2)));
1682 f << "id[bitmap]=" << shape->m_bitmapIdList.back() << ",";
1683 shape->m_type=MacDraft5ParserInternal::Shape::Bitmap;
1684 if (rotation) {
1685 MWAWBox2f bdbox;
1686 MWAWVec2f center=0.5f*(listPts[0]+listPts[2]);
1687 for (int i=0; i<4; ++i) {
1688 MWAWVec2f point=libmwaw::rotatePointAroundCenter(listPts[i], center, float(-rotation));
1689 if (i==0)
1690 bdbox=MWAWBox2f(point,point);
1691 else
1692 bdbox=bdbox.getUnion(MWAWBox2f(point,point));
1693 }
1694 shape->m_box=bdbox;
1695 }
1696 else
1697 shape->m_box=MWAWBox2f(listPts[0],listPts[2]);
1698 break;
1699 }
1700 case 0x33:
1701 case 0x35: { // group
1702 int headerSize=shape->m_fileType==0x33 ? 0x2a : 60;
1703 if (fSz<headerSize) {
1704 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown group size\n"));
1705 f << "##fSz,";
1706 break;
1707 }
1708 if (shape->m_fileType==0x35) {
1709 val=static_cast<int>(input->readULong(1));
1710 if (val) // alway 0?
1711 f << "f3=" << val << ",";
1712 auto surfType=static_cast<int>(input->readULong(1));
1713 colId=static_cast<int>(input->readULong(2)); // 0-78
1714 f << m_styleManager->updateSurfaceStyle(surfType, colId, style);
1715 static bool first=true;
1716 if (first && style.hasSurface()) {
1717 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: creating surface from group is not implemented\n"));
1718 first=false;
1719 f << "#surf[group],";
1720 }
1721 for (int i=0; i<7; ++i) { // g4=0|100, g5=N
1722 val=static_cast<int>(input->readLong(2));
1723 if (val) f << "g" << i << "=" << val << ",";
1724 }
1725 }
1726 auto nChild=static_cast<int>(input->readULong(2));
1727 if (fSz<headerSize+4*nChild) {
1728 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown group size\n"));
1729 f << "##fSz,";
1730 break;
1731 }
1732 shape->m_type=MacDraft5ParserInternal::Shape::Group;
1733 f << "child[id]=[";
1734 for (int i=0; i<nChild; ++i) {
1735 val=static_cast<int>(input->readULong(4));
1736 shape->m_childList.push_back(val);
1737 f << std::hex << val << std::dec << ",";
1738 }
1739 f << "],";
1740 break;
1741 }
1742 case 0x51: // quotation
1743 case 0x52:
1744 case 0x53:
1745 case 0x54:
1746 case 0x55:
1747 case 0x56:
1748 case 0x57:
1749 case 0x58: {
1750 long expectedSize=(shape->m_fileType==0x57) ? 0x106 : (shape->m_fileType==0x58) ? 0x17a : 0x176;
1751 if (fSz!=expectedSize) {
1752 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown quotation size\n"));
1753 f << "##fSz,";
1754 break;
1755 }
1756 ascii().addPos(pos);
1757 ascii().addNote(f.str().c_str());
1758 input->seek(pos+52, librevenge::RVNG_SEEK_SET);
1759
1760 pos=input->tell();
1761 f.str("");
1762 f << "Object-A:quotation,";
1763 ascii().addPos(pos);
1764 ascii().addNote(f.str().c_str());
1765 input->seek(pos+82, librevenge::RVNG_SEEK_SET);
1766
1767 pos=input->tell();
1768 f.str("");
1769 f << "Object-B:quotation,";
1770 f << "unkn=[";
1771 for (size_t i=0; i<8; ++i) {
1772 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1773 f << MWAWVec2f(coord[1],coord[0]) << ",";
1774 }
1775 f << "],";
1776 ascii().addPos(pos);
1777 ascii().addNote(f.str().c_str());
1778 input->seek(pos+64, librevenge::RVNG_SEEK_SET);
1779
1780 pos=input->tell();
1781 f.str("");
1782 f << "Object-C:quotation,";
1783 auto sSz=static_cast<int>(input->readULong(1));
1784 if (sSz>31) {
1785 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown string size\n"));
1786 f << "##sSz=" << sSz << ",";
1787 break;
1788 }
1789 std::string text("");
1790 for (int i=0; i<sSz; ++i) text+=char(input->readULong(1));
1791 f << text << ",";
1792 input->seek(pos+32, librevenge::RVNG_SEEK_SET);
1793 for (int i=0; i<8; ++i) { // always 0
1794 val=static_cast<int>(input->readLong(2));
1795 if (val)
1796 f << "f" << i << "=" << val << ",";
1797 }
1798 ascii().addPos(pos);
1799 ascii().addNote(f.str().c_str());
1800 input->seek(pos+48, librevenge::RVNG_SEEK_SET);
1801
1802 pos=input->tell();
1803 f.str("");
1804 f << "Object-D:quotation,";
1805 MWAWVec2f listPts[13];
1806 f << "pts=[";
1807 int numPts=shape->m_fileType==0x57 ? 1 : shape->m_fileType==0x58 ? 11 : 13;
1808 for (int i=0; i<numPts; ++i) {
1809 libmwaw::DebugStream f2;
1810 val=static_cast<int>(input->readULong(1));
1811 if (val!=(i?0:1)) f2 << "h0=" << val << ",";
1812 val=static_cast<int>(input->readULong(1));
1813 if (val!=0x81) f2 << "fl=" << std::hex << val << std::dec << ",";
1814 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1815 listPts[i]=MWAWVec2f(coord[1],coord[0]);
1816 f << listPts[i];
1817 if (!f2.str().empty())
1818 f << ":[" << f2.str() << "],";
1819 else
1820 f << ",";
1821 }
1822 f << "],";
1823 if (shape->m_fileType==0x57) { // cross quotation, no text
1824 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1825 MWAWVec2f axis(coord[1],coord[0]);
1826 f << "axis,dim=" << axis << ",";
1827 rotation=0;
1828
1829 shape->m_type=MacDraft5ParserInternal::Shape::Basic;
1830 style=MWAWGraphicStyle();
1831 style.m_lineDashWidth.resize(4); // normally, must depend on the axis size
1832 style.m_lineDashWidth[0]=3;
1833 style.m_lineDashWidth[1]=2;
1834 style.m_lineDashWidth[2]=20;
1835 style.m_lineDashWidth[3]=0;
1836 shape->m_shape=MWAWGraphicShape::line(shape->m_origin-axis,shape->m_origin+axis);
1837 shape->m_otherStyleList.push_back(style);
1838 shape->m_otherShapeList.push_back(MWAWGraphicShape::line(shape->m_origin-MWAWVec2f(-coord[0],coord[1]),shape->m_origin+MWAWVec2f(-coord[0],coord[1])));
1839 break;
1840 }
1841 else if (shape->m_fileType==0x58) {
1842 f << "angle,unkn=[";
1843 for (int i=0; i<3; ++i) f << float(input->readLong(4))/65536.f << ",";
1844 f << "],";
1845 // then 0004002d0000000311050000
1846 }
1847 else {
1848 shape->m_type=MacDraft5ParserInternal::Shape::Basic;
1849 style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain();
1850 style.m_lineColor=MWAWColor(125,125,125);
1851 style.m_lineWidth=1;
1852 int const firstPoint=(shape->m_fileType==0x55 || shape->m_fileType==0x56) ? 7 : 0;
1853 shape->m_shape=MWAWGraphicShape::measure(listPts[firstPoint],listPts[firstPoint+1]);
1854 rotation=0;
1855 break;
1856 }
1857 static bool first=true;
1858 if (first) {
1859 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find some angle quotations, unimplemented\n"));
1860 first=false;
1861 }
1862 break;
1863 }
1864 case 0x5e: { // correspondance between surface quotation and parent
1865 if (fSz!=0x3e) {
1866 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown correspondance quotation size\n"));
1867 f << "##fSz,";
1868 break;
1869 }
1870 for (int i=0; i<7; ++i) { // g0=1, g1=4b40, g2=dc00
1871 val=static_cast<int>(input->readULong(2));
1872 if (val) f << "g" << i << "=" << std::hex << val << std::dec << ",";
1873 }
1874 auto pId=long(input->readULong(4));
1875 f << "parent[id]=" << std::hex << pId << std::dec << ",";
1876 if (shape->m_parentId==0) shape->m_parentId=pId;
1877 shape->m_type=MacDraft5ParserInternal::Shape::Group;
1878 shape->m_childList.push_back(static_cast<int>(input->readULong(4)));
1879 f << "child[id]=" << std::hex << shape->m_childList.back() << std::dec << ",";
1880 break;
1881 }
1882 case 0x63: { // surface quotation
1883 if (fSz!=0x62) {
1884 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown surface quotation size\n"));
1885 f << "##fSz,";
1886 break;
1887 }
1888 val=static_cast<int>(input->readULong(1));
1889 if (val) // alway 0?
1890 f << "f3=" << val << ",";
1891 auto surfType=static_cast<int>(input->readULong(1));
1892 colId=static_cast<int>(input->readULong(2)); // 0-78
1893 f << m_styleManager->updateSurfaceStyle(surfType, colId, style);
1894 for (int i=0; i<4; ++i) { // g0=7, g2=c, g3=0: font definition ?
1895 val=static_cast<int>(input->readLong(2));
1896 if (val) f << "g" << i << "=" << val << ",";
1897 }
1898 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1899 f << "pos1=" << MWAWVec2f(coord[1],coord[0]) << ",";;
1900 for (int i=0; i<5; ++i) { // g6=4
1901 val=static_cast<int>(input->readLong(2));
1902 if (val) f << "g" << i+6 << "=" << val << ",";
1903 }
1904 auto pId=long(input->readULong(4));
1905 f << "parent[id]=" << std::hex << pId << std::dec << ",";
1906 if (shape->m_parentId==0) shape->m_parentId=pId;
1907 auto sSz=static_cast<int>(input->readULong(1));
1908 if (sSz>23) {
1909 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unexpected text size\n"));
1910 sSz=0;
1911 }
1912 shape->m_type=MacDraft5ParserInternal::Shape::QuotationSurface;
1913 style.m_lineWidth=0;
1914 style.m_surfaceOpacity=0;
1915 shape->m_textEntry.setBegin(input->tell());
1916 shape->m_textEntry.setLength(sSz);
1917 std::string text("");
1918 for (int i=0; i<sSz; ++i) text+=char(input->readULong(1));
1919 f << text << ",";
1920 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1921 rotation=0;
1922 break;
1923 }
1924 case 0x64: { // line para
1925 if (fSz!=0x70) {
1926 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown line[para] size\n"));
1927 f << "##fSz,";
1928 break;
1929 }
1930 val=static_cast<int>(input->readULong(1));
1931 if (val) // alway 0?
1932 f << "g0=" << val << ",";
1933 auto surfType=static_cast<int>(input->readULong(1));
1934 colId=static_cast<int>(input->readULong(2)); // 0-78
1935 f << m_styleManager->updateSurfaceStyle(surfType, colId, style);
1936
1937 for (auto &c : coord) c=float(input->readLong(4))/65536.f;
1938 f << "dim?=" << MWAWVec2f(coord[1],coord[0]) << ",";
1939 f << "points=[";
1940 std::vector<MWAWVec2f> listPts;
1941 for (size_t i=0; i<2; ++i) {
1942 for (int j=0; j<3; ++j) { // checkme: original line, line1, line2?
1943 libmwaw::DebugStream f2;
1944 val=static_cast<int>(input->readULong(1));
1945 if (val!=((i||j)?0:1)) f2 << "h0=" << val << ",";
1946 val=static_cast<int>(input->readULong(1));
1947 if (val!=(j==0 ? 0x81 : 0x90)) f2 << "fl=" << std::hex << val << std::dec << ",";
1948 for (auto &c : coord) c=float(input->readLong(4))/65536;
1949 listPts.push_back(MWAWVec2f(coord[1],coord[0]));
1950 f << listPts.back();
1951 if (!f2.str().empty()) f << "[" << f2.str() << "]";
1952 if (j+1==3) f << ",";
1953 else f << ":";
1954 }
1955 }
1956 shape->m_type=MacDraft5ParserInternal::Shape::Basic;
1957 if (style.hasSurface()) {
1958 shape->m_shape.m_type = MWAWGraphicShape::Polygon;
1959 std::vector<MWAWVec2f> &vertices=shape->m_shape.m_vertices;
1960 MWAWBox2f box;
1961 for (int i=0; i<4; ++i) {
1962 size_t const which[]= {1,4,5,2};
1963 MWAWVec2f point=listPts[which[i]];
1964 vertices.push_back(point);
1965 if (i==0)
1966 box=MWAWBox2f(point, point);
1967 else
1968 box=box.getUnion(MWAWBox2f(point, point));
1969 }
1970 shape->m_shape.m_bdBox=shape->m_shape.m_formBox=box;
1971 }
1972 else if (style.hasLine()) {
1973 shape->m_shape=MWAWGraphicShape::line(listPts[1], listPts[4]);
1974
1975 shape->m_otherStyleList.push_back(style);
1976 shape->m_otherShapeList.push_back(MWAWGraphicShape::line(listPts[2], listPts[5]));
1977 }
1978 else
1979 shape->m_shape=MWAWGraphicShape::line(listPts[1], listPts[4]);
1980 rotation=0;
1981 break;
1982 }
1983 case 0x65: { // poly para
1984 if (fSz<58) {
1985 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find unknown poly[para] size\n"));
1986 f << "##fSz,";
1987 break;
1988 }
1989 MWAWGraphicStyle surfStyle;
1990 for (int i=0; i<2; ++i) {
1991 f << "style[" << (i==1 ? "inter" : "surf") << "]=[";
1992 val=static_cast<int>(input->readULong(1));
1993 if (val) // alway 0?
1994 f << "g0=" << val << ",";
1995 auto surfType=static_cast<int>(input->readULong(1));
1996 colId=static_cast<int>(input->readULong(2)); // 0-78
1997 f << m_styleManager->updateSurfaceStyle(surfType, colId, i==1 ? style : surfStyle);
1998 f << "],";
1999 }
2000
2001 for (int i=0; i<3; ++i) { // g0=9,g1=0,g2=2|3|e
2002 val=static_cast<int>(input->readLong(2));
2003 if (val)
2004 f << "g" << i << "=" << val << ",";
2005 }
2006 bool isClosed=false;
2007 val=static_cast<int>(input->readLong(1));
2008 if (val==1) {
2009 f << "closed,";
2010 isClosed=true;
2011 }
2012 else if (val) f << "poly[type]=" << val << ",";
2013 val=static_cast<int>(input->readLong(1)); // always 0
2014 if (val) f << "g7=" << val << ",";
2015 auto nbPts=static_cast<int>(input->readULong(2));
2016 if (fSz<58+30*nbPts) {
2017 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: numbers of points of unknown poly[para] seems bad\n"));
2018 f << "##nbPts=" << nbPts << ",";
2019 break;
2020 }
2021 std::vector<MWAWVec2f> listPts[3];
2022 for (int p=0; p<3; ++p) {
2023 f << "poly" << p << "=[";
2024 for (int j=0; j<nbPts; ++j) {
2025 libmwaw::DebugStream f2;
2026 val=static_cast<int>(input->readULong(1));
2027 if (val!=((p||j)?0:1)) f2 << "h0=" << val << ",";
2028 val=static_cast<int>(input->readULong(1));
2029 if (val!=(p==0 ? 0x81 : 0x90)) f2 << "fl=" << std::hex << val << std::dec << ",";
2030 for (auto &c : coord) c=float(input->readLong(4))/65536;
2031 listPts[p].push_back(MWAWVec2f(coord[1],coord[0]));
2032 f << listPts[p].back();
2033 if (!f2.str().empty()) f << "[" << f2.str() << "]";
2034 if (j+1==nbPts) f << ",";
2035 else f << ":";
2036 }
2037 f << "],";
2038 }
2039 bool mainSet=false;
2040 shape->m_type=MacDraft5ParserInternal::Shape::Basic;
2041 MWAWGraphicStyle mainStyle=style;
2042 if (surfStyle.hasSurface()) {
2043 shape->m_shape.m_type = MWAWGraphicShape::Polygon;
2044 std::vector<MWAWVec2f> &vertices=shape->m_shape.m_vertices;
2045 MWAWBox2f box;
2046 for (size_t p=0; p<listPts[0].size(); ++p) {
2047 MWAWVec2f point=listPts[0][p];
2048 vertices.push_back(point);
2049 if (p==0)
2050 box=MWAWBox2f(point, point);
2051 else
2052 box=box.getUnion(MWAWBox2f(point, point));
2053 }
2054 shape->m_shape.m_bdBox=shape->m_shape.m_formBox=box;
2055 surfStyle.m_lineWidth=0;
2056 shape->m_style=surfStyle;
2057 mainSet=true;
2058 }
2059
2060 MWAWGraphicShape newShape;
2061 newShape.m_type = MWAWGraphicShape::Polygon;
2062 std::vector<MWAWVec2f> &vertices=newShape.m_vertices;
2063 MWAWBox2f box;
2064 for (size_t p=0; p<listPts[1].size(); ++p) {
2065 MWAWVec2f point=listPts[1][p];
2066 vertices.push_back(point);
2067 if (p==0)
2068 box=MWAWBox2f(point, point);
2069 else
2070 box=box.getUnion(MWAWBox2f(point, point));
2071 }
2072 if (isClosed && !listPts[1].empty())
2073 vertices.push_back(listPts[1][0]);
2074 if (isClosed && !listPts[2].empty())
2075 vertices.push_back(listPts[2][0]);
2076 for (size_t p=listPts[2].size(); p>0;) {
2077 MWAWVec2f point=listPts[2][--p];
2078 vertices.push_back(point);
2079 box=box.getUnion(MWAWBox2f(point, point));
2080 }
2081 newShape.m_bdBox=newShape.m_formBox=box;
2082 if (mainSet) {
2083 shape->m_otherStyleList.push_back(mainStyle);
2084 shape->m_otherShapeList.push_back(newShape);
2085 }
2086 else {
2087 shape->m_style=mainStyle;
2088 shape->m_shape=newShape;
2089 }
2090 rotation=0;
2091 break;
2092 }
2093 default:
2094 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: find some unknown data\n"));
2095 f << "#unparsed,";
2096 }
2097
2098 if (input->tell()!=pos && input->tell()!=endPos)
2099 ascii().addDelimiter(input->tell(),'|');
2100 ascii().addPos(pos);
2101 ascii().addNote(f.str().c_str());
2102 input->seek(endPos,librevenge::RVNG_SEEK_SET);
2103 ++layout.m_objectId;
2104
2105 pos=input->tell();
2106 if (shape->m_modifierId>0 && !readModifier(*shape)) {
2107 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: can not find the modifier\n"));
2108 input->seek(pos,librevenge::RVNG_SEEK_SET);
2109 }
2110
2111 pos=input->tell();
2112 if (shape->m_nameId && !readStringList()) {
2113 MWAW_DEBUG_MSG(("MacDraft5Parser::readObject: can not find name list\n"));
2114 input->seek(pos,librevenge::RVNG_SEEK_SET);
2115 }
2116 if (rotation)
2117 shape->transform(float(rotation), false, shape->m_origin);
2118 layout.m_shapeList.push_back(shape);
2119 if (shape->m_fileType!=0x28)
2120 return true;
2121 pos=input->tell();
2122 if (!readText(*shape))
2123 input->seek(pos, librevenge::RVNG_SEEK_SET);
2124 return true;
2125 }
2126
2127 bool MacDraft5Parser::readText(MacDraft5ParserInternal::Shape &shape)
2128 {
2129 MWAWInputStreamPtr input = getInput();
2130 long pos=input->tell();
2131 libmwaw::DebugStream f;
2132 f << "Entries(Text):";
2133 bool ok=input->checkPosition(pos+24);
2134 int tSz=0;
2135 if (ok) {
2136 for (int i=0; i<2; ++i) {
2137 int dim[4];
2138 for (auto &d : dim) d=static_cast<int>(input->readLong(2));
2139 f << "dim" << i << "=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
2140 }
2141 tSz=static_cast<int>(input->readULong(2));
2142 ok=(tSz<20000 && input->checkPosition(pos+24+tSz));
2143 }
2144 int nData=0;
2145 if (ok) {
2146 f << "f0=" << input->readULong(4) << ",";
2147 shape.m_textEntry.setBegin(input->tell());
2148 shape.m_textEntry.setLength(tSz);
2149 input->seek(shape.m_textEntry.end(), librevenge::RVNG_SEEK_SET);
2150 nData=static_cast<int>(input->readULong(2));
2151 }
2152 long endPos=pos+24+tSz+nData*20;
2153 if (!ok || nData>100 || !input->checkPosition(endPos)) {
2154 MWAW_DEBUG_MSG(("MacDraft5Parser::readText: can not read text\n"));
2155 input->seek(pos, librevenge::RVNG_SEEK_SET);
2156 ascii().addPos(pos);
2157 ascii().addNote("###Text");
2158 return true;
2159 }
2160 ascii().addPos(pos);
2161 ascii().addNote(f.str().c_str());
2162
2163 for (int i=0; i<nData; ++i) {
2164 pos=input->tell();
2165 f.str("");
2166 f << "Text-C" << i << ":";
2167 auto cPos=long(input->readULong(4));
2168 f << "pos=" << cPos << ",";
2169 auto val=static_cast<int>(input->readLong(2)); // c-2f
2170 if (val) f << "f0=" << val << ",";
2171 f << "height=" << input->readULong(2) << ",";
2172 MWAWFont font;
2173 font.setId(static_cast<int>(input->readULong(2)));
2174 auto flag = static_cast<int>(input->readULong(1));
2175 uint32_t flags=0;
2176 if (flag&0x1) flags |= MWAWFont::boldBit;
2177 if (flag&0x2) flags |= MWAWFont::italicBit;
2178 if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple);
2179 if (flag&0x88) f << "#fl=" << std::hex << flag << ",";
2180 font.setFlags(flags);
2181 val=static_cast<int>(input->readULong(1)); // always 0
2182 if (val) f << "f1=" << val << ",";
2183 font.setSize(float(input->readULong(2)));
2184 uint8_t col[3];
2185 for (auto &c : col) c=static_cast<uint8_t>(input->readULong(2)>>8);
2186 font.setColor(MWAWColor(col[0],col[1],col[2]));
2187 f << "font=[" << font.getDebugString(getParserState()->m_fontConverter) << "],";
2188 if (shape.m_posToFontMap.find(cPos)==shape.m_posToFontMap.end())
2189 shape.m_posToFontMap[cPos]=font;
2190 else {
2191 MWAW_DEBUG_MSG(("MacDraft5Parser::readText: pos %ld already exists\n", cPos));
2192 }
2193 ascii().addPos(pos);
2194 ascii().addNote(f.str().c_str());
2195 input->seek(pos+20, librevenge::RVNG_SEEK_SET);
2196 }
2197 return true;
2198 }
2199
2200 ////////////////////////////////////////////////////////////
2201 // read an modifier
2202 ////////////////////////////////////////////////////////////
2203 bool MacDraft5Parser::readModifier(MacDraft5ParserInternal::Shape &shape)
2204 {
2205 MWAWInputStreamPtr input = getInput();
2206 if (input->isEnd())
2207 return false;
2208 long pos=input->tell();
2209 auto fSz=long(input->readULong(2));
2210 long endPos=pos+2+fSz;
2211 if (fSz<0x25 || (fSz%6)!=1 || !input->checkPosition(endPos)) {
2212 input->seek(pos,librevenge::RVNG_SEEK_SET);
2213 return false;
2214 }
2215 libmwaw::DebugStream f;
2216 f << "Entries(Modifier):";
2217 long val;
2218 for (int i=0; i<3; ++i) { // always 0
2219 val=input->readLong(2);
2220 if (val) f << "f" << i << "=" << val << ",";
2221 }
2222 auto N=static_cast<int>(input->readLong(2));
2223 if (6*N+0x1f!=fSz) {
2224 input->seek(pos,librevenge::RVNG_SEEK_SET);
2225 return false;
2226 }
2227 for (int i=0; i<4; ++i) {
2228 val=input->readLong(4);
2229 static long const expected[4]= {6,6,6,2 };
2230 if (val!=expected[i]) f << "f" << i+3 << "=" << val << ",";
2231 }
2232 for (int i=0; i<3; ++i) { // always 0
2233 val=input->readLong(2);
2234 if (val) f << "f" << i+7 << "=" << val << ",";
2235 }
2236 for (int i=0; i<N; ++i) {
2237 auto type=static_cast<int>(input->readULong(2));
2238 auto value=long(input->readULong(4));
2239 f << "mod" << i << "=[";
2240 switch (type) {
2241 case 0:
2242 if (value==0)
2243 f << "nop";
2244 else
2245 f << "###nop=" << value << ",";
2246 break;
2247 case 102:
2248 f << "quot[child]=" << std::hex << value << std::dec << ",";
2249 shape.m_childList.push_back(int(value));
2250 break;
2251 case 501:
2252 if (value>=0 && value<=255)
2253 shape.m_style.m_surfaceOpacity=float(value)/255.f;
2254 else
2255 f << "###";
2256 f << "opacity[surf]=" << float(value)/255.f << ",";
2257 break;
2258 case 502: // checkme
2259 if (value>=0 && value<=255)
2260 shape.m_style.m_lineOpacity=float(value)/255.f;
2261 else
2262 f << "###";
2263 f << "opacity[line]=" << float(value)/255.f << ",";
2264 break;
2265 default:
2266 MWAW_DEBUG_MSG(("MacDraft5Parser::readModifier: find unknown modifier type %d\n", type));
2267 f << "###type=" << type << ",val=" << std::hex << value << std::dec << ",";
2268 }
2269 f << "],";
2270 }
2271 val=static_cast<int>(input->readULong(1)); // always 0
2272 if (val) f << "fl=" << std::hex << val << std::dec << ",";
2273 ascii().addPos(pos);
2274 ascii().addNote(f.str().c_str());
2275 input->seek(endPos,librevenge::RVNG_SEEK_SET);
2276 return true;
2277 }
2278
2279 bool MacDraft5Parser::readStringList()
2280 {
2281 MWAWInputStreamPtr input = getInput();
2282 if (input->isEnd())
2283 return false;
2284 long pos=input->tell();
2285 auto fSz=long(input->readULong(2));
2286 long endPos=pos+2+fSz;
2287 if (fSz<14 || !input->checkPosition(endPos)) {
2288 input->seek(pos,librevenge::RVNG_SEEK_SET);
2289 return false;
2290 }
2291 libmwaw::DebugStream f;
2292 f << "Entries(StringLists):";
2293 for (int i=0; i<2; ++i) { // always 1,1
2294 auto val=static_cast<int>(input->readLong(2));
2295 if (val==1)
2296 continue;
2297 if (fSz>=0x2e) {
2298 input->seek(pos,librevenge::RVNG_SEEK_SET);
2299 return false;
2300 }
2301 f << "f" << i << "=" << val << ",";
2302 }
2303 for (int i=0; i<10; ++i) { // find s0, s2, s4
2304 auto sSz=static_cast<int>(input->readULong(1));
2305 if (input->tell()+sSz>endPos) {
2306 input->seek(pos,librevenge::RVNG_SEEK_SET);
2307 return false;
2308 }
2309 if (!sSz) continue;
2310 std::string text("");
2311 for (int j=0; j<sSz; ++j) text += char(input->readULong(1));
2312 f << "s" << i << "=" << text << ",";
2313 }
2314 if (input->tell()!=endPos)
2315 ascii().addDelimiter(input->tell(),'|');
2316 ascii().addPos(pos);
2317 ascii().addNote(f.str().c_str());
2318 input->seek(endPos,librevenge::RVNG_SEEK_SET);
2319 return true;
2320 }
2321
2322 ////////////////////////////////////////////////////////////
2323 // try to read the print info zone
2324 ////////////////////////////////////////////////////////////
2325 bool MacDraft5Parser::readPrintInfo()
2326 {
2327 MWAWInputStreamPtr input = getInput();
2328 long pos=input->tell();
2329 long endPos=pos+120;
2330 if (!input->checkPosition(endPos)) {
2331 MWAW_DEBUG_MSG(("MacDraft5Parser::readPrintInfo: file seems too short\n"));
2332 return false;
2333 }
2334 libmwaw::DebugStream f;
2335 f << "Entries(PrintInfo):";
2336 libmwaw::PrinterInfo info;
2337 if (!info.read(input)) {
2338 MWAW_DEBUG_MSG(("MacDraft5Parser::readPrintInfo: can not read print info\n"));
2339 return false;
2340 }
2341 f << info;
2342 MWAWVec2i paperSize = info.paper().size();
2343 MWAWVec2i pageSize = info.page().size();
2344 if (pageSize.x() <= 0 || pageSize.y() <= 0 ||
2345 paperSize.x() <= 0 || paperSize.y() <= 0) {
2346 ascii().addPos(pos);
2347 ascii().addNote(f.str().c_str());
2348 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2349 return true;
2350 }
2351
2352 // define margin from print info
2353 MWAWVec2i lTopMargin= -1 * info.paper().pos(0);
2354 MWAWVec2i rBotMargin=info.paper().size() - info.page().size();
2355
2356 // move margin left | top
2357 int decalX = lTopMargin.x() > 14 ? lTopMargin.x()-14 : 0;
2358 int decalY = lTopMargin.y() > 14 ? lTopMargin.y()-14 : 0;
2359 lTopMargin -= MWAWVec2i(decalX, decalY);
2360 rBotMargin += MWAWVec2i(decalX, decalY);
2361
2362 // decrease right | bottom
2363 int rightMarg = rBotMargin.x() -50;
2364 if (rightMarg < 0) rightMarg=0;
2365 int botMarg = rBotMargin.y() -50;
2366 if (botMarg < 0) botMarg=0;
2367
2368 getPageSpan().setMarginTop(lTopMargin.y()/72.0);
2369 getPageSpan().setMarginBottom(botMarg/72.0);
2370 getPageSpan().setMarginLeft(lTopMargin.x()/72.0);
2371 getPageSpan().setMarginRight(rightMarg/72.0);
2372 getPageSpan().setFormLength(paperSize.y()/72.);
2373 getPageSpan().setFormWidth(paperSize.x()/72.);
2374
2375 ascii().addPos(pos);
2376 ascii().addNote(f.str().c_str());
2377 input->seek(endPos, librevenge::RVNG_SEEK_SET);
2378 return true;
2379 }
2380
2381 ////////////////////////////////////////////////////////////
2382 // layout
2383 ////////////////////////////////////////////////////////////
2384 bool MacDraft5Parser::readLayout(MacDraft5ParserInternal::Layout &layout)
2385 {
2386 MWAWEntry const &entry=layout.m_entry;
2387 MWAWInputStreamPtr input = getInput();
2388 if (!entry.valid() || !input->checkPosition(entry.begin())) {
2389 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayout: the entry seems bad\n"));
2390 return false;
2391 }
2392 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
2393 libmwaw::DebugStream f;
2394 f << "Layout[def]:";
2395 auto val=static_cast<int>(input->readULong(4));
2396 bool checkN=false;
2397 if (m_state->m_isLibrary) {
2398 layout.m_N=val;
2399 checkN=true;
2400 }
2401 else if (val!=layout.m_N) {
2402 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayout: N seems bad\n"));
2403 f << "###";
2404 if (layout.m_N==0) {
2405 layout.m_N=val;
2406 checkN=true;
2407 }
2408 }
2409 f << "N=" << val << ",";
2410 ascii().addPos(entry.begin());
2411 ascii().addNote(f.str().c_str());
2412 while (!input->isEnd()) {
2413 if (checkN && layout.m_N==layout.m_objectId) {
2414 layout.updateRelations();
2415 return true;
2416 }
2417 long pos=input->tell();
2418 if (pos>=entry.end())
2419 break;
2420 if (!readObject(layout)) {
2421 input->seek(pos, librevenge::RVNG_SEEK_SET);
2422 break;
2423 }
2424 }
2425
2426 long pos=input->tell();
2427 if (pos<entry.end()) {
2428 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayout: find some extra data\n"));
2429 ascii().addPos(input->tell());
2430 ascii().addNote("Layout[extra]:###");
2431 }
2432 layout.updateRelations();
2433 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
2434 return true;
2435 }
2436
2437 ////////////////////////////////////////////////////////////
2438 // last zone
2439 ////////////////////////////////////////////////////////////
2440 bool MacDraft5Parser::readPICT(MWAWEntry const &entry, librevenge::RVNGBinaryData &pict)
2441 {
2442 MWAWInputStreamPtr input = getInput();
2443 pict.clear();
2444 if (!input || !entry.valid() || entry.length()<0xd) {
2445 MWAW_DEBUG_MSG(("MacDraft5Parser::readPict: entry is invalid\n"));
2446 return false;
2447 }
2448
2449 libmwaw::DebugStream f;
2450 f << "Entries(RSRC" << entry.type() << ")[" << entry.id() << "]:";
2451 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
2452 input->readDataBlock(entry.length(), pict);
2453
2454 #ifdef DEBUG_WITH_FILES
2455 if (!entry.isParsed()) {
2456 ascii().skipZone(entry.begin(), entry.end()-1);
2457 libmwaw::DebugStream f2;
2458 f2 << "RSRC-" << entry.type() << "_" << entry.id() << ".pct";
2459 libmwaw::Debug::dumpFile(pict, f2.str().c_str());
2460 }
2461 #endif
2462
2463 ascii().addPos(entry.begin()-16);
2464 ascii().addNote(f.str().c_str());
2465
2466 entry.setParsed(true);
2467 return true;
2468 }
2469
2470 bool MacDraft5Parser::readViews(MWAWEntry const &entry, bool inRsrc)
2471 {
2472 if (inRsrc && !getRSRCParser()) return false;
2473 MWAWInputStreamPtr input = inRsrc ? getRSRCParser()->getInput() : getInput();
2474 if (!input || !entry.valid() || entry.length()<38 || (entry.length()%38)<30 || (entry.length()%38)>31) {
2475 MWAW_DEBUG_MSG(("MacDraft5Parser::readViews: entry is invalid\n"));
2476 return false;
2477 }
2478 entry.setParsed(true);
2479 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
2480 libmwaw::DebugFile &ascFile = inRsrc ? getRSRCParser()->ascii() : ascii();
2481 libmwaw::DebugStream f;
2482 f << "Entries(Views):";
2483 if (entry.id()!=1) {
2484 MWAW_DEBUG_MSG(("MacDraft5Parser::readViews: entry id seems odd\n"));
2485 f << "##id=" << entry.id() << ",";
2486 }
2487 int val;
2488 for (int i=0; i<3; ++i) { // always 0
2489 val=static_cast<int>(input->readLong(2));
2490 if (val) f << "f" << i << "=" << val << ",";
2491 }
2492 auto N=static_cast<int>(input->readULong(2));
2493 if (30+38*N!=entry.length() && 31+38*N!=entry.length()) {
2494 MWAW_DEBUG_MSG(("MacDraft5Parser::readViews:N seems bad\n"));
2495 f << "##N=" << N << ",";
2496 if (30+38*N>entry.length())
2497 N=int((entry.length()-30)/38);
2498 }
2499 val=static_cast<int>(input->readLong(2)); // always 0 ?
2500 if (val) f << "f3=" << val << ",";
2501 val=static_cast<int>(input->readLong(2)); // always 38
2502 if (val!=38) f << "#fSz=" << val << ",";
2503 long dataSz=input->readLong(4);
2504 if (dataSz!=38*N) {
2505 MWAW_DEBUG_MSG(("MacDraft5Parser::readViews:dataSize seems bad\n"));
2506 f << "##dataSz=" << dataSz << ",";
2507 }
2508 for (int i=0; i<7; ++i) {
2509 val=static_cast<int>(input->readLong(2));
2510 static int const expected[]= {0,0x26,0,0x1e,0,0,0};
2511 if (val!=expected[i]) f << "f" << i+4 << "=" << val << ",";
2512 }
2513
2514 ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16));
2515 ascFile.addNote(f.str().c_str());
2516
2517 for (long i=0; i<N; ++i) {
2518 long pos=input->tell();
2519 f.str("");
2520 f << "Views-" << i << ":";
2521 auto sSz=static_cast<int>(input->readULong(1));
2522 if (sSz>31) {
2523 MWAW_DEBUG_MSG(("MacDraft5Parser::readViews:stringSize seems bad\n"));
2524 f << "##sSz=" << sSz << ",";
2525 sSz=0;
2526 }
2527 std::string name("");
2528 for (int c=0; c<sSz; ++c) name += char(input->readULong(1));
2529 f << name << ",";
2530 input->seek(pos+32, librevenge::RVNG_SEEK_SET);
2531 int coord[2];
2532 for (auto &c : coord) c=static_cast<int>(input->readULong(2));
2533 f << MWAWVec2i(coord[0],coord[1]) << ",";
2534 val=static_cast<int>(input->readULong(2)); // 0 or 1
2535 if (val) f << "page=?" << val << ",";
2536 ascFile.addPos(pos);
2537 ascFile.addNote(f.str().c_str());
2538 }
2539 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
2540 return true;
2541 }
2542
2543 ////////////////////////////////////////////////////////////
2544 // PICT list
2545 ////////////////////////////////////////////////////////////
2546 bool MacDraft5Parser::readPICTList(MWAWEntry const &entry, bool inRsrc)
2547 {
2548 if (inRsrc && !getRSRCParser()) return false;
2549 MWAWInputStreamPtr input = inRsrc ? getRSRCParser()->getInput() : getInput();
2550 if (!input || !entry.valid() || entry.length()<12 || (entry.length()%12)!=0) {
2551 MWAW_DEBUG_MSG(("MacDraft5Parser::readPICTLists: entry is invalid\n"));
2552 return false;
2553 }
2554 entry.setParsed(true);
2555 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
2556 libmwaw::DebugFile &ascFile = inRsrc ? getRSRCParser()->ascii() : ascii();
2557 libmwaw::DebugStream f;
2558 f << "Entries(PICTNot):";
2559 if (entry.id()!=0) {
2560 MWAW_DEBUG_MSG(("MacDraft5Parser::readPICTLists: entry id seems odd\n"));
2561 f << "##id=" << entry.id() << ",";
2562 }
2563 auto N=int(entry.length()/12);
2564 for (long i=0; i<N; ++i) {
2565 f << "[";
2566 f << std::hex << input->readULong(4) << std::dec << ","; // big number, maybe flag
2567 auto val=static_cast<int>(input->readLong(2)); // always 0
2568 if (val)
2569 f << val << ",";
2570 else
2571 f << "_,";
2572 std::string type(""); // PICT
2573 for (int c=0; c<4; ++c) type+=char(input->readULong(1));
2574 f << type << ":" << input->readLong(2); // ID
2575 f << "],";
2576 }
2577 ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16));
2578 ascFile.addNote(f.str().c_str());
2579 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
2580 return true;
2581 }
2582
2583 ////////////////////////////////////////////////////////////
2584 // RSRC layout
2585 ////////////////////////////////////////////////////////////
2586 bool MacDraft5Parser::readLayoutDefinitions(MWAWEntry const &entry, bool inRsrc)
2587 {
2588 if (inRsrc && !getRSRCParser()) return false;
2589 MWAWInputStreamPtr input = inRsrc ? getRSRCParser()->getInput() : getInput();
2590 if (!input || !entry.valid() || entry.length()<30 || (entry.length()%34)<30 || (entry.length()%34)>31) {
2591 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayoutDefinitions: entry is invalid\n"));
2592 return false;
2593 }
2594 entry.setParsed(true);
2595 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
2596 libmwaw::DebugFile &ascFile = inRsrc ? getRSRCParser()->ascii() : ascii();
2597 libmwaw::DebugStream f;
2598 f << "Entries(Layout):";
2599 if (entry.id()!=0) {
2600 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayoutDefinitions: entry id seems odd\n"));
2601 f << "##id=" << entry.id() << ",";
2602 }
2603 int val;
2604 for (int i=0; i<3; ++i) { // always 0
2605 val=static_cast<int>(input->readLong(2));
2606 if (val) f << "f" << i << "=" << val << ",";
2607 }
2608 auto N=static_cast<int>(input->readULong(2));
2609 if (30+34*N!=entry.length() && 31+34*N!=entry.length()) {
2610 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayoutDefinitions:N seems bad\n"));
2611 f << "##N=" << N << ",";
2612 if (30+34*N>entry.length())
2613 N=int((entry.length()-30)/34);
2614 }
2615 val=static_cast<int>(input->readLong(2)); // always 0 ?
2616 if (val) f << "f3=" << val << ",";
2617 val=static_cast<int>(input->readLong(2)); // always c
2618 if (val!=34) f << "#fSz=" << val << ",";
2619 long dataSz=input->readLong(4);
2620 if (dataSz && dataSz!=34*N) {
2621 MWAW_DEBUG_MSG(("MacDraft5Parser::readLayoutDefinitions:dataSize seems bad\n"));
2622 f << "##dataSz=" << dataSz << ",";
2623 }
2624 for (int i=0; i<7; ++i) {
2625 val=static_cast<int>(input->readLong(2));
2626 static int const expected[]= {0,0x22,0,0x10,0,0,0};
2627 if (val!=expected[i]) f << "f" << i+4 << "=" << val << ",";
2628 }
2629
2630 ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16));
2631 ascFile.addNote(f.str().c_str());
2632 /* Normally, we can find one layout definition in the data fork and one in the resource.
2633 So, we must clear the layout list to avoid dupplicating each layout
2634 */
2635 m_state->m_layoutList.clear();
2636 for (long i=0; i<N; ++i) {
2637 long pos=input->tell();
2638 f.str("");
2639 std::shared_ptr<MacDraft5ParserInternal::Layout> layout(new MacDraft5ParserInternal::Layout(int(m_state->m_layoutList.size())));
2640 for (int c=0; c<16; ++c) {
2641 auto ch=char(input->readULong(1));
2642 if (ch==0) break;
2643 int unicode= getParserState()->m_fontConverter->unicode(3, static_cast<unsigned char>(ch));
2644 if (unicode==-1)
2645 layout->m_name.append(ch);
2646 else
2647 libmwaw::appendUnicode(static_cast<uint32_t>(unicode), layout->m_name);
2648 }
2649 input->seek(pos+16, librevenge::RVNG_SEEK_SET);
2650 for (int j=0; j<3; ++j) { // f0=3f|ae|be|bf, f1=4-10, f2=-1..4
2651 val=static_cast<int>(input->readLong(2));
2652 if (val) f << "f" << j << "=" << val << ",";
2653 }
2654 layout->m_N=static_cast<int>(input->readULong(4));
2655 layout->m_entry.setBegin(long(input->readULong(4)));
2656 layout->m_entry.setLength(long(input->readULong(4)));
2657 layout->m_extra=f.str();
2658
2659 m_state->m_layoutList.push_back(layout);
2660 f.str("");
2661 f << "Layout-" << i << ":" << layout;
2662 input->seek(pos+34, librevenge::RVNG_SEEK_SET);
2663 ascFile.addPos(pos);
2664 ascFile.addNote(f.str().c_str());
2665 }
2666 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
2667 return true;
2668 }
2669
2670 ////////////////////////////////////////////////////////////
2671 // RSRC unknown
2672 ////////////////////////////////////////////////////////////
2673 bool MacDraft5Parser::readLinks(MWAWEntry const &entry, bool inRsrc)
2674 {
2675 if (inRsrc && !getRSRCParser()) return false;
2676 MWAWInputStreamPtr input = inRsrc ? getRSRCParser()->getInput() : getInput();
2677 if (!input || !entry.valid() || entry.length()!=0x30) {
2678 MWAW_DEBUG_MSG(("MacDraft5Parser::readLinks: entry is invalid\n"));
2679 return false;
2680 }
2681 entry.setParsed(true);
2682 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
2683 libmwaw::DebugFile &ascFile = inRsrc ? getRSRCParser()->ascii() : ascii();
2684 libmwaw::DebugStream f;
2685 f << "Entries(Links)[" << entry.id() << "]:";
2686 std::string name(""); // MD40
2687 for (int i=0; i<4; ++i) name+=char(input->readULong(1));
2688 f << name << ",";
2689 for (int i=0; i<21; ++i) { // f0=3b0, f11=137|145, fl13=1, fl17=fl11+1
2690 auto val=static_cast<int>(input->readULong(2));
2691 if (val) f << "f" << i << "=" << val << ",";
2692 }
2693 ascFile.addPos(entry.begin()-(inRsrc ? 4 : 16));
2694 ascFile.addNote(f.str().c_str());
2695 input->seek(entry.end(), librevenge::RVNG_SEEK_SET);
2696 return true;
2697 }
2698
2699 ////////////////////////////////////////////////////////////
2700 //
2701 // send data
2702 //
2703 ////////////////////////////////////////////////////////////
2704 bool MacDraft5Parser::send(MacDraft5ParserInternal::Image const &image)
2705 {
2706 MWAWGraphicListenerPtr listener=getGraphicListener();
2707 if (!listener) {
2708 MWAW_DEBUG_MSG(("MacDraft5Parser::send[image]: can not find the listener\n"));
2709 return false;
2710 }
2711 if (!image.m_id) {
2712 MWAW_DEBUG_MSG(("MacDraft5Parser::send[image]: can not find the image id\n"));
2713 return false;
2714 }
2715 bool ok=false;
2716 for (auto const &layout : m_state->m_layoutList) {
2717 if (!layout) continue;
2718 std::shared_ptr<MacDraft5ParserInternal::Shape> shape=layout->findShape(image.m_id, false);
2719 if (!shape) continue;
2720 ok=true;
2721 bool openLayer=false;
2722 if (!layout->m_name.empty())
2723 openLayer=listener->openLayer(layout->m_name);
2724 send(*shape, *layout);
2725 if (openLayer)
2726 listener->closeLayer();
2727 }
2728 if (!ok) {
2729 MWAW_DEBUG_MSG(("MacDraft5Parser::send[image]: can not find any layout for the image id=%lx\n", static_cast<unsigned long>(image.m_id)));
2730 return false;
2731 }
2732 return true;
2733 }
2734
2735 bool MacDraft5Parser::send(MacDraft5ParserInternal::Layout const &layout)
2736 {
2737 MWAWGraphicListenerPtr listener=getGraphicListener();
2738 if (!listener) {
2739 MWAW_DEBUG_MSG(("MacDraft5Parser::send[layout]: can not find the listener\n"));
2740 return false;
2741 }
2742 bool openLayer=false;
2743 if (!layout.m_name.empty())
2744 openLayer=listener->openLayer(layout.m_name);
2745 for (auto id : layout.m_rootList) {
2746 auto child=layout.m_shapeList[id];
2747 if (!child || child->m_isSent)
2748 continue;
2749 send(*child, layout);
2750 }
2751 if (openLayer)
2752 listener->closeLayer();
2753 return true;
2754 }
2755
2756 bool MacDraft5Parser::send(MacDraft5ParserInternal::Shape const &shape,
2757 MacDraft5ParserInternal::Layout const &layout)
2758 {
2759 MWAWGraphicListenerPtr listener=getGraphicListener();
2760 if (!listener) {
2761 MWAW_DEBUG_MSG(("MacDraft5Parser::send[shape]: can not find the listener\n"));
2762 return false;
2763 }
2764 shape.m_isSent=true;
2765 MWAWBox2f box=shape.getBdBox();
2766 MWAWPosition pos(box[0]+m_state->m_origin, box.size(), librevenge::RVNG_POINT);
2767 pos.m_anchorTo = MWAWPosition::Page;
2768
2769 if (!shape.m_childList.empty())
2770 listener->openGroup(pos);
2771 MWAWGraphicStyle style=shape.m_style;
2772 switch (shape.m_type) {
2773 case MacDraft5ParserInternal::Shape::Basic:
2774 listener->insertShape(pos, shape.m_shape, style);
2775 for (size_t i=0; i<shape.m_otherShapeList.size(); ++i) {
2776 if (i>=shape.m_otherStyleList.size()) {
2777 MWAW_DEBUG_MSG(("MacDraft5Parser::send[shape]: can not find some style\n"));
2778 break;
2779 }
2780 box=shape.m_otherShapeList[i].getBdBox();
2781 pos=MWAWPosition(box[0]+m_state->m_origin, box.size(), librevenge::RVNG_POINT);
2782 pos.m_anchorTo = MWAWPosition::Page;
2783 listener->insertShape(pos, shape.m_otherShapeList[i], shape.m_otherStyleList[i]);
2784 }
2785 break;
2786 case MacDraft5ParserInternal::Shape::Text: {
2787 std::shared_ptr<MWAWSubDocument> doc(new MacDraft5ParserInternal::SubDocument(*this, getInput(), layout.m_id, shape.m_id));
2788 listener->insertTextBox(pos, doc, style);
2789 break;
2790 }
2791 case MacDraft5ParserInternal::Shape::QuotationSurface: {
2792 pos=MWAWPosition(shape.m_origin+m_state->m_origin, MWAWVec2f(-1,-1), librevenge::RVNG_POINT);
2793 pos.m_anchorTo = MWAWPosition::Page;
2794 std::shared_ptr<MWAWSubDocument> doc(new MacDraft5ParserInternal::SubDocument(*this, getInput(), layout.m_id, shape.m_id));
2795 listener->insertTextBox(pos, doc, style);
2796 break;
2797 }
2798 case MacDraft5ParserInternal::Shape::Bitmap:
2799 sendBitmap(shape, pos);
2800 break;
2801 case MacDraft5ParserInternal::Shape::Group:
2802 case MacDraft5ParserInternal::Shape::Unknown:
2803 #if !defined(__clang__)
2804 default:
2805 #endif
2806 break;
2807 }
2808
2809 for (auto id : shape.m_childList) {
2810 auto child=layout.findShape(id);
2811 if (!child) continue;
2812 if (child->m_isSent) {
2813 MWAW_DEBUG_MSG(("MacDraft5Parser::send[shape]: the child is already sent\n"));
2814 continue;
2815 }
2816 send(*child, layout);
2817 }
2818 if (!shape.m_childList.empty())
2819 listener->closeGroup();
2820
2821 return true;
2822 }
2823
2824 bool MacDraft5Parser::sendBitmap(MacDraft5ParserInternal::Shape const &bitmap, MWAWPosition const &position)
2825 {
2826 MWAWGraphicListenerPtr listener=getGraphicListener();
2827 if (!listener) {
2828 MWAW_DEBUG_MSG(("MacDraft5Parser::sendBitmap: can not find the listener\n"));
2829 return false;
2830 }
2831 bitmap.m_isSent=true;
2832
2833 if (bitmap.m_bitmapIdList.empty() || bitmap.m_bitmapIdList.size()!=1) {
2834 MWAW_DEBUG_MSG(("MacDraft5Parser::sendBitmap: the bitmap seems bad\n"));
2835 return false;
2836 }
2837
2838 MWAWEmbeddedObject picture;
2839 if (!m_styleManager->getBitmap(bitmap.m_bitmapIdList[0], picture)) return false;
2840 MWAWGraphicStyle style=bitmap.m_style;
2841 style.m_lineWidth=0;
2842 listener->insertPicture(position, picture, style);
2843
2844 return true;
2845 }
2846
2847 bool MacDraft5Parser::sendText(int layoutId, long zId)
2848 {
2849 MWAWGraphicListenerPtr listener=getGraphicListener();
2850 if (!listener) {
2851 MWAW_DEBUG_MSG(("MacDraft5Parser::sendText: can not find the listener\n"));
2852 return false;
2853 }
2854 if (layoutId<0 || layoutId>=static_cast<int>(m_state->m_layoutList.size()) || !m_state->m_layoutList[size_t(layoutId)]) {
2855 MWAW_DEBUG_MSG(("MacDraft5Parser::sendText: can not find the layout\n"));
2856 return false;
2857 }
2858 auto const &layout=*m_state->m_layoutList[size_t(layoutId)];
2859 auto shape=layout.findShape(zId);
2860 if (!shape)
2861 return false;
2862 shape->m_isSent = true;
2863
2864 listener->setParagraph(shape->m_paragraph);
2865 listener->setFont(MWAWFont(3,12));
2866 if (shape->m_type != MacDraft5ParserInternal::Shape::Text &&
2867 shape->m_type != MacDraft5ParserInternal::Shape::QuotationSurface) {
2868 MWAW_DEBUG_MSG(("MacDraft5Parser::sendText: unexpected shape type\n"));
2869 return false;
2870 }
2871 if (!shape->m_textEntry.valid())
2872 return true;
2873 MWAWInputStreamPtr input=getInput();
2874 input->seek(shape->m_textEntry.begin(), librevenge::RVNG_SEEK_SET);
2875 libmwaw::DebugStream f;
2876 f << "Text-data:";
2877 long endPos=shape->m_textEntry.end();
2878 long cPos=0;
2879 while (!input->isEnd()) {
2880 if (input->tell()>=shape->m_textEntry.end())
2881 break;
2882 if (shape->m_posToFontMap.find(cPos)!=shape->m_posToFontMap.end()) {
2883 listener->setFont(shape->m_posToFontMap.find(cPos)->second);
2884 f << "[F]";
2885 }
2886 ++cPos;
2887 auto c = char(input->readULong(1));
2888 if (c==0) {
2889 MWAW_DEBUG_MSG(("MacDraft5Parser::sendText: find char 0\n"));
2890 f << "#[0]";
2891 continue;
2892 }
2893 f << c;
2894 switch (c) {
2895 case 9:
2896 listener->insertTab();
2897 break;
2898 case 0xd:
2899 listener->insertEOL();
2900 break;
2901 default:
2902 listener->insertCharacter(static_cast<unsigned char>(c), input, endPos);
2903 break;
2904 }
2905 }
2906 if (shape->m_type == MacDraft5ParserInternal::Shape::QuotationSurface) {
2907 // we still need to squared the unit
2908 MWAWFont font(3,12);
2909 font.set(MWAWFont::Script::super());
2910 listener->setFont(font);
2911 listener->insertCharacter('2');
2912 }
2913 ascii().addPos(shape->m_textEntry.begin());
2914 ascii().addNote(f.str().c_str());
2915 return true;
2916 }
2917 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: