Skip to content

Commit 47435c5

Browse files
committed
More refactoring - adding missing Symbolizer properties [WIP] [skip ci]
1 parent 82c57a5 commit 47435c5

File tree

5 files changed

+131
-46
lines changed

5 files changed

+131
-46
lines changed

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def run(self):
279279
ext_modules=[
280280
Extension('mapnik._mapnik', [
281281
'src/mapnik_color.cpp',
282+
'src/mapnik_composite_modes.cpp',
282283
'src/mapnik_coord.cpp',
283284
'src/mapnik_datasource.cpp',
284285
'src/mapnik_datasource_cache.cpp',
@@ -311,7 +312,7 @@ def run(self):
311312
'src/mapnik_style.cpp',
312313
'src/mapnik_symbolizer.cpp',
313314
'src/mapnik_view_transform.cpp',
314-
'src/python_grid_utils.cpp',
315+
'src/python_grid_utils.cpp'
315316
],
316317
language='c++',
317318
extra_compile_args=extra_comp_args,

src/mapnik_composite_modes.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*****************************************************************************
2+
*
3+
* This file is part of Mapnik (c++ mapping toolkit)
4+
*
5+
* Copyright (C) 2015 Artem Pavlenko, Jean-Francois Doyon
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
*****************************************************************************/
22+
23+
#include <mapnik/config.hpp>
24+
25+
#pragma GCC diagnostic push
26+
#include <mapnik/warning_ignore.hpp>
27+
#include <boost/python.hpp>
28+
#include <boost/noncopyable.hpp>
29+
#pragma GCC diagnostic pop
30+
31+
#include "mapnik_enumeration.hpp"
32+
#include <mapnik/image_compositing.hpp>
33+
34+
void export_composite_modes()
35+
{
36+
using namespace boost::python;
37+
// NOTE: must match list in include/mapnik/image_compositing.hpp
38+
enum_<mapnik::composite_mode_e>("CompositeOp")
39+
.value("clear", mapnik::clear)
40+
.value("src", mapnik::src)
41+
.value("dst", mapnik::dst)
42+
.value("src_over", mapnik::src_over)
43+
.value("dst_over", mapnik::dst_over)
44+
.value("src_in", mapnik::src_in)
45+
.value("dst_in", mapnik::dst_in)
46+
.value("src_out", mapnik::src_out)
47+
.value("dst_out", mapnik::dst_out)
48+
.value("src_atop", mapnik::src_atop)
49+
.value("dst_atop", mapnik::dst_atop)
50+
.value("xor", mapnik::_xor)
51+
.value("plus", mapnik::plus)
52+
.value("minus", mapnik::minus)
53+
.value("multiply", mapnik::multiply)
54+
.value("screen", mapnik::screen)
55+
.value("overlay", mapnik::overlay)
56+
.value("darken", mapnik::darken)
57+
.value("lighten", mapnik::lighten)
58+
.value("color_dodge", mapnik::color_dodge)
59+
.value("color_burn", mapnik::color_burn)
60+
.value("hard_light", mapnik::hard_light)
61+
.value("soft_light", mapnik::soft_light)
62+
.value("difference", mapnik::difference)
63+
.value("exclusion", mapnik::exclusion)
64+
.value("contrast", mapnik::contrast)
65+
.value("invert", mapnik::invert)
66+
.value("grain_merge", mapnik::grain_merge)
67+
.value("grain_extract", mapnik::grain_extract)
68+
.value("hue", mapnik::hue)
69+
.value("saturation", mapnik::saturation)
70+
.value("color", mapnik::_color)
71+
.value("value", mapnik::_value)
72+
.value("linear_dodge", mapnik::linear_dodge)
73+
.value("linear_burn", mapnik::linear_burn)
74+
.value("divide", mapnik::divide)
75+
;
76+
}

src/mapnik_image.cpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -350,45 +350,6 @@ std::shared_ptr<image_any> from_cairo(PycairoSurface* py_surface)
350350
void export_image()
351351
{
352352
using namespace boost::python;
353-
// NOTE: must match list in include/mapnik/image_compositing.hpp
354-
enum_<mapnik::composite_mode_e>("CompositeOp")
355-
.value("clear", mapnik::clear)
356-
.value("src", mapnik::src)
357-
.value("dst", mapnik::dst)
358-
.value("src_over", mapnik::src_over)
359-
.value("dst_over", mapnik::dst_over)
360-
.value("src_in", mapnik::src_in)
361-
.value("dst_in", mapnik::dst_in)
362-
.value("src_out", mapnik::src_out)
363-
.value("dst_out", mapnik::dst_out)
364-
.value("src_atop", mapnik::src_atop)
365-
.value("dst_atop", mapnik::dst_atop)
366-
.value("xor", mapnik::_xor)
367-
.value("plus", mapnik::plus)
368-
.value("minus", mapnik::minus)
369-
.value("multiply", mapnik::multiply)
370-
.value("screen", mapnik::screen)
371-
.value("overlay", mapnik::overlay)
372-
.value("darken", mapnik::darken)
373-
.value("lighten", mapnik::lighten)
374-
.value("color_dodge", mapnik::color_dodge)
375-
.value("color_burn", mapnik::color_burn)
376-
.value("hard_light", mapnik::hard_light)
377-
.value("soft_light", mapnik::soft_light)
378-
.value("difference", mapnik::difference)
379-
.value("exclusion", mapnik::exclusion)
380-
.value("contrast", mapnik::contrast)
381-
.value("invert", mapnik::invert)
382-
.value("grain_merge", mapnik::grain_merge)
383-
.value("grain_extract", mapnik::grain_extract)
384-
.value("hue", mapnik::hue)
385-
.value("saturation", mapnik::saturation)
386-
.value("color", mapnik::_color)
387-
.value("value", mapnik::_value)
388-
.value("linear_dodge", mapnik::linear_dodge)
389-
.value("linear_burn", mapnik::linear_burn)
390-
.value("divide", mapnik::divide)
391-
;
392353

393354
enum_<mapnik::image_dtype>("ImageType")
394355
.value("rgba8", mapnik::image_dtype_rgba8)

src/mapnik_python.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <fstream>
4646

4747
void export_color();
48+
void export_composite_modes();
4849
void export_coord();
4950
void export_layer();
5051
void export_parameters();
@@ -732,6 +733,7 @@ BOOST_PYTHON_MODULE(_mapnik)
732733
export_datasource();
733734
export_parameters();
734735
export_color();
736+
export_composite_modes();
735737
export_envelope();
736738
export_palette();
737739
export_image();

src/mapnik_symbolizer.cpp

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include <mapnik/group/group_symbolizer_properties.hpp>
4949
#include <mapnik/util/variant.hpp>
5050
#include <mapnik/text/placements/dummy.hpp>
51+
#include <mapnik/transform/parse_transform.hpp>
52+
#include <mapnik/transform/transform_processor.hpp>
5153

5254
using mapnik::symbolizer;
5355
using mapnik::point_symbolizer;
@@ -185,7 +187,7 @@ struct extract_python_object
185187
}
186188
};
187189

188-
/*
190+
189191
boost::python::object __getitem__(mapnik::symbolizer_base const& sym, std::string const& name)
190192
{
191193
using const_iterator = symbolizer_base::cont_type::const_iterator;
@@ -199,7 +201,7 @@ boost::python::object __getitem__(mapnik::symbolizer_base const& sym, std::strin
199201
//return mapnik::util::apply_visitor(extract_python_object(), std::get<1>(meta));
200202
return boost::python::object();
201203
}
202-
*/
204+
203205

204206
boost::python::object symbolizer_keys(mapnik::symbolizer_base const& sym)
205207
{
@@ -271,6 +273,20 @@ void set(symbolizer_base & sym, Value const& val)
271273
mapnik::put<Value>(sym, Key, val);
272274
}
273275

276+
std::string get_transform(symbolizer_base const& sym)
277+
{
278+
auto expr = mapnik::get<mapnik::transform_type>(sym, mapnik::keys::geometry_transform);
279+
if (expr)
280+
return mapnik::transform_processor_type::to_string(*expr);
281+
return "";
282+
}
283+
284+
void set_transform(symbolizer_base & sym, std::string const& str)
285+
{
286+
mapnik::put(sym, mapnik::keys::geometry_transform, mapnik::parse_transform(str));
287+
}
288+
289+
274290
}
275291

276292
void export_symbolizer()
@@ -306,11 +322,26 @@ void export_symbolizer()
306322
class_<symbolizer_base>("SymbolizerBase",no_init)
307323
//.def("__setitem__",&__setitem__)
308324
//.def("__setattr__",&__setitem__)
309-
//.def("__getitem__",&__getitem__)
310-
//.def("__getattr__",&__getitem__)
325+
.def("__getitem__",&__getitem__)
326+
.def("__getattr__",&__getitem__)
311327
.def("keys", &symbolizer_keys)
312328
//.def("__str__", &__str__)
313329
.def(self == self) // __eq__
330+
.add_property("smooth",
331+
&get<double, mapnik::keys::smooth>,
332+
&set<double, mapnik::keys::smooth>, "Smooth")
333+
.add_property("simplify_tolerance",
334+
&get<double, mapnik::keys::simplify_tolerance>,
335+
&set<double, mapnik::keys::simplify_tolerance>, "Simplify tolerance")
336+
.add_property("clip",
337+
&get<mapnik::value_bool, mapnik::keys::clip>,
338+
&set<mapnik::value_bool, mapnik::keys::clip>, "Clip - False/True")
339+
.add_property("comp_op",
340+
&get<mapnik::composite_mode_e, mapnik::keys::comp_op>,
341+
&set<mapnik::composite_mode_e, mapnik::keys::comp_op>, "Composite mode (comp-op)")
342+
.add_property("geometry_transform",
343+
&get_transform,
344+
&set_transform, "Geometry transform")
314345
;
315346
}
316347

@@ -377,7 +408,16 @@ void export_polygon_symbolizer()
377408
.def("__hash__",hash_impl_2<polygon_symbolizer>)
378409
.add_property("fill",
379410
&get<mapnik::color, mapnik::keys::fill>,
380-
&set<mapnik::color, mapnik::keys::fill>, "Fill color")
411+
&set<mapnik::color, mapnik::keys::fill>, "Fill - CSS color)")
412+
.add_property("fill_opacity",
413+
&get<double, mapnik::keys::fill_opacity>,
414+
&set<double, mapnik::keys::fill_opacity>, "Fill opacity - 0..1.0")
415+
.add_property("gamma",
416+
&get<double, mapnik::keys::gamma>,
417+
&set<double, mapnik::keys::gamma>, "Fill gamma")
418+
.add_property("gamma_method",
419+
&get<mapnik::gamma_method_enum, mapnik::keys::gamma_method>,
420+
&set<mapnik::gamma_method_enum, mapnik::keys::gamma_method>, "Fill gamma method")
381421
;
382422

383423
}
@@ -530,7 +570,12 @@ void export_line_symbolizer()
530570
.add_property("stroke_dasharray",
531571
&get_stroke_dasharray,
532572
&set_stroke_dasharray, "Stroke dasharray")
533-
573+
.add_property("stroke_dashoffset",
574+
&get<double, mapnik::keys::stroke_dashoffset>,
575+
&set<double, mapnik::keys::stroke_dashoffset>, "Stroke dashoffset")
576+
.add_property("stroke_miterlimit",
577+
&get<double, mapnik::keys::stroke_miterlimit>,
578+
&set<double, mapnik::keys::stroke_miterlimit>, "Stroke miterlimit")
534579

535580
;
536581
}

0 commit comments

Comments
 (0)