summaryrefslogtreecommitdiff
path: root/src/mbgl/text/shaping.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text/shaping.cpp')
-rw-r--r--src/mbgl/text/shaping.cpp70
1 files changed, 35 insertions, 35 deletions
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp
index 02dbf146e1..ba21b97389 100644
--- a/src/mbgl/text/shaping.cpp
+++ b/src/mbgl/text/shaping.cpp
@@ -1,4 +1,5 @@
#include <mbgl/text/shaping.hpp>
+#include <mbgl/util/constants.hpp>
#include <mbgl/util/i18n.hpp>
#include <mbgl/layout/symbol_feature.hpp>
#include <mbgl/math/minmax.hpp>
@@ -10,58 +11,61 @@
namespace mbgl {
-struct AnchorAlignment {
- AnchorAlignment(float horizontal_, float vertical_)
- : horizontalAlign(horizontal_), verticalAlign(vertical_) {
- }
-
- float horizontalAlign;
- float verticalAlign;
-};
-AnchorAlignment getAnchorAlignment(style::SymbolAnchorType anchor) {
- float horizontalAlign = 0.5;
- float verticalAlign = 0.5;
+// static
+AnchorAlignment AnchorAlignment::getAnchorAlignment(style::SymbolAnchorType anchor) {
+ AnchorAlignment result(0.5f, 0.5f);
switch (anchor) {
- case style::SymbolAnchorType::Top:
- case style::SymbolAnchorType::Bottom:
- case style::SymbolAnchorType::Center:
- break;
case style::SymbolAnchorType::Right:
case style::SymbolAnchorType::TopRight:
case style::SymbolAnchorType::BottomRight:
- horizontalAlign = 1;
+ result.horizontalAlign = 1.0f;
break;
case style::SymbolAnchorType::Left:
case style::SymbolAnchorType::TopLeft:
case style::SymbolAnchorType::BottomLeft:
- horizontalAlign = 0;
+ result.horizontalAlign = 0.0f;
break;
+ default:
+ break;
}
switch (anchor) {
- case style::SymbolAnchorType::Left:
- case style::SymbolAnchorType::Right:
- case style::SymbolAnchorType::Center:
- break;
case style::SymbolAnchorType::Bottom:
case style::SymbolAnchorType::BottomLeft:
case style::SymbolAnchorType::BottomRight:
- verticalAlign = 1;
+ result.verticalAlign = 1.0f;
break;
case style::SymbolAnchorType::Top:
case style::SymbolAnchorType::TopLeft:
case style::SymbolAnchorType::TopRight:
- verticalAlign = 0;
+ result.verticalAlign = 0.0f;
+ break;
+ default:
break;
}
- return AnchorAlignment(horizontalAlign, verticalAlign);
+ return result;
+}
+
+style::TextJustifyType getAnchorJustification(style::SymbolAnchorType anchor) {
+ switch (anchor) {
+ case style::SymbolAnchorType::Right:
+ case style::SymbolAnchorType::TopRight:
+ case style::SymbolAnchorType::BottomRight:
+ return style::TextJustifyType::Right;
+ case style::SymbolAnchorType::Left:
+ case style::SymbolAnchorType::TopLeft:
+ case style::SymbolAnchorType::BottomLeft:
+ return style::TextJustifyType::Left;
+ default:
+ return style::TextJustifyType::Center;
+ }
}
PositionedIcon PositionedIcon::shapeIcon(const ImagePosition& image, const std::array<float, 2>& iconOffset, style::SymbolAnchorType iconAnchor, const float iconRotation) {
- AnchorAlignment anchorAlign = getAnchorAlignment(iconAnchor);
+ AnchorAlignment anchorAlign = AnchorAlignment::getAnchorAlignment(iconAnchor);
float dx = iconOffset[0];
float dy = iconOffset[1];
float x1 = dx - image.displaySize()[0] * anchorAlign.horizontalAlign;
@@ -269,7 +273,6 @@ void shapeLines(Shaping& shaping,
const float lineHeight,
const style::SymbolAnchorType textAnchor,
const style::TextJustifyType textJustify,
- const float verticalHeight,
const WritingModeType writingMode,
const GlyphMap& glyphMap) {
@@ -314,7 +317,7 @@ void shapeLines(Shaping& shaping,
// We don't know the baseline, but since we're laying out
// at 24 points, we can calculate how much it will move when
// we scale up or down.
- const double baselineOffset = (lineMaxScale - section.scale) * 24;
+ const double baselineOffset = (lineMaxScale - section.scale) * util::ONE_EM;
const Glyph& glyph = **it->second;
@@ -323,7 +326,7 @@ void shapeLines(Shaping& shaping,
x += glyph.metrics.advance * section.scale + spacing;
} else {
shaping.positionedGlyphs.emplace_back(codePoint, x, baselineOffset, true, section.fontStackHash, section.scale, sectionIndex);
- x += verticalHeight * section.scale + spacing;
+ x += util::ONE_EM * section.scale + spacing;
}
}
@@ -340,7 +343,7 @@ void shapeLines(Shaping& shaping,
y += lineHeight * lineMaxScale;
}
- auto anchorAlign = getAnchorAlignment(textAnchor);
+ auto anchorAlign = AnchorAlignment::getAnchorAlignment(textAnchor);
align(shaping, justify, anchorAlign.horizontalAlign, anchorAlign.verticalAlign, maxLineLength,
lineHeight, lines.size());
@@ -360,12 +363,9 @@ const Shaping getShaping(const TaggedString& formattedString,
const style::TextJustifyType textJustify,
const float spacing,
const Point<float>& translate,
- const float verticalHeight,
const WritingModeType writingMode,
BiDi& bidi,
- const GlyphMap& glyphs) {
- Shaping shaping(translate.x, translate.y, writingMode);
-
+ const GlyphMap& glyphs) {
std::vector<TaggedString> reorderedLines;
if (formattedString.sectionCount() == 1) {
auto untaggedLines = bidi.processText(formattedString.rawText(),
@@ -380,9 +380,9 @@ const Shaping getShaping(const TaggedString& formattedString,
reorderedLines.emplace_back(line, formattedString.getSections());
}
}
-
+ Shaping shaping(translate.x, translate.y, writingMode, reorderedLines.size());
shapeLines(shaping, reorderedLines, spacing, lineHeight, textAnchor,
- textJustify, verticalHeight, writingMode, glyphs);
+ textJustify, writingMode, glyphs);
return shaping;
}