From 55cb8188abe1c40758793b671e7ee5a8e32deb58 Mon Sep 17 00:00:00 2001 From: artemp Date: Thu, 18 Jul 2013 16:55:52 +0100 Subject: [PATCH] + initial text rendering support (FIXME: implement font metrics etc) --- demo/viewer/main.cpp | 12 ++++++++++++ include/mapnik/processed_text.hpp | 29 +++++++++++++++++++++-------- src/font_engine_freetype.cpp | 6 ++++-- src/skia/skia_renderer.cpp | 17 +++++++++++++---- src/skia/skia_typeface_cache.cpp | 7 +++++-- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/demo/viewer/main.cpp b/demo/viewer/main.cpp index 7bd6b3de8..511bd8368 100644 --- a/demo/viewer/main.cpp +++ b/demo/viewer/main.cpp @@ -24,6 +24,9 @@ #include #include #include +#if defined(HAVE_SKIA) +#include +#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 ); diff --git a/include/mapnik/processed_text.hpp b/include/mapnik/processed_text.hpp index 9cb33fe62..647673a07 100644 --- a/include/mapnik/processed_text.hpp +++ b/include/mapnik/processed_text.hpp @@ -30,6 +30,8 @@ #include // stl #include +// icu (temp) +#include 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_; diff --git a/src/font_engine_freetype.cpp b/src/font_engine_freetype.cpp index 09de096ec..7f66c62fd 100644 --- a/src/font_engine_freetype.cpp +++ b/src/font_engine_freetype.cpp @@ -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; diff --git a/src/skia/skia_renderer.cpp b/src/skia/skia_renderer.cpp index 7a91636a8..f57e81669 100644 --- a/src/skia/skia_renderer.cpp +++ b/src/skia/skia_renderer.cpp @@ -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(); } } } diff --git a/src/skia/skia_typeface_cache.cpp b/src/skia/skia_typeface_cache.cpp index 05f53130f..320f81d93 100644 --- a/src/skia/skia_typeface_cache.cpp +++ b/src/skia/skia_typeface_cache.cpp @@ -28,6 +28,7 @@ #endif #include +//#include #include #include @@ -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)