+ initial text rendering support (FIXME: implement font metrics etc)
This commit is contained in:
parent
6a82e617cc
commit
55cb8188ab
5 changed files with 55 additions and 16 deletions
|
@ -24,6 +24,9 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <mapnik/datasource_cache.hpp>
|
#include <mapnik/datasource_cache.hpp>
|
||||||
#include <mapnik/font_engine_freetype.hpp>
|
#include <mapnik/font_engine_freetype.hpp>
|
||||||
|
#if defined(HAVE_SKIA)
|
||||||
|
#include <mapnik/skia/skia_typeface_cache.hpp>
|
||||||
|
#endif
|
||||||
#include "mainwindow.hpp"
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
// boost
|
// boost
|
||||||
|
@ -54,6 +57,15 @@ int main( int argc, char **argv )
|
||||||
QString font_dir = settings.value("dir").toString();
|
QString font_dir = settings.value("dir").toString();
|
||||||
freetype_engine::register_fonts(font_dir.toStdString());
|
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();
|
settings.endArray();
|
||||||
|
|
||||||
QApplication app( argc, argv );
|
QApplication app( argc, argv );
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include <mapnik/skia/skia_font_manager.hpp>
|
#include <mapnik/skia/skia_font_manager.hpp>
|
||||||
// stl
|
// stl
|
||||||
#include <list>
|
#include <list>
|
||||||
|
// icu (temp)
|
||||||
|
#include <unicode/schriter.h>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik {
|
||||||
|
|
||||||
|
@ -86,14 +88,25 @@ public:
|
||||||
for (; itr != end; ++itr)
|
for (; itr != end; ++itr)
|
||||||
{
|
{
|
||||||
char_properties const& p = itr->p;
|
char_properties const& p = itr->p;
|
||||||
std::cerr << p.face_name << " : " << p.fontset << std::endl;
|
if (p.fontset)
|
||||||
//face_set_ptr faces = font_manager.get_face_set(p.face_name, p.fontset);
|
{
|
||||||
//if (faces->size() > 0)
|
for (auto const& face_name : p.fontset->get_face_names())
|
||||||
//{
|
{
|
||||||
//faces->set_character_sizes(p.text_size * scale_factor_); // ???
|
std::cerr << face_name << std::endl;
|
||||||
// faces->get_string_info(info_, itr->str, &(itr->p));
|
}
|
||||||
// info_.add_text(itr->str);
|
}
|
||||||
//}
|
|
||||||
|
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_;
|
return info_;
|
||||||
|
|
|
@ -375,9 +375,11 @@ void font_face_set::get_string_info(string_info & info, UnicodeString const& ust
|
||||||
|
|
||||||
shaped.releaseBuffer(length);
|
shaped.releaseBuffer(length);
|
||||||
|
|
||||||
if (U_SUCCESS(err)) {
|
if (U_SUCCESS(err))
|
||||||
|
{
|
||||||
StringCharacterIterator iter(shaped);
|
StringCharacterIterator iter(shaped);
|
||||||
for (iter.setToStart(); iter.hasNext();) {
|
for (iter.setToStart(); iter.hasNext();)
|
||||||
|
{
|
||||||
UChar ch = iter.nextPostInc();
|
UChar ch = iter.nextPostInc();
|
||||||
char_info char_dim = character_dimensions(ch);
|
char_info char_dim = character_dimensions(ch);
|
||||||
char_dim.format = format;
|
char_dim.format = format;
|
||||||
|
|
|
@ -259,10 +259,8 @@ void skia_renderer::process(text_symbolizer const& sym,
|
||||||
|
|
||||||
for (unsigned i = 0; i < placements.size(); ++i)
|
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 sx = placements[i].center.x;
|
||||||
double sy = placements[i].center.y;
|
double sy = placements[i].center.y;
|
||||||
|
|
||||||
placements[i].rewind();
|
placements[i].rewind();
|
||||||
|
|
||||||
for (int j = 0; j < placements[i].num_nodes(); ++j)
|
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;
|
char_info_ptr c;
|
||||||
double x, y, angle;
|
double x, y, angle;
|
||||||
placements[i].vertex(c, x, y, angle);
|
placements[i].vertex(c, x, y, angle);
|
||||||
std::cerr << c << " " << x << "," << y << " angle=" << angle << std::endl;
|
SkPaint paint;
|
||||||
//context_.add_text(placements[ii], face_manager_, font_manager_, scale_factor_);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <SkTypeface.h>
|
#include <SkTypeface.h>
|
||||||
|
//#include <SkFontHost.h>
|
||||||
#include <SkAdvancedTypefaceMetrics.h>
|
#include <SkAdvancedTypefaceMetrics.h>
|
||||||
|
|
||||||
#include <mapnik/skia/skia_typeface_cache.hpp>
|
#include <mapnik/skia/skia_typeface_cache.hpp>
|
||||||
|
@ -53,9 +54,11 @@ bool skia_typeface_cache::register_font(std::string const& file_name)
|
||||||
if (typeface)
|
if (typeface)
|
||||||
{
|
{
|
||||||
SkAdvancedTypefaceMetrics * metrics = typeface->getAdvancedTypefaceMetrics(SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo);
|
SkAdvancedTypefaceMetrics * metrics = typeface->getAdvancedTypefaceMetrics(SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo);
|
||||||
std::cerr << metrics->fFontName.writable_str() << std::endl;
|
std::cerr << metrics->fFontName.c_str() << std::endl;
|
||||||
//typefaces_.insert(std::make_pair(
|
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)
|
bool skia_typeface_cache::register_fonts(std::string const& dir, bool recurse)
|
||||||
|
|
Loading…
Add table
Reference in a new issue