summaryrefslogtreecommitdiff
path: root/src/mbgl/text/shaping.cpp
diff options
context:
space:
mode:
authorLauren Budorick <lauren@mapbox.com>2017-07-26 13:18:47 -0700
committerGitHub <noreply@github.com>2017-07-26 13:18:47 -0700
commita8ef2af353de195648578bf0d753703cb6f34905 (patch)
treeb6afc3efd568b0310c9e6287d4c0c9c78bee5baf /src/mbgl/text/shaping.cpp
parentc5a5b4083795107b7df7bab39b461568a3861dba (diff)
downloadqtlocation-mapboxgl-a8ef2af353de195648578bf0d753703cb6f34905.tar.gz
[core][android][macos][ios] Implement property functions for line-join, text-justify, text-anchor (#9583)
Diffstat (limited to 'src/mbgl/text/shaping.cpp')
-rw-r--r--src/mbgl/text/shaping.cpp63
1 files changed, 51 insertions, 12 deletions
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp
index 6c7ecff42a..4a206e9bae 100644
--- a/src/mbgl/text/shaping.cpp
+++ b/src/mbgl/text/shaping.cpp
@@ -200,9 +200,8 @@ void shapeLines(Shaping& shaping,
const std::vector<std::u16string>& lines,
const float spacing,
const float lineHeight,
- const float horizontalAlign,
- const float verticalAlign,
- const float justify,
+ const style::TextAnchorType textAnchor,
+ const style::TextJustifyType textJustify,
const float verticalHeight,
const WritingModeType writingMode,
const Glyphs& glyphs) {
@@ -214,6 +213,10 @@ void shapeLines(Shaping& shaping,
float y = yOffset;
float maxLineLength = 0;
+
+ const float justify = textJustify == style::TextJustifyType::Right ? 1 :
+ textJustify == style::TextJustifyType::Left ? 0 :
+ 0.5;
for (std::u16string line : lines) {
// Collapse whitespace so it doesn't throw off justification
@@ -254,11 +257,48 @@ void shapeLines(Shaping& shaping,
x = 0;
y += lineHeight;
}
-
- align(shaping, justify, horizontalAlign, verticalAlign, maxLineLength, lineHeight,
- lines.size());
+
+ float horizontalAlign = 0.5;
+ float verticalAlign = 0.5;
+
+ switch (textAnchor) {
+ case style::TextAnchorType::Top:
+ case style::TextAnchorType::Bottom:
+ case style::TextAnchorType::Center:
+ break;
+ case style::TextAnchorType::Right:
+ case style::TextAnchorType::TopRight:
+ case style::TextAnchorType::BottomRight:
+ horizontalAlign = 1;
+ break;
+ case style::TextAnchorType::Left:
+ case style::TextAnchorType::TopLeft:
+ case style::TextAnchorType::BottomLeft:
+ horizontalAlign = 0;
+ break;
+ }
+
+ switch (textAnchor) {
+ case style::TextAnchorType::Left:
+ case style::TextAnchorType::Right:
+ case style::TextAnchorType::Center:
+ break;
+ case style::TextAnchorType::Bottom:
+ case style::TextAnchorType::BottomLeft:
+ case style::TextAnchorType::BottomRight:
+ verticalAlign = 1;
+ break;
+ case style::TextAnchorType::Top:
+ case style::TextAnchorType::TopLeft:
+ case style::TextAnchorType::TopRight:
+ verticalAlign = 0;
+ break;
+ }
+
+ align(shaping, justify, horizontalAlign, verticalAlign,
+ maxLineLength, lineHeight, lines.size());
const uint32_t height = lines.size() * lineHeight;
-
+
// Calculate the bounding box
shaping.top += -verticalAlign * height;
shaping.bottom = shaping.top + height;
@@ -269,9 +309,8 @@ void shapeLines(Shaping& shaping,
const Shaping getShaping(const std::u16string& logicalInput,
const float maxWidth,
const float lineHeight,
- const float horizontalAlign,
- const float verticalAlign,
- const float justify,
+ const style::TextAnchorType textAnchor,
+ const style::TextJustifyType textJustify,
const float spacing,
const Point<float>& translate,
const float verticalHeight,
@@ -284,8 +323,8 @@ const Shaping getShaping(const std::u16string& logicalInput,
bidi.processText(logicalInput,
determineLineBreaks(logicalInput, spacing, maxWidth, writingMode, glyphs));
- shapeLines(shaping, reorderedLines, spacing, lineHeight, horizontalAlign, verticalAlign,
- justify, verticalHeight, writingMode, glyphs);
+ shapeLines(shaping, reorderedLines, spacing, lineHeight, textAnchor,
+ textJustify, verticalHeight, writingMode, glyphs);
return shaping;
}