summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnsis Brammanis <ansis.brammanis@gmail.com>2014-05-30 03:11:57 -0400
committerAnsis Brammanis <ansis.brammanis@gmail.com>2014-05-30 03:11:57 -0400
commit41c310c76238d3a2823c79592b553a6ff3205c47 (patch)
tree8e017924c9ac1bc7d1d56d00c19366b2e398abe8 /src
parent9057c4980dc12515cd8d6f33d9253e61592272fe (diff)
downloadqtlocation-mapboxgl-41c310c76238d3a2823c79592b553a6ff3205c47.tar.gz
add verticalAlign for text
Default is center. Other options are "top" and "bottom"
Diffstat (limited to 'src')
-rw-r--r--src/map/tile_parser.cpp4
-rw-r--r--src/style/style_parser.cpp6
-rw-r--r--src/text/glyph_store.cpp29
-rw-r--r--src/text/placement.cpp2
4 files changed, 30 insertions, 11 deletions
diff --git a/src/map/tile_parser.cpp b/src/map/tile_parser.cpp
index 4313003189..f2b3ac05cb 100644
--- a/src/map/tile_parser.cpp
+++ b/src/map/tile_parser.cpp
@@ -225,7 +225,9 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye
const std::u32string string = ucs4conv.convert(toString(it_prop->second));
// Shape labels.
- const Shaping shaped = fontStack.getShaping(string, bucket_desc.geometry.max_width, bucket_desc.geometry.line_height, bucket_desc.geometry.alignment);
+ const Shaping shaped = fontStack.getShaping(string, bucket_desc.geometry.max_width,
+ bucket_desc.geometry.line_height, bucket_desc.geometry.alignment,
+ bucket_desc.geometry.vertical_alignment);
shaping.emplace(toString(it_prop->second), shaped);
// Place labels.
diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp
index ba189f76f2..535e63916e 100644
--- a/src/style/style_parser.cpp
+++ b/src/style/style_parser.cpp
@@ -108,6 +108,12 @@ BucketDescription StyleParser::parseBucket(JSVal value) {
} else {
throw Style::exception("alignment 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");
+ }
} else if (name == "lineHeight") {
if (value.IsNumber()) {
bucket.geometry.line_height = value.GetDouble() * 24;
diff --git a/src/text/glyph_store.cpp b/src/text/glyph_store.cpp
index 6293aee23b..ac647eb842 100644
--- a/src/text/glyph_store.cpp
+++ b/src/text/glyph_store.cpp
@@ -29,7 +29,8 @@ const std::map<uint32_t, SDFGlyph> &FontStack::getSDFs() const {
return sdfs;
}
-const Shaping FontStack::getShaping(const std::u32string &string, const float &maxWidth, const float &lineHeight, const float &alignment) const {
+const Shaping FontStack::getShaping(const std::u32string &string, const float &maxWidth,
+ const float &lineHeight, const float &alignment, const float &verticalAlignment) const {
std::lock_guard<std::mutex> lock(mtx);
uint32_t i = 0;
uint32_t x = 0;
@@ -42,23 +43,32 @@ const Shaping FontStack::getShaping(const std::u32string &string, const float &m
x += metrics.find(chr)->second.advance;
}
- shaped = lineWrap(shaped, lineHeight, maxWidth, alignment);
+ shaped = lineWrap(shaped, lineHeight, maxWidth, alignment, verticalAlignment);
return shaped;
}
+void alignVertically(Shaping &shaping, const uint32_t &lines, const float &lineHeight, const float &verticalAlign) {
+ const float dy = -(lineHeight * (lines - 1) + 24) * verticalAlign - 5;
+ for (GlyphPlacement &shape : shaping) {
+ shape.y += dy;
+ }
+}
+
void alignHorizontally(Shaping &shaping, const std::map<uint32_t, GlyphMetrics> &metrics,
const uint32_t &start, const uint32_t &end, const float &alignment) {
- uint32_t lastAdvance = metrics.find(shaping[end].glyph)->second.advance;
- int32_t lineIndent = (shaping[end].x + lastAdvance) * alignment;
+ uint32_t lastAdvance = metrics.find(shaping[end].glyph)->second.advance;
+ int32_t lineIndent = (shaping[end].x + lastAdvance) * alignment;
+
+ for (uint32_t j = start; j <= end; j++) {
+ shaping[j].x -= lineIndent;
+ }
+}
- for (uint32_t j = start; j <= end; j++) {
- shaping[j].x -= lineIndent;
- }
- }
+Shaping FontStack::lineWrap(Shaping shaped, const float &lineHeight, const float &maxWidth,
+ const float &alignment, const float &verticalAlignment) const {
-Shaping FontStack::lineWrap(Shaping shaped, const float &lineHeight, const float &maxWidth, const float &alignment) const {
uint32_t lastSafeBreak = 0;
uint32_t lengthBeforeCurrentLine = 0;
uint32_t lineStartIndex = 0;
@@ -94,6 +104,7 @@ Shaping FontStack::lineWrap(Shaping shaped, const float &lineHeight, const float
}
alignHorizontally(shaped, metrics, lineStartIndex, shaped.size() - 1, alignment);
+ alignVertically(shaped, line + 1, lineHeight, verticalAlignment);
return shaped;
}
diff --git a/src/text/placement.cpp b/src/text/placement.cpp
index ed71f881e2..edefa6075d 100644
--- a/src/text/placement.cpp
+++ b/src/text/placement.cpp
@@ -261,7 +261,7 @@ void Placement::addFeature(TextBucket& bucket,
Anchors anchors;
// TODO: figure out correct ascender height.
- vec2<float> origin{0, -17};
+ vec2<float> origin{0, 0};
if (line.size() == 1) {
// Point labels