vfs: check userland buffers before reading them.
[haiku.git] / src / libs / icon / transformer / ContourTransformer.cpp
bloba120e8291f707a879e1e246481dc48ea93bdfcf2
1 /*
2 * Copyright 2006-2007, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
10 #include "ContourTransformer.h"
12 #ifdef ICON_O_MATIC
13 # include <Message.h>
15 # include "CommonPropertyIDs.h"
16 # include "OptionProperty.h"
17 # include "Property.h"
18 # include "PropertyObject.h"
19 #endif // ICON_O_MATIC
21 #include <new>
24 _USING_ICON_NAMESPACE
25 using std::nothrow;
28 // constructor
29 ContourTransformer::ContourTransformer(VertexSource& source)
30 : Transformer(source, "Contour"),
31 Contour(source)
33 auto_detect_orientation(true);
36 // constructor
37 ContourTransformer::ContourTransformer(VertexSource& source,
38 BMessage* archive)
39 : Transformer(source, archive),
40 Contour(source)
42 auto_detect_orientation(true);
44 if (!archive)
45 return;
47 int32 mode;
48 if (archive->FindInt32("line join", &mode) == B_OK)
49 line_join((agg::line_join_e)mode);
51 if (archive->FindInt32("inner join", &mode) == B_OK)
52 inner_join((agg::inner_join_e)mode);
54 double value;
55 if (archive->FindDouble("width", &value) == B_OK)
56 width(value);
58 if (archive->FindDouble("miter limit", &value) == B_OK)
59 miter_limit(value);
61 if (archive->FindDouble("inner miter limit", &value) == B_OK)
62 inner_miter_limit(value);
65 // destructor
66 ContourTransformer::~ContourTransformer()
70 // Clone
71 Transformer*
72 ContourTransformer::Clone(VertexSource& source) const
74 ContourTransformer* clone = new (nothrow) ContourTransformer(source);
75 if (clone) {
76 clone->line_join(line_join());
77 clone->inner_join(inner_join());
78 clone->width(width());
79 clone->miter_limit(miter_limit());
80 clone->inner_miter_limit(inner_miter_limit());
81 clone->auto_detect_orientation(auto_detect_orientation());
83 return clone;
86 // rewind
87 void
88 ContourTransformer::rewind(unsigned path_id)
90 Contour::rewind(path_id);
93 // vertex
94 unsigned
95 ContourTransformer::vertex(double* x, double* y)
97 return Contour::vertex(x, y);
100 // SetSource
101 void
102 ContourTransformer::SetSource(VertexSource& source)
104 Transformer::SetSource(source);
105 Contour::attach(source);
108 // ApproximationScale
109 double
110 ContourTransformer::ApproximationScale() const
112 double scale = fSource.ApproximationScale();
113 double factor = fabs(width());
114 if (factor > 1.0)
115 scale *= factor;
116 return scale;
119 // #pragma mark -
121 #ifdef ICON_O_MATIC
123 // Archive
124 status_t
125 ContourTransformer::Archive(BMessage* into, bool deep) const
127 status_t ret = Transformer::Archive(into, deep);
129 if (ret == B_OK)
130 into->what = archive_code;
132 if (ret == B_OK)
133 ret = into->AddInt32("line join", line_join());
135 if (ret == B_OK)
136 ret = into->AddInt32("inner join", inner_join());
138 if (ret == B_OK)
139 ret = into->AddDouble("width", width());
141 if (ret == B_OK)
142 ret = into->AddDouble("miter limit", miter_limit());
144 if (ret == B_OK)
145 ret = into->AddDouble("inner miter limit", inner_miter_limit());
147 return ret;
150 // MakePropertyObject
151 PropertyObject*
152 ContourTransformer::MakePropertyObject() const
154 PropertyObject* object = Transformer::MakePropertyObject();
155 if (!object)
156 return NULL;
158 // width
159 object->AddProperty(new FloatProperty(PROPERTY_WIDTH, width()));
161 // auto detect orientation
162 object->AddProperty(new BoolProperty(PROPERTY_DETECT_ORIENTATION,
163 auto_detect_orientation()));
165 // join mode
166 OptionProperty* property = new OptionProperty(PROPERTY_JOIN_MODE);
167 property->AddOption(agg::miter_join, "Miter");
168 property->AddOption(agg::round_join, "Round");
169 property->AddOption(agg::bevel_join, "Bevel");
170 property->SetCurrentOptionID(line_join());
172 object->AddProperty(property);
174 // miter limit
175 object->AddProperty(new FloatProperty(PROPERTY_MITER_LIMIT,
176 miter_limit()));
178 return object;
181 // SetToPropertyObject
182 bool
183 ContourTransformer::SetToPropertyObject(const PropertyObject* object)
185 AutoNotificationSuspender _(this);
186 Transformer::SetToPropertyObject(object);
188 // width
189 float w = object->Value(PROPERTY_WIDTH, (float)width());
190 if (w != width()) {
191 width(w);
192 Notify();
195 // auto detect orientation
196 bool ado = object->Value(PROPERTY_DETECT_ORIENTATION,
197 auto_detect_orientation());
198 if (ado != auto_detect_orientation()) {
199 auto_detect_orientation(ado);
200 Notify();
203 // join mode
204 OptionProperty* property = dynamic_cast<OptionProperty*>(
205 object->FindProperty(PROPERTY_JOIN_MODE));
206 if (property && line_join() != property->CurrentOptionID()) {
207 line_join((agg::line_join_e)property->CurrentOptionID());
208 Notify();
211 // miter limit
212 float l = object->Value(PROPERTY_MITER_LIMIT, (float)miter_limit());
213 if (l != miter_limit()) {
214 miter_limit(l);
215 Notify();
218 return HasPendingNotifications();
221 #endif // ICON_O_MATIC