From 7c653895c6f6f7dc07241031277610efb439a243 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 30 May 2014 03:50:25 -0400 Subject: [PATCH] translate as a text bucket property When used, text is translated before being checked for collisions. --- bin/style.js | 18 ++++++++++-------- include/llmr/style/bucket_description.hpp | 2 ++ src/style/style_parser.cpp | 9 ++++++++- src/text/placement.cpp | 5 +---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bin/style.js b/bin/style.js index 38ffd7c32..3d24d6e79 100644 --- a/bin/style.js +++ b/bin/style.js @@ -765,8 +765,7 @@ module.exports = { "path": "horizontal", "font": "Open Sans Semibold, Arial Unicode MS Bold", "fontSize": 18, - "maxWidth": 2, - "lineHeight": 1.4, + "maxWidth": 6, "feature_type": "point", "type": "text" }, @@ -880,6 +879,9 @@ module.exports = { "text_field": "name", "path": "horizontal", "padding": 2, + "maxWidth": 8, + "verticalAlignment": "top", + "translate": [0, -1], "font": "Open Sans Semibold, Arial Unicode MS Bold", "fontSize": 11, "feature_type": "point", @@ -893,6 +895,9 @@ module.exports = { "text_field": "name", "path": "horizontal", "padding": 2, + "maxWidth": 8, + "verticalAlignment": "top", + "translate": [0, -1], "font": "Open Sans Semibold, Arial Unicode MS Bold", "fontSize": 10, "feature_type": "point", @@ -906,6 +911,9 @@ module.exports = { "text_field": "name", "path": "horizontal", "padding": 2, + "maxWidth": 8, + "verticalAlignment": "top", + "translate": [0, -1], "font": "Open Sans Semibold, Arial Unicode MS Bold", "fontSize": 10, "feature_type": "point", @@ -2417,7 +2425,6 @@ module.exports = { "stroke": "land", "strokeWidth": 0.3, "strokeBlur": 1, - "translate": [0, 14] }, "poi_label_3": { "color": "#444", @@ -2425,7 +2432,6 @@ module.exports = { "stroke": "land", "strokeWidth": 0.3, "strokeBlur": 1, - "translate": [0, 14], "opacity": [ "stops", {"z": 16.5, "val": 0}, @@ -2443,7 +2449,6 @@ module.exports = { "stroke": "land", "strokeWidth": 0.3, "strokeBlur": 1, - "translate": [0, 14] }, "poi_aerodrome": { "opacity": ["stops", @@ -3169,7 +3174,6 @@ module.exports = { "stroke": "text2_stroke_night", "strokeWidth": 0.3, "strokeBlur": 1, - "translate": [0, 14] }, "poi_label_3": { "color": "#fff", @@ -3177,7 +3181,6 @@ module.exports = { "stroke": "text2_stroke_night", "strokeWidth": 0.3, "strokeBlur": 1, - "translate": [0, 14], "opacity": [ "stops", {"z": 16.5, "val": 0}, @@ -3195,7 +3198,6 @@ module.exports = { "stroke": "text2_stroke_night", "strokeWidth": 0.3, "strokeBlur": 1, - "translate": [0, 14] }, "poi_aerodrome": { "opacity": ["stops", diff --git a/include/llmr/style/bucket_description.hpp b/include/llmr/style/bucket_description.hpp index b708ef686..e306b799f 100644 --- a/include/llmr/style/bucket_description.hpp +++ b/include/llmr/style/bucket_description.hpp @@ -6,6 +6,7 @@ #include #include "value.hpp" +#include "../util/vec.hpp" namespace llmr { @@ -95,6 +96,7 @@ public: float vertical_alignment = 0.5; float line_height = 1.2 * 24; float max_width = 15.0f * 24; + vec2 translate {0, 0}; float padding = 2.0f; float textMinDistance = 250.0f; float rotate = 0.0f; // what is this? diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 535e63916..1a1d8ee1e 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -108,11 +108,18 @@ BucketDescription StyleParser::parseBucket(JSVal value) { } else { throw Style::exception("alignment must be a string"); } + } else if (name == "translate") { + if (value.IsArray()) { + bucket.geometry.translate.x = value[(rapidjson::SizeType)0].GetDouble() * 24; + bucket.geometry.translate.y = value[(rapidjson::SizeType)1].GetDouble() * -24; + } else { + throw Style::exception("translate must be a string"); + } } else if (name == "verticalAlignment") { if (value.IsString()) { bucket.geometry.vertical_alignment = verticalAlignmentType({ value.GetString(), value.GetStringLength() }); } else { - throw Style::exception("alignment must be a string"); + throw Style::exception("verticalAlignment must be a string"); } } else if (name == "lineHeight") { if (value.IsNumber()) { diff --git a/src/text/placement.cpp b/src/text/placement.cpp index edefa6075..b15e32496 100644 --- a/src/text/placement.cpp +++ b/src/text/placement.cpp @@ -260,9 +260,6 @@ void Placement::addFeature(TextBucket& bucket, Anchors anchors; - // TODO: figure out correct ascender height. - vec2 origin{0, 0}; - if (line.size() == 1) { // Point labels anchors = Anchors{{Anchor{ @@ -282,7 +279,7 @@ void Placement::addFeature(TextBucket& bucket, PlacedGlyphs glyphs; GlyphBoxes boxes; - getGlyphs(glyphs, boxes, anchor, origin, shaping, face, fontScale, horizontal, + getGlyphs(glyphs, boxes, anchor, info.translate, shaping, face, fontScale, horizontal, line, maxAngleDelta, rotate); PlacementProperty place = collision.place(boxes, anchor, anchor.scale, maxPlacementScale,