Merge pull request #3477 from mapycz/cairo-style-level-comp-op

Style level comp-op and opacity for Cairo renderer
This commit is contained in:
Artem Pavlenko 2016-08-08 10:52:54 +01:00 committed by GitHub
commit b0cf57aa53
5 changed files with 50 additions and 6 deletions

View file

@ -308,6 +308,7 @@ public:
void stroke();
void fill();
void paint();
void paint(double opacity);
void set_pattern(cairo_pattern const& pattern);
void set_gradient(cairo_gradient const& pattern, box2d<double> const& bbox);
void add_image(double x, double y, image_rgba8 const& data, double opacity = 1.0);
@ -327,6 +328,9 @@ public:
composite_mode_e halo_comp_op = src_over,
double scale_factor = 1.0);
void push_group();
void pop_group();
template <typename T>
void add_path(T& path, unsigned start_index = 0)
{

View file

@ -177,6 +177,7 @@ protected:
cairo_context context_;
renderer_common common_;
cairo_face_manager face_manager_;
bool style_level_compositing_;
void setup(Map const& m);
};

View file

@ -304,6 +304,12 @@ void cairo_context::paint()
check_object_status_and_throw_exception(*this);
}
void cairo_context::paint(double opacity)
{
cairo_paint_with_alpha(cairo_.get(), opacity);
check_object_status_and_throw_exception(*this);
}
void cairo_context::set_pattern(cairo_pattern const& pattern)
{
cairo_set_source(cairo_.get(), pattern.pattern());
@ -489,6 +495,18 @@ void cairo_context::add_text(glyph_positions const& pos,
}
void cairo_context::push_group()
{
cairo_push_group(cairo_.get());
check_object_status_and_throw_exception(*this);
}
void cairo_context::pop_group()
{
cairo_pop_group_to_source(cairo_.get());
check_object_status_and_throw_exception(*this);
}
cairo_face_manager::cairo_face_manager(std::shared_ptr<font_library> font_library)
: font_library_(font_library)
{

View file

@ -36,6 +36,7 @@
#include <mapnik/label_collision_detector.hpp>
#include <mapnik/marker.hpp>
#include <mapnik/marker_cache.hpp>
#include <mapnik/feature_type_style.hpp>
// agg
#include "agg/include/agg_trans_affine.h" // for trans_affine, etc
@ -58,7 +59,8 @@ cairo_renderer<T>::cairo_renderer(Map const& m,
m_(m),
context_(cairo),
common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor),
face_manager_(common_.shared_font_library_)
face_manager_(common_.shared_font_library_),
style_level_compositing_(false)
{
setup(m);
}
@ -75,7 +77,9 @@ cairo_renderer<T>::cairo_renderer(Map const& m,
m_(m),
context_(cairo),
common_(m, req, vars, offset_x, offset_y, req.width(), req.height(), scale_factor),
face_manager_(common_.shared_font_library_)
face_manager_(common_.shared_font_library_),
style_level_compositing_(false)
{
setup(m);
}
@ -91,7 +95,9 @@ cairo_renderer<T>::cairo_renderer(Map const& m,
m_(m),
context_(cairo),
common_(m, attributes(), offset_x, offset_y, m.width(), m.height(), scale_factor, detector),
face_manager_(common_.shared_font_library_)
face_manager_(common_.shared_font_library_),
style_level_compositing_(false)
{
setup(m);
}
@ -191,15 +197,30 @@ void cairo_renderer<T>::end_layer_processing(layer const&)
}
template <typename T>
void cairo_renderer<T>::start_style_processing(feature_type_style const&)
void cairo_renderer<T>::start_style_processing(feature_type_style const & st)
{
MAPNIK_LOG_DEBUG(cairo_renderer) << "cairo_renderer:start style processing";
style_level_compositing_ = st.comp_op() || st.get_opacity() < 1;
if (style_level_compositing_)
{
context_.push_group();
}
}
template <typename T>
void cairo_renderer<T>::end_style_processing(feature_type_style const&)
void cairo_renderer<T>::end_style_processing(feature_type_style const & st)
{
MAPNIK_LOG_DEBUG(cairo_renderer) << "cairo_renderer:end style processing";
if (style_level_compositing_)
{
context_.pop_group();
composite_mode_e comp_op = st.comp_op() ? *st.comp_op() : src_over;
context_.set_operator(comp_op);
context_.paint(st.get_opacity());
}
}
struct cairo_render_marker_visitor

@ -1 +1 @@
Subproject commit 5f0e6f86696a2a9a6733e42b1f400ba4ec2f8847
Subproject commit 4a054f2efe35a65aa5163f080304fb90ae9c6194