Debian Codegraph @

src/lib/PowerPoint1Parser.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 <algorithm>
35 #include <iomanip>
36 #include <iostream>
37 #include <set>
38 #include <sstream>
39
40 #include <librevenge/librevenge.h>
41
42 #include "MWAWPresentationListener.hxx"
43 #include "MWAWFont.hxx"
44 #include "MWAWFontConverter.hxx"
45 #include "MWAWHeader.hxx"
46 #include "MWAWGraphicShape.hxx"
47 #include "MWAWGraphicStyle.hxx"
48 #include "MWAWParagraph.hxx"
49 #include "MWAWPosition.hxx"
50 #include "MWAWPrinter.hxx"
51 #include "MWAWSubDocument.hxx"
52
53 #include "PowerPoint1Parser.hxx"
54
55 /** Internal: the structures of a PowerPoint1Parser */
56 namespace PowerPoint1ParserInternal
57 {
58 //! Internal: a ruler
59 struct Ruler {
60 //! constructor
61 Ruler()
62 : m_tabs()
63 {
64 }
65 //! the outline
66 struct Outline {
67 //! constructor
68 Outline()
69 {
70 for (auto &margin : m_margins) margin=0;
71 for (auto &interline : m_interlines) interline=0;
72 }
73 //! operator<<
74 friend std::ostream &operator<<(std::ostream &o, Outline const &outline)
75 {
76 for (int i=0; i<2; ++i) {
77 if (outline.m_margins[i]==0) continue;
78 o << (i==0 ? "first[margin]" : "left[margin]") << "=" << outline.m_margins[i] << ",";
79 }
80 for (int i=0; i<2; ++i) {
81 if (outline.m_interlines[i]==100) continue;
82 o << (i==0 ? "space[interline]" : "space[paragraph]") << "=" << outline.m_interlines[i] << "%,";
83 }
84 return o;
85 }
86 //! the first margin and left margin
87 int m_margins[2];
88 //! the interline and paragraph spacing
89 int m_interlines[2];
90 };
91 //! the tabs
92 std::vector<MWAWTabStop> m_tabs;
93 //! the outline
94 Outline m_outlines[5];
95 };
96 //! a scheme of a PowerPoint1Parser
97 struct Scheme {
98 //! the color: back, foreground, accents
99 MWAWColor m_colors[8];
100 };
101 //! Internal: a text zone of a PowerPoint1Parser
102 struct TextZone {
103 //! constructor
104 TextZone()
105 : m_lineList()
106 , m_schemeId(-1)
107 {
108 }
109 //! small structure used to store a line of text and its format
110 struct Line {
111 //! constructor
112 Line()
113 : m_text()
114 , m_format()
115 , m_ruler()
116 , m_justify(MWAWParagraph::JustificationLeft)
117 , m_outlineLevel(0)
118 {
119 }
120 //! the text entry
121 MWAWEntry m_text;
122 //! the format entry
123 MWAWEntry m_format;
124 //! the ruler entry (windows v2)
125 MWAWEntry m_ruler;
126 //! the justification
127 MWAWParagraph::Justification m_justify;
128 //! the outline level
129 int m_outlineLevel;
130 };
131 //! return true if the zone has no text
132 bool empty() const
133 {
134 for (auto const &line : m_lineList) {
135 if (line.m_text.valid()) return false;
136 }
137 return true;
138 }
139 //! the line list
140 std::vector<Line> m_lineList;
141 //! the scheme id (if v2)
142 mutable int m_schemeId;
143 };
144 //! Internal: a frame of a PowerPoint1Parser
145 struct Frame {
146 //! constructor
147 Frame()
148 : m_type(-1)
149 , m_dimension()
150 , m_cornerSize(0)
151 , m_style()
152 , m_rulerId(-1)
153 , m_pictureId(-1)
154 , m_textId(-1,-1)
155 {
156 }
157 //! the type: 0:line, 1:rect, 2: textbox, ...
158 int m_type;
159 //! the dimension
160 MWAWBox2i m_dimension;
161 //! the corner width
162 int m_cornerSize;
163 //! the style
164 MWAWGraphicStyle m_style;
165 //! the paragraph id
166 int m_rulerId;
167 //! the picture id
168 int m_pictureId;
169 //! the text sub id: first and last id
170 MWAWVec2i m_textId;
171 };
172 //! Internal: a slide of a PowerPoint1Parser
173 struct Slide {
174 //! constructor
175 Slide()
176 : m_useMasterPage(true)
177 , m_schemeId(-1)
178 {
179 }
180 //! the textzone: main's and note's zone
181 TextZone m_textZones[2];
182 //! the list of frames: main's and note's list of frame
183 std::vector<Frame> m_framesList[2];
184 //! a flag to know if we need to use the master page
185 bool m_useMasterPage;
186 //! the scheme id
187 int m_schemeId;
188 };
189
190 ////////////////////////////////////////
191 //! Internal: the state of a PowerPoint1Parser
192 struct State {
193 //! constructor
194 State()
195 : m_isMacFile(true)
196 , m_unit(1)
197 , m_zoneListBegin(0)
198 , m_zonesList()
199 , m_origin(0,0)
200 , m_rulersList()
201 , m_idToSlideMap()
202 , m_idToSchemeMap()
203 , m_idToUserColorMap()
204 , m_picturesIdList()
205 , m_schemesIdList()
206 , m_badEntry()
207 {
208 for (auto &slideId : m_slideIds) slideId=-1;
209 for (auto &printInfoId : m_printInfoIds) printInfoId=-1;
210 for (auto &zoneId : m_zoneIds) zoneId=-1;
211 }
212 //! try to return a zone
213 MWAWEntry const &getZoneEntry(int id) const
214 {
215 if (id==-1) return m_badEntry;
216 if (id<0||size_t(id)>=m_zonesList.size()) {
217 MWAW_DEBUG_MSG(("PowerPoint1ParserInternal::State::getZone: can find entry with id=%d\n", id));
218 return m_badEntry;
219 }
220 return m_zonesList[size_t(id)];
221 }
222 //! try to return a pattern
223 bool getPattern(int id, MWAWGraphicStyle::Pattern &pattern) const;
224 //! flag to know if the file is a mac file or a pc file
225 bool m_isMacFile;
226 //! the data unit: 1 if the file is a mac file, 1/8 if the file is a windows file
227 float m_unit;
228 //! the begin position of the list of zones
229 long m_zoneListBegin;
230 //! the list of zone entries
231 std::vector<MWAWEntry> m_zonesList;
232 //! the origin
233 MWAWVec2i m_origin;
234 //! the ruler
235 std::vector<Ruler> m_rulersList;
236 //! a map between zoneId and slide
237 std::map<int,Slide> m_idToSlideMap;
238 //! a map between schemeId and scheme
239 std::map<int,Scheme> m_idToSchemeMap;
240 //! a map between colorId and user color map
241 std::map<int,MWAWColor> m_idToUserColorMap;
242 //! the list of slides ids: 0 (master, slide 1, slide 2, ...), 1 (handout slide)
243 std::vector<int> m_slidesIdList[2];
244 //! the list of pictures id
245 std::vector<int> m_picturesIdList;
246 //! the list of scheme id
247 std::vector<int> m_schemesIdList;
248 //! the slide id
249 int m_slideIds[2];
250 //! the printInfo id
251 int m_printInfoIds[2];
252 //! the sequential zones id: picture list, ...
253 int m_zoneIds[10];
254 //! an entry used by getZoneEntry if it does not find the zone
255 MWAWEntry m_badEntry;
256 };
257
258 bool State::getPattern(int id, MWAWGraphicStyle::Pattern &pattern) const
259 {
260 // normally between 1 and 22 but find a pattern resource with 39 patterns
261 if (id<=0 || id>39) {
262 MWAW_DEBUG_MSG(("PowerPoint1ParserInternal::State::getPattern: unknown id=%d\n", id));
263 return false;
264 }
265 static uint16_t const values[] = {
266 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000, 0x0000,
267 0xddff, 0x77ff, 0xddff, 0x77ff, 0x8000, 0x0800, 0x8000, 0x0800,
268 0xdd77, 0xdd77, 0xdd77, 0xdd77, 0x8800, 0x2200, 0x8800, 0x2200,
269 0xaa55, 0xaa55, 0xaa55, 0xaa55, 0x8822, 0x8822, 0x8822, 0x8822,
270 0x8844, 0x2211, 0x8844, 0x2211, 0x1122, 0x4488, 0x1122, 0x4488,
271 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0xff00, 0xff00, 0xff00, 0xff00,
272 0x81c0, 0x6030, 0x180c, 0x0603, 0x8103, 0x060c, 0x1830, 0x60c0,
273 0x8888, 0x8888, 0x8888, 0x8888, 0xff00, 0x0000, 0xff00, 0x0000,
274 0xb130, 0x031b, 0xd8c0, 0x0c8d, 0x8010, 0x0220, 0x0108, 0x4004,
275 0xff80, 0x8080, 0x8080, 0x8080, 0xff88, 0x8888, 0xff88, 0x8888,
276 0xff80, 0x8080, 0xff08, 0x0808, 0xeedd, 0xbb77, 0xeedd, 0xbb77,
277 0x8040, 0x2000, 0x0204, 0x0800, 0x8000, 0x0000, 0x0000, 0x0000,
278 0x8244, 0x3944, 0x8201, 0x0101, 0xf874, 0x2247, 0x8f17, 0x2271,
279 0x55a0, 0x4040, 0x550a, 0x0404, 0x2050, 0x8888, 0x8888, 0x0502,
280 0xbf00, 0xbfbf, 0xb0b0, 0xb0b0, 0x0102, 0x0408, 0x1020, 0x4080,
281 0xaa00, 0x8000, 0x8800, 0x8000, 0x081c, 0x22c1, 0x8001, 0x0204,
282 0x8814, 0x2241, 0x8800, 0xaa00, 0x40a0, 0x0000, 0x040a, 0x0000,
283 0x0384, 0x4830, 0x0c02, 0x0101, 0x8080, 0x413e, 0x0808, 0x14e3,
284 0x1020, 0x54aa, 0xff02, 0x0408, 0x7789, 0x8f8f, 0x7798, 0xf8f8,
285 0x0008, 0x142a, 0x552a, 0x1408
286 };
287 pattern.m_dim=MWAWVec2i(8,8);
288 uint16_t const *ptr=&values[4*(id-1)];
289 pattern.m_data.resize(8);
290 for (size_t i=0; i < 4; ++i, ++ptr) {
291 pattern.m_data[2*i]=static_cast<unsigned char>((*ptr)>>8);
292 pattern.m_data[2*i+1]=static_cast<unsigned char>((*ptr)&0xff);
293 }
294 return true;
295 }
296
297 ////////////////////////////////////////
298 //! Internal: the subdocument of a PowerPointParser
299 class SubDocument final : public MWAWSubDocument
300 {
301 public:
302 //! constructor for text
303 SubDocument(PowerPoint1Parser &pars, MWAWInputStreamPtr const &input, TextZone const *textZone, MWAWVec2i const &tId, int rulerId)
304 : MWAWSubDocument(&pars, input, MWAWEntry())
305 , m_slide(nullptr)
306 , m_textZone(textZone)
307 , m_id(tId)
308 , m_rulerId(rulerId)
309 {
310 }
311 //! constructor for slide note
312 SubDocument(PowerPoint1Parser &pars, MWAWInputStreamPtr const &input, Slide const *slide)
313 : MWAWSubDocument(&pars, input, MWAWEntry())
314 , m_slide(slide)
315 , m_textZone(nullptr)
316 , m_id()
317 , m_rulerId(-1)
318 {
319 }
320
321 //! destructor
322 ~SubDocument() final {}
323
324 //! operator!=
325 bool operator!=(MWAWSubDocument const &doc) const final
326 {
327 if (MWAWSubDocument::operator!=(doc)) return true;
328 auto const *sDoc = dynamic_cast<SubDocument const *>(&doc);
329 if (!sDoc) return true;
330 if (m_slide != sDoc->m_slide) return true;
331 if (m_textZone != sDoc->m_textZone) return true;
332 if (m_id != sDoc->m_id) return true;
333 if (m_rulerId != sDoc->m_rulerId) return true;
334 return false;
335 }
336
337 //! the parser function
338 void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
339
340 protected:
341 //! the slide
342 Slide const *m_slide;
343 //! the text zone
344 TextZone const *m_textZone;
345 //! the text id in text zone
346 MWAWVec2i m_id;
347 //! the ruler id
348 int m_rulerId;
349
350 private:
351 SubDocument(SubDocument const &) = delete;
352 SubDocument &operator=(SubDocument const &) = delete;
353 };
354
355 void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType)
356 {
357 if (!listener.get()) {
358 MWAW_DEBUG_MSG(("PowerPoint1ParserInternal::SubDocument::parse: no listener\n"));
359 return;
360 }
361 auto *parser=dynamic_cast<PowerPoint1Parser *>(m_parser);
362 if (!parser) {
363 MWAW_DEBUG_MSG(("PowerPoint1ParserInternal::SubDocument::parse: no parser\n"));
364 return;
365 }
366 if (m_slide) {
367 parser->sendSlideNote(*m_slide);
368 return;
369 }
370 if (!m_textZone) {
371 MWAW_DEBUG_MSG(("PowerPoint1ParserInternal::SubDocument::parse: no text zone\n"));
372 return;
373 }
374
375 long pos = m_input->tell();
376 parser->sendText(*m_textZone, m_id, m_rulerId);
377 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
378 }
379 }
380
381
382 ////////////////////////////////////////////////////////////
383 // constructor/destructor, ...
384 ////////////////////////////////////////////////////////////
385 PowerPoint1Parser::PowerPoint1Parser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
386 : MWAWPresentationParser(input, rsrcParser, header)
387 , m_state(new PowerPoint1ParserInternal::State)
388 {
389 setAsciiName("main-1");
390 }
391
392 PowerPoint1Parser::~PowerPoint1Parser()
393 {
394 }
395
396 bool PowerPoint1Parser::getColor(int colorId, int schemeId, MWAWColor &color) const
397 {
398 // if scheme is defined, we must use it for 0<=colorId<8
399 if (schemeId>=0 && colorId>=0 && colorId<8 && m_state->m_idToSchemeMap.find(schemeId)!=m_state->m_idToSchemeMap.end()) {
400 color=m_state->m_idToSchemeMap.find(schemeId)->second.m_colors[colorId];
401 return true;
402 }
403 if (m_state->m_idToUserColorMap.find(colorId)!=m_state->m_idToUserColorMap.end()) {
404 color=m_state->m_idToUserColorMap.find(colorId)->second;
405 return true;
406 }
407 if (schemeId!=0) { // seems to happens in the master slide
408 MWAW_DEBUG_MSG(("PowerPoint1Parser::getColor: can not find color=%d in scheme=%d\n", colorId, schemeId));
409 }
410 return false;
411 }
412
413 ////////////////////////////////////////////////////////////
414 // the parser
415 ////////////////////////////////////////////////////////////
416 void PowerPoint1Parser::parse(librevenge::RVNGPresentationInterface *docInterface)
417 {
418 if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException());
419 bool ok = true;
420 try {
421 // create the asciiFile
422 ascii().setStream(getInput());
423 ascii().open(asciiName());
424 checkHeader(nullptr);
425 ok = createZones();
426 if (ok) {
427 createDocument(docInterface);
428 sendSlides();
429 }
430
431 #ifdef DEBUG
432 checkForUnparsedZones();
433 #endif
434 ascii().reset();
435 }
436 catch (...) {
437 MWAW_DEBUG_MSG(("PowerPoint1Parser::parse: exception catched when parsing\n"));
438 ok = false;
439 }
440
441 resetPresentationListener();
442 if (!ok) throw(libmwaw::ParseException());
443 }
444
445 ////////////////////////////////////////////////////////////
446 // create the document
447 ////////////////////////////////////////////////////////////
448 void PowerPoint1Parser::createDocument(librevenge::RVNGPresentationInterface *documentInterface)
449 {
450 if (!documentInterface) return;
451 if (getPresentationListener()) {
452 MWAW_DEBUG_MSG(("PowerPoint1Parser::createDocument: listener already exist\n"));
453 return;
454 }
455
456 // create the page list
457 std::vector<MWAWPageSpan> pageList;
458 for (size_t i=1; i<m_state->m_slidesIdList[0].size(); ++i) {
459 MWAWPageSpan ps(getPageSpan());
460 int sId=m_state->m_slidesIdList[0][i];
461 if (m_state->m_idToSlideMap.find(sId)!=m_state->m_idToSlideMap.end()) {
462 auto const &slide=m_state->m_idToSlideMap.find(sId)->second;
463 if (slide.m_useMasterPage)
464 ps.setMasterPageName(librevenge::RVNGString("Master"));
465 MWAWColor backColor;
466 if (slide.m_schemeId>=0 && getColor(0, slide.m_schemeId, backColor))
467 ps.setBackgroundColor(backColor);
468 }
469 pageList.push_back(ps);
470 }
471
472 //
473 MWAWPresentationListenerPtr listen(new MWAWPresentationListener(*getParserState(), pageList, documentInterface));
474 setPresentationListener(listen);
475 listen->startDocument();
476 }
477
478
479 ////////////////////////////////////////////////////////////
480 // Intermediate level
481 ////////////////////////////////////////////////////////////
482
483 // create the different zones
484 bool PowerPoint1Parser::createZones()
485 {
486 MWAWInputStreamPtr input=getInput();
487 if (!input) {
488 MWAW_DEBUG_MSG(("PowerPoint1Parser::createZones: can not find the main input\n"));
489 return false;
490 }
491 int docInfo;
492 if (!readListZones(docInfo)) return false;
493 size_t numZones=m_state->m_zonesList.size();
494 if (docInfo<0 || docInfo>=int(numZones) || !readDocInfo(m_state->m_zonesList[size_t(docInfo)])) {
495 MWAW_DEBUG_MSG(("PowerPoint1Parser::createZones: can not find the document info zone\n"));
496 return false;
497 }
498 int const vers=version();
499 bool const isMacFile=m_state->m_isMacFile;
500 int numStyles=vers<=1 ? 4 : m_state->m_isMacFile ? 6 : 8;
501 if (isMacFile) {
502 for (int i=0; i<numStyles; ++i) {
503 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_zoneIds[i]);
504 if (!entry.valid() || entry.isParsed()) continue;
505 if (i==0 || i==3)
506 readZoneIdList(entry, i);
507 else if (i==1)
508 readRulers(entry);
509 else if (i==2)
510 readFonts(entry);
511 else if (i==4)
512 readColorZone(entry);
513 else if (i==5)
514 readZone2(entry);
515 }
516 }
517 else {
518 for (int i=0; i<numStyles; ++i) {
519 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_zoneIds[i]);
520 if (!entry.valid() || entry.isParsed()) continue;
521 if (i<3) // list of 0: picture, 1: rulers, 2: scheme
522 readZoneIdList2(entry, i);
523 else if (i==3)
524 readColorZone(entry);
525 else if (i==4)
526 readZone2(entry);
527 // 5: never seens
528 else if (i==6)
529 readFonts(entry);
530 else if (i==7)
531 readFontNames(entry);
532 }
533 }
534 readSchemes();
535 for (int i=0; i<2; ++i) {
536 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_slideIds[i]);
537 if (!entry.valid() || entry.isParsed()) continue;
538 readSlide(entry, m_state->m_slidesIdList[i]);
539 }
540 for (int i=0; i<2; ++i) {
541 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_printInfoIds[i]);
542 if (!entry.valid() || entry.isParsed()) continue;
543 if (m_state->m_isMacFile && i==1)
544 readPrintInfo(entry);
545 else {
546 entry.setParsed(true);
547 libmwaw::DebugStream f;
548 f << "Entries(PrintInfo" << i << ")[Z" << entry.id() << "]:";
549 ascii().addPos(entry.begin());
550 ascii().addNote(f.str().c_str());
551 ascii().addPos(entry.end());
552 ascii().addNote("_");
553 }
554 }
555 for (int i=0; i<10; ++i) {
556 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_zoneIds[i]);
557 if (!entry.valid() || entry.isParsed()) continue;
558 static bool first=true;
559 if (first) {
560 first=false;
561 MWAW_DEBUG_MSG(("PowerPoint1Parser::createZones: find unknown Zone%d\n", i));
562 }
563 entry.setParsed(true);
564 libmwaw::DebugStream f;
565 f << "Entries(Zone" << i << ")[Z" << entry.id() << "]:";
566 ascii().addPos(entry.begin());
567 ascii().addNote(f.str().c_str());
568 ascii().addPos(entry.end());
569 ascii().addNote("_");
570 }
571 return !m_state->m_slidesIdList[0].empty();
572 }
573
574 bool PowerPoint1Parser::readListZones(int &docInfoId)
575 {
576 docInfoId=-1;
577 MWAWInputStreamPtr input=getInput();
578 libmwaw::DebugStream f;
579 f << "Entries(ListZones):";
580 // v3: N in 4, then 16+8*N (potential extra data)
581 long pos=input->tell();
582 auto N=int(input->readULong(2));
583 f << "N=" << N << ",";
584 if (!input->checkPosition(m_state->m_zoneListBegin+N*8)) {
585 MWAW_DEBUG_MSG(("PowerPoint1Parser::readListZones: the number of zones seems bad\n"));
586 f << "###zone";
587 ascii().addPos(pos);
588 ascii().addNote(f.str().c_str());
589 return false;
590 }
591 auto val=int(input->readULong(2)); // always 4
592 if (val!=4) f << "f0=" << val << ",";
593 auto endPos=long(input->readULong(4));
594 if (!input->checkPosition(endPos) || input->checkPosition(endPos+1)) {
595 MWAW_DEBUG_MSG(("PowerPoint1Parser::readListZones: the endPos seems bad\n"));
596 f << "###endPos=" << std::hex << endPos << std::dec << ",";
597 }
598 val=int(input->readULong(2)); // find a|10
599 if (val) f << "f1=" << val << ",";
600 docInfoId=int(input->readULong(2));
601 if (docInfoId) f << "docInfo=Z" << docInfoId << ",";
602 if (input->tell()!=m_state->m_zoneListBegin)
603 ascii().addDelimiter(input->tell(),'|');
604 ascii().addPos(pos);
605 ascii().addNote(f.str().c_str());
606
607 input->seek(m_state->m_zoneListBegin, librevenge::RVNG_SEEK_SET);
608 pos=input->tell();
609 f.str("");
610 f << "ListZones:zones=[";
611 m_state->m_zonesList.resize(size_t(N));
612 std::set<long> posList;
613 for (int i=0; i<N; ++i) {
614 unsigned long length=input->readULong(4);
615 auto begin=long(input->readULong(4));
616 if (length&0x80000000) {
617 f << "*";
618 length&=0x7FFFFFFF;
619 }
620 if (length==0) {
621 f << "_,";
622 continue;
623 }
624 if (begin+long(length)<=begin || !input->checkPosition(begin+long(length))) {
625 MWAW_DEBUG_MSG(("PowerPoint1Parser::readListZones: a zone seems bad\n"));
626 f << std::hex << begin << ":" << begin+long(length) << std::dec << "###,";
627 continue;
628 }
629 MWAWEntry &zone=m_state->m_zonesList[size_t(i)];
630 zone.setBegin(begin);
631 zone.setLength(long(length));
632 zone.setId(i);
633 posList.insert(begin);
634 posList.insert(zone.end());
635 f << std::hex << begin << ":" << begin+long(length) << std::dec << ",";
636 }
637 f << "],";
638 ascii().addPos(pos);
639 ascii().addNote(f.str().c_str());
640
641 // check that the zones do not overlap
642 for (size_t i=0; i<m_state->m_zonesList.size(); ++i) {
643 MWAWEntry const &zone=m_state->m_zonesList[size_t(i)];
644 if (!zone.valid()) continue;
645 auto it=posList.find(zone.begin());
646 bool ok=it!=posList.end();
647 if (ok) {
648 if (++it==posList.end() || *it!=zone.end())
649 ok=false;
650 }
651 if (ok) continue;
652 MWAW_DEBUG_MSG(("PowerPoint3Parser::readListZones: the zone %d overlaps with other zones\n", int(i)));
653 m_state->m_zonesList[size_t(i)]=MWAWEntry();
654 }
655 ascii().addPos(input->tell());
656 ascii().addNote("_");
657 return true;
658 }
659
660 void PowerPoint1Parser::sendSlides()
661 {
662 MWAWPresentationListenerPtr listener=getPresentationListener();
663 if (!listener) {
664 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendSlides: can not find the listener\n"));
665 return;
666 }
667 if (m_state->m_slidesIdList[0].empty())
668 return;
669 // first send the master page
670 MWAWPageSpan ps(getPageSpan());
671 ps.setMasterPageName(librevenge::RVNGString("Master"));
672 if (!listener->openMasterPage(ps)) {
673 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendSlides: can not create the master page\n"));
674 }
675 else {
676 int id=m_state->m_slidesIdList[0][0];
677 if (m_state->m_idToSlideMap.find(id)!=m_state->m_idToSlideMap.end())
678 sendSlide(m_state->m_idToSlideMap.find(id)->second, true);
679 listener->closeMasterPage();
680 }
681
682 for (size_t i=1; i<m_state->m_slidesIdList[0].size(); ++i) {
683 if (i>1)
684 listener->insertBreak(MWAWListener::PageBreak);
685 int id=m_state->m_slidesIdList[0][i];
686 if (m_state->m_idToSlideMap.find(id)==m_state->m_idToSlideMap.end())
687 continue;
688 sendSlide(m_state->m_idToSlideMap.find(id)->second, false);
689 }
690 }
691
692 void PowerPoint1Parser::checkForUnparsedZones()
693 {
694 for (auto id : m_state->m_picturesIdList) {
695 MWAWEntry const &entry=m_state->getZoneEntry(id);
696 if (!entry.valid() || entry.isParsed()) continue;
697 static bool first=true;
698 if (first) {
699 MWAW_DEBUG_MSG(("PowerPoint1Parser::checkForUnparsedZones: find some unparsed picture\n"));
700 first=false;
701 }
702 MWAWEmbeddedObject picture;
703 readPicture(entry, picture);
704 }
705 // check if there remains some unparsed zone
706 for (auto const &entry : m_state->m_zonesList) {
707 if (!entry.valid() || entry.isParsed()) continue;
708 static bool first=true;
709 if (first) {
710 first=false;
711 MWAW_DEBUG_MSG(("PowerPoint1Parser::checkForUnparsedZones: find some unknown zone\n"));
712 }
713 libmwaw::DebugStream f;
714 f << "Entries(UnknZone)[Z" << entry.id() << "]:";
715 ascii().addPos(entry.begin());
716 ascii().addNote(f.str().c_str());
717 ascii().addPos(entry.end());
718 ascii().addNote("_");
719 }
720 }
721
722 ////////////////////////////////////////////////////////////
723 // try to read the different zones
724 ////////////////////////////////////////////////////////////
725 bool PowerPoint1Parser::readFramesList(MWAWEntry const &entry, std::vector<PowerPoint1ParserInternal::Frame> &frameList, int schemeId)
726 {
727 MWAWInputStreamPtr input=getInput();
728 int const vers=version();
729 int const isMacFile=m_state->m_isMacFile;
730 int dataSz=isMacFile ? 28 : 32;
731 if (!entry.valid() || (entry.length()%dataSz)!=0) {
732 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: the entry seems bad\n"));
733 return false;
734 }
735 if (!isMacFile) dataSz=30;
736 entry.setParsed(true);
737 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
738 long pos=input->tell();
739 libmwaw::DebugStream f;
740 f << "Entries(Frames)[Z" << entry.id() << "]:";
741 ascii().addPos(pos);
742 ascii().addNote(f.str().c_str());
743 auto N=size_t(entry.length()/dataSz);
744 frameList.resize(N);
745 int tId=0;
746 MWAWColor colors[4]= {MWAWColor::black(),MWAWColor::white(),MWAWColor::black(),MWAWColor::black()}; // frame, fill, shadow, pat2
747 for (size_t fr=0; fr<N; ++fr) {
748 PowerPoint1ParserInternal::Frame &frame=frameList[fr];
749 pos=input->tell();
750 f.str("");
751 f << "Frames[F" << fr << "]:";
752 int dim[4];
753 for (auto &d : dim) d=int(input->readLong(2));
754 if (!isMacFile) {
755 std::swap(dim[0],dim[1]);
756 std::swap(dim[2],dim[3]);
757 }
758 frame.m_dimension=MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2]));
759 f << "dim=" << frame.m_dimension << ",";
760 frame.m_type=int(input->readULong(1));
761 switch (frame.m_type) {
762 case 0:
763 f << "line,";
764 break;
765 case 1: // rect, roundrect, oval, this depends on corner width
766 f << "rect,";
767 break;
768 case 2:
769 if (isMacFile)
770 f << "textbox,";
771 else {
772 frame.m_textId=MWAWVec2i(tId,tId);
773 f << "textbox=T" << tId++ << ",";
774 }
775 break;
776 case 3:
777 frame.m_textId=MWAWVec2i(tId,tId);
778 f << "textbox[small]=T" << tId++ << ",";
779 break;
780 default:
781 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find unknown frame type\n"));
782 f << "##frame.m_type=" << frame.m_type << ",";
783 }
784 int val;
785 int flags[5];
786 if (vers<=1) {
787 for (int i=0; i<5; ++i) {
788 val=flags[i]=int(input->readULong(1));
789 if (!val) continue;
790 char const *wh[]= {"opaque", "frame", "filled", "shadowed", "sized to text"};
791 if (val!=1) { // v2 can have other value
792 static bool first=true;
793 if (first) {
794 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find some unexpected draw value\n"));
795 first=false;
796 }
797 f << "#" << wh[i] << "=" << val << ",";
798 }
799 else
800 f << wh[i] << ",";
801 }
802 }
803 else {
804 if (isMacFile) {
805 val=int(input->readULong(1));
806 for (int i=0, bit=1; i<5; ++i, bit<<=1) {
807 flags[i]=(val&bit);
808 if (!flags[i]) continue;
809 char const *wh[]= {"opaque", "frame", "filled", "shadowed", "sized to text"};
810 f << wh[i] << ",";
811 }
812 if (val&0xE0) {
813 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find unexpected flags\n"));
814 f << "##fl=" << (val>>5) << ",";
815 }
816 }
817 else {
818 val=int(input->readULong(1));
819 if (val) f << "fl0=" << val << ",";
820 val=int(input->readULong(1));
821 for (int i=0, bit=1; i<5; ++i, bit<<=1) {
822 int const corresp[]= {2,1,3,0,4};
823 flags[corresp[i]]=(val&bit);
824 if (!flags[corresp[i]]) continue;
825 char const *wh[]= {"filled", "frame", "shadowed", "opaque", "sized to text"};
826 f << wh[i] << ",";
827 }
828 if (val&0xE0) {
829 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find unexpected flags\n"));
830 f << "##fl=" << (val>>5) << ",";
831 }
832 val=int(input->readULong(1));
833 if (val) f << "fl2=" << val << ",";
834 }
835 for (int i=0; i<4; ++i) { // frame, fill, shadow, pat2
836 auto col=int(input->readULong(1));
837 int const expected[]= { 1, 4, 2, 0};
838 if (schemeId>=0 && !getColor(col, schemeId, colors[i])) f << "##col,";
839 if (col!=expected[i]) f << "col" << i << "=" << col << ",";
840 }
841 if (!isMacFile) std::swap(colors[1],colors[3]);
842 }
843 MWAWGraphicStyle &style=frame.m_style;
844 val=int(input->readULong(1));
845 if (val>=1 && val<=10) {
846 if (val!=1) {
847 char const *wh[]= {"", "w=1", "w=2","w=4", "w=8", "w=16", "w=32",
848 "double", "double1x2", "double2x1", "triple1x2x1"
849 };
850 f << "line=[" << wh[val] << "],";
851 }
852 float const lWidth[]= {0, 1, 2, 4, 8, 12, 16, 3, 4, 4, 6};
853 style.m_lineWidth=lWidth[val];
854 style.m_lineColor=colors[0];
855 MWAWBorder border;
856 border.m_width=double(lWidth[val]);
857 border.m_color=colors[0];
858 switch (val) {
859 case 7:
860 border.m_type=MWAWBorder::Double;
861 break;
862 case 8:
863 border.m_type=MWAWBorder::Double;
864 border.m_widthsList.push_back(1);
865 border.m_widthsList.push_back(0);
866 border.m_widthsList.push_back(2);
867 break;
868 case 9:
869 border.m_type=MWAWBorder::Double;
870 border.m_widthsList.push_back(2);
871 border.m_widthsList.push_back(0);
872 border.m_widthsList.push_back(1);
873 break;
874 case 10:
875 border.m_type=MWAWBorder::Triple;
876 border.m_widthsList.push_back(1);
877 border.m_widthsList.push_back(0);
878 border.m_widthsList.push_back(2);
879 border.m_widthsList.push_back(0);
880 border.m_widthsList.push_back(1);
881 break;
882 default:
883 break;
884 }
885 style.setBorders(0xF, border);
886 }
887 else {
888 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find unexpected line type\n"));
889 f << "##line=" << val << ",";
890 }
891 if (flags[1]==0 && frame.m_type!=0) {
892 style.m_lineWidth=0;
893 style.resetBorders();
894 }
895 val=int(input->readULong(1));
896 MWAWGraphicStyle::Pattern pattern;
897 if (m_state->getPattern(val, pattern)) {
898 pattern.m_colors[0]=colors[1];
899 pattern.m_colors[1]=colors[3];
900 if (val!=1)
901 f << "pat=" << pattern << ",";
902 if (flags[2]) { // filled
903 MWAWColor color;
904 if (pattern.getUniqueColor(color))
905 style.setSurfaceColor(color);
906 else
907 style.setPattern(pattern);
908 }
909 else if (flags[0]) // opaque
910 style.setSurfaceColor(colors[1]);
911 if (!flags[2] && !flags[0] && flags[1]) {
912 // the pattern is used for border
913 MWAWColor color;
914 if (pattern.getAverageColor(color))
915 style.m_lineColor=color;
916 }
917 }
918 else {
919 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find unexpected pattern\n"));
920 f << "##pattern=" << val << ",";
921 if (flags[0]) style.setSurfaceColor(colors[1]);
922 }
923 if (flags[3]) {
924 style.setShadowColor(colors[2]);
925 style.m_shadowOffset=MWAWVec2f(3,3);
926 }
927 for (int i=0; i<2; ++i) { // often f0=0 and f1=small number
928 val=int(input->readULong(1));
929 if (!val) continue;
930 if (i==0 && frame.m_type==0) {
931 if (val==1) {
932 style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain();
933 f << "arrow[end],";
934 }
935 else if (val==2) {
936 style.m_arrows[0]=style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain();
937 f << "arrow[beg,end],";
938 }
939 else {
940 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFramesList: find unexpected arrow\n"));
941 f << "##arrow=" << val << ",";
942 }
943 }
944 else if (i==0 && frame.m_type==1) {
945 frame.m_cornerSize=val;
946 f << "size[corner]=" << val << ",";
947 }
948 else
949 f << "f" << i << "=" << val << ",";
950 }
951 val=int(input->readLong(2));
952 if (val!=-1) {
953 frame.m_pictureId=val;
954 f << "P" << val << ",";
955 }
956 val=int(input->readULong(2));
957 if (val) {
958 frame.m_rulerId=val;
959 f << "para=R" << val << ",";
960 }
961 val=int(input->readULong(2));
962 if (frame.m_type==2 && isMacFile) {
963 frame.m_textId=MWAWVec2i(tId,tId+val-1);
964 tId+=val;
965 f << "text=T" << frame.m_textId[0] << "<->T" << frame.m_textId[1] << ",";
966 }
967 val=int(input->readULong(2));
968 if (frame.m_type==1 && val && frame.m_pictureId<0) {
969 // unsure, find some rectangle with text, in this case this value is set
970 frame.m_type=3;
971 frame.m_textId=MWAWVec2i(tId,tId);
972 f << "textbox[small]=T" << tId++ << ",";
973 }
974 if (input->tell()!=pos+dataSz)
975 ascii().addDelimiter(input->tell(),'|');
976 input->seek(pos+dataSz, librevenge::RVNG_SEEK_SET);
977 ascii().addPos(pos);
978 ascii().addNote(f.str().c_str());
979 }
980 if (input->tell()!=entry.end()) {
981 ascii().addPos(input->tell());
982 ascii().addNote("Frames:extra");
983 }
984 ascii().addPos(entry.end());
985 ascii().addNote("_");
986 return true;
987 }
988
989 bool PowerPoint1Parser::readTextZone(MWAWEntry const &entry, PowerPoint1ParserInternal::TextZone &zone)
990 {
991 MWAWInputStreamPtr input=getInput();
992 bool isMacFile=m_state->m_isMacFile;
993 if (!entry.valid() || entry.length()<(isMacFile ? 6 : 32)) {
994 MWAW_DEBUG_MSG(("PowerPoint1Parser::readTextZone: the entry seems bad\n"));
995 return false;
996 }
997 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
998 long pos=input->tell();
999 libmwaw::DebugStream f;
1000 f << "Entries(TextZone)[Z" << entry.id() << "]:";
1001 int val;
1002 ascii().addPos(pos);
1003 ascii().addNote(f.str().c_str());
1004 long const endPos=entry.end();
1005 int n=0;
1006 while (input->tell()+6<=endPos) {
1007 PowerPoint1ParserInternal::TextZone::Line line;
1008 pos=input->tell();
1009 if (!isMacFile && pos+32>endPos)
1010 break;
1011 f.str("");
1012 f << "TextZone-T" << ++n << ":";
1013 if (isMacFile) {
1014 val=int(input->readLong(1));
1015 switch (val) {
1016 case 0: // left
1017 break;
1018 case 1:
1019 line.m_justify=MWAWParagraph::JustificationCenter;
1020 f << "center,";
1021 break;
1022 case 2:
1023 line.m_justify=MWAWParagraph::JustificationRight;
1024 f << "right,";
1025 break;
1026 case 3:
1027 line.m_justify=MWAWParagraph::JustificationFull;
1028 f << "justify,";
1029 break;
1030 default:
1031 MWAW_DEBUG_MSG(("PowerPoint1Parser::readTextZone: find unknown justification\n"));
1032 f << "##justify=" << val << ",";
1033 }
1034 line.m_outlineLevel=int(input->readLong(1));
1035 if (line.m_outlineLevel) f << "outline[levl]=" << line.m_outlineLevel << ",";
1036 }
1037 else if (entry.length()>32+16) {
1038 for (int i=0; i<16; ++i) { // f0=1|8|c|10,f1=d|12,f2=1|3f,f3=0|c,f5=sz|big number,f6=0-3,f7=0-1a,f9=0|1,f13=0-2,f14=0|5
1039 val=int(input->readLong(2));
1040 if (val)
1041 f << "f" << i << "=" << val << ",";
1042 }
1043 for (int i=0; i<4; ++i) {
1044 val=int(input->readULong(2));
1045 if (val) f << "g" << i << "=" << val << ",";
1046 }
1047 }
1048 else {
1049 input->seek(pos+32, librevenge::RVNG_SEEK_SET);
1050 ascii().addPos(pos);
1051 ascii().addNote(f.str().c_str());
1052 zone.m_lineList.push_back(line);
1053 break;
1054 }
1055 auto sSz=int(input->readULong(2));
1056 if (input->tell()+sSz+(isMacFile ? (sSz&1)+2:16)>endPos) {
1057 input->seek(pos, librevenge::RVNG_SEEK_SET);
1058 n--;
1059 break;
1060 }
1061 line.m_text.setBegin(input->tell());
1062 line.m_text.setLength(sSz);
1063 std::string text;
1064 for (int i=0; i<sSz; ++i) text+=char(input->readULong(1));
1065 f << text << ",";
1066 if (isMacFile && (sSz&1)) input->seek(1, librevenge::RVNG_SEEK_CUR);
1067 ascii().addPos(pos);
1068 ascii().addNote(f.str().c_str());
1069
1070 pos=input->tell();
1071 f.str("");
1072 f << "TextZone-F" << n << ":";
1073 if (isMacFile) {
1074 sSz=int(input->readULong(2));
1075 if ((sSz!=0 && sSz<6) || pos+2+sSz>endPos) {
1076 input->seek(pos, librevenge::RVNG_SEEK_SET);
1077 n--;
1078 break;
1079 }
1080 line.m_format.setBegin(pos+2);
1081 line.m_format.setLength(sSz);
1082 input->seek(sSz, librevenge::RVNG_SEEK_CUR);
1083 ascii().addPos(pos);
1084 ascii().addNote(f.str().c_str());
1085 }
1086 else {
1087 for (int i=0; i<3; ++i) {
1088 val=int(input->readULong(2));
1089 if (val) f << "f" << i << "=" << val << ",";
1090 }
1091 auto nFonts=int(input->readULong(2));
1092 if (pos+nFonts*14+8>endPos) {
1093 input->seek(pos, librevenge::RVNG_SEEK_SET);
1094 n--;
1095 break;
1096 }
1097 ascii().addPos(pos);
1098 ascii().addNote(f.str().c_str());
1099 line.m_format.setBegin(pos+8);
1100 line.m_format.setLength(nFonts*14);
1101 input->seek(nFonts*14, librevenge::RVNG_SEEK_CUR);
1102
1103 pos=input->tell();
1104 f.str("");
1105 f << "TextZone-R" << n << ":";
1106 for (int i=0; i<3; ++i) {
1107 val=int(input->readULong(2));
1108 if (val) f << "f" << i << "=" << val << ",";
1109 }
1110 auto nRulers=int(input->readULong(2));
1111 if (pos+nRulers*6>endPos) {
1112 input->seek(pos, librevenge::RVNG_SEEK_SET);
1113 n--;
1114 break;
1115 }
1116 line.m_ruler.setBegin(pos+8);
1117 line.m_ruler.setLength(nRulers*6);
1118 ascii().addPos(pos);
1119 ascii().addNote(f.str().c_str());
1120 input->seek(nRulers*6, librevenge::RVNG_SEEK_CUR);
1121 }
1122 zone.m_lineList.push_back(line);
1123 }
1124 if (n==0 && isMacFile) return false;
1125 entry.setParsed(true);
1126 ascii().addPos(endPos);
1127 ascii().addNote("_");
1128 pos=input->tell();
1129 if (pos!=endPos) {
1130 if (!isMacFile && pos<endPos && endPos<pos+32) {
1131 ascii().addPos(pos);
1132 ascii().addNote("TextZone-extra");
1133 }
1134 else {
1135 MWAW_DEBUG_MSG(("PowerPoint1Parser::readTextZone: find extra data\n"));
1136 ascii().addPos(pos);
1137 ascii().addNote("TextZone-###extra");
1138 }
1139 }
1140 return true;
1141 }
1142
1143 bool PowerPoint1Parser::readSlide(MWAWEntry const &entry, std::vector<int> &listIds)
1144 {
1145 int const isMacFile=m_state->m_isMacFile;
1146
1147 if (!entry.valid() || entry.length()!=(isMacFile ? 58 : 64)) {
1148 MWAW_DEBUG_MSG(("PowerPoint1Parser::readSlide: the entry %d seems bad\n", entry.id()));
1149 return false;
1150 }
1151 if (entry.isParsed()) return true;
1152 entry.setParsed(true);
1153 listIds.push_back(entry.id());
1154 PowerPoint1ParserInternal::Slide bugSlide;
1155 auto *slide=&bugSlide;
1156 if (m_state->m_idToSlideMap.find(entry.id())==m_state->m_idToSlideMap.end()) {
1157 m_state->m_idToSlideMap[entry.id()]=PowerPoint1ParserInternal::Slide();
1158 slide=&m_state->m_idToSlideMap.find(entry.id())->second;
1159 }
1160 else {
1161 MWAW_DEBUG_MSG(("PowerPoint1Parser::readSlide: oops, an slide already exists with id=%d\n", entry.id()));
1162 }
1163 MWAWInputStreamPtr input=getInput();
1164 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1165 libmwaw::DebugStream f;
1166 f << "Entries(Slide)[Z" << entry.id() << "]:";
1167 auto numZones=int(m_state->m_zonesList.size());
1168 long childIds[5]= {-1,-1,-1,-1,-1};
1169 long id=input->readLong(4);
1170 if (id>=0 && id<numZones) {
1171 childIds[0]=id;
1172 f << "prev[page]=Z" << id << ",";
1173 }
1174 else if (id!=-1) // can happen in the last slide
1175 f << "#prev[page]=" << id << ",";
1176 int val;
1177 for (int i=0; i<3; ++i) { //f2=0
1178 val=int(input->readLong(2));
1179 if (val) f << "f" << i << "=" << val << ",";
1180 }
1181 if (isMacFile) {
1182 f << "ids=[";
1183 for (int i=0; i<2; ++i) { // two big num or 0
1184 val=int(input->readULong(4));
1185 if (val)
1186 f << std::hex << val << std::dec << ",";
1187 else
1188 f << "_,";
1189 }
1190 f << "],";
1191 }
1192 val=int(input->readULong(2)); // always 0
1193 if (val)
1194 f << "f3=" << val << ",";
1195 id=int(input->readULong(2));
1196 if (id>=0 && id<numZones) {
1197 childIds[1]=id;
1198 f << "text=Z" << id << ",";
1199 }
1200 else if (id!=0xFFFF) // can happen in the last slide
1201 f << "#text=" << id << ",";
1202 val=int(input->readLong(2)); // 0
1203 if (val) f << "f4=" << val << ",";
1204 if (isMacFile) {
1205 val=int(input->readULong(2)); // always 0
1206 if (val)
1207 f << "f5=" << val << ",";
1208 }
1209 id=int(input->readULong(2));
1210 if (id>=0 && id<numZones) {
1211 childIds[2]=id;
1212 f << "frame=Z" << id << ",";
1213 }
1214 else if (id!=0xFFFF) // can happen in the last slide
1215 f << "#frame=" << id << ",";
1216 val=int(input->readLong(2));
1217 if (val) f << "num[frames]=" << val << ",";
1218 val=int(input->readLong(1));
1219 if (val==0) {
1220 slide->m_useMasterPage=false;
1221 f << "no[master],";
1222 }
1223 else if (val!=1)
1224 f << "#use[master]=" << val << ",";
1225 val=int(input->readLong(1)); // always 0
1226 if (val) f << "f6=" << val << ",";
1227 if (!isMacFile) {
1228 // maybe junk
1229 val=int(input->readULong(2));
1230 if (val)
1231 f << "f7=" << std::hex << val << std::dec << ",";
1232 }
1233 val=int(input->readULong(2));
1234 if (val>=0 && val<int(m_state->m_schemesIdList.size())) {
1235 slide->m_schemeId=val;
1236 f << "scheme=S" << val << ",";
1237 }
1238 else if (val)
1239 f << "#scheme=" << val << ",";
1240 if (isMacFile) {
1241 // maybe junk
1242 val=int(input->readULong(2));
1243 if (val)
1244 f << "f7=" << std::hex << val << std::dec << ",";
1245 }
1246 val=int(input->readULong(2)); // 0 or big number
1247 if (val) f << "g0=" << std::hex << val << std::dec << ",";
1248 val=int(input->readLong(2));
1249 if (val) f << "g1=" << val << ",";
1250 id=int(input->readULong(2));
1251 val=isMacFile ? int(input->readLong(2)) : 0; // 0 or junk ?
1252 if (val==0 && id>0 && id<numZones) {
1253 childIds[3]=id;
1254 f << "note[text]=Z" << id << ",";
1255 }
1256 else if (val==0 && id!=0 && id!=0xFFFF) { // can be bad
1257 f << "#note[text]=" << id << ",";
1258 }
1259 val=int(input->readULong(2)); // 0
1260 if (val) f << "g2=" << val << ",";
1261 id=int(input->readULong(2));
1262 val=int(input->readLong(2)); // 1|2 or junk
1263 if (val>=1 && val<32) {
1264 if (id>0 && id<numZones) {
1265 childIds[4]=id;
1266 f << "note[frame]=Z" << id << ",";
1267 f << "num[note,frame]=" << val << ",";
1268 }
1269 else if (id!=0 && id!=0xFFFF) { // can be bad
1270 f << "#note[frame]=" << id << ",";
1271 }
1272 }
1273 for (int i=0; i<2; ++i) { // g3=1|junk, g4=0|1|junk
1274 val=int(input->readLong(1));
1275 if (val!=1) f << "g" << i+3 << "=" << val << ",";
1276 }
1277 ascii().addDelimiter(input->tell(),'|');
1278 ascii().addPos(entry.begin());
1279 ascii().addNote(f.str().c_str());
1280 ascii().addPos(entry.end());
1281 ascii().addNote("_");
1282
1283 // now read the child zone
1284 for (int i=0; i<5; ++i) {
1285 long const cId=childIds[i];
1286 if (cId<0 || cId>=numZones) continue;
1287 MWAWEntry const &childEntry=m_state->m_zonesList[size_t(cId)];
1288 if (!childEntry.valid()) continue;
1289 if (i==0 && childEntry.isParsed()) {
1290 // we do not want loop here
1291 MWAW_DEBUG_MSG(("PowerPoint1Parser::readSlide: the entry %d is already parsed, we may loose some part\n", int(cId)));
1292 continue;
1293 }
1294 if (i==0) readSlide(childEntry, listIds);
1295 else if ((i%2)==1) readTextZone(childEntry, slide->m_textZones[i/2]);
1296 else readFramesList(childEntry, slide->m_framesList[i/2-1], slide->m_schemeId);
1297 }
1298 return true;
1299 }
1300
1301 bool PowerPoint1Parser::readDocInfo(MWAWEntry const &entry)
1302 {
1303 MWAWInputStreamPtr input=getInput();
1304 int vers=version();
1305 int const isMacFile=m_state->m_isMacFile;
1306 bool ok=entry.valid() && vers==1;
1307 if (ok && !isMacFile) {
1308 ok=entry.length()==192;
1309 vers=2;
1310 setVersion(vers);
1311 }
1312 else if (ok && entry.length()==164) {
1313 vers=2;
1314 setVersion(vers);
1315 }
1316 else
1317 ok=ok && entry.length()==160;
1318 if (!ok) {
1319 MWAW_DEBUG_MSG(("PowerPoint1Parser::readDocInfo: the entry %d seems bad\n", entry.id()));
1320 return false;
1321 }
1322 entry.setParsed(true);
1323 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1324 long pos=input->tell();
1325 libmwaw::DebugStream f;
1326 f << "Entries(DocInfo)[Z" << entry.id() << "]:";
1327 int val;
1328 auto numZones=int(m_state->m_zonesList.size());
1329 f << "unkn=[";
1330 for (int i=0; i<4; ++i) { // list of 0 or big number
1331 val=int(input->readLong(2));
1332 if (val) f << val << ",";
1333 else f << "_,";
1334 }
1335 f << "],";
1336 int numId=isMacFile ? 1 : 2;
1337 for (int i=0; i<numId; ++i) {
1338 val=int(input->readLong(2));
1339 if (val) f << "id" << i << "=" << std::hex << val << std::dec << ",";
1340 }
1341 for (int i=0; i<2; ++i) { // f0=3|6, f1=0
1342 val=int(input->readLong(1));
1343 if (val) f << "f" << i << "=" << val << ",";
1344 }
1345 int dim[4];
1346 for (auto &d : dim) d=int(input->readLong(2));
1347 f << "dim[screen]=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
1348 int pages[2];
1349 for (auto &p : pages) p=int(input->readLong(2));
1350 f << "num[pages]=" << pages[0] << ",";
1351 if (pages[0]!=pages[1]) f << "act[page]=" << pages[1] << ",";
1352 for (int i=0; i<2; ++i) { // id1=0, id2=0|big number
1353 val=int(input->readULong(!isMacFile ? 2 : 4));
1354 if (val) f << "id" << i+2 << "=" << std::hex << val << std::dec << ",";
1355 }
1356 if (isMacFile) {
1357 val=int(input->readLong(2)); // 0
1358 if (val) f << "f4=" << val << ",";
1359 }
1360 m_state->m_slideIds[0]=int(input->readULong(2));
1361 f << "slide[id]=Z" << m_state->m_slideIds[0] << ",";
1362 if (m_state->m_slideIds[0]>=numZones) {
1363 MWAW_DEBUG_MSG(("PowerPoint1Parser::readDocInfo: the slideId %d seems bad\n", m_state->m_slideIds[0]));
1364 f << "###";
1365 m_state->m_slideIds[0]=-1;
1366 }
1367 for (int i=0; i<2; ++i) { // two big number
1368 val=int(input->readULong(!isMacFile ? 2 : 4));
1369 if (val) f << "id" << i+4 << "=" << std::hex << val << std::dec << ",";
1370 }
1371 for (int &i : dim) i=int(input->readLong(2));
1372 if (!isMacFile) {
1373 std::swap(dim[0],dim[1]);
1374 std::swap(dim[2],dim[3]);
1375 }
1376 MWAWBox2i pageBox(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2]));
1377 f << "dim[page]=" << pageBox << ",";
1378 for (int &i : dim) i=int(input->readLong(2));
1379 if (!isMacFile) {
1380 std::swap(dim[0],dim[1]);
1381 std::swap(dim[2],dim[3]);
1382 }
1383 MWAWBox2i paperBox(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2]));
1384 paperBox=MWAWBox2i(MWAWVec2i(dim[0],dim[1]),MWAWVec2i(dim[2],dim[3]));
1385 f << "dim[paper]=" << paperBox << ",";
1386 m_state->m_origin=-1*paperBox[0];
1387 MWAWVec2i paperSize = paperBox.size();
1388 MWAWVec2i pageSize = pageBox.size();
1389 if (pageSize.x() <= 0 || pageSize.y() <= 0 ||
1390 paperSize.x() <= 0 || paperSize.y() <= 0) {
1391 MWAW_DEBUG_MSG(("PowerPoint1Parser::readDocInfo: the page dimension seems bad\n"));
1392 }
1393 else {
1394 double const unit=double(m_state->m_unit);
1395 // checkme, maybe better to define a slide with pageSize and no margins
1396 getPageSpan().setFormOrientation(MWAWPageSpan::PORTRAIT);
1397 if (pageBox[0][1]>=paperBox[0][1])
1398 getPageSpan().setMarginTop(double(pageBox[0][1]-paperBox[0][1])*unit/72.0);
1399 if (pageBox[1][1]<=paperBox[1][1])
1400 getPageSpan().setMarginBottom(double(paperBox[1][1]-pageBox[1][1])*unit/72.0);
1401 if (pageBox[0][0]>=paperBox[0][0])
1402 getPageSpan().setMarginLeft(double(pageBox[0][0]-paperBox[0][0])*unit/72.0);
1403 if (pageBox[1][0]<=paperBox[1][0])
1404 getPageSpan().setMarginRight(double(paperBox[1][0]-pageBox[1][0])*unit/72.0);
1405 getPageSpan().setFormLength(double(paperSize.y())*unit/72.);
1406 getPageSpan().setFormWidth(double(paperSize.x())*unit/72.);
1407 }
1408 if (isMacFile) {
1409 val=int(input->readLong(2)); // 0
1410 if (val) f << "f5=" << val << ",";
1411 }
1412 m_state->m_slideIds[1]=int(input->readULong(2));
1413 f << "slide[handout,id]=Z" << m_state->m_slideIds[1] << ",";
1414 if (m_state->m_slideIds[1]>=numZones) {
1415 MWAW_DEBUG_MSG(("PowerPoint1Parser::readDocInfo: the slideIds[1] %d seems bad\n", m_state->m_slideIds[1]));
1416 f << "###";
1417 m_state->m_slideIds[1]=-1;
1418 }
1419 ascii().addPos(pos);
1420 ascii().addNote(f.str().c_str());
1421
1422 pos=input->tell();
1423 f.str("");
1424 f << "DocInfo-2:";
1425 val=int(input->readULong(!isMacFile ? 2 : 4));
1426 if (val) f << "id=" << std::hex << val << std::dec << ",";
1427 for (auto &d : dim) d=int(input->readLong(2));
1428 f << "dim=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
1429 val=int(input->readLong(1)); // 0|1
1430 if (val) f << "f0=" << val << ",";
1431 val=int(input->readLong(2)); // 0 or big number
1432 if (val) f << "f1=" << val << ",";
1433 val=int(input->readULong(1)); // 2..80
1434 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1435 if (!isMacFile) {
1436 val=int(input->readLong(2)); // 1|25|26
1437 if (val) f << "f2=" << val << ",";
1438 }
1439 for (int i=0; i<2; ++i) { // 0
1440 val=int(input->readLong(2));
1441 if (val) f << "f" << 3+i << "=" << val << ",";
1442 }
1443 for (auto &d : dim) d=int(input->readLong(2));
1444 f << "dim2=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
1445 f << "unkn=[";
1446 for (int i=0; i<3; ++i) { // 3 small int
1447 val=int(input->readLong(2));
1448 if (val) f << val << ",";
1449 else f << "_,";
1450 }
1451 f << "],";
1452 val=int(input->readULong(1)); // 2
1453 if (val!=2) f << "fl1=" << val << ",";
1454 val=int(input->readLong(2)); // 1
1455 if (val!=1) f << "f5=" << val << ",";
1456 ascii().addDelimiter(input->tell(),'|');
1457 input->seek(pos+(!isMacFile ? 66 : 48), librevenge::RVNG_SEEK_SET);
1458 ascii().addPos(pos);
1459 ascii().addNote(f.str().c_str());
1460
1461 pos=input->tell();
1462 f.str("");
1463 f << "DocInfo-3:";
1464 f << "zones=[";
1465 int numSubZone=isMacFile ? 5+vers : 10;
1466 for (int i=0; i<numSubZone; ++i) {
1467 // 0: picture zones, 1: picture pos?, 2: some style?,
1468 long id=input->readLong(!isMacFile ? 2 : 4);
1469 if (id==0 || id==-1)
1470 f << "_,";
1471 else if (id>0 && id<numZones) {
1472 f << "Z" << id << ",";
1473 m_state->m_zoneIds[i]=int(id);
1474 }
1475 else {
1476 MWAW_DEBUG_MSG(("PowerPoint1Parser::readDocInfo: find odd zone\n"));
1477 f << "###" << id << ",";
1478 }
1479 }
1480 f << "],";
1481 for (auto &d: dim) d=int(input->readULong(2));
1482 f << "page=" << MWAWVec2i(dim[0],dim[1]) << ",";
1483 f << "dim?=" << MWAWVec2i(dim[3],dim[2]) << ","; // frame, slide dim?
1484 for (int i=0; i<2; ++i) { // f0=1, f1=0|80
1485 val=int(input->readULong(2));
1486 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1487 }
1488 for (int i=0; i<2; ++i) {
1489 m_state->m_printInfoIds[i]= int(input->readULong(2));
1490 if (!m_state->m_printInfoIds[i]) continue;
1491 f << "printInfo[id" << i << "]=Z" << m_state->m_printInfoIds[i] << ",";
1492 if (m_state->m_printInfoIds[i]>=numZones) {
1493 MWAW_DEBUG_MSG(("PowerPoint1Parser::readDocInfo: the printInfoId %d seems bad\n", m_state->m_printInfoIds[i]));
1494 f << "###";
1495 m_state->m_printInfoIds[i]=-1;
1496 }
1497 }
1498 if (isMacFile) {
1499 for (int i=0; i<4; ++i) { // 0
1500 val=int(input->readULong(2));
1501 if (val) f << "g" << i << "=" << val << ",";
1502 }
1503 }
1504 else
1505 ascii().addDelimiter(input->tell(),'|');
1506 ascii().addPos(pos);
1507 ascii().addNote(f.str().c_str());
1508 ascii().addPos(entry.end());
1509 ascii().addNote("_");
1510
1511 return true;
1512 }
1513
1514 bool PowerPoint1Parser::readPictureDefinition(MWAWEntry const &entry, size_t pId)
1515 {
1516 if (!entry.valid() || entry.length()<28) {
1517 MWAW_DEBUG_MSG(("PowerPoint1Parser::readPictureDefinition: the zone seems bad\n"));
1518 return false;
1519 }
1520 MWAWInputStreamPtr input = getInput();
1521 long pos = entry.begin();
1522 entry.setParsed(true);
1523 ascii().addPos(entry.end());
1524 ascii().addNote("_");
1525 input->seek(pos, librevenge::RVNG_SEEK_SET);
1526 libmwaw::DebugStream f;
1527 f << "Entries(Picture)[Z"<< entry.id() << "-" << pId << "]:def,";
1528 auto val=int(input->readULong(2)); // big number [0-3]XXX
1529 if (val) f << "id=" << std::hex << val << std::dec << ",";
1530 auto type=int(input->readULong(2)); // 1-4
1531 if (type)
1532 f << "type=" << type << ",";
1533 int dim[4];
1534 for (auto &d : dim) d=int(input->readLong(2));
1535 f << "dim=" << MWAWBox2i(MWAWVec2i(dim[0],dim[1]),MWAWVec2i(dim[2],dim[3])) << ",";
1536 val=int(input->readULong(2));
1537 if (val!=2) {
1538 f << "###type2=" << val << ",";
1539 MWAW_DEBUG_MSG(("PowerPoint1Parser::readPictureDefinition: find unexpected type 2\n"));
1540 }
1541 auto child=int(input->readULong(2));
1542 if (child>=0 && child<int(m_state->m_zonesList.size())) {
1543 f << "child[id]=Z" << child << ",";
1544 if (pId>=m_state->m_picturesIdList.size())
1545 m_state->m_picturesIdList.resize(pId+1,-1);
1546 m_state->m_picturesIdList[pId]=child;
1547 }
1548 else {
1549 MWAW_DEBUG_MSG(("PowerPoint1Parser::readPictureDefinition: find some bad child\n"));
1550 f << "child[id]=##Z" << child << ",";
1551 }
1552 if (type==4) {
1553 for (int i=0; i<3; ++i) {
1554 val=int(input->readULong(2));
1555 child=int(input->readULong(2));
1556 if (child>=0 && child<int(m_state->m_zonesList.size())) {
1557 f << "child" << i << "[id]=Z" << child << "[" << val << "],";
1558 MWAWEntry const &cEntry=m_state->getZoneEntry(child);
1559 if (!cEntry.valid() || cEntry.isParsed()) continue;
1560 // find type=10,14(string: Graph),16(probably the graph structure)
1561 cEntry.setParsed(true);
1562 libmwaw::DebugStream f2;
1563 f2 << "Entries(Pict" << val << "):";
1564 ascii().addPos(cEntry.begin());
1565 ascii().addNote(f2.str().c_str());
1566 }
1567 else {
1568 MWAW_DEBUG_MSG(("PowerPoint1Parser::readPictureDefinition: find some bad child\n"));
1569 f << "child" << i << "[id]=##Z" << child << "[" << val << "],";
1570 }
1571 }
1572 }
1573 ascii().addDelimiter(input->tell(),'|');
1574 ascii().addPos(pos);
1575 ascii().addNote(f.str().c_str());
1576 return true;
1577 }
1578
1579 bool PowerPoint1Parser::readPicture(MWAWEntry const &entry, MWAWEmbeddedObject &picture)
1580 {
1581 if (!entry.valid() || entry.length()<20) {
1582 MWAW_DEBUG_MSG(("PowerPoint1Parser::readPicture: the zone seems bad\n"));
1583 return false;
1584 }
1585 MWAWInputStreamPtr input = getInput();
1586 long pos = entry.begin();
1587 entry.setParsed(true);
1588 input->seek(pos, librevenge::RVNG_SEEK_SET);
1589
1590 ascii().skipZone(pos, entry.end()-1);
1591 librevenge::RVNGBinaryData file;
1592 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1593 input->readDataBlock(entry.length(), file);
1594 picture.add(file);
1595 #ifdef DEBUG_WITH_FILES
1596 static int volatile pictName = 0;
1597 libmwaw::DebugStream f;
1598 f << "PICT-" << ++pictName << ".pct";
1599 libmwaw::Debug::dumpFile(file, f.str().c_str());
1600 #endif
1601
1602 ascii().addPos(entry.end());
1603 ascii().addNote("_");
1604
1605 return true;
1606 }
1607
1608 bool PowerPoint1Parser::readZoneIdList(MWAWEntry const &entry, int zId)
1609 {
1610 if (!entry.valid() || (entry.length()%6) != 0) {
1611 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZoneIdList: the zone seems bad\n"));
1612 return false;
1613 }
1614 if (zId!=0 && zId!=3) {
1615 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZoneIdList: find unexpected zone id=%d\n", zId));
1616 }
1617 MWAWInputStreamPtr input = getInput();
1618 long pos = entry.begin();
1619 entry.setParsed(true);
1620 input->seek(pos, librevenge::RVNG_SEEK_SET);
1621
1622 libmwaw::DebugStream f;
1623 std::string const wh(zId==0 ? "PictureList" : zId==3 ? "Scheme" : "UnknownList");
1624 f << "Entries(" << wh << ")[Z"<< entry.id() << "]:";
1625 ascii().addPos(pos);
1626 ascii().addNote(f.str().c_str());
1627 auto N=size_t(entry.length()/6);
1628 auto const numZones=int(m_state->m_zonesList.size());
1629 std::vector<int> unknownList;
1630 std::vector<int> &list=zId==0 ? m_state->m_picturesIdList : zId==3 ? m_state->m_schemesIdList : unknownList;
1631 list.resize(N, -1);
1632 for (size_t i=0; i<N; ++i) {
1633 pos=input->tell();
1634 f.str("");
1635 if (zId==0)
1636 f << "PictureList-P" << i << ":";
1637 else if (zId==3)
1638 f << "Scheme-S" << i << ":";
1639 else
1640 f << wh << "-" << i << ":";
1641 auto type=int(input->readULong(2));
1642 auto id=int(input->readLong(4));
1643 if (type==0 || id==-1) {
1644 f << "_,";
1645 ascii().addPos(pos);
1646 ascii().addNote(f.str().c_str());
1647 continue;
1648 }
1649 f << "Z" << id << ":" << type;
1650 if (id<0 || id>=numZones) {
1651 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZoneIdList: the picture id seems bad\n"));
1652 f << "###";
1653 }
1654 else
1655 list[i]=id;
1656 ascii().addPos(pos);
1657 ascii().addNote(f.str().c_str());
1658 }
1659 ascii().addPos(entry.end());
1660 ascii().addNote("_");
1661 return true;
1662 }
1663
1664 bool PowerPoint1Parser::readZoneIdList2(MWAWEntry const &entry, int zId)
1665 {
1666 if (!entry.valid() || entry.length()<16 || (entry.length()%4) != 0) {
1667 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZoneIdList2: the zone seems bad\n"));
1668 return false;
1669 }
1670 MWAWInputStreamPtr input = getInput();
1671 long pos = entry.begin();
1672 entry.setParsed(true);
1673 input->seek(pos, librevenge::RVNG_SEEK_SET);
1674
1675 libmwaw::DebugStream f;
1676 std::string const wh(zId==0 ? "Picture" : zId==1 ? "Ruler" : zId==2 ? "Scheme" : "UnknownList");
1677 f << "Entries(" << wh << ")[Z"<< entry.id() << "]:list,";
1678 auto val=int(input->readULong(2)); // 8001
1679 if (val!=0x8001) f << "f0=" << std::hex << val << std::dec << ",";
1680 val=int(input->readULong(2)); // big number
1681 if (val) f << "id=" << std::hex << val << std::dec << ",";
1682 auto N=size_t(input->readULong(2));
1683 f << "N=" << N << ",";
1684 if (16+4*long(N)>entry.length()) {
1685 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZoneIdList2: the N value seems bad\n"));
1686 f << "###";
1687 ascii().addPos(pos);
1688 ascii().addNote(f.str().c_str());
1689 ascii().addPos(entry.end());
1690 ascii().addNote("_");
1691 return false;
1692 }
1693 for (int i=0; i<5; ++i) {
1694 val=int(input->readULong(2));
1695 int const expected[]= {0x7fff, 0, 2, 0, 0};
1696 if (val!=expected[i])
1697 f << "f" << i+2 << "=" << val << ",";
1698 }
1699 ascii().addPos(pos);
1700 ascii().addNote(f.str().c_str());
1701 auto const numZones=int(m_state->m_zonesList.size());
1702 std::vector<int> list;
1703 list.resize(N, -1);
1704 for (size_t i=0; i<N; ++i) {
1705 pos=input->tell();
1706 f.str("");
1707 if (zId==0)
1708 f << "Picture-P" << i << ":";
1709 else if (zId==1)
1710 f << "Ruler-R" << i << ":";
1711 else if (zId==2)
1712 f << "Scheme-S" << i << ":";
1713 else
1714 f << wh << "-" << i << ":";
1715 auto type=int(input->readULong(2));
1716 auto id=int(input->readLong(2));
1717 if (type==0 || id==-1) {
1718 f << "_,";
1719 ascii().addPos(pos);
1720 ascii().addNote(f.str().c_str());
1721 continue;
1722 }
1723 f << "Z" << id << ":" << type;
1724 if (id<0 || id>=numZones) {
1725 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZoneIdList2: the picture id seems bad\n"));
1726 f << "###";
1727 }
1728 else
1729 list[i]=id;
1730 ascii().addPos(pos);
1731 ascii().addNote(f.str().c_str());
1732 }
1733 if (input->tell()!=entry.end()) {
1734 ascii().addPos(input->tell());
1735 ascii().addNote("UnkList:extra");
1736 }
1737 ascii().addPos(entry.end());
1738 ascii().addNote("_");
1739 if (zId==2)
1740 m_state->m_schemesIdList=list;
1741 else {
1742 f.str("");
1743 f << "Entries(UnknList" << zId << "):";
1744 for (size_t i=0; i<N; ++i) {
1745 if (list[i]==-1) continue;
1746 MWAWEntry const &cEntry=m_state->getZoneEntry(list[i]);
1747 if (!cEntry.valid() || cEntry.isParsed()) continue;
1748 if (zId==0)
1749 readPictureDefinition(cEntry, i);
1750 else if (zId==1)
1751 readRuler(cEntry, i);
1752 else {
1753 cEntry.setParsed(true);
1754 ascii().addPos(cEntry.begin());
1755 ascii().addNote(f.str().c_str());
1756 ascii().addPos(cEntry.end());
1757 ascii().addNote("_");
1758 }
1759 }
1760 }
1761 return true;
1762 }
1763
1764 bool PowerPoint1Parser::readPrintInfo(MWAWEntry const &entry)
1765 {
1766 if (entry.length() != 0x78) {
1767 MWAW_DEBUG_MSG(("PowerPoint1Parser::readPrintInfo: the zone seems bad\n"));
1768 return false;
1769 }
1770 MWAWInputStreamPtr input = getInput();
1771 long pos = entry.begin();
1772 entry.setParsed(true);
1773 input->seek(pos, librevenge::RVNG_SEEK_SET);
1774 libmwaw::DebugStream f;
1775 // print info
1776 libmwaw::PrinterInfo info;
1777 if (!info.read(input)) return false;
1778 f << "Entries(PrintInfo)[Z"<< entry.id() << "]:" << info;
1779
1780 // this is the final paper, so let ignore this
1781 MWAWVec2i paperSize = info.paper().size();
1782 MWAWVec2i pageSize = info.page().size();
1783 if (pageSize.x() <= 0 || pageSize.y() <= 0 ||
1784 paperSize.x() <= 0 || paperSize.y() <= 0) return false;
1785 ascii().addPos(pos);
1786 ascii().addNote(f.str().c_str());
1787
1788 ascii().addPos(entry.end());
1789 ascii().addNote("_");
1790
1791 return true;
1792 }
1793
1794 bool PowerPoint1Parser::readRulers(MWAWEntry const &entry)
1795 {
1796 if (!entry.valid() || (entry.length()%66)!=0) {
1797 MWAW_DEBUG_MSG(("PowerPoint1Parser::readRulers: the zone seems bad\n"));
1798 return false;
1799 }
1800 MWAWInputStreamPtr input = getInput();
1801 long pos = entry.begin();
1802 entry.setParsed(true);
1803 input->seek(pos, librevenge::RVNG_SEEK_SET);
1804 libmwaw::DebugStream f;
1805 f << "Entries(Ruler)[Z"<< entry.id() << "]:";
1806 ascii().addPos(pos);
1807 ascii().addNote(f.str().c_str());
1808
1809 auto N=size_t(entry.length()/66);
1810 m_state->m_rulersList.resize(N);
1811 for (size_t i=0; i<N; ++i) {
1812 pos=input->tell();
1813 f.str("");
1814 f << "Ruler-R" << i+1 << ":";
1815 auto &ruler=m_state->m_rulersList[i];
1816 auto val=int(input->readULong(2)); // 1, 2, 5, 8, 1fff, 2000, 2001,
1817 if (val) f << "f0=" << std::hex << val << std::dec << ",";
1818 auto nTabs=int(input->readULong(2));
1819 if (nTabs>10) {
1820 MWAW_DEBUG_MSG(("PowerPoint1Parser::readRulers: the number of tab seems bad\n"));
1821 f << "###n[tabs]=" << nTabs << ",";
1822 nTabs=0;
1823 }
1824 std::vector<int> tPos;
1825 for (int j=0; j<nTabs; ++j) tPos.push_back(int(input->readULong(2)));
1826 input->seek(pos+24, librevenge::RVNG_SEEK_SET);
1827 val=int(input->readULong(2));
1828 f << "tabs=[";
1829 for (int j=0, bit=1; j<nTabs; ++j, bit<<=1) {
1830 MWAWTabStop tab;
1831 tab.m_position=double(tPos[size_t(j)])/72.;
1832 tab.m_alignment=(val&bit) ? MWAWTabStop::CENTER : MWAWTabStop::LEFT;
1833 ruler.m_tabs.push_back(tab);
1834 f << tab << ",";
1835 }
1836 f << "],";
1837 f << "levels=[";
1838 for (auto &outline : ruler.m_outlines) {
1839 f << "[";
1840 for (int &margin : outline.m_margins) margin=int(input->readULong(2));
1841 for (int &interline : outline.m_interlines) interline=10*int(input->readULong(1));
1842 f << outline << ",";
1843 f << "fl=" << std::hex << input->readULong(2) << std::dec << ",";
1844 f << "],";
1845 }
1846 f << "],";
1847 input->seek(pos+66, librevenge::RVNG_SEEK_SET);
1848 ascii().addPos(pos);
1849 ascii().addNote(f.str().c_str());
1850 }
1851 ascii().addPos(entry.end());
1852 ascii().addNote("_");
1853 return true;
1854 }
1855
1856 bool PowerPoint1Parser::readRuler(MWAWEntry const &entry, size_t id)
1857 {
1858 if (!entry.valid() || (entry.length()<54)!=0) {
1859 MWAW_DEBUG_MSG(("PowerPoint1Parser::readRuler: the zone seems bad\n"));
1860 return false;
1861 }
1862 MWAWInputStreamPtr input = getInput();
1863 long pos = entry.begin();
1864 entry.setParsed(true);
1865 input->seek(pos, librevenge::RVNG_SEEK_SET);
1866 libmwaw::DebugStream f;
1867 f << "Entries(Ruler)[Z"<< entry.id() << "]:R" << id << ",";
1868
1869 if (m_state->m_rulersList.size()<id+1)
1870 m_state->m_rulersList.resize(id+1);
1871 PowerPoint1ParserInternal::Ruler &ruler=m_state->m_rulersList[id];
1872 f << "levels=[";
1873 for (auto &outline : ruler.m_outlines) {
1874 f << "[";
1875 for (int &margin : outline.m_margins) margin=int(input->readULong(2));
1876 for (int &interline : outline.m_interlines) interline=int(input->readULong(2));
1877 f << outline << ",";
1878 f << "fl=" << std::hex << input->readULong(2) << std::dec << ",";
1879 f << "],";
1880 }
1881 f << "],";
1882 auto val=int(input->readULong(2)); // 2-3: align?
1883 if (val!=3) f << "f0=" << val << ",";
1884 auto nTabs=int(input->readULong(2));
1885 if (input->tell()+4*nTabs>entry.end()) {
1886 MWAW_DEBUG_MSG(("PowerPoint1Parser::readRuler: the number of tab seems bad\n"));
1887 f << "###n[tabs]=" << nTabs << ",";
1888 nTabs=0;
1889 }
1890 f << "tabs=[";
1891 for (int j=0; j<nTabs; ++j) {
1892 MWAWTabStop tab;
1893 tab.m_position=double(input->readULong(2))/8./72.;
1894 val=int(input->readULong(2));
1895 switch (val) {
1896 case 0:
1897 tab.m_alignment=MWAWTabStop::DECIMAL;
1898 break;
1899 case 1:
1900 tab.m_alignment=MWAWTabStop::RIGHT;
1901 break;
1902 case 2:
1903 tab.m_alignment=MWAWTabStop::CENTER;
1904 break;
1905 case 3:
1906 tab.m_alignment=MWAWTabStop::LEFT;
1907 break;
1908 default:
1909 MWAW_DEBUG_MSG(("PowerPoint1Parser::readRuler: find unknown alignment\n"));
1910 f << "##align=" << val << ",";
1911 break;
1912 }
1913 ruler.m_tabs.push_back(tab);
1914 f << tab << ",";
1915 }
1916 f << "],";
1917 if (input->tell()!=entry.end())
1918 ascii().addDelimiter(input->tell(),'|');
1919 ascii().addPos(pos);
1920 ascii().addNote(f.str().c_str());
1921 return true;
1922 }
1923
1924
1925 bool PowerPoint1Parser::readColors(MWAWEntry const &entry)
1926 {
1927 if (!entry.valid() || (entry.length()%8)!=0) {
1928 MWAW_DEBUG_MSG(("PowerPoint1Parser::readColors: the zone seems bad\n"));
1929 return false;
1930 }
1931 MWAWInputStreamPtr input = getInput();
1932 long pos = entry.begin();
1933 entry.setParsed(true);
1934 input->seek(pos, librevenge::RVNG_SEEK_SET);
1935 bool const isMacFile=m_state->m_isMacFile;
1936 libmwaw::DebugStream f;
1937 f << "Entries(Color)[Z"<< entry.id() << "]:";
1938 int val;
1939 for (int i=0; i<3; ++i) { // always 0
1940 val=int(input->readLong(2));
1941 if (val) f << "f" << i << "=" << val << ",";
1942 }
1943 auto N=int(input->readULong(2));
1944 f << "N=" << N << ",";
1945 if ((isMacFile && 8+(N+1)*8 != int(entry.length())) || (!isMacFile && 8+(N+1)*8 > int(entry.length()))) {
1946 MWAW_DEBUG_MSG(("PowerPoint1Parser::readColors: the N value seems bad\n"));
1947 f << "###";
1948 ascii().addPos(pos);
1949 ascii().addNote(f.str().c_str());
1950 ascii().addPos(entry.end());
1951 ascii().addNote("_");
1952 return true;
1953 }
1954 ascii().addPos(pos);
1955 ascii().addNote(f.str().c_str());
1956 ascii().addPos(entry.end());
1957 ascii().addNote("_");
1958 // cmyk picker 32-33-34-35
1959 for (int i=0; i<=N; ++i) {
1960 pos=input->tell();
1961 f.str("");
1962 f << "Color-C" << i << ":";
1963 val=int(input->readLong(2));
1964 if (val) {
1965 unsigned char col[3];
1966 for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8);
1967 MWAWColor color(col[0],col[1],col[2]);
1968 m_state->m_idToUserColorMap[i]=color;
1969 f << color << ",";
1970 }
1971 else
1972 f << "_,";
1973 input->seek(pos+8, librevenge::RVNG_SEEK_SET);
1974 ascii().addPos(pos);
1975 ascii().addNote(f.str().c_str());
1976 }
1977 if (input->tell()!=entry.end()) {
1978 ascii().addPos(input->tell());
1979 ascii().addNote("Color:extra");
1980 }
1981 return true;
1982 }
1983
1984 bool PowerPoint1Parser::readColorZone(MWAWEntry const &entry)
1985 {
1986 bool const isMacFile=m_state->m_isMacFile;
1987 if (!entry.valid() || (entry.length()<(isMacFile ? 48 : 43))) {
1988 MWAW_DEBUG_MSG(("PowerPoint1Parser::readColorZone: the zone seems bad\n"));
1989 return false;
1990 }
1991 MWAWInputStreamPtr input = getInput();
1992 long pos = entry.begin();
1993 entry.setParsed(true);
1994 input->seek(pos, librevenge::RVNG_SEEK_SET);
1995 libmwaw::DebugStream f;
1996 f << "Entries(Color)[Z"<< entry.id() << "]:menu,";
1997 auto N=int(input->readULong(2));
1998 f << "N=" << N << ",";
1999 if ((isMacFile && 48+2*N!=int(entry.length())) || (!isMacFile && 43+2*N>int(entry.length()))) {
2000 MWAW_DEBUG_MSG(("PowerPoint1Parser::readColorZone: the N value seems bad\n"));
2001 f << "###";
2002 ascii().addPos(pos);
2003 ascii().addNote(f.str().c_str());
2004 ascii().addPos(entry.end());
2005 ascii().addNote("_");
2006 return true;
2007 }
2008 auto val=int(input->readLong(2)); // always a
2009 if (val!=10) f << "f0=" << val << ",";
2010 auto id=int(input->readLong(isMacFile ? 4 : 2));
2011 auto const numZones=int(m_state->m_zonesList.size());
2012 if (id>0 && id<numZones)
2013 f << "colors=Z" << id << ",";
2014 else {
2015 if (id!=0 && id!=-1) {
2016 MWAW_DEBUG_MSG(("PowerPoint1Parser::readColorZone: the child zone seems bad\n"));
2017 f << "###colors=Z" << id << ",";
2018 }
2019 id = -1;
2020 }
2021 ascii().addDelimiter(input->tell(),'|');
2022 // unsure probably some dimension here
2023 input->seek(pos+(isMacFile ? 46 : 43), librevenge::RVNG_SEEK_SET);
2024 ascii().addDelimiter(input->tell(),'|');
2025 f << "num[used]=[";
2026 for (int i=0; i<N; ++i) { // 0|1|2
2027 val=int(input->readLong(2));
2028 if (val) f << val << ",";
2029 else f << "_,";
2030 }
2031 f << "],";
2032 if (isMacFile) {
2033 val=int(input->readULong(2));
2034 if (val) f << "g0=" << std::hex << val << std::dec << ",";
2035 }
2036 if (input->tell()!=entry.end())
2037 ascii().addDelimiter(input->tell(),'|');
2038 ascii().addPos(pos);
2039 ascii().addNote(f.str().c_str());
2040 ascii().addPos(entry.end());
2041 ascii().addNote("_");
2042
2043 MWAWEntry const &cEntry=m_state->getZoneEntry(id);
2044 if (cEntry.valid() && !cEntry.isParsed()) readColors(cEntry);
2045 return true;
2046 }
2047
2048 bool PowerPoint1Parser::readFonts(MWAWEntry const &entry)
2049 {
2050 static bool isMacFile=m_state->m_isMacFile;
2051 if (!entry.valid() || entry.length()<(isMacFile ? 6 : 13) || (isMacFile && entry.length()%6)!=0) {
2052 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFonts: the zone seems bad\n"));
2053 return false;
2054 }
2055 MWAWInputStreamPtr input = getInput();
2056 long pos = entry.begin();
2057 entry.setParsed(true);
2058 input->seek(pos, librevenge::RVNG_SEEK_SET);
2059 libmwaw::DebugStream f;
2060 f << "Entries(FontDef)[Z"<< entry.id() << "]:";
2061 auto N=size_t(entry.length()/6);
2062 if (!isMacFile) {
2063 N=size_t(input->readULong(2)); // always 6?
2064 if (long(6+7*N)>entry.length()) {
2065 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFonts: the zone seems bad\n"));
2066 return false;
2067 }
2068 f << "N=" << N << ",";
2069 f << "id=" << std::hex << input->readULong(4) << std::dec << ","; // big number
2070 }
2071 ascii().addPos(pos);
2072 ascii().addNote(f.str().c_str());
2073
2074 for (size_t i=0; i<N; ++i) {
2075 pos=input->tell();
2076 f.str("");
2077 f << "FontDef-F" << i << ":";
2078 MWAWFont font;
2079 font.setId(int(input->readULong(2)));
2080 font.setSize(float(input->readULong(2)));
2081 auto flag = int(input->readULong(isMacFile ? 1 : 2));
2082 uint32_t flags=0;
2083 if (flag&0x1) flags |= MWAWFont::boldBit;
2084 if (flag&0x2) flags |= MWAWFont::italicBit;
2085 if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple);
2086 if (flag&0x8) flags |= MWAWFont::embossBit;
2087 if (flag&0x10) flags |= MWAWFont::shadowBit;
2088 if (flag&0xE0) f << "#flag=" << (flag>>5) << ",";
2089 font.setFlags(flags);
2090 f << font.getDebugString(getParserState()->m_fontConverter);
2091 auto val=int(input->readULong(1)); // 1-4: another flag or maybe the font's color ?
2092 if (val) f << "fl=" << std::hex << val << std::dec << ",";
2093 ascii().addPos(pos);
2094 ascii().addNote(f.str().c_str());
2095 }
2096 ascii().addPos(entry.end());
2097 ascii().addNote("_");
2098 if (input->tell()!=entry.end()) {
2099 ascii().addPos(input->tell());
2100 ascii().addNote("FontDef:extra");
2101 }
2102 return true;
2103 }
2104
2105 bool PowerPoint1Parser::readFontNames(MWAWEntry const &entry)
2106 {
2107 if (!entry.valid() || entry.length()<16) {
2108 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFontNames: the zone seems bad\n"));
2109 return false;
2110 }
2111 MWAWInputStreamPtr input = getInput();
2112 long pos = entry.begin();
2113 entry.setParsed(true);
2114 input->seek(pos, librevenge::RVNG_SEEK_SET);
2115 libmwaw::DebugStream f;
2116 f << "Entries(FontName)[Z"<< entry.id() << "]:";
2117 int val;
2118 for (int i=0; i<2; ++i) {
2119 val=int(input->readULong(2));
2120 int const expected[]= {0x8001,0x25ba};
2121 if (val!=expected[i])
2122 f << "f" << i << "=" << std::hex << val << std::dec << ",";
2123 }
2124 auto N=size_t(input->readULong(2)); // always 6?
2125 if (long(16+52*N)>entry.length()) {
2126 MWAW_DEBUG_MSG(("PowerPoint1Parser::readFontNames: the zone seems bad\n"));
2127 return false;
2128 }
2129 f << "N=" << N << ",";
2130 for (int i=0; i<5; ++i) {
2131 val=int(input->readULong(2));
2132 int const expected[]= {0x7fff,0,0x32,0,0};
2133 if (val!=expected[i])
2134 f << "f" << i << "=" << std::hex << val << std::dec << ",";
2135 }
2136 ascii().addPos(pos);
2137 ascii().addNote(f.str().c_str());
2138
2139 for (size_t i=0; i<N; ++i) {
2140 pos=input->tell();
2141 f.str("");
2142 f << "FontName-FN" << i << ":";
2143 val=int(input->readULong(2));
2144 if (!val) {
2145 f << "_,";
2146 input->seek(pos+52,librevenge::RVNG_SEEK_SET);
2147 ascii().addPos(pos);
2148 ascii().addNote(f.str().c_str());
2149 continue;
2150 }
2151 f << "id=" << val << ",";
2152 for (int j=0; j<9; ++j) { // f4=0|190, f8=0|22|52
2153 val=int(input->readULong(2));
2154 if (val)
2155 f << "f" << j << "=" << std::hex << val << std::dec << ",";
2156 }
2157 std::string name; // Helv, Tms Rmn, ZapfDingbats
2158 for (int c=0; c<32; ++c) {
2159 auto ch=char(input->readULong(1));
2160 if (!ch) break;
2161 name+=ch;
2162 }
2163 if (!name.empty()) {
2164 f << name << ",";
2165 /* FIXME: by default, we force the family to be CP1252,
2166 but we may want to use the file/font encoding */
2167 getFontConverter()->setCorrespondance(int(i), name, (name=="Monotype Sorts" || name=="Wingdings") ? "" : "CP1252");
2168 }
2169 input->seek(pos+52,librevenge::RVNG_SEEK_SET);
2170 ascii().addPos(pos);
2171 ascii().addNote(f.str().c_str());
2172 }
2173 ascii().addPos(entry.end());
2174 ascii().addNote("_");
2175 if (input->tell()!=entry.end()) {
2176 ascii().addPos(input->tell());
2177 ascii().addNote("FontName:extra");
2178 }
2179 return true;
2180 }
2181
2182 bool PowerPoint1Parser::readSchemes()
2183 {
2184 for (size_t i=0; i<m_state->m_schemesIdList.size(); ++i) {
2185 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_schemesIdList[i]);
2186 if (!entry.valid() || entry.isParsed()) continue;
2187 readScheme(entry, int(i));
2188 }
2189 return true;
2190 }
2191 bool PowerPoint1Parser::readScheme(MWAWEntry const &entry, int id)
2192 {
2193 bool const isMacFile=m_state->m_isMacFile;
2194 if (!entry.valid() || (isMacFile && entry.length()!=86) || (!isMacFile && entry.length() < 96)) {
2195 MWAW_DEBUG_MSG(("PowerPoint1Parser::readScheme: the zone seems bad\n"));
2196 return false;
2197 }
2198 MWAWInputStreamPtr input = getInput();
2199 long pos = entry.begin();
2200 entry.setParsed(true);
2201 PowerPoint1ParserInternal::Scheme scheme;
2202 input->seek(pos, librevenge::RVNG_SEEK_SET);
2203 libmwaw::DebugStream f;
2204 f << "Entries(Scheme)[Z"<< entry.id() << "]:S" << id << ",";
2205 int val;
2206 if (isMacFile) {
2207 for (int i=0; i<10; ++i) { // f8=0|80
2208 val=int(input->readLong(2));
2209 int const expected[]= {16,0,0,100,100,100, 0x101, 0, 0, 0};
2210 if (val!=expected[i])
2211 f << "f" << i << "=" << val << ",";
2212 }
2213 }
2214 else {
2215 for (int i=0; i<12; ++i) { // f9=0|80
2216 val=int(input->readLong(i==3 ? 1 : 2));
2217 int const expected[]= {0,16,0,0, 100,100,100, 1, 1, 0, 0, 0};
2218 if (val!=expected[i])
2219 f << "f" << i << "=" << val << ",";
2220 }
2221 }
2222 val=int(input->readLong(2));
2223 if (val!=7) f << "max[color]=##" << val << ",";
2224 f << "colors=[";
2225 for (auto &color : scheme.m_colors) {
2226 val=int(input->readULong(2));
2227 unsigned char col[3];
2228 for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8);
2229 color=MWAWColor(col[0],col[1],col[2]);
2230 f << color << ":" << val << ",";
2231 }
2232 f << "],";
2233 if (m_state->m_idToSchemeMap.find(id)!=m_state->m_idToSchemeMap.end()) {
2234 MWAW_DEBUG_MSG(("PowerPoint1Parser::readScheme: oops, scheme S%d is already defined\n", id));
2235 }
2236 else
2237 m_state->m_idToSchemeMap[id]=scheme;
2238 if (input->tell()!=entry.end())
2239 ascii().addDelimiter(input->tell(),'|');
2240 ascii().addPos(pos);
2241 ascii().addNote(f.str().c_str());
2242 ascii().addPos(entry.end());
2243 ascii().addNote("_");
2244 return true;
2245 }
2246
2247 bool PowerPoint1Parser::readZone2(MWAWEntry const &entry)
2248 {
2249 // probably the document current style
2250 int const expectedSize=m_state->m_isMacFile ? 22 : 32;
2251 if (!entry.valid() || entry.length()!=expectedSize) {
2252 MWAW_DEBUG_MSG(("PowerPoint1Parser::readZone2: the zone seems bad\n"));
2253 return false;
2254 }
2255 MWAWInputStreamPtr input = getInput();
2256 long pos = entry.begin();
2257 entry.setParsed(true);
2258 input->seek(pos, librevenge::RVNG_SEEK_SET);
2259 libmwaw::DebugStream f;
2260 f << "Entries(Zone2)[Z"<< entry.id() << "]:";
2261 ascii().addPos(pos);
2262 ascii().addNote(f.str().c_str());
2263 ascii().addPos(entry.end());
2264 ascii().addNote("_");
2265 return true;
2266 }
2267
2268 ////////////////////////////////////////////////////////////
2269 // try to send data
2270 ////////////////////////////////////////////////////////////
2271 bool PowerPoint1Parser::sendSlide(PowerPoint1ParserInternal::Slide const &slide, bool master)
2272 {
2273 MWAWPresentationListenerPtr listener=getPresentationListener();
2274 if (!listener) {
2275 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendSlide: can not find the listener\n"));
2276 return false;
2277 }
2278 slide.m_textZones[0].m_schemeId=slide.m_textZones[1].m_schemeId=slide.m_schemeId;
2279 // first is title, better to remove it in the master slide
2280 for (size_t f=master ? 1 : 0; f<slide.m_framesList[0].size(); ++f)
2281 sendFrame(slide.m_framesList[0][f], slide.m_textZones[0]);
2282 if (!slide.m_framesList[1].empty() && !slide.m_textZones[1].empty()) {
2283 MWAWPosition pos(MWAWVec2f(0,0), MWAWVec2f(200,200), librevenge::RVNG_POINT);
2284 pos.m_anchorTo = MWAWPosition::Page;
2285 MWAWSubDocumentPtr doc(new PowerPoint1ParserInternal::SubDocument(*this, getInput(), &slide));
2286 listener->insertSlideNote(pos, doc);
2287 }
2288 return true;
2289 }
2290
2291 bool PowerPoint1Parser::sendSlideNote(PowerPoint1ParserInternal::Slide const &slide)
2292 {
2293 MWAWListenerPtr listener=getPresentationListener();
2294 if (!listener) {
2295 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendSlideNote: can not find the listener\n"));
2296 return false;
2297 }
2298 // normally, the note rectangles, followed by the note's text
2299 for (auto const &frame : slide.m_framesList[1]) {
2300 if (frame.m_type==1) continue;
2301 if (frame.m_type!=2 && frame.m_type!=3) {
2302 static bool first=true;
2303 if (first) {
2304 first=false;
2305 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendSlideNote: find unexpected frame\n"));
2306 }
2307 continue;
2308 }
2309 sendText(slide.m_textZones[1], frame.m_textId, frame.m_type==2 ? frame.m_rulerId : -1);
2310 }
2311 return true;
2312 }
2313
2314 bool PowerPoint1Parser::sendPicture(MWAWPosition const &position, MWAWGraphicStyle const &style, int pId)
2315 {
2316 MWAWListenerPtr listener=getPresentationListener();
2317 if (!listener) {
2318 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendPicture: can not find the listener\n"));
2319 return false;
2320 }
2321 if (pId<0) return true;
2322 if (pId>=int(m_state->m_picturesIdList.size())) {
2323 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendPicture: can not find the picture with id=%d\n", pId));
2324 return false;
2325 }
2326 int zId=m_state->m_picturesIdList[size_t(pId)];
2327 if (zId<=0 || zId>=int(m_state->m_zonesList.size()))
2328 return true;
2329 MWAWEmbeddedObject picture;
2330 if (!readPicture(m_state->m_zonesList[size_t(zId)], picture) || picture.isEmpty())
2331 return true;
2332 listener->insertPicture(position, picture, style);
2333 return true;
2334 }
2335
2336 bool PowerPoint1Parser::sendText(PowerPoint1ParserInternal::TextZone const &textZone, MWAWVec2i tId, int rulerId)
2337 {
2338 MWAWListenerPtr listener=getPresentationListener();
2339 if (!listener) {
2340 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: can not find the listener\n"));
2341 return false;
2342 }
2343 if (tId[0]<0 || tId[0]>=int(textZone.m_lineList.size())) {
2344 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: oops can not find the text Z%d\n", tId[0]));
2345 return false;
2346 }
2347 if (tId[1]>=int(textZone.m_lineList.size())) {
2348 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: oops can not find the text Z%d\n", tId[1]));
2349 tId[1]=tId[0];
2350 }
2351 PowerPoint1ParserInternal::Ruler ruler;
2352 bool const isMacFile=m_state->m_isMacFile;
2353 bool hasRuler=false;
2354 if (rulerId>=0 && rulerId<int(m_state->m_rulersList.size())) {
2355 ruler=m_state->m_rulersList[size_t(rulerId)];
2356 hasRuler=true;
2357 }
2358 else if (rulerId != -1) {
2359 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: oops can not find the ruler id R%d\n", rulerId));
2360 }
2361 MWAWInputStreamPtr input = getInput();
2362 long pos;
2363 int const vers=version();
2364 auto const unit=double(m_state->m_unit);
2365 for (int z=tId[0]; z<=tId[1]; ++z) {
2366 if (z!=tId[0]) listener->insertEOL();
2367 auto const &line=textZone.m_lineList[size_t(z)];
2368 MWAWEntry const &fEntry=line.m_format;
2369 MWAWEntry const &rEntry=line.m_ruler;
2370 MWAWEntry const &tEntry=line.m_text;
2371 // update the paragraph
2372 MWAWParagraph para;
2373 para.m_tabs=ruler.m_tabs;
2374 para.m_justify=line.m_justify;
2375 if (hasRuler && line.m_outlineLevel>=0 && line.m_outlineLevel<=4) {
2376 auto const &outline=ruler.m_outlines[line.m_outlineLevel];
2377 para.m_marginsUnit=librevenge::RVNG_POINT;
2378 for (int i=0; i<2; ++i)
2379 para.m_margins[i]=unit*double(outline.m_margins[i]);
2380 *para.m_margins[0]-=*(para.m_margins[1]);
2381 para.setInterline(double(outline.m_interlines[0])*0.01, librevenge::RVNG_PERCENT);
2382 if (outline.m_interlines[1]>outline.m_interlines[0]) // assume 12 pt
2383 para.m_spacings[2]=double(outline.m_interlines[1]-outline.m_interlines[0])*0.01*12/72;
2384 }
2385 listener->setParagraph(para);
2386 // now read the format
2387 input->seek(fEntry.begin(), librevenge::RVNG_SEEK_SET);
2388 int const dtSz=vers==1 ? 6 : isMacFile ? 8 : 14;
2389 int N=(fEntry.length()%dtSz)==0 ? int(fEntry.length()/dtSz) : 0;
2390 libmwaw::DebugStream f;
2391 std::map<int, MWAWFont> posToFontMap;
2392 int cPos=0;
2393 for (int i=0; i<N; ++i) {
2394 pos=input->tell();
2395 f.str("");
2396 f << "TextZone-F[" << i << "]:";
2397 auto numC=int(input->readULong(2));
2398 if (isMacFile) cPos=numC;
2399 f << "pos=" << cPos << ",";
2400 MWAWFont font;
2401 if (!isMacFile)
2402 font.setId(int(input->readULong(2)));
2403 font.setSize(float(input->readULong(isMacFile ? 1 : 2)));
2404 auto flag = int(input->readULong(isMacFile ? 1 : 2));
2405 uint32_t flags=0;
2406 if (flag&0x1) flags |= MWAWFont::boldBit;
2407 if (flag&0x2) flags |= MWAWFont::italicBit;
2408 if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple);
2409 if (flag&0x8) flags |= MWAWFont::embossBit;
2410 if (flag&0x10) flags |= MWAWFont::shadowBit;
2411 if (flag&0xE0) f << "#flag=" << (flag>>5) << ",";
2412 font.setFlags(flags);
2413 if (isMacFile)
2414 font.setId(int(input->readULong(2)));
2415 if (dtSz>=8) {
2416 auto col=int(input->readULong(1));
2417 MWAWColor color;
2418 if (textZone.m_schemeId>=0 && getColor(col, textZone.m_schemeId, color)) {
2419 font.setColor(color);
2420 if (!color.isBlack())
2421 f << "col=" << color << ",";
2422 }
2423 else
2424 f << "#col=" << color << ",";
2425 auto val=int(input->readULong(1)); // 0-255
2426 if (val) f << "f0=" << val << ",";
2427 }
2428 if (posToFontMap.find(cPos)!=posToFontMap.end()) {
2429 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: oops, find duplicated position\n"));
2430 f << "##dup,";
2431 }
2432 else
2433 posToFontMap[cPos]=font;
2434 f << font.getDebugString(getParserState()->m_fontConverter);
2435 if (input->tell()!=pos+dtSz)
2436 ascii().addDelimiter(input->tell(),'|');
2437 input->seek(pos+dtSz, librevenge::RVNG_SEEK_SET);
2438 ascii().addPos(pos);
2439 ascii().addNote(f.str().c_str());
2440 if (!isMacFile) cPos+=numC;
2441 }
2442 std::map<int, MWAWParagraph> posToRulerMap;
2443 if (rEntry.valid()) {
2444 // now read the rulers
2445 input->seek(rEntry.begin(), librevenge::RVNG_SEEK_SET);
2446 N=(rEntry.length()%6)==0 ? int(rEntry.length()/6) : 0;
2447 cPos=0;
2448 for (int i=0; i<N; ++i) {
2449 pos=input->tell();
2450 f.str("");
2451 f << "TextZone-R[" << i << "]:";
2452 auto numC=int(input->readULong(2));
2453 f << "pos=" << cPos << ",";
2454 MWAWParagraph cPara(para);
2455 auto outlineLevel=int(input->readULong(2));
2456 if (hasRuler && outlineLevel>0 && outlineLevel<=4) {
2457 f << "level=" << outlineLevel << ",";
2458 auto const &outline=ruler.m_outlines[outlineLevel];
2459 cPara.m_marginsUnit=librevenge::RVNG_POINT;
2460 for (int j=0; j<2; ++j)
2461 cPara.m_margins[j]=unit*double(outline.m_margins[j]);
2462 *cPara.m_margins[0]-=*(cPara.m_margins[1]);
2463 cPara.setInterline(double(outline.m_interlines[0])*0.01, librevenge::RVNG_PERCENT);
2464 if (outline.m_interlines[1]>outline.m_interlines[0]) // assume 12 pt
2465 cPara.m_spacings[2]=double(outline.m_interlines[1]-outline.m_interlines[0])*0.01*12/72;
2466 }
2467 else if (outlineLevel>4) {
2468 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: oops, the outline level seems bad\n"));
2469 f << "###outlineLevel=" << outlineLevel << ",";
2470 }
2471 auto adjust=int(input->readULong(2));
2472 switch (adjust) {
2473 case 0: // left
2474 cPara.m_justify=MWAWParagraph::JustificationLeft;
2475 break;
2476 case 1:
2477 cPara.m_justify=MWAWParagraph::JustificationCenter;
2478 f << "center,";
2479 break;
2480 case 2:
2481 cPara.m_justify=MWAWParagraph::JustificationRight;
2482 f << "right,";
2483 break;
2484 case 3:
2485 cPara.m_justify=MWAWParagraph::JustificationFull;
2486 f << "justify,";
2487 break;
2488 default:
2489 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: find unknown alignment\n"));
2490 f << "##align=" << adjust << ",";
2491 break;
2492 }
2493 if (posToRulerMap.find(cPos)!=posToRulerMap.end()) {
2494 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendText: oops, find duplicated paragraph\n"));
2495 f << "##dup,";
2496 }
2497 else
2498 posToRulerMap[cPos]=cPara;
2499 ascii().addPos(pos);
2500 ascii().addNote(f.str().c_str());
2501 cPos+=numC;
2502 }
2503 }
2504 input->seek(tEntry.begin(), librevenge::RVNG_SEEK_SET);
2505 for (int i=0; i<int(tEntry.length()); ++i) {
2506 if (posToRulerMap.find(i)!=posToRulerMap.end())
2507 listener->setParagraph(posToRulerMap.find(i)->second);
2508 if (posToFontMap.find(i)!=posToFontMap.end())
2509 listener->setFont(posToFontMap.find(i)->second);
2510 auto c=static_cast<unsigned char>(input->readULong(1));
2511 switch (c) {
2512 case 0x9:
2513 listener->insertTab();
2514 break;
2515 case 0xd:
2516 listener->insertEOL();
2517 break;
2518 case 0x11: // command key
2519 listener->insertUnicode(0x2318);
2520 break;
2521 // special, if dupplicated, this is a field
2522 case '/': // date
2523 case ':': // time
2524 case '#': { // page number
2525 pos=input->tell();
2526 if (i+1<int(tEntry.length()) && char(input->readULong(1))==char(c)) {
2527 ++i;
2528 listener->insertField(MWAWField(c=='#' ? MWAWField::PageNumber : c=='/' ? MWAWField::Date : MWAWField::Time));
2529 }
2530 else {
2531 input->seek(pos, librevenge::RVNG_SEEK_SET);
2532 listener->insertCharacter(c);
2533 }
2534 break;
2535 }
2536 default:
2537 listener->insertCharacter(c);
2538 break;
2539 }
2540 }
2541 }
2542 return true;
2543 }
2544
2545 bool PowerPoint1Parser::sendFrame(PowerPoint1ParserInternal::Frame const &frame, PowerPoint1ParserInternal::TextZone const &zone)
2546 {
2547 MWAWListenerPtr listener=getPresentationListener();
2548 if (!listener) {
2549 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendFrame: can not find the listener\n"));
2550 return false;
2551 }
2552 MWAWBox2f fBox(m_state->m_unit*MWAWVec2f(frame.m_dimension[0]+m_state->m_origin),
2553 m_state->m_unit*MWAWVec2f(frame.m_dimension[1]+m_state->m_origin));
2554 if (frame.m_textId[0]>=0) {
2555 MWAWPosition pos(fBox[0], fBox.size(), librevenge::RVNG_POINT);
2556 pos.m_anchorTo = MWAWPosition::Page;
2557 MWAWSubDocumentPtr subdoc(new PowerPoint1ParserInternal::SubDocument(*this, getInput(), &zone, frame.m_textId, frame.m_type==2 ? frame.m_rulerId : -1));
2558 listener->insertTextBox(pos, subdoc, frame.m_style);
2559 return true;
2560 }
2561 switch (frame.m_type) {
2562 case 0:
2563 case 1: {
2564 MWAWGraphicShape shape;
2565 if (frame.m_type==0)
2566 shape=MWAWGraphicShape::line(fBox[0], fBox[1]);
2567 else {
2568 if (float(frame.m_cornerSize) >= fBox.size()[0] || float(frame.m_cornerSize) >= fBox.size()[1])
2569 shape=MWAWGraphicShape::circle(fBox);
2570 else
2571 shape=MWAWGraphicShape::rectangle(fBox, MWAWVec2f(float(frame.m_cornerSize)/2.f, float(frame.m_cornerSize)/2.f));
2572 }
2573 MWAWBox2f box=shape.getBdBox();
2574 MWAWPosition pos(box[0], box.size(), librevenge::RVNG_POINT);
2575 pos.m_anchorTo = MWAWPosition::Page;
2576 if (frame.m_type==1 && frame.m_pictureId>=0)
2577 sendPicture(pos, MWAWGraphicStyle::emptyStyle(), frame.m_pictureId);
2578 else
2579 listener->insertShape(pos, shape, frame.m_style);
2580 return true;
2581 }
2582 default:
2583 MWAW_DEBUG_MSG(("PowerPoint1Parser::sendFrame: can not send some frame\n"));
2584 break;
2585 }
2586 return false;
2587 }
2588
2589 ////////////////////////////////////////////////////////////
2590 // Low level
2591 ////////////////////////////////////////////////////////////
2592
2593 // read the header
2594 bool PowerPoint1Parser::checkHeader(MWAWHeader *header, bool strict)
2595 {
2596 *m_state = PowerPoint1ParserInternal::State();
2597 MWAWInputStreamPtr input = getInput();
2598 if (!input || !input->hasDataFork())
2599 return false;
2600
2601 libmwaw::DebugStream f;
2602 if (!input->checkPosition(24+8)) {
2603 MWAW_DEBUG_MSG(("PowerPoint1Parser::checkHeader: file is too short\n"));
2604 return false;
2605 }
2606 long pos = 0;
2607 input->setReadInverted(false);
2608 input->seek(pos, librevenge::RVNG_SEEK_SET);
2609 unsigned long signature=input->readULong(4);
2610 if (signature==0xeddead0b) {
2611 input->setReadInverted(true);
2612 m_state->m_isMacFile=false;
2613 m_state->m_unit=1.f/8.f;
2614 }
2615 else if (signature!=0xbaddeed)
2616 return false;
2617 f << "FileHeader:";
2618 auto vers=int(input->readLong(4));
2619 if (vers!=2) return false;
2620 m_state->m_zoneListBegin=long(input->readULong(4));
2621 if (m_state->m_zoneListBegin<24 || !input->checkPosition(m_state->m_zoneListBegin))
2622 return false;
2623 f << "zone[begin]=" << std::hex << m_state->m_zoneListBegin << std::dec << ",";
2624
2625 if (strict) {
2626 input->seek(12, librevenge::RVNG_SEEK_SET);
2627 auto val=int(input->readULong(2));
2628 if (!input->checkPosition(m_state->m_zoneListBegin+val*8))
2629 return false;
2630 }
2631 input->seek(12, librevenge::RVNG_SEEK_SET);
2632 ascii().addPos(pos);
2633 ascii().addNote(f.str().c_str());
2634
2635 setVersion(1);
2636 if (header)
2637 header->reset(MWAWDocument::MWAW_T_POWERPOINT, 1, MWAWDocument::MWAW_K_PRESENTATION);
2638 return true;
2639 }
2640
2641 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: