+ initial text rendering support (FIXME: implement font metrics etc)

This commit is contained in:
artemp 2013-07-18 16:55:52 +01:00
parent 6a82e617cc
commit 55cb8188ab
5 changed files with 55 additions and 16 deletions

View file

@ -24,6 +24,9 @@
#include <QSettings>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#if defined(HAVE_SKIA)
#include <mapnik/skia/skia_typeface_cache.hpp>
#endif
#include "mainwindow.hpp"
// boost
@ -54,6 +57,15 @@ int main( int argc, char **argv )
QString font_dir = settings.value("dir").toString();
freetype_engine::register_fonts(font_dir.toStdString());
}
#if defined(HAVE_SKIA)
for (int index=0; index < count; ++index)
{
settings.setArrayIndex(index);
QString font_dir = settings.value("dir").toString();
mapnik::skia_typeface_cache::register_fonts(font_dir.toStdString());
}
#endif
settings.endArray();
QApplication app( argc, argv );

View file

@ -30,6 +30,8 @@
#include <mapnik/skia/skia_font_manager.hpp>
// stl
#include <list>
// icu (temp)
#include <unicode/schriter.h>
namespace mapnik {
@ -86,14 +88,25 @@ public:
for (; itr != end; ++itr)
{
char_properties const& p = itr->p;
std::cerr << p.face_name << " : " << p.fontset << std::endl;
//face_set_ptr faces = font_manager.get_face_set(p.face_name, p.fontset);
//if (faces->size() > 0)
//{
//faces->set_character_sizes(p.text_size * scale_factor_); // ???
// faces->get_string_info(info_, itr->str, &(itr->p));
// info_.add_text(itr->str);
//}
if (p.fontset)
{
for (auto const& face_name : p.fontset->get_face_names())
{
std::cerr << face_name << std::endl;
}
}
StringCharacterIterator iter(itr->str);
for (iter.setToStart(); iter.hasNext();)
{
UChar ch = iter.nextPostInc();
char_info char_dim(ch, 10, 12, 0, 12);
char_dim.format = &(itr->p);
char_dim.avg_height = 12;//avg_height;
info_.add_info(char_dim);
}
// char sizes ---> p.text_size * scale_factor_
info_.add_text(itr->str);
}
return info_;

View file

@ -375,9 +375,11 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust
shaped.releaseBuffer(length);
if (U_SUCCESS(err)) {
if (U_SUCCESS(err))
{
StringCharacterIterator iter(shaped);
for (iter.setToStart(); iter.hasNext();) {
for (iter.setToStart(); iter.hasNext();)
{
UChar ch = iter.nextPostInc();
char_info char_dim = character_dimensions(ch);
char_dim.format = format;

View file

@ -259,10 +259,8 @@ void skia_renderer::process(text_symbolizer const& sym,
for (unsigned i = 0; i < placements.size(); ++i)
{
//std::cerr << placements[i].x << "," << placements[i].y << std::endl;
double sx = placements[i].center.x;
double sy = placements[i].center.y;
placements[i].rewind();
for (int j = 0; j < placements[i].num_nodes(); ++j)
@ -270,8 +268,19 @@ void skia_renderer::process(text_symbolizer const& sym,
char_info_ptr c;
double x, y, angle;
placements[i].vertex(c, x, y, angle);
std::cerr << c << " " << x << "," << y << " angle=" << angle << std::endl;
//context_.add_text(placements[ii], face_manager_, font_manager_, scale_factor_);
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setAntiAlias(true);
double text_size = c->format->text_size * scale_factor_;
paint.setTextSize((SkScalar)text_size);
color const& fill = c->format->fill; // !!
paint.setARGB(int(fill.alpha() * sym.get_text_opacity()), fill.red(), fill.green(), fill.blue());
SkPoint pt = SkPoint::Make(0,0);
canvas_.save();
canvas_.translate((SkScalar)(sx + x), (SkScalar)(sy - y));
canvas_.rotate(-(SkScalar)180 * (angle/M_PI));
canvas_.drawPosText(&(c->c),1, &pt, paint);
canvas_.restore();
}
}
}

View file

@ -28,6 +28,7 @@
#endif
#include <SkTypeface.h>
//#include <SkFontHost.h>
#include <SkAdvancedTypefaceMetrics.h>
#include <mapnik/skia/skia_typeface_cache.hpp>
@ -53,9 +54,11 @@ bool skia_typeface_cache::register_font(std::string const& file_name)
if (typeface)
{
SkAdvancedTypefaceMetrics * metrics = typeface->getAdvancedTypefaceMetrics(SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo);
std::cerr << metrics->fFontName.writable_str() << std::endl;
//typefaces_.insert(std::make_pair(
std::cerr << metrics->fFontName.c_str() << std::endl;
typefaces_.insert(std::make_pair(std::string(metrics->fFontName.c_str()),typeface));
return true;
}
return false;
}
bool skia_typeface_cache::register_fonts(std::string const& dir, bool recurse)