2010-06-01 15:31:08 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
//$Id$
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/agg_renderer.hpp>
|
2010-06-13 14:03:42 +02:00
|
|
|
#include <mapnik/agg_rasterizer.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
#include <mapnik/image_util.hpp>
|
|
|
|
#include <mapnik/image_cache.hpp>
|
2010-07-06 02:37:05 +02:00
|
|
|
#include <mapnik/metawriter.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
#include <mapnik/svg/marker_cache.hpp>
|
2010-06-08 12:16:22 +02:00
|
|
|
#include <mapnik/svg/svg_converter.hpp>
|
|
|
|
#include <mapnik/svg/svg_renderer.hpp>
|
2010-06-14 18:38:02 +02:00
|
|
|
#include <mapnik/svg/svg_path_adapter.hpp>
|
2010-06-01 15:31:08 +02:00
|
|
|
|
|
|
|
#include "agg_basics.h"
|
|
|
|
#include "agg_rendering_buffer.h"
|
|
|
|
#include "agg_pixfmt_rgba.h"
|
|
|
|
#include "agg_rasterizer_scanline_aa.h"
|
|
|
|
#include "agg_scanline_u.h"
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace mapnik {
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void agg_renderer<T>::process(point_symbolizer const& sym,
|
|
|
|
Feature const& feature,
|
|
|
|
proj_transform const& prj_trans)
|
|
|
|
{
|
|
|
|
typedef agg::pixfmt_rgba32 pixfmt;
|
|
|
|
typedef agg::renderer_base<pixfmt> renderer_base;
|
|
|
|
typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
|
|
|
|
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double z=0;
|
|
|
|
|
2010-07-06 02:37:05 +02:00
|
|
|
std::string filename = path_processor_type::evaluate(*sym.get_filename(), feature);
|
2010-06-01 15:31:08 +02:00
|
|
|
boost::optional<mapnik::image_ptr> data;
|
|
|
|
|
2010-06-19 22:32:00 +02:00
|
|
|
if (is_svg(filename))
|
2010-06-01 15:31:08 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
// SVG
|
2010-06-14 18:38:02 +02:00
|
|
|
using namespace mapnik::svg;
|
2010-06-02 13:03:30 +02:00
|
|
|
boost::optional<path_ptr> marker;
|
|
|
|
ras_ptr->reset();
|
|
|
|
ras_ptr->gamma(agg::gamma_linear());
|
|
|
|
agg::scanline_u8 sl;
|
|
|
|
agg::rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_ * 4);
|
|
|
|
pixfmt pixf(buf);
|
|
|
|
renderer_base renb(pixf);
|
|
|
|
renderer_solid ren(renb);
|
|
|
|
box2d<double> extent;
|
|
|
|
|
2010-06-03 14:35:43 +02:00
|
|
|
marker = marker_cache::instance()->find(filename, true);
|
2010-06-08 12:16:22 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
if (marker && *marker)
|
|
|
|
{
|
2010-06-08 12:16:22 +02:00
|
|
|
|
2010-06-08 12:16:31 +02:00
|
|
|
box2d<double> const& bbox = (*marker)->bounding_box();
|
|
|
|
double x1 = bbox.minx();
|
|
|
|
double y1 = bbox.miny();
|
|
|
|
double x2 = bbox.maxx();
|
|
|
|
double y2 = bbox.maxy();
|
2010-09-25 14:12:59 +02:00
|
|
|
|
|
|
|
agg::trans_affine recenter = agg::trans_affine_translation(-0.5*(x1+x2),-0.5*(y1+y2));
|
|
|
|
|
2010-06-14 18:38:02 +02:00
|
|
|
vertex_stl_adapter<svg_path_storage> stl_storage((*marker)->source());
|
|
|
|
svg_path_adapter svg_path(stl_storage);
|
|
|
|
svg_renderer<svg_path_adapter,
|
|
|
|
agg::pod_bvector<path_attributes> > svg_renderer(svg_path,
|
|
|
|
(*marker)->attributes());
|
2010-06-02 13:03:30 +02:00
|
|
|
|
|
|
|
for (unsigned i=0; i<feature.num_geometries(); ++i)
|
|
|
|
{
|
|
|
|
geometry2d const& geom = feature.get_geometry(i);
|
|
|
|
geom.label_position(&x,&y);
|
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
t_.forward(&x,&y);
|
|
|
|
|
|
|
|
agg::trans_affine tr;
|
|
|
|
boost::array<double,6> const& m = sym.get_transform();
|
|
|
|
tr.load_from(&m[0]);
|
2010-09-27 11:58:21 +02:00
|
|
|
tr = recenter * tr;
|
2010-06-10 16:12:28 +02:00
|
|
|
tr *= agg::trans_affine_scaling(scale_factor_);
|
2010-06-02 13:03:30 +02:00
|
|
|
tr *= agg::trans_affine_translation(x, y);
|
|
|
|
|
|
|
|
tr.transform(&x1,&y1);
|
|
|
|
tr.transform(&x2,&y2);
|
|
|
|
|
|
|
|
extent.init(x1,y1,x2,y2);
|
|
|
|
if (sym.get_allow_overlap() ||
|
|
|
|
detector_.has_placement(extent))
|
|
|
|
{
|
2010-06-08 12:16:22 +02:00
|
|
|
svg_renderer.render(*ras_ptr, sl, ren, tr, renb.clip_box(), sym.get_opacity());
|
2010-06-02 13:03:30 +02:00
|
|
|
detector_.insert(extent);
|
2010-07-12 17:27:33 +02:00
|
|
|
metawriter_with_properties writer = sym.get_metawriter();
|
2010-07-06 02:37:05 +02:00
|
|
|
if (writer.first)
|
|
|
|
{
|
2010-08-02 14:14:27 +02:00
|
|
|
writer.first->add_box(extent, feature, t_, writer.second);
|
2010-07-06 02:37:05 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-01 15:31:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-19 22:32:00 +02:00
|
|
|
if ( filename.empty() )
|
|
|
|
{
|
|
|
|
// default OGC 4x4 black square
|
|
|
|
data = boost::optional<mapnik::image_ptr>(new image_data_32(4,4));
|
|
|
|
(*data)->set(0xff000000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data = mapnik::image_cache::instance()->find(filename,true);
|
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
if ( data )
|
|
|
|
{
|
2010-07-06 02:37:05 +02:00
|
|
|
for (unsigned i=0; i<feature.num_geometries(); ++i)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
geometry2d const& geom = feature.get_geometry(i);
|
|
|
|
|
|
|
|
geom.label_position(&x,&y);
|
|
|
|
prj_trans.backward(x,y,z);
|
|
|
|
t_.forward(&x,&y);
|
|
|
|
int w = (*data)->width();
|
|
|
|
int h = (*data)->height();
|
2010-07-06 02:37:05 +02:00
|
|
|
int px = int(floor(x - 0.5 * w));
|
|
|
|
int py = int(floor(y - 0.5 * h));
|
|
|
|
box2d<double> label_ext (px, py, px + w, py + h);
|
2010-06-02 13:03:30 +02:00
|
|
|
if (sym.get_allow_overlap() ||
|
|
|
|
detector_.has_placement(label_ext))
|
|
|
|
{
|
2010-07-06 02:37:05 +02:00
|
|
|
pixmap_.set_rectangle_alpha2(*(*data), px, py, sym.get_opacity());
|
2010-06-02 13:03:30 +02:00
|
|
|
detector_.insert(label_ext);
|
2010-07-12 17:27:33 +02:00
|
|
|
metawriter_with_properties writer = sym.get_metawriter();
|
2010-08-12 21:12:15 +02:00
|
|
|
if (writer.first) writer.first->add_box(label_ext, feature, t_, writer.second);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-01 15:31:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template void agg_renderer<image_32>::process(point_symbolizer const&,
|
2010-06-02 13:03:30 +02:00
|
|
|
Feature const&,
|
|
|
|
proj_transform const&);
|
2010-06-01 15:31:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|