1 // LineStyle.h Line style types.
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // Based on public domain work by Thatcher Ulrich <tu@tulrich.com> 2003
21
22 #ifndef GNASH_LINESTYLE_H
23 #define GNASH_LINESTYLE_H
24
25 #include "RGBA.h"
26 #include "SWF.h"
27 #include <utility>
28
29 namespace gnash {
30 class SWFStream;
31 class movie_definition;
32 class RunResources;
33 }
34
35 namespace gnash {
36
37 enum CapStyle {
38 CAP_ROUND = 0,
39 CAP_NONE = 1,
40 CAP_SQUARE = 2
41 };
42
43 enum JoinStyle {
44 JOIN_ROUND = 0,
45 JOIN_BEVEL = 1,
46 JOIN_MITER = 2
47 };
48
49 /// For the outside of outline shapes, or just bare lines.
50 class LineStyle
51 {
52 public:
53
54 /// Construct a default LineStyle.
55 LineStyle();
56
57 /// Construct a line style with explicit values
58 ///
59 /// @param width Thickness of line in twips.
60 /// Zero for hair line
61 ///
62 /// @param color Line color
63 /// @param scaleThicknessVertically
64 /// @param scaleThicknessHorizontally
65 /// @param noClose
66 /// @param startCapStyle
67 /// @param endCapStyle
68 /// @param joinStyle
69 /// @param miterLimitFactor
70 LineStyle(std::uint16_t width, rgba color,
71 bool scaleThicknessVertically=true,
72 bool scaleThicknessHorizontally=true,
73 bool pixelHinting=false,
74 bool noClose=false,
75 CapStyle startCapStyle=CAP_ROUND,
76 CapStyle endCapStyle=CAP_ROUND,
77 JoinStyle joinStyle=JOIN_ROUND,
78 float miterLimitFactor=1.0f
79 )
80 :
m_width(width)81 m_width(width),
82 m_color(std::move(color)),
83 _scaleVertically(scaleThicknessVertically),
84 _scaleHorizontally(scaleThicknessHorizontally),
85 _pixelHinting(pixelHinting),
86 _noClose(noClose),
87 _startCapStyle(startCapStyle),
88 _endCapStyle(endCapStyle),
89 _joinStyle(joinStyle),
90 _miterLimitFactor(miterLimitFactor)
91 {
92 }
93
94 /// Read the line style from an SWF stream
95 //
96 /// Stream is assumed to be positioned at
97 /// the right place.
98 ///
99 /// Throw a ParserException if there's no enough bytes in the
100 /// currently opened tag for reading. See stream::ensureBytes()
101 void read(SWFStream& in, SWF::TagType t, movie_definition& md,
102 const RunResources& r);
103
104 /// Read two lines styles from the SWF stream
105 /// at the same time -- this is used in morphing.
106 void read_morph(SWFStream& in, SWF::TagType t, movie_definition& md,
107 const RunResources& r, LineStyle *pOther);
108
109 /// Return thickness of the line, in TWIPS
getThickness()110 std::uint16_t getThickness() const {
111 return m_width;
112 }
113
114 /// Return true if line thickness should be scaled vertically
scaleThicknessVertically()115 bool scaleThicknessVertically() const {
116 return _scaleVertically;
117 }
118
119 /// Return true if line thickness should be scaled horizontally
scaleThicknessHorizontally()120 bool scaleThicknessHorizontally() const {
121 return _scaleHorizontally;
122 }
123
124 /// Return the start cap style
startCapStyle()125 CapStyle startCapStyle() const {
126 return _startCapStyle;
127 }
128
129 /// Return the end cap style
endCapStyle()130 CapStyle endCapStyle() const {
131 return _endCapStyle;
132 }
133
134 /// Return the join style
joinStyle()135 JoinStyle joinStyle() const {
136 return _joinStyle;
137 }
138
139 /// Return the miter limit factor
miterLimitFactor()140 float miterLimitFactor() const {
141 return _miterLimitFactor;
142 }
143
144 /// Return true if stroke should not be closed if the stroke's last point
145 /// matches the first point. Caps should be applied instead of a join
noClose()146 bool noClose() const {
147 return _noClose;
148 }
149
150 /// Return true if pixel hinting should be activated
doPixelHinting()151 bool doPixelHinting() const {
152 return _pixelHinting;
153 }
154
155 /// Return line color and alpha
get_color()156 const rgba& get_color() const { return m_color; }
157
158 /// Set this style to the interpolation of the given one
159 //
160 /// @param ls1 First LineStyle to interpolate.
161 /// @param ls2 Second LineStyle to interpolate.
162 /// @ratio The interpolation factor (0..1).
163 /// When 0, this will be equal to ls1, when 1
164 /// this will be equal to ls2.
165 void set_lerp(const LineStyle& ls1, const LineStyle& ls2, float ratio);
166
167 private:
168
169 /// Width in twips.
170 std::uint16_t m_width;
171
172 rgba m_color;
173
174 bool _scaleVertically;
175
176 bool _scaleHorizontally;
177
178 bool _pixelHinting;
179
180 bool _noClose;
181
182 CapStyle _startCapStyle;
183
184 CapStyle _endCapStyle;
185
186 JoinStyle _joinStyle;
187
188 float _miterLimitFactor;
189 };
190
191 inline void
setLerp(LineStyle & s,const LineStyle & ls1,const LineStyle & ls2,double ratio)192 setLerp(LineStyle& s, const LineStyle& ls1, const LineStyle& ls2, double ratio)
193 {
194 s.set_lerp(ls1, ls2, ratio);
195 }
196
197 } // namespace gnash
198
199 #endif
200
201 // Local Variables:
202 // mode: C++
203 // indent-tabs-mode: t
204 // End:
205