/src/libmwaw/src/lib/MWAWPict.hxx
Line | Count | Source |
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 <ostream> |
46 | | # include <vector> |
47 | | |
48 | | # include "libmwaw_internal.hxx" |
49 | | |
50 | | /** \brief Generic function used to define/store a picture */ |
51 | | class MWAWPict |
52 | | { |
53 | | public: |
54 | | //! virtual destructor |
55 | | virtual ~MWAWPict(); |
56 | | |
57 | | /*! \enum Type |
58 | | * \brief the different picture types: |
59 | | * - pictData: a classic format of file (AppleŠ Pict, ...) |
60 | | * - bitmap: a image |
61 | | * - ... |
62 | | */ |
63 | | enum Type { PictData, Bitmap, Unknown }; |
64 | | //! returns the picture type |
65 | | virtual Type getType() const = 0; |
66 | | |
67 | | /*! \brief an enum to defined the result of a parsing |
68 | | * use by some picture's classes which can read their data |
69 | | * - R_OK_EMPTY: data ok but empty content, |
70 | | * - R_MAYBE: can not check if the data are valid |
71 | | * - ... |
72 | | */ |
73 | | enum ReadResult { MWAW_R_BAD=0, MWAW_R_OK, MWAW_R_OK_EMPTY, MWAW_R_MAYBE }; |
74 | | |
75 | | //! returns the bdbox of the picture |
76 | | MWAWBox2f getBdBox() const |
77 | 1.18M | { |
78 | 1.18M | MWAWBox2f res(m_bdbox); |
79 | 1.18M | res.extend(m_bdBoxExt); |
80 | 1.18M | return res; |
81 | 1.18M | } |
82 | | |
83 | | //! sets the bdbox of the picture |
84 | | void setBdBox(MWAWBox2f const &box) |
85 | 3.08M | { |
86 | 3.08M | m_bdbox = box; |
87 | 3.08M | } |
88 | | |
89 | | /** tries to convert the picture in a binary data : |
90 | | * - either a basic image/pict |
91 | | * - or an encrypted pict in ODG : "image/mwaw-odg" |
92 | | */ |
93 | | virtual bool getBinary(MWAWEmbeddedObject &) const |
94 | 0 | { |
95 | 0 | return false; |
96 | 0 | } |
97 | | |
98 | | /** \brief a virtual function used to obtain a strict order, |
99 | | * must be redefined in the subs class |
100 | | */ |
101 | | virtual int cmp(MWAWPict const &a) const |
102 | 0 | { |
103 | | // first compare the bdbox |
104 | 0 | if (m_bdbox!=a.m_bdbox) |
105 | 0 | return m_bdbox < a.m_bdbox ? -1 : 1; |
106 | | // the type |
107 | 0 | int diff = getType() - a.getType(); |
108 | 0 | if (diff) return (diff < 0) ? -1 : 1; |
109 | | |
110 | 0 | return 0; |
111 | 0 | } |
112 | | protected: |
113 | | //! computes the minimum and maximum of a list of point |
114 | | static MWAWBox2f getBdBox(int numPt, MWAWVec2f const *pt) |
115 | 0 | { |
116 | 0 | if (numPt <= 0) { |
117 | 0 | return MWAWBox2f(); |
118 | 0 | } |
119 | 0 |
|
120 | 0 | float minV[2], maxV[2]; |
121 | 0 | for (int c = 0; c < 2; c++) minV[c] = maxV[c] = pt[0][c]; |
122 | 0 |
|
123 | 0 | for (int i = 1; i < numPt; i++) { |
124 | 0 | for (int c = 0; c < 2; c++) { |
125 | 0 | float v = pt[i][c]; |
126 | 0 | if (v < minV[c]) minV[c] = v; |
127 | 0 | else if (v > maxV[c]) maxV[c] = v; |
128 | 0 | } |
129 | 0 | } |
130 | 0 |
|
131 | 0 | return MWAWBox2f(MWAWVec2f(minV[0], minV[1]), MWAWVec2f(maxV[0], maxV[1])); |
132 | 0 | } |
133 | | |
134 | | // a function to extend the bdbox |
135 | | |
136 | | //! udaptes the bdbox, by extended it by (val-previousVal) |
137 | | void extendBDBox(float val) |
138 | 288k | { |
139 | 288k | m_bdBoxExt = val; |
140 | 288k | } |
141 | | |
142 | | //! protected constructor must not be called directly |
143 | | MWAWPict() |
144 | 4.81M | : m_bdbox() |
145 | 4.81M | , m_bdBoxExt(0.0) |
146 | 4.81M | { |
147 | 4.81M | } |
148 | | //! protected constructor must not be called directly |
149 | | explicit MWAWPict(MWAWPict const &p) |
150 | | : m_bdbox() |
151 | | , m_bdBoxExt(0.0) |
152 | 0 | { |
153 | 0 | *this=p; |
154 | 0 | } |
155 | | //! protected operator= must not be called directly |
156 | | MWAWPict &operator=(MWAWPict const &p) |
157 | 0 | { |
158 | 0 | if (&p == this) return *this; |
159 | 0 | m_bdbox = p.m_bdbox; |
160 | 0 | m_bdBoxExt = p.m_bdBoxExt; |
161 | 0 | return *this; |
162 | 0 | } |
163 | | |
164 | | private: |
165 | | //! the bdbox (min and max pt) |
166 | | MWAWBox2f m_bdbox; |
167 | | //! the actual extension of the original box, |
168 | | float m_bdBoxExt; |
169 | | }; |
170 | | |
171 | | #endif |
172 | | // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |