MWAWPict.hxx Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

MWAWPict.hxx
Go to the documentation of this file.
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 (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 /*
35 * This header contains code specific to manage basic picture (line, rectangle, ...)
36 *
37 * Note: generic class for all sort of pict
38 * - PictBitmap: regroup some classes used to store bitmap
39 * - PictData: regroup the data which can be read via a librevenge::RVNGBinaryData
40 */
41
42 #ifndef MWAW_PICT
43 # define MWAW_PICT
44
45 # include <assert.h>
46 # include <ostream>
47 # include <vector>
48
49 # include "libmwaw_internal.hxx"
50
52 class MWAWPict
53 {
54 public:
56 virtual ~MWAWPict() {}
57
64 enum Type { PictData, Bitmap, Unknown };
66 virtual Type getType() const = 0;
67
74 enum ReadResult { MWAW_R_BAD=0, MWAW_R_OK, MWAW_R_OK_EMPTY, MWAW_R_MAYBE };
75
77 Box2f getBdBox() const
78 {
79 Box2f res(m_bdbox);
80 res.extend(m_bdBoxExt);
81 return res;
82 }
83
85 void setBdBox(Box2f const &box)
86 {
87 m_bdbox = box;
88 }
89
94 virtual bool getBinary(librevenge::RVNGBinaryData &, std::string &) const
95 {
96 return false;
97 }
98
102 virtual int cmp(MWAWPict const &a) const
103 {
104 // first compare the bdbox
105 int diff = m_bdbox.cmp(a.m_bdbox);
106 if (diff) return diff;
107 // the type
108 diff = getType() - a.getType();
109 if (diff) return (diff < 0) ? -1 : 1;
110
111 return 0;
112 }
113 protected:
115 static Box2f getBdBox(int numPt, Vec2f const *pt)
116 {
117 if (numPt <= 0) {
118 return Box2f();
119 }
120
121 float minV[2], maxV[2];
122 for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c];
123
124 for (int i = 1; i < numPt; i++) {
125 for (int c = 0; c < 2; c++) {
126 float v = pt[i][c];
127 if (v < minV[c]) minV[c] = v;
128 else if (v > maxV[c]) maxV[c] = v;
129 }
130 }
131
132 return Box2f(Vec2f(minV[0], minV[1]), Vec2f(maxV[0], maxV[1]));
133 }
134
135 // a function to extend the bdbox
136
138 void extendBDBox(float val)
139 {
140 m_bdBoxExt = val;
141 }
142
144 MWAWPict() : m_bdbox(), m_bdBoxExt(0.0) {}
146 MWAWPict(MWAWPict const &p) : m_bdbox(), m_bdBoxExt(0.0)
147 {
148 *this=p;
149 }
151 MWAWPict &operator=(MWAWPict const &p)
152 {
153 if (&p == this) return *this;
154 m_bdbox = p.m_bdbox;
155 m_bdBoxExt = p.m_bdBoxExt;
156 return *this;
157 }
158
159 private:
161 Box2f m_bdbox;
163 float m_bdBoxExt;
164 };
165
166 #endif
167 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
libmwaw_internal.hxx
Box2::cmp
int cmp(Box2< T > const &p) const
comparison function : fist sorts min by Y,X values then max extremity
Definition: libmwaw_internal.hxx:1033
Vec2f
Vec2< float > Vec2f
Vec2 of float.
Definition: libmwaw_internal.hxx:711
Box2< float >
MWAWPict::ReadResult
ReadResult
an enum to defined the result of a parsing use by some picture's classes which can read their data ...
Definition: MWAWPict.hxx:74
Box2::extend
void extend(T val)
extends the bdbox by (val, val) keeping the center
Definition: libmwaw_internal.hxx:990
Box2f
Box2< float > Box2f
Box2 of float.
Definition: libmwaw_internal.hxx:1072
MWAWPict::~MWAWPict
virtual ~MWAWPict()
virtual destructor
Definition: MWAWPict.hxx:56
MWAWPict::cmp
virtual int cmp(MWAWPict const &a) const
a virtual function used to obtain a strict order, must be redefined in the subs class ...
Definition: MWAWPict.hxx:102
MWAWPict::MWAW_R_OK
Definition: MWAWPict.hxx:74
MWAWPict::MWAWPict
MWAWPict(MWAWPict const &p)
protected constructor must not be called directly
Definition: MWAWPict.hxx:146
MWAWPict::m_bdbox
Box2f m_bdbox
the bdbox (min and max pt)
Definition: MWAWPict.hxx:161
MWAWPict::MWAW_R_OK_EMPTY
Definition: MWAWPict.hxx:74
MWAWPict::m_bdBoxExt
float m_bdBoxExt
the actual extension of the original box,
Definition: MWAWPict.hxx:163
MWAWPict::setBdBox
void setBdBox(Box2f const &box)
sets the bdbox of the picture
Definition: MWAWPict.hxx:85
MWAWPict::Type
Type
the different picture types:
Definition: MWAWPict.hxx:64
MWAWPict::getBinary
virtual bool getBinary(librevenge::RVNGBinaryData &, std::string &) const
tries to convert the picture in a binary data :
Definition: MWAWPict.hxx:94
MWAWPict::PictData
Definition: MWAWPict.hxx:64
MWAWPict::getBdBox
static Box2f getBdBox(int numPt, Vec2f const *pt)
computes the minimum and maximum of a list of point
Definition: MWAWPict.hxx:115
MWAWPict::MWAW_R_BAD
Definition: MWAWPict.hxx:74
MWAWPict::Unknown
Definition: MWAWPict.hxx:64
MWAWPict::getBdBox
Box2f getBdBox() const
returns the bdbox of the picture
Definition: MWAWPict.hxx:77
MWAWPict::MWAWPict
MWAWPict()
protected constructor must not be called directly
Definition: MWAWPict.hxx:144
MWAWPict::MWAW_R_MAYBE
Definition: MWAWPict.hxx:74
Vec2< float >
MWAWPict::Bitmap
Definition: MWAWPict.hxx:64
MWAWPict::getType
virtual Type getType() const =0
returns the picture type
MWAWPict::extendBDBox
void extendBDBox(float val)
udaptes the bdbox, by extended it by (val-previousVal)
Definition: MWAWPict.hxx:138
MWAWPict
Generic function used to define/store a picture.
Definition: MWAWPict.hxx:52
MWAWPict::operator=
MWAWPict & operator=(MWAWPict const &p)
protected operator= must not be called directly
Definition: MWAWPict.hxx:151