Debian Codegraph @

src/lib/PowerPoint3Parser.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 <sstream>
38 #include <utility>
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 "PowerPoint3Parser.hxx"
54
55 #include "PowerPoint3OLE.hxx"
56
57 /** Internal: the structures of a PowerPoint3Parser */
58 namespace PowerPoint3ParserInternal
59 {
60 int swapUInt8(int v);
61 int swapBool8(int v);
62 int swapBool4UInt4(int v);
63 int swapUInt4Bool4(int v);
64 ////////////////////////////////////////
65 //! swap an uint8_t by 4 offset
66 int swapUInt8(int v)
67 {
68 return ((v>>4)|(v<<4)) & 0xFF;
69 }
70 //! swap a list of 8 bool
71 int swapBool8(int v)
72 {
73 int val=0;
74 for (int b=0, d1=1, d2=0x80; b<4; ++b, d1<<=1, d2>>=1) {
75 if (v&d1) val|=d2;
76 if (v&d2) val|=d1;
77 }
78 return val;
79 }
80 //! swap a list of 4bool and a int4
81 int swapBool4UInt4(int v)
82 {
83 int val=0;
84 for (int b=0, d1=1, d2=0x80; b<4; ++b, d1<<=1, d2>>=1) {
85 if (v&d2) val|=d1;
86 }
87 val|=((v&3)<<6)|((v&0x0c)<<2);
88 return val;
89 }
90 //! swap a list of a int4 and 4bool
91 int swapUInt4Bool4(int v)
92 {
93 int val=0;
94 for (int b=0, d1=1, d2=0x80; b<4; ++b, d1<<=1, d2>>=1) {
95 if (v&d1) val|=d2;
96 }
97 val|=((v&0x30)>>2)|((v&0xc0)>>6);
98 return val;
99 }
100
101 ////////////////////////////////////////
102 //! Internal: virtual field parser of a PowerPoint3Parser
103 struct FieldParser {
104 //! the constructor
105 FieldParser(int fSize, std::string const &debugName)
106 : m_fieldSize(fSize)
107 , m_name(debugName)
108 {
109 }
110 //! destructor
111 virtual ~FieldParser();
112 //! virtual function used to parse a field
113 virtual bool parse(int id, MWAWInputStreamPtr &input, libmwaw::DebugFile &ascFile)=0;
114 //! the field size
115 int m_fieldSize;
116 //! the debug name
117 std::string m_name;
118 };
119
120 FieldParser::~FieldParser()
121 {
122 }
123 ////////////////////////////////////////
124 //! Internal: a basic zone id parser of a PowerPoint3Parser
125 struct ListZoneIdParser final : public FieldParser {
126 //! the constructor
127 ListZoneIdParser(int numZones, std::string const &debugName)
128 : FieldParser(4, debugName)
129 , m_numZones(numZones)
130 , m_fieldIdToZoneIdMap()
131 {
132 }
133 //! virtual function used to parse a field
134 bool parse(int id, MWAWInputStreamPtr &input, libmwaw::DebugFile &ascFile) final;
135 //! the number of zones
136 int m_numZones;
137 //! map field id to zone id
138 std::map<int,int> m_fieldIdToZoneIdMap;
139 };
140
141 bool ListZoneIdParser::parse(int id, MWAWInputStreamPtr &input, libmwaw::DebugFile &ascFile)
142 {
143 long pos=input->tell();
144 libmwaw::DebugStream f;
145 f << m_name << "[" << id << "]:pos,";
146 auto zId=int(input->readULong(4));
147 f << "Z" << zId;
148 if (zId>=0 && zId<m_numZones)
149 m_fieldIdToZoneIdMap[id]=zId;
150 else {
151 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::ListZoneIdParser::parse: find bad zone Z%d\n", zId));
152 f << "###";
153 }
154 ascFile.addPos(pos-2);
155 ascFile.addNote(f.str().c_str());
156 return true;
157 }
158
159 ////////////////////////////////////////
160 //! Internal: a font name parser of a PowerPoint3Parser
161 struct FontNameFieldParser final : public FieldParser {
162 //! the constructor
163 explicit FontNameFieldParser(int numZones)
164 : FieldParser(64, "FontName")
165 , m_numZones(numZones)
166 , m_idToNameMap()
167 , m_childList()
168 {
169 }
170 //! virtual function used to parse a field
171 bool parse(int id, MWAWInputStreamPtr &input, libmwaw::DebugFile &ascFile) final;
172 //! the number of zones
173 int m_numZones;
174 //! map file id to font name
175 std::map<int, std::string> m_idToNameMap;
176 //! the child list
177 std::vector<int> m_childList;
178 };
179
180 bool FontNameFieldParser::parse(int id, MWAWInputStreamPtr &input, libmwaw::DebugFile &ascFile)
181 {
182 long pos=input->tell();
183 libmwaw::DebugStream f;
184 f << m_name << "[" << id << "]:";
185 int val;
186 for (int i=0; i<5; ++i) { // f4=400|700
187 val=int(input->readLong(2));
188 if (val) f << "f" << i << "=" << val << ",";;
189 }
190 val=int(input->readLong(1)); // 0|1|-1
191 if (val) f << "f5=" << val << ",";
192 for (int i=0; i<3; ++i) { // f7=0|2
193 val=int(input->readLong(2));
194 if (val) f << "f" << i+6 << "=" << val << ",";
195 }
196 val=int(input->readLong(1)); // [012][07]
197 if (val) f << "fl=" << std::hex << val << std::dec << ",";
198 std::string name;
199 for (int i=0; i<32; ++i) {
200 auto c=char(input->readULong(1));
201 if (!c) break;
202 name+=c;
203 }
204 f << name << ",";
205 if (!name.empty()) m_idToNameMap[id]=name;
206 input->seek(pos+50, librevenge::RVNG_SEEK_SET);
207 auto zId=int(input->readULong(4));
208 if (zId)
209 f << "Z" << zId << ",";
210 if (zId>0 && zId<m_numZones)
211 m_childList.push_back(zId);
212 else if (zId) {
213 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::ListZoneIdParser::parse: find bad zone Z%d\n", zId));
214 f << "###";
215 }
216 for (int i=0; i<5; ++i) { // g0=0|1, g1,g2=small number g3=2048, g4=0
217 val=int(input->readLong(2));
218 if (val) f << "g" << i << "=" << val << ",";
219 }
220 ascFile.addPos(pos-2);
221 ascFile.addNote(f.str().c_str());
222 return true;
223 }
224
225 //! Internal: a ruler
226 struct Ruler {
227 //! constructor
228 Ruler()
229 : m_paragraph()
230 {
231 for (auto &margin : m_margins) margin=0;
232 }
233 //! operator<<
234 friend std::ostream &operator<<(std::ostream &o, Ruler const &ruler)
235 {
236 o << "margins=[";
237 for (int i=0; i<5; ++i)
238 o << double(ruler.m_margins[2*i+1]-ruler.m_margins[2*i])/8 << ":" << double(ruler.m_margins[2*i])/8 << ",";
239 o << "],";
240 o << ruler.m_paragraph;
241 return o;
242 }
243 //! returns a paragraph corresponding to a level
244 void updateParagraph(MWAWParagraph &para, int level) const
245 {
246 if (level<0 || level>4) {
247 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::Ruler::updateParagraph: the level %d seems bad\n", level));
248 level=0;
249 }
250 para.m_marginsUnit=librevenge::RVNG_POINT;
251 para.m_margins[0]=double(m_margins[2*level+1]-m_margins[2*level+0])/8;
252 para.m_margins[1]=double(m_margins[2*level+0])/8;
253 para.m_tabs=m_paragraph.m_tabs;
254 }
255 //! the paragraph
256 MWAWParagraph m_paragraph;
257 //! the left/first margins * 5 (0: normal, 1-4: level)
258 int m_margins[10];
259 };
260 //! Internal: a frame of a PowerPoint3Parser
261 struct Frame {
262 //! constructor
263 Frame()
264 : m_type(-1)
265 , m_formatId(-1)
266 , m_dimension()
267 , m_shapeId(-1)
268 , m_customShapeId(-1)
269 , m_customTransformation(0)
270 , m_polygonId(-1)
271 , m_pictureId(-1)
272 , m_textId(-1)
273 , m_mainTextBox(false)
274 , m_style()
275 , m_isSent(false)
276 {
277 for (auto &angle : m_angles) angle=0;
278 for (auto &groupChild : m_groupChild) groupChild=-1;
279 }
280 //! the type: 0:line, 1:rect, 2: textbox, ...
281 int m_type;
282 //! the format id
283 int m_formatId;
284 //! the dimension
285 MWAWBox2i m_dimension;
286 //! the shape id: 1: oval, 2: rectOval, 3:rectangle
287 int m_shapeId;
288 //! the custom shape id
289 int m_customShapeId;
290 //! the custom transformation: 1:rot90, 2:rot180, 4:flipX
291 int m_customTransformation;
292 //! the polygon id
293 int m_polygonId;
294 //! the picture id
295 int m_pictureId;
296 //! the textzone id
297 int m_textId;
298 //! flag to know if the textbox is a place holder
299 bool m_mainTextBox;
300 //! the arc angles
301 float m_angles[2];
302 //! the group limit
303 int m_groupChild[2];
304 //! the style
305 MWAWGraphicStyle m_style;
306 //! flag to know if a frame is sent
307 mutable bool m_isSent;
308 };
309 //! Internal: a polygon of a PowerPoint3Parser
310 struct Polygon {
311 //! constructor
312 Polygon()
313 : m_type(0)
314 , m_box()
315 , m_vertices()
316 {
317 }
318 //! update the shape
319 bool updateShape(MWAWBox2f const &finalBox, MWAWGraphicShape &shape) const;
320 //! the polygon type
321 int m_type;
322 //! the bdbox
323 MWAWBox2i m_box;
324 //! the list of points
325 std::vector<MWAWVec2f> m_vertices;
326 };
327
328 bool Polygon::updateShape(MWAWBox2f const &finalBox, MWAWGraphicShape &shape) const
329 {
330 if (m_vertices.empty()) return false;
331 MWAWBox2f actBox(m_vertices[0],m_vertices[0]);
332 for (size_t i=1; i<m_vertices.size(); ++i) actBox=actBox.getUnion(MWAWBox2f(m_vertices[i],m_vertices[i]));
333 float factor[2], decal[2];
334 for (int i=0; i<2; ++i) {
335 if (actBox.size()[i]<0||actBox.size()[i]>0)
336 factor[i]=finalBox.size()[i]/actBox.size()[i];
337 else
338 factor[i]=1.f;
339 decal[i]=finalBox[0][i]-factor[i]*actBox[0][i];
340 }
341 shape.m_type = MWAWGraphicShape::Polygon;
342 for (auto const &pt : m_vertices)
343 shape.m_vertices.push_back(MWAWVec2f(decal[0]+factor[0]*pt[0], decal[1]+factor[1]*pt[1]));
344 if (m_type==1) shape.m_vertices.push_back(shape.m_vertices[0]);
345 return true;
346 }
347
348 //! a scheme of a PowerPoint3Parser
349 struct Scheme {
350 //! the color: back, foreground, accents
351 MWAWColor m_colors[8];
352 };
353 //! Internal: the third zone defining a slide of a PowerPoint3Parser
354 struct SlideFormat {
355 //! constructor
356 SlideFormat()
357 : m_margins(0,0)
358 , m_gradientOffset(0)
359 , m_shadowOffset(0,0)
360 {
361 }
362 //! the left/right and top/bottom margins
363 MWAWVec2i m_margins;
364 //! the color gradient offset: -10 means black, 10 means white
365 int m_gradientOffset;
366 //! the shadow offset
367 MWAWVec2i m_shadowOffset;
368 };
369
370 //! Internal: a text zone of a PowerPoint3Parser
371 struct TextZone {
372 //! constructor
373 TextZone()
374 : m_rulerId(-1)
375 , m_box()
376 , m_text()
377 , m_fonts()
378 , m_rulers()
379 , m_centered(false)
380 , m_wrapText(false)
381 , m_adjustSize(false)
382 {
383 }
384 //! return true if the zone has no text
385 bool empty() const
386 {
387 return !m_text.valid();
388 }
389 //! the ruler id
390 int m_rulerId;
391 //! the bdbox
392 MWAWBox2i m_box;
393 //! the text entry
394 MWAWEntry m_text;
395 //! the fonts entry
396 MWAWEntry m_fonts;
397 //! the ruler entry
398 MWAWEntry m_rulers;
399 //! force horizontal centered
400 bool m_centered;
401 //! wrap the text
402 bool m_wrapText;
403 //! adjust the textbox size
404 bool m_adjustSize;
405 };
406
407 //! Internal: a slide of a PowerPoint3Parser
408 struct SlideContent {
409 //! constructor
410 SlideContent()
411 : m_useMasterPage(false)
412 , m_numMainZones(0)
413 , m_textZone()
414 , m_frameList()
415 , m_formatList()
416 , m_polygonList()
417 , m_schemeId(-1)
418 {
419 for (auto &id : m_mainZoneIds) id=-1;
420 }
421 //! return true if the zone has text
422 bool hasText() const
423 {
424 for (auto const &zone : m_textZone) {
425 if (!zone.empty()) return true;
426 }
427 return false;
428 }
429 //! a flag to know if we need to use the master page
430 bool m_useMasterPage;
431 //! the number of title/body zones
432 int m_numMainZones;
433 //! the title/body position
434 int m_mainZoneIds[2];
435 //! the textzone
436 std::vector<TextZone> m_textZone;
437 //! the list of frames
438 std::vector<Frame> m_frameList;
439 //! the format list
440 std::vector<SlideFormat> m_formatList;
441 //! the list of polygons
442 std::vector<Polygon> m_polygonList;
443 //! the scheme id
444 int m_schemeId;
445 };
446 //! Internal: a slide of a PowerPoint3Parser
447 struct Slide {
448 //! constructor
449 Slide()
450 {
451 for (auto &id : m_contentIds) id=-1;
452 }
453 //! the slide content ids: slide and not
454 int m_contentIds[2];
455 };
456
457 ////////////////////////////////////////
458 //! Internal: the state of a PowerPoint3Parser
459 struct State {
460 //! constructor
461 State()
462 : m_isMacFile(true)
463 , m_fontFamily("CP1252")
464 , m_oleParser()
465 , m_zoneListBegin(0)
466 , m_zonesList()
467 , m_slidesIdList()
468 , m_idToSlideMap()
469 , m_idToSlideContentMap()
470 , m_idToSchemeMap()
471 , m_pictIdToZoneIdMap()
472 , m_idToPictureContentMap()
473 , m_origin(0,0)
474 , m_idToUserColorMap()
475 , m_idToFontIdMap()
476 , m_idToRulerMap()
477 , m_monoTypeFontId(-1)
478 , m_badEntry()
479 {
480 for (auto &id : m_printInfoIds) id=-1;
481 for (auto &id : m_zoneIds) id=-1;
482 }
483 //! try to return a zone
484 MWAWEntry const &getZoneEntry(int id) const
485 {
486 if (id==-1) return m_badEntry;
487 if (id<0||size_t(id)>=m_zonesList.size()) {
488 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::State::getZone: can find entry with id=%d\n", id));
489 return m_badEntry;
490 }
491 return m_zonesList[size_t(id)];
492 }
493 //! try to return a pattern
494 bool getPattern(int id, MWAWGraphicStyle::Pattern &pattern) const;
495 //! returns a custom shape corresponding to an id
496 static bool getCustomShape(int id, MWAWGraphicShape &shape);
497 //! flag to know if the file is a mac file or a pc file
498 bool m_isMacFile;
499 //! the basic pc font family if known
500 std::string m_fontFamily;
501 //! the ole parser
502 std::shared_ptr<PowerPoint3OLE> m_oleParser;
503 //! the begin position of the list of zones
504 long m_zoneListBegin;
505 //! the list of zone entries
506 std::vector<MWAWEntry> m_zonesList;
507 //! the main list of slides id
508 std::vector<int> m_slidesIdList;
509 //! a map zoneId to slide
510 std::map<int, Slide> m_idToSlideMap;
511 //! a map zoneId to slide content
512 std::map<int, SlideContent> m_idToSlideContentMap;
513 //! a map between schemeId and scheme
514 std::map<int, Scheme> m_idToSchemeMap;
515 //! a map pictId to picture zone
516 std::map<int, int> m_pictIdToZoneIdMap;
517 //! a map zoneId to picture object
518 std::map<int, MWAWEmbeddedObject> m_idToPictureContentMap;
519 //! the origin
520 MWAWVec2i m_origin;
521 //! a map between colorId and user color
522 std::map<int, MWAWColor> m_idToUserColorMap;
523 //! a map between file id and font id
524 std::map<int, int> m_idToFontIdMap;
525 //! a map between id and paragraph
526 std::map<int, Ruler> m_idToRulerMap;
527 //! the printInfo id
528 int m_printInfoIds[2];
529 //! the sequential zones id
530 int m_zoneIds[13];
531 //! the monotype font id
532 int m_monoTypeFontId;
533 //! an entry used by getZoneEntry if it does not find the zone
534 MWAWEntry m_badEntry;
535 };
536
537 bool State::getPattern(int id, MWAWGraphicStyle::Pattern &pattern) const
538 {
539 // normally between 1 and 32 but find a pattern resource with 38 patterns
540 if (id<=0 || id>=39) {
541 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::State::getPattern: unknown id=%d\n", id));
542 return false;
543 }
544 static uint16_t const values[] = {
545 0xffff, 0xffff, 0xffff, 0xffff, 0x0, 0x0, 0x0, 0x0,
546 0xddff, 0x77ff, 0xddff, 0x77ff, 0x8000, 0x800, 0x8000, 0x800,
547 0xdd77, 0xdd77, 0xdd77, 0xdd77, 0x8800, 0x2200, 0x8800, 0x2200,
548 0xaa55, 0xaa55, 0xaa55, 0xaa55, 0x8822, 0x8822, 0x8822, 0x8822,
549 0x8844, 0x2211, 0x8844, 0x2211, 0x1122, 0x4488, 0x1122, 0x4488,
550 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 0xff00, 0xff00, 0xff00, 0xff00,
551 0x81c0, 0x6030, 0x180c, 0x603, 0x8103, 0x60c, 0x1830, 0x60c0,
552 0x8888, 0x8888, 0x8888, 0x8888, 0xff00, 0x0, 0xff00, 0x0,
553 0xb130, 0x31b, 0xd8c0, 0xc8d, 0x8010, 0x220, 0x108, 0x4004,
554 0xff80, 0x8080, 0x8080, 0x8080, 0xff88, 0x8888, 0xff88, 0x8888,
555 0xff80, 0x8080, 0xff08, 0x808, 0xeedd, 0xbb77, 0xeedd, 0xbb77,
556 0x7fff, 0xffff, 0xf7ff, 0xffff, 0x88, 0x4422, 0x1100, 0x0,
557 0x11, 0x2244, 0x8800, 0x0, 0x8080, 0x8080, 0x808, 0x808, 0xf000,
558 0x0, 0xf00, 0x0, 0x8142, 0x2418, 0x8142, 0x2418,
559 0x8000, 0x2200, 0x800, 0x2200, 0x1038, 0x7cfe, 0x7c38, 0x1000,
560 0x102, 0x408, 0x1824, 0x4281, 0xc1e0, 0x7038, 0x1c0e, 0x783,
561 0x8307, 0xe1c, 0x3870, 0xe0c1, 0xcccc, 0xcccc, 0xcccc, 0xcccc,
562 0xffff, 0x0, 0xffff, 0x0, 0xf0f0, 0xf0f0, 0xf0f, 0xf0f,
563 0x6699, 0x9966, 0x6699, 0x9966, 0x8142, 0x2418, 0x1824, 0x4281,
564 };
565 pattern.m_dim=MWAWVec2i(8,8);
566 uint16_t const *ptr=&values[4*(id-1)];
567 pattern.m_data.resize(8);
568 for (size_t i=0; i < 4; ++i, ++ptr) {
569 pattern.m_data[2*i]=static_cast<unsigned char>((*ptr)>>8);
570 pattern.m_data[2*i+1]=static_cast<unsigned char>((*ptr)&0xff);
571 }
572 return true;
573 }
574
575 bool State::getCustomShape(int id, MWAWGraphicShape &shape)
576 {
577 int N=4;
578 double const *vertices=nullptr;
579 switch (id) {
580 case 0: {
581 static double const v[]= {0.5,1, 1,0.5, 0.5,0, 0,0.5 };
582 vertices=v;
583 break;
584 }
585 case 1: {
586 N=3;
587 static double const v[]= {0,1, 1,1, 0.5,0};
588 vertices=v;
589 break;
590 }
591 case 2: {
592 N=3;
593 static double const v[]= {0,1, 1,1, 0,0};
594 vertices=v;
595 break;
596 }
597 case 3: {
598 static double const v[]= {0,1, 0.7,1, 1,0, 0.3,0 };
599 vertices=v;
600 break;
601 }
602 case 4: {
603 static double const v[]= {0,1, 0.3,0, 0.7,0, 1,1 };
604 vertices=v;
605 break;
606 }
607 case 5: {
608 N=6;
609 static double const v[]= {0,0.5, 0.2,1, 0.8,1, 1,0.5, 0.8,0, 0.2,0};
610 vertices=v;
611 break;
612 }
613 case 6: {
614 N=8;
615 static double const v[]= {0,0.3, 0,0.7, 0.3,1, 0.7,1, 1,0.7, 1,0.3, 0.7,0, 0.3,0};
616 vertices=v;
617 break;
618 }
619 case 7: {
620 N=12;
621 static double const v[]= {0,0.2, 0,0.8, 0.2,0.8, 0.2,1,
622 0.8,1, 0.8,0.8, 1,0.8, 1,0.2,
623 0.8,0.2, 0.8,0, 0.2,0, 0.2,0.2
624 };
625 vertices=v;
626 break;
627 }
628 case 8: {
629 N=10;
630 static double const v[]= {0.5,0, 0.383,0.383, 0,0.383, 0.3112,0.62,
631 0.1943,1, 0.5,0.78, 0.8056,1, 0.688,0.62,
632 1,0.3822, 0.6167,0.3822,
633 };
634 vertices=v;
635 break;
636 }
637 case 9: {
638 N=7;
639 static double const v[]= {0,0.333, 0,0.666, 0.7,0.666, 0.7,1,
640 1,0.5, 0.7,0, 0.7,0.333
641 };
642 vertices=v;
643 break;
644 }
645 case 10: {
646 N=7;
647 static double const v[]= {0,0.2, 0,0.8, 0.7,0.8, 0.7,1,
648 1,0.5, 0.7,0, 0.7,0.2
649 };
650 vertices=v;
651 break;
652 }
653 case 11: {
654 N=5;
655 static double const v[]= {0,0, 0,1, 0.7,1, 1,0.5, 0.7,0};
656 vertices=v;
657 break;
658 }
659 case 12: {
660 N=12;
661 static double const v[]= {0,1, 0.8,1, 1,0.8, 1,0,
662 0.8,0.2, 0.8,1, 0.8,0.2, 0,0.2,
663 0.2,0., 1,0, 0.2,0, 0,0.2
664 };
665
666 vertices=v;
667 break;
668 }
669 case 13: {
670 N=11;
671 static double const v[]= {0,0.1, 0,0.8, 0.1,0.9, 0.2,0.9,
672 0.1,1, 0.3,0.9, 0.9,0.9, 1,0.8,
673 1,0.1, 0.9,0, 0.1,0
674 };
675 vertices=v;
676 break;
677 }
678 case 14: {
679 N=24;
680 static double const v[]= { 0.5,0, 0.55,0.286, 0.7465,0.07, 0.656,0.342,
681 0.935,0.251, 0.7186,0.4465, 1,0.5, 0.7186,0.5535,
682 0.935,0.75, 0.6558,0.66558, 0.7465,0.9349, 0.558,0.7186,
683 0.495,1, 0.44,0.7186, 0.2511,0.935, 0.3418,0.6627,
684 0.063,0.7535, 0.279,0.558, 0,0.502, 0.279,0.4465,
685 0.063,0.2511, 0.3418,0.3418, 0.2511,0.069, 0.4395,0.286
686 };
687 vertices=v;
688 break;
689 }
690 default:
691 break;
692 }
693 if (N<=0 || !vertices) {
694 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::State::getCustomShape: unknown id %d\n", id));
695 return false;
696 }
697 shape.m_type = MWAWGraphicShape::Polygon;
698 shape.m_vertices.resize(size_t(N+1));
699 for (int i=0; i<N; ++i)
700 shape.m_vertices[size_t(i)]=MWAWVec2f(float(vertices[2*i]),float(vertices[2*i+1]));
701 shape.m_vertices[size_t(N)]=MWAWVec2f(float(vertices[0]),float(vertices[1]));
702 return true;
703 }
704
705 ////////////////////////////////////////
706 //! Internal: the subdocument of a PowerPointParser
707 class SubDocument final : public MWAWSubDocument
708 {
709 public:
710 //! constructor for text
711 SubDocument(PowerPoint3Parser &pars, MWAWInputStreamPtr const &input, SlideContent const *slide, int tId, bool mainZone, bool master)
712 : MWAWSubDocument(&pars, input, MWAWEntry())
713 , m_slide(slide)
714 , m_textId(tId)
715 , m_mainTextBox(mainZone)
716 , m_isMaster(master)
717 {
718 }
719 //! constructor for note
720 SubDocument(PowerPoint3Parser &pars, MWAWInputStreamPtr const &input, SlideContent const *slide)
721 : MWAWSubDocument(&pars, input, MWAWEntry())
722 , m_slide(slide)
723 , m_textId(-1)
724 , m_mainTextBox(false)
725 , m_isMaster(false)
726 {
727 }
728
729 //! destructor
730 ~SubDocument() final {}
731
732 //! operator!=
733 bool operator!=(MWAWSubDocument const &doc) const final
734 {
735 if (MWAWSubDocument::operator!=(doc)) return true;
736 auto const *sDoc = dynamic_cast<SubDocument const *>(&doc);
737 if (!sDoc) return true;
738 if (m_slide != sDoc->m_slide) return true;
739 if (m_textId != sDoc->m_textId) return true;
740 if (m_mainTextBox != sDoc->m_mainTextBox) return true;
741 if (m_isMaster != sDoc->m_isMaster) return true;
742 return false;
743 }
744
745 //! the parser function
746 void parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType type) final;
747
748 protected:
749 //! the slide
750 SlideContent const *m_slide;
751 //! the text id
752 int m_textId;
753 //! flag to know if we send the title or the body
754 bool m_mainTextBox;
755 //! flag to know if we send a master text zone
756 bool m_isMaster;
757 private:
758 SubDocument(SubDocument const &) = delete;
759 SubDocument &operator=(SubDocument const &) = delete;
760 };
761
762 void SubDocument::parse(MWAWListenerPtr &listener, libmwaw::SubDocumentType)
763 {
764 if (!listener.get()) {
765 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::SubDocument::parse: no listener\n"));
766 return;
767 }
768 auto *parser=dynamic_cast<PowerPoint3Parser *>(m_parser);
769 if (!parser) {
770 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::SubDocument::parse: no parser\n"));
771 return;
772 }
773 if (!m_slide) {
774 MWAW_DEBUG_MSG(("PowerPoint3ParserInternal::SubDocument::parse: no slide zone\n"));
775 return;
776 }
777
778 long pos = m_input->tell();
779 parser->sendText(*m_slide, m_textId, m_mainTextBox, m_isMaster);
780 m_input->seek(pos, librevenge::RVNG_SEEK_SET);
781 }
782 }
783
784 ////////////////////////////////////////////////////////////
785 // constructor/destructor, ...
786 ////////////////////////////////////////////////////////////
787 PowerPoint3Parser::PowerPoint3Parser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header)
788 : MWAWPresentationParser(input, rsrcParser, header)
789 , m_state(new PowerPoint3ParserInternal::State)
790 {
791 setAsciiName("main-1");
792 }
793
794 PowerPoint3Parser::~PowerPoint3Parser()
795 {
796 }
797
798 bool PowerPoint3Parser::getColor(int colorId, int schemeId, MWAWColor &color) const
799 {
800 // if scheme is defined, we must use it for 0<=colorId<8
801 if (schemeId>=0 && colorId>=0 && colorId<8 && m_state->m_idToSchemeMap.find(schemeId)!=m_state->m_idToSchemeMap.end()) {
802 color=m_state->m_idToSchemeMap.find(schemeId)->second.m_colors[colorId];
803 return true;
804 }
805 if (m_state->m_idToUserColorMap.find(colorId)!=m_state->m_idToUserColorMap.end()) {
806 color=m_state->m_idToUserColorMap.find(colorId)->second;
807 return true;
808 }
809 if (schemeId!=0) { // seems to happens in the master slide
810 MWAW_DEBUG_MSG(("PowerPoint3Parser::getColor: can not find color=%d in scheme=%d\n", colorId, schemeId));
811 }
812 return false;
813 }
814
815 ////////////////////////////////////////////////////////////
816 // the parser
817 ////////////////////////////////////////////////////////////
818 void PowerPoint3Parser::parse(librevenge::RVNGPresentationInterface *docInterface)
819 {
820 if (!getInput().get() || !checkHeader(nullptr)) throw(libmwaw::ParseException());
821 bool ok = true;
822 try {
823 ok = createZones();
824 if (ok) {
825 createDocument(docInterface);
826 sendSlides();
827 }
828
829 #ifdef DEBUG
830 checkForUnparsedZones();
831 if (m_state->m_oleParser)
832 m_state->m_oleParser->checkForUnparsedStream();
833 #endif
834 ascii().reset();
835 }
836 catch (...) {
837 MWAW_DEBUG_MSG(("PowerPoint3Parser::parse: exception catched when parsing\n"));
838 ok = false;
839 }
840
841 resetPresentationListener();
842 if (!ok) throw(libmwaw::ParseException());
843 }
844
845 ////////////////////////////////////////////////////////////
846 // create the document
847 ////////////////////////////////////////////////////////////
848 void PowerPoint3Parser::createDocument(librevenge::RVNGPresentationInterface *documentInterface)
849 {
850 if (!documentInterface) return;
851 if (getPresentationListener()) {
852 MWAW_DEBUG_MSG(("PowerPoint3Parser::createDocument: listener already exist\n"));
853 return;
854 }
855
856 std::vector<MWAWPageSpan> pageList;
857 for (auto id : m_state->m_slidesIdList) {
858 MWAWPageSpan ps(getPageSpan());
859 if (m_state->m_idToSlideMap.find(id)!=m_state->m_idToSlideMap.end()) {
860 int cId=m_state->m_idToSlideMap.find(id)->second.m_contentIds[0];
861 if (m_state->m_idToSlideContentMap.find(cId)!=m_state->m_idToSlideContentMap.end()) {
862 auto const &slide=m_state->m_idToSlideContentMap.find(cId)->second;
863 if (slide.m_useMasterPage && m_state->m_zoneIds[2]>=0)
864 ps.setMasterPageName(librevenge::RVNGString("Master"));
865 MWAWColor backColor;
866 if (getColor(0, slide.m_schemeId, backColor))
867 ps.setBackgroundColor(backColor);
868 }
869 }
870 pageList.push_back(ps);
871 }
872
873 //
874 MWAWPresentationListenerPtr listen(new MWAWPresentationListener(*getParserState(), pageList, documentInterface));
875 setPresentationListener(listen);
876 if (m_state->m_oleParser) {
877 librevenge::RVNGPropertyList metaData;
878 m_state->m_oleParser->updateMetaData(metaData);
879 listen->setDocumentMetaData(metaData);
880 }
881 listen->startDocument();
882 }
883
884
885 ////////////////////////////////////////////////////////////
886 // Intermediate level
887 ////////////////////////////////////////////////////////////
888
889 // create the different zones
890 bool PowerPoint3Parser::createZones()
891 {
892 MWAWInputStreamPtr input=getInput();
893 if (!input) {
894 MWAW_DEBUG_MSG(("PowerPoint3Parser::createZones: can not find the main input\n"));
895 return false;
896 }
897 bool const isMacFile=m_state->m_isMacFile;
898
899 std::shared_ptr<PowerPoint3OLE> oleParser;
900 if (input->isStructured()) {
901 MWAWInputStreamPtr mainOle=input->getSubStreamByName("PP40");
902 if (!mainOle) {
903 MWAW_DEBUG_MSG(("PowerPoint3Parser::createZones: can not find the main ole\n"));
904 return false;
905 }
906 int fId=3;
907 if (!isMacFile)
908 // create a temporary font, to use a CP1252 encoding
909 fId=getFontConverter()->getId("CP1252");
910 oleParser.reset(new PowerPoint3OLE(input, version(), getFontConverter(), fId));
911 oleParser->parse();
912 int encoding=oleParser->getFontEncoding();
913 if (!isMacFile && encoding>=1250 && encoding<=1258) {
914 std::stringstream s;
915 s << "CP" << encoding;
916 m_state->m_fontFamily=s.str();
917 }
918 getParserState()->m_input=input=mainOle;
919 input->setReadInverted(!isMacFile);
920 }
921 // create the asciiFile
922 ascii().setStream(input);
923 ascii().open(asciiName());
924 if (!checkHeader(nullptr)) return false;
925 m_state->m_oleParser=oleParser;
926 int docInfo;
927 if (!readListZones(docInfo)) return false;
928 size_t numZones=m_state->m_zonesList.size();
929 if (docInfo<0 || docInfo>=int(numZones) || !readDocInfo(m_state->m_zonesList[size_t(docInfo)])) {
930 MWAW_DEBUG_MSG(("PowerPoint3Parser::createZones: can not find the document info zone\n"));
931 return false;
932 }
933 // first try to read the font name and scheme
934 libmwaw::DebugStream f;
935 for (int w=0; w<3; ++w) {
936 int id=w==0 ? 11 : w==1 ? 7 : 8;
937 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_zoneIds[id]);
938 if (!entry.valid()) continue;
939 if (w==2) {
940 readColorZone(entry);
941 continue;
942 }
943 if (w==0 && !isMacFile) {
944 PowerPoint3ParserInternal::FontNameFieldParser parser(static_cast<int>(numZones));
945 readStructList(entry, parser);
946 for (auto const &it : parser.m_idToNameMap) {
947 m_state->m_idToFontIdMap[it.first]=it.first;
948 /* FIXME: by default, we force the family to be CP1252,
949 but we may want to use the file/font encoding */
950 getFontConverter()->setCorrespondance(it.first, it.second, it.second=="Monotype Sorts" || it.second=="Wingdings" ? "" : m_state->m_fontFamily);
951 }
952 for (auto cId : parser.m_childList) {
953 MWAWEntry const &cEntry=m_state->getZoneEntry(cId);
954 if (!cEntry.valid() || cEntry.isParsed()) continue;
955 cEntry.setParsed(true);
956 f.str("");
957 f << "Entries(FontDef)" << "[Z" << cEntry.id() << "]:";
958 ascii().addPos(cEntry.begin());
959 ascii().addNote(f.str().c_str());
960 ascii().addPos(cEntry.end());
961 ascii().addNote("_");
962 }
963 continue;
964 }
965 PowerPoint3ParserInternal::ListZoneIdParser parser(int(numZones), w==0 ? "FontName" : "Scheme");
966 if (!readStructList(entry, parser)) continue;
967 if (w==0) {
968 readFontNamesList(parser.m_fieldIdToZoneIdMap);
969 continue;
970 }
971 for (auto const &it : parser.m_fieldIdToZoneIdMap) {
972 MWAWEntry const &cEntry=m_state->getZoneEntry(it.second);
973 if (!cEntry.valid() || cEntry.isParsed()) continue;
974 readScheme(cEntry, it.first);
975 }
976 }
977 for (int i=0; i<13; ++i) {
978 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_zoneIds[i]);
979 if (!entry.valid() || entry.isParsed()) continue;
980 bool done=true;
981 switch (i) {
982 case 0:
983 readDocRoot(entry);
984 break;
985 case 1:
986 case 2: // master
987 case 3: {
988 PowerPoint3ParserInternal::Slide slide;
989 readSlide(entry, slide, i);
990 break;
991 }
992 case 5:
993 readPictureMain(entry);
994 break;
995 case 6: {
996 PowerPoint3ParserInternal::ListZoneIdParser parser(int(numZones), "Ruler");
997 if (readStructList(entry, parser)) {
998 for (auto const &it : parser.m_fieldIdToZoneIdMap) {
999 MWAWEntry const &cEntry=m_state->getZoneEntry(it.second);
1000 if (!cEntry.valid() || cEntry.isParsed()) continue;
1001 readRuler(cEntry, it.first);
1002 }
1003 }
1004 break;
1005 }
1006 case 9:
1007 readZone9(entry);
1008 break;
1009 case 10:
1010 readZone10(entry);
1011 break;
1012 default:
1013 done=false;
1014 }
1015 if (done) continue;
1016 entry.setParsed(true);
1017 f.str("");
1018 f << "Entries(Zone" << i << "A)[Z" << entry.id() << "]:";
1019 ascii().addPos(entry.begin());
1020 ascii().addNote(f.str().c_str());
1021 ascii().addPos(entry.end());
1022 ascii().addNote("_");
1023 }
1024 for (auto id : m_state->m_slidesIdList) {
1025 MWAWEntry const &entry=m_state->getZoneEntry(id);
1026 if (!entry.valid() || entry.isParsed()) continue;
1027 PowerPoint3ParserInternal::Slide slide;
1028 readSlide(entry, slide, -1);
1029 }
1030 for (int i=0; i<2; ++i) {
1031 MWAWEntry const &entry=m_state->getZoneEntry(m_state->m_printInfoIds[i]);
1032 if (!entry.valid() || entry.isParsed()) continue;
1033 if (isMacFile && i==0)
1034 readPrintInfo(entry);
1035 else {
1036 entry.setParsed(true);
1037 f.str("");
1038 f << "Entries(PrintInfo" << i << ")[Z" << entry.id() << "]:";
1039 ascii().addPos(entry.begin());
1040 ascii().addNote(f.str().c_str());
1041 ascii().addPos(entry.end());
1042 ascii().addNote("_");
1043 }
1044 }
1045 return !m_state->m_slidesIdList.empty();
1046 }
1047
1048 bool PowerPoint3Parser::readListZones(int &docInfoId)
1049 {
1050 docInfoId=-1;
1051 MWAWInputStreamPtr input=getInput();
1052 libmwaw::DebugStream f;
1053 f << "Entries(ListZones):";
1054 long pos=input->tell();
1055 auto N=int(input->readULong(2));
1056 f << "N=" << N << ",";
1057 if (!input->checkPosition(m_state->m_zoneListBegin+N*8)) {
1058 MWAW_DEBUG_MSG(("PowerPoint3Parser::readListZones: the number of zones seems bad\n"));
1059 f << "###zone";
1060 ascii().addPos(pos);
1061 ascii().addNote(f.str().c_str());
1062 return false;
1063 }
1064 auto val=int(input->readULong(2)); // always 4
1065 if (val!=4) f << "f0=" << val << ",";
1066 auto endPos=long(input->readULong(4));
1067 if (!input->checkPosition(endPos) || input->checkPosition(endPos+1)) {
1068 MWAW_DEBUG_MSG(("PowerPoint3Parser::readListZones: the endPos seems bad\n"));
1069 f << "###endPos=" << std::hex << endPos << std::dec << ",";
1070 }
1071 val=int(input->readULong(2)); // find a|10
1072 if (val) f << "f1=" << val << ",";
1073 docInfoId=int(input->readULong(2));
1074 if (docInfoId) f << "docInfo=Z" << docInfoId << ",";
1075 if (input->tell()!=m_state->m_zoneListBegin)
1076 ascii().addDelimiter(input->tell(),'|');
1077 ascii().addPos(pos);
1078 ascii().addNote(f.str().c_str());
1079
1080 input->seek(m_state->m_zoneListBegin, librevenge::RVNG_SEEK_SET);
1081 pos=input->tell();
1082 f.str("");
1083 f << "ListZones:zones=[";
1084 m_state->m_zonesList.resize(size_t(N));
1085 std::set<long> posList;
1086 for (int i=0; i<N; ++i) {
1087 unsigned long length=input->readULong(4);
1088 auto begin=long(input->readULong(4));
1089 if (length&0x80000000) {
1090 f << "*";
1091 length&=0x7FFFFFFF;
1092 }
1093 if (length&0x40000000) {
1094 f << "@";
1095 length&=0xBFFFFFFF;
1096 }
1097 if (length==0) {
1098 f << "_,";
1099 continue;
1100 }
1101 if (begin+long(length)<=begin || !input->checkPosition(begin+long(length))) {
1102 MWAW_DEBUG_MSG(("PowerPoint3Parser::readListZones: a zone seems bad\n"));
1103 f << std::hex << begin << ":" << begin+long(length) << std::dec << "###,";
1104 continue;
1105 }
1106 MWAWEntry &zone=m_state->m_zonesList[size_t(i)];
1107 zone.setBegin(begin);
1108 zone.setLength(long(length));
1109 zone.setId(i);
1110 posList.insert(begin);
1111 posList.insert(zone.end());
1112 f << std::hex << begin << ":" << begin+long(length) << std::dec << ",";
1113 }
1114 f << "],";
1115 ascii().addPos(pos);
1116 ascii().addNote(f.str().c_str());
1117 // check that the zones do not overlap
1118 for (size_t i=0; i<m_state->m_zonesList.size(); ++i) {
1119 MWAWEntry const &zone=m_state->m_zonesList[size_t(i)];
1120 if (!zone.valid()) continue;
1121 auto it=posList.find(zone.begin());
1122 bool ok=it!=posList.end();
1123 if (ok) {
1124 if (++it==posList.end() || *it!=zone.end())
1125 ok=false;
1126 }
1127 if (ok) continue;
1128 MWAW_DEBUG_MSG(("PowerPoint3Parser::readListZones: the zone %d overlaps with other zones\n", int(i)));
1129 m_state->m_zonesList[size_t(i)]=MWAWEntry();
1130 }
1131 ascii().addPos(input->tell());
1132 ascii().addNote("_");
1133 return true;
1134 }
1135
1136 void PowerPoint3Parser::checkForUnparsedZones()
1137 {
1138 // check if there remains some unparsed zone
1139 for (auto const &entry : m_state->m_zonesList) {
1140 if (!entry.valid() || entry.isParsed()) continue;
1141 static bool first=true;
1142 if (first) {
1143 first=false;
1144 MWAW_DEBUG_MSG(("PowerPoint3Parser::checkForUnparsedZones: find some unknown zone\n"));
1145 }
1146 libmwaw::DebugStream f;
1147 f << "Entries(UnknZone)[Z" << entry.id() << "]:";
1148 ascii().addPos(entry.begin());
1149 ascii().addNote(f.str().c_str());
1150 ascii().addPos(entry.end());
1151 ascii().addNote("_");
1152 }
1153 }
1154
1155 ////////////////////////////////////////////////////////////
1156 // try to read the different zones
1157 ////////////////////////////////////////////////////////////
1158 bool PowerPoint3Parser::readDocInfo(MWAWEntry const &entry)
1159 {
1160 MWAWInputStreamPtr input=getInput();
1161 int const vers=version();
1162 if (entry.length()!=(vers<=3 ? 142 : 146)) {
1163 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: the entry %d seems bad\n", entry.id()));
1164 return false;
1165 }
1166 entry.setParsed(true);
1167 input->seek(entry.begin(), librevenge::RVNG_SEEK_SET);
1168 long pos=input->tell();
1169 libmwaw::DebugStream f;
1170 f << "Entries(DocInfo)[Z" << entry.id() << "]:";
1171 int val;
1172 auto numZones=int(m_state->m_zonesList.size());
1173 f << "unkn=[";
1174 for (int i=0; i<4; ++i) { // list of 0 or big number (multiple of 12?)
1175 val=int(input->readLong(2));
1176 if (val) f << float(val)/12.f << ",";
1177 else f << "_,";
1178 }
1179 f << "],";
1180 int dim[4];
1181 for (auto &d : dim) d=int(input->readLong(2));
1182 if (!m_state->m_isMacFile) {
1183 std::swap(dim[0],dim[1]);
1184 std::swap(dim[2],dim[3]);
1185 }
1186 MWAWBox2i pageBox(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2]));
1187 f << "dim[page]=" << pageBox << ",";
1188 for (auto &d : dim) d=int(input->readLong(2));
1189 if (!m_state->m_isMacFile) {
1190 std::swap(dim[0],dim[1]);
1191 std::swap(dim[2],dim[3]);
1192 }
1193 MWAWBox2i paperBox=MWAWBox2i(MWAWVec2i(dim[0],dim[1]),MWAWVec2i(dim[2],dim[3]));
1194 f << "dim[paper]=" << paperBox << ",";
1195 MWAWVec2i paperSize = paperBox.size();
1196 MWAWVec2i pageSize = pageBox.size();
1197 // basic check
1198 if (pageSize.x()+pageSize.y() > paperSize.x()+paperSize.y()) {
1199 // checkme: is page/paper order inverted in mac file?
1200 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: swap page and paper box\n"));
1201 std::swap(pageBox, paperBox);
1202 std::swap(pageSize, paperSize);
1203 f << "##paper/page,";
1204 }
1205 if (pageSize.x() > paperSize.x() || pageSize.y() > paperSize.y()) {
1206 // checkme: rare happened on one file found on internet, related to page orientation?
1207 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: swap paper x/y\n"));
1208 paperBox=MWAWBox2i(MWAWVec2i(paperBox[0][1],paperBox[0][0]),MWAWVec2i(paperBox[1][1],paperBox[1][0]));
1209 paperSize = paperBox.size();
1210 f << "##paperXY,";
1211 }
1212 m_state->m_origin=-1*paperBox[0];
1213 if (pageSize.x() <= 0 || pageSize.y() <= 0 ||
1214 paperSize.x() <= 0 || paperSize.y() <= 0 ||
1215 pageSize.x() > paperSize.x() || pageSize.y() > paperSize.y()) {
1216 f << "###,";
1217 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: the page dimension seems bad\n"));
1218 }
1219 else {
1220 // checkme, maybe better to define a slide with pageSize and no margins
1221 getPageSpan().setFormOrientation(MWAWPageSpan::PORTRAIT);
1222 if (pageBox[0][1]>=paperBox[0][1])
1223 getPageSpan().setMarginTop(double(pageBox[0][1]-paperBox[0][1])/576.0);
1224 if (pageBox[1][1]<=paperBox[1][1])
1225 getPageSpan().setMarginBottom(double(paperBox[1][1]-pageBox[1][1])/576.0);
1226 if (pageBox[0][0]>=paperBox[0][0])
1227 getPageSpan().setMarginLeft(double(pageBox[0][0]-paperBox[0][0])/576.0);
1228 if (pageBox[1][0]<=paperBox[1][0])
1229 getPageSpan().setMarginRight(double(paperBox[1][0]-pageBox[1][0])/576.0);
1230 getPageSpan().setFormLength(double(paperSize.y())/576.0);
1231 getPageSpan().setFormWidth(double(paperSize.x())/576.0);
1232 }
1233 for (auto &d : dim) d=int(input->readLong(2));
1234 f << "dim=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
1235 val=int(input->readLong(2));
1236 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1237 for (int i=0; i<5; ++i) {
1238 m_state->m_zoneIds[i]=int(input->readULong(4));
1239 f << "zone[id" << i << "]=Z" << m_state->m_zoneIds[i] << ",";
1240 if (m_state->m_zoneIds[i]>=numZones) {
1241 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: the zoneId %d seems bad\n", m_state->m_zoneIds[i]));
1242 f << "###";
1243 m_state->m_zoneIds[i]=-1;
1244 }
1245 }
1246 ascii().addPos(pos);
1247 ascii().addNote(f.str().c_str());
1248
1249 pos=input->tell();
1250 f.str("");
1251 f << "DocInfo-2:";
1252 for (int i=0; i<2; ++i) dim[i]=int(input->readLong(2));
1253 f << "dim?=" << MWAWVec2i(dim[1],dim[0]) << ",";
1254 val=int(input->readLong(2)); // 1,2,8
1255 if (val) f << "f0=" << val << ",";
1256 val=int(input->readULong(2)); // big number
1257 if (val) f << "fl=" << std::hex << val << std::dec << ",";
1258 f << "unk=[";
1259 for (int i=0; i<5; ++i) { // 1,2,3,2|3|4,0|3|4
1260 val=int(input->readLong(2));
1261 f << val << ",";
1262 }
1263 f << "],";
1264 for (int i=0; i<2; ++i) { // f1=big number, f2=0
1265 val=int(input->readULong(1));
1266 if (val) f << "fl" << i+1 << "=" << std::hex << val << std::dec << ",";
1267 }
1268 ascii().addPos(pos);
1269 ascii().addNote(f.str().c_str());
1270
1271 pos=input->tell();
1272 f.str("");
1273 f << "DocInfo-3:";
1274 f << "zones=[";
1275 for (int i=0; i<8; ++i) {
1276 // 0: picture zones, 1: picture pos?, 2: some style?,
1277 long id=input->readLong(4);
1278 if (id==0 || id==-1)
1279 f << "_,";
1280 else if (id>0 && id<numZones) {
1281 f << "Z" << id << ",";
1282 m_state->m_zoneIds[i+5]=int(id);
1283 }
1284 else {
1285 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: find odd zone\n"));
1286 f << "###" << id << ",";
1287 }
1288 }
1289 f << "],";
1290 for (auto &d : dim) d=int(input->readULong(2));
1291 f << "page=" << MWAWVec2i(dim[0],dim[1]) << ",";
1292 f << "dim?=" << MWAWVec2i(dim[3],dim[2]) << ","; // frame, slide dim?
1293 for (int i=0; i<2; ++i) { // f2=1, f3=0
1294 val=int(input->readLong(2));
1295 if (val!=1-i)
1296 f << "f" << i << "=" << val << ",";
1297 }
1298 for (int i=0; i<2; ++i) {
1299 m_state->m_printInfoIds[i]= int(input->readLong(4));
1300 if (m_state->m_printInfoIds[i]==-1) continue;
1301 f << "printInfo[id" << i << "]=Z" << m_state->m_printInfoIds[i] << ",";
1302 if (m_state->m_printInfoIds[i]>=numZones) {
1303 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocInfo: the printInfoId %d seems bad\n", m_state->m_printInfoIds[i]));
1304 f << "###";
1305 m_state->m_printInfoIds[i]=-1;
1306 }
1307 }
1308 for (int i=0; i<3; ++i) {
1309 val=int(input->readLong(i<2 ? 4 : 2));
1310 int const expected[]= {10000, 7500, -2};
1311 if (val!=expected[i])
1312 f << "g" << i << "=" << val << ",";
1313 }
1314 if (vers<=3) {
1315 for (int i=0; i<2; ++i) { // two big number
1316 val=int(input->readULong(2));
1317 if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
1318 }
1319 val=int(input->readLong(2)); // 3|4
1320 if (val) f << "g3=" << val << ",";
1321 }
1322 else {
1323 for (int i=0; i<5; ++i) { // three big number
1324 val=int(input->readULong(2));
1325 if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
1326 }
1327 }
1328 ascii().addPos(pos);
1329 ascii().addNote(f.str().c_str());
1330 ascii().addPos(entry.end());
1331 ascii().addNote("_");
1332
1333 return true;
1334 }
1335
1336 bool PowerPoint3Parser::readPrintInfo(MWAWEntry const &entry)
1337 {
1338 if (entry.length() != 0x78) {
1339 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPrintInfo: the zone seems bad\n"));
1340 return false;
1341 }
1342 MWAWInputStreamPtr input = getInput();
1343 long pos = entry.begin();
1344 entry.setParsed(true);
1345 input->seek(pos, librevenge::RVNG_SEEK_SET);
1346 libmwaw::DebugStream f;
1347 // print info
1348 libmwaw::PrinterInfo info;
1349 if (!info.read(input)) return false;
1350 f << "Entries(PrintInfo)[Z"<< entry.id() << "]:" << info;
1351
1352 // this is the final paper, so let ignore this
1353 MWAWVec2i paperSize = info.paper().size();
1354 MWAWVec2i pageSize = info.page().size();
1355 if (pageSize.x() <= 0 || pageSize.y() <= 0 ||
1356 paperSize.x() <= 0 || paperSize.y() <= 0) return false;
1357 ascii().addPos(pos);
1358 ascii().addNote(f.str().c_str());
1359
1360 ascii().addPos(entry.end());
1361 ascii().addNote("_");
1362
1363 return true;
1364 }
1365
1366 bool PowerPoint3Parser::readDocRoot(MWAWEntry const &entry)
1367 {
1368 if (!entry.valid() || entry.length()!=22) {
1369 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocRoot: the zone seems bad\n"));
1370 return false;
1371 }
1372 MWAWInputStreamPtr input = getInput();
1373 long pos = entry.begin();
1374 entry.setParsed(true);
1375 input->seek(pos, librevenge::RVNG_SEEK_SET);
1376 libmwaw::DebugStream f;
1377 f << "Entries(DocRoot)[Z"<< entry.id() << "]:";
1378 int val;
1379 for (int i=0; i<2; ++i) { // fl0=[359][4c], fl1=0|c
1380 val=int(input->readULong(1));
1381 if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
1382 }
1383 for (int i=0; i<2; ++i) { // big numbers, maybe a int32t
1384 val=int(input->readLong(2));
1385 if (val) f << "f" << i << "=" << val << ",";
1386 }
1387 auto numZones=int(m_state->m_zonesList.size());
1388 val=int(input->readULong(4));
1389 int child=-1;
1390 if (val) {
1391 if (val>=0 && val<numZones) {
1392 f << "slideList[id]=Z" << val << ",";
1393 child=val;
1394 }
1395 else {
1396 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocRoot: find some bad child\n"));
1397 f << "slideList[id]=##Z" << val << ",";
1398 }
1399 }
1400 for (int i=0; i<2; ++i) { // f2=1 (actual slide?)
1401 val=int(input->readLong(2));
1402 if (!val) continue;
1403 if (i==1)
1404 f << "num[slides]=" << val << ",";
1405 else
1406 f << "f2=" << val << ",";
1407 }
1408 val=int(input->readULong(4)); // 257-298
1409 if (val) f << "f3=" << val << ",";
1410 for (int i=0; i<2; ++i) { // big numbers, maybe a int32t
1411 val=int(input->readLong(2));
1412 if (val) f << "f" << i+4 << "=" << val << ",";
1413 }
1414 ascii().addPos(pos);
1415 ascii().addNote(f.str().c_str());
1416 ascii().addPos(entry.end());
1417 ascii().addNote("_");
1418
1419 MWAWEntry const &cEntry=m_state->getZoneEntry(child);
1420 if (cEntry.valid() && !cEntry.isParsed())
1421 readSlidesList(cEntry);
1422 else {
1423 MWAW_DEBUG_MSG(("PowerPoint3Parser::readDocRoot: can not find the slide list...\n"));
1424 return false;
1425 }
1426 return true;
1427 }
1428
1429 bool PowerPoint3Parser::readScheme(MWAWEntry const &entry, int id)
1430 {
1431 int const vers=version();
1432 if (!entry.valid() || entry.length()<(vers<=3 ? 94 : 118)) {
1433 MWAW_DEBUG_MSG(("PowerPoint3Parser::readScheme: the zone seems bad\n"));
1434 return false;
1435 }
1436 MWAWInputStreamPtr input = getInput();
1437 long pos = entry.begin();
1438 entry.setParsed(true);
1439 PowerPoint3ParserInternal::Scheme scheme;
1440 input->seek(pos, librevenge::RVNG_SEEK_SET);
1441 libmwaw::DebugStream f;
1442 f << "Entries(Scheme)[Z"<< entry.id() << "]:S" << id << ",";
1443 int val;
1444 val=int(input->readLong(2)); // -2|-6
1445 if (val!=-2) f << "f0=" << val << ",";
1446 if (vers>=4) {
1447 for (int i=0; i<12; ++i) {
1448 val=int(input->readLong(2));
1449 if (val) f << "g" << i << "=" << val << ",";
1450 }
1451 }
1452 for (int i=0; i<14; ++i) { // f2=X, f3=X|0, f4,f5,f6:small number, f7=0|1|101, f8=0|1, f9=0|e1c,f10=0|3715,f11=0|80
1453 val=int(input->readLong(2));
1454 int const expected[]= {0,0,0,100,100,100, 0x101, 0, 0, 0, 0, 0, 7, 0};
1455 if (val!=expected[i])
1456 f << "f" << i+1 << "=" << val << ",";
1457 }
1458 f << "colors=[";
1459 for (auto &color : scheme.m_colors) {
1460 val=int(input->readULong(2));
1461 unsigned char col[3];
1462 for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8);
1463 color=MWAWColor(col[0],col[1],col[2]);
1464 f << color << ":" << val << ",";
1465 }
1466 f << "],";
1467 if (m_state->m_idToSchemeMap.find(id)!=m_state->m_idToSchemeMap.end()) {
1468 MWAW_DEBUG_MSG(("PowerPoint3Parser::readScheme: oops, scheme S%d is already defined\n", id));
1469 }
1470 else
1471 m_state->m_idToSchemeMap[id]=scheme;
1472 ascii().addPos(pos);
1473 ascii().addNote(f.str().c_str());
1474 ascii().addPos(entry.end());
1475 ascii().addNote("_");
1476 if (input->tell()!=entry.end()) {
1477 MWAW_DEBUG_MSG(("PowerPoint3Parser::readScheme: find extra data\n"));
1478 ascii().addPos(input->tell());
1479 ascii().addNote("Scheme:##extra");
1480 }
1481 return true;
1482 }
1483
1484 bool PowerPoint3Parser::readSlidesList(MWAWEntry const &entry)
1485 {
1486 if (!entry.valid() || (entry.length()%16)!=0) {
1487 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlidesList: the zone seems bad\n"));
1488 return false;
1489 }
1490 MWAWInputStreamPtr input = getInput();
1491 long pos = entry.begin();
1492 entry.setParsed(true);
1493 input->seek(pos, librevenge::RVNG_SEEK_SET);
1494 libmwaw::DebugStream f;
1495 f << "Entries(SlideList)[Z"<< entry.id() << "]:";
1496 auto N=int(input->readULong(2));
1497 f << "N=" << N << ",";
1498 if ((N+1)*16>int(entry.length())) {
1499 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlidesList: the number of slides seems bad\n"));
1500 f << "###";
1501 N=int(entry.length()/16)-1;
1502 }
1503 auto val=int(input->readLong(4)); // always 10, headerSz?
1504 if (val!=10) f << "f0=" << val << ",";
1505 for (int i=0; i<5; ++i) { // f1=1
1506 val=int(input->readLong(2));
1507 if (val) f << "f" << i+1 << "=" << val << ",";
1508 }
1509 ascii().addPos(pos);
1510 ascii().addNote(f.str().c_str());
1511 auto const numZones=int(m_state->m_zonesList.size());
1512 m_state->m_slidesIdList.resize(size_t(N), -1);
1513 for (int i=0; i<N; ++i) {
1514 pos=input->tell();
1515 f.str("");
1516 f << "SlideList-" << i << ":";
1517 for (int j=0; j<3; ++j) { // f0=0-3
1518 val=int(input->readLong(2));
1519 if (val) f << "f" << j << "=" << val << ",";
1520 }
1521 for (int j=0; j<2; ++j) { // fl0=0|1|81
1522 val=int(input->readULong(1));
1523 if (val) f << "fl" << j << "=" << std::hex << val << std::dec << ",";
1524 }
1525 for (int j=0; j<2; ++j) { // always 0
1526 val=int(input->readLong(2));
1527 if (val) f << "f" << j+2 << "=" << val << ",";
1528 }
1529 val=int(input->readULong(4));
1530 if (val>=0 && val<numZones) {
1531 f << "slide[id]=Z" << val << ",";
1532 m_state->m_slidesIdList[size_t(i)]=val;
1533 }
1534 else {
1535 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlidesList: find some bad child\n"));
1536 f << "slide[id]=##Z" << val << ",";
1537 }
1538 ascii().addPos(pos);
1539 ascii().addNote(f.str().c_str());
1540 }
1541 if (input->tell()!=entry.end()) {
1542 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlidesList: find extra data\n"));
1543 ascii().addPos(input->tell());
1544 ascii().addNote("SlideList-extra:###");
1545 }
1546 ascii().addPos(entry.end());
1547 ascii().addNote("_");
1548 return true;
1549 }
1550
1551 bool PowerPoint3Parser::readSlide(MWAWEntry const &entry, PowerPoint3ParserInternal::Slide &slide, int zId)
1552 {
1553 int const vers=version();
1554 if (!entry.valid() || entry.length()!=(vers<=3 ? 32 : 34)) {
1555 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlide: the zone seems bad\n"));
1556 return false;
1557 }
1558 MWAWInputStreamPtr input = getInput();
1559 long pos = entry.begin();
1560 entry.setParsed(true);
1561 input->seek(pos, librevenge::RVNG_SEEK_SET);
1562 libmwaw::DebugStream f;
1563 if (zId>=0)
1564 f << "Entries(SlideMain)[Z"<< entry.id() << "," << zId << "]:";
1565 else
1566 f << "Entries(SlideMain)[Z"<< entry.id() << "]:";
1567 auto val=int(input->readULong(4));
1568 if (val) f << "id=" << std::hex << val << std::dec << ",";
1569 auto const numZones=int(m_state->m_zonesList.size());
1570 int childA=-1;
1571 for (size_t i=0; i<3; ++i) {
1572 val=int(input->readULong(4));
1573 if (i && val==0) continue;
1574 char const *wh[]= {"transition[id]", "slide[id]", "note[id]"};
1575 if (val>=0 && val<numZones) {
1576 f << wh[i] << "=Z" << val << ",";
1577 if (i==0)
1578 childA=val;
1579 else
1580 slide.m_contentIds[i-1]=val;
1581 }
1582 else {
1583 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlide: find some bad child\n"));
1584 f << wh[i] << "=##Z" << val << ",";
1585 }
1586 }
1587 f << "ids=[";
1588 for (int i=0; i<3; ++i) // first two big numbers, last 1|2a3d
1589 f << std::hex << input->readULong(4) << std::dec << ",";
1590 f << "],";
1591 for (int i=0; i<2; ++i) { // f0=0(for mac),-1(for pc), f1=0
1592 val=int(input->readLong(2));
1593 if (val) f << "f" << i << "=" << val << ",";
1594 }
1595 m_state->m_idToSlideMap[entry.id()]=slide;
1596 ascii().addPos(pos);
1597 ascii().addNote(f.str().c_str());
1598 ascii().addPos(entry.end());
1599 ascii().addNote("_");
1600 for (size_t i=0; i<3; ++i) {
1601 int id=i==0 ? childA : slide.m_contentIds[i-1];
1602 MWAWEntry const &cEntry=m_state->getZoneEntry(id);
1603 if (!cEntry.valid() || cEntry.isParsed()) continue;
1604 if (i==0)
1605 readSlideTransition(cEntry);
1606 else {
1607 PowerPoint3ParserInternal::SlideContent content;
1608 if (readSlideContent(cEntry, content))
1609 m_state->m_idToSlideContentMap[id]=content;
1610 }
1611 }
1612 return true;
1613 }
1614
1615 bool PowerPoint3Parser::readSlideTransition(MWAWEntry const &entry)
1616 {
1617 if (!entry.valid() || entry.length()!=24) {
1618 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlideTransition: the zone seems bad\n"));
1619 return false;
1620 }
1621 MWAWInputStreamPtr input = getInput();
1622 long pos = entry.begin();
1623 entry.setParsed(true);
1624 input->seek(pos, librevenge::RVNG_SEEK_SET);
1625 libmwaw::DebugStream f;
1626 f << "Entries(SlideTransition)[Z"<< entry.id() << "]:";
1627 int val;
1628 for (int i=0; i<2; ++i) {
1629 val=int(input->readULong(2));
1630 int const expected[]= {m_state->m_isMacFile ? 0 : 0x4b4e, 0x554e};
1631 if (val==expected[i]) continue;
1632 if (i==0)
1633 f << "effect=" << val << ",";
1634 else
1635 f << "id" << i << "=" << std::hex << val << std::dec << ",";
1636 }
1637 val=int(input->readLong(2));
1638 switch (val) {
1639 case 0:
1640 f << "effect[slow],";
1641 break;
1642 case 1:
1643 f << "effect[medium],";
1644 break;
1645 case 2: // fast
1646 break;
1647 default:
1648 f << "effect=##" << val << ",";
1649 break;
1650 }
1651 val=int(input->readULong(2)); // small number
1652 if (val) f << "f0=" << val << ",";
1653 val=int(input->readLong(4));
1654 if (val!=-1) f << "adv[time]=" << double(val)/1000. << "s,";
1655 val=int(input->readLong(2));
1656 if (val) f << "f1=" << val << ",";
1657 for (int i=0; i<2; ++i) {
1658 val=int(input->readLong(1));
1659 int const expected[]= {7, 2};
1660 if (val!=expected[i]) f << "f" << i+2 << "=" << val << ",";
1661 }
1662 for (int i=0; i<3; ++i) { // g0=0|c
1663 val=int(input->readLong(2));
1664 if (val) f << "g" << i << "=" << val << ",";
1665 }
1666 val=int(input->readULong(1)); // 0|3f
1667 if (val) f << "g3=" << val << ",";
1668 ascii().addPos(pos);
1669 ascii().addNote(f.str().c_str());
1670 ascii().addPos(entry.end());
1671 ascii().addNote("_");
1672 return true;
1673 }
1674
1675 bool PowerPoint3Parser::readSlideContent(MWAWEntry const &entry, PowerPoint3ParserInternal::SlideContent &slide)
1676 {
1677 if (!entry.valid() || entry.length()!=38) {
1678 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlideContent: the zone seems bad\n"));
1679 return false;
1680 }
1681 MWAWInputStreamPtr input = getInput();
1682 long pos = entry.begin();
1683 entry.setParsed(true);
1684 input->seek(pos, librevenge::RVNG_SEEK_SET);
1685 libmwaw::DebugStream f;
1686 f << "Entries(SlideContent)[Z"<< entry.id() << "]:";
1687 int val;
1688 auto numZones=int(m_state->m_zonesList.size());
1689 std::vector<int> listChild;
1690 listChild.resize(4, -1);
1691 for (size_t i=0; i<2; ++i) {
1692 val=int(input->readULong(4));
1693 if (!val) continue;
1694 f << (i==0 ? "text[id]" : "frame[id]") << "=Z" << val << ",";
1695 if (val>=0 && val<numZones)
1696 listChild[i]=val;
1697 else {
1698 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlideContent: find some bad child\n"));
1699 f << "###";
1700 }
1701 }
1702 f << "num[shapes]=" << input->readLong(2) << ",";
1703 f << "act[shape]=" << input->readLong(2) << ",";
1704 f << "frames[ids]=["; // 0: ?, 1: title, 2: body
1705 slide.m_numMainZones=0;
1706 for (int i=0; i<3; ++i) {
1707 val=int(input->readLong(2));
1708 if (val==-1) {
1709 f << "_,";
1710 continue;
1711 }
1712 if (i>=1) slide.m_mainZoneIds[i-1]=val;
1713 f << val << ",";
1714 }
1715 f << "],";
1716 val=int(input->readULong(1));
1717 f << "useMaster[";
1718 if (m_state->m_isMacFile) {
1719 if (val&0x80) {
1720 slide.m_useMasterPage=true;
1721 f << "content,";
1722 }
1723 if (val&0x40)
1724 f << "schemeStyle,";
1725 if (val&0x20)
1726 f << "titleStyle,";
1727 if (val&0x10)
1728 f << "bodyStyle,";
1729 val &= 0xF;
1730 }
1731 else {
1732 if (val&1) {
1733 slide.m_useMasterPage=true;
1734 f << "content,";
1735 }
1736 val &= 0xFE;
1737 }
1738 f << "],";
1739 if (val)
1740 f << "fl=" << std::hex << val << std::dec << ",";
1741 val=int(input->readULong(1));
1742 if (val) f << "fl1=" << std::hex << val << std::dec << ",";
1743 slide.m_schemeId=int(input->readULong(2));
1744 if (slide.m_schemeId) f << "scheme=S" << slide.m_schemeId << ",";
1745 val=int(input->readULong(1));
1746 if (val) f << "fl2=" << std::hex << val << std::dec << ",";
1747 for (int i=0; i<7; ++i) {
1748 val=int(input->readULong(1));
1749 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
1750 }
1751 for (size_t i=2; i<4; ++i) {
1752 val=int(input->readULong(4));
1753 if (!val) continue;
1754 f << (i==2 ? "format[id]" : "poly[id]") << "=Z" << val << ",";
1755 if (val>=0 && val<numZones)
1756 listChild[i]=val;
1757 else {
1758 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlideContent: find some bad child\n"));
1759 f << "###";
1760 }
1761 }
1762 ascii().addPos(pos);
1763 ascii().addNote(f.str().c_str());
1764 ascii().addPos(entry.end());
1765 ascii().addNote("_");
1766 for (size_t i=0; i<4; ++i) {
1767 size_t const orders[]= {0, 2, 1, 3};
1768 size_t const id=orders[i];
1769 MWAWEntry const &cEntry=m_state->getZoneEntry(listChild[id]);
1770 if (!cEntry.valid() || cEntry.isParsed()) continue;
1771 if (id==0)
1772 readTextZone(cEntry, slide);
1773 else if (id==1)
1774 readFramesList(cEntry, slide);
1775 else if (id==2)
1776 readSlideFormats(cEntry, slide.m_formatList);
1777 else
1778 readSlidePolygons(cEntry, slide.m_polygonList);
1779 }
1780 return true;
1781 }
1782
1783 bool PowerPoint3Parser::readSlideFormats(MWAWEntry const &entry, std::vector<PowerPoint3ParserInternal::SlideFormat> &formatList)
1784 {
1785 int const vers=version();
1786 int const dSz = vers<=3 ? 20 : 26;
1787 if (!entry.valid() || (entry.length()%dSz)!=0) {
1788 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlideFormats: the zone Z%d seems bad\n", entry.id()));
1789 return false;
1790 }
1791 MWAWInputStreamPtr input = getInput();
1792 long pos = entry.begin();
1793 entry.setParsed(true);
1794 input->seek(pos, librevenge::RVNG_SEEK_SET);
1795 libmwaw::DebugStream f;
1796 f << "Entries(SlideFormat)[Z"<< entry.id() << "]:";
1797 ascii().addPos(pos);
1798 ascii().addNote(f.str().c_str());
1799 bool const isMacFile=m_state->m_isMacFile;
1800 auto N=size_t(entry.length()/dSz);
1801 formatList.resize(N);
1802 for (size_t i=0; i<N; ++i) {
1803 PowerPoint3ParserInternal::SlideFormat &format=formatList[i];
1804 pos=input->tell();
1805 f.str("");
1806 f << "SlideFormat-" << i << ":";
1807 int val;
1808 for (int j=0; j<2; ++j) { // fl0=[1-c]0
1809 val=int(input->readULong(1));
1810 if (!isMacFile) val=PowerPoint3ParserInternal::swapBool8(val);
1811 if (val) f << "fl" << j << "=" << std::hex << val << std::dec << ",";
1812 }
1813 val=int(input->readULong(4));
1814 if (val) f << "id=" << std::hex << val << std::dec << ",";
1815 int dim[2];
1816 for (auto &d : dim) d=int(input->readLong(2));
1817 if (!isMacFile) std::swap(dim[0],dim[1]);
1818 f << "dim0=" << MWAWVec2i(dim[1], dim[0]) << ",";
1819 format.m_gradientOffset=int(input->readLong(2));
1820 if (format.m_gradientOffset) f << "grad[col,offset]=" << format.m_gradientOffset << ",";
1821 for (auto &d : dim) d=int(input->readLong(2));
1822 if (!isMacFile) std::swap(dim[0],dim[1]);
1823 format.m_margins=MWAWVec2i(dim[1], dim[0]);
1824 f << "box[margins]=" << format.m_margins << ",";
1825 for (auto &d : dim) d=int(input->readLong(2));
1826 if (!isMacFile) std::swap(dim[0],dim[1]);
1827 format.m_shadowOffset=MWAWVec2i(dim[1], dim[0]);
1828 if (format.m_shadowOffset!=MWAWVec2i(0,0))
1829 f << "shadow[offset]=" << format.m_shadowOffset << ",";
1830 if (input->tell()!=pos+dSz) {
1831 ascii().addDelimiter(input->tell(),'|');
1832 input->seek(pos+dSz, librevenge::RVNG_SEEK_SET);
1833 }
1834 ascii().addPos(pos);
1835 ascii().addNote(f.str().c_str());
1836 }
1837 ascii().addPos(entry.end());
1838 ascii().addNote("_");
1839 return true;
1840 }
1841
1842 bool PowerPoint3Parser::readSlidePolygons(MWAWEntry const &entry, std::vector<PowerPoint3ParserInternal::Polygon> &polyList)
1843 {
1844 if (!entry.valid() || entry.length()<12) {
1845 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlidePolygons: the zone Z%d seems bad\n", entry.id()));
1846 return false;
1847 }
1848 MWAWInputStreamPtr input = getInput();
1849 long pos = entry.begin();
1850 entry.setParsed(true);
1851 input->seek(pos, librevenge::RVNG_SEEK_SET);
1852 libmwaw::DebugStream f;
1853 f << "Entries(SlidePolygon)[Z"<< entry.id() << "]:";
1854 ascii().addPos(pos);
1855 ascii().addNote(f.str().c_str());
1856 int n=0;
1857 bool const isMacFile=m_state->m_isMacFile;
1858 while (input->tell()<entry.end()+12) {
1859 pos=input->tell();
1860 f.str("");
1861 f << "SlidePolygon-" << n++ << ":";
1862 auto N=int(input->readULong(2));
1863 if (pos+4+(N+2)*4 > entry.end()) {
1864 input->seek(pos, librevenge::RVNG_SEEK_SET);
1865 break;
1866 }
1867 polyList.push_back(PowerPoint3ParserInternal::Polygon());
1868 auto &poly=polyList.back();
1869 f << "N=" << N << ",";
1870 poly.m_type=int(input->readULong(2));
1871 f << "type=" << poly.m_type << ",";
1872 int dim[4];
1873 for (auto &d : dim) d=int(input->readLong(2));
1874 if (!isMacFile) {
1875 std::swap(dim[0],dim[1]);
1876 std::swap(dim[2],dim[3]);
1877 }
1878 poly.m_box=MWAWBox2i(MWAWVec2i(dim[1],dim[0]), MWAWVec2i(dim[3],dim[2]));
1879 f << "box=" << poly.m_box << ",";
1880 f << "pts=[";
1881 for (int pt=0; pt<N; ++pt) {
1882 for (int i=0; i<2; ++i) dim[i]=int(input->readLong(2));
1883 if (!isMacFile) std::swap(dim[0],dim[1]);
1884 poly.m_vertices.push_back(MWAWVec2f(float(dim[1])/8.f, float(dim[0])/8.f));
1885 f << poly.m_vertices.back() << ",";
1886 }
1887 f << "],";
1888 ascii().addPos(pos);
1889 ascii().addNote(f.str().c_str());
1890 }
1891 if (input->tell()!=entry.end()) {
1892 MWAW_DEBUG_MSG(("PowerPoint3Parser::readSlidePolygons: find extra data\n"));
1893 ascii().addPos(input->tell());
1894 ascii().addNote("SlidePolygon:###extra");
1895 }
1896 ascii().addPos(entry.end());
1897 ascii().addNote("_");
1898 return true;
1899 }
1900
1901 bool PowerPoint3Parser::readFramesList(MWAWEntry const &entry, PowerPoint3ParserInternal::SlideContent &content)
1902 {
1903 if (!entry.valid() || (entry.length()%32)!=0) {
1904 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: the zone seems bad\n"));
1905 return false;
1906 }
1907 int const vers=version();
1908 MWAWInputStreamPtr input = getInput();
1909 long pos = entry.begin();
1910 entry.setParsed(true);
1911 input->seek(pos, librevenge::RVNG_SEEK_SET);
1912 libmwaw::DebugStream f;
1913 f << "Entries(Frames)[Z"<< entry.id() << "]:";
1914 ascii().addPos(pos);
1915 ascii().addNote(f.str().c_str());
1916
1917 auto N=size_t(entry.length()/32);
1918 bool const isMacFile=m_state->m_isMacFile;
1919 content.m_frameList.resize(N);
1920 int format=0, poly=0, text=0;
1921 int showTypes[3]= {0,0,0}; // surf, frame, shadow
1922 // surf, surf[back], frame, frame[back], shadow
1923 MWAWColor colors[5]= {MWAWColor::black(),MWAWColor::white(),MWAWColor::white(),MWAWColor::black(),MWAWColor::black()};
1924 int patterns[2]= {0,0};
1925 for (size_t i=0; i<N; ++i) {
1926 pos=input->tell();
1927 f.str("");
1928 f << "Frames-" << i << ":";
1929 auto &frame=content.m_frameList[i];
1930 MWAWGraphicStyle &style=frame.m_style;
1931 if (vers<=3) {
1932 auto type=int(input->readULong(1));
1933 if (!isMacFile) type=PowerPoint3ParserInternal::swapUInt8(type);
1934 frame.m_type=(type>>4)&7;
1935 showTypes[0]=type&0x7;
1936 type&=0x88;
1937 if (type) f << "fl0=" << std::hex << type << std::dec << ",";
1938 auto type2=int(input->readULong(1));
1939 if (!isMacFile) type2=PowerPoint3ParserInternal::swapUInt8(type2);
1940 showTypes[2]=type2&3;
1941 showTypes[1]=(type2>>4)&3;
1942 type2&=0xCC;
1943 if (type2) f << "fl1=" << std::hex << type2 << std::dec << ",";
1944 }
1945 else {
1946 auto type=int(input->readULong(2));
1947 int dashId=0;
1948 if (isMacFile) {
1949 frame.m_type=(type>>13)&7;
1950 showTypes[0]=(type>>10)&0x7;
1951 dashId=(type>>6)&7;
1952 showTypes[2]=(type>>4)&3;
1953 type &= 0x20F;
1954 }
1955 else {
1956 frame.m_type=(type&7);
1957 showTypes[0]=(type>>3)&0x7;
1958 dashId=(type>>6)&7;
1959 showTypes[2]=(type>>10)&3;
1960 type&=0xF200;
1961 }
1962 showTypes[1]=1;
1963 switch (dashId) {
1964 case 0: // none
1965 case 1: // normal
1966 case 2: // unsure
1967 showTypes[1]=dashId;
1968 break;
1969 case 3:
1970 style.m_lineDashWidth.resize(2,1);
1971 f << "dot,";
1972 break;
1973 case 4:
1974 style.m_lineDashWidth.resize(2,2);
1975 f << "dot[2x2],";
1976 break;
1977 case 5:
1978 style.m_lineDashWidth.resize(2,4);
1979 f << "dot[4x2],";
1980 break;
1981 case 6:
1982 style.m_lineDashWidth.resize(4,2);
1983 style.m_lineDashWidth[2]=1;
1984 f << "dot[4,4,1,4],";
1985 break;
1986 default:
1987 f << "##dashId=" << dashId << ",";
1988 }
1989 if (type) f << "fl0=" << std::hex << type << std::dec << ",";
1990 }
1991 switch (frame.m_type) {
1992 case 0:
1993 f << "line,";
1994 break;
1995 case 0x1: // link to data?
1996 f << "gen,";
1997 break;
1998 case 0x2:
1999 frame.m_polygonId=poly++;
2000 f << "poly,";
2001 break;
2002 case 0x3:
2003 f << "arc,";
2004 break;
2005 case 0x4:
2006 f << "group,";
2007 break;
2008 default:
2009 f << "type=" << frame.m_type << ",";
2010 break;
2011 }
2012 switch (showTypes[0]) {
2013 case 0: // none
2014 break;
2015 case 1:
2016 f << "filled,";
2017 break;
2018 case 2:
2019 f << "opaque,";
2020 break;
2021 case 3:
2022 f << "pattern,";
2023 break;
2024 case 4:
2025 f << "gradient,";
2026 break;
2027 default:
2028 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find unknown surface style\n"));
2029 f << "###surf[type]=" << showTypes[0] << ",";
2030 break;
2031 }
2032 switch (showTypes[1]) {
2033 case 0:
2034 f << "no[line],";
2035 break;
2036 case 2:
2037 f << "line[pattern],";
2038 break;
2039 case 3:
2040 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find unknown line style\n"));
2041 f << "##line[type2]=3,";
2042 break;
2043 default:
2044 break;
2045 }
2046 if (showTypes[2]&1) f << "shadow,";
2047 if (showTypes[2]&2) f << "emboss,";
2048 bool hasPicture=false;
2049 auto val=int(input->readULong(1));
2050 if (!isMacFile) val=PowerPoint3ParserInternal::swapBool8(val);
2051 if (val&1)
2052 f << "basic,";
2053 if (val&2)
2054 f << "wrap[text],";
2055 if (val&4)
2056 f << "adjust[textbox],";
2057 if (val&0x8) {
2058 style.m_arrows[1]=MWAWGraphicStyle::Arrow::plain();
2059 f << "arrow[start],";
2060 }
2061 if (val&0x10) {
2062 style.m_arrows[0]=MWAWGraphicStyle::Arrow::plain();
2063 f << "arrow[end],";
2064 }
2065 PowerPoint3ParserInternal::SlideFormat *sFormat=nullptr;
2066 if (val&0x20) {
2067 f << "has[format],";
2068 if (format<0||format>=int(content.m_formatList.size())) {
2069 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: can not find the slide format's\n"));
2070 f << "###,";
2071 }
2072 else {
2073 sFormat=&content.m_formatList[size_t(format)];
2074 frame.m_formatId=format++;
2075 }
2076 }
2077 if (val&0x40) {
2078 f << "has[pict],";
2079 hasPicture=true;
2080 }
2081 if (val&0x80) {
2082 f << "has[text],";
2083 int mainId=-1;
2084 for (int j=0; j<2; ++j) {
2085 if (int(i)!=content.m_mainZoneIds[j]) continue;
2086 mainId = (j==1 && content.m_mainZoneIds[0]==-1) ? 0 : j;
2087 }
2088 if (mainId!=-1) {
2089 frame.m_textId=mainId;
2090 frame.m_mainTextBox=true;
2091 ++content.m_numMainZones;
2092 }
2093 else
2094 frame.m_textId=text++;
2095 }
2096 val=int(input->readULong(1));
2097 if (isMacFile) val=PowerPoint3ParserInternal::swapUInt4Bool4(val);
2098 switch ((val>>2)&3) {
2099 case 0: // top
2100 break;
2101 case 1:
2102 f << "center[h],";
2103 break;
2104 case 2:
2105 f << "bottom[h],";
2106 break;
2107 default:
2108 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: unknown vertical\n"));
2109 f << "##vert=3,";
2110 }
2111 if (!(val&0x2)) f << "centered,";
2112 val &=0xF1;
2113 if (val) f << "fl3=" << std::hex << val << std::dec << ",";
2114 int dim[4];
2115 for (auto &d : dim) d=int(input->readLong(2));
2116 if (!isMacFile) {
2117 std::swap(dim[0],dim[1]);
2118 std::swap(dim[2],dim[3]);
2119 }
2120 frame.m_dimension=MWAWBox2i(MWAWVec2i(dim[1],dim[0]), MWAWVec2i(dim[3],dim[2]));
2121 f << "dim=" << frame.m_dimension << ",";
2122 int lineType=1;
2123 for (int w=0; w<2; ++w) {
2124 f << (w==0 ? "surf" : "line") << "=[";
2125 if (w==1) {
2126 val=int(input->readULong(1));
2127 if (val>=0 && val<=10) {
2128 if (val!=1) {
2129 char const *wh[]= {"none", "w=1", "w=2","w=4", "w=8", "w=16", "w=32",
2130 "double", "double1x2", "double2x1", "triple1x2x1"
2131 };
2132 f << wh[val] << ",";
2133 }
2134 lineType=val;
2135 }
2136 else {
2137 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find unexpected line type\n"));
2138 f << "##line=" << val << ",";
2139 }
2140 }
2141 patterns[w]=int(input->readULong(1));
2142 if (patterns[w]) f << "pat=" << patterns[w] << ",";
2143 for (int j=0; j<2; ++j) {
2144 val=int(input->readULong(1));
2145 int cId=2*w+j;
2146 if (getColor(val, content.m_schemeId, colors[cId])) {
2147 if (((cId%3)!=0 && !colors[cId].isBlack()) || ((cId%3)==0 && !colors[cId].isWhite()))
2148 f << colors[cId] << ",";
2149 else
2150 f << "_,";
2151 }
2152 else
2153 f << "###col=" << val << ",";
2154 }
2155 f << "],";
2156 }
2157
2158 if (lineType && showTypes[1]) {
2159 MWAWColor color=colors[2];
2160 if (showTypes[1]==2) {
2161 MWAWGraphicStyle::Pattern pattern;
2162 if (m_state->getPattern(patterns[1], pattern)) {
2163 pattern.m_colors[0]=colors[2];
2164 pattern.m_colors[1]=colors[3];
2165 pattern.getAverageColor(color);
2166 }
2167 }
2168 float const lWidth[]= {0, 1, 2, 3, 6, 12, 16, 3, 4, 4, 6};
2169 style.m_lineWidth=lWidth[lineType];
2170 style.m_lineColor=color;
2171 MWAWBorder border;
2172 border.m_width=double(lWidth[lineType]);
2173 border.m_color=color;
2174 switch (lineType) {
2175 case 7:
2176 border.m_type=MWAWBorder::Double;
2177 break;
2178 case 8:
2179 border.m_type=MWAWBorder::Double;
2180 border.m_widthsList.push_back(1);
2181 border.m_widthsList.push_back(0);
2182 border.m_widthsList.push_back(2);
2183 break;
2184 case 9:
2185 border.m_type=MWAWBorder::Double;
2186 border.m_widthsList.push_back(2);
2187 border.m_widthsList.push_back(0);
2188 border.m_widthsList.push_back(1);
2189 break;
2190 case 10:
2191 border.m_type=MWAWBorder::Triple;
2192 border.m_widthsList.push_back(1);
2193 border.m_widthsList.push_back(0);
2194 border.m_widthsList.push_back(2);
2195 border.m_widthsList.push_back(0);
2196 border.m_widthsList.push_back(1);
2197 break;
2198 default:
2199 break;
2200 }
2201 style.setBorders(0xF, border);
2202 }
2203 else
2204 style.m_lineWidth=0;
2205 if (showTypes[0]==4) {
2206 int gradId=(patterns[0]>>4);
2207 int subId=(patterns[0]&0xF);
2208 MWAWColor auxColor(0,0,0);
2209 if (sFormat) {
2210 if (sFormat->m_gradientOffset<0)
2211 auxColor=MWAWColor::barycenter(float(-sFormat->m_gradientOffset)/10.f,MWAWColor::black(), float(10+sFormat->m_gradientOffset)/10.f, colors[0]);
2212 else if (sFormat->m_gradientOffset>0)
2213 auxColor=MWAWColor::barycenter(float(sFormat->m_gradientOffset)/10.f,MWAWColor::white(), float(10-sFormat->m_gradientOffset)/10.f, colors[0]);
2214 else
2215 auxColor=colors[0];
2216 }
2217 auto &finalGrad=style.m_gradient;
2218 finalGrad.m_stopList.resize(0);
2219 if (gradId>=1 && gradId<=4) {
2220 if (subId<2) {
2221 finalGrad.m_type=MWAWGraphicStyle::Gradient::G_Linear;
2222 for (int c=0; c < 2; ++c)
2223 finalGrad.m_stopList.push_back(MWAWGraphicStyle::Gradient::Stop(float(c), (c==subId) ? colors[0] : auxColor));
2224 }
2225 else {
2226 finalGrad.m_type=MWAWGraphicStyle::Gradient::G_Axial;
2227 for (int c=0; c < 3; ++c)
2228 finalGrad.m_stopList.push_back(MWAWGraphicStyle::Gradient::Stop(float(c)/2.f, ((c%2)==(subId%2)) ? colors[0] : auxColor));
2229 }
2230 float const angles[]= {0,90,45,315};
2231 finalGrad.m_angle=angles[gradId-1];
2232 }
2233 else if (gradId==5) {
2234 finalGrad.m_type=MWAWGraphicStyle::Gradient::G_Rectangular;
2235 for (int c=0; c < 2; ++c)
2236 finalGrad.m_stopList.push_back(MWAWGraphicStyle::Gradient::Stop(float(c), c==0 ? colors[0] : auxColor));
2237 finalGrad.m_percentCenter=MWAWVec2f(float(subId&1),float(subId<2 ? 0 : 1));
2238 }
2239 else if (gradId==7) {
2240 finalGrad.m_type=MWAWGraphicStyle::Gradient::G_Rectangular;
2241 for (int c=0; c < 2; ++c)
2242 finalGrad.m_stopList.push_back(MWAWGraphicStyle::Gradient::Stop(float(c), ((c%2)==(subId%2)) ? colors[0] : auxColor));
2243 }
2244 else {
2245 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find unknown gradient\n"));
2246 style.setSurfaceColor(colors[0]);
2247 }
2248 }
2249 else if (showTypes[0]==3) {
2250 MWAWGraphicStyle::Pattern pattern;
2251 if (m_state->getPattern(patterns[0], pattern)) {
2252 pattern.m_colors[0]=colors[1];
2253 pattern.m_colors[1]=colors[0];
2254 MWAWColor color;
2255 if (pattern.getUniqueColor(color))
2256 style.setSurfaceColor(color);
2257 else
2258 style.setPattern(pattern);
2259 }
2260 }
2261 else if (showTypes[0]==1)
2262 style.setSurfaceColor(colors[0]);
2263 else if (showTypes[0]==2) {
2264 MWAWColor bgColor;
2265 if (getColor(0, content.m_schemeId, bgColor))
2266 style.setSurfaceColor(bgColor);
2267 }
2268 f << "shadow=[";
2269 val=int(input->readULong(1));
2270 if (getColor(val, content.m_schemeId, colors[4])) {
2271 if (!colors[4].isBlack())
2272 f << colors[4] << ",";
2273 }
2274 else
2275 f << "###col=" << val << ":S" << content.m_schemeId << ",";
2276 val=int(input->readULong(4)); // some big number probably an id
2277 if (val) f << std::hex << val << std::dec << ",";
2278 f << "],";
2279 if (showTypes[2]) {
2280 style.setShadowColor(colors[4]);
2281 style.m_shadowOffset=MWAWVec2f(6,6);
2282 }
2283 switch (frame.m_type) {
2284 case 1:
2285 val=int(input->readLong(2));
2286 if (val<0) {
2287 frame.m_shapeId=-val;
2288 if (frame.m_shapeId<=3) {
2289 char const *wh[]= {"oval", "rect[oval]", "rect"};
2290 f << wh[frame.m_shapeId-1] << ",";
2291 }
2292 else {
2293 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find unexpected type\n"));
2294 f << "###type=" << frame.m_shapeId << ",";
2295 }
2296 }
2297 else {
2298 frame.m_customShapeId=(val&0xFF);
2299 frame.m_customTransformation=(val>>12);
2300 f << "custom=" << frame.m_customShapeId << ",";
2301 if (frame.m_customTransformation&1) f << "rot90,";
2302 if (frame.m_customTransformation&2) f << "rot180,";
2303 if (frame.m_customTransformation&4) f << "flipX,";
2304 val=((val&0x8f00)>>8);
2305 if (val) {
2306 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find unexpected transformation\n"));
2307 f << "##trans=" << std::hex << val << std::dec << "]";
2308 }
2309 f << ",";
2310 }
2311 val=int(input->readLong(2));
2312 if (val) f << "f0=" << val << ",";
2313 if (hasPicture) {
2314 frame.m_pictureId=int(input->readULong(2));
2315 f << "pict[id]=" << frame.m_pictureId << ",";
2316 }
2317 break;
2318 case 3:
2319 for (auto &angle : frame.m_angles) angle=float(input->readLong(2))/16.f;
2320 f << "angles=" << frame.m_angles[0] << "<->" << frame.m_angles[0]+frame.m_angles[1] << ",";
2321 for (int j=0; j<4; ++j) { // f0=0|1
2322 val=int(input->readLong(1));
2323 if (val) f << "f" << j << "=" << val << ",";
2324 }
2325 break;
2326 case 4:
2327 for (auto &id : frame.m_groupChild) id=int(input->readULong(4));
2328 f << "child=" << frame.m_groupChild[0] << "<->" << frame.m_groupChild[1] << ",";
2329 if (frame.m_groupChild[0]<0 || frame.m_groupChild[1]>=int(N) || frame.m_groupChild[0]>frame.m_groupChild[1]) {
2330 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFramesList: find bad group child\n"));
2331 f << "###";
2332 frame.m_groupChild[0]=frame.m_groupChild[1]=-1;
2333 }
2334 break;
2335 // line, poly, probably no other data or flag
2336 default:
2337 break;
2338 }
2339 if (input->tell()!=pos+32)
2340 ascii().addDelimiter(input->tell(),'|');
2341 input->seek(pos+32, librevenge::RVNG_SEEK_SET);
2342 ascii().addPos(pos);
2343 ascii().addNote(f.str().c_str());
2344 }
2345 ascii().addPos(entry.end());
2346 ascii().addNote("_");
2347 return true;
2348 }
2349
2350 bool PowerPoint3Parser::readTextZone(MWAWEntry const &entry, PowerPoint3ParserInternal::SlideContent &content)
2351 {
2352 if (!entry.valid() || entry.end()<14) {
2353 MWAW_DEBUG_MSG(("PowerPoint3Parser::readTextZone: the zone seems bad\n"));
2354 return false;
2355 }
2356 MWAWInputStreamPtr input = getInput();
2357 long pos = entry.begin();
2358 long const endPos = entry.end();
2359 entry.setParsed(true);
2360 input->seek(pos, librevenge::RVNG_SEEK_SET);
2361 libmwaw::DebugStream f;
2362 f << "Entries(TextZone)[Z"<< entry.id() << "]:";
2363 bool const isMacFile=m_state->m_isMacFile;
2364 int val;
2365 for (int i=0; i<2; ++i) {
2366 val=int(input->readULong(4));
2367 if (val) f << "f" << i << "=" << val << ",";
2368 }
2369 for (int i=0; i<2; ++i) {
2370 val=int(input->readULong(1));
2371 if (!val) continue;
2372 if (!isMacFile) val=PowerPoint3ParserInternal::swapBool8(val);
2373 f << "fl" << i << "=" << std::hex << val << std::dec <<",";
2374 }
2375 val=int(input->readULong(4));
2376 if (val) f << "f2=" << val << ",";
2377 ascii().addPos(pos);
2378 ascii().addNote(f.str().c_str());
2379 ascii().addPos(endPos);
2380 ascii().addNote("_");
2381 int const schemeId=content.m_schemeId;
2382 while (input->tell()+58<endPos) {
2383 PowerPoint3ParserInternal::TextZone tZone;
2384 pos=input->tell();
2385 f.str("");
2386 f << "TextZone-A:";
2387 tZone.m_rulerId=int(input->readLong(2));
2388 if (tZone.m_rulerId) f << "ruler=" << tZone.m_rulerId << ",";
2389 for (int i=0; i<2; ++i) { // fl0 small number
2390 val=int(input->readULong(1));
2391 if (!val) continue;
2392 if (isMacFile) val=PowerPoint3ParserInternal::swapBool4UInt4(val);
2393 if (i==0) {
2394 switch ((val>>6)&3) {
2395 case 0: // top
2396 break;
2397 case 1:
2398 f << "center[h],";
2399 break;
2400 case 2:
2401 f << "bottom[h],";
2402 break;
2403 default:
2404 MWAW_DEBUG_MSG(("PowerPoint3Parser::readTextZone: unknown vertical\n"));
2405 f << "##vert=3,";
2406 }
2407 if (!(val&0x20)) {
2408 tZone.m_centered=true;
2409 f << "centered,";
2410 }
2411 if (val&0x2) {
2412 tZone.m_wrapText=true;
2413 f << "wrap[text],";
2414 }
2415 if (val&0x1) {
2416 tZone.m_adjustSize=true;
2417 f << "adjust[textbox],";
2418 }
2419 if (val&0x8)
2420 f << "basic,";
2421 val&=0x14;
2422 }
2423 if (val)
2424 f << "fl" << i << "=" << std::hex << val << std::dec << ",";
2425 }
2426 for (int i=0; i<2; ++i) { // f1 small number
2427 val=int(input->readLong(2));
2428 if (val) f << "f" << i+1 << "=" << val << ",";
2429 }
2430 int dim[4];
2431 for (int &d : dim) d=int(input->readLong(2));
2432 if (!isMacFile) {
2433 std::swap(dim[0],dim[1]);
2434 std::swap(dim[2],dim[3]);
2435 }
2436 tZone.m_box=MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2]));
2437 f << "dim=" << tZone.m_box << ",";
2438 MWAWFont font;
2439 if (readFont(font, schemeId))
2440 f << "font=[" << font.getDebugString(getFontConverter()) << "],";
2441 else {
2442 f << "###font,";
2443 input->seek(pos+16+12, librevenge::RVNG_SEEK_SET);
2444 }
2445 MWAWParagraph para;
2446 PowerPoint3ParserInternal::Ruler ruler;
2447 if (readParagraph(para, ruler, schemeId))
2448 f << "ruler=[" << para << "],";
2449 else {
2450 f << "###para,";
2451 input->seek(pos+16+12+24, librevenge::RVNG_SEEK_SET);
2452 }
2453 val=int(input->readLong(2));
2454 if (val) f << "f3=" << val << ",";
2455 auto sSz=int(input->readULong(4));
2456 if (sSz<0 || endPos-pos-58-8-10<sSz || pos+58+sSz+8+10>endPos) {
2457 input->seek(pos, librevenge::RVNG_SEEK_SET);
2458 break;
2459 }
2460 ascii().addPos(pos);
2461 ascii().addNote(f.str().c_str());
2462
2463 tZone.m_text.setBegin(input->tell());
2464 tZone.m_text.setLength(sSz);
2465 if (sSz) {
2466 pos=input->tell();
2467 f.str("");
2468 f << "TextZone-text:";
2469 std::string text;
2470 for (int c=0; c<sSz; ++c) text+=char(input->readULong(1));
2471 f << text;
2472 if (sSz&1)
2473 input->seek(1, librevenge::RVNG_SEEK_CUR);
2474 ascii().addPos(pos);
2475 ascii().addNote(f.str().c_str());
2476 }
2477
2478 pos=input->tell();
2479 f.str("");
2480 f << "TextZone:font,";
2481 val=int(input->readLong(2));
2482 if (val!=0xc) f << "f0=" << val << ",";
2483 val=int(input->readULong(4));
2484 if (val!=sSz) f << "#N=" << val << ",";
2485 auto fSz=int(input->readULong(2));
2486 if (fSz!=16) {
2487 MWAW_DEBUG_MSG(("PowerPoint3Parser::readTextZone: field size seems bad\n"));
2488 f << "#fSz=" << fSz << ",";
2489 }
2490 auto N=int(input->readULong(4));
2491 f << "N=" << N << ",";
2492 if (fSz<4 || N<0 || (endPos-pos)/fSz<N || pos+12+fSz*N+8>endPos) {
2493 input->seek(pos, librevenge::RVNG_SEEK_SET);
2494 break;
2495 }
2496 ascii().addPos(pos);
2497 ascii().addNote(f.str().c_str());
2498 if (fSz==16) {
2499 tZone.m_fonts.setBegin(input->tell());
2500 tZone.m_fonts.setLength(N*fSz);
2501 input->seek(tZone.m_fonts.end(), librevenge::RVNG_SEEK_SET);
2502 }
2503 else {
2504 for (int i=0; i<N; ++i) {
2505 pos=input->tell();
2506 f.str("");
2507 f << "TextZone-F" << i << ":";
2508 ascii().addPos(pos);
2509 ascii().addNote(f.str().c_str());
2510 input->seek(pos+fSz, librevenge::RVNG_SEEK_SET);
2511 }
2512 }
2513
2514 pos=input->tell();
2515 f.str("");
2516 f << "TextZone-R:";
2517 val=int(input->readLong(2));
2518 if (val!=0x18) f << "f0=" << val << ",";
2519 val=int(input->readULong(4));
2520 if (val!=sSz) f << "#N=" << val << ",";
2521 fSz=int(input->readULong(2));
2522 if (fSz!=28) {
2523 MWAW_DEBUG_MSG(("PowerPoint3Parser::readTextZone: field size seems bad\n"));
2524 f << "#fSz=" << fSz << ",";
2525 }
2526 N=int(input->readULong(4));
2527 f << "N=" << N << ",";
2528 if (fSz<4 || N<0 || (endPos-pos)/fSz<N || pos+12+fSz*N>endPos) {
2529 input->seek(pos, librevenge::RVNG_SEEK_SET);
2530 break;
2531 }
2532 ascii().addPos(pos);
2533 ascii().addNote(f.str().c_str());
2534 if (fSz==28) {
2535 tZone.m_rulers.setBegin(input->tell());
2536 tZone.m_rulers.setLength(N*fSz);
2537 input->seek(tZone.m_rulers.end(), librevenge::RVNG_SEEK_SET);
2538 }
2539 else {
2540 long cPos=0;
2541 for (int i=0; i<N; ++i) {
2542 pos=input->tell();
2543 f.str("");
2544 auto cLen=int(input->readULong(4));
2545 f << "TextZone-R" << i << "[" << cPos << "->" << cPos+cLen << "]:";
2546 cPos+=cLen;
2547 if (cPos>sSz) {
2548 MWAW_DEBUG_MSG(("PowerPoint3Parser::readTextZone: the cLen seems bad\n"));
2549 f << "###";
2550 }
2551 if (input->tell()!=pos+fSz)
2552 ascii().addDelimiter(input->tell(),'|');
2553 input->seek(pos+fSz, librevenge::RVNG_SEEK_SET);
2554 ascii().addPos(pos);
2555 ascii().addNote(f.str().c_str());
2556 }
2557 }
2558 content.m_textZone.push_back(tZone);
2559 }
2560 if (input->tell()!=endPos) {
2561 MWAW_DEBUG_MSG(("PowerPoint3Parser::readTextZone: find extra data\n"));
2562 ascii().addPos(input->tell());
2563 ascii().addNote("TextZone:###extra");
2564 }
2565 return true;
2566 }
2567
2568 bool PowerPoint3Parser::readStructList(MWAWEntry const &entry, PowerPoint3ParserInternal::FieldParser &parser)
2569 {
2570 bool useInt16 = (!m_state->m_isMacFile && version()<=3);
2571 int const headerSize= useInt16 ? 16 : 18;
2572 if (!entry.valid() || entry.length()<headerSize) {
2573 MWAW_DEBUG_MSG(("PowerPoint3Parser::readStructList: the zone seems bad\n"));
2574 return false;
2575 }
2576 MWAWInputStreamPtr input = getInput();
2577 long pos = entry.begin();
2578 entry.setParsed(true);
2579 input->seek(pos, librevenge::RVNG_SEEK_SET);
2580 libmwaw::DebugStream f;
2581 f << "Entries(" << parser.m_name << ")[Z"<< entry.id() << "]:list,";
2582 auto val=int(input->readULong(2));
2583 if (val!=0x8001)
2584 f << "f0=" << std::hex << val << std::dec << ",";
2585 f << "id=" << std::hex << input->readULong(useInt16 ? 2 : 4) << std::dec << ",";
2586 auto N=int(input->readULong(2));
2587 f << "N=" << N << ",";
2588 for (int i=0; i<2; ++i) {
2589 val=int(input->readULong(2));
2590 int const expected[]= {0x7fff, 0};
2591 if (val!=expected[i])
2592 f << "f" << i+1 << "=" << val << ",";
2593 }
2594 auto const fieldSize=int(input->readULong(2));
2595 if (N>(entry.length()-headerSize)/(2+fieldSize)) {
2596 MWAW_DEBUG_MSG(("PowerPoint3Parser::readStructList: the N value seems bad\n"));
2597 f << "###";
2598 N=int((entry.length()-headerSize)/(2+fieldSize));
2599 }
2600 f << "id2=" << std::hex << input->readULong(4) << std::dec << ",";
2601 ascii().addPos(pos);
2602 ascii().addNote(f.str().c_str());
2603 std::vector<int> listChild;
2604 listChild.resize(size_t(N), -1);
2605 for (int i=0; i<N; ++i) {
2606 pos=input->tell();
2607 f.str("");
2608 val=int(input->readLong(2));
2609 if (val && fieldSize==parser.m_fieldSize && parser.parse(i, input, ascii())) {
2610 input->seek(pos+2+fieldSize, librevenge::RVNG_SEEK_SET);
2611 continue;
2612 }
2613 else if (val) {
2614 f << parser.m_name << "-" << val << ":";
2615 ascii().addDelimiter(input->tell(),'|');
2616 }
2617 else
2618 f << "_,";
2619 input->seek(pos+2+fieldSize, librevenge::RVNG_SEEK_SET);
2620 ascii().addPos(pos);
2621 ascii().addNote(f.str().c_str());
2622 }
2623 if (input->tell()!=entry.end()) {
2624 f.str("");
2625 f << parser.m_name << ":##extra";
2626 ascii().addPos(input->tell());
2627 ascii().addNote(f.str().c_str());
2628 }
2629 ascii().addPos(entry.end());
2630 ascii().addNote("_");
2631 return true;
2632 }
2633
2634 bool PowerPoint3Parser::readPicturesList(std::map<int,int> const &pIdtoZIdMap)
2635 {
2636 for (auto const &it : pIdtoZIdMap) {
2637 MWAWEntry const &cEntry=m_state->getZoneEntry(it.second);
2638 if (!cEntry.valid() || cEntry.isParsed()) continue;
2639 readPictureDefinition(cEntry, it.first);
2640 }
2641 return true;
2642 }
2643
2644 bool PowerPoint3Parser::readPictureDefinition(MWAWEntry const &entry, int pId)
2645 {
2646 if (!entry.valid() || entry.length()<24) {
2647 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureDefinition: the zone seems bad\n"));
2648 return false;
2649 }
2650 MWAWInputStreamPtr input = getInput();
2651 long pos = entry.begin();
2652 entry.setParsed(true);
2653 ascii().addPos(entry.end());
2654 ascii().addNote("_");
2655 input->seek(pos, librevenge::RVNG_SEEK_SET);
2656 libmwaw::DebugStream f;
2657 f << "Entries(Picture)[Z"<< entry.id() << "-" << pId << "]:def,";
2658 auto val=int(input->readULong(2)); // 0|4|90|b4|fc|120|144
2659 if (val) f << "fl=" << std::hex << val << std::dec << ",";
2660 auto id=int(input->readULong(2));
2661 if (id)
2662 f << "id=" << std::hex << id << std::dec << ",";
2663 f << "ole,";
2664 val=int(input->readULong(2));
2665 if (val)
2666 f << "id2=" << std::hex << val << std::dec << ",";
2667 val=int(input->readULong(4));
2668 if (val)
2669 f << "id3=" << std::hex << val << std::dec << ",";
2670 val=int(input->readLong(2)); // small number
2671 if (val) f << "f0=" << val << ",";
2672 val=int(input->readULong(4));
2673 if (val)
2674 f << "id4=" << std::hex << val << std::dec << ",";
2675 for (int i=0; i<2; ++i) { // 0
2676 val=int(input->readLong(2));
2677 if (val) f << "f" << i+1 << "=" << val << ",";
2678 }
2679 auto numZones=int(m_state->m_zonesList.size());
2680 int childs[2]= {-1,-1};
2681 for (int i=0; i<2; ++i) {
2682 val=int(input->readULong(4));
2683 if (val>=0 && val<numZones) {
2684 f << "child" << i << "[id]=Z" << val << ",";
2685 childs[i]=val;
2686 }
2687 else {
2688 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureDefinition: find some bad child\n"));
2689 f << "child" << i << "[id]=##Z" << val << ",";
2690 }
2691 if (entry.length()==24) break;
2692 }
2693 if (entry.length()==122) {
2694 ascii().addPos(pos);
2695 ascii().addNote(f.str().c_str());
2696 pos=input->tell();
2697 f.str("");
2698 f << "PictureA:ole,";
2699 for (int i=0; i<2; ++i) { // f0=8(windows)|10(mac)
2700 val=int(input->readULong(1));
2701 if (val) f << "fl=" << std::hex << val << std::dec << ",";
2702 }
2703 for (int i=0; i<2; ++i) { // mine, program
2704 long actPos=input->tell();
2705 int sSz=32;
2706 if (m_state->m_isMacFile) { // Mac : pascal, Windows : C string
2707 sSz=int(input->readULong(1));
2708 if (sSz>31) {
2709 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureDefinition: the string size seems bad\n"));
2710 f << "##sSz=" << sSz << ",";
2711 sSz=31;
2712 }
2713 }
2714 std::string name;
2715 for (int c=0; c<sSz; ++c) {
2716 auto ch=char(input->readULong(1));
2717 if (ch==0) break;
2718 name+=ch;
2719 }
2720 f << "str" << i << "=" << name << ",";
2721 input->seek(actPos+32, librevenge::RVNG_SEEK_SET);
2722 }
2723 ascii().addDelimiter(input->tell(),'|');
2724 }
2725 ascii().addPos(pos);
2726 ascii().addNote(f.str().c_str());
2727 for (int i=0; i<2; ++i) {
2728 MWAWEntry const &cEntry=m_state->getZoneEntry(childs[i]);
2729 if (!cEntry.valid() || cEntry.isParsed()) continue;
2730 if (i==0) {
2731 MWAWEmbeddedObject data;
2732 readPictureContent(cEntry, data);
2733 if (!data.isEmpty())
2734 m_state->m_idToPictureContentMap.insert(std::map<int, MWAWEmbeddedObject>::value_type(entry.id(),data));
2735 }
2736 else {
2737 cEntry.setParsed(true);
2738 f.str("");
2739 f << "Entries(PictData)[Z" << cEntry.id() << "-B]:";
2740 ascii().addPos(cEntry.begin());
2741 ascii().addNote(f.str().c_str());
2742 ascii().addPos(cEntry.end());
2743 ascii().addNote("_");
2744 }
2745 }
2746 return true;
2747 }
2748
2749 bool PowerPoint3Parser::readPictureContent(MWAWEntry const &entry, MWAWEmbeddedObject &pict)
2750 {
2751 bool isMacFile=m_state->m_isMacFile;
2752 int const vers=version();
2753 if (!entry.valid() || entry.length()!=(vers>=4 ? 60 : isMacFile ? 50 : 48)) {
2754 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureContent: the zone seems bad\n"));
2755 return false;
2756 }
2757 MWAWInputStreamPtr input = getInput();
2758 long pos = entry.begin();
2759 entry.setParsed(true);
2760 input->seek(pos, librevenge::RVNG_SEEK_SET);
2761 libmwaw::DebugStream f;
2762 f << "Entries(PictData)[Z"<< entry.id() << "-A]:def,";
2763 auto numZones=int(m_state->m_zonesList.size());
2764 auto val=int(input->readLong(2)); // mac: 5, windows: 0
2765 if (val) f << "f0=" << val << ",";
2766 int childs[2]= {-1,-1};
2767 if (isMacFile) {
2768 std::string rsrcName;
2769 for (int i=0; i<4; ++i) rsrcName+=char(input->readULong(1));
2770 f << rsrcName << ",";
2771 f << "id=" << std::hex << input->readULong(4) << std::dec << ",";
2772 for (int i=0; i<2; ++i) {
2773 val=int(input->readLong(4));
2774 if (val==-1) continue;
2775 if (val>=0 && val<numZones) {
2776 f << "child" << i << "[id]=Z" << val << ",";
2777 childs[i]=val;
2778 }
2779 else {
2780 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureContent: find some bad child\n"));
2781 f << "child" << i << "[id]=##Z" << val << ",";
2782 }
2783 }
2784 }
2785 else {
2786 for (int i=0; i<2; ++i) { // f1=0-4
2787 val=int(input->readLong(2));
2788 if (val) f << "f" << i+1 << "=" << val << ",";
2789 }
2790 val=int(input->readULong(vers>=4 ? 4 : 2));
2791 if (val!=0x262a) f << "id=" << std::hex << val << std::dec << ",";
2792 int dim[4];
2793 for (auto &d : dim) d=int(input->readLong(2));
2794 f << "dim=" << MWAWBox2i(MWAWVec2i(dim[1],dim[0]),MWAWVec2i(dim[3],dim[2])) << ",";
2795 for (int i=0; i<2; ++i) {
2796 val=int(input->readLong(2));
2797 if (val==-1) continue;
2798 if (val>=0 && val<numZones) {
2799 f << "child" << i << "[id]=Z" << val << ",";
2800 childs[i]=val;
2801 }
2802 else {
2803 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureContent: find some bad child\n"));
2804 f << "child" << i << "[id]=##Z" << val << ",";
2805 }
2806 }
2807 }
2808 for (int i=0; i<(isMacFile ? 16 : 14); ++i) { // 0
2809 val=int(input->readLong(2));
2810 if (val) f << "g" << i << "=" << val << ",";
2811 }
2812 ascii().addPos(pos);
2813 ascii().addNote(f.str().c_str());
2814 ascii().addPos(entry.end());
2815 ascii().addNote("_");
2816 for (int i=0; i<2; ++i) { // first is the picture, second maybe a bitmap
2817 MWAWEntry const &cEntry=m_state->getZoneEntry(childs[i]);
2818 if (!cEntry.valid() || cEntry.isParsed()) continue;
2819 cEntry.setParsed(true);
2820 if (i==0) {
2821 input->seek(cEntry.begin(), librevenge::RVNG_SEEK_SET);
2822 ascii().skipZone(pos, cEntry.end()-1);
2823 librevenge::RVNGBinaryData file;
2824 input->seek(cEntry.begin(), librevenge::RVNG_SEEK_SET);
2825 input->readDataBlock(cEntry.length(), file);
2826 pict.add(file);
2827 #ifdef DEBUG_WITH_FILES
2828 static int volatile pictName = 0;
2829 f.str("");
2830 f << "PICT-" << ++pictName << ".pct";
2831 libmwaw::Debug::dumpFile(file, f.str().c_str());
2832 #endif
2833 ascii().addPos(cEntry.end());
2834 ascii().addNote("_");
2835 continue;
2836 }
2837 f.str("");
2838 f << "Entries(PictData)[Z" << cEntry.id() << "-D]:";
2839 ascii().addPos(cEntry.begin());
2840 ascii().addNote(f.str().c_str());
2841 ascii().addPos(cEntry.end());
2842 ascii().addNote("_");
2843 }
2844 return true;
2845 }
2846
2847 bool PowerPoint3Parser::readFont(MWAWFont &font, int schemeId)
2848 {
2849 MWAWInputStreamPtr input = getInput();
2850 long pos = input->tell();
2851 if (!input->checkPosition(pos+12)) {
2852 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFont: the zone seems bad\n"));
2853 return false;
2854 }
2855 font=MWAWFont();
2856 libmwaw::DebugStream f;
2857 auto val=int(input->readLong(2));
2858 if (val>=0 && m_state->m_idToFontIdMap.find(val)!= m_state->m_idToFontIdMap.end())
2859 font.setId(m_state->m_idToFontIdMap.find(val)->second);
2860 else if (val>=0) {
2861 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFont: can not find the font id\n"));
2862 f << "##id=" << val << ",";
2863 }
2864 val=int(input->readLong(2));
2865 if (val>0) font.setSize(float(val));
2866 auto flag = int(input->readULong(2));
2867 uint32_t flags=0;
2868 if (flag&0x1) flags |= MWAWFont::boldBit;
2869 if (flag&0x2) flags |= MWAWFont::italicBit;
2870 if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple);
2871 if (flag&0x8) flags |= MWAWFont::embossBit;
2872 if (flag&0x10) flags |= MWAWFont::shadowBit;
2873 if (flag&0xFFE0) f << "##flag=" << std::hex << (flag>>5) << std::dec << ",";
2874 font.setFlags(flags);
2875 auto col=int(input->readLong(2));
2876 MWAWColor color;
2877 if (col>=0 && getColor(col, schemeId, color))
2878 font.setColor(color);
2879 else if (col>=0)
2880 f << "###col=" << col << ":S" << schemeId << ",";
2881 val=int(input->readLong(2));
2882 if (val) font.set(MWAWFont::Script(float(val),librevenge::RVNG_PERCENT,58));
2883 font.m_extra=f.str();
2884 ascii().addDelimiter(input->tell(),'|');
2885 input->seek(pos+12, librevenge::RVNG_SEEK_SET);
2886 return true;
2887 }
2888
2889 bool PowerPoint3Parser::readFontNamesList(std::map<int,int> const &pIdtoZIdMap)
2890 {
2891 for (auto const &it : pIdtoZIdMap) {
2892 MWAWEntry const &cEntry=m_state->getZoneEntry(it.second);
2893 if (!cEntry.valid() || cEntry.isParsed()) continue;
2894 readFontName(cEntry, it.first);
2895 }
2896 return true;
2897 }
2898
2899 bool PowerPoint3Parser::readFontName(MWAWEntry const &entry, int id)
2900 {
2901 if (!entry.valid() || entry.length()!=12) {
2902 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFontName: the zone seems bad\n"));
2903 return false;
2904 }
2905 MWAWInputStreamPtr input = getInput();
2906 long pos = entry.begin();
2907 entry.setParsed(true);
2908 input->seek(pos, librevenge::RVNG_SEEK_SET);
2909 libmwaw::DebugStream f;
2910 f << "FontName[Z"<< entry.id() << "-" << id << "]:def,";
2911 auto numZones=int(m_state->m_zonesList.size());
2912 auto val=int(input->readULong(4));
2913 int child=-1;
2914 if (val) {
2915 if (val>=0 && val<numZones) {
2916 f << "name[id]=Z" << val << ",";
2917 child=val;
2918 }
2919 else {
2920 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFontName: find some bad child\n"));
2921 f << "name[id]=##Z" << val << ",";
2922 }
2923 }
2924 for (int i=0; i<4; ++i) { // f3=0..255
2925 val=int(input->readULong(2));
2926 if (!val) continue;
2927 if (i==2) {
2928 if (val!=0xFFFF)
2929 f << "fId=" << val << ",";
2930 else
2931 f << "fId*,";
2932 }
2933 else
2934 f << "f" << i << "=" << val <<",";
2935 }
2936 ascii().addPos(pos);
2937 ascii().addNote(f.str().c_str());
2938 ascii().addPos(entry.end());
2939 ascii().addNote("_");
2940 MWAWEntry const &cEntry=m_state->getZoneEntry(child);
2941 if (cEntry.valid()) {
2942 cEntry.setParsed(true);
2943 input->seek(cEntry.begin(), librevenge::RVNG_SEEK_SET);
2944 pos=input->tell();
2945 f.str("");
2946 f << "FontName[Z" << child << "-" << id << "]:";
2947 auto sSz=int(input->readULong(1));
2948 if (sSz+1>cEntry.length()) {
2949 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFontName: the string size seems bad\n"));
2950 f << "###sSz=" << sSz << ",";
2951 }
2952 else {
2953 std::string name;
2954 for (int i=0; i<sSz; ++i) name+=char(input->readULong(1));
2955 f << name << ",";
2956 if (!name.empty())
2957 m_state->m_idToFontIdMap[id]=getFontConverter()->getId(name);
2958 }
2959 if (input->tell()!=cEntry.end())
2960 ascii().addDelimiter(input->tell(),'|');
2961 ascii().addPos(pos);
2962 ascii().addNote(f.str().c_str());
2963 ascii().addPos(cEntry.end());
2964 ascii().addNote("_");
2965 }
2966 else {
2967 MWAW_DEBUG_MSG(("PowerPoint3Parser::readFontName: can not find the font name\n"));
2968 }
2969 return true;
2970 }
2971
2972 bool PowerPoint3Parser::readParagraph(MWAWParagraph &para, PowerPoint3ParserInternal::Ruler const &ruler, int schemeId)
2973 {
2974 bool isMacFile=m_state->m_isMacFile;
2975 para=MWAWParagraph();
2976 MWAWInputStreamPtr input = getInput();
2977 long pos = input->tell();
2978 if (!input->checkPosition(pos+24)) {
2979 MWAW_DEBUG_MSG(("PowerPoint3Parser::readParagraph: the zone seems bad\n"));
2980 ruler.updateParagraph(para, 0);
2981 return false;
2982 }
2983 libmwaw::DebugStream f;
2984 f << "fl=[";
2985 bool hasBullet=false;
2986 int val;
2987 char bulletChar=0;
2988 MWAWFont bulletFont;
2989 if (!isMacFile) {
2990 if (m_state->m_monoTypeFontId<0)
2991 m_state->m_monoTypeFontId=getFontConverter()->getId("Monotype Sorts");
2992 bulletFont.setId(m_state->m_monoTypeFontId);
2993 }
2994
2995 for (int j=0; j<4; ++j) { // ?:swap?, 1|23|ff, 6e|95, 0
2996 val=int(input->readULong(1));
2997 switch (j) {
2998 case 1:
2999 if (hasBullet) {
3000 MWAWColor color;
3001 if (val!=255 && getColor(val, schemeId, color)) {
3002 bulletFont.setColor(color);
3003 if (!color.isBlack())
3004 f << "bullet[color]=" << color << ",";
3005 }
3006 else if (val!=255) {
3007 MWAW_DEBUG_MSG(("PowerPoint3Parser::readParagraph: can not read a color\n"));
3008 f << "bullet[color]=C" << val << ",";
3009 }
3010 }
3011 break;
3012 case 2:
3013 if (hasBullet && val!=255) {
3014 bulletChar=char(val);
3015 f << "bullet=" << bulletChar << ",";
3016 }
3017 break;
3018 case 0:
3019 if (!m_state->m_isMacFile) {
3020 if (val&1) {
3021 hasBullet=true;
3022 f << "bullet[has],";
3023 }
3024 val &= 0xfe;
3025 }
3026 else {
3027 if (val&0x40) {
3028 hasBullet=true;
3029 f << "bullet[has],";
3030 }
3031 val &= 0xbf;
3032 }
3033 MWAW_FALLTHROUGH;
3034 default:
3035 if (val)
3036 f << std::hex << val << std::dec << ",";
3037 else
3038 f << "_,";
3039 }
3040 }
3041 f << "],";
3042 f << "unkn=[";
3043 int level=0;
3044 for (int j=0; j<10; ++j) { // 0-6, 75|100, 0, 0, 1-4, 0-2, 40-160, 30-60, 0, 0-d
3045 val=int(input->readLong(2));
3046 switch (j) {
3047 case 0:
3048 if (hasBullet && val >=0) {
3049 if (m_state->m_idToFontIdMap.find(val)!= m_state->m_idToFontIdMap.end()) {
3050 bulletFont.setId(m_state->m_idToFontIdMap.find(val)->second);
3051 f << "bullet[font]=F" << val << ",";
3052 }
3053 else {
3054 MWAW_DEBUG_MSG(("PowerPoint3Parser::readParagraph: can not read a font\n"));
3055 f << "###bullet[font]=F" << val << ",";
3056 }
3057 }
3058 break;
3059 case 1:
3060 if (hasBullet) {
3061 if (val!=100)
3062 f << "bullet[size]=" << val << "%,";
3063 bulletFont.setSize(float(val)/100.f, true);
3064 }
3065 break;
3066 case 4:
3067 level=val&0xFF;
3068 ruler.updateParagraph(para, level);
3069 if (level) f << "level=" << level << ",";
3070 if (val&0xFF00) f << "level[high]=" << (val>>8) << ",";
3071 break;
3072 case 5:
3073 switch (val) {
3074 case 0: // left
3075 break;
3076 case 1:
3077 para.m_justify=MWAWParagraph::JustificationCenter;
3078 break;
3079 case 2:
3080 para.m_justify=MWAWParagraph::JustificationRight;
3081 break;
3082 case 3:
3083 para.m_justify=MWAWParagraph::JustificationFull;
3084 break;
3085 default:
3086 MWAW_DEBUG_MSG(("PowerPoint3Parser::readParagraph: find unknown justifcation\n"));
3087 f << "##justify=" << val << ",";
3088 }
3089 break;
3090 case 6:
3091 if (val<0)
3092 para.setInterline(-val, librevenge::RVNG_POINT);
3093 else if (val>0)
3094 para.setInterline(double(val)/100., librevenge::RVNG_PERCENT);
3095 break;
3096 case 7:
3097 case 8:
3098 if (val<0)
3099 para.m_spacings[j-6]=double(-val)/72.;
3100 else if (val>0)
3101 para.m_spacings[j-6]=double(val)/100.*24./72.; // percent assume font=24
3102 break;
3103 default:
3104 if (val)
3105 f << val << ",";
3106 else
3107 f << "_,";
3108 }
3109 }
3110 f << "],";
3111 if (hasBullet && bulletChar && getMainListener()) {
3112 para.m_listLevelIndex=level+1;
3113 para.m_listLevel=MWAWListLevel();
3114 para.m_listLevel->m_type=MWAWListLevel::BULLET;
3115 para.m_listLevel->m_spanId=getFontManager()->getId(bulletFont);
3116 int unicode=getFontConverter()->unicode(bulletFont.id(), static_cast<unsigned char>(bulletChar));
3117 libmwaw::appendUnicode(unicode==-1 ? 0x2022 : uint32_t(unicode), para.m_listLevel->m_bullet);
3118 }
3119 para.m_extra=f.str();
3120 input->seek(pos+24, librevenge::RVNG_SEEK_SET);
3121 return true;
3122 }
3123
3124 bool PowerPoint3Parser::readRuler(MWAWEntry const &entry, int pId)
3125 {
3126 if (!entry.valid() || entry.length()<26) {
3127 MWAW_DEBUG_MSG(("PowerPoint3Parser::readRuler: the zone seems bad\n"));
3128 return false;
3129 }
3130 PowerPoint3ParserInternal::Ruler ruler;
3131 MWAWInputStreamPtr input = getInput();
3132 long pos = entry.begin();
3133 entry.setParsed(true);
3134 ascii().addPos(entry.end());
3135 ascii().addNote("_");
3136 input->seek(pos, librevenge::RVNG_SEEK_SET);
3137 libmwaw::DebugStream f;
3138 f << "Entries(Ruler)[Z"<< entry.id() << "-R" << pId << "]:,";
3139 for (auto &margin : ruler.m_margins) margin=int(input->readLong(2));
3140 int val;
3141 for (int i=0; i<2; ++i) { // f0=1-3, f1=223,240, 242
3142 val=int(input->readLong(2));
3143 if (val) f << "f" << i << "=" << val << ",";
3144 }
3145 auto N=int(input->readULong(2));
3146 if (26+4*N>entry.length()) {
3147 MWAW_DEBUG_MSG(("PowerPoint3Parser::readRuler: the N value seems bad\n"));
3148 f << "###N=" << N << ",";
3149 N=0;
3150 }
3151 for (int i=0; i<N; ++i) {
3152 MWAWTabStop tab;
3153 tab.m_position=double(input->readLong(2))/8./72.;
3154 val=int(input->readLong(2));
3155 switch (val) {
3156 case 0:
3157 tab.m_alignment=MWAWTabStop::DECIMAL;
3158 break;
3159 case 1:
3160 tab.m_alignment=MWAWTabStop::RIGHT;
3161 break;
3162 case 2:
3163 tab.m_alignment=MWAWTabStop::CENTER;
3164 break;
3165 case 3: // left
3166 break;
3167 default:
3168 MWAW_DEBUG_MSG(("PowerPoint3Parser::readRuler: find unknown tab position\n"));
3169 f << "##tab" << i << "=" << val << ",";
3170 break;
3171 }
3172 ruler.m_paragraph.m_tabs->push_back(tab);
3173 }
3174 f << ruler << ",";
3175 if (m_state->m_idToRulerMap.find(pId)==m_state->m_idToRulerMap.end())
3176 m_state->m_idToRulerMap[pId]=ruler;
3177 else {
3178 f << "###dup,";
3179 MWAW_DEBUG_MSG(("PowerPoint3Parser::readRuler: paragraph %d already exists\n", pId));
3180 }
3181 if (input->tell()!=entry.end()) {
3182 f << "#extra,";
3183 ascii().addDelimiter(input->tell(),'|');
3184 }
3185 ascii().addPos(pos);
3186 ascii().addNote(f.str().c_str());
3187 return true;
3188 }
3189
3190 bool PowerPoint3Parser::readPictureMain(MWAWEntry const &entry)
3191 {
3192 if (!entry.valid() || entry.length()!=16) {
3193 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureMain: the zone seems bad\n"));
3194 return false;
3195 }
3196 MWAWInputStreamPtr input = getInput();
3197 long pos = entry.begin();
3198 entry.setParsed(true);
3199 input->seek(pos, librevenge::RVNG_SEEK_SET);
3200 libmwaw::DebugStream f;
3201 f << "Entries(PictMain)[Z"<< entry.id() << "]:";
3202 auto numZones=int(m_state->m_zonesList.size());
3203 auto val=int(input->readULong(4));
3204 int child=-1;
3205 if (val) {
3206 if (val>=0 && val<numZones) {
3207 f << "picture[id]=Z" << val << ",";
3208 child=val;
3209 }
3210 else {
3211 MWAW_DEBUG_MSG(("PowerPoint3Parser::readPictureMain: find some bad child\n"));
3212 f << "picture[id]=##Z" << val << ",";
3213 }
3214 }
3215 f << "ids=[";
3216 for (int i=0; i<3; ++i)
3217 f << std::hex << input->readULong(4) << std::dec << ",";
3218 f << "],";
3219 ascii().addPos(pos);
3220 ascii().addNote(f.str().c_str());
3221 ascii().addPos(entry.end());
3222 ascii().addNote("_");
3223 MWAWEntry const &cEntry=m_state->getZoneEntry(child);
3224 if (cEntry.valid()) {
3225 PowerPoint3ParserInternal::ListZoneIdParser parser(numZones, "Picture");
3226 if (readStructList(cEntry, parser)) {
3227 m_state->m_pictIdToZoneIdMap=parser.m_fieldIdToZoneIdMap;
3228 readPicturesList(parser.m_fieldIdToZoneIdMap);
3229 }
3230 }
3231 return true;
3232 }
3233
3234 bool PowerPoint3Parser::readColors(MWAWEntry const &entry)
3235 {
3236 if (!entry.valid() || (entry.length()%8)!=0) {
3237 MWAW_DEBUG_MSG(("PowerPoint3Parser::readColors: the zone seems bad\n"));
3238 return false;
3239 }
3240 MWAWInputStreamPtr input = getInput();
3241 long pos = entry.begin();
3242 entry.setParsed(true);
3243 input->seek(pos, librevenge::RVNG_SEEK_SET);
3244 libmwaw::DebugStream f;
3245 f << "Entries(Color)[Z"<< entry.id() << "]:";
3246 int val;
3247 for (int i=0; i<3; ++i) { // can be big numbers
3248 val=int(input->readULong(2));
3249 if (val) f << "f" << i << "=" << std::hex << val << std::dec << ",";
3250 }
3251 auto N=int(input->readULong(2));
3252 f << "N=" << N << ",";
3253 if (8+(N+1)*8 != int(entry.length())) {
3254 MWAW_DEBUG_MSG(("PowerPoint3Parser::readColors: the N value seems bad\n"));
3255 f << "###";
3256 ascii().addPos(pos);
3257 ascii().addNote(f.str().c_str());
3258 ascii().addPos(entry.end());
3259 ascii().addNote("_");
3260 return true;
3261 }
3262 ascii().addPos(pos);
3263 ascii().addNote(f.str().c_str());
3264 ascii().addPos(entry.end());
3265 ascii().addNote("_");
3266 // cmyk picker 32-33-34-35
3267 for (int i=0; i<=N; ++i) {
3268 pos=input->tell();
3269 f.str("");
3270 f << "Color-C" << i << ":";
3271 val=int(input->readLong(2));
3272 if (val) {
3273 unsigned char col[3];
3274 for (auto &c : col) c=static_cast<unsigned char>(input->readULong(2)>>8);
3275 MWAWColor color(col[0],col[1],col[2]);
3276 m_state->m_idToUserColorMap[i]=color;
3277 f << color << ",";
3278 }
3279 else
3280 f << "_,";
3281 input->seek(pos+8, librevenge::RVNG_SEEK_SET);
3282 ascii().addPos(pos);
3283 ascii().addNote(f.str().c_str());
3284 }
3285 return true;
3286 }
3287
3288 bool PowerPoint3Parser::readColorZone(MWAWEntry const &entry)
3289 {
3290 if (!entry.valid() || entry.length()<48) {
3291 MWAW_DEBUG_MSG(("PowerPoint3Parser::readColorZone: the zone seems bad\n"));
3292 return false;
3293 }
3294 MWAWInputStreamPtr input = getInput();
3295 long pos = entry.begin();
3296 entry.setParsed(true);
3297 input->seek(pos, librevenge::RVNG_SEEK_SET);
3298 libmwaw::DebugStream f;
3299 f << "Entries(Color)[Z"<< entry.id() << "]:menu,";
3300 auto N=int(input->readULong(2));
3301 f << "N=" << N << ",";
3302 if (48+2*N!=entry.length()) {
3303 MWAW_DEBUG_MSG(("PowerPoint3Parser::readColorZone: the N number seems bad\n"));
3304 f << "###";
3305 N=int(entry.length()/2)-24;
3306 }
3307 auto val=int(input->readLong(2)); // 8-a
3308 if (val) f << "f0=" << val << ",";
3309 auto numZones=int(m_state->m_zonesList.size());
3310 val=int(input->readULong(4));
3311 int child=-1;
3312 if (val) {
3313 if (val>=0 && val<numZones) {
3314 f << "child[id]=Z" << val << ",";
3315 child=val;
3316 }
3317 else {
3318 MWAW_DEBUG_MSG(("PowerPoint3Parser::readColorZone: find some bad child\n"));
3319 f << "child[id]=##Z" << val << ",";
3320 }
3321 }
3322 //unsure, look like a list of flags?
3323 ascii().addDelimiter(input->tell(),'|');
3324 input->seek(pos+46, librevenge::RVNG_SEEK_SET);
3325 ascii().addPos(pos);
3326 ascii().addNote(f.str().c_str());
3327
3328 pos=input->tell();
3329 f.str("");
3330 f << "Color-A:menu,used=[";
3331 for (int i=0; i<N; ++i) {
3332 val=int(input->readLong(2));
3333 if (val)
3334 f << val << ",";
3335 else
3336 f << "_,";
3337 }
3338 f << "],";
3339 val=int(input->readULong(2)); // big number
3340 if (val) f << "f0=" << std::hex << val << std::dec << ",";
3341 ascii().addPos(pos);
3342 ascii().addNote(f.str().c_str());
3343
3344 ascii().addPos(entry.end());
3345 ascii().addNote("_");
3346 MWAWEntry const &cEntry=m_state->getZoneEntry(child);
3347 if (cEntry.valid() && !cEntry.isParsed())
3348 readColors(cEntry);
3349 return true;
3350 }
3351
3352 bool PowerPoint3Parser::readZone9(MWAWEntry const &entry)
3353 {
3354 if (!entry.valid() || entry.length()!=34) {
3355 MWAW_DEBUG_MSG(("PowerPoint3Parser::readZone9: the zone seems bad\n"));
3356 return false;
3357 }
3358 MWAWInputStreamPtr input = getInput();
3359 long pos = entry.begin();
3360 entry.setParsed(true);
3361 input->seek(pos, librevenge::RVNG_SEEK_SET);
3362 libmwaw::DebugStream f;
3363 f << "Entries(Zone9)[Z"<< entry.id() << "]:";
3364 int val;
3365 for (int i=0; i<5; ++i) {
3366 val=int(input->readLong(2));
3367 int const expected[]= {1,1,0,0,0};
3368 if (val!=expected[i]) f << "f" << i << "=" << val << ",";
3369 }
3370 for (int i=0; i<8; ++i) {
3371 val=int(input->readLong(1));
3372 int const expected[]= {0,1,0,0,1,0,2,0};
3373 if (val!=expected[i]) f << "fl" << i << "=" << val << ",";
3374 }
3375 for (int i=0; i<5; ++i) { // g0=4|2000
3376 val=int(input->readLong(2));
3377 int const expected[]= {0,48,48,0,0};
3378 if (val!=expected[i]) f << "g" << i << "=" << std::hex << val << std::dec << ",";
3379 }
3380 val=int(input->readULong(1)); // 1|80
3381 if (val) f << "fl8=" << std::hex << val << std::dec << ",";
3382 for (int i=0; i<2; ++i) { // h1=0|3000
3383 val=int(input->readULong(2));
3384 if (val) f << "h" << i << "=" << std::hex << val << std::dec << ",";
3385 }
3386 val=int(input->readLong(1)); // 0
3387 if (val) f << "fl9=" << std::hex << val << std::dec << ",";
3388 ascii().addPos(pos);
3389 ascii().addNote(f.str().c_str());
3390 ascii().addPos(entry.end());
3391 ascii().addNote("_");
3392 return true;
3393 }
3394
3395 bool PowerPoint3Parser::readZone10(MWAWEntry const &entry)
3396 {
3397 if (!entry.valid() || (entry.length()%206)!=12) {
3398 MWAW_DEBUG_MSG(("PowerPoint3Parser::readZone10: the zone seems bad\n"));
3399 return false;
3400 }
3401 MWAWInputStreamPtr input = getInput();
3402 long pos = entry.begin();
3403 entry.setParsed(true);
3404 input->seek(pos, librevenge::RVNG_SEEK_SET);
3405 libmwaw::DebugStream f;
3406 f << "Entries(Zone10)[Z"<< entry.id() << "]:";
3407 f << "ids=[";
3408 for (int i=0; i<3; ++i)
3409 f << std::hex << input->readLong(4) << std::dec << ",";
3410 ascii().addPos(pos);
3411 ascii().addNote(f.str().c_str());
3412 auto N=int(entry.length()/206);
3413 for (int i=0; i<N; ++i) {
3414 pos=input->tell();
3415 f.str("");
3416 f << "Zone10A[" << i << "]:";
3417 auto val=int(input->readLong(2)); // -1|0-5
3418 if (val) f << "f0=" << val << ",";
3419 for (int k=0; k<2; ++k) { // fl0=[347c][23cd]
3420 val=int(input->readULong(1));
3421 if (val) f << "fl" << k << "=" << std::hex << val << std::dec << ",";
3422 }
3423 val=int(input->readULong(2)); // 8001|801f
3424 if (val!=0x801f) f << "fl2=" << std::hex << val << std::dec << ",";
3425 ascii().addPos(pos);
3426 ascii().addNote(f.str().c_str());
3427 for (int j=0; j<5; ++j) {
3428 pos=input->tell();
3429 f.str("");
3430 f << "Zone10B[" << i << "-" << j << "]:";
3431 for (int k=0; k<6; ++k) { // f0=[0-3] fontid?, f2=0|1, f3=1|3
3432 val=int(input->readLong(2));
3433 if (!val) continue;
3434 if (k==1) f << "font[sz]=" << val << ",";
3435 else f << "f" << k << "=" << val << ",";
3436 }
3437 ascii().addPos(pos);
3438 ascii().addNote(f.str().c_str());
3439 }
3440 for (int j=0; j<5; ++j) {
3441 pos=input->tell();
3442 f.str("");
3443 f << "Zone10C[" << i << "-" << j << "]:";
3444 for (int k=0; k<4; ++k) { // fl0=0|1|15|40|54, fl1=1|ff, fl2=[9-d][058b]
3445 val=int(input->readULong(1));
3446 if (val) f << "fl" << k << "=" << std::hex << val << std::dec << ",";
3447 }
3448 for (int k=0; k<12; ++k) { // f0=0-2, f1=100, f4=0-4, f5=0|1, f6=90|100, f7=0|20|30|40, f9=0|1
3449 val=int(input->readLong(2));
3450 if (val) f << "f" << k << "=" << val << ",";
3451 }
3452 input->seek(pos+28, librevenge::RVNG_SEEK_SET);
3453 ascii().addPos(pos);
3454 ascii().addNote(f.str().c_str());
3455 }
3456 }
3457 ascii().addPos(entry.end());
3458 ascii().addNote("_");
3459 return true;
3460 }
3461 ////////////////////////////////////////////////////////////
3462 // try to send data
3463 ////////////////////////////////////////////////////////////
3464 bool PowerPoint3Parser::sendText(PowerPoint3ParserInternal::SlideContent const &content, int tId, bool mainText, bool master)
3465 {
3466 MWAWListenerPtr listener=getPresentationListener();
3467 if (!listener) {
3468 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendText: can not find the listener\n"));
3469 return false;
3470 }
3471 auto numTZones=int(content.m_textZone.size());
3472 if (mainText) tId+=numTZones-content.m_numMainZones;
3473 int minTId=tId, maxTId=tId;
3474 if (tId==-1) {
3475 minTId=0;
3476 maxTId=numTZones-1;
3477 }
3478 else if (tId<0 || tId>=numTZones) {
3479 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendText: oops the textId=%d seems bad\n", tId));
3480 return false;
3481 }
3482 int const schemeId=content.m_schemeId;
3483 for (int id=minTId; id<=maxTId; ++id) {
3484 auto const &textZone=content.m_textZone[size_t(id)];
3485 MWAWInputStreamPtr input = getInput();
3486 long pos;
3487
3488 // paragraph
3489 PowerPoint3ParserInternal::Ruler ruler;
3490 if (m_state->m_idToRulerMap.find(textZone.m_rulerId)!=m_state->m_idToRulerMap.end())
3491 ruler=m_state->m_idToRulerMap.find(textZone.m_rulerId)->second;
3492 else {
3493 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendText: can not find paragraph %d\n", textZone.m_rulerId));
3494 }
3495
3496 MWAWEntry const &rEntry=textZone.m_rulers;
3497 int N=(rEntry.length()%28)==0 ? int(rEntry.length()/28) : 0;
3498 libmwaw::DebugStream f;
3499 std::map<int, MWAWParagraph> posToParagraphMap;
3500 input->seek(rEntry.begin(), librevenge::RVNG_SEEK_SET);
3501 int cPos=0;
3502 for (int i=0; i<N; ++i) {
3503 pos=input->tell();
3504 f.str("");
3505 f << "TextZone-R[" << i << "]:";
3506 auto cLen=int(input->readULong(4));
3507 f << "pos=" << cPos << "<->" << long(cPos)+cLen << ",";
3508 MWAWParagraph para;
3509 if (readParagraph(para, ruler, schemeId)) {
3510 if (posToParagraphMap.find(cPos)!=posToParagraphMap.end()) {
3511 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendText: oops, find duplicated position\n"));
3512 f << "##dup,";
3513 }
3514 f << para;
3515 }
3516 else
3517 f << "###";
3518 posToParagraphMap[cPos]=para;
3519 if (cLen < 0 || cLen > textZone.m_text.length() - cPos) // there can't be any para that long
3520 break;
3521 cPos+=cLen;
3522 input->seek(pos+28, librevenge::RVNG_SEEK_SET);
3523 ascii().addPos(pos);
3524 ascii().addNote(f.str().c_str());
3525 }
3526
3527 // fonts
3528 MWAWEntry const &fEntry=textZone.m_fonts;
3529 N=(fEntry.length()%16)==0 ? int(fEntry.length()/16) : 0;
3530 std::map<int, MWAWFont> posToFontMap;
3531 input->seek(fEntry.begin(), librevenge::RVNG_SEEK_SET);
3532 cPos=0;
3533 for (int i=0; i<N; ++i) {
3534 pos=input->tell();
3535 f.str("");
3536 f << "TextZone-F[" << i << "]:";
3537 auto cLen=int(input->readULong(4));
3538 f << "pos=" << cPos << "<->" << long(cPos)+cLen << ",";
3539 MWAWFont font;
3540 if (readFont(font, schemeId)) {
3541 if (posToFontMap.find(cPos)!=posToFontMap.end()) {
3542 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendText: oops, find duplicated position\n"));
3543 f << "##dup,";
3544 }
3545 else
3546 posToFontMap[cPos]=font;
3547 if (cLen < 0 || cLen > textZone.m_text.length() - cPos) // there can't be any span that long
3548 break;
3549 cPos+=cLen;
3550 f << font.getDebugString(getFontConverter());
3551 }
3552 else
3553 f << "###";
3554 input->seek(pos+16, librevenge::RVNG_SEEK_SET);
3555 ascii().addPos(pos);
3556 ascii().addNote(f.str().c_str());
3557 }
3558
3559 if (id!=minTId) listener->insertEOL();
3560 MWAWEntry const &tEntry=textZone.m_text;
3561 input->seek(tEntry.begin(), librevenge::RVNG_SEEK_SET);
3562 for (int i=0; i<int(tEntry.length()); ++i) {
3563 if (posToParagraphMap.find(i)!=posToParagraphMap.end())
3564 listener->setParagraph(posToParagraphMap.find(i)->second);
3565 if (posToFontMap.find(i)!=posToFontMap.end())
3566 listener->setFont(posToFontMap.find(i)->second);
3567 auto c=static_cast<unsigned char>(input->readULong(1));
3568 switch (c) {
3569 case 0x9:
3570 listener->insertTab();
3571 break;
3572 case 0xb:
3573 case 0xd:
3574 listener->insertEOL(c==0xb);
3575 break;
3576 case 0x11: // command key
3577 listener->insertUnicode(0x2318);
3578 break;
3579 // special, if dupplicated, this is a field
3580 case '/': // date
3581 case ':': // time
3582 case '#': { // page number
3583 pos=input->tell();
3584 if (master && i+1<int(tEntry.length()) && char(input->readULong(1))==char(c)) {
3585 ++i;
3586 listener->insertField(MWAWField(c=='#' ? MWAWField::PageNumber : c=='/' ? MWAWField::Date : MWAWField::Time));
3587 }
3588 else {
3589 input->seek(pos, librevenge::RVNG_SEEK_SET);
3590 listener->insertCharacter(c);
3591 }
3592 break;
3593 }
3594 default:
3595 listener->insertCharacter(c);
3596 break;
3597 }
3598 }
3599 }
3600 return true;
3601 }
3602
3603 void PowerPoint3Parser::sendSlides()
3604 {
3605 MWAWPresentationListenerPtr listener=getPresentationListener();
3606 if (!listener) {
3607 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendSlides: can not find the listener\n"));
3608 return;
3609 }
3610 if (m_state->m_slidesIdList.empty())
3611 return;
3612
3613 // first send the master page
3614 if (m_state->m_zoneIds[2]>=0) {
3615 MWAWPageSpan ps(getPageSpan());
3616 ps.setMasterPageName(librevenge::RVNGString("Master"));
3617 if (!listener->openMasterPage(ps)) {
3618 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendSlides: can not create the master page\n"));
3619 }
3620 else {
3621 int id=m_state->m_zoneIds[2];
3622 if (m_state->m_idToSlideMap.find(id)!=m_state->m_idToSlideMap.end()) {
3623 int cId=m_state->m_idToSlideMap.find(id)->second.m_contentIds[0];
3624 if (m_state->m_idToSlideContentMap.find(cId)!=m_state->m_idToSlideContentMap.end())
3625 sendSlide(m_state->m_idToSlideContentMap.find(cId)->second, true);
3626 }
3627 listener->closeMasterPage();
3628 }
3629 }
3630
3631 for (size_t i=0; i<m_state->m_slidesIdList.size(); ++i) {
3632 if (i>0)
3633 listener->insertBreak(MWAWListener::PageBreak);
3634 int id=m_state->m_slidesIdList[i];
3635 if (m_state->m_idToSlideMap.find(id)==m_state->m_idToSlideMap.end())
3636 continue;
3637 int cId=m_state->m_idToSlideMap.find(id)->second.m_contentIds[0];
3638 if (m_state->m_idToSlideContentMap.find(cId)==m_state->m_idToSlideContentMap.end())
3639 continue;
3640 sendSlide(m_state->m_idToSlideContentMap.find(cId)->second, false);
3641 // now try to send the note
3642 cId=m_state->m_idToSlideMap.find(id)->second.m_contentIds[1];
3643 if (m_state->m_idToSlideContentMap.find(cId)==m_state->m_idToSlideContentMap.end())
3644 continue;
3645 auto const &note=m_state->m_idToSlideContentMap.find(cId)->second;
3646 if (!note.hasText()) continue;
3647 MWAWPosition pos(MWAWVec2f(0,0), MWAWVec2f(200,200), librevenge::RVNG_POINT);
3648 pos.m_anchorTo = MWAWPosition::Page;
3649 MWAWSubDocumentPtr doc(new PowerPoint3ParserInternal::SubDocument(*this, getInput(), &note));
3650 listener->insertSlideNote(pos, doc);
3651 }
3652 }
3653
3654 bool PowerPoint3Parser::sendSlide(PowerPoint3ParserInternal::SlideContent const &slide, bool master)
3655 {
3656 MWAWPresentationListenerPtr listener=getPresentationListener();
3657 if (!listener) {
3658 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendSlide: can not find the listener\n"));
3659 return false;
3660 }
3661 // first is title, better to remove it in the master slide
3662 for (size_t f=0; f<slide.m_frameList.size(); ++f) {
3663 if (slide.m_frameList[f].m_isSent) continue;
3664 if (master && slide.m_frameList[f].m_mainTextBox) continue;
3665 std::set<int> seen;
3666 seen.insert(int(f));
3667 sendFrame(slide.m_frameList[f], slide, master, seen);
3668 }
3669 return true;
3670 }
3671
3672 bool PowerPoint3Parser::sendFrame(PowerPoint3ParserInternal::Frame const &frame, PowerPoint3ParserInternal::SlideContent const &content, bool master, std::set<int> &seen)
3673 {
3674 frame.m_isSent=true;
3675 MWAWListenerPtr listener=getPresentationListener();
3676 if (!listener) {
3677 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendFrame: can not find the listener\n"));
3678 return false;
3679 }
3680
3681 MWAWBox2f fBox(1.f/8.f*MWAWVec2f(frame.m_dimension[0]+m_state->m_origin),
3682 1.f/8.f*MWAWVec2f(frame.m_dimension[1]+m_state->m_origin));
3683 if (frame.m_textId>=0) {
3684 MWAWPosition pos(fBox[0], fBox.size(), librevenge::RVNG_POINT);
3685 pos.m_anchorTo = MWAWPosition::Page;
3686 MWAWSubDocumentPtr subdoc(new PowerPoint3ParserInternal::SubDocument(*this, getInput(), &content, frame.m_textId, frame.m_mainTextBox, master));
3687 listener->insertTextBox(pos, subdoc, frame.m_style);
3688 return true;
3689 }
3690 if (frame.m_pictureId>=0) {
3691 if (m_state->m_pictIdToZoneIdMap.find(frame.m_pictureId)==m_state->m_pictIdToZoneIdMap.end()) {
3692 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendFrame: can not find the picture %d\n", frame.m_pictureId));
3693 return false;
3694 }
3695 int zId=m_state->m_pictIdToZoneIdMap.find(frame.m_pictureId)->second;
3696 if (m_state->m_idToPictureContentMap.find(zId)==m_state->m_idToPictureContentMap.end()) {
3697 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendFrame: can not find the picture %d in Z%d\n", frame.m_pictureId, zId));
3698 return false;
3699 }
3700 MWAWPosition pos(fBox[0], fBox.size(), librevenge::RVNG_POINT);
3701 pos.m_anchorTo = MWAWPosition::Page;
3702 listener->insertPicture(pos, m_state->m_idToPictureContentMap.find(zId)->second);
3703 return true;
3704 }
3705 MWAWGraphicShape shape;
3706 switch (frame.m_type) {
3707 case 0:
3708 shape=MWAWGraphicShape::line(fBox[0], fBox[1]);
3709 break;
3710 case 1: {
3711 if (frame.m_customShapeId>=0) {
3712 if (!m_state->getCustomShape(frame.m_customShapeId, shape))
3713 return false;
3714 if (frame.m_customTransformation&3)
3715 shape=shape.rotate(-90.f*float(frame.m_customTransformation&3), MWAWVec2f(0.5f,0.5f));
3716 if (frame.m_customTransformation&4) {
3717 shape.translate(MWAWVec2f(-0.5f,-0.5f));
3718 shape.scale(MWAWVec2f(-1,1));
3719 shape.translate(MWAWVec2f(0.5f,0.5f));
3720 }
3721 shape.scale(fBox.size());
3722 shape.translate(fBox[0]);
3723 break;
3724 }
3725 switch (frame.m_shapeId) {
3726 case 1:
3727 shape=MWAWGraphicShape::circle(fBox);
3728 break;
3729 case 2:
3730 shape=MWAWGraphicShape::rectangle(fBox, MWAWVec2f(3,3));
3731 break;
3732 case 3:
3733 shape=MWAWGraphicShape::rectangle(fBox);
3734 break;
3735 default:
3736 return false;
3737 }
3738 break;
3739 }
3740 case 2: {
3741 if (frame.m_polygonId<0||frame.m_polygonId>=int(content.m_polygonList.size())) {
3742 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendFrame: can not find the polygon %d\n", frame.m_polygonId));
3743 return false;
3744 }
3745 auto const &poly=content.m_polygonList[size_t(frame.m_polygonId)];
3746 if (!poly.updateShape(fBox, shape)) return false;
3747 break;
3748 }
3749 case 3: {
3750 float angle[2] = { frame.m_angles[0], frame.m_angles[0]+frame.m_angles[1] };
3751 if (angle[1]<angle[0])
3752 std::swap(angle[0],angle[1]);
3753 if (angle[1]>360) {
3754 int numLoop=int(angle[1]/360)-1;
3755 angle[0]-=float(numLoop*360);
3756 angle[1]-=float(numLoop*360);
3757 while (angle[1] > 360) {
3758 angle[0]-=360;
3759 angle[1]-=360;
3760 }
3761 }
3762 if (angle[0] < -360) {
3763 int numLoop=int(angle[0]/360)+1;
3764 angle[0]-=float(numLoop*360);
3765 angle[1]-=float(numLoop*360);
3766 while (angle[0] < -360) {
3767 angle[0]+=360;
3768 angle[1]+=360;
3769 }
3770 }
3771 MWAWVec2f center = fBox.center();
3772 MWAWVec2f axis = 0.5f*MWAWVec2f(fBox.size());
3773 // we must compute the real bd box
3774 float minVal[2] = { 0, 0 }, maxVal[2] = { 0, 0 };
3775 int limitAngle[2];
3776 for (int i = 0; i < 2; i++)
3777 limitAngle[i] = (angle[i] < 0) ? int(angle[i]/90)-1 : int(angle[i]/90);
3778 for (int bord = limitAngle[0]; bord <= limitAngle[1]+1; bord++) {
3779 float ang = (bord == limitAngle[0]) ? angle[0] :
3780 (bord == limitAngle[1]+1) ? angle[1] : 90 * float(bord);
3781 ang *= float(M_PI/180.);
3782 float const actVal[2] = { axis[0] *std::cos(ang), -axis[1] *std::sin(ang)};
3783 if (actVal[0] < minVal[0]) minVal[0] = actVal[0];
3784 else if (actVal[0] > maxVal[0]) maxVal[0] = actVal[0];
3785 if (actVal[1] < minVal[1]) minVal[1] = actVal[1];
3786 else if (actVal[1] > maxVal[1]) maxVal[1] = actVal[1];
3787 }
3788 MWAWBox2f realBox(MWAWVec2f(center[0]+minVal[0],center[1]+minVal[1]),
3789 MWAWVec2f(center[0]+maxVal[0],center[1]+maxVal[1]));
3790 shape = MWAWGraphicShape::pie(realBox, fBox, MWAWVec2f(float(angle[0]),float(angle[1])));
3791 break;
3792 }
3793 case 4: {
3794 MWAWPosition pos(fBox[0], fBox.size(), librevenge::RVNG_POINT);
3795 pos.m_anchorTo = MWAWPosition::Page;
3796 listener->openGroup(pos);
3797 auto numGroups=int(content.m_frameList.size());
3798 // check if the group child list is not broken
3799 bool ok=true;
3800 for (auto id : seen) {
3801 if (frame.m_groupChild[0]<=id && id<=frame.m_groupChild[1]) {
3802 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendFrame: oops the child list seems broken\n"));
3803 ok=false;
3804 break;
3805 }
3806 }
3807 if (ok) {
3808 for (int i=frame.m_groupChild[0]; i<=frame.m_groupChild[1]; ++i) {
3809 if (i<0||i>=numGroups || seen.find(i)!=seen.end()) {
3810 MWAW_DEBUG_MSG(("PowerPoint3Parser::sendFrame: group %d seens bad\n", i));
3811 continue;
3812 }
3813 seen.insert(i);
3814 sendFrame(content.m_frameList[size_t(i)], content, master, seen);
3815 seen.erase(i);
3816 }
3817 }
3818 listener->closeGroup();
3819 return true;
3820 }
3821 default:
3822 shape=MWAWGraphicShape::rectangle(fBox);
3823 break;
3824 }
3825 MWAWBox2f box=shape.getBdBox();
3826 MWAWPosition pos(box[0], box.size(), librevenge::RVNG_POINT);
3827 pos.m_anchorTo = MWAWPosition::Page;
3828 listener->insertShape(pos, shape, frame.m_style);
3829
3830 return true;
3831 }
3832 ////////////////////////////////////////////////////////////
3833 // Low level
3834 ////////////////////////////////////////////////////////////
3835
3836 // read the header
3837 bool PowerPoint3Parser::checkHeader(MWAWHeader *header, bool strict)
3838 {
3839 *m_state = PowerPoint3ParserInternal::State();
3840 MWAWInputStreamPtr input = getInput();
3841 if (!input || !input->hasDataFork())
3842 return false;
3843 if (input->isStructured()) {
3844 input=input->getSubStreamByName("PP40");
3845 if (!input)
3846 return false;
3847 }
3848 libmwaw::DebugStream f;
3849 if (!input->checkPosition(24+8)) {
3850 MWAW_DEBUG_MSG(("PowerPoint3Parser::checkHeader: file is too short\n"));
3851 return false;
3852 }
3853 long pos = 0;
3854 input->setReadInverted(false);
3855 input->seek(pos, librevenge::RVNG_SEEK_SET);
3856 unsigned long signature=input->readULong(4);
3857 if (signature==0xeddead0b) {
3858 input->setReadInverted(true);
3859 m_state->m_isMacFile=false;
3860 }
3861 else if (signature!=0xbaddeed)
3862 return false;
3863 f << "FileHeader:";
3864 auto vers=int(input->readLong(4));
3865 if (vers!=3 && vers!=4) return false;
3866 m_state->m_zoneListBegin=long(input->readULong(4));
3867 if (m_state->m_zoneListBegin<24 || !input->checkPosition(m_state->m_zoneListBegin))
3868 return false;
3869 f << "zone[begin]=" << std::hex << m_state->m_zoneListBegin << std::dec << ",";
3870
3871 if (strict) {
3872 input->seek(12, librevenge::RVNG_SEEK_SET);
3873 auto val=int(input->readULong(2));
3874 if (!input->checkPosition(m_state->m_zoneListBegin+val*8))
3875 return false;
3876 }
3877 input->seek(12, librevenge::RVNG_SEEK_SET);
3878 ascii().addPos(pos);
3879 ascii().addNote(f.str().c_str());
3880
3881 setVersion(vers);
3882 if (header)
3883 header->reset(MWAWDocument::MWAW_T_POWERPOINT, vers, MWAWDocument::MWAW_K_PRESENTATION);
3884 return true;
3885 }
3886
3887 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: