Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2015-06-16 12:49:16 +02:00
|
|
|
* Copyright (C) 2015 Artem Pavlenko
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01: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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/text/renderer.hpp>
|
|
|
|
#include <mapnik/grid/grid.hpp>
|
|
|
|
#include <mapnik/text/text_properties.hpp>
|
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
|
|
|
#include <mapnik/text/face.hpp>
|
2015-01-16 23:48:43 +01:00
|
|
|
#include <mapnik/image_util.hpp>
|
2015-01-22 02:40:12 +01:00
|
|
|
#include <mapnik/image_any.hpp>
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
|
2014-07-10 13:46:42 +02:00
|
|
|
text_renderer::text_renderer (halo_rasterizer_e rasterizer, composite_mode_e comp_op,
|
|
|
|
composite_mode_e halo_comp_op, double scale_factor, stroker_ptr stroker)
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
: rasterizer_(rasterizer),
|
|
|
|
comp_op_(comp_op),
|
2014-06-17 16:10:20 +02:00
|
|
|
halo_comp_op_(halo_comp_op),
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
scale_factor_(scale_factor),
|
|
|
|
glyphs_(),
|
2014-01-17 12:47:18 +01:00
|
|
|
stroker_(stroker),
|
|
|
|
transform_(),
|
|
|
|
halo_transform_()
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
{}
|
|
|
|
|
2014-01-17 12:47:18 +01:00
|
|
|
void text_renderer::set_transform(agg::trans_affine const& transform)
|
|
|
|
{
|
|
|
|
transform_ = transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void text_renderer::set_halo_transform(agg::trans_affine const& halo_transform)
|
|
|
|
{
|
|
|
|
halo_transform_ = halo_transform;
|
|
|
|
}
|
|
|
|
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
void text_renderer::prepare_glyphs(glyph_positions const& positions)
|
|
|
|
{
|
|
|
|
FT_Matrix matrix;
|
|
|
|
FT_Vector pen;
|
|
|
|
FT_Error error;
|
|
|
|
|
2014-10-12 07:59:56 +02:00
|
|
|
glyphs_.reserve(positions.size());
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
for (auto const& glyph_pos : positions)
|
|
|
|
{
|
2014-10-10 03:38:29 +02:00
|
|
|
glyph_info const& glyph = glyph_pos.glyph;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
glyph.face->set_character_sizes(glyph.format->text_size * scale_factor_); //TODO: Optimize this?
|
|
|
|
|
|
|
|
matrix.xx = static_cast<FT_Fixed>( glyph_pos.rot.cos * 0x10000L);
|
|
|
|
matrix.xy = static_cast<FT_Fixed>(-glyph_pos.rot.sin * 0x10000L);
|
|
|
|
matrix.yx = static_cast<FT_Fixed>( glyph_pos.rot.sin * 0x10000L);
|
|
|
|
matrix.yy = static_cast<FT_Fixed>( glyph_pos.rot.cos * 0x10000L);
|
|
|
|
|
|
|
|
pixel_position pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot);
|
|
|
|
pen.x = static_cast<FT_Pos>(pos.x * 64);
|
|
|
|
pen.y = static_cast<FT_Pos>(pos.y * 64);
|
|
|
|
|
|
|
|
FT_Face face = glyph.face->get_face();
|
|
|
|
FT_Set_Transform(face, &matrix, &pen);
|
|
|
|
|
|
|
|
error = FT_Load_Glyph(face, glyph.glyph_index, FT_LOAD_NO_HINTING);
|
|
|
|
if (error) continue;
|
|
|
|
|
|
|
|
FT_Glyph image;
|
|
|
|
error = FT_Get_Glyph(face->glyph, &image);
|
|
|
|
if (error) continue;
|
|
|
|
|
2014-10-11 03:01:24 +02:00
|
|
|
glyphs_.emplace_back(image, *glyph.format);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void composite_bitmap(T & pixmap, FT_Bitmap *bitmap, unsigned rgba, int x, int y, double opacity, composite_mode_e comp_op)
|
|
|
|
{
|
2015-07-02 10:14:14 +02:00
|
|
|
int x_max = x + bitmap->width;
|
|
|
|
int y_max = y + bitmap->rows;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
2015-07-02 10:14:14 +02:00
|
|
|
for (int i = x, p = 0; i < x_max; ++i, ++p)
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
{
|
2015-07-02 10:14:14 +02:00
|
|
|
for (int j = y, q = 0; j < y_max; ++j, ++q)
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
{
|
|
|
|
unsigned gray=bitmap->buffer[q*bitmap->width+p];
|
|
|
|
if (gray)
|
|
|
|
{
|
2015-01-20 17:48:33 +01:00
|
|
|
mapnik::composite_pixel(pixmap, comp_op, i, j, rgba, gray, opacity);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
agg_text_renderer<T>::agg_text_renderer (pixmap_type & pixmap,
|
|
|
|
halo_rasterizer_e rasterizer,
|
|
|
|
composite_mode_e comp_op,
|
2014-06-17 16:10:20 +02:00
|
|
|
composite_mode_e halo_comp_op,
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
double scale_factor,
|
|
|
|
stroker_ptr stroker)
|
2014-06-17 16:10:20 +02:00
|
|
|
: text_renderer(rasterizer, comp_op, halo_comp_op, scale_factor, stroker), pixmap_(pixmap)
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void agg_text_renderer<T>::render(glyph_positions const& pos)
|
|
|
|
{
|
|
|
|
glyphs_.clear();
|
|
|
|
prepare_glyphs(pos);
|
|
|
|
FT_Error error;
|
|
|
|
FT_Vector start;
|
2014-01-17 12:47:18 +01:00
|
|
|
FT_Vector start_halo;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
int height = pixmap_.height();
|
|
|
|
pixel_position const& base_point = pos.get_base_point();
|
|
|
|
|
|
|
|
start.x = static_cast<FT_Pos>(base_point.x * (1 << 6));
|
|
|
|
start.y = static_cast<FT_Pos>((height - base_point.y) * (1 << 6));
|
2014-01-17 12:47:18 +01:00
|
|
|
start_halo = start;
|
|
|
|
start.x += transform_.tx * 64;
|
|
|
|
start.y += transform_.ty * 64;
|
|
|
|
start_halo.x += halo_transform_.tx * 64;
|
|
|
|
start_halo.y += halo_transform_.ty * 64;
|
|
|
|
|
|
|
|
FT_Matrix halo_matrix;
|
|
|
|
halo_matrix.xx = halo_transform_.sx * 0x10000L;
|
|
|
|
halo_matrix.xy = halo_transform_.shx * 0x10000L;
|
|
|
|
halo_matrix.yy = halo_transform_.sy * 0x10000L;
|
|
|
|
halo_matrix.yx = halo_transform_.shy * 0x10000L;
|
|
|
|
|
|
|
|
FT_Matrix matrix;
|
|
|
|
matrix.xx = transform_.sx * 0x10000L;
|
|
|
|
matrix.xy = transform_.shx * 0x10000L;
|
|
|
|
matrix.yy = transform_.sy * 0x10000L;
|
|
|
|
matrix.yx = transform_.shy * 0x10000L;
|
|
|
|
|
2014-10-10 03:24:39 +02:00
|
|
|
// default formatting
|
|
|
|
double halo_radius = 0;
|
|
|
|
color black(0,0,0);
|
|
|
|
unsigned fill = black.rgba();
|
|
|
|
unsigned halo_fill = black.rgba();
|
|
|
|
double text_opacity = 1.0;
|
|
|
|
double halo_opacity = 1.0;
|
|
|
|
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
for (auto const& glyph : glyphs_)
|
|
|
|
{
|
2014-10-11 03:01:24 +02:00
|
|
|
halo_fill = glyph.properties.halo_fill.rgba();
|
|
|
|
halo_opacity = glyph.properties.halo_opacity;
|
|
|
|
halo_radius = glyph.properties.halo_radius * scale_factor_;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
// make sure we've got reasonable values.
|
|
|
|
if (halo_radius <= 0.0 || halo_radius > 1024.0) continue;
|
|
|
|
FT_Glyph g;
|
|
|
|
error = FT_Glyph_Copy(glyph.image, &g);
|
|
|
|
if (!error)
|
|
|
|
{
|
2014-01-17 12:47:18 +01:00
|
|
|
FT_Glyph_Transform(g, &halo_matrix, &start_halo);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
if (rasterizer_ == HALO_RASTERIZER_FULL)
|
|
|
|
{
|
|
|
|
stroker_->init(halo_radius);
|
|
|
|
FT_Glyph_Stroke(&g, stroker_->get(), 1);
|
|
|
|
error = FT_Glyph_To_Bitmap(&g, FT_RENDER_MODE_NORMAL, 0, 1);
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
FT_BitmapGlyph bit = reinterpret_cast<FT_BitmapGlyph>(g);
|
|
|
|
composite_bitmap(pixmap_,
|
|
|
|
&bit->bitmap,
|
2014-10-10 03:24:39 +02:00
|
|
|
halo_fill,
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
bit->left,
|
|
|
|
height - bit->top,
|
2014-10-10 03:24:39 +02:00
|
|
|
halo_opacity,
|
2014-06-17 16:10:20 +02:00
|
|
|
halo_comp_op_);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error = FT_Glyph_To_Bitmap(&g, FT_RENDER_MODE_NORMAL, 0, 1);
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
FT_BitmapGlyph bit = reinterpret_cast<FT_BitmapGlyph>(g);
|
|
|
|
render_halo(&bit->bitmap,
|
2014-10-10 03:24:39 +02:00
|
|
|
halo_fill,
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
bit->left,
|
|
|
|
height - bit->top,
|
|
|
|
halo_radius,
|
2014-10-10 03:24:39 +02:00
|
|
|
halo_opacity,
|
2014-06-17 16:10:20 +02:00
|
|
|
halo_comp_op_);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FT_Done_Glyph(g);
|
|
|
|
}
|
|
|
|
|
|
|
|
// render actual text
|
|
|
|
for (auto & glyph : glyphs_)
|
|
|
|
{
|
2014-10-11 03:01:24 +02:00
|
|
|
fill = glyph.properties.fill.rgba();
|
|
|
|
text_opacity = glyph.properties.text_opacity;
|
2014-01-17 12:47:18 +01:00
|
|
|
FT_Glyph_Transform(glyph.image, &matrix, &start);
|
2014-07-10 13:46:42 +02:00
|
|
|
error = FT_Glyph_To_Bitmap(&glyph.image ,FT_RENDER_MODE_NORMAL, 0, 1);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
FT_BitmapGlyph bit = reinterpret_cast<FT_BitmapGlyph>(glyph.image);
|
|
|
|
composite_bitmap(pixmap_,
|
|
|
|
&bit->bitmap,
|
2014-10-10 03:24:39 +02:00
|
|
|
fill,
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
bit->left,
|
|
|
|
height - bit->top,
|
2014-10-10 03:24:39 +02:00
|
|
|
text_opacity,
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
comp_op_);
|
|
|
|
}
|
2014-10-11 03:01:24 +02:00
|
|
|
FT_Done_Glyph(glyph.image);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
2014-10-11 03:01:24 +02:00
|
|
|
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void grid_text_renderer<T>::render(glyph_positions const& pos, value_integer feature_id)
|
|
|
|
{
|
|
|
|
glyphs_.clear();
|
|
|
|
prepare_glyphs(pos);
|
|
|
|
FT_Error error;
|
|
|
|
FT_Vector start;
|
|
|
|
unsigned height = pixmap_.height();
|
|
|
|
pixel_position const& base_point = pos.get_base_point();
|
|
|
|
start.x = static_cast<FT_Pos>(base_point.x * (1 << 6));
|
|
|
|
start.y = static_cast<FT_Pos>((height - base_point.y) * (1 << 6));
|
2014-09-20 00:37:13 +02:00
|
|
|
start.x += transform_.tx * 64;
|
|
|
|
start.y += transform_.ty * 64;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
|
|
|
// now render transformed glyphs
|
|
|
|
double halo_radius = 0.0;
|
2014-09-20 00:37:13 +02:00
|
|
|
FT_Matrix halo_matrix;
|
|
|
|
halo_matrix.xx = halo_transform_.sx * 0x10000L;
|
|
|
|
halo_matrix.xy = halo_transform_.shx * 0x10000L;
|
|
|
|
halo_matrix.yy = halo_transform_.sy * 0x10000L;
|
|
|
|
halo_matrix.yx = halo_transform_.shy * 0x10000L;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
for (auto & glyph : glyphs_)
|
|
|
|
{
|
2014-10-11 03:01:24 +02:00
|
|
|
halo_radius = glyph.properties.halo_radius * scale_factor_;
|
2014-09-20 00:37:13 +02:00
|
|
|
FT_Glyph_Transform(glyph.image, &halo_matrix, &start);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
error = FT_Glyph_To_Bitmap(&glyph.image, FT_RENDER_MODE_NORMAL, 0, 1);
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
|
|
|
|
FT_BitmapGlyph bit = reinterpret_cast<FT_BitmapGlyph>(glyph.image);
|
|
|
|
render_halo_id(&bit->bitmap,
|
|
|
|
feature_id,
|
|
|
|
bit->left,
|
|
|
|
height - bit->top,
|
|
|
|
static_cast<int>(halo_radius));
|
|
|
|
}
|
2014-10-11 03:01:24 +02:00
|
|
|
FT_Done_Glyph(glyph.image);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void agg_text_renderer<T>::render_halo(FT_Bitmap *bitmap,
|
|
|
|
unsigned rgba,
|
|
|
|
int x1,
|
|
|
|
int y1,
|
|
|
|
double halo_radius,
|
|
|
|
double opacity,
|
|
|
|
composite_mode_e comp_op)
|
|
|
|
{
|
|
|
|
int width = bitmap->width;
|
|
|
|
int height = bitmap->rows;
|
|
|
|
int x, y;
|
|
|
|
if (halo_radius < 1.0)
|
|
|
|
{
|
|
|
|
for (x=0; x < width; x++)
|
|
|
|
{
|
|
|
|
for (y=0; y < height; y++)
|
|
|
|
{
|
|
|
|
int gray = bitmap->buffer[y*bitmap->width+x];
|
|
|
|
if (gray)
|
|
|
|
{
|
2015-01-20 17:48:33 +01:00
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1-1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
|
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1, y+y1-1, rgba, gray*halo_radius, opacity);
|
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1+1, y+y1-1, rgba, gray*halo_radius*halo_radius, opacity);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
2015-01-20 17:48:33 +01:00
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1-1, y+y1, rgba, gray*halo_radius, opacity);
|
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1, y+y1, rgba, gray, opacity);
|
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1+1, y+y1, rgba, gray*halo_radius, opacity);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
2015-01-20 17:48:33 +01:00
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1-1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
|
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1, y+y1+1, rgba, gray*halo_radius, opacity);
|
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1+1, y+y1+1, rgba, gray*halo_radius*halo_radius, opacity);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (x=0; x < width; x++)
|
|
|
|
{
|
|
|
|
for (y=0; y < height; y++)
|
|
|
|
{
|
|
|
|
int gray = bitmap->buffer[y*bitmap->width+x];
|
|
|
|
if (gray)
|
|
|
|
{
|
|
|
|
for (int n=-halo_radius; n <=halo_radius; ++n)
|
|
|
|
for (int m=-halo_radius; m <= halo_radius; ++m)
|
2015-01-20 17:48:33 +01:00
|
|
|
mapnik::composite_pixel(pixmap_, comp_op, x+x1+m, y+y1+n, rgba, gray, opacity);
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void grid_text_renderer<T>::render_halo_id(
|
|
|
|
FT_Bitmap *bitmap,
|
|
|
|
mapnik::value_integer feature_id,
|
|
|
|
int x1,
|
|
|
|
int y1,
|
|
|
|
int halo_radius)
|
|
|
|
{
|
|
|
|
int width = bitmap->width;
|
|
|
|
int height = bitmap->rows;
|
|
|
|
int x, y;
|
|
|
|
for (x=0; x < width; x++)
|
|
|
|
{
|
|
|
|
for (y=0; y < height; y++)
|
|
|
|
{
|
|
|
|
int gray = bitmap->buffer[y*bitmap->width+x];
|
|
|
|
if (gray)
|
|
|
|
{
|
|
|
|
for (int n=-halo_radius; n <=halo_radius; ++n)
|
|
|
|
for (int m=-halo_radius; m <= halo_radius; ++m)
|
|
|
|
pixmap_.setPixel(x+x1+m,y+y1+n,feature_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
grid_text_renderer<T>::grid_text_renderer(pixmap_type &pixmap,
|
|
|
|
composite_mode_e comp_op,
|
2014-06-17 16:10:20 +02:00
|
|
|
double scale_factor)
|
|
|
|
: text_renderer(HALO_RASTERIZER_FAST, comp_op, src_over, scale_factor),
|
|
|
|
pixmap_(pixmap) {}
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
|
2015-01-22 03:31:02 +01:00
|
|
|
template class agg_text_renderer<image_rgba8>;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
template class grid_text_renderer<grid>;
|
2014-06-17 16:10:20 +02:00
|
|
|
|
|
|
|
} // namespace mapnik
|