1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libstaroffice
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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 "STOFFParagraph.hxx"
35 #include "STOFFPageSpan.hxx"
36
37 #include "StarAttribute.hxx"
38 #include "StarBitmap.hxx"
39 #include "StarFormatManager.hxx"
40 #include "StarItemPool.hxx"
41 #include "StarObject.hxx"
42 #include "StarObjectNumericRuler.hxx"
43 #include "StarState.hxx"
44 #include "StarZone.hxx"
45
46 #include "StarParagraphAttribute.hxx"
47
48 namespace StarParagraphAttribute
49 {
50 //! a character bool attribute
51 class StarPAttributeBool final : public StarAttributeBool
52 {
53 public:
54 //! constructor
StarPAttributeBool(Type type,std::string const & debugName,bool value)55 StarPAttributeBool(Type type, std::string const &debugName, bool value)
56 : StarAttributeBool(type, debugName, value)
57 {
58 }
59 //! destructor
60 ~StarPAttributeBool() final;
61 //! create a new attribute
create() const62 std::shared_ptr<StarAttribute> create() const final
63 {
64 return std::shared_ptr<StarAttribute>(new StarPAttributeBool(*this));
65 }
66 //! add to a para
67 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
68
69 protected:
70 //! copy constructor
71 StarPAttributeBool(StarPAttributeBool const &) = default;
72 };
73
~StarPAttributeBool()74 StarPAttributeBool::~StarPAttributeBool()
75 {
76 }
77
78 //! a character color attribute
79 class StarPAttributeColor final : public StarAttributeColor
80 {
81 public:
82 //! constructor
StarPAttributeColor(Type type,std::string const & debugName,STOFFColor const & value)83 StarPAttributeColor(Type type, std::string const &debugName, STOFFColor const &value)
84 : StarAttributeColor(type, debugName, value)
85 {
86 }
87 //! destructor
88 ~StarPAttributeColor() final;
89 //! create a new attribute
create() const90 std::shared_ptr<StarAttribute> create() const final
91 {
92 return std::shared_ptr<StarAttribute>(new StarPAttributeColor(*this));
93 }
94 //! add to a para
95 // void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
96 protected:
97 //! copy constructor
98 StarPAttributeColor(StarPAttributeColor const &) = default;
99 };
100
~StarPAttributeColor()101 StarPAttributeColor::~StarPAttributeColor()
102 {
103 }
104 //! a character integer attribute
105 class StarPAttributeInt final : public StarAttributeInt
106 {
107 public:
108 //! constructor
StarPAttributeInt(Type type,std::string const & debugName,int intSize,int value)109 StarPAttributeInt(Type type, std::string const &debugName, int intSize, int value)
110 : StarAttributeInt(type, debugName, intSize, value)
111 {
112 }
113 //! destructor
114 ~StarPAttributeInt() final;
115 //! add to a para
116 // void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
117 //! create a new attribute
create() const118 std::shared_ptr<StarAttribute> create() const final
119 {
120 return std::shared_ptr<StarAttribute>(new StarPAttributeInt(*this));
121 }
122 protected:
123 //! copy constructor
124 StarPAttributeInt(StarPAttributeInt const &) = default;
125 };
126
~StarPAttributeInt()127 StarPAttributeInt::~StarPAttributeInt()
128 {
129 }
130
131 //! a character unsigned integer attribute
132 class StarPAttributeUInt final : public StarAttributeUInt
133 {
134 public:
135 //! constructor
StarPAttributeUInt(Type type,std::string const & debugName,int intSize,unsigned int value)136 StarPAttributeUInt(Type type, std::string const &debugName, int intSize, unsigned int value)
137 : StarAttributeUInt(type, debugName, intSize, value)
138 {
139 }
140 //! destructor
141 ~StarPAttributeUInt() final;
142 //! create a new attribute
create() const143 std::shared_ptr<StarAttribute> create() const final
144 {
145 return std::shared_ptr<StarAttribute>(new StarPAttributeUInt(*this));
146 }
147 //! read a zone
read(StarZone & zone,int vers,long endPos,StarObject & object)148 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final
149 {
150 STOFFInputStreamPtr input=zone.input();
151 long pos=input->tell();
152 if (pos+2==endPos && m_intSize==1 && (m_type==ATTR_PARA_WIDOWS || m_type==ATTR_PARA_ORPHANS)) {
153 // unsure, sometimes, I found an extra byte
154 libstoff::DebugFile &ascFile=zone.ascii();
155 libstoff::DebugStream f;
156 m_value=static_cast<unsigned int>(input->readULong(1));
157 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:" << m_debugName << "=" << m_value << ",";
158 auto tmp=int(input->readULong(1));
159 if (tmp) f << "#unkn=" << tmp << ",";
160 ascFile.addPos(pos);
161 ascFile.addNote(f.str().c_str());
162 return input->tell()<=endPos;
163 }
164 return StarAttributeUInt::read(zone, vers, endPos, object);
165 }
166 //! add to a para
167 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
168 protected:
169 //! copy constructor
170 StarPAttributeUInt(StarPAttributeUInt const &) = default;
171 };
172
~StarPAttributeUInt()173 StarPAttributeUInt::~StarPAttributeUInt()
174 {
175 }
176 //! a void attribute
177 class StarPAttributeVoid final : public StarAttributeVoid
178 {
179 public:
180 //! constructor
StarPAttributeVoid(Type type,std::string const & debugName)181 StarPAttributeVoid(Type type, std::string const &debugName)
182 : StarAttributeVoid(type, debugName)
183 {
184 }
185 //! destructor
186 ~StarPAttributeVoid() final;
187 //! add to a para
188 // void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
189 //! create a new attribute
create() const190 std::shared_ptr<StarAttribute> create() const final
191 {
192 return std::shared_ptr<StarAttribute>(new StarPAttributeVoid(*this));
193 }
194 protected:
195 //! copy constructor
196 StarPAttributeVoid(StarPAttributeVoid const &) = default;
197 };
198
~StarPAttributeVoid()199 StarPAttributeVoid::~StarPAttributeVoid()
200 {
201 }
202
addTo(StarState & state,std::set<StarAttribute const * > &) const203 void StarPAttributeBool::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
204 {
205 if (m_type==ATTR_PARA_SPLIT)
206 state.m_paragraph.m_propertyList.insert("fo:keep-together", m_value ? "auto" : "always");
207 else if (m_type==ATTR_PARA_HANGINGPUNCTUATION)
208 state.m_paragraph.m_propertyList.insert("style:punctuation-wrap", m_value ? "hanging" : "simple");
209 else if (m_type==ATTR_PARA_SNAPTOGRID)
210 state.m_paragraph.m_propertyList.insert("style:snap-to-layout-grid", m_value);
211 else if (m_type==ATTR_PARA_CONNECT_BORDER)
212 state.m_paragraph.m_propertyList.insert("style:join-border", m_value);
213 else if (m_type==ATTR_EE_PARA_ASIANCJKSPACING)
214 state.m_paragraph.m_propertyList.insert("style:font-independent-line-spacing", !m_value);
215 }
216
addTo(StarState & state,std::set<StarAttribute const * > &) const217 void StarPAttributeUInt::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
218 {
219 if (m_type==ATTR_PARA_ORPHANS)
220 state.m_paragraph.m_propertyList.insert("fo:orphans", int(m_value));
221 else if (m_type==ATTR_PARA_WIDOWS)
222 state.m_paragraph.m_propertyList.insert("fo:widows", int(m_value));
223 else if (m_type==ATTR_PARA_VERTALIGN) {
224 if (m_value<=4) {
225 char const *wh[]= {"auto", "baseline", "top", "middle", "bottom"};
226 state.m_paragraph.m_propertyList.insert("style:vertical-align", wh[m_value]);
227 }
228 else {
229 STOFF_DEBUG_MSG(("StarPAttributeUInt::addTo: unknown vertical align %d\n", int(m_value)));
230 }
231 }
232 else if (m_type==ATTR_EE_PARA_BULLETSTATE)
233 state.m_paragraph.m_bulletVisible=m_value!=0;
234 else if (m_type==ATTR_EE_PARA_OUTLLEVEL)
235 state.m_paragraph.m_listLevelIndex=int(m_value);
236 }
237
238 //! add a bool attribute
addAttributeBool(std::map<int,std::shared_ptr<StarAttribute>> & map,StarAttribute::Type type,std::string const & debugName,bool defValue)239 inline void addAttributeBool(std::map<int, std::shared_ptr<StarAttribute> > &map, StarAttribute::Type type, std::string const &debugName, bool defValue)
240 {
241 map[type]=std::shared_ptr<StarAttribute>(new StarPAttributeBool(type,debugName, defValue));
242 }
243 //! add a color attribute
addAttributeColor(std::map<int,std::shared_ptr<StarAttribute>> & map,StarAttribute::Type type,std::string const & debugName,STOFFColor const & defValue)244 inline void addAttributeColor(std::map<int, std::shared_ptr<StarAttribute> > &map, StarAttribute::Type type, std::string const &debugName, STOFFColor const &defValue)
245 {
246 map[type]=std::shared_ptr<StarAttribute>(new StarPAttributeColor(type,debugName, defValue));
247 }
248 //! add a int attribute
addAttributeInt(std::map<int,std::shared_ptr<StarAttribute>> & map,StarAttribute::Type type,std::string const & debugName,int numBytes,int defValue)249 inline void addAttributeInt(std::map<int, std::shared_ptr<StarAttribute> > &map, StarAttribute::Type type, std::string const &debugName, int numBytes, int defValue)
250 {
251 map[type]=std::shared_ptr<StarAttribute>(new StarPAttributeInt(type,debugName, numBytes, defValue));
252 }
253 //! add a unsigned int attribute
addAttributeUInt(std::map<int,std::shared_ptr<StarAttribute>> & map,StarAttribute::Type type,std::string const & debugName,int numBytes,unsigned int defValue)254 inline void addAttributeUInt(std::map<int, std::shared_ptr<StarAttribute> > &map, StarAttribute::Type type, std::string const &debugName, int numBytes, unsigned int defValue)
255 {
256 map[type]=std::shared_ptr<StarAttribute>(new StarPAttributeUInt(type,debugName, numBytes, defValue));
257 }
258 //! add a void attribute
addAttributeVoid(std::map<int,std::shared_ptr<StarAttribute>> & map,StarAttribute::Type type,std::string const & debugName)259 inline void addAttributeVoid(std::map<int, std::shared_ptr<StarAttribute> > &map, StarAttribute::Type type, std::string const &debugName)
260 {
261 map[type]=std::shared_ptr<StarAttribute>(new StarPAttributeVoid(type,debugName));
262 }
263
264 }
265
266 namespace StarParagraphAttribute
267 {
268 // ------------------------------------------------------------
269 //! a adjust attribute
270 class StarPAttributeAdjust final : public StarAttribute
271 {
272 public:
273 //! constructor
StarPAttributeAdjust(Type type,std::string const & debugName)274 StarPAttributeAdjust(Type type, std::string const &debugName)
275 : StarAttribute(type, debugName)
276 , m_adjust(0)
277 , m_flags(0)
278 {
279 }
280 //! create a new attribute
create() const281 std::shared_ptr<StarAttribute> create() const final
282 {
283 return std::shared_ptr<StarAttribute>(new StarPAttributeAdjust(*this));
284 }
285 //! read a zone
286 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
287 //! add to a para
288 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
289 //! debug function to print the data
printData(libstoff::DebugStream & o) const290 void printData(libstoff::DebugStream &o) const final
291 {
292 o << m_debugName << "=[";
293 if (m_adjust) o << "adjust=" << m_adjust << ",";
294 if (m_flags) o << "flags=" << std::hex << m_flags << std::dec << ",";
295 o << "],";
296 }
297 protected:
298 //! copy constructor
299 StarPAttributeAdjust(StarPAttributeAdjust const &) = default;
300 //! the adjust value
301 int m_adjust;
302 //! the flags
303 int m_flags;
304 };
305
306 // ------------------------------------------------------------
307 //! a numeric bullet attribute
308 class StarPAttributeBulletNumeric final : public StarAttribute
309 {
310 public:
311 //! constructor
StarPAttributeBulletNumeric(Type type,std::string const & debugName)312 StarPAttributeBulletNumeric(Type type, std::string const &debugName)
313 : StarAttribute(type, debugName)
314 , m_numType(0)
315 , m_numLevels(0)
316 , m_flags(0)
317 , m_continuous(true)
318 {
319 }
320 //! create a new attribute
create() const321 std::shared_ptr<StarAttribute> create() const final
322 {
323 return std::shared_ptr<StarAttribute>(new StarPAttributeBulletNumeric(*this));
324 }
325 //! read a zone
326 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
327 //! add to a para
328 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
329 //! debug function to print the data
printData(libstoff::DebugStream & o) const330 void printData(libstoff::DebugStream &o) const final
331 {
332 o << m_debugName << "=[";
333 if (m_numType) o << "type=" << m_numType << ",";
334 if (m_numLevels) o << "numLevels=" << m_numLevels << ",";
335 if (m_flags) o << "flags=" << std::hex << m_flags << std::dec << ",";
336 if (!m_continuous) o << "continuous*,";
337 o << "],";
338 }
339 protected:
340 //! copy constructor
341 StarPAttributeBulletNumeric(StarPAttributeBulletNumeric const &) = default;
342 //! the type
343 int m_numType;
344 //! the numLevels
345 int m_numLevels;
346 //! the flags
347 int m_flags;
348 //! a continuous flag
349 bool m_continuous;
350 };
351
352 // ------------------------------------------------------------
353 //! a simple bullet attribute
354 class StarPAttributeBulletSimple final : public StarAttribute
355 {
356 public:
357 //! constructor
StarPAttributeBulletSimple(Type type,std::string const & debugName)358 StarPAttributeBulletSimple(Type type, std::string const &debugName)
359 : StarAttribute(type, debugName)
360 , m_level()
361 {
362 }
363 //! create a new attribute
create() const364 std::shared_ptr<StarAttribute> create() const final
365 {
366 return std::shared_ptr<StarAttribute>(new StarPAttributeBulletSimple(*this));
367 }
368 //! read a zone
369 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
370 //! add to a para
371 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
372 //! debug function to print the data
printData(libstoff::DebugStream & o) const373 void printData(libstoff::DebugStream &o) const final
374 {
375 o << m_debugName;
376 }
377 protected:
378 //! copy constructor
379 StarPAttributeBulletSimple(StarPAttributeBulletSimple const &) = default;
380 //! the level
381 STOFFListLevel m_level;
382 };
383
384 //! a drop attribute
385 class StarPAttributeDrop final : public StarAttribute
386 {
387 public:
388 //! constructor
StarPAttributeDrop(Type type,std::string const & debugName)389 StarPAttributeDrop(Type type, std::string const &debugName)
390 : StarAttribute(type, debugName)
391 , m_numFormats(0)
392 , m_numLines(0)
393 , m_numChars(0)
394 , m_numDistances(0)
395 , m_whole(false)
396 , m_numX(0)
397 , m_numY(0)
398 {
399 }
400 //! create a new attribute
create() const401 std::shared_ptr<StarAttribute> create() const final
402 {
403 return std::shared_ptr<StarAttribute>(new StarPAttributeDrop(*this));
404 }
405 //! read a zone
406 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
407 //! add to a para
408 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
409 //! debug function to print the data
printData(libstoff::DebugStream & o) const410 void printData(libstoff::DebugStream &o) const final
411 {
412 o << m_debugName << "=[";
413 if (m_numFormats!=0xFFFF) o << "num[formats]=" << m_numFormats << ",";
414 if (m_numLines) o << "num[lines]=" << m_numLines << ",";
415 if (m_numChars) o << "num[chars]=" << m_numChars << ",";
416 if (m_numDistances) o << "num[distances]=" << m_numDistances << ",";
417 if (m_whole) o << "whole,";
418 if (m_numX) o << "numX=" << m_numX << ",";
419 if (m_numY) o << "numY=" << m_numY << ",";
420 o << "],";
421 }
422 protected:
423 //! copy constructor
424 StarPAttributeDrop(StarPAttributeDrop const &) = default;
425 //! the number of format
426 int m_numFormats;
427 //! the number of lines
428 int m_numLines;
429 //! the number of chars
430 int m_numChars;
431 //! the number of distances
432 int m_numDistances;
433 //! flag to know if whole
434 bool m_whole;
435 //! the number of x
436 int m_numX;
437 //! the number of y
438 int m_numY;
439 };
440
441 //! a hyphen attribute
442 class StarPAttributeHyphen final : public StarAttribute
443 {
444 public:
445 //! constructor
StarPAttributeHyphen(Type type,std::string const & debugName)446 StarPAttributeHyphen(Type type, std::string const &debugName)
447 : StarAttribute(type, debugName)
448 , m_hyphenZone(0)
449 , m_pageEnd(0)
450 , m_minLead(0)
451 , m_minTail(0)
452 , m_maxHyphen(0)
453 {
454 }
455 //! create a new attribute
create() const456 std::shared_ptr<StarAttribute> create() const final
457 {
458 return std::shared_ptr<StarAttribute>(new StarPAttributeHyphen(*this));
459 }
460 //! read a zone
461 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
462 //! add to a para
463 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
464 //! debug function to print the data
printData(libstoff::DebugStream & o) const465 void printData(libstoff::DebugStream &o) const final
466 {
467 o << m_debugName << "=[";
468 if (m_hyphenZone) o << "hyphenZone=" << m_hyphenZone << ",";
469 if (m_pageEnd) o << "pageEnd,";
470 if (m_minLead) o << "lead[min]=" << m_minLead << ",";
471 if (m_minTail) o << "tail[min]=" << m_minTail << ",";
472 if (m_maxHyphen) o << "hyphen[max]=" << m_maxHyphen << ",";
473 o << "],";
474 }
475 protected:
476 //! copy constructor
477 StarPAttributeHyphen(StarPAttributeHyphen const &) = default;
478 //! the hyphen value
479 int m_hyphenZone;
480 //! the page end flag
481 bool m_pageEnd;
482 //! the min lead
483 int m_minLead;
484 //! the min tail
485 int m_minTail;
486 //! the max hyphen
487 int m_maxHyphen;
488 };
489
490 //! a line spacing attribute
491 class StarPAttributeLineSpacing final : public StarAttribute
492 {
493 public:
494 //! constructor
StarPAttributeLineSpacing(Type type,std::string const & debugName)495 StarPAttributeLineSpacing(Type type, std::string const &debugName)
496 : StarAttribute(type, debugName)
497 , m_propLineSpace(100)
498 , m_interLineSpace(0)
499 , m_lineHeight(200)
500 , m_lineSpaceRule(0)
501 , m_interLineSpaceRule(0)
502 {
503 }
504 //! create a new attribute
create() const505 std::shared_ptr<StarAttribute> create() const final
506 {
507 return std::shared_ptr<StarAttribute>(new StarPAttributeLineSpacing(*this));
508 }
509 //! read a zone
510 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
511 //! add to a para
512 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
513 //! debug function to print the data
printData(libstoff::DebugStream & o) const514 void printData(libstoff::DebugStream &o) const final
515 {
516 o << m_debugName << "=[";
517 if (m_interLineSpace) o << "lineSpace=" << m_interLineSpace;
518 if (m_propLineSpace!=100) o << "propLineSpace=" << m_propLineSpace << ",";
519 if (m_lineHeight) o << "height=" << m_lineHeight << ",";
520 if (m_lineSpaceRule) o << "lineSpaceRule=" << m_lineSpaceRule << ",";
521 if (m_interLineSpaceRule) o << "interLineSpaceRule=" << m_interLineSpaceRule << ",";
522 o << "],";
523 }
524 protected:
525 //! copy constructor
526 StarPAttributeLineSpacing(StarPAttributeLineSpacing const &) = default;
527 //! the prop lineSpacing
528 int m_propLineSpace;
529 //! the line spacing
530 int m_interLineSpace;
531 //! the height
532 int m_lineHeight;
533 //! the line spacing rule: SvxLineSpace
534 int m_lineSpaceRule;
535 //! the inter line spacing rule: SvxInterLineSpace
536 int m_interLineSpaceRule;
537 };
538
539 //! a numRule attribute
540 class StarPAttributeNumericRuler final : public StarAttribute
541 {
542 public:
543 //! constructor
StarPAttributeNumericRuler(Type type,std::string const & debugName)544 StarPAttributeNumericRuler(Type type, std::string const &debugName)
545 : StarAttribute(type, debugName)
546 , m_name("")
547 , m_poolId(0)
548 {
549 }
550 //! create a new attribute
create() const551 std::shared_ptr<StarAttribute> create() const final
552 {
553 return std::shared_ptr<StarAttribute>(new StarPAttributeNumericRuler(*this));
554 }
555 //! read a zone
556 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
557 //! add to a para
558 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
559 //! debug function to print the data
printData(libstoff::DebugStream & o) const560 void printData(libstoff::DebugStream &o) const final
561 {
562 o << m_debugName << "=[";
563 if (!m_name.empty()) o << m_name.cstr() << ",";
564 if (m_poolId) o << "poolId=" << m_poolId << ",";
565 o << "],";
566 }
567 protected:
568 //! copy constructor
569 StarPAttributeNumericRuler(StarPAttributeNumericRuler const &) = default;
570 //! the name value
571 librevenge::RVNGString m_name;
572 //! the poolId
573 int m_poolId;
574 };
575
576 //! a tabStop attribute
577 class StarPAttributeTabStop final : public StarAttribute
578 {
579 public:
580 //! a tabs structure
581 struct TabStop {
582 //! constructor
TabStopStarParagraphAttribute::StarPAttributeTabStop::TabStop583 TabStop()
584 : m_pos(0)
585 , m_type(0)
586 , m_decimal(44)
587 , m_fill(32)
588 {
589 }
590 //! debug function to print the data
printDataStarParagraphAttribute::StarPAttributeTabStop::TabStop591 void printData(libstoff::DebugStream &o) const
592 {
593 o << "pos=" << m_pos;
594 if (m_type>=0 && m_type<5) {
595 char const *wh[]= {"L", "R", "D", "C", "Def"};
596 o << wh[m_type];
597 }
598 else
599 o << "[##type=" << m_type << "]";
600 if (m_decimal!=44) o << "[decimal=" << m_decimal << "]";
601 if (m_fill!=32) o << "[fill=" << m_fill << "]";
602 o << ",";
603 }
604 //! the position
605 int m_pos;
606 //! the type: SvxTabAdjust: left, right, decimal, center, default
607 int m_type;
608 //! the decimal char
609 int m_decimal;
610 //! the fill char
611 int m_fill;
612 };
613 //! constructor
StarPAttributeTabStop(Type type,std::string const & debugName)614 StarPAttributeTabStop(Type type, std::string const &debugName)
615 : StarAttribute(type, debugName)
616 , m_tabList()
617 {
618 }
619 //! create a new attribute
create() const620 std::shared_ptr<StarAttribute> create() const final
621 {
622 return std::shared_ptr<StarAttribute>(new StarPAttributeTabStop(*this));
623 }
624 //! read a zone
625 bool read(StarZone &zone, int vers, long endPos, StarObject &object) final;
626 //! add to a para
627 void addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const final;
628 //! debug function to print the data
printData(libstoff::DebugStream & o) const629 void printData(libstoff::DebugStream &o) const override
630 {
631 o << m_debugName << "=[";
632 for (auto const &t : m_tabList)
633 t.printData(o);
634 o << "],";
635 }
636 protected:
637 //! copy constructor
638 StarPAttributeTabStop(StarPAttributeTabStop const &) = default;
639 //! the tabStop list
640 std::vector<TabStop> m_tabList;
641 };
642
addTo(StarState & state,std::set<StarAttribute const * > &) const643 void StarPAttributeAdjust::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
644 {
645 if (m_type==ATTR_PARA_ADJUST) {
646 switch (m_adjust) {
647 case 0:
648 state.m_paragraph.m_propertyList.insert("fo:text-align", "left");
649 break;
650 case 1:
651 state.m_paragraph.m_propertyList.insert("fo:text-align", "right");
652 break;
653 case 2: // block
654 state.m_paragraph.m_propertyList.insert("fo:text-align", "justify");
655 state.m_paragraph.m_propertyList.insert("fo:text-align-last", "default");
656 break;
657 case 3:
658 state.m_paragraph.m_propertyList.insert("fo:text-align", "center");
659 break;
660 case 4: // blockline
661 state.m_paragraph.m_propertyList.insert("fo:text-align", "justify");
662 break;
663 case 5:
664 state.m_paragraph.m_propertyList.insert("fo:text-align", "end");
665 break;
666 default:
667 STOFF_DEBUG_MSG(("StarPAttributeAdjust::addTo: unknown adjust %d\n", int(m_adjust)));
668 }
669 }
670 }
671
addTo(StarState & state,std::set<StarAttribute const * > &) const672 void StarPAttributeBulletNumeric::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
673 {
674 if (m_type==ATTR_EE_PARA_NUMBULLET) {
675 STOFFListLevel level;
676 if (m_numType<=4) {
677 char const *wh[]= {"A", "a", "I", "i", "1"};
678 level.m_propertyList.insert("style:num-format", wh[m_numType]);
679 level.m_type=STOFFListLevel::NUMBER;
680 }
681 else {
682 STOFF_DEBUG_MSG(("StarPAttributeBulletNumeric::addTo: unknown type=%d\n", m_numType));
683 level.m_type=STOFFListLevel::BULLET;
684 librevenge::RVNGString bullet;
685 libstoff::appendUnicode(0x2022, bullet); // checkme
686 level.m_propertyList.insert("text:bullet-char", bullet);
687 }
688 state.m_paragraph.m_listLevel=level;
689 }
690 }
691
addTo(StarState & state,std::set<StarAttribute const * > &) const692 void StarPAttributeBulletSimple::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
693 {
694 if (m_type==ATTR_EE_PARA_BULLET)
695 state.m_paragraph.m_listLevel=m_level;
696 }
697
addTo(StarState & state,std::set<StarAttribute const * > &) const698 void StarPAttributeDrop::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
699 {
700 if (m_type==ATTR_PARA_DROP) {
701 librevenge::RVNGPropertyList cap;
702 cap.insert("style:distance", state.m_global->m_relativeUnit*double(m_numDistances), librevenge::RVNG_POINT);
703 cap.insert("style:length", m_numChars);
704 cap.insert("style:lines", m_numLines);
705 librevenge::RVNGPropertyListVector capVector;
706 capVector.append(cap);
707 state.m_paragraph.m_propertyList.insert("style:drop-cap", capVector);
708 }
709 }
710
addTo(StarState &,std::set<StarAttribute const * > &) const711 void StarPAttributeHyphen::addTo(StarState &/*state*/, std::set<StarAttribute const *> &/*done*/) const
712 {
713 }
714
addTo(StarState & state,std::set<StarAttribute const * > &) const715 void StarPAttributeLineSpacing::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
716 {
717 if (m_type==ATTR_PARA_LINESPACING) {
718 // svx_paraitem.cxx SvxLineSpacingItem::QueryValue
719 if (m_interLineSpaceRule==0)
720 state.m_paragraph.m_propertyList.insert("fo:line-height", "normal");
721 switch (m_lineSpaceRule) {
722 case 0: // will be set later
723 break;
724 case 1:
725 state.m_paragraph.m_propertyList.insert("fo:line-height", state.m_global->m_relativeUnit*double(m_lineHeight), librevenge::RVNG_POINT);
726 return;
727 case 2:
728 state.m_paragraph.m_propertyList.insert("fo:line-height-at-least", state.m_global->m_relativeUnit*double(m_lineHeight), librevenge::RVNG_POINT);
729 return;
730 default:
731 STOFF_DEBUG_MSG(("StarPAttributeLineSpacing::addTo: unknown rule %d\n", int(m_lineSpaceRule)));
732 }
733 switch (m_interLineSpaceRule) {
734 case 0: // off
735 state.m_paragraph.m_propertyList.insert("fo:line-height", 1., librevenge::RVNG_PERCENT);
736 break;
737 case 1: // Prop
738 state.m_paragraph.m_propertyList.insert("fo:line-height", double(m_propLineSpace)/100., librevenge::RVNG_PERCENT);
739 break;
740 case 2: // Fix
741 state.m_paragraph.m_propertyList.insert("fo:line-height", state.m_global->m_relativeUnit*double(m_interLineSpace), librevenge::RVNG_POINT);
742 break;
743 default:
744 STOFF_DEBUG_MSG(("StarPAttributeLineSpacing::addTo: unknown inter linse spacing rule %d\n", int(m_interLineSpaceRule)));
745 }
746 }
747 }
748
addTo(StarState & state,std::set<StarAttribute const * > &) const749 void StarPAttributeNumericRuler::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
750 {
751 if (m_name.empty() || !state.m_global->m_numericRuler)
752 return;
753 state.m_global->m_list=state.m_global->m_numericRuler->getList(m_name);
754 }
755
addTo(StarState & state,std::set<StarAttribute const * > &) const756 void StarPAttributeTabStop::addTo(StarState &state, std::set<StarAttribute const *> &/*done*/) const
757 {
758 librevenge::RVNGPropertyListVector tabs;
759 for (auto const &tabStop : m_tabList) {
760 librevenge::RVNGPropertyList tab;
761 switch (tabStop.m_type) {
762 case 0:
763 tab.insert("style:type", "left");
764 break;
765 case 1:
766 tab.insert("style:type", "right");
767 break;
768 case 2:
769 tab.insert("style:type", "center");
770 break;
771 case 3:
772 tab.insert("style:type", "char");
773 if (tabStop.m_decimal) {
774 librevenge::RVNGString sDecimal;
775 libstoff::appendUnicode(uint32_t(tabStop.m_decimal), sDecimal);
776 tab.insert("style:char", sDecimal);
777 }
778 break;
779 case 4: // default: checkme: can we set "style:tab-stop-distance" here
780 break;
781 default:
782 STOFF_DEBUG_MSG(("StarPAttributeTabStop::addTo: unknown attrib %d\n", int(tabStop.m_type)));
783 }
784 if (tabStop.m_fill) {
785 librevenge::RVNGString sFill;
786 libstoff::appendUnicode(uint32_t(tabStop.m_fill), sFill);
787 tab.insert("style:leader-text", sFill);
788 tab.insert("style:leader-style", "solid");
789 }
790 tab.insert("style:position", state.m_global->m_relativeUnit*double(tabStop.m_pos), librevenge::RVNG_POINT);
791 tabs.append(tab);
792 }
793 state.m_paragraph.m_propertyList.insert("style:tab-stops", tabs);
794 }
795
read(StarZone & zone,int vers,long endPos,StarObject &)796 bool StarPAttributeAdjust::read(StarZone &zone, int vers, long endPos, StarObject &/*object*/)
797 {
798 STOFFInputStreamPtr input=zone.input();
799 long pos=input->tell();
800 libstoff::DebugFile &ascFile=zone.ascii();
801 libstoff::DebugStream f;
802 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
803 m_adjust=int(input->readULong(1));
804 if (vers>=1) m_flags=int(input->readULong(1));
805 printData(f);
806 ascFile.addPos(pos);
807 ascFile.addNote(f.str().c_str());
808 return input->tell()<=endPos;
809 }
810
read(StarZone & zone,int,long endPos,StarObject & object)811 bool StarPAttributeBulletNumeric::read(StarZone &zone, int /*vers*/, long endPos, StarObject &object)
812 {
813 STOFFInputStreamPtr input=zone.input();
814 long pos=input->tell();
815 libstoff::DebugFile &ascFile=zone.ascii();
816 libstoff::DebugStream f;
817 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
818 // svx_numitem.cxx SvxNumRule::SvxNumRule
819 uint16_t version;
820 *input >> version;
821 m_numLevels=int(input->readULong(2));
822 m_flags=int(input->readULong(2));
823 m_continuous=(input->readULong(2)!=0);
824 m_numType=int(input->readULong(2));
825 f << "set=[";
826 for (int i=0; i<10; ++i) {
827 uint16_t nSet;
828 *input>>nSet;
829 if (nSet) {
830 f << nSet << ",";
831 if (!object.getFormatManager()->readNumberFormat(zone, endPos, object) || input->tell()>endPos) {
832 f << "###";
833 break;
834 }
835 }
836 else
837 f << "_,";
838 }
839 f << "],";
840 if (version>=2)
841 m_flags=int(input->readULong(2));
842 printData(f);
843 ascFile.addPos(pos);
844 ascFile.addNote(f.str().c_str());
845 return input->tell()<=endPos;
846 }
847
read(StarZone & zone,int vers,long endPos,StarObject &)848 bool StarPAttributeBulletSimple::read(StarZone &zone, int vers, long endPos, StarObject &/*object*/)
849 {
850 // svx_bulitem.cxx SvxBulletItem::SvxBulletItem
851 return StarObjectNumericRuler::readAttributeLevel(zone, vers, endPos, m_level);
852 }
853
read(StarZone & zone,int vers,long endPos,StarObject &)854 bool StarPAttributeDrop::read(StarZone &zone, int vers, long endPos, StarObject &/*object*/)
855 {
856 STOFFInputStreamPtr input=zone.input();
857 long pos=input->tell();
858 libstoff::DebugFile &ascFile=zone.ascii();
859 libstoff::DebugStream f;
860 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
861 m_numFormats=int(input->readULong(2));
862 m_numLines=int(input->readULong(2));
863 m_numChars=int(input->readULong(2));
864 m_numDistances=int(input->readULong(2));
865 if (vers>=1)
866 *input >> m_whole;
867 else {
868 m_numX=int(input->readULong(2));
869 m_numY=int(input->readULong(2));
870 }
871 printData(f);
872 ascFile.addPos(pos);
873 ascFile.addNote(f.str().c_str());
874 return input->tell()<=endPos;
875 }
876
read(StarZone & zone,int,long endPos,StarObject &)877 bool StarPAttributeHyphen::read(StarZone &zone, int /*vers*/, long endPos, StarObject &/*object*/)
878 {
879 STOFFInputStreamPtr input=zone.input();
880 long pos=input->tell();
881 libstoff::DebugFile &ascFile=zone.ascii();
882 libstoff::DebugStream f;
883 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
884 m_hyphenZone=int(input->readLong(1));
885 *input >> m_pageEnd;
886 m_minLead=int(input->readLong(1));
887 m_minTail=int(input->readLong(1));
888 m_maxHyphen=int(input->readLong(1));
889 printData(f);
890 ascFile.addPos(pos);
891 ascFile.addNote(f.str().c_str());
892 return input->tell()<=endPos;
893 }
894
read(StarZone & zone,int,long endPos,StarObject &)895 bool StarPAttributeLineSpacing::read(StarZone &zone, int /*vers*/, long endPos, StarObject &/*object*/)
896 {
897 STOFFInputStreamPtr input=zone.input();
898 long pos=input->tell();
899 libstoff::DebugFile &ascFile=zone.ascii();
900 libstoff::DebugStream f;
901 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
902 m_propLineSpace=int(input->readULong(1));
903 m_interLineSpace=int(input->readLong(2));
904 m_lineHeight=int(input->readULong(2));
905 m_lineSpaceRule=int(input->readULong(1));
906 m_interLineSpaceRule=int(input->readULong(1));
907
908 printData(f);
909 ascFile.addPos(pos);
910 ascFile.addNote(f.str().c_str());
911 return input->tell()<=endPos;
912 }
913
read(StarZone & zone,int vers,long endPos,StarObject &)914 bool StarPAttributeNumericRuler::read(StarZone &zone, int vers, long endPos, StarObject &/*object*/)
915 {
916 STOFFInputStreamPtr input=zone.input();
917 long pos=input->tell();
918 libstoff::DebugFile &ascFile=zone.ascii();
919 libstoff::DebugStream f;
920 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
921 // sw_sw3attr.cxx SwNumRuleItem::Create
922 std::vector<uint32_t> string;
923 if (!zone.readString(string) || input->tell()>endPos) {
924 STOFF_DEBUG_MSG(("StarPAttributeNumericRuler::read: can not find the sTmp\n"));
925 f << "###sTmp,";
926 ascFile.addPos(pos);
927 ascFile.addNote(f.str().c_str());
928 return false;
929 }
930 m_name=libstoff::getString(string);
931 if (vers>0)
932 // 3<<11+1<<10+(num1,num2,...,num5,bul1,...,bul5)
933 m_poolId=int(input->readULong(2));
934 printData(f);
935 ascFile.addPos(pos);
936 ascFile.addNote(f.str().c_str());
937 return input->tell()<=endPos;
938 }
939
read(StarZone & zone,int,long endPos,StarObject &)940 bool StarPAttributeTabStop::read(StarZone &zone, int /*vers*/, long endPos, StarObject &/*object*/)
941 {
942 STOFFInputStreamPtr input=zone.input();
943 long pos=input->tell();
944 libstoff::DebugFile &ascFile=zone.ascii();
945 libstoff::DebugStream f;
946 f << "Entries(StarAttribute)[" << zone.getRecordLevel() << "]:";
947 auto N=int(input->readULong(1));
948 if (input->tell()+7*N>endPos) {
949 STOFF_DEBUG_MSG(("StarPAttributeTabStop::read: N is too big\n"));
950 f << "###N=" << N << ",";
951 ascFile.addPos(pos);
952 ascFile.addNote(f.str().c_str());
953 return false;
954 }
955 m_tabList.resize(size_t(N));
956 for (size_t i=0; i<size_t(N); ++i) {
957 StarPAttributeTabStop::TabStop &tab=m_tabList[i];
958 tab.m_pos=int(input->readLong(4));
959 tab.m_type=int(input->readULong(1));
960 tab.m_decimal=int(input->readULong(1));
961 tab.m_fill=int(input->readULong(1));
962 }
963 f << "],";
964 printData(f);
965 ascFile.addPos(pos);
966 ascFile.addNote(f.str().c_str());
967 return input->tell()<=endPos;
968 }
969
970 }
971
972 namespace StarParagraphAttribute
973 {
addInitTo(std::map<int,std::shared_ptr<StarAttribute>> & map)974 void addInitTo(std::map<int, std::shared_ptr<StarAttribute> > &map)
975 {
976 addAttributeBool(map,StarAttribute::ATTR_PARA_SPLIT,"para[split]",true);
977 addAttributeUInt(map,StarAttribute::ATTR_PARA_WIDOWS,"para[widows]",1,0); // numlines
978 addAttributeUInt(map,StarAttribute::ATTR_PARA_ORPHANS,"para[orphans]",1,0); // numlines
979 addAttributeBool(map,StarAttribute::ATTR_PARA_HANGINGPUNCTUATION,"para[hangingPunctuation]",true);
980 addAttributeUInt(map,StarAttribute::ATTR_PARA_VERTALIGN,"para[vert,align]",2,0);
981 addAttributeBool(map,StarAttribute::ATTR_PARA_SNAPTOGRID,"para[snapToGrid]",true);
982 addAttributeBool(map,StarAttribute::ATTR_PARA_CONNECT_BORDER,"para[connectBorder]",true);
983 addAttributeUInt(map, StarAttribute::ATTR_EE_PARA_BULLETSTATE,"para[bullet,state]",2,0);
984 addAttributeUInt(map, StarAttribute::ATTR_EE_PARA_OUTLLEVEL,"para[outlevel]",2,0);
985 addAttributeBool(map, StarAttribute::ATTR_EE_PARA_ASIANCJKSPACING,"para[asianCJKSpacing]",false);
986
987 map[StarAttribute::ATTR_PARA_ADJUST]=std::shared_ptr<StarAttribute>(new StarPAttributeAdjust(StarAttribute::ATTR_PARA_ADJUST,"parAtrAdjust"));
988 map[StarAttribute::ATTR_PARA_LINESPACING]=std::shared_ptr<StarAttribute>(new StarPAttributeLineSpacing(StarAttribute::ATTR_PARA_LINESPACING,"parAtrLinespacing"));
989 map[StarAttribute::ATTR_PARA_TABSTOP]=std::shared_ptr<StarAttribute>(new StarPAttributeTabStop(StarAttribute::ATTR_PARA_TABSTOP,"parAtrTabStop"));
990 map[StarAttribute::ATTR_EE_PARA_NUMBULLET]=std::shared_ptr<StarAttribute>(new StarPAttributeBulletNumeric(StarAttribute::ATTR_EE_PARA_NUMBULLET,"eeParaNumBullet"));
991 map[StarAttribute::ATTR_EE_PARA_BULLET]=std::shared_ptr<StarAttribute>(new StarPAttributeBulletSimple(StarAttribute::ATTR_EE_PARA_BULLET,"paraBullet"));
992 map[StarAttribute::ATTR_PARA_DROP]=std::shared_ptr<StarAttribute>(new StarPAttributeDrop(StarAttribute::ATTR_PARA_DROP,"parAtrDrop"));
993
994 // seems safe to ignore
995 addAttributeBool(map,StarAttribute::ATTR_PARA_SCRIPTSPACE,"para[scriptSpace]",false); // script type, use by ui
996 addAttributeVoid(map, StarAttribute::ATTR_EE_PARA_XMLATTRIBS, "para[xmlAttrib]");
997 std::stringstream s;
998 for (int type=StarAttribute::ATTR_PARA_DUMMY5; type<=StarAttribute::ATTR_PARA_DUMMY8; ++type) {
999 s.str("");
1000 s << "paraDummy" << type-StarAttribute::ATTR_PARA_DUMMY5+5;
1001 addAttributeBool(map,StarAttribute::Type(type), s.str(), false);
1002 }
1003
1004 // can we retrieve the following attribute ?
1005 addAttributeBool(map,StarAttribute::ATTR_PARA_REGISTER,"para[register]",false);
1006 addAttributeBool(map,StarAttribute::ATTR_PARA_FORBIDDEN_RULES,"para[forbiddenRules]",true); // If the forbidden characters rules are to be applied or not.
1007 map[StarAttribute::ATTR_PARA_HYPHENZONE]=std::shared_ptr<StarAttribute>(new StarPAttributeHyphen(StarAttribute::ATTR_PARA_HYPHENZONE,"parAtrHyphenZone"));
1008 map[StarAttribute::ATTR_PARA_NUMRULE]=std::shared_ptr<StarAttribute>(new StarPAttributeNumericRuler(StarAttribute::ATTR_PARA_NUMRULE,"parAtrNumRule"));
1009
1010 // TODO
1011 }
1012 }
1013 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
1014