/usr/include/svgpp/parser/misc.hpp is in libsvgpp-dev 1.2.3+dfsg1-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | // Copyright Oleg Maximenko 2014.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://github.com/svgpp/svgpp for library home page.
#pragma once
#include <svgpp/config.hpp>
#include <svgpp/definitions.hpp>
#include <svgpp/parser/detail/common.hpp>
#include <svgpp/parser/detail/value_parser_parameters.hpp>
#include <svgpp/parser/external_function/parse_preserveAspectRatio.hpp>
#if !defined(SVGPP_USE_EXTERNAL_PRESERVE_ASPECT_RATIO_PARSER)
# include <svgpp/parser/external_function/parse_preserveAspectRatio_impl.hpp>
#endif
#include <svgpp/parser/external_function/parse_misc.hpp>
#if !defined(SVGPP_USE_EXTERNAL_MISC_PARSER)
# include <svgpp/parser/external_function/parse_misc_impl.hpp>
#endif
#include <svgpp/parser/value_parser_fwd.hpp>
#include <svgpp/policy/value_events.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
namespace svgpp
{
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::type::integer, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class AttributeTag, class Context, class AttributeValue, class PropertySource>
static bool parse(AttributeTag tag, Context & context, AttributeValue const & attribute_value,
PropertySource property_source)
{
namespace qi = boost::spirit::qi;
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
int value;
if (qi::parse(it, end, qi::int_, value) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context), tag, property_source, value);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::attribute::viewBox, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue>
static bool parse(tag::attribute::viewBox tag, Context & context, AttributeValue const & attribute_value,
tag::source::attribute property_source)
{
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename args_t::number_type coordinate_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
coordinate_t x, y, w, h;
if (detail::parse_viewBox(it, end, x, y, w, h) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context), tag, property_source, x, y, w, h);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::attribute::bbox, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue>
static bool parse(tag::attribute::bbox tag, Context & context, AttributeValue const & attribute_value,
tag::source::attribute property_source)
{
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename args_t::number_type coordinate_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
SVGPP_STATIC_IF_SAFE const qi::real_parser<coordinate_t, detail::svg_real_policies<coordinate_t> > number;
coordinate_t lo_x, lo_y, hi_x, hi_y;
if (detail::parse_bbox(it, end, lo_x, lo_y, hi_x, hi_y) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context), tag, property_source, lo_x, lo_y, hi_x, hi_y);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::attribute::preserveAspectRatio, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue>
static bool parse(tag::attribute::preserveAspectRatio tag, Context & context,
AttributeValue const & attribute_value, tag::source::attribute)
{
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
preserveAspectRatio_value value;
if (detail::parse_preserveAspectRatio(it, end, value) && it == end)
{
typedef typename boost::parameter::parameters<
boost::parameter::optional<tag::value_events_policy>
>::template bind<SVGPP_TEMPLATE_ARGS_PASS>::type args2_t;
typedef typename detail::unwrap_context<Context, tag::value_events_policy> unwrap_value_events_policy_t;
typedef typename unwrap_value_events_policy_t::template bind<args2_t>::type value_events_policy_t;
switch (value.align)
{
case preserveAspectRatio_value::none:
value_events_policy_t::set(unwrap_value_events_policy_t::get(context),
tag::attribute::preserveAspectRatio(),
tag::source::attribute(),
value.defer, tag::value::none());
break;
#define SVGPP_CASE(value_tag) \
case preserveAspectRatio_value::value_tag: \
if (value.slice) \
value_events_policy_t::set(unwrap_value_events_policy_t::get(context), \
tag::attribute::preserveAspectRatio(), tag::source::attribute(), \
value.defer, tag::value::value_tag(), tag::value::slice()); \
else \
value_events_policy_t::set(unwrap_value_events_policy_t::get(context), \
tag::attribute::preserveAspectRatio(), tag::source::attribute(), \
value.defer, tag::value::value_tag(), tag::value::meet()); \
break;
SVGPP_CASE(xMinYMin);
SVGPP_CASE(xMidYMin);
SVGPP_CASE(xMaxYMin);
SVGPP_CASE(xMinYMid);
SVGPP_CASE(xMidYMid);
SVGPP_CASE(xMaxYMid);
SVGPP_CASE(xMinYMax);
SVGPP_CASE(xMidYMax);
SVGPP_CASE(xMaxYMax);
#undef SVGPP_CASE
}
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<boost::mpl::pair<tag::element::stop, tag::attribute::offset>, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue>
static bool parse(tag::attribute::offset tag, Context & context, AttributeValue const & attribute_value,
tag::source::attribute property_source)
{
namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
using qi::_1;
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename args_t::number_type coordinate_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
SVGPP_STATIC_IF_SAFE const qi::real_parser<coordinate_t, detail::number_policies<coordinate_t, tag::source::attribute> > number;
coordinate_t value;
bool percentage = false;
if (qi::parse(it, end, number[phx::ref(value) = _1] >> -(qi::lit('%')[phx::ref(percentage) = true])) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context),
tag, property_source, percentage ? value / 100 : value);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::attribute::clip, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue, class PropertySource>
static bool parse(tag::attribute::clip tag, Context & context, AttributeValue const & attribute_value,
PropertySource property_source)
{
// 'auto' and 'inherit' values must be checked outside
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
typedef typename boost::parameter::parameters<
boost::parameter::optional<tag::length_policy>
>::template bind<SVGPP_TEMPLATE_ARGS_PASS>::type args2_t;
typedef typename detail::unwrap_context<Context, tag::length_policy> length_policy_context;
typedef typename length_policy_context::template bind<args2_t>::type length_policy_t;
typename length_policy_t::length_factory_type & length_factory
= length_policy_t::length_factory(length_policy_context::get(context));
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
typename length_policy_t::length_factory_type::length_type rect[4];
if (detail::parse_clip(length_factory, it, end, property_source, rect) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context),
tag, property_source, tag::value::rect(), rect[0], rect[1], rect[2], rect[3]);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::attribute::enable_background, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue, class PropertySource>
static bool parse(tag::attribute::enable_background tag, Context & context, AttributeValue const & attribute_value,
PropertySource property_source)
{
// 'accumulate', 'new' and 'inherit' values must be checked outside
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
typedef typename args_t::number_type coordinate_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
coordinate_t x, y, width, height;
if (detail::parse_enable_background(it, end, property_source, x, y, width, height) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context),
tag, property_source, tag::value::new_(), x, y, width, height);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
template<SVGPP_TEMPLATE_ARGS>
struct value_parser<tag::attribute::text_decoration, SVGPP_TEMPLATE_ARGS_PASS>
{
template<class Context, class AttributeValue, class PropertySource>
static bool parse(tag::attribute::text_decoration tag, Context & context, AttributeValue const & attribute_value,
PropertySource property_source)
{
// 'none' and 'inherit' values must be checked outside
namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;
using qi::_1;
typedef detail::value_parser_parameters<Context, SVGPP_TEMPLATE_ARGS_PASS> args_t;
typedef typename boost::range_const_iterator<AttributeValue>::type iterator_t;
iterator_t it = boost::begin(attribute_value), end = boost::end(attribute_value);
bool underline = false, overline = false, line_through = false, blink = false;
const qi::rule<iterator_t> value =
detail::no_case_if_css(property_source)
[
qi::lit("underline") [phx::ref(underline) = true]
| qi::lit("overline") [phx::ref(overline) = true]
| qi::lit("line-through") [phx::ref(line_through) = true]
| qi::lit("blink") [phx::ref(blink) = true]
];
const qi::rule<iterator_t> rule = value % +detail::character_encoding_namespace::space;
if (qi::parse(it, end, rule) && it == end)
{
args_t::value_events_policy::set(args_t::value_events_context::get(context), tag, property_source,
tag::value::underline(), underline,
tag::value::overline(), overline,
tag::value::line_through(), line_through,
tag::value::blink(), blink);
return true;
}
else
{
return args_t::error_policy::parse_failed(args_t::error_policy_context::get(context), tag, attribute_value);
}
}
};
}
|