Main Page
Namespaces
Classes
Files
File List
File Members
MWAWPictBasic.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
/* This header contains code specific to manage basic picture (line, rectangle, ...)
35
*
36
* Note: all unit are points
37
*
38
*/
39
40
#ifndef MWAW_PICT_BASIC
41
# define MWAW_PICT_BASIC
42
43
# include <assert.h>
44
# include <ostream>
45
# include <string>
46
# include <vector>
47
48
# include "
libmwaw_internal.hxx
"
49
# include "
MWAWPict.hxx
"
50
51
class
MWAWPropertyHandlerEncoder
;
52
53
/*
54
libmwaw:document w="..pt" h="..pt"
55
libmwaw:graphicStyle lineColor="#......" lineWidth="..pt" lineFill="solid/none"
56
surfaceColor="#......" surfaceFill="solid/none"
57
startArrow="true/false" startArrowWidth="..pt"
58
endArrow="true/false" endArrowWidth="..pt" /
59
libmwaw:drawLine x0=".." y0=".." x1=".." y1=".." /
60
libmwaw:drawRectangle x0=".." y0=".." w=".." h=".." [ rw=".." rh=".." ] /
61
libmwaw:drawCircle x0=".." y0=".." w=".." h=".." /
62
libmwaw:drawArc x0=".." y0=".." w=".." h=".." angle0=".." angle1=".." /
63
libmwaw:drawPolygon x0=".." y0=".." ... x{N-1}=".." y{N-1}=".." w=".." h=".." /
64
libmwaw:drawPath path=".." w=".." h=".." /
65
/libmwaw:document
66
*/
67
69
class
MWAWPictBasic
:
public
MWAWPict
70
{
71
public
:
73
virtual
~MWAWPictBasic
() {}
74
76
enum
SubType
{
Line
,
Rectangle
,
Polygon
,
Circle
,
Arc
,
Path
};
78
virtual
Type
getType
()
const
{
79
return
Basic
;
80
}
82
virtual
SubType
getSubType
()
const
= 0;
83
85
void
setLineWidth
(
float
w) {
86
m_lineWidth
= w;
87
extendBDBox
(
m_lineWidth
, 0);
88
}
91
void
setLineColor
(
MWAWColor
const
&col) {
92
m_lineColor
= col;
93
}
94
96
void
setSurfaceColor
(
MWAWColor
const
&col,
bool
hasColor =
true
) {
97
m_surfaceColor
= col;
98
m_surfaceHasColor
= hasColor;
99
}
100
bool
hasSurfaceColor
()
const
{
101
return
m_surfaceHasColor
;
102
}
103
105
virtual
bool
getBinary
(WPXBinaryData &data, std::string &s)
const
{
106
if
(!
getODGBinary
(data))
return
false
;
107
s =
"image/mwaw-odg"
;
108
return
true
;
109
}
111
virtual
bool
getODGBinary
(WPXBinaryData &)
const
{
112
return
false
;
113
}
114
118
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
119
int
diff =
MWAWPict::cmp
(a);
120
if
(diff)
return
diff;
121
122
MWAWPictBasic
const
&aPict =
static_cast<
MWAWPictBasic
const
&
>
(a);
123
// the type
124
diff =
getSubType
() - aPict.
getSubType
();
125
if
(diff)
return
(diff < 0) ? -1 : 1;
126
127
float
diffF =
m_lineWidth
- aPict.
m_lineWidth
;
128
if
(diffF < 0)
return
-1;
129
if
(diffF > 0)
return
1;
130
131
if
(
m_lineColor
< aPict.
m_lineColor
)
return
-1;
132
if
(
m_lineColor
> aPict.
m_lineColor
)
return
1;
133
if
(
m_surfaceColor
< aPict.
m_surfaceColor
)
return
-1;
134
if
(
m_surfaceColor
> aPict.
m_surfaceColor
)
return
1;
135
for
(
int
c = 0; c < 2; c++) {
136
diffF =
m_extend
[c]-aPict.
m_extend
[c];
137
if
(diffF < 0)
return
-1;
138
if
(diffF > 0)
return
1;
139
}
140
if
(
m_surfaceHasColor
!= aPict.
m_surfaceHasColor
)
141
return
m_surfaceHasColor
;
142
return
0;
143
}
144
protected
:
146
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
= 0;
147
149
void
getStyle1DProperty
(WPXPropertyList &list)
const
;
151
void
getStyle2DProperty
(WPXPropertyList &list)
const
;
152
154
void
startODG
(
MWAWPropertyHandlerEncoder
&doc)
const
;
156
void
endODG
(
MWAWPropertyHandlerEncoder
&doc)
const
;
157
159
// - \param id=0 corresponds to linewidth
160
// - \param id=1 corresponds to a second extension (arrow)
161
void
extendBDBox
(
float
val,
int
id
) {
162
assert(
id
>=0&&
id
<=1);
163
m_extend
[id] = val;
164
MWAWPict::extendBDBox
(
m_extend
[0]+
m_extend
[1]);
165
}
166
168
MWAWPictBasic
() :
m_lineWidth
(1.0),
m_lineColor
(
MWAWColor
::black()),
m_surfaceColor
(
MWAWColor
::white()),
m_surfaceHasColor
(false) {
169
for
(
int
c = 0; c < 2; c++)
m_extend
[c]=0;
170
setLineWidth
(1.0);
171
}
173
MWAWPictBasic
(
MWAWPictBasic
const
&p) :
MWAWPict
(),
m_lineWidth
(1.0),
m_lineColor
(
MWAWColor
::black()),
m_surfaceColor
(
MWAWColor
::white()),
m_surfaceHasColor
(false) {
174
*
this
=p;
175
}
177
MWAWPictBasic
&
operator=
(
MWAWPictBasic
const
&p) {
178
if
(&p ==
this
)
return
*
this
;
179
MWAWPict::operator=
(p);
180
m_lineWidth
= p.
m_lineWidth
;
181
m_lineColor
= p.
m_lineColor
;
182
m_surfaceColor
= p.
m_surfaceColor
;
183
for
(
int
c=0; c < 2; c++)
m_extend
[c] = p.
m_extend
[c];
184
m_surfaceHasColor
= p.
m_surfaceHasColor
;
185
return
*
this
;
186
}
187
188
private
:
190
float
m_lineWidth
;
192
MWAWColor
m_lineColor
;
194
MWAWColor
m_surfaceColor
;
196
bool
m_surfaceHasColor
;
198
float
m_extend
[2];
199
};
200
202
class
MWAWPictLine
:
public
MWAWPictBasic
203
{
204
public
:
206
MWAWPictLine
(
Vec2f
orig,
Vec2f
end) :
MWAWPictBasic
() {
207
m_extremity
[0] = orig;
208
m_extremity
[1] = end;
209
m_arrows
[0] =
m_arrows
[1] =
false
;
210
setBdBox
(
getBdBox
(2,
m_extremity
));
211
}
213
virtual
~MWAWPictLine
() {}
215
void
setArrow
(
int
v,
bool
val) {
216
assert(v>=0 && v<=1);
217
m_arrows
[v]=val;
218
extendBDBox
((
m_arrows
[0] ||
m_arrows
[1]) ? 5 : 0, 1);
219
}
220
222
virtual
bool
getODGBinary
(WPXBinaryData &res)
const
;
223
224
protected
:
226
virtual
SubType
getSubType
()
const
{
227
return
Line
;
228
}
230
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
;
232
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
233
int
diff =
MWAWPictBasic::cmp
(a);
234
if
(diff)
return
diff;
235
MWAWPictLine
const
&aLine =
static_cast<
MWAWPictLine
const
&
>
(a);
236
for
(
int
c = 0; c < 2; c++) {
237
diff =
m_extremity
[c].
cmpY
(aLine.
m_extremity
[c]);
238
if
(diff)
return
diff;
239
}
240
for
(
int
c = 0; c < 2; c++) {
241
diff =
m_arrows
[c]-aLine.
m_arrows
[c];
242
if
(diff)
return
(diff < 0) ? -1 : 1;
243
}
244
return
0;
245
}
246
247
249
Vec2f
m_extremity
[2];
251
bool
m_arrows
[2];
252
};
253
255
class
MWAWPictRectangle
:
public
MWAWPictBasic
256
{
257
public
:
259
MWAWPictRectangle
(
Box2f
box) :
MWAWPictBasic
(),
m_rectBox
(box) {
260
setBdBox
(box);
261
for
(
int
i = 0; i < 2; i++)
m_cornerWidth
[i] = 0;
262
}
264
virtual
~MWAWPictRectangle
() {}
265
267
void
setRoundCornerWidth
(
int
w) {
268
m_cornerWidth
[0] =
m_cornerWidth
[1] = w;
269
}
270
272
void
setRoundCornerWidth
(
int
xw,
int
yw) {
273
m_cornerWidth
[0] = xw;
274
m_cornerWidth
[1] = yw;
275
}
276
278
virtual
bool
getODGBinary
(WPXBinaryData &res)
const
;
279
280
protected
:
282
virtual
SubType
getSubType
()
const
{
283
return
Rectangle
;
284
}
286
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
;
288
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
289
int
diff =
MWAWPictBasic::cmp
(a);
290
if
(diff)
return
diff;
291
MWAWPictRectangle
const
&aRect =
static_cast<
MWAWPictRectangle
const
&
>
(a);
292
for
(
int
i = 0; i < 2; i++) {
293
diff =
m_cornerWidth
[i] - aRect.
m_cornerWidth
[i];
294
if
(diff)
return
(diff < 0) ? -1 : 1;
295
}
296
return
0;
297
}
298
300
int
m_cornerWidth
[2];
302
Box2f
m_rectBox
;
303
};
304
306
class
MWAWPictCircle
:
public
MWAWPictBasic
307
{
308
public
:
310
MWAWPictCircle
(
Box2f
box) :
MWAWPictBasic
(),
m_circleBox
(box) {
311
setBdBox
(box);
312
}
314
virtual
~MWAWPictCircle
() {}
315
317
virtual
bool
getODGBinary
(WPXBinaryData &res)
const
;
318
319
protected
:
321
virtual
SubType
getSubType
()
const
{
322
return
Circle
;
323
}
325
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
;
327
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
328
return
MWAWPictBasic::cmp
(a);
329
}
330
331
// corner point
332
Box2f
m_circleBox
;
333
};
334
336
class
MWAWPictArc
:
public
MWAWPictBasic
337
{
338
public
:
341
MWAWPictArc
(
Box2f
box,
Box2f
ellBox,
float
ang1,
float
ang2) :
MWAWPictBasic
(),
m_circleBox
(ellBox) {
342
setBdBox
(box);
343
m_angle
[0] = ang1;
344
m_angle
[1] = ang2;
345
}
347
virtual
~MWAWPictArc
() {}
348
350
virtual
bool
getODGBinary
(WPXBinaryData &res)
const
;
351
352
protected
:
354
virtual
SubType
getSubType
()
const
{
355
return
Arc
;
356
}
358
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
;
360
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
361
int
diff =
MWAWPictBasic::cmp
(a);
362
if
(diff)
return
diff;
363
MWAWPictArc
const
&aArc =
static_cast<
MWAWPictArc
const
&
>
(a);
364
// first check the bdbox
365
diff =
m_circleBox
.
cmp
(aArc.
m_circleBox
);
366
if
(diff)
return
diff;
367
for
(
int
c = 0; c < 2; c++) {
368
float
diffF =
m_angle
[c]-aArc.
m_angle
[c];
369
if
(diffF < 0)
return
-1;
370
if
(diffF > 0)
return
1;
371
}
372
return
0;
373
}
374
376
Box2f
m_circleBox
;
377
379
float
m_angle
[2];
380
};
381
383
class
MWAWPictPath
:
public
MWAWPictBasic
384
{
385
public
:
387
MWAWPictPath
(
Box2f
bdBox, std::string path) :
MWAWPictBasic
(),
m_path
(path) {
388
setBdBox
(bdBox);
389
}
391
virtual
~MWAWPictPath
() {}
392
394
virtual
bool
getODGBinary
(WPXBinaryData &res)
const
;
395
396
protected
:
398
virtual
SubType
getSubType
()
const
{
399
return
Path
;
400
}
402
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
;
404
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
405
int
diff =
MWAWPictBasic::cmp
(a);
406
if
(diff)
return
diff;
407
MWAWPictPath
const
&aPath =
static_cast<
MWAWPictPath
const
&
>
(a);
408
// first check the bdbox
409
diff =
m_path
.compare(aPath.
m_path
);
410
if
(diff)
return
diff;
411
return
0;
412
}
413
415
std::string
m_path
;
416
};
417
419
class
MWAWPictPolygon
:
public
MWAWPictBasic
420
{
421
public
:
424
MWAWPictPolygon
(
Box2f
bdBox, std::vector<Vec2f>
const
&lVect) :
MWAWPictBasic
(),
m_verticesList
(lVect) {
425
setBdBox
(bdBox);
426
}
428
virtual
~MWAWPictPolygon
() {}
429
431
virtual
bool
getODGBinary
(WPXBinaryData &res)
const
;
432
433
protected
:
435
virtual
SubType
getSubType
()
const
{
436
return
Polygon
;
437
}
439
virtual
void
getGraphicStyleProperty
(WPXPropertyList &list)
const
;
441
virtual
int
cmp
(
MWAWPict
const
&a)
const
{
442
int
diff =
MWAWPictBasic::cmp
(a);
443
if
(diff)
return
diff;
444
MWAWPictPolygon
const
&aPoly =
static_cast<
MWAWPictPolygon
const
&
>
(a);
445
if
(
m_verticesList
.size()<aPoly.
m_verticesList
.size())
446
return
-1;
447
if
(
m_verticesList
.size()>aPoly.
m_verticesList
.size())
448
return
1;
449
450
// check the vertices
451
for
(
size_t
c = 0; c <
m_verticesList
.size(); c++) {
452
diff =
m_verticesList
[c].cmpY(aPoly.
m_verticesList
[c]);
453
if
(diff)
return
diff;
454
}
455
return
0;
456
}
457
459
std::vector<Vec2f>
m_verticesList
;
460
};
461
462
#endif
463
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Generated on Tue Oct 8 2013 19:56:45 for libmwaw by
doxygen
1.8.4