|
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * This file is part of Mapnik (c++ mapping toolkit) |
| 4 | + * |
| 5 | + * Copyright (C) 2024 Artem Pavlenko |
| 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 | +// mapnik |
| 24 | +#include <mapnik/config.hpp> |
| 25 | +#include <mapnik/symbolizer.hpp> |
| 26 | +#include <mapnik/symbolizer_hash.hpp> |
| 27 | +#include <mapnik/symbolizer_utils.hpp> |
| 28 | +#include <mapnik/symbolizer_keys.hpp> |
| 29 | + |
| 30 | +#include "mapnik_symbolizer.hpp" |
| 31 | +//pybind11 |
| 32 | +#include <pybind11/pybind11.h> |
| 33 | +#include <pybind11/operators.h> |
| 34 | +#include <pybind11/stl.h> |
| 35 | +#include <pybind11/stl_bind.h> |
| 36 | + |
| 37 | +#define PYBIND11_DETAILED_ERROR_MESSAGES |
| 38 | + |
| 39 | +namespace py = pybind11; |
| 40 | + |
| 41 | +namespace { |
| 42 | + |
| 43 | +std::string get_stroke_dasharray(mapnik::symbolizer_base & sym) |
| 44 | +{ |
| 45 | + auto dash = mapnik::get<mapnik::dash_array>(sym, mapnik::keys::stroke_dasharray); |
| 46 | + |
| 47 | + std::ostringstream os; |
| 48 | + for (std::size_t i = 0; i < dash.size(); ++i) |
| 49 | + { |
| 50 | + os << dash[i].first << "," << dash[i].second; |
| 51 | + if (i + 1 < dash.size()) |
| 52 | + os << ","; |
| 53 | + } |
| 54 | + return os.str(); |
| 55 | +} |
| 56 | + |
| 57 | +void set_stroke_dasharray(mapnik::symbolizer_base & sym, std::string str) |
| 58 | +{ |
| 59 | + mapnik::dash_array dash; |
| 60 | + if (mapnik::util::parse_dasharray(str, dash)) |
| 61 | + { |
| 62 | + mapnik::put(sym, mapnik::keys::stroke_dasharray, dash); |
| 63 | + } |
| 64 | + else |
| 65 | + { |
| 66 | + throw std::runtime_error("Can't parse dasharray"); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +} |
| 71 | + |
| 72 | + |
| 73 | +void export_line_symbolizer(py::module const& m) |
| 74 | +{ |
| 75 | + using namespace python_mapnik; |
| 76 | + using mapnik::line_symbolizer; |
| 77 | + |
| 78 | + py::enum_<mapnik::line_rasterizer_enum>(m, "line_rasterizer") |
| 79 | + .value("FULL",mapnik::line_rasterizer_enum::RASTERIZER_FULL) |
| 80 | + .value("FAST",mapnik::line_rasterizer_enum::RASTERIZER_FAST) |
| 81 | + ; |
| 82 | + |
| 83 | + py::enum_<mapnik::line_cap_enum>(m, "stroke_linecap") |
| 84 | + .value("BUTT_CAP",mapnik::line_cap_enum::BUTT_CAP) |
| 85 | + .value("SQUARE_CAP",mapnik::line_cap_enum::SQUARE_CAP) |
| 86 | + .value("ROUND_CAP",mapnik::line_cap_enum::ROUND_CAP) |
| 87 | + ; |
| 88 | + |
| 89 | + py::enum_<mapnik::line_join_enum>(m, "stroke_linejoin") |
| 90 | + .value("MITER_JOIN",mapnik::line_join_enum::MITER_JOIN) |
| 91 | + .value("MITER_REVERT_JOIN",mapnik::line_join_enum::MITER_REVERT_JOIN) |
| 92 | + .value("ROUND_JOIN",mapnik::line_join_enum::ROUND_JOIN) |
| 93 | + .value("BEVEL_JOIN",mapnik::line_join_enum::BEVEL_JOIN) |
| 94 | + ; |
| 95 | + |
| 96 | + py::class_<line_symbolizer, symbolizer_base>(m, "LineSymbolizer") |
| 97 | + .def(py::init<>(), "Default LineSymbolizer - 1px solid black") |
| 98 | + .def("__hash__",hash_impl_2<line_symbolizer>) |
| 99 | + .def_property("stroke", |
| 100 | + &get_property<line_symbolizer, mapnik::keys::stroke>, |
| 101 | + &set_color_property<line_symbolizer, mapnik::keys::stroke>, |
| 102 | + "Stroke color") |
| 103 | + .def_property("stroke_width", |
| 104 | + &get_property<line_symbolizer,mapnik::keys::stroke_width>, |
| 105 | + &set_double_property<line_symbolizer, mapnik::keys::stroke_width>, |
| 106 | + "Stroke width") |
| 107 | + .def_property("stroke_opacity", |
| 108 | + &get_property<line_symbolizer,mapnik::keys::stroke_opacity>, |
| 109 | + &set_double_property<line_symbolizer, mapnik::keys::stroke_opacity>, |
| 110 | + "Stroke opacity") |
| 111 | + .def_property("stroke_gamma", |
| 112 | + &get_property<line_symbolizer,mapnik::keys::stroke_gamma>, |
| 113 | + &set_double_property<line_symbolizer,mapnik::keys::stroke_gamma>, |
| 114 | + "Stroke gamma") |
| 115 | + .def_property("stroke_gamma_method", |
| 116 | + &get<mapnik::gamma_method_enum, mapnik::keys::stroke_gamma_method>, |
| 117 | + &set_enum_property<line_symbolizer, mapnik::gamma_method_enum, mapnik::keys::stroke_gamma_method>, |
| 118 | + "Stroke gamma method") |
| 119 | + .def_property("line_rasterizer", |
| 120 | + &get<mapnik::line_rasterizer_enum, mapnik::keys::line_rasterizer>, |
| 121 | + &set_enum_property<line_symbolizer, mapnik::line_rasterizer_enum, mapnik::keys::line_rasterizer>, |
| 122 | + "Line rasterizer") |
| 123 | + .def_property("stroke_linecap", |
| 124 | + &get<mapnik::line_cap_enum, mapnik::keys::stroke_linecap>, |
| 125 | + &set_enum_property<line_symbolizer, mapnik::line_cap_enum, mapnik::keys::stroke_linecap>, |
| 126 | + "Stroke linecap") |
| 127 | + .def_property("stroke_linejoin", |
| 128 | + &get<mapnik::line_join_enum, mapnik::keys::stroke_linejoin>, |
| 129 | + &set_enum_property<line_symbolizer, mapnik::line_join_enum, mapnik::keys::stroke_linejoin>, |
| 130 | + "Stroke linejoin") |
| 131 | + .def_property("stroke_dasharray", |
| 132 | + &get_stroke_dasharray, |
| 133 | + &set_stroke_dasharray, |
| 134 | + "Stroke dasharray") |
| 135 | + .def_property("stroke_dashoffset", |
| 136 | + &get_property<line_symbolizer, mapnik::keys::stroke_dashoffset>, |
| 137 | + &set_double_property<line_symbolizer,mapnik::keys::stroke_dashoffset>, |
| 138 | + "Stroke dashoffset") |
| 139 | + .def_property("stroke_miterlimit", |
| 140 | + &get_property<line_symbolizer, mapnik::keys::stroke_miterlimit>, |
| 141 | + &set_double_property<line_symbolizer, mapnik::keys::stroke_miterlimit>, |
| 142 | + "Stroke miterlimit") |
| 143 | + |
| 144 | + ; |
| 145 | +} |
0 commit comments