add text letterSpacing

This commit is contained in:
Ansis Brammanis
2014-05-30 04:02:23 -04:00
parent 7c653895c6
commit 9ac55e0d74
5 changed files with 14 additions and 4 deletions

View File

@@ -96,6 +96,7 @@ public:
float vertical_alignment = 0.5;
float line_height = 1.2 * 24;
float max_width = 15.0f * 24;
float letter_spacing = 0;
vec2<float> translate {0, 0};
float padding = 2.0f;
float textMinDistance = 250.0f;

View File

@@ -34,7 +34,8 @@ public:
const float &maxWidth,
const float &lineHeight,
const float &alignment,
const float &verticalAlignment) const;
const float &verticalAlignment,
const float &letterSpacing) const;
Shaping lineWrap(Shaping shaped,
const float &lineHeight,
const float &maxWidth,

View File

@@ -227,7 +227,7 @@ std::unique_ptr<Bucket> TileParser::createTextBucket(const VectorTileLayer& laye
// Shape labels.
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);
bucket_desc.geometry.vertical_alignment, bucket_desc.geometry.letter_spacing);
shaping.emplace(toString(it_prop->second), shaped);
// Place labels.

View File

@@ -133,6 +133,12 @@ BucketDescription StyleParser::parseBucket(JSVal value) {
} else {
throw Style::exception("max width must be a number");
}
} else if (name == "letterSpacing") {
if (value.IsNumber()) {
bucket.geometry.letter_spacing = value.GetDouble() * 24;
} else {
throw Style::exception("letter spacing must be a number");
}
} else if (name == "miterLimit") {
if (value.IsNumber()) {
bucket.geometry.miter_limit = value.GetDouble();

View File

@@ -30,7 +30,9 @@ const std::map<uint32_t, SDFGlyph> &FontStack::getSDFs() const {
}
const Shaping FontStack::getShaping(const std::u32string &string, const float &maxWidth,
const float &lineHeight, const float &alignment, const float &verticalAlignment) const {
const float &lineHeight, const float &alignment, const float &verticalAlignment,
const float &letterSpacing) const {
std::lock_guard<std::mutex> lock(mtx);
uint32_t i = 0;
uint32_t x = 0;
@@ -40,7 +42,7 @@ const Shaping FontStack::getShaping(const std::u32string &string, const float &m
GlyphPlacement glyph = GlyphPlacement(0, chr, x, 0);
shaped.push_back(glyph);
i++;
x += metrics.find(chr)->second.advance;
x += metrics.find(chr)->second.advance + letterSpacing;
}
shaped = lineWrap(shaped, lineHeight, maxWidth, alignment, verticalAlignment);