2007-09-25 18:47:12 +00:00
|
|
|
/*****************************************************************************
|
2012-02-02 01:53:35 +00:00
|
|
|
*
|
2007-09-25 18:47:12 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 13:04:25 +00:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2007-09-25 18:47:12 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <mapnik/stroke.hpp>
|
2013-05-20 19:44:55 +00:00
|
|
|
#include <mapnik/enumeration.hpp>
|
2007-09-25 18:47:12 +00:00
|
|
|
|
2007-10-19 22:17:16 +00:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2007-09-25 18:47:12 +00:00
|
|
|
|
2010-04-09 18:46:41 +00:00
|
|
|
static const char * line_cap_strings[] = {
|
|
|
|
"butt",
|
|
|
|
"square",
|
|
|
|
"round",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-04-01 07:20:41 +00:00
|
|
|
IMPLEMENT_ENUM( line_cap_e, line_cap_strings )
|
|
|
|
|
|
|
|
|
2010-04-09 18:46:41 +00:00
|
|
|
static const char * line_join_strings[] = {
|
|
|
|
"miter",
|
|
|
|
"miter_revert",
|
|
|
|
"round",
|
|
|
|
"bevel",
|
|
|
|
""
|
|
|
|
};
|
2007-09-25 18:47:12 +00:00
|
|
|
|
2011-04-01 07:20:41 +00:00
|
|
|
IMPLEMENT_ENUM( line_join_e, line_join_strings )
|
2007-09-25 18:47:12 +00:00
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
stroke::stroke()
|
|
|
|
: c_(0,0,0),
|
|
|
|
width_(1.0),
|
|
|
|
opacity_(1.0),
|
|
|
|
line_cap_(BUTT_CAP),
|
|
|
|
line_join_(MITER_JOIN),
|
|
|
|
gamma_(1.0),
|
|
|
|
gamma_method_(GAMMA_POWER),
|
|
|
|
dash_(),
|
2012-05-02 16:04:24 +00:00
|
|
|
dash_offset_(0),
|
|
|
|
miterlimit_(4.0) {}
|
2010-04-09 18:46:41 +00:00
|
|
|
|
|
|
|
stroke::stroke(color const& c, double width)
|
|
|
|
: c_(c),
|
|
|
|
width_(width),
|
|
|
|
opacity_(1.0),
|
|
|
|
line_cap_(BUTT_CAP),
|
|
|
|
line_join_(MITER_JOIN),
|
2011-02-02 01:46:14 +00:00
|
|
|
gamma_(1.0),
|
2012-01-13 17:20:03 +00:00
|
|
|
gamma_method_(GAMMA_POWER),
|
2010-04-09 18:46:41 +00:00
|
|
|
dash_(),
|
2012-05-02 16:04:24 +00:00
|
|
|
dash_offset_(0.0),
|
|
|
|
miterlimit_(4.0) {}
|
2010-04-09 18:46:41 +00:00
|
|
|
|
|
|
|
stroke::stroke(stroke const& other)
|
|
|
|
: c_(other.c_),
|
|
|
|
width_(other.width_),
|
|
|
|
opacity_(other.opacity_),
|
|
|
|
line_cap_(other.line_cap_),
|
|
|
|
line_join_(other.line_join_),
|
2011-02-02 01:46:14 +00:00
|
|
|
gamma_(other.gamma_),
|
2012-01-13 17:20:03 +00:00
|
|
|
gamma_method_(other.gamma_method_),
|
2012-02-02 01:53:35 +00:00
|
|
|
dash_(other.dash_),
|
2012-05-02 16:04:24 +00:00
|
|
|
dash_offset_(other.dash_offset_),
|
|
|
|
miterlimit_(other.miterlimit_) {}
|
2010-04-09 18:46:41 +00:00
|
|
|
|
|
|
|
stroke & stroke::operator=(const stroke& rhs)
|
|
|
|
{
|
|
|
|
stroke tmp(rhs);
|
|
|
|
swap(tmp);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
void stroke::set_color(const color& c)
|
2010-04-09 18:46:41 +00:00
|
|
|
{
|
|
|
|
c_=c;
|
|
|
|
}
|
|
|
|
|
|
|
|
color const& stroke::get_color() const
|
|
|
|
{
|
|
|
|
return c_;
|
|
|
|
}
|
|
|
|
|
|
|
|
double stroke::get_width() const
|
|
|
|
{
|
|
|
|
return width_;
|
|
|
|
}
|
|
|
|
void stroke::set_width(double w)
|
|
|
|
{
|
|
|
|
width_=w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stroke::set_opacity(double opacity)
|
2012-02-02 01:53:35 +00:00
|
|
|
{
|
2010-04-09 18:46:41 +00:00
|
|
|
if (opacity > 1.0) opacity_=1.0;
|
|
|
|
else if (opacity < 0.0) opacity_=0.0;
|
|
|
|
else opacity_=opacity;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
double stroke::get_opacity() const
|
2010-04-09 18:46:41 +00:00
|
|
|
{
|
|
|
|
return opacity_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stroke::set_line_cap(line_cap_e line_cap)
|
|
|
|
{
|
|
|
|
line_cap_=line_cap;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
line_cap_e stroke::get_line_cap() const
|
2010-04-09 18:46:41 +00:00
|
|
|
{
|
|
|
|
return line_cap_;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
void stroke::set_line_join(line_join_e line_join)
|
2010-04-09 18:46:41 +00:00
|
|
|
{
|
|
|
|
line_join_=line_join;
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
line_join_e stroke::get_line_join() const
|
2010-04-09 18:46:41 +00:00
|
|
|
{
|
|
|
|
return line_join_;
|
|
|
|
}
|
|
|
|
|
2011-02-02 01:46:14 +00:00
|
|
|
void stroke::set_gamma(double gamma)
|
|
|
|
{
|
|
|
|
gamma_ = gamma;
|
|
|
|
}
|
|
|
|
|
|
|
|
double stroke::get_gamma() const
|
|
|
|
{
|
|
|
|
return gamma_;
|
|
|
|
}
|
|
|
|
|
2012-01-13 17:20:03 +00:00
|
|
|
void stroke::set_gamma_method(gamma_method_e gamma_method)
|
|
|
|
{
|
|
|
|
gamma_method_ = gamma_method;
|
|
|
|
}
|
|
|
|
|
|
|
|
gamma_method_e stroke::get_gamma_method() const
|
|
|
|
{
|
|
|
|
return gamma_method_;
|
|
|
|
}
|
|
|
|
|
2010-04-09 18:46:41 +00:00
|
|
|
void stroke::add_dash(double dash, double gap)
|
|
|
|
{
|
|
|
|
dash_.push_back(std::make_pair(dash,gap));
|
|
|
|
}
|
|
|
|
|
2012-02-02 01:53:35 +00:00
|
|
|
bool stroke::has_dash() const
|
2010-04-09 18:46:41 +00:00
|
|
|
{
|
|
|
|
return ! dash_.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void stroke::set_dash_offset(double offset)
|
|
|
|
{
|
|
|
|
dash_offset_ = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
double stroke::dash_offset() const
|
|
|
|
{
|
|
|
|
return dash_offset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
dash_array const& stroke::get_dash_array() const
|
|
|
|
{
|
2011-02-02 01:46:14 +00:00
|
|
|
return dash_;
|
2010-04-09 18:46:41 +00:00
|
|
|
}
|
|
|
|
|
2012-05-02 16:04:24 +00:00
|
|
|
void stroke::set_miterlimit(double val)
|
|
|
|
{
|
|
|
|
miterlimit_ = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
double stroke::get_miterlimit() const
|
|
|
|
{
|
|
|
|
return miterlimit_;
|
|
|
|
}
|
|
|
|
|
2010-04-09 18:46:41 +00:00
|
|
|
void stroke::swap(const stroke& other) throw()
|
|
|
|
{
|
2012-01-13 17:20:03 +00:00
|
|
|
c_ = other.c_;
|
|
|
|
width_ = other.width_;
|
|
|
|
opacity_ = other.opacity_;
|
|
|
|
line_cap_ = other.line_cap_;
|
|
|
|
line_join_ = other.line_join_;
|
|
|
|
gamma_ = other.gamma_;
|
|
|
|
gamma_method_ = other.gamma_method_;
|
2010-04-09 18:46:41 +00:00
|
|
|
dash_ = other.dash_;
|
2011-02-02 01:46:14 +00:00
|
|
|
dash_offset_ = other.dash_offset_;
|
2012-05-02 16:04:24 +00:00
|
|
|
miterlimit_ = other.miterlimit_;
|
2010-04-09 18:46:41 +00:00
|
|
|
}
|
2007-09-25 18:47:12 +00:00
|
|
|
}
|