Debian Codegraph @

src/lib/PowerPoint7Text.cxx

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2002 William Lachance ([email protected])
18 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
19 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
22 *
23 *
24 * All Rights Reserved.
25 *
26 * For minor contributions see the git repository.
27 *
28 * Alternatively, the contents of this file may be used under the terms of
29 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30 * in which case the provisions of the LGPLv2+ are applicable
31 * instead of those above.
32 */
33
34 #include <cmath>
35 #include <iomanip>
36 #include <iostream>
37 #include <limits>
38 #include <map>
39 #include <sstream>
40
41 #include <librevenge/librevenge.h>
42
43 #include "MWAWFont.hxx"
44 #include "MWAWFontConverter.hxx"
45 #include "MWAWParagraph.hxx"
46 #include "MWAWParser.hxx"
47 #include "MWAWPosition.hxx"
48 #include "MWAWPresentationListener.hxx"
49
50 #include "PowerPoint7Struct.hxx"
51
52 #include "PowerPoint7Text.hxx"
53 #include "PowerPoint7Parser.hxx"
54
55 /** Internal: the structures of a PowerPoint7Text */
56 namespace PowerPoint7TextInternal
57 {
58 //! Internal: a ruler of a PowerPoint7Text
59 struct Ruler {
60 //! constructor
61 Ruler()
62 : m_paragraph()
63 {
64 for (auto &margin : m_margins) margin=0;
65 }
66 //! returns a paragraph corresponding to a level
67 void updateParagraph(int level)
68 {
69 if (level<0 || level>4) {
70 MWAW_DEBUG_MSG(("PowerPoint7TextInternal::Ruler::updateParagraph: the level %d seems bad\n", level));
71 level=0;
72 }
73 m_paragraph.m_marginsUnit=librevenge::RVNG_POINT;
74 m_paragraph.m_margins[0]=(double(m_margins[2*level+1])-m_margins[2*level+0])/8;
75 m_paragraph.m_margins[1]=double(m_margins[2*level+0])/8;
76 }
77 //! the paragraph
78 MWAWParagraph m_paragraph;
79 //! the left/first margins * 5 (0: normal, 1-4: level)
80 int m_margins[10];
81 };
82
83 //! Internal: a text zone of a PowerPoint7Text
84 struct TextZone {
85 //! constructor
86 TextZone()
87 : m_textEntry()
88 , m_rulerId(-1)
89 , m_posToFontMap()
90 , m_posToRulerMap()
91 , m_posToFieldFormatMap()
92 {
93 }
94 //! returns true if the zone contain no text
95 bool isEmpty() const
96 {
97 return !m_textEntry.valid();
98 }
99 //! the list of text zone
100 MWAWEntry m_textEntry;
101 //! the ruler identifier
102 int m_rulerId;
103 //! a map position to font
104 std::map<long,MWAWFont> m_posToFontMap;
105 //! a map position to ruler
106 std::map<long,Ruler> m_posToRulerMap;
107 //! a map position to format
108 std::map<long,int> m_posToFieldFormatMap;
109 };
110
111 ////////////////////////////////////////
112 //! Internal: the state of a PowerPoint7Text
113 struct State {
114 //! constructor
115 State()
116 : m_fontFamily("CP1252")
117 , m_fileIdFontIdMap()
118 , m_idToRulerMap()
119 , m_fieldIdToFormatIdMap()
120 , m_textZoneList()
121 { }
122 //! the basic pc font family if known
123 std::string m_fontFamily;
124 //! a local id to final id font map
125 std::map<int,int> m_fileIdFontIdMap;
126 //! a local id to ruler id map
127 std::map<int,Ruler> m_idToRulerMap;
128 //! a field id to format id map
129 std::map<int,int> m_fieldIdToFormatIdMap;
130 //! the list of text zone
131 std::vector<std::shared_ptr<TextZone> > m_textZoneList;
132 };
133 }
134
135 ////////////////////////////////////////////////////////////
136 // constructor/destructor, ...
137 ////////////////////////////////////////////////////////////
138 PowerPoint7Text::PowerPoint7Text(PowerPoint7Parser &parser)
139 : m_parserState(parser.getParserState())
140 , m_state(new PowerPoint7TextInternal::State)
141 , m_mainParser(&parser)
142 {
143 }
144
145 PowerPoint7Text::~PowerPoint7Text()
146 { }
147
148 int PowerPoint7Text::version() const
149 {
150 return m_parserState->m_version;
151 }
152
153 void PowerPoint7Text::setFontFamily(std::string const &family)
154 {
155 m_state->m_fontFamily=family;
156 }
157
158 ////////////////////////////////////////////////////////////
159 //
160 // Intermediate level
161 //
162 ////////////////////////////////////////////////////////////
163 bool PowerPoint7Text::readFontCollection(int level, long lastPos)
164 {
165 MWAWInputStreamPtr input=m_parserState->m_input;
166 long pos=input->tell();
167
168 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
169 libmwaw::DebugStream f;
170 PowerPoint7Struct::Zone header;
171 if (!header.read(input,lastPos) || header.m_type!=2005) {
172 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontCollection: can not find the zone header\n"));
173 input->seek(pos, librevenge::RVNG_SEEK_SET);
174 return false;
175 }
176 f << "Entries(FontDef)[collection," << level << "]:" << header;
177 ascFile.addPos(pos);
178 ascFile.addNote(f.str().c_str());
179
180 long endPos=pos+16+header.m_dataSize;
181 std::string fName;
182 int id;
183 while (input->tell()<endPos) {
184 pos=input->tell();
185 auto cType=int(input->readULong(2));
186 input->seek(pos, librevenge::RVNG_SEEK_SET);
187
188 bool done=false;
189 switch (cType) {
190 case 2017: {
191 done=m_mainParser->readIdentifier(level+1,endPos,id,"FontDef");
192 if (!done || fName.empty()) break;
193 if (m_state->m_fileIdFontIdMap.find(id)!=m_state->m_fileIdFontIdMap.end()) {
194 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontCollection: can not define font %d\n", id));
195 break;
196 }
197 int fId;
198 if (fName=="Monotype Sorts" || fName=="Wingdings")
199 fId=m_parserState->m_fontConverter->getId(fName);
200 else {
201 std::string finalName("_");
202 finalName+=fName;
203 fId=m_parserState->m_fontConverter->getId(finalName, m_state->m_fontFamily);
204 }
205 m_state->m_fileIdFontIdMap[id]=fId;
206 fName="";
207 break;
208 }
209 case 2018:
210 done=m_mainParser->readZoneNoData(level+1,endPos,"FontDef","id,end");
211 break;
212 case 4022: // StyleTextProp11Atom
213 done=readFontContainer(level+1,endPos,fName);
214 break;
215 case 4042: // after readFontContainer
216 done=m_mainParser->readZoneNoData(level+1,endPos,"FontDef","flags"); // some flags?
217 break;
218 default:
219 done=m_mainParser->readZone(level+1,endPos);
220 if (done) {
221 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontCollection: find unexpected zone %d\n", cType));
222 }
223 break;
224 }
225 if (done) continue;
226 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontCollection: can not read some data\n"));
227 ascFile.addPos(pos);
228 ascFile.addNote("FontDef:###extra");
229 input->seek(endPos, librevenge::RVNG_SEEK_SET);
230 break;
231 }
232 return true;
233 }
234
235 bool PowerPoint7Text::readTextZoneContainer(int level, long lastPos, PowerPoint7TextInternal::TextZone &zone)
236 {
237 MWAWInputStreamPtr input=m_parserState->m_input;
238 long pos=input->tell();
239
240 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
241 libmwaw::DebugStream f;
242 PowerPoint7Struct::Zone header;
243 if (!header.read(input,lastPos) || header.m_type!=2028) {
244 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZoneContainer: can not find the zone header\n"));
245 input->seek(pos, librevenge::RVNG_SEEK_SET);
246 return false;
247 }
248 f << "Entries(TextZone)[container," << level << "]:" << header;
249 ascFile.addPos(pos);
250 ascFile.addNote(f.str().c_str());
251
252 long endPos=pos+16+header.m_dataSize;
253 while (input->tell()<endPos) {
254 pos=input->tell();
255 auto cType=int(input->readULong(2));
256 input->seek(pos, librevenge::RVNG_SEEK_SET);
257
258 bool done=false;
259 switch (cType) {
260 case 2030:
261 done=readTextZone(level+1,endPos,zone);
262 break;
263 default:
264 done=m_mainParser->readZone(level+1,endPos);
265 if (done) {
266 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZoneContainer: find unexpected zone %d\n", cType));
267 }
268 break;
269 }
270 if (done) continue;
271 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZoneContainer: can not read some data\n"));
272 ascFile.addPos(pos);
273 ascFile.addNote("TextZone:###extra");
274 input->seek(endPos, librevenge::RVNG_SEEK_SET);
275 break;
276 }
277 return true;
278 }
279
280 bool PowerPoint7Text::readTextZone(int level, long lastPos, PowerPoint7TextInternal::TextZone &zone)
281 {
282 MWAWInputStreamPtr input=m_parserState->m_input;
283 long pos=input->tell();
284
285 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
286 libmwaw::DebugStream f;
287 PowerPoint7Struct::Zone header;
288 if (!header.read(input,lastPos) || header.m_type!=2030) {
289 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: can not find the zone header\n"));
290 input->seek(pos, librevenge::RVNG_SEEK_SET);
291 return false;
292 }
293 long endPos=pos+16+header.m_dataSize;
294 f << "Entries(TextZone)[" << level << "]:" << header;
295 int val;
296 switch (header.m_values[3]) {
297 case 47: {
298 if (header.m_dataSize%44) {
299 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: unexpected data size for zone=47\n"));
300 f << "###,";
301 break;
302 }
303 ascFile.addPos(pos);
304 ascFile.addNote(f.str().c_str());
305 auto N=int(header.m_dataSize/44);
306 long actC=0;
307 int defaultId=m_parserState->m_fontConverter->getId(m_state->m_fontFamily.c_str());
308 for (int fo=0; fo<N; ++fo) {
309 pos=input->tell();
310 f.str("");
311 f << "TextZone-FS" << fo << "[font]:";
312 auto nC=long(input->readULong(4));
313 f << "nC=" << nC << ",";
314 for (int i=0; i<6; ++i) {
315 val=int(input->readLong(2));
316 int const expected[]= {0xfe2, 0, 0, 0, 0x18, 0};
317 if (val!=expected[i])
318 f << "f" << i << "=" << val << ",";
319 }
320 f << "fl=[";
321 for (int i=0; i<4; ++i) {
322 val=int(input->readULong(1));
323 if (val)
324 f << std::hex << val << std::dec << ",";
325 else
326 f << "_,";
327 }
328 f << "],";
329 auto fontId=int(input->readULong(2));
330 MWAWFont font;
331 if (m_state->m_fileIdFontIdMap.find(fontId)!=m_state->m_fileIdFontIdMap.end())
332 font.setId(m_state->m_fileIdFontIdMap.find(fontId)->second);
333 else {
334 font.setId(defaultId);
335 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: can not find font %d\n", fontId));
336 f << "fId=###" << "F" << fontId << ",";
337 }
338 val=int(input->readLong(2));
339 if (val!=2) f << "f6=" << val << ",";
340 val=int(input->readULong(2));
341 if (val) font.setSize(float(val));
342 val=int(input->readLong(2));
343 if (val) f << "f7=" << val << ",";
344 auto flag=int(input->readULong(2));
345 uint32_t flags=0;
346 if (flag&0x1) flags |= MWAWFont::boldBit;
347 if (flag&0x2) flags |= MWAWFont::italicBit;
348 if (flag&0x4) font.setUnderlineStyle(MWAWFont::Line::Simple);
349 if (flag&0x8) flags |= MWAWFont::embossBit;
350 if (flag&0x10) flags |= MWAWFont::shadowBit;
351 if (flag&0x80) f << "fl4,";
352 if (flag&0x200) flags |= MWAWFont::embossBit;
353 // flag&0x400 super, flag&0x800 sub
354 flag&=0xF160;
355 if (flag) f << "##flag=" << std::hex << flag << std::dec << ",";// find 4
356 font.setFlags(flags);
357 unsigned char col[4];
358 for (auto &c : col) c=static_cast<unsigned char>(input->readULong(1));
359 MWAWColor color=MWAWColor::black();
360 if (col[3]==0xfe)
361 color=MWAWColor(col[0],col[1],col[2]);
362 else if (!m_mainParser->getColor(col[3],color)) {
363 f << "##color[id]=" << int(col[3]) << ",";
364 }
365 if (!color.isBlack())
366 font.setColor(color);
367 val=int(input->readLong(2)); // 12|47|62
368 if (val) f << "g0=" << val << ",";
369 val=int(input->readLong(4));
370 if (val) font.set(MWAWFont::Script(float(val),librevenge::RVNG_PERCENT,58));
371 for (int i=0; i<2; ++i) { // 0
372 val=int(input->readLong(2));
373 if (val) f << "g" << i+1 << "=" << val << ",";
374 }
375 f << font.getDebugString(m_parserState->m_fontConverter);
376
377 if (zone.m_posToFontMap.find(actC)!=zone.m_posToFontMap.end()) {
378 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: a font already exists for pos=%ld\n", actC));
379 f << "###,";
380 }
381 else
382 zone.m_posToFontMap[actC]=font;
383 actC+=nC;
384 input->seek(pos+44, librevenge::RVNG_SEEK_SET);
385 ascFile.addPos(pos);
386 ascFile.addNote(f.str().c_str());
387 }
388 return true;
389 }
390 case 48: {
391 if (header.m_dataSize%72) {
392 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: unexpected data size for zone=48\n"));
393 f << "###,";
394 break;
395 }
396 ascFile.addPos(pos);
397 ascFile.addNote(f.str().c_str());
398 auto N=int(header.m_dataSize/72);
399 int defaultId=m_parserState->m_fontConverter->getId(m_state->m_fontFamily.c_str());
400 PowerPoint7TextInternal::Ruler defaultRuler;
401 if (m_state->m_idToRulerMap.find(zone.m_rulerId)!=m_state->m_idToRulerMap.end())
402 defaultRuler=m_state->m_idToRulerMap.find(zone.m_rulerId)->second;
403 else {
404 f << "##R" << zone.m_rulerId << ",";
405 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: can not find ruler %d\n", zone.m_rulerId));
406 }
407 long actC=0;
408 for (int r=0; r<N; ++r) {
409 pos=input->tell();
410 f.str("");
411 f << "TextZone-R" << r << "[ruler]:";
412 auto nC=int(input->readULong(4));
413 f << "nChar=" << nC << ",";
414 auto ruler=defaultRuler;
415 MWAWParagraph &para=ruler.m_paragraph;
416 for (int i=0; i<6; ++i) {
417 val=int(input->readLong(2));
418 int const expected[]= {0xfe3, 0, 0, 0, 0x34, 0};
419 if (val!=expected[i])
420 f << "f" << i << "=" << val << ",";
421 }
422 f << "fl=[";
423 for (int i=0; i<4; ++i) {
424 val=int(input->readULong(1));
425 if (val)
426 f << std::hex << val << std::dec << ",";
427 else
428 f << "_,";
429 }
430 f << "],";
431 // bullet
432 char bulletChar=0;
433 MWAWColor bulletColor;
434 MWAWFont bulletFont;
435 bulletFont.setId(defaultId);
436 auto bulletFlags=int(input->readULong(2));
437 if (bulletFlags&1) {
438 f << "useBullet[";
439 if (bulletFlags&4) f << "font,";
440 if (bulletFlags&0x10) f << "color,";
441 if (bulletFlags&0x40) f << "size,";
442 f << "],";
443 if (bulletFlags&0xffaa) f << "bullet[flag]=" << std::hex << (bulletFlags&0xffaa) << std::dec << ",";
444 }
445 unsigned char col[4];
446 for (auto &c : col) c=static_cast<unsigned char>(input->readULong(1));
447 if (col[3]==0xfe)
448 bulletColor=MWAWColor(col[0],col[1],col[2]);
449 else if ((bulletFlags&0x11)==0x11 && col[3]!=0xfd && !m_mainParser->getColor(col[3],bulletColor)) {
450 f << "##color[id]=" << int(col[3]) << ",";
451 }
452 if (!bulletColor.isBlack()) {
453 bulletFont.setColor(bulletColor);
454 f << "bullet[color]=" << bulletColor << ",";
455 }
456 for (int i=0; i<9; ++i) { // f8=-1|2-4,f10=small number
457 val=int(input->readLong(2));
458 int const expected[]= {0,-1,2,100,0,0,0,0,0};
459 if (val==expected[i]) continue;
460 switch (i) {
461 case 0:
462 if ((bulletFlags&1)==0) break;
463 bulletChar=char(val);
464 f << "bullet[char]=" << bulletChar << ",";
465 break;
466 case 1:
467 if ((bulletFlags&5)!=5) break;
468 if (m_state->m_fileIdFontIdMap.find(val)!=m_state->m_fileIdFontIdMap.end())
469 bulletFont.setId(m_state->m_fileIdFontIdMap.find(val)->second);
470 else {
471 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: can not find font %d\n", val));
472 f << "###";
473 }
474 f << "fId[bullet]=F" << val << ",";
475 break;
476 case 3:
477 if ((bulletFlags&0x41)!=0x41) break;
478 f << "bullet[size]=" << val << "%,";
479 bulletFont.setSize(float(val)/100.f, true);
480 break;
481 default:
482 f << "f" << i+8 << "=" << val << ",";
483 break;
484 }
485 }
486
487 auto levl=int(input->readULong(1));
488 if (levl) f << "level=" << levl << ",";
489 ruler.updateParagraph(levl);
490 if (bulletChar) {
491 para.m_listLevelIndex=(levl>=0 && levl<=4) ? levl+1 : 1;
492 para.m_listLevel=MWAWListLevel();
493 para.m_listLevel->m_type=MWAWListLevel::BULLET;
494 para.m_listLevel->m_spanId=m_parserState->m_fontManager->getId(bulletFont);
495 int unicode=m_parserState->m_fontConverter->unicode(bulletFont.id(), static_cast<unsigned char>(bulletChar));
496 libmwaw::appendUnicode(unicode==-1 ? 0x2022 : uint32_t(unicode), para.m_listLevel->m_bullet);
497 }
498 val=int(input->readULong(1)); // 0|1|10|30|33 junk?
499 if (val) f << "fl3=" << std::hex << val << std::dec << ",";
500 for (int i=0; i<3; ++i) {
501 val=int(input->readLong(2));
502 if (i==1) {
503 switch (val) {
504 case 0: // left
505 break;
506 case 1:
507 para.m_justify=MWAWParagraph::JustificationCenter;
508 f << "center,";
509 break;
510 case 2:
511 para.m_justify=MWAWParagraph::JustificationRight;
512 f << "right,";
513 break;
514 case 3:
515 para.m_justify=MWAWParagraph::JustificationFull;
516 f << "justify,";
517 break;
518 default:
519 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: find unknown justifcation\n"));
520 f << "##justify=" << val << ",";
521 }
522 }
523 else if (val)
524 f << "g" << i << "=" << val << ",";
525 }
526 for (int i=0; i<3; ++i) {
527 val=int(input->readLong(4));
528 char const *wh[]= {"interline","before","after"};
529 if (val<0) {
530 f << wh[i] << "=" << -int64_t(val) << "pt,";
531 if (val + std::numeric_limits<int>::max() < 0) {
532 f << "###";
533 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: find bad spacing\n"));
534 }
535 else if (i==0)
536 para.setInterline(-val, librevenge::RVNG_POINT);
537 else
538 para.m_spacings[i]=-double(val)/72.;
539 }
540 else if ((i==0 && val!=100) || (i!=0 && val)) {
541 if (i==0)
542 para.setInterline(double(val)/100., librevenge::RVNG_PERCENT);
543 else
544 para.m_spacings[i]=double(val)/100.*24./72.; // percent assume font=24
545 f << wh[i] << "=" << val << "%,";
546 }
547 }
548 for (int i=0; i<4; ++i) {
549 val=int(input->readLong(2));
550 if (val!=(i==3 ? 1 : 0))
551 f << "g" << i+3 << "=" << val << ",";
552 }
553 if (zone.m_posToRulerMap.find(actC)!=zone.m_posToRulerMap.end()) {
554 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: a ruler already exists for pos=%ld\n", actC));
555 f << "###,";
556 }
557 else
558 zone.m_posToRulerMap[actC]=ruler;
559 actC+=nC;
560 input->seek(pos+72, librevenge::RVNG_SEEK_SET);
561 ascFile.addPos(pos);
562 ascFile.addNote(f.str().c_str());
563 }
564 return true;
565 }
566 case 49: {
567 if (header.m_dataSize%24) {
568 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: unexpected data size for zone=49\n"));
569 f << "###,";
570 break;
571 }
572 ascFile.addPos(pos);
573 ascFile.addNote(f.str().c_str());
574 auto N=int(header.m_dataSize/24);
575 long actC=0;
576 for (int fl=0; fl<N; ++fl) {
577 pos=input->tell();
578 f.str("");
579 f << "TextZone-F" << fl << "[field]:";
580 auto nC=int(input->readULong(4));
581 f << "nChar=" << nC << ",";
582 for (int i=0; i<6; ++i) {
583 val=int(input->readLong(2));
584 int const expected[]= {0xfe1, 0, 0, 0, 0x4, 0};
585 if (val!=expected[i])
586 f << "f" << i << "=" << val << ",";
587 }
588 f << "fl=[";
589 for (int i=0; i<4; ++i) {
590 val=int(input->readULong(1));
591 if (val)
592 f << std::hex << val << std::dec << ",";
593 else
594 f << "_,";
595 }
596 f << "],";
597 val=int(input->readLong(4));
598 if (val!=-1 && m_state->m_fieldIdToFormatIdMap.find(val)!=m_state->m_fieldIdToFormatIdMap.end()) {
599 int format=m_state->m_fieldIdToFormatIdMap.find(val)->second;
600 f << "FS" << format << ",";
601 if (zone.m_posToFieldFormatMap.find(actC)!=zone.m_posToFieldFormatMap.end()) {
602 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: a fieldFormat already exists for pos=%ld\n", actC));
603 f << "###,";
604 }
605 else
606 zone.m_posToFieldFormatMap[actC]=format;
607 }
608 else if (val!=-1) {
609 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: can not find format\n"));
610 f << "##FS=" << val << ",";
611 }
612 actC+=nC;
613 input->seek(pos+24, librevenge::RVNG_SEEK_SET);
614 ascFile.addPos(pos);
615 ascFile.addNote(f.str().c_str());
616 }
617 return true;
618 }
619 case 53: {
620 if (zone.m_textEntry.valid()) {
621 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: oops a text entry is already defined\n"));
622 f << "##duplicated,";
623 }
624 else {
625 zone.m_textEntry.setBegin(input->tell());
626 zone.m_textEntry.setLength(header.m_dataSize);
627 }
628 std::string text;
629 for (long i=0; i<header.m_dataSize; ++i)
630 text+=char(input->readULong(1));
631 f << text << ",";
632 break;
633 }
634 default:
635 if (!header.m_dataSize)
636 break;
637 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextZone: unexpected data for zone=%d\n", header.m_values[3]));
638 f << "###,";
639 break;
640 }
641 if (input->tell()!=endPos)
642 ascFile.addDelimiter(input->tell(),'|');
643 ascFile.addPos(pos);
644 ascFile.addNote(f.str().c_str());
645
646 input->seek(endPos, librevenge::RVNG_SEEK_SET);
647 return true;
648 }
649
650 bool PowerPoint7Text::readTextMasterProp(int level, long lastPos, int &tId)
651 {
652 tId=-1;
653 MWAWInputStreamPtr input=m_parserState->m_input;
654 long pos=input->tell();
655
656 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
657 libmwaw::DebugStream f;
658 PowerPoint7Struct::Zone header;
659 if (!header.read(input,lastPos) || header.m_type!=4002) {
660 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterProp: can not find the zone header\n"));
661 input->seek(pos, librevenge::RVNG_SEEK_SET);
662 return false;
663 }
664 f << "Entries(TextMasterProp)[container," << level << "]:" << header;
665 ascFile.addPos(pos);
666 ascFile.addNote(f.str().c_str());
667
668 long endPos=pos+16+header.m_dataSize;
669 int rId=-1;
670 while (input->tell()<endPos) {
671 pos=input->tell();
672 auto cType=int(input->readULong(2));
673 input->seek(pos, librevenge::RVNG_SEEK_SET);
674
675 bool done=false;
676 switch (cType) {
677 case 4003:
678 done=readTextMasterPropAtom(level+1,endPos);
679 break;
680 case 4021:
681 done=readRulerSetId(level+1,endPos,rId);
682 break;
683 case 4051:
684 done=readExternalHyperlinkAtom(level+1,endPos);
685 break;
686 case 4055:
687 done=readExternalHyperlinkData(level+1,endPos);
688 break;
689 case 4064: {
690 if (tId!=-1) {
691 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterProp: the text id is already set\n"));
692 }
693 done=readZone4064(level+1,endPos,rId,tId);
694 break;
695 }
696 default:
697 done=m_mainParser->readZone(level+1,endPos);
698 if (done) {
699 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterProp: find unexpected zone %d\n", cType));
700 }
701 break;
702 }
703 if (done) continue;
704 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterProp: can not read some data\n"));
705 ascFile.addPos(pos);
706 ascFile.addNote("MasterTextPropAtom:###extra");
707 input->seek(endPos, librevenge::RVNG_SEEK_SET);
708 break;
709 }
710 if (tId==-1) {
711 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterProp: can not find Zone4064\n"));
712 }
713 return true;
714 }
715
716 bool PowerPoint7Text::readTextMasterPropAtom(int level, long lastPos)
717 {
718 MWAWInputStreamPtr input=m_parserState->m_input;
719 long pos=input->tell();
720
721 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
722 libmwaw::DebugStream f;
723 PowerPoint7Struct::Zone header;
724 if (!header.read(input,lastPos) || header.m_type!=4003) {
725 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterPropAtom: can not find the zone header\n"));
726 input->seek(pos, librevenge::RVNG_SEEK_SET);
727 return false;
728 }
729 f << "Entries(TextMasterProp)[atom," << level << "]:" << header;
730 if (header.m_dataSize!=0x24) {
731 MWAW_DEBUG_MSG(("PowerPoint7Text::readTextMasterPropAtom: find unexpected data size\n"));
732 f << "###dataSz=" << header.m_dataSize << ",";
733 if (header.m_dataSize)
734 ascFile.addDelimiter(pos+16,'|');
735 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
736 ascFile.addPos(pos);
737 ascFile.addNote(f.str().c_str());
738 return true;
739 }
740
741 int val;
742 f << "unkn=[";
743 for (int i=0; i<6; ++i) { // f0=0-6
744 val=int(input->readULong(2));
745 if (val)
746 f << std::hex << val << std::dec << ",";
747 else
748 f << "_,";
749 }
750 f << "],";
751 for (int i=0; i<4; ++i) { // f0=-32768|-1680
752 val=int(input->readLong(2));
753 int const expected[]= {-32768,-1,0,0};
754 if (val!=expected[i])
755 f << "f" << i << "=" << val << ",";
756 }
757 int dim[4];
758 for (auto &d : dim) d=int(input->readLong(4));
759 f << "box=" << MWAWBox2i(MWAWVec2i(dim[0],dim[1]),MWAWVec2i(dim[2],dim[3])) << ",";
760 input->seek(pos+16+header.m_dataSize, librevenge::RVNG_SEEK_SET);
761 ascFile.addPos(pos);
762 ascFile.addNote(f.str().c_str());
763
764 return true;
765 }
766
767 bool PowerPoint7Text::readRulerSetId(int level, long lastPos,int &rId)
768 {
769 rId=-1;
770 MWAWInputStreamPtr input=m_parserState->m_input;
771 long pos=input->tell();
772
773 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
774 libmwaw::DebugStream f;
775 PowerPoint7Struct::Zone header;
776 if (!header.read(input,lastPos) || header.m_type!=4021) {
777 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerSetId: can not find the zone header\n"));
778 input->seek(pos, librevenge::RVNG_SEEK_SET);
779 return false;
780 }
781 f << "Entries(Ruler)[setId," << level << "]:" << header;
782 if (header.m_dataSize!=4) {
783 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerSetId: find unexpected data size\n"));
784 f << "###dataSz=" << header.m_dataSize << ",";
785 if (header.m_dataSize)
786 ascFile.addDelimiter(pos+16,'|');
787 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
788 }
789 else {
790 rId=int(input->readULong(4));
791 f << "R" << rId << ",";
792 }
793 ascFile.addPos(pos);
794 ascFile.addNote(f.str().c_str());
795 return true;
796 }
797
798 bool PowerPoint7Text::readFontContainer(int level, long lastPos, std::string &fName)
799 {
800 fName="";
801 MWAWInputStreamPtr input=m_parserState->m_input;
802 long pos=input->tell();
803
804 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
805 libmwaw::DebugStream f;
806 PowerPoint7Struct::Zone header;
807 if (!header.read(input,lastPos) || header.m_type!=4022) {
808 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontContainer: can not find the zone header\n"));
809 input->seek(pos, librevenge::RVNG_SEEK_SET);
810 return false;
811 }
812 f << "Entries(FontDef)[container," << level << "]:" << header;
813 ascFile.addPos(pos);
814 ascFile.addNote(f.str().c_str());
815
816 long endPos=pos+16+header.m_dataSize;
817 while (input->tell()<endPos) {
818 pos=input->tell();
819 auto cType=int(input->readULong(2));
820 input->seek(pos, librevenge::RVNG_SEEK_SET);
821
822 bool done=false;
823 switch (cType) {
824 case 4023:
825 done=readFont(level+1,endPos,fName);
826 break;
827 case 4024:
828 done=readFontEmbedded(level+1,endPos);
829 break;
830 default:
831 done=m_mainParser->readZone(level+1,endPos);
832 if (done) {
833 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontContainer: find unexpected zone %d\n", cType));
834 }
835 break;
836 }
837 if (done) continue;
838 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontContainer: can not read some data\n"));
839 ascFile.addPos(pos);
840 ascFile.addNote("FontDef:###extra");
841 input->seek(endPos, librevenge::RVNG_SEEK_SET);
842 break;
843 }
844 if (fName.empty()) {
845 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontContainer: can not find the font name\n"));
846 }
847 return true;
848 }
849
850 bool PowerPoint7Text::readFont(int level, long lastPos, std::string &fName)
851 {
852 fName="";
853 MWAWInputStreamPtr input=m_parserState->m_input;
854 long pos=input->tell();
855
856 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
857 libmwaw::DebugStream f;
858 PowerPoint7Struct::Zone header;
859 if (!header.read(input,lastPos) || header.m_type!=4023) {
860 MWAW_DEBUG_MSG(("PowerPoint7Text::readFont: can not find the zone header\n"));
861 input->seek(pos, librevenge::RVNG_SEEK_SET);
862 return false;
863 }
864 f << "Entries(FontDef)[atom," << level << "]:" << header;
865 if (header.m_dataSize!=0x3c) {
866 MWAW_DEBUG_MSG(("PowerPoint7Text::readFont: find unexpected data size\n"));
867 f << "###dataSz=" << header.m_dataSize << ",";
868 if (header.m_dataSize)
869 ascFile.addDelimiter(pos+16,'|');
870 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
871 ascFile.addPos(pos);
872 ascFile.addNote(f.str().c_str());
873 return true;
874 }
875
876 for (int i=0; i<14; ++i) { // f8=109|2bc,f10=0|ff|100,f11=0|200,f13=XX00
877 auto val=int(input->readLong(2));
878 if (val) f << "f" << i << "=" << val << ",";
879 }
880 for (int i=0; i<32; ++i) {
881 auto c=char(input->readULong(1));
882 if (!c) break;
883 fName+=c;
884 }
885 f << fName << ",";
886 input->seek(pos+16+header.m_dataSize, librevenge::RVNG_SEEK_SET);
887 ascFile.addPos(pos);
888 ascFile.addNote(f.str().c_str());
889
890 return true;
891 }
892 bool PowerPoint7Text::readFontEmbedded(int level, long lastPos)
893 {
894 MWAWInputStreamPtr input=m_parserState->m_input;
895 long pos=input->tell();
896
897 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
898 libmwaw::DebugStream f;
899 PowerPoint7Struct::Zone header;
900 if (!header.read(input,lastPos) || header.m_type!=4024) {
901 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontEmbedded: can not find the zone header\n"));
902 input->seek(pos, librevenge::RVNG_SEEK_SET);
903 return false;
904 }
905 f << "Entries(FontDef)[embedded," << level << "]:" << header;
906 static bool first=true;
907 if (first) {
908 first=false;
909 MWAW_DEBUG_MSG(("PowerPoint7Text::readFontEmbedded: reading embedded font is not implemented\n"));
910 }
911 if (header.m_dataSize)
912 ascFile.addDelimiter(pos+16,'|');
913 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
914 ascFile.addPos(pos);
915 ascFile.addNote(f.str().c_str());
916 return true;
917 }
918
919 bool PowerPoint7Text::readExternalHyperlinkAtom(int level, long lastPos)
920 {
921 MWAWInputStreamPtr input=m_parserState->m_input;
922 long pos=input->tell();
923
924 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
925 libmwaw::DebugStream f;
926 PowerPoint7Struct::Zone header;
927 if (!header.read(input,lastPos) || header.m_type!=4051) {
928 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlinkAtom: can not find the zone header\n"));
929 input->seek(pos, librevenge::RVNG_SEEK_SET);
930 return false;
931 }
932 f << "Entries(ExternalHyperlink)[atom," << level << "]:" << header;
933 if (header.m_dataSize!=12) {
934 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlinkAtom: find unexpected data size\n"));
935 f << "###dataSz=" << header.m_dataSize << ",";
936 if (header.m_dataSize)
937 ascFile.addDelimiter(pos+16,'|');
938 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
939 }
940 else {
941 for (int i=0; i<6; ++i) { // f0=1,f4=0|16
942 auto val=int(input->readULong(2));
943 if (val)
944 f << "f"<< i << "=" << val << ",";
945 }
946 }
947 ascFile.addPos(pos);
948 ascFile.addNote(f.str().c_str());
949 return true;
950 }
951
952 bool PowerPoint7Text::readExternalHyperlinkData(int level, long lastPos)
953 {
954 MWAWInputStreamPtr input=m_parserState->m_input;
955 long pos=input->tell();
956
957 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
958 libmwaw::DebugStream f;
959 PowerPoint7Struct::Zone header;
960 if (!header.read(input,lastPos) || header.m_type!=4055) {
961 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlinkData: can not find the zone header\n"));
962 input->seek(pos, librevenge::RVNG_SEEK_SET);
963 return false;
964 }
965 f << "Entries(ExternalHyperlink)[data," << level << "]:" << header;
966 if (header.m_dataSize!=8) {
967 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlinkData: find unexpected data size\n"));
968 f << "###dataSz=" << header.m_dataSize << ",";
969 if (header.m_dataSize)
970 ascFile.addDelimiter(pos+16,'|');
971 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
972 }
973 else {
974 for (int i=0; i<2; ++i) {
975 long val=input->readLong(4);
976 if (val)
977 f << "id"<< i << "=" << val << ",";
978 }
979 }
980 ascFile.addPos(pos);
981 ascFile.addNote(f.str().c_str());
982 return true;
983 }
984
985 bool PowerPoint7Text::readZone4064(int level, long lastPos, int rId, int &tId)
986 {
987 tId=-1;
988 MWAWInputStreamPtr input=m_parserState->m_input;
989 long pos=input->tell();
990
991 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
992 libmwaw::DebugStream f;
993 PowerPoint7Struct::Zone header;
994 if (!header.read(input,lastPos) || header.m_type!=4064) {
995 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4064: can not find the zone header\n"));
996 input->seek(pos, librevenge::RVNG_SEEK_SET);
997 return false;
998 }
999 f << "Entries(Zone4064B)[" << level << "]:" << header;
1000 ascFile.addPos(pos);
1001 ascFile.addNote(f.str().c_str());
1002
1003 long endPos=pos+16+header.m_dataSize;
1004 std::shared_ptr<PowerPoint7TextInternal::TextZone> zone(new PowerPoint7TextInternal::TextZone);
1005 zone->m_rulerId=rId;
1006 while (input->tell()<endPos) {
1007 pos=input->tell();
1008 auto cType=int(input->readULong(2));
1009 input->seek(pos, librevenge::RVNG_SEEK_SET);
1010
1011 bool done=false;
1012 switch (cType) {
1013 case 2028:
1014 done=readTextZoneContainer(level+1,endPos,*zone);
1015 break;
1016 case 2030:
1017 done=readTextZone(level+1,endPos,*zone);
1018 break;
1019 case 4013:
1020 done=m_mainParser->readZoneNoData(level+1,endPos,"Zone4064B","flags");
1021 break;
1022 case 4066:
1023 done=readZone4066(level+1,endPos);
1024 break;
1025 case 4067:
1026 done=readZone4067(level+1,endPos);
1027 break;
1028 default:
1029 done=m_mainParser->readZone(level+1,endPos);
1030 if (done) {
1031 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4064: find unexpected zone %d\n", cType));
1032 }
1033 break;
1034 }
1035 if (done) continue;
1036 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4064: can not read some data\n"));
1037 ascFile.addPos(pos);
1038 ascFile.addNote("Zone4064B:###extra");
1039 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1040 break;
1041 }
1042 if (!zone->isEmpty()) {
1043 tId=int(m_state->m_textZoneList.size());
1044 m_state->m_textZoneList.push_back(zone);
1045 }
1046 else
1047 tId=-2;
1048 return true;
1049 }
1050
1051 bool PowerPoint7Text::readZone4066(int level, long lastPos)
1052 {
1053 MWAWInputStreamPtr input=m_parserState->m_input;
1054 long pos=input->tell();
1055
1056 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1057 libmwaw::DebugStream f;
1058 PowerPoint7Struct::Zone header;
1059 if (!header.read(input,lastPos) || header.m_type!=4066) {
1060 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4066: can not find the zone header\n"));
1061 input->seek(pos, librevenge::RVNG_SEEK_SET);
1062 return false;
1063 }
1064 f << "Entries(Zone4066B)[" << level << "]:" << header;
1065 if (header.m_dataSize!=0x18) {
1066 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4066: find unexpected data size\n"));
1067 f << "###dataSz=" << header.m_dataSize << ",";
1068 if (header.m_dataSize)
1069 ascFile.addDelimiter(pos+16,'|');
1070 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
1071 ascFile.addPos(pos);
1072 ascFile.addNote(f.str().c_str());
1073 return true;
1074 }
1075
1076 int val;
1077 for (int i=0; i<6; ++i) { // f0=id?, f1=2, f2=fSz, f4=1|200
1078 val=int(input->readLong(2));
1079 if (val) f << "f" << i << "=" << val << ",";
1080 }
1081 for (int i=0; i<2; ++i) { // fl1=100|300, fl2=6200: color?
1082 val=int(input->readULong(2));
1083 if (val) f << "fl" << i << "=" << std::hex << val << std::dec << ",";
1084 }
1085 for (int i=0; i<4; ++i) { // 0
1086 val=int(input->readLong(2));
1087 if (val) f << "f" << i+4 << "=" << val << ",";
1088 }
1089 input->seek(pos+16+header.m_dataSize, librevenge::RVNG_SEEK_SET);
1090 ascFile.addPos(pos);
1091 ascFile.addNote(f.str().c_str());
1092 return true;
1093 }
1094
1095 bool PowerPoint7Text::readZone4067(int level, long lastPos)
1096 {
1097 MWAWInputStreamPtr input=m_parserState->m_input;
1098 long pos=input->tell();
1099
1100 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1101 libmwaw::DebugStream f;
1102 PowerPoint7Struct::Zone header;
1103 if (!header.read(input,lastPos) || header.m_type!=4067) {
1104 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4067: can not find the zone header\n"));
1105 input->seek(pos, librevenge::RVNG_SEEK_SET);
1106 return false;
1107 }
1108 f << "Entries(Zone4067B)[" << level << "]:" << header;
1109 if (header.m_dataSize!=0x34) {
1110 MWAW_DEBUG_MSG(("PowerPoint7Text::readZone4067: find unexpected data size\n"));
1111 f << "###dataSz=" << header.m_dataSize << ",";
1112 if (header.m_dataSize)
1113 ascFile.addDelimiter(pos+16,'|');
1114 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
1115 ascFile.addPos(pos);
1116 ascFile.addNote(f.str().c_str());
1117 return true;
1118 }
1119
1120 int val;
1121 for (int i=0; i<2; ++i) {
1122 val=int(input->readULong(1));
1123 if (val)
1124 f << "fl" << i << "=" << std::hex << val << std::dec << ",";
1125 }
1126 for (int i=0; i<11; ++i) {
1127 val=int(input->readLong(2));
1128 int const expected[]= {0,-768,0x95,-1,2,100,0,0,0,0,0};
1129 if (val!=expected[i])
1130 f << "f" << i << "=" << val << ",";
1131 }
1132 for (int i=0; i<14; ++i) {
1133 val=int(input->readLong(2));
1134 if (val) f << "f" << i << "=" << val << ",";
1135 }
1136 input->seek(pos+16+header.m_dataSize, librevenge::RVNG_SEEK_SET);
1137 ascFile.addPos(pos);
1138 ascFile.addNote(f.str().c_str());
1139 return true;
1140 }
1141
1142 bool PowerPoint7Text::readExternalHyperlink9(int level, long lastPos, int &tId)
1143 {
1144 tId=-1;
1145 MWAWInputStreamPtr input=m_parserState->m_input;
1146 long pos=input->tell();
1147
1148 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1149 libmwaw::DebugStream f;
1150 PowerPoint7Struct::Zone header;
1151 if (!header.read(input,lastPos) || header.m_type!=4068) {
1152 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlink9: can not find the zone header\n"));
1153 input->seek(pos, librevenge::RVNG_SEEK_SET);
1154 return false;
1155 }
1156 f << "Entries(ExternalHyperlnk9)[" << level << "]:" << header;
1157 ascFile.addPos(pos);
1158 ascFile.addNote(f.str().c_str());
1159
1160 long endPos=pos+16+header.m_dataSize;
1161 int rId=-1;
1162 while (input->tell()<endPos) {
1163 pos=input->tell();
1164 auto cType=int(input->readULong(2));
1165 input->seek(pos, librevenge::RVNG_SEEK_SET);
1166
1167 bool done=false;
1168 switch (cType) {
1169 case 4003:
1170 done=readTextMasterPropAtom(level+1,endPos);
1171 break;
1172 case 4021:
1173 done=readRulerSetId(level+1,endPos,rId);
1174 break;
1175 case 4064:
1176 if (tId!=-1) {
1177 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlink9: find a duplicated Zone4064\n"));
1178 }
1179 done=readZone4064(level+1,endPos,rId,tId);
1180 break;
1181 default:
1182 done=m_mainParser->readZone(level+1,endPos);
1183 if (done) {
1184 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlink9: find unexpected zone %d\n", cType));
1185 }
1186 break;
1187 }
1188 if (done) continue;
1189 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlink9: can not read some data\n"));
1190 ascFile.addPos(pos);
1191 ascFile.addNote("ExternalHyperlink9:###extra");
1192 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1193 break;
1194 }
1195 if (tId==-1) {
1196 MWAW_DEBUG_MSG(("PowerPoint7Text::readExternalHyperlink9: can not find Zone4064\n"));
1197 }
1198 return true;
1199 }
1200
1201 bool PowerPoint7Text::readRulerList(int level, long lastPos)
1202 {
1203 MWAWInputStreamPtr input=m_parserState->m_input;
1204 long pos=input->tell();
1205
1206 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1207 libmwaw::DebugStream f;
1208 PowerPoint7Struct::Zone header;
1209 if (!header.read(input,lastPos) || header.m_type!=4016) {
1210 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerList: can not find the zone header\n"));
1211 input->seek(pos, librevenge::RVNG_SEEK_SET);
1212 return false;
1213 }
1214 f << "Entries(Ruler)[list," << level << "]:" << header;
1215 ascFile.addPos(pos);
1216 ascFile.addNote(f.str().c_str());
1217
1218 long endPos=pos+16+header.m_dataSize;
1219 PowerPoint7TextInternal::Ruler ruler;
1220 while (input->tell()<endPos) {
1221 pos=input->tell();
1222 auto cType=int(input->readULong(2));
1223 input->seek(pos, librevenge::RVNG_SEEK_SET);
1224
1225 bool done=false;
1226 switch (cType) {
1227 case 2017: {
1228 int id;
1229 done=m_mainParser->readIdentifier(level+1,endPos,id,"Ruler");
1230 if (!done) break;
1231 if (m_state->m_idToRulerMap.find(id)!=m_state->m_idToRulerMap.end()) {
1232 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerList: find dupplicated id\n"));
1233 }
1234 else
1235 m_state->m_idToRulerMap[id]=ruler;
1236 ruler=PowerPoint7TextInternal::Ruler();
1237 break;
1238 }
1239 case 2018:
1240 done=m_mainParser->readZoneNoData(level+1,endPos,"Ruler","id,end");
1241 break;
1242 case 4043:
1243 done=m_mainParser->readZoneNoData(level+1,endPos,"Ruler","flags"); // flags?
1244 break;
1245 case 4069:
1246 done=readRulerContainer(level+1,endPos,ruler);
1247 break;
1248 default:
1249 done=m_mainParser->readZone(level+1,endPos);
1250 if (done) {
1251 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerList: find unexpected zone %d\n", cType));
1252 }
1253 break;
1254 }
1255 if (done) continue;
1256 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerList: can not read some data\n"));
1257 ascFile.addPos(pos);
1258 ascFile.addNote("Ruler:###extra");
1259 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1260 break;
1261 }
1262 return true;
1263 }
1264
1265 bool PowerPoint7Text::readRuler(int level, long lastPos, PowerPoint7TextInternal::Ruler &ruler)
1266 {
1267 MWAWInputStreamPtr input=m_parserState->m_input;
1268 long pos=input->tell();
1269
1270 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1271 libmwaw::DebugStream f;
1272 PowerPoint7Struct::Zone header;
1273 if (!header.read(input,lastPos) || header.m_type!=4019) {
1274 MWAW_DEBUG_MSG(("PowerPoint7Text::readRuler: can not find the zone header\n"));
1275 input->seek(pos, librevenge::RVNG_SEEK_SET);
1276 return false;
1277 }
1278 f << "Entries(Ruler)[" << level << "]:" << header;
1279 if (header.m_dataSize!=0x34) {
1280 MWAW_DEBUG_MSG(("PowerPoint7Text::readRuler: find unexpected data size\n"));
1281 f << "###dataSz=" << header.m_dataSize << ",";
1282 if (header.m_dataSize)
1283 ascFile.addDelimiter(pos+16,'|');
1284 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
1285 ascFile.addPos(pos);
1286 ascFile.addNote(f.str().c_str());
1287 return true;
1288 }
1289 f << "margins=[";
1290 for (auto &margin : ruler.m_margins) {
1291 margin=int(input->readLong(4));
1292 f << margin << ",";
1293 }
1294 f << "],";
1295 for (int i=0; i<6; ++i) {
1296 auto val=int(input->readLong(2));
1297 int const expected[]= {3,0,576,0,0,0};
1298 if (val==expected[i]) continue;
1299 if (i==4)
1300 f << "num[ruler]=" << val << ",";
1301 else
1302 f << "f" << i << "=" << val << ",";
1303 }
1304 input->seek(pos+16+header.m_dataSize, librevenge::RVNG_SEEK_SET);
1305 ascFile.addPos(pos);
1306 ascFile.addNote(f.str().c_str());
1307
1308 return true;
1309 }
1310
1311 bool PowerPoint7Text::readRulerContainer(int level, long lastPos, PowerPoint7TextInternal::Ruler &ruler)
1312 {
1313 ruler=PowerPoint7TextInternal::Ruler();
1314 MWAWInputStreamPtr input=m_parserState->m_input;
1315 long pos=input->tell();
1316
1317 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1318 libmwaw::DebugStream f;
1319 PowerPoint7Struct::Zone header;
1320 if (!header.read(input,lastPos) || header.m_type!=4069) {
1321 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerContainer: can not find the zone header\n"));
1322 input->seek(pos, librevenge::RVNG_SEEK_SET);
1323 return false;
1324 }
1325 f << "Entries(Ruler)[container," << level << "]:" << header;
1326 ascFile.addPos(pos);
1327 ascFile.addNote(f.str().c_str());
1328
1329 long endPos=pos+16+header.m_dataSize;
1330 while (input->tell()<endPos) {
1331 pos=input->tell();
1332 auto cType=int(input->readULong(2));
1333 input->seek(pos, librevenge::RVNG_SEEK_SET);
1334
1335 bool done=false;
1336 switch (cType) {
1337 case 4019:
1338 done=readRuler(level+1,endPos,ruler);
1339 break;
1340 case 4070:
1341 done=readRulerTabs(level+1,endPos,ruler);
1342 break;
1343 default:
1344 done=m_mainParser->readZone(level+1,endPos);
1345 if (done) {
1346 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerContainer: find unexpected zone %d\n", cType));
1347 }
1348 break;
1349 }
1350 if (done) continue;
1351 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerContainer: can not read some data\n"));
1352 ascFile.addPos(pos);
1353 ascFile.addNote("Ruler:###extra");
1354 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1355 break;
1356 }
1357 return true;
1358 }
1359
1360 bool PowerPoint7Text::readRulerTabs(int level, long lastPos, PowerPoint7TextInternal::Ruler &ruler)
1361 {
1362 MWAWInputStreamPtr input=m_parserState->m_input;
1363 long pos=input->tell();
1364
1365 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1366 libmwaw::DebugStream f;
1367 PowerPoint7Struct::Zone header;
1368 if (!header.read(input,lastPos) || header.m_type!=4070) {
1369 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerTabs: can not find the zone header\n"));
1370 input->seek(pos, librevenge::RVNG_SEEK_SET);
1371 return false;
1372 }
1373 f << "Entries(Ruler)[tabs," << level << "]:" << header;
1374 if (header.m_dataSize%8) {
1375 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerTabs: find unexpected data size\n"));
1376 f << "###dataSz=" << header.m_dataSize << ",";
1377 if (header.m_dataSize)
1378 ascFile.addDelimiter(pos+16,'|');
1379 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
1380 ascFile.addPos(pos);
1381 ascFile.addNote(f.str().c_str());
1382 return true;
1383 }
1384
1385 auto N=int(header.m_dataSize/8);
1386 f << "tabs=[";
1387 for (int i=0; i<N; ++i) {
1388 MWAWTabStop tab;
1389 tab.m_position=double(input->readLong(4))/8./72.;
1390 auto val=int(input->readLong(4));
1391 switch (val) {
1392 case 0:
1393 tab.m_alignment=MWAWTabStop::DECIMAL;
1394 break;
1395 case 1:
1396 tab.m_alignment=MWAWTabStop::RIGHT;
1397 break;
1398 case 2:
1399 tab.m_alignment=MWAWTabStop::CENTER;
1400 break;
1401 case 3: // left
1402 break;
1403 default:
1404 MWAW_DEBUG_MSG(("PowerPoint7Text::readRulerTabs: find unknown tab position\n"));
1405 f << "##tab" << i << "=" << val << ",";
1406 break;
1407 }
1408 f << tab << ",";
1409 ruler.m_paragraph.m_tabs->push_back(tab);
1410 }
1411 f << "],";
1412 input->seek(pos+16+header.m_dataSize, librevenge::RVNG_SEEK_SET);
1413 ascFile.addPos(pos);
1414 ascFile.addNote(f.str().c_str());
1415 return true;
1416 }
1417
1418 bool PowerPoint7Text::readFieldList(int level, long lastPos)
1419 {
1420 MWAWInputStreamPtr input=m_parserState->m_input;
1421 long pos=input->tell();
1422
1423 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1424 libmwaw::DebugStream f;
1425 PowerPoint7Struct::Zone header;
1426 if (!header.read(input,lastPos) || header.m_type!=2027) {
1427 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldList: can not find the zone header\n"));
1428 input->seek(pos, librevenge::RVNG_SEEK_SET);
1429 return false;
1430 }
1431 f << "Entries(Field)[list" << level << "]:" << header;
1432 ascFile.addPos(pos);
1433 ascFile.addNote(f.str().c_str());
1434
1435 long endPos=pos+16+header.m_dataSize;
1436 int format=-1;
1437 while (input->tell()<endPos) {
1438 pos=input->tell();
1439 auto cType=int(input->readULong(2));
1440 input->seek(pos, librevenge::RVNG_SEEK_SET);
1441
1442 bool done=false;
1443 switch (cType) {
1444 case 2017: {
1445 int id;
1446 done=m_mainParser->readIdentifier(level+1,endPos,id,"Field");
1447 if (!done || format==-1) break;
1448 if (m_state->m_fieldIdToFormatIdMap.find(id)!=m_state->m_fieldIdToFormatIdMap.end()) {
1449 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldList: can not store field %d\n", id));
1450 }
1451 else
1452 m_state->m_fieldIdToFormatIdMap[id]=format;
1453 format=-1;
1454 break;
1455 }
1456 case 2018:
1457 done=m_mainParser->readZoneNoData(level+1,endPos,"Field","id,end");
1458 break;
1459 case 4056:
1460 if (format!=-1) {
1461 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldList: find unused format %d\n", format));
1462 }
1463 done=readFieldDef(level+1,endPos,format);
1464 break;
1465 default:
1466 done=m_mainParser->readZone(level+1,endPos);
1467 if (done) {
1468 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldList: find unexpected zone %d\n", cType));
1469 }
1470 break;
1471 }
1472 if (done) continue;
1473 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldList: can not read some data\n"));
1474 ascFile.addPos(pos);
1475 ascFile.addNote("Field:###extra");
1476 input->seek(endPos, librevenge::RVNG_SEEK_SET);
1477 break;
1478 }
1479 return true;
1480 }
1481
1482 bool PowerPoint7Text::readFieldDef(int level, long lastPos, int &format)
1483 {
1484 format=-1;
1485 MWAWInputStreamPtr input=m_parserState->m_input;
1486 long pos=input->tell();
1487
1488 libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile;
1489 libmwaw::DebugStream f;
1490 PowerPoint7Struct::Zone header;
1491 if (!header.read(input,lastPos) || header.m_type!=4056) {
1492 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldDef: can not find the zone header\n"));
1493 input->seek(pos, librevenge::RVNG_SEEK_SET);
1494 return false;
1495 }
1496 f << "Entries(Field)[def," << level << "]:" << header;
1497 if (header.m_dataSize!=2) {
1498 MWAW_DEBUG_MSG(("PowerPoint7Text::readFieldDef: find unexpected data size\n"));
1499 f << "###dataSz=" << header.m_dataSize << ",";
1500 if (header.m_dataSize)
1501 ascFile.addDelimiter(pos+16,'|');
1502 input->seek(header.m_dataSize, librevenge::RVNG_SEEK_CUR);
1503 }
1504 else {
1505 format=int(input->readULong(2));
1506 if (format>=0 && format<=16) {
1507 char const *wh[]= {
1508 "title,", "%m/%d/%y", "%A, %d %B, %Y", "%d %B, %Y", "%B %d, %Y",
1509 "%d-%b-%y","%B, %y","%m-%y","%m/%d/%y %H:%M","%m/%d/%y %I:%M:%S %p",
1510 "%H:%M", "%H:%M:%S", "%I:%M %p", "%I:%M:%S %p", "header",
1511 "footer", "page[number]"
1512 };
1513 f << wh[format] << ",";
1514 }
1515 else
1516 f << "##FS" << format << ",";
1517 }
1518 ascFile.addPos(pos);
1519 ascFile.addNote(f.str().c_str());
1520 return true;
1521 }
1522
1523 ////////////////////////////////////////////////////////////
1524 // send data
1525 ////////////////////////////////////////////////////////////
1526 bool PowerPoint7Text::sendText(int textId)
1527 {
1528 MWAWListenerPtr listener=m_parserState->m_presentationListener;
1529 if (!listener) {
1530 MWAW_DEBUG_MSG(("PowerPoint7Text::sendText: can not find the listener\n"));
1531 return false;
1532 }
1533 if (textId<0 || textId>=int(m_state->m_textZoneList.size()) || !m_state->m_textZoneList[size_t(textId)]) {
1534 MWAW_DEBUG_MSG(("PowerPoint7Text::sendText: can not find the text zone %d\n", textId));
1535 return false;
1536 }
1537 PowerPoint7TextInternal::TextZone const &zone=*m_state->m_textZoneList[size_t(textId)];
1538 if (!zone.m_textEntry.valid())
1539 return true;
1540 MWAWInputStreamPtr input=m_parserState->m_input;
1541 input->seek(zone.m_textEntry.begin(), librevenge::RVNG_SEEK_SET);
1542 long endPos=zone.m_textEntry.end();
1543 int fId=m_parserState->m_fontConverter->getId(m_state->m_fontFamily.c_str());
1544 MWAWFont font;
1545 font.setId(fId);
1546 listener->setFont(font);
1547 long actPosC=0;
1548 while (!input->isEnd()) {
1549 if (input->tell()>=endPos) break;
1550 auto c=static_cast<unsigned char>(input->readULong(1));
1551 if (zone.m_posToRulerMap.find(actPosC)!=zone.m_posToRulerMap.end())
1552 listener->setParagraph(zone.m_posToRulerMap.find(actPosC)->second.m_paragraph);
1553 if (zone.m_posToFontMap.find(actPosC)!=zone.m_posToFontMap.end())
1554 listener->setFont(zone.m_posToFontMap.find(actPosC)->second);
1555 if (zone.m_posToFieldFormatMap.find(actPosC)!=zone.m_posToFieldFormatMap.end()) {
1556 if (c!='*') {
1557 MWAW_DEBUG_MSG(("PowerPoint7Text::sendText: find odd character for char %d\n", int(c)));
1558 }
1559 int format=zone.m_posToFieldFormatMap.find(actPosC)->second;
1560 if (format==16)
1561 listener->insertField(MWAWField(MWAWField::PageNumber));
1562 else if (format>=1 && format<=13) {
1563 char const *wh[]= {
1564 "", "%m/%d/%y", "%A, %d %B, %Y", "%d %B, %Y", "%B %d, %Y",
1565 "%d-%b-%y","%B, %y","%m-%y","%m/%d/%y %H:%M","%m/%d/%y %I:%M:%S %p",
1566 "%H:%M", "%H:%M:%S", "%I:%M %p", "%I:%M:%S %p"
1567 };
1568 MWAWField field(format<=9 ? MWAWField::Date : MWAWField::Time);
1569 field.m_DTFormat = wh[format];
1570 listener->insertField(field);
1571 }
1572 else {
1573 MWAW_DEBUG_MSG(("PowerPoint7Text::sendText: unsure how to insert format %d\n", format));
1574 listener->insertCharacter('#');
1575 }
1576 ++actPosC;
1577 continue;
1578 }
1579 ++actPosC;
1580 switch (c) {
1581 case 0x9:
1582 listener->insertTab();
1583 break;
1584 case 0xb:
1585 case 0xd:
1586 listener->insertEOL(c==0xb);
1587 break;
1588 case 0x11: // command key
1589 listener->insertUnicode(0x2318);
1590 break;
1591 default:
1592 listener->insertCharacter(c);
1593 break;
1594 }
1595 }
1596 return true;
1597 }
1598 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: