2012-03-08 18:51:23 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-02-17 15:50:24 +01:00
|
|
|
#include <mapnik/processed_text.hpp>
|
2012-03-08 18:51:23 +01:00
|
|
|
#include <mapnik/config_error.hpp>
|
2013-01-10 01:45:37 +01:00
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
2012-03-08 18:51:23 +01:00
|
|
|
|
2012-02-17 15:50:24 +01:00
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
|
|
|
|
void processed_text::push_back(char_properties const& properties, UnicodeString const& text)
|
|
|
|
{
|
|
|
|
expr_list_.push_back(processed_expression(properties, text));
|
|
|
|
}
|
|
|
|
|
|
|
|
processed_text::expression_list::const_iterator processed_text::begin() const
|
|
|
|
{
|
|
|
|
return expr_list_.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
processed_text::expression_list::const_iterator processed_text::end() const
|
|
|
|
{
|
|
|
|
return expr_list_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
processed_text::processed_text(face_manager<freetype_engine> & font_manager, double scale_factor)
|
|
|
|
: font_manager_(font_manager), scale_factor_(scale_factor)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void processed_text::clear()
|
|
|
|
{
|
|
|
|
info_.clear();
|
|
|
|
expr_list_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-16 12:15:00 +02:00
|
|
|
string_info const& processed_text::get_string_info()
|
2012-02-17 15:50:24 +01:00
|
|
|
{
|
|
|
|
info_.clear(); //if this function is called twice invalid results are returned, so clear string_info first
|
|
|
|
expression_list::iterator itr = expr_list_.begin();
|
|
|
|
expression_list::iterator end = expr_list_.end();
|
|
|
|
for (; itr != end; ++itr)
|
|
|
|
{
|
|
|
|
char_properties const &p = itr->p;
|
|
|
|
face_set_ptr faces = font_manager_.get_face_set(p.face_name, p.fontset);
|
2012-02-25 00:53:09 +01:00
|
|
|
if (faces->size() == 0)
|
2012-02-17 15:50:24 +01:00
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
if (p.fontset && !p.fontset->get_name().empty())
|
2012-02-25 00:53:09 +01:00
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
if (p.fontset->size())
|
2012-08-23 02:01:24 +02:00
|
|
|
{
|
|
|
|
if (!p.face_name.empty())
|
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
throw config_error("Unable to find specified font face '" + p.face_name + "' in font set: '" + p.fontset->get_name() + "'");
|
2012-08-23 02:01:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
throw config_error("No valid font face could be loaded for font set: '" + p.fontset->get_name() + "'");
|
2012-08-23 02:01:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-09-14 23:17:45 +02:00
|
|
|
throw config_error("Font set '" + p.fontset->get_name() + "' does not contain any Font face-name entries");
|
2012-08-23 02:01:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!p.face_name.empty())
|
|
|
|
{
|
2012-02-25 00:53:09 +01:00
|
|
|
throw config_error("Unable to find specified font face '" + p.face_name + "'");
|
2012-08-23 02:01:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-25 00:53:09 +01:00
|
|
|
throw config_error("Both font set and face name are empty!");
|
|
|
|
}
|
2012-02-17 15:50:24 +01:00
|
|
|
}
|
|
|
|
faces->set_character_sizes(p.text_size * scale_factor_);
|
|
|
|
faces->get_string_info(info_, itr->str, &(itr->p));
|
|
|
|
info_.add_text(itr->str);
|
|
|
|
}
|
|
|
|
return info_;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //ns mapnik
|