From 073d8d91c8f0ce2ac6db2bef7acc64d018546dee Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Thu, 22 May 2014 16:56:37 -0400 Subject: [PATCH] update fontstack protobuf message --- proto/vector_tile.proto | 3 ++- src/tile.cpp | 51 ++++++++++++++++++----------------------- src/tile.hpp | 1 - 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/proto/vector_tile.proto b/proto/vector_tile.proto index 0e2cd8b..d84ddf2 100644 --- a/proto/vector_tile.proto +++ b/proto/vector_tile.proto @@ -100,7 +100,8 @@ message face { // Stores fontstack information and a list of faces. message fontstack { required string name = 1; - repeated string faces = 2; + required string range = 2; + repeated glyph glyphs = 3; } // Stores the shaping information for the label with a given text diff --git a/src/tile.cpp b/src/tile.cpp index 061d477..14d90cc 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -8,6 +8,7 @@ // stl #include #include +#include #include // freetype2 @@ -357,11 +358,18 @@ void Tile::AsyncRange(uv_work_t* req) { std::map face_map; std::vector tile_faces; + FT_UInt glyph_index = baton->start; + FT_UInt glyph_end = baton->end; + llmr::vector::tile& tile = baton->tile->tile; llmr::vector::fontstack *mutable_fontstack = tile.add_stacks(); mutable_fontstack->set_name(baton->fontstack); + std::stringstream range; + range << baton->start << "-" << baton->end; + mutable_fontstack->set_range(range.str()); + fontserver::text_format format(baton->fontstack, 24); const double scale_factor = 1.0; @@ -369,17 +377,12 @@ void Tile::AsyncRange(uv_work_t* req) { double size = format.text_size * scale_factor; face_set->set_character_sizes(size); - FT_UInt glyph_index = baton->start; - FT_UInt glyph_end = baton->end; - for (auto const& face : *face_set) { // Create tile_face, add to face_map and tile_faces. fontserver::tile_face *t_face = new fontserver::tile_face(face); face_map.emplace(face, t_face); tile_faces.push_back(t_face); - mutable_fontstack->add_faces(t_face->family + ' ' + t_face->style); - // Get FreeType face from face_ptr. FT_Face ft_face = face->get_face(); @@ -400,7 +403,20 @@ void Tile::AsyncRange(uv_work_t* req) { } } - InsertGlyphs(tile, tile_faces); + for (auto const& face : tile_faces) { + for (auto const& glyph : face->glyphs) { + llmr::vector::glyph *mutable_glyph = mutable_fontstack->add_glyphs(); + mutable_glyph->set_id(glyph.glyph_index); + mutable_glyph->set_width(glyph.width); + mutable_glyph->set_height(glyph.height); + mutable_glyph->set_left(glyph.left); + mutable_glyph->set_top(glyph.top); + mutable_glyph->set_advance(glyph.advance); + if (glyph.width > 0) { + mutable_glyph->set_bitmap(glyph.bitmap); + } + } + } } // Insert glyph indexes @@ -418,29 +434,6 @@ void Tile::InsertIndexes(llmr::vector::tile &tile, } } -// Insert SDF glyphs + bitmaps -void Tile::InsertGlyphs(llmr::vector::tile &tile, - std::vector &tile_faces) { - for (auto const& face : tile_faces) { - llmr::vector::face *mutable_face = tile.add_faces(); - mutable_face->set_family(face->family); - mutable_face->set_style(face->style); - - for (auto const& glyph : face->glyphs) { - llmr::vector::glyph *mutable_glyph = mutable_face->add_glyphs(); - mutable_glyph->set_id(glyph.glyph_index); - mutable_glyph->set_width(glyph.width); - mutable_glyph->set_height(glyph.height); - mutable_glyph->set_left(glyph.left); - mutable_glyph->set_top(glyph.top); - mutable_glyph->set_advance(glyph.advance); - if (glyph.width > 0) { - mutable_glyph->set_bitmap(glyph.bitmap); - } - } - } -} - void Tile::ShapeAfter(uv_work_t* req) { v8::HandleScope scope; ShapeBaton* baton = static_cast(req->data); diff --git a/src/tile.hpp b/src/tile.hpp index 516885d..a931bb8 100644 --- a/src/tile.hpp +++ b/src/tile.hpp @@ -27,7 +27,6 @@ protected: static void AsyncRange(uv_work_t* req); static void InsertIndexes(llmr::vector::tile &tile, std::vector &tile_faces); - static void InsertGlyphs(llmr::vector::tile &tile, std::vector &tile_faces); static void ShapeAfter(uv_work_t* req); static void RangeAfter(uv_work_t* req);