From 67a88824573aa961bf1632cd83a3966bceca9660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 24 Mar 2014 11:13:20 +0100 Subject: [PATCH] use the correct glyphs --- include/llmr/map/tile_parser.hpp | 2 +- include/llmr/renderer/text_bucket.hpp | 2 +- include/llmr/text/glyph.hpp | 6 +++--- include/llmr/text/placement.hpp | 4 ++-- src/map/tile_parser.cpp | 6 +++--- src/renderer/text_bucket.cpp | 2 +- src/text/placement.cpp | 19 +++++++++++++------ 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/llmr/map/tile_parser.hpp b/include/llmr/map/tile_parser.hpp index 5789dd9de..26d1cbc50 100644 --- a/include/llmr/map/tile_parser.hpp +++ b/include/llmr/map/tile_parser.hpp @@ -26,7 +26,7 @@ private: TileData& tile; const Style& style; GlyphAtlas& glyphAtlas; - FaceGlyphPositions faces; + Faces faces; Placement placement; }; diff --git a/include/llmr/renderer/text_bucket.hpp b/include/llmr/renderer/text_bucket.hpp index 770e982cf..4306d8ba0 100644 --- a/include/llmr/renderer/text_bucket.hpp +++ b/include/llmr/renderer/text_bucket.hpp @@ -36,7 +36,7 @@ public: PlacementRange placementRange, float zoom); void addFeature(const VectorTileFeature &feature, - const IndexedFaceGlyphPositions &faces, + const IndexedFaces &faces, const std::map &shapings); bool empty() const; diff --git a/include/llmr/text/glyph.hpp b/include/llmr/text/glyph.hpp index 204ce5f14..09b4ddb5a 100644 --- a/include/llmr/text/glyph.hpp +++ b/include/llmr/text/glyph.hpp @@ -37,9 +37,9 @@ struct Glyph { const GlyphMetrics metrics; }; -typedef std::vector GlyphPositions; -typedef std::map FaceGlyphPositions; -typedef std::vector IndexedFaceGlyphPositions; +typedef std::map GlyphPositions; +typedef std::map Faces; +typedef std::vector IndexedFaces; class GlyphPlacement { public: diff --git a/include/llmr/text/placement.hpp b/include/llmr/text/placement.hpp index f84417901..8ec7df5e4 100644 --- a/include/llmr/text/placement.hpp +++ b/include/llmr/text/placement.hpp @@ -18,9 +18,9 @@ public: void addFeature(TextBucket &bucket, const std::vector &line, const BucketGeometryDescription &info, - const IndexedFaceGlyphPositions &faces, + const IndexedFaces &faces, const Shaping &shaping); - float measureText(const IndexedFaceGlyphPositions &faces, + float measureText(const IndexedFaces &faces, const Shaping &shaping); private: diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp index 95868c95a..1592f6b90 100644 --- a/src/map/tile_parser.cpp +++ b/src/map/tile_parser.cpp @@ -32,7 +32,7 @@ void TileParser::parseGlyphs() { for (const VectorTileGlyph &glyph : face.glyphs) { const Rect rect = glyphAtlas.addGlyph((uint64_t)tile.id, name, glyph); - glyphs.emplace_back(Glyph{rect, glyph.metrics}); + glyphs.emplace(glyph.id, Glyph{rect, glyph.metrics}); } } } @@ -141,9 +141,9 @@ std::shared_ptr TileParser::createTextBucket(const VectorTileLayer& laye // TODO: currently hardcoded to use the first font stack. const std::map& shaping = layer.shaping.begin()->second; - const FaceGlyphPositions& const_faces = faces; + const Faces& const_faces = faces; - IndexedFaceGlyphPositions faces; + IndexedFaces faces; for (const std::string& face : layer.faces) { auto it = const_faces.find(face); if (it == const_faces.end()) { diff --git a/src/renderer/text_bucket.cpp b/src/renderer/text_bucket.cpp index 8e488f21f..d515a4a2b 100644 --- a/src/renderer/text_bucket.cpp +++ b/src/renderer/text_bucket.cpp @@ -103,7 +103,7 @@ void TextBucket::addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, }; void TextBucket::addFeature(const VectorTileFeature &feature, - const IndexedFaceGlyphPositions &faces, + const IndexedFaces &faces, const std::map &shapings) { auto it_prop = feature.properties.find(geom_desc.text_field); if (it_prop == feature.properties.end()) { diff --git a/src/text/placement.cpp b/src/text/placement.cpp index 2380e191e..be329eda3 100644 --- a/src/text/placement.cpp +++ b/src/text/placement.cpp @@ -33,14 +33,21 @@ bool byScale(const Anchor &a, const Anchor &b) { return a.scale < b.scale; } static const Glyph null_glyph; inline const Glyph &getGlyph(const GlyphPlacement &placed, - const IndexedFaceGlyphPositions &faces) { + const IndexedFaces &faces) { if (placed.face < faces.size()) { const GlyphPositions &face = *faces[placed.face]; if (&face) { - if (placed.glyph < face.size()) { - return face[placed.glyph]; + auto it = face.find(placed.glyph); + if (it != face.end()) { + return it->second; + } else { + fprintf(stderr, "glyph %d does not exist\n", placed.glyph); } + } else { + fprintf(stderr, "face pointer is null\n"); } + } else { + fprintf(stderr, "face does not exist\n"); } return null_glyph; @@ -137,7 +144,7 @@ void getSegmentGlyphs(std::back_insert_iterator glyphs, } PlacedGlyphs getGlyphs(Anchor &anchor, float advance, const Shaping &shaping, - const IndexedFaceGlyphPositions &faces, float fontScale, + const IndexedFaces &faces, float fontScale, bool horizontal, const std::vector &line, float maxAngleDelta, float rotate) { // The total text advance is the width of this label. @@ -260,7 +267,7 @@ PlacedGlyphs getGlyphs(Anchor &anchor, float advance, const Shaping &shaping, void Placement::addFeature(TextBucket& bucket, const std::vector &line, const BucketGeometryDescription &info, - const IndexedFaceGlyphPositions &faces, + const IndexedFaces &faces, const Shaping &shaping) { const bool horizontal = info.path == TextPathType::Horizontal; @@ -306,7 +313,7 @@ void Placement::addFeature(TextBucket& bucket, } } -float Placement::measureText(const IndexedFaceGlyphPositions &faces, +float Placement::measureText(const IndexedFaces &faces, const Shaping &shaping) { float advance = 0;