Main Page
Namespaces
Classes
Files
File List
File Members
MWAWGraphicStyle.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
#ifndef MWAW_GRAPHIC_STYLE
34
# define MWAW_GRAPHIC_STYLE
35
# include <ostream>
36
# include <string>
37
# include <vector>
38
39
# include "libwpd/libwpd.h"
40
# include "
libmwaw_internal.hxx
"
41
47
class
MWAWGraphicStyle
48
{
49
public
:
51
enum
LineCap
{
C_Butt
,
C_Square
,
C_Round
};
53
enum
LineJoin
{
J_Miter
,
J_Round
,
J_Bevel
};
55
enum
GradientType
{
G_None
,
G_Axial
,
G_Linear
,
G_Radial
,
G_Rectangular
,
G_Square
,
G_Ellipsoid
};
56
58
struct
GradientStop
{
60
GradientStop
(
float
offset=0.0,
MWAWColor
const
&col=
MWAWColor::black
(),
float
opacity=1.0) :
61
m_offset
(offset),
m_color
(col),
m_opacity
(opacity) {
62
}
64
int
cmp
(
GradientStop
const
&a)
const
{
65
if
(
m_offset
< a.
m_offset
)
return
-1;
66
if
(
m_offset
> a.
m_offset
)
return
1;
67
if
(
m_color
< a.
m_color
)
return
-1;
68
if
(
m_color
> a.
m_color
)
return
1;
69
if
(
m_opacity
< a.
m_opacity
)
return
-1;
70
if
(
m_opacity
> a.
m_opacity
)
return
1;
71
return
0;
72
}
74
friend
std::ostream &
operator<<
(std::ostream &o,
GradientStop
const
&st) {
75
o <<
"offset="
<< st.
m_offset
<<
","
;
76
o <<
"color="
<< st.
m_color
<<
","
;
77
if
(st.
m_opacity
<1.0)
78
o <<
"opacity="
<< st.
m_opacity
*100.f <<
"%,"
;
79
return
o;
80
}
82
float
m_offset
;
84
MWAWColor
m_color
;
86
float
m_opacity
;
87
};
92
struct
Pattern
{
94
Pattern
() :
m_dim
(0,0),
m_data
(),
m_picture
(),
m_pictureMime
(
""
),
m_pictureAverageColor
(
MWAWColor
::white()) {
95
m_colors
[0]=
MWAWColor::black
();
96
m_colors
[1]=
MWAWColor::white
();
97
}
99
Pattern
(
Vec2i
dim, WPXBinaryData
const
&picture, std::string
const
&mime,
MWAWColor
const
&avColor) :
100
m_dim
(dim),
m_data
(),
m_picture
(picture),
m_pictureMime
(mime),
m_pictureAverageColor
(avColor) {
101
m_colors
[0]=
MWAWColor::black
();
102
m_colors
[1]=
MWAWColor::white
();
103
}
105
virtual
~Pattern
() {}
107
bool
empty
()
const
{
108
if
(
m_dim
[0]==0 ||
m_dim
[1]==0)
return
true
;
109
if
(
m_picture
.size())
return
false
;
110
if
(
m_dim
[0]!=8 &&
m_dim
[0]!=16 &&
m_dim
[0]!=32)
return
true
;
111
return
m_data
.size()!=size_t((
m_dim
[0]/8)*
m_dim
[1]);
112
}
114
bool
getAverageColor
(
MWAWColor
&col)
const
;
116
bool
getUniqueColor
(
MWAWColor
&col)
const
;
118
bool
getBinary
(WPXBinaryData &data, std::string &type)
const
;
119
121
int
cmp
(
Pattern
const
&a)
const
{
122
int
diff =
m_dim
.
cmp
(a.
m_dim
);
123
if
(diff)
return
diff;
124
if
(
m_data
.size() < a.
m_data
.size())
return
-1;
125
if
(
m_data
.size() > a.
m_data
.size())
return
1;
126
for
(
size_t
h=0; h <
m_data
.size(); ++h) {
127
if
(
m_data
[h]<a.
m_data
[h])
return
1;
128
if
(
m_data
[h]>a.
m_data
[h])
return
-1;
129
}
130
for
(
int
i=0; i<2; ++i) {
131
if
(
m_colors
[i] < a.
m_colors
[i])
return
1;
132
if
(
m_colors
[i] > a.
m_colors
[i])
return
-1;
133
}
134
if
(
m_pictureAverageColor
< a.
m_pictureAverageColor
)
return
1;
135
if
(
m_pictureAverageColor
> a.
m_pictureAverageColor
)
return
-1;
136
if
(
m_pictureMime
< a.
m_pictureMime
)
return
1;
137
if
(
m_pictureMime
> a.
m_pictureMime
)
return
-1;
138
if
(
m_picture
.size() < a.
m_picture
.size())
return
1;
139
if
(
m_picture
.size() > a.
m_picture
.size())
return
-1;
140
const
unsigned
char
*ptr=
m_picture
.getDataBuffer();
141
const
unsigned
char
*aPtr=a.
m_picture
.getDataBuffer();
142
for
(
unsigned
long
h=0; h <
m_picture
.size(); ++h, ++ptr, ++aPtr) {
143
if
(*ptr < *aPtr)
return
1;
144
if
(*ptr > *aPtr)
return
-1;
145
}
146
return
0;
147
}
149
friend
std::ostream &
operator<<
(std::ostream &o,
Pattern
const
&pat) {
150
o <<
"dim="
<< pat.
m_dim
<<
","
;
151
if
(pat.
m_picture
.size()) {
152
o <<
"type="
<< pat.
m_pictureMime
<<
","
;
153
o <<
"col[average]="
<< pat.
m_pictureAverageColor
<<
","
;
154
}
else
{
155
if
(!pat.
m_colors
[0].
isBlack
()) o <<
"col0="
<< pat.
m_colors
[0] <<
","
;
156
if (!pat.
m_colors
[1].
isWhite
()) o <<
"col1="
<< pat.
m_colors
[1] <<
","
;
157
o <<
"["
;
158
for (
size_t
h=0; h < pat.
m_data
.size(); ++h)
159
o << std::hex << (
int
) pat.
m_data
[h] << std::dec <<
","
;
160
o <<
"],"
;
161
}
162
return
o;
163
}
165
Vec2i
m_dim
;
166
168
MWAWColor
m_colors
[2];
170
std::vector<unsigned char>
m_data
;
171
protected
:
173
WPXBinaryData
m_picture
;
175
std::string
m_pictureMime
;
177
MWAWColor
m_pictureAverageColor
;
178
};
180
MWAWGraphicStyle
() :
m_lineWidth
(1),
m_lineDashWidth
(),
m_lineCap
(
C_Butt
),
m_lineJoin
(
J_Miter
),
m_lineOpacity
(1),
m_lineColor
(
MWAWColor
::black()),
181
m_fillRuleEvenOdd
(false),
m_surfaceColor
(
MWAWColor
::white()),
m_surfaceOpacity
(0),
182
m_shadowColor
(
MWAWColor
::black()),
m_shadowOpacity
(0),
m_shadowOffset
(1,1),
183
m_pattern
(),
184
m_gradientType
(
G_None
),
m_gradientStopList
(),
m_gradientAngle
(0),
m_gradientBorder
(0),
m_gradientPercentCenter
(0.5f,0.5f),
m_gradientRadius
(1),
185
m_rotate
(0),
m_extra
(
""
) {
186
m_arrows
[0]=
m_arrows
[1]=
false
;
187
m_flip
[0]=
m_flip
[1]=
false
;
188
m_gradientStopList
.push_back(
GradientStop
(0.0,
MWAWColor::white
()));
189
m_gradientStopList
.push_back(
GradientStop
(1.0,
MWAWColor::black
()));
190
}
192
virtual
~MWAWGraphicStyle
() { }
194
bool
hasLine
()
const
{
195
return
m_lineWidth
>0 &&
m_lineOpacity
>0;
196
}
198
void
setSurfaceColor
(
MWAWColor
const
&col,
float
opacity = 1) {
199
m_surfaceColor
= col;
200
m_surfaceOpacity
= opacity;
201
}
203
bool
hasSurfaceColor
()
const
{
204
return
m_surfaceOpacity
> 0;
205
}
207
void
setPattern
(
Pattern
const
&pat) {
208
m_pattern
=pat;
209
}
211
bool
hasPattern
()
const
{
212
return
!
m_pattern
.
empty
();
213
}
215
bool
hasGradient
(
bool
complex=
false
)
const
{
216
return
m_gradientType
!=
G_None
&&
m_gradientStopList
.size() >= (complex ? 3 : 2);
217
}
219
bool
hasSurface
()
const
{
220
return
hasSurfaceColor
() ||
hasPattern
() ||
hasGradient
();
221
}
223
void
setShadowColor
(
MWAWColor
const
&col,
float
opacity = 1) {
224
m_shadowColor
= col;
225
m_shadowOpacity
= opacity;
226
}
228
bool
hasShadow
()
const
{
229
return
m_shadowOpacity
> 0;
230
}
232
friend
std::ostream &
operator<<
(std::ostream &o,
MWAWGraphicStyle
const
&st);
234
void
addTo
(WPXPropertyList &pList, WPXPropertyListVector &gradient,
bool
only1d=
false
)
const
;
235
237
int
cmp
(
MWAWGraphicStyle
const
&a)
const
;
238
240
float
m_lineWidth
;
242
std::vector<float>
m_lineDashWidth
;
244
LineCap
m_lineCap
;
246
LineJoin
m_lineJoin
;
248
float
m_lineOpacity
;
250
MWAWColor
m_lineColor
;
252
bool
m_fillRuleEvenOdd
;
254
MWAWColor
m_surfaceColor
;
256
float
m_surfaceOpacity
;
257
259
MWAWColor
m_shadowColor
;
261
float
m_shadowOpacity
;
263
Vec2f
m_shadowOffset
;
264
266
Pattern
m_pattern
;
267
269
GradientType
m_gradientType
;
271
std::vector<GradientStop>
m_gradientStopList
;
273
float
m_gradientAngle
;
275
float
m_gradientBorder
;
277
Vec2f
m_gradientPercentCenter
;
279
float
m_gradientRadius
;
280
282
bool
m_arrows
[2];
283
284
// some transformation: must probably be somewhere else
285
287
float
m_rotate
;
289
bool
m_flip
[2];
290
292
std::string
m_extra
;
293
};
294
#endif
295
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
Generated on Wed May 7 2014 00:30:21 for libmwaw by
doxygen
1.8.3.1