libwps_internal.h Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

libwps_internal.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * Major Contributor(s):
10 * Copyright (C) 2002 William Lachance (william.lachance@sympatico.ca)
11 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
12 *
13 * For minor contributions see the git repository.
14 *
15 * Alternatively, the contents of this file may be used under the terms
16 * of the GNU Lesser General Public License Version 2.1 or later
17 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
18 * applicable instead of those above.
19 *
20 * For further information visit http://libwps.sourceforge.net
21 */
22
23 #ifndef LIBWPS_INTERNAL_H
24 #define LIBWPS_INTERNAL_H
25
26 #include <assert.h>
27 #ifdef DEBUG
28 #include <stdio.h>
29 #endif
30
31 #include <cmath>
32 #include <iostream>
33 #include <map>
34 #include <string>
35 #include <vector>
36
37 #include <librevenge-stream/librevenge-stream.h>
38 #include <librevenge/librevenge.h>
39
40 #ifndef M_PI
41 #define M_PI 3.14159265358979323846
42 #endif
43
44 #if defined(_MSC_VER) || defined(__DJGPP__)
45 typedef signed char int8_t;
46 typedef unsigned char uint8_t;
47 typedef signed short int16_t;
48 typedef unsigned short uint16_t;
49 typedef signed int int32_t;
50 typedef unsigned int uint32_t;
51 #else /* !_MSC_VER && !__DJGPP__*/
52 # include <inttypes.h>
53 #endif /* _MSC_VER || __DJGPP__*/
54
55 /* ---------- memory --------------- */
56 #ifdef HAVE_CONFIG_H
57 # include "config.h"
58 #endif
59
60 // define localtime_r on Windows, so that can use
61 // thread-safe functions on other environments
62 #ifdef _WIN32
63 # define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
64 # define localtime_r(tp,tmp) (localtime(tp)?(*(tmp)=*localtime(tp),(tmp)):0)
65 #endif
66
67 #if defined(SHAREDPTR_TR1)
68 #include <tr1/memory>
69 using std::tr1::shared_ptr;
70 #elif defined(SHAREDPTR_STD)
71 #include <memory>
72 using std::shared_ptr;
73 #else
74 #include <boost/shared_ptr.hpp>
75 using boost::shared_ptr;
76 #endif
77
79 template <class T>
80 struct WPS_shared_ptr_noop_deleter
81 {
82 void operator()(T *) {}
83 };
84
85 // basic classes and autoptr
87 typedef shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr;
88
89 class WPSCell;
90 class WPSListener;
91 class WPSContentListener;
92 class WPSEntry;
93 class WPSFont;
94 class WPSHeader;
95 class WPSPosition;
96 class WPSSubDocument;
97
98 class WKSContentListener;
99 class WKSSubDocument;
100
102 typedef shared_ptr<WPSCell> WPSCellPtr;
104 typedef shared_ptr<WPSListener> WPSListenerPtr;
106 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
108 typedef shared_ptr<WPSHeader> WPSHeaderPtr;
110 typedef shared_ptr<WPSSubDocument> WPSSubDocumentPtr;
111
113 typedef shared_ptr<WKSContentListener> WKSContentListenerPtr;
115 typedef shared_ptr<WKSSubDocument> WKSSubDocumentPtr;
116
117 #if defined(__clang__) || defined(__GNUC__)
118 # define WPS_ATTRIBUTE_PRINTF(fmt, arg) __attribute__((__format__(__printf__, fmt, arg)))
119 #else
120 # define WPS_ATTRIBUTE_PRINTF(fmt, arg)
121 #endif
122 /* ---------- debug --------------- */
123 #ifdef DEBUG
124 namespace libwps
125 {
126 void printDebugMsg(const char *format, ...) WPS_ATTRIBUTE_PRINTF(1, 2);
127 }
128 #define WPS_DEBUG_MSG(M) libwps::printDebugMsg M
129 #else
130 #define WPS_DEBUG_MSG(M)
131 #endif
132
133 /* ---------- exception ------------ */
134 namespace libwps
135 {
136 // Various exceptions
137 class VersionException
138 {
139 // needless to say, we could flesh this class out a bit
140 };
141
142 class FileException
143 {
144 // needless to say, we could flesh this class out a bit
145 };
146
147 class ParseException
148 {
149 // needless to say, we could flesh this class out a bit
150 };
151
152 class GenericException
153 {
154 // needless to say, we could flesh this class out a bit
155 };
156 }
157
158 /* ---------- input ----------------- */
159 namespace libwps
160 {
161 uint8_t readU8(librevenge::RVNGInputStream *input);
162 uint16_t readU16(librevenge::RVNGInputStream *input);
163 uint32_t readU32(librevenge::RVNGInputStream *input);
164
165 int8_t read8(librevenge::RVNGInputStream *input);
166 int16_t read16(librevenge::RVNGInputStream *input);
167 int32_t read32(librevenge::RVNGInputStream *input);
168
169 inline uint8_t readU8(RVNGInputStreamPtr &input)
170 {
171 return readU8(input.get());
172 }
173 inline uint16_t readU16(RVNGInputStreamPtr &input)
174 {
175 return readU16(input.get());
176 }
177 inline uint32_t readU32(RVNGInputStreamPtr &input)
178 {
179 return readU32(input.get());
180 }
181
182 inline int8_t read8(RVNGInputStreamPtr &input)
183 {
184 return read8(input.get());
185 }
186 inline int16_t read16(RVNGInputStreamPtr &input)
187 {
188 return read16(input.get());
189 }
190 inline int32_t read32(RVNGInputStreamPtr &input)
191 {
192 return read32(input.get());
193 }
194
196 bool readDouble4(RVNGInputStreamPtr &input, double &res, bool &isNaN);
198 bool readDouble8(RVNGInputStreamPtr &input, double &res, bool &isNaN);
200 bool readDouble10(RVNGInputStreamPtr &input, double &res, bool &isNaN);
202 bool readDouble2Inv(RVNGInputStreamPtr &input, double &res, bool &isNaN);
204 bool readDouble4Inv(RVNGInputStreamPtr &input, double &res, bool &isNaN);
205
207 bool readData(RVNGInputStreamPtr &input, unsigned long sz, librevenge::RVNGBinaryData &data);
209 bool readDataToEnd(RVNGInputStreamPtr &input, librevenge::RVNGBinaryData &data);
211 void appendUnicode(uint32_t val, librevenge::RVNGString &buffer);
212 }
213
214 #define WPS_LE_GET_GUINT16(p) \
215 (uint16_t)((((uint8_t const *)(p))[0] << 0) | \
216 (((uint8_t const *)(p))[1] << 8))
217 #define WPS_LE_GET_GUINT32(p) \
218 (uint32_t)((((uint8_t const *)(p))[0] << 0) | \
219 (((uint8_t const *)(p))[1] << 8) | \
220 (((uint8_t const *)(p))[2] << 16) | \
221 (((uint8_t const *)(p))[3] << 24))
222
223 #define WPS_LE_PUT_GUINT16(p, v) \
224 *((uint8_t*)(p)) = uint8_t(v); \
225 *(((uint8_t*)(p)) + 1) = uint8_t((v) >> 8)
226
227 #define WPS_LE_PUT_GUINT32(p, v) \
228 *((uint8_t*)(p)) = uint8_t(v); \
229 *(((uint8_t*)(p)) + 1) = uint8_t((v) >> 8); \
230 *(((uint8_t*)(p)) + 2) = uint8_t((v) >> 16); \
231 *(((uint8_t*)(p)) + 3) = uint8_t((v) >> 24)
232
233 // Various helper structures for the parser..
234 /* ---------- small enum/class ------------- */
235 namespace libwps
236 {
237 enum NumberingType { NONE, BULLET, ARABIC, LOWERCASE, UPPERCASE, LOWERCASE_ROMAN, UPPERCASE_ROMAN };
238 std::string numberingTypeToString(NumberingType type);
239 enum SubDocumentType { DOC_NONE, DOC_HEADER_FOOTER, DOC_NOTE, DOC_TABLE, DOC_TEXT_BOX, DOC_COMMENT_ANNOTATION };
240 enum Justification { JustificationLeft, JustificationFull, JustificationCenter,
241 JustificationRight, JustificationFullAllLines
242 };
243 enum { NoBreakBit = 0x1, NoBreakWithNextBit=0x2};
244 }
245
246 struct WPSColumnDefinition
247 {
248 WPSColumnDefinition() : m_width(0), m_leftGutter(0), m_rightGutter(0)
249 {
250 }
251 double m_width;
252 double m_leftGutter;
253 double m_rightGutter;
254 };
255
256 struct WPSColumnProperties
257 {
258 WPSColumnProperties() : m_attributes(0), m_alignment(0)
259 {
260 }
261 uint32_t m_attributes;
262 uint8_t m_alignment;
263 };
264
266 struct WPSColor
267 {
269 explicit WPSColor(uint32_t argb=0) : m_value(argb)
270 {
271 }
273 WPSColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255) :
274 m_value(uint32_t((a<<24)+(r<<16)+(g<<8)+b))
275 {
276 }
278 WPSColor &operator=(uint32_t argb)
279 {
280 m_value = argb;
281 return *this;
282 }
284 static WPSColor black()
285 {
286 return WPSColor(0,0,0);
287 }
289 static WPSColor white()
290 {
291 return WPSColor(255,255,255);
292 }
293
295 static WPSColor barycenter(float alpha, WPSColor const &colA,
296 float beta, WPSColor const &colB);
298 uint32_t value() const
299 {
300 return m_value;
301 }
303 unsigned char getAlpha() const
304 {
305 return (unsigned char)((m_value>>24)&0xFF);
306 }
308 unsigned char getBlue() const
309 {
310 return (unsigned char)(m_value&0xFF);
311 }
313 unsigned char getRed() const
314 {
315 return (unsigned char)((m_value>>16)&0xFF);
316 }
318 unsigned char getGreen() const
319 {
320 return (unsigned char)((m_value>>8)&0xFF);
321 }
323 bool isBlack() const
324 {
325 return (m_value&0xFFFFFF)==0;
326 }
328 bool isWhite() const
329 {
330 return (m_value&0xFFFFFF)==0xFFFFFF;
331 }
333 bool operator==(WPSColor const &c) const
334 {
335 return (c.m_value&0xFFFFFF)==(m_value&0xFFFFFF);
336 }
338 bool operator!=(WPSColor const &c) const
339 {
340 return !operator==(c);
341 }
343 bool operator<(WPSColor const &c) const
344 {
345 return (c.m_value&0xFFFFFF)<(m_value&0xFFFFFF);
346 }
348 bool operator<=(WPSColor const &c) const
349 {
350 return (c.m_value&0xFFFFFF)<=(m_value&0xFFFFFF);
351 }
353 bool operator>(WPSColor const &c) const
354 {
355 return !operator<=(c);
356 }
358 bool operator>=(WPSColor const &c) const
359 {
360 return !operator<(c);
361 }
363 friend std::ostream &operator<< (std::ostream &o, WPSColor const &c);
365 std::string str() const;
366 protected:
368 uint32_t m_value;
369 };
370
372 struct WPSBorder
373 {
375 enum Style { None, Simple, Dot, LargeDot, Dash };
377 enum Type { Single, Double, Triple };
378 enum Pos { Left = 0, Right = 1, Top = 2, Bottom = 3 };
379 enum { LeftBit = 0x01, RightBit = 0x02, TopBit=0x4, BottomBit = 0x08 };
380
382 WPSBorder() : m_style(Simple), m_type(Single), m_width(1), m_widthsList(), m_color(WPSColor::black()), m_extra("") { }
386 bool addTo(librevenge::RVNGPropertyList &propList, std::string which="") const;
388 bool isEmpty() const
389 {
390 return m_style==None || m_width <= 0;
391 }
392
394 bool operator==(WPSBorder const &orig) const
395 {
396 return m_style == orig.m_style && m_type == orig.m_type && m_width == orig.m_width
397 && m_color == orig.m_color;
398 }
400 bool operator!=(WPSBorder const &orig) const
401 {
402 return !operator==(orig);
403 }
405 int compare(WPSBorder const &orig) const;
406
408 friend std::ostream &operator<< (std::ostream &o, WPSBorder const &border);
410 friend std::ostream &operator<< (std::ostream &o, WPSBorder::Style const &style);
412 Style m_style;
414 Type m_type;
416 int m_width;
420 std::vector<double> m_widthsList;
422 WPSColor m_color;
424 std::string m_extra;
425 };
426
431 struct WPSEmbeddedObject
432 {
434 WPSEmbeddedObject() : m_dataList(), m_typeList()
435 {
436 }
438 WPSEmbeddedObject(librevenge::RVNGBinaryData const &binaryData,
439 std::string type="image/pict") : m_dataList(), m_typeList()
440 {
441 add(binaryData, type);
442 }
444 virtual ~WPSEmbeddedObject()
445 {
446 }
448 bool isEmpty() const
449 {
450 for (size_t i=0; i<m_dataList.size(); ++i)
451 {
452 if (!m_dataList[i].empty())
453 return false;
454 }
455 return true;
456 }
458 void add(librevenge::RVNGBinaryData const &binaryData, std::string type="image/pict")
459 {
460 size_t pos=m_dataList.size();
461 if (pos<m_typeList.size()) pos=m_typeList.size();
462 m_dataList.resize(pos+1);
463 m_dataList[pos]=binaryData;
464 m_typeList.resize(pos+1);
465 m_typeList[pos]=type;
466 }
468 bool addTo(librevenge::RVNGPropertyList &propList) const;
470 friend std::ostream &operator<<(std::ostream &o, WPSEmbeddedObject const &pict);
471
473 std::vector<librevenge::RVNGBinaryData> m_dataList;
475 std::vector<std::string> m_typeList;
476 };
477
479 struct WPSField
480 {
482 enum Type { None, Database, Date, Link, PageCount, PageNumber, PageNumberNext, Time, Title };
483
485 explicit WPSField(Type type) : m_type(type), m_DTFormat(""), m_numberingType(libwps::ARABIC), m_data("")
486 {
487 }
489 bool addTo(librevenge::RVNGPropertyList &propList) const;
491 librevenge::RVNGString getString() const;
493 Type m_type;
495 std::string m_DTFormat;
497 libwps::NumberingType m_numberingType;
499 std::string m_data;
500 };
501
502 // ATTRIBUTE bits
503 #define WPS_EXTRA_LARGE_BIT 1
504 #define WPS_VERY_LARGE_BIT 2
505 #define WPS_LARGE_BIT 4
506 #define WPS_SMALL_PRINT_BIT 8
507 #define WPS_FINE_PRINT_BIT 0x10
508 #define WPS_SUPERSCRIPT_BIT 0x20
509 #define WPS_SUBSCRIPT_BIT 0x40
510 #define WPS_OUTLINE_BIT 0x80
511 #define WPS_ITALICS_BIT 0x100
512 #define WPS_SHADOW_BIT 0x200
513 #define WPS_REDLINE_BIT 0x400
514 #define WPS_DOUBLE_UNDERLINE_BIT 0x800
515 #define WPS_BOLD_BIT 0x1000
516 #define WPS_STRIKEOUT_BIT 0x2000
517 #define WPS_UNDERLINE_BIT 0x4000
518 #define WPS_SMALL_CAPS_BIT 0x8000
519 #define WPS_BLINK_BIT 0x10000L
520 #define WPS_REVERSEVIDEO_BIT 0x20000L
521 #define WPS_ALL_CAPS_BIT 0x40000L
522 #define WPS_EMBOSS_BIT 0x80000L
523 #define WPS_ENGRAVE_BIT 0x100000L
524 #define WPS_OVERLINE_BIT 0x400000L
525 #define WPS_HIDDEN_BIT 0x800000L
526
527 // BREAK bits
528 #define WPS_PAGE_BREAK 0x00
529 #define WPS_SOFT_PAGE_BREAK 0x01
530 #define WPS_COLUMN_BREAK 0x02
531
532 // Generic bits
533 #define WPS_LEFT 0x00
534 #define WPS_RIGHT 0x01
535 #define WPS_CENTER 0x02
536 #define WPS_TOP 0x03
537 #define WPS_BOTTOM 0x04
538
539 /* ---------- vec2/box2f ------------- */
543 template <class T> class Vec2
544 {
545 public:
547 Vec2(T xx=0,T yy=0) : m_x(xx), m_y(yy) { }
549 template <class U> Vec2(Vec2<U> const &p) : m_x(T(p.x())), m_y(T(p.y())) {}
550
552 T x() const
553 {
554 return m_x;
555 }
557 T y() const
558 {
559 return m_y;
560 }
562 T operator[](int c) const
563 {
564 if (c<0 || c>1) throw libwps::GenericException();
565 return (c==0) ? m_x : m_y;
566 }
568 T &operator[](int c)
569 {
570 if (c<0 || c>1) throw libwps::GenericException();
571 return (c==0) ? m_x : m_y;
572 }
573
575 void set(T xx, T yy)
576 {
577 m_x = xx;
578 m_y = yy;
579 }
581 void setX(T xx)
582 {
583 m_x = xx;
584 }
586 void setY(T yy)
587 {
588 m_y = yy;
589 }
590
592 void add(T dx, T dy)
593 {
594 m_x += dx;
595 m_y += dy;
596 }
597
599 Vec2<T> &operator+=(Vec2<T> const &p)
600 {
601 m_x += p.m_x;
602 m_y += p.m_y;
603 return *this;
604 }
606 Vec2<T> &operator-=(Vec2<T> const &p)
607 {
608 m_x -= p.m_x;
609 m_y -= p.m_y;
610 return *this;
611 }
613 template <class U>
614 Vec2<T> &operator*=(U scale)
615 {
616 m_x = T(m_x*scale);
617 m_y = T(m_y*scale);
618 return *this;
619 }
620
622 friend Vec2<T> operator+(Vec2<T> const &p1, Vec2<T> const &p2)
623 {
624 Vec2<T> p(p1);
625 return p+=p2;
626 }
628 friend Vec2<T> operator-(Vec2<T> const &p1, Vec2<T> const &p2)
629 {
630 Vec2<T> p(p1);
631 return p-=p2;
632 }
634 template <class U>
635 friend Vec2<T> operator*(U scale, Vec2<T> const &p1)
636 {
637 Vec2<T> p(p1);
638 return p *= scale;
639 }
640
642 bool operator==(Vec2<T> const &p) const
643 {
644 return cmpY(p) == 0;
645 }
647 bool operator!=(Vec2<T> const &p) const
648 {
649 return cmpY(p) != 0;
650 }
652 bool operator<(Vec2<T> const &p) const
653 {
654 return cmpY(p) < 0;
655 }
657 int cmp(Vec2<T> const &p) const
658 {
659 if (m_x<p.m_x) return -1;
660 if (m_x>p.m_x) return 1;
661 if (m_y<p.m_y) return -1;
662 if (m_y>p.m_y) return 1;
663 return 0;
664 }
666 int cmpY(Vec2<T> const &p) const
667 {
668 if (m_y<p.m_y) return -1;
669 if (m_y>p.m_y) return 1;
670 if (m_x<p.m_x) return -1;
671 if (m_x>p.m_x) return 1;
672 return 0;
673 }
674
676 friend std::ostream &operator<< (std::ostream &o, Vec2<T> const &f)
677 {
678 o << f.m_x << "x" << f.m_y;
679 return o;
680 }
681
685 struct PosSizeLtX
686 {
688 bool operator()(Vec2<T> const &s1, Vec2<T> const &s2) const
689 {
690 return s1.cmp(s2) < 0;
691 }
692 };
693
697 struct PosSizeLtY
698 {
700 bool operator()(Vec2<T> const &s1, Vec2<T> const &s2) const
701 {
702 return s1.cmpY(s2) < 0;
703 }
704 };
705 protected:
706 T m_x, m_y;
707 };
708
710 typedef Vec2<bool> Vec2b;
712 typedef Vec2<int> Vec2i;
714 typedef Vec2<float> Vec2f;
715
719 template <class T> class Box2
720 {
721 public:
723 Box2(Vec2<T> minPt=Vec2<T>(), Vec2<T> maxPt=Vec2<T>())
724 {
725 m_pt[0] = minPt;
726 m_pt[1] = maxPt;
727 }
729 template <class U> Box2(Box2<U> const &p)
730 {
731 for (int c=0; c < 2; c++) m_pt[c] = p[c];
732 }
733
735 Vec2<T> const &min() const
736 {
737 return m_pt[0];
738 }
740 Vec2<T> const &max() const
741 {
742 return m_pt[1];
743 }
745 Vec2<T> &min()
746 {
747 return m_pt[0];
748 }
750 Vec2<T> &max()
751 {
752 return m_pt[1];
753 }
754
758 Vec2<T> const &operator[](int c) const
759 {
760 if (c<0 || c>1) throw libwps::GenericException();
761 return m_pt[c];
762 }
764 Vec2<T> size() const
765 {
766 return m_pt[1]-m_pt[0];
767 }
769 Vec2<T> center() const
770 {
771 return 0.5*(m_pt[0]+m_pt[1]);
772 }
773
775 void set(Vec2<T> const &x, Vec2<T> const &y)
776 {
777 m_pt[0] = x;
778 m_pt[1] = y;
779 }
781 void setMin(Vec2<T> const &x)
782 {
783 m_pt[0] = x;
784 }
786 void setMax(Vec2<T> const &y)
787 {
788 m_pt[1] = y;
789 }
790
792 void resizeFromMin(Vec2<T> const &sz)
793 {
794 m_pt[1] = m_pt[0]+sz;
795 }
797 void resizeFromMax(Vec2<T> const &sz)
798 {
799 m_pt[0] = m_pt[1]-sz;
800 }
802 void resizeFromCenter(Vec2<T> const &sz)
803 {
804 Vec2<T> ctr = 0.5*(m_pt[0]+m_pt[1]);
805 m_pt[0] = ctr - 0.5*sz;
806 m_pt[1] = ctr + (sz - 0.5*sz);
807 }
808
810 template <class U> void scale(U factor)
811 {
812 m_pt[0] *= factor;
813 m_pt[1] *= factor;
814 }
815
817 void extend(T val)
818 {
819 m_pt[0] -= Vec2<T>(val/2,val/2);
820 m_pt[1] += Vec2<T>(val-(val/2),val-(val/2));
821 }
823 Box2<T> getUnion(Box2<T> const &box) const
824 {
825 Box2<T> res;
826 res.m_pt[0]=Vec2<T>(m_pt[0][0]<box.m_pt[0][0]?m_pt[0][0] : box.m_pt[0][0],
827 m_pt[0][1]<box.m_pt[0][1]?m_pt[0][1] : box.m_pt[0][1]);
828 res.m_pt[1]=Vec2<T>(m_pt[1][0]>box.m_pt[1][0]?m_pt[1][0] : box.m_pt[1][0],
829 m_pt[1][1]>box.m_pt[1][1]?m_pt[1][1] : box.m_pt[1][1]);
830 return res;
831 }
833 Box2<T> getIntersection(Box2<T> const &box) const
834 {
835 Box2<T> res;
836 res.m_pt[0]=Vec2<T>(m_pt[0][0]>box.m_pt[0][0]?m_pt[0][0] : box.m_pt[0][0],
837 m_pt[0][1]>box.m_pt[0][1]?m_pt[0][1] : box.m_pt[0][1]);
838 res.m_pt[1]=Vec2<T>(m_pt[1][0]<box.m_pt[1][0]?m_pt[1][0] : box.m_pt[1][0],
839 m_pt[1][1]<box.m_pt[1][1]?m_pt[1][1] : box.m_pt[1][1]);
840 return res;
841 }
842
844 bool operator==(Box2<T> const &p) const
845 {
846 return cmp(p) == 0;
847 }
849 bool operator!=(Box2<T> const &p) const
850 {
851 return cmp(p) != 0;
852 }
854 bool operator<(Box2<T> const &p) const
855 {
856 return cmp(p) < 0;
857 }
858
860 int cmp(Box2<T> const &p) const
861 {
862 int diff = m_pt[0].cmpY(p.m_pt[0]);
863 if (diff) return diff;
864 diff = m_pt[1].cmpY(p.m_pt[1]);
865 if (diff) return diff;
866 return 0;
867 }
868
870 friend std::ostream &operator<< (std::ostream &o, Box2<T> const &f)
871 {
872 o << "(" << f.m_pt[0] << "<->" << f.m_pt[1] << ")";
873 return o;
874 }
875
879 struct PosSizeLt
880 {
882 bool operator()(Box2<T> const &s1, Box2<T> const &s2) const
883 {
884 return s1.cmp(s2) < 0;
885 }
886 };
890 typedef std::map<Box2<T>, T,struct PosSizeLt> Map;
891
892 protected:
894 Vec2<T> m_pt[2];
895 };
896
898 typedef Box2<int> Box2i;
900 typedef Box2<float> Box2f;
901
902 #endif /* LIBWPS_INTERNAL_H */
903 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPSField::m_data
std::string m_data
the database/link field ( if defined )
Definition: libwps_internal.h:499
libwps::LOWERCASE
Definition: libwps_internal.h:237
WPSContentListenerPtr
shared_ptr< WPSContentListener > WPSContentListenerPtr
shared pointer to WPSContentListener
Definition: libwps_internal.h:106
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libwps_internal.h:714
libwps::read16
int16_t read16(RVNGInputStreamPtr &input)
Definition: libwps_internal.h:186
WPSColor::WPSColor
WPSColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
constructor from color
Definition: libwps_internal.h:273
Vec2::setY
void setY(T yy)
resets the second element
Definition: libwps_internal.h:586
WPSBorder
a border list
Definition: libwps_internal.h:372
WPSColumnProperties
Definition: libwps_internal.h:256
libwps::GenericException
Definition: libwps_internal.h:152
Vec2::m_x
T m_x
first element
Definition: libwps_internal.h:706
WPSField::m_numberingType
libwps::NumberingType m_numberingType
the number type ( for number field )
Definition: libwps_internal.h:497
libwps
Definition: libwps_internal.cpp:38
libwps::readU8
uint8_t readU8(RVNGInputStreamPtr &input)
Definition: libwps_internal.h:169
Box2::operator[]
Vec2< T > const & operator[](int c) const
the two extremum points which defined the box
Definition: libwps_internal.h:758
Box2::min
Vec2< T > const & min() const
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:735
WPSSubDocumentPtr
shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition: libwps_internal.h:110
Box2::operator!=
bool operator!=(Box2< T > const &p) const
comparison operator!=
Definition: libwps_internal.h:849
libwps::read8
int8_t read8(RVNGInputStreamPtr &input)
Definition: libwps_internal.h:182
Box2::cmp
int cmp(Box2< T > const &p) const
comparison function : fist sorts min by Y,X values then max extremity
Definition: libwps_internal.h:860
Vec2::operator-
friend Vec2< T > operator-(Vec2< T > const &p1, Vec2< T > const &p2)
operator-
Definition: libwps_internal.h:628
WPSEmbeddedObject::WPSEmbeddedObject
WPSEmbeddedObject(librevenge::RVNGBinaryData const &binaryData, std::string type="image/pict")
constructor
Definition: libwps_internal.h:438
Vec2::operator[]
T & operator[](int c)
operator[]
Definition: libwps_internal.h:568
Box2
small class which defines a 2D Box
Definition: libwps_internal.h:719
Box2::PosSizeLt
internal struct used to create sorted map, sorted first min then max
Definition: libwps_internal.h:879
libwps::readU16
uint16_t readU16(RVNGInputStreamPtr &input)
Definition: libwps_internal.h:173
WPSFont
define the font properties
Definition: WPSFont.h:36
WPSEmbeddedObject::m_typeList
std::vector< std::string > m_typeList
the picture type: one type by representation
Definition: libwps_internal.h:475
WPSColor::operator==
bool operator==(WPSColor const &c) const
operator==
Definition: libwps_internal.h:333
Box2::resizeFromMin
void resizeFromMin(Vec2< T > const &sz)
resize the box keeping the minimum
Definition: libwps_internal.h:792
WPSColumnDefinition::m_leftGutter
double m_leftGutter
Definition: libwps_internal.h:252
WPSField
a field
Definition: libwps_internal.h:479
WPS_ATTRIBUTE_PRINTF
#define WPS_ATTRIBUTE_PRINTF(fmt, arg)
Definition: libwps_internal.h:120
WPSListener
virtual class for content listener
Definition: WPSListener.h:36
Vec2::PosSizeLtX
internal struct used to create sorted map, sorted by X
Definition: libwps_internal.h:685
WPSField::m_type
Type m_type
the type
Definition: libwps_internal.h:493
WPSColor::black
static WPSColor black()
return the back color
Definition: libwps_internal.h:284
WPSBorder::m_width
int m_width
the border width
Definition: libwps_internal.h:416
WPSColor::white
static WPSColor white()
return the white color
Definition: libwps_internal.h:289
libwps::DOC_COMMENT_ANNOTATION
Definition: libwps_internal.h:239
WPSEmbeddedObject::WPSEmbeddedObject
WPSEmbeddedObject()
empty constructor
Definition: libwps_internal.h:434
Vec2::operator+=
Vec2< T > & operator+=(Vec2< T > const &p)
operator+=
Definition: libwps_internal.h:599
libwps::LOWERCASE_ROMAN
Definition: libwps_internal.h:237
libwps::BULLET
Definition: libwps_internal.h:237
Box2::extend
void extend(T val)
extends the bdbox by (val, val) keeping the center
Definition: libwps_internal.h:817
libwps::DOC_TEXT_BOX
Definition: libwps_internal.h:239
WPSContentListener
Definition: WPSContentListener.h:44
WPSColor::operator=
WPSColor & operator=(uint32_t argb)
operator=
Definition: libwps_internal.h:278
libwps::readDouble4
bool readDouble4(RVNGInputStreamPtr &input, double &res, bool &isNaN)
read a double store with 4 bytes: mantisse 2.5 bytes, exponent 1.5 bytes
Definition: libwps_internal.cpp:90
WPSColumnProperties::m_attributes
uint32_t m_attributes
Definition: libwps_internal.h:261
libwps::DOC_NOTE
Definition: libwps_internal.h:239
WPSColor::getRed
unsigned char getRed() const
returns the red value
Definition: libwps_internal.h:313
Box2i
Box2< int > Box2i
Box2 of int.
Definition: libwps_internal.h:898
WPSColor::isBlack
bool isBlack() const
return true if the color is black
Definition: libwps_internal.h:323
WPSColor::operator<
bool operator<(WPSColor const &c) const
operator<
Definition: libwps_internal.h:343
WPSColor::operator>=
bool operator>=(WPSColor const &c) const
operator>=
Definition: libwps_internal.h:358
WPSEmbeddedObject::add
void add(librevenge::RVNGBinaryData const &binaryData, std::string type="image/pict")
add a picture
Definition: libwps_internal.h:458
Box2::max
Vec2< T > & max()
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:750
WPSField::Type
Type
Defines some basic type for field.
Definition: libwps_internal.h:482
WPSCell
a structure used to defined the cell position, and a format
Definition: WPSCell.h:251
WPSColumnDefinition::m_width
double m_width
Definition: libwps_internal.h:251
Box2::center
Vec2< T > center() const
the box center
Definition: libwps_internal.h:769
libwps::Justification
Justification
Definition: libwps_internal.h:240
WPSColumnDefinition::m_rightGutter
double m_rightGutter
Definition: libwps_internal.h:253
WPSSubDocument
virtual class to define a sub document
Definition: WPSSubDocument.h:33
WPSField::WPSField
WPSField(Type type)
basic constructor
Definition: libwps_internal.h:485
Vec2::operator==
bool operator==(Vec2< T > const &p) const
comparison==
Definition: libwps_internal.h:642
libwps::UPPERCASE
Definition: libwps_internal.h:237
libwps::readDouble10
bool readDouble10(RVNGInputStreamPtr &input, double &res, bool &isNaN)
read a double store with 10 bytes: mantisse 8 bytes, exponent 2 bytes
Definition: libwps_internal.cpp:224
WPSEmbeddedObject::isEmpty
bool isEmpty() const
return true if the picture contains no data
Definition: libwps_internal.h:448
WPSHeaderPtr
shared_ptr< WPSHeader > WPSHeaderPtr
shared pointer to WPSHeader
Definition: libwps_internal.h:108
libwps::DOC_TABLE
Definition: libwps_internal.h:239
Vec2::operator!=
bool operator!=(Vec2< T > const &p) const
comparison!=
Definition: libwps_internal.h:647
Vec2::y
T y() const
second element
Definition: libwps_internal.h:557
Vec2::Vec2
Vec2(T xx=0, T yy=0)
constructor
Definition: libwps_internal.h:547
Box2f
Box2< float > Box2f
Box2 of float.
Definition: libwps_internal.h:900
libwps::NoBreakWithNextBit
Definition: libwps_internal.h:243
libwps::readU32
uint32_t readU32(RVNGInputStreamPtr &input)
Definition: libwps_internal.h:177
WPSListenerPtr
shared_ptr< WPSListener > WPSListenerPtr
shared pointer to WPSListener
Definition: libwps_internal.h:104
Vec2::setX
void setX(T xx)
resets the first element
Definition: libwps_internal.h:581
Box2< int >::Map
std::map< Box2< int >, int, struct PosSizeLt > Map
Definition: libwps_internal.h:890
WPSBorder::WPSBorder
WPSBorder()
constructor
Definition: libwps_internal.h:382
libwps::NoBreakBit
Definition: libwps_internal.h:243
libwps::SubDocumentType
SubDocumentType
Definition: libwps_internal.h:239
libwps::NONE
Definition: libwps_internal.h:237
libwps::JustificationFull
Definition: libwps_internal.h:240
libwps::DOC_HEADER_FOOTER
Definition: libwps_internal.h:239
libwps::ParseException
Definition: libwps_internal.h:147
WPSBorder::m_widthsList
std::vector< double > m_widthsList
the different length used for each line/sep (if defined)
Definition: libwps_internal.h:420
WKSSubDocument
Basic class used to store a spreadsheet sub document.
Definition: WKSSubDocument.h:35
libwps::JustificationFullAllLines
Definition: libwps_internal.h:241
libwps::appendUnicode
void appendUnicode(uint32_t val, librevenge::RVNGString &buffer)
adds an unicode character to a string ( with correct encoding ).
Definition: libwps_internal.cpp:718
WPSColor::isWhite
bool isWhite() const
return true if the color is white
Definition: libwps_internal.h:328
WKSContentListenerPtr
shared_ptr< WKSContentListener > WKSContentListenerPtr
shared pointer to WKSContentListener
Definition: libwps_internal.h:113
WPSHeader
Definition: WPSHeader.h:31
Box2::max
Vec2< T > const & max() const
the maximum 2D point (in x and in y)
Definition: libwps_internal.h:740
WPSBorder::operator!=
bool operator!=(WPSBorder const &orig) const
operator!=
Definition: libwps_internal.h:400
libwps::DOC_NONE
Definition: libwps_internal.h:239
libwps::VersionException
Definition: libwps_internal.h:137
WPSColor::getBlue
unsigned char getBlue() const
returns the green value
Definition: libwps_internal.h:308
Box2::Box2
Box2(Box2< U > const &p)
generic constructor
Definition: libwps_internal.h:729
WPSColor::m_value
uint32_t m_value
the argb color
Definition: libwps_internal.h:368
Vec2::PosSizeLtY
internal struct used to create sorted map, sorted by Y
Definition: libwps_internal.h:697
Box2::m_pt
Vec2< T > m_pt[2]
the two extremities
Definition: libwps_internal.h:894
Vec2::x
T x() const
first element
Definition: libwps_internal.h:552
WPS_shared_ptr_noop_deleter::operator()
void operator()(T *)
Definition: libwps_internal.h:82
WPSBorder::Type
Type
the line repetition
Definition: libwps_internal.h:377
Vec2::add
void add(T dx, T dy)
increases the actuals values by dx and dy
Definition: libwps_internal.h:592
WPSEmbeddedObject::m_dataList
std::vector< librevenge::RVNGBinaryData > m_dataList
the picture content: one data by representation
Definition: libwps_internal.h:473
WPSColumnProperties::m_alignment
uint8_t m_alignment
Definition: libwps_internal.h:262
WPSColumnDefinition
Definition: libwps_internal.h:246
Vec2::PosSizeLtY::operator()
bool operator()(Vec2< T > const &s1, Vec2< T > const &s2) const
comparaison function
Definition: libwps_internal.h:700
WPSBorder::isEmpty
bool isEmpty() const
returns true if the border is empty
Definition: libwps_internal.h:388
WPSColumnProperties::WPSColumnProperties
WPSColumnProperties()
Definition: libwps_internal.h:258
Vec2::operator-=
Vec2< T > & operator-=(Vec2< T > const &p)
operator-=
Definition: libwps_internal.h:606
WPSBorder::m_color
WPSColor m_color
the border color
Definition: libwps_internal.h:422
Vec2::operator*=
Vec2< T > & operator*=(U scale)
generic operator*=
Definition: libwps_internal.h:614
libwps::NumberingType
NumberingType
Definition: libwps_internal.h:237
libwps::read32
int32_t read32(RVNGInputStreamPtr &input)
Definition: libwps_internal.h:190
WPSColor::value
uint32_t value() const
return the rgba value
Definition: libwps_internal.h:298
WPSColor::operator!=
bool operator!=(WPSColor const &c) const
operator!=
Definition: libwps_internal.h:338
Vec2::cmpY
int cmpY(Vec2< T > const &p) const
a comparison function: which first compares y then x
Definition: libwps_internal.h:666
RVNGInputStreamPtr
shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr
shared pointer to librevenge::RVNGInputStream
Definition: libwps_internal.h:87
libwps::readDouble4Inv
bool readDouble4Inv(RVNGInputStreamPtr &input, double &res, bool &isNaN)
read a double store with 4 bytes: exponent 3.5 bytes, mantisse 0.5 bytes
Definition: libwps_internal.cpp:303
Vec2i
Vec2< int > Vec2i
Vec2 of int.
Definition: libwps_internal.h:712
WPSColor
the class to store a color
Definition: libwps_internal.h:266
WPSEmbeddedObject::~WPSEmbeddedObject
virtual ~WPSEmbeddedObject()
destructor
Definition: libwps_internal.h:444
WPSBorder::Pos
Pos
Definition: libwps_internal.h:378
libwps::JustificationRight
Definition: libwps_internal.h:241
Vec2::Vec2
Vec2(Vec2< U > const &p)
generic copy constructor
Definition: libwps_internal.h:549
Box2::operator==
bool operator==(Box2< T > const &p) const
comparison operator==
Definition: libwps_internal.h:844
Vec2::operator[]
T operator[](int c) const
operator[]
Definition: libwps_internal.h:562
libwps::readData
bool readData(RVNGInputStreamPtr &input, unsigned long size, librevenge::RVNGBinaryData &data)
try to read sz bytes from input and store them in a librevenge::RVNGBinaryData
Definition: libwps_internal.cpp:332
WPSColor::getGreen
unsigned char getGreen() const
returns the green value
Definition: libwps_internal.h:318
Box2::resizeFromMax
void resizeFromMax(Vec2< T > const &sz)
resize the box keeping the maximum
Definition: libwps_internal.h:797
WPSColor::operator<=
bool operator<=(WPSColor const &c) const
operator<=
Definition: libwps_internal.h:348
libwps::readDataToEnd
bool readDataToEnd(RVNGInputStreamPtr &input, librevenge::RVNGBinaryData &data)
try to read the last bytes from input and store them in a librevenge::RVNGBinaryData ...
Definition: libwps_internal.cpp:346
Box2::scale
void scale(U factor)
scales all points of the box by factor
Definition: libwps_internal.h:810
libwps::numberingTypeToString
std::string numberingTypeToString(NumberingType type)
Definition: libwps_internal.cpp:357
WPSColor::operator>
bool operator>(WPSColor const &c) const
operator>
Definition: libwps_internal.h:353
Box2::setMax
void setMax(Vec2< T > const &y)
resets the maximum point
Definition: libwps_internal.h:786
Box2::getUnion
Box2< T > getUnion(Box2< T > const &box) const
returns the union between this and box
Definition: libwps_internal.h:823
WPSBorder::Style
Style
the line style
Definition: libwps_internal.h:375
WPSBorder::operator==
bool operator==(WPSBorder const &orig) const
operator==
Definition: libwps_internal.h:394
Box2::setMin
void setMin(Vec2< T > const &x)
resets the minimum point
Definition: libwps_internal.h:781
WPSEmbeddedObject
small class use to define a embedded object
Definition: libwps_internal.h:431
Box2::Box2
Box2(Vec2< T > minPt=Vec2< T >(), Vec2< T > maxPt=Vec2< T >())
constructor
Definition: libwps_internal.h:723
libwps::FileException
Definition: libwps_internal.h:142
WPSColumnDefinition::WPSColumnDefinition
WPSColumnDefinition()
Definition: libwps_internal.h:248
WPSBorder::m_style
Style m_style
the border style
Definition: libwps_internal.h:412
libwps::JustificationLeft
Definition: libwps_internal.h:240
libwps::UPPERCASE_ROMAN
Definition: libwps_internal.h:237
WKSSubDocumentPtr
shared_ptr< WKSSubDocument > WKSSubDocumentPtr
shared pointer to WKSSubDocument
Definition: libwps_internal.h:115
libwps::readDouble8
bool readDouble8(RVNGInputStreamPtr &input, double &res, bool &isNaN)
read a double store with 8 bytes: mantisse 6.5 bytes, exponent 1.5 bytes
Definition: libwps_internal.cpp:173
libwps::JustificationCenter
Definition: libwps_internal.h:240
WPSEntry
basic class to store an entry in a file This contained :
Definition: WPSEntry.h:37
Vec2
small class which defines a vector with 2 elements
Definition: libwps_internal.h:543
Vec2::PosSizeLtX::operator()
bool operator()(Vec2< T > const &s1, Vec2< T > const &s2) const
comparaison function
Definition: libwps_internal.h:688
libwps::ARABIC
Definition: libwps_internal.h:237
Vec2::operator*
friend Vec2< T > operator*(U scale, Vec2< T > const &p1)
generic operator*
Definition: libwps_internal.h:635
WPSPosition
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: WPSPosition.h:39
Box2::size
Vec2< T > size() const
the box size
Definition: libwps_internal.h:764
WPSBorder::m_extra
std::string m_extra
extra data ( if needed)
Definition: libwps_internal.h:424
WPSCellPtr
shared_ptr< WPSCell > WPSCellPtr
shared pointer to WPSCell
Definition: libwps_internal.h:99
libwps::readDouble2Inv
bool readDouble2Inv(RVNGInputStreamPtr &input, double &res, bool &isNaN)
read a double store with 2 bytes: exponent 1.5 bytes, kind of mantisse 0.5 bytes
Definition: libwps_internal.cpp:273
Box2::getIntersection
Box2< T > getIntersection(Box2< T > const &box) const
returns the intersection between this and box
Definition: libwps_internal.h:833
operator<<
std::ostream & operator<<(std::ostream &o, WPSColor const &c)
Definition: libwps_internal.cpp:401
WPSColor::WPSColor
WPSColor(uint32_t argb=0)
constructor
Definition: libwps_internal.h:269
Vec2::m_y
T m_y
second element
Definition: libwps_internal.h:706
WPS_shared_ptr_noop_deleter
a noop deleter used to transform a librevenge pointer in a false shared_ptr
Definition: libwps_internal.h:80
Box2::PosSizeLt::operator()
bool operator()(Box2< T > const &s1, Box2< T > const &s2) const
comparaison function
Definition: libwps_internal.h:882
WPSBorder::m_type
Type m_type
the border repetition
Definition: libwps_internal.h:414
WPSField::m_DTFormat
std::string m_DTFormat
the date/time format using strftime format if defined (see strftime)
Definition: libwps_internal.h:495
WKSContentListener
Definition: WKSContentListener.h:50
Vec2::cmp
int cmp(Vec2< T > const &p) const
a comparison function: which first compares x then y
Definition: libwps_internal.h:657
Vec2b
Vec2< bool > Vec2b
Vec2 of bool.
Definition: libwps_internal.h:710
WPSColor::getAlpha
unsigned char getAlpha() const
returns the alpha value
Definition: libwps_internal.h:303
Box2::resizeFromCenter
void resizeFromCenter(Vec2< T > const &sz)
resize the box keeping the center
Definition: libwps_internal.h:802
Box2::min
Vec2< T > & min()
the minimum 2D point (in x and in y)
Definition: libwps_internal.h:745
Vec2::operator+
friend Vec2< T > operator+(Vec2< T > const &p1, Vec2< T > const &p2)
operator+
Definition: libwps_internal.h:622