summaryrefslogtreecommitdiff
path: root/src/mbgl/text/shaping.cpp
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-08-04 14:44:22 +0300
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-08-13 13:32:56 +0300
commit1b9d4d792cbd877f627987cbd0d5ed41709375c8 (patch)
tree5571f19bc807620e61a5762e41a8e2c2a6561134 /src/mbgl/text/shaping.cpp
parent03bb17f8c506164efa39708cd2caea7aa11403f7 (diff)
downloadqtlocation-mapboxgl-1b9d4d792cbd877f627987cbd0d5ed41709375c8.tar.gz
[core] Render half-width glyphs in upright orientation
This change forces glyphs whose natural orientation in vertical writing mode is 'sideways' to be rendered in upright orientation (only for non complex text layouts). This is different compared to W3C / browser behavior that is by default, renders glyphs in their respective natural orientation. In the future, there might need to add a new layout property that would control glyph orientation separately (e.g., text-glyph-orientation: natural | upright).
Diffstat (limited to 'src/mbgl/text/shaping.cpp')
-rw-r--r--src/mbgl/text/shaping.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp
index 3ed35fc725..7bf0e14f80 100644
--- a/src/mbgl/text/shaping.cpp
+++ b/src/mbgl/text/shaping.cpp
@@ -290,7 +290,8 @@ void shapeLines(Shaping& shaping,
const style::SymbolAnchorType textAnchor,
const style::TextJustifyType textJustify,
const WritingModeType writingMode,
- const GlyphMap& glyphMap) {
+ const GlyphMap& glyphMap,
+ bool allowVerticalPlacement) {
float x = 0;
float y = Shaping::yOffset;
@@ -332,8 +333,13 @@ void shapeLines(Shaping& shaping,
const double baselineOffset = (lineMaxScale - section.scale) * util::ONE_EM;
const Glyph& glyph = **it->second;
-
- if (writingMode == WritingModeType::Horizontal || !util::i18n::hasUprightVerticalOrientation(codePoint)) {
+
+ if (writingMode == WritingModeType::Horizontal ||
+ // Don't verticalize glyphs that have no upright orientation if vertical placement is disabled.
+ (!allowVerticalPlacement && !util::i18n::hasUprightVerticalOrientation(codePoint)) ||
+ // If vertical placement is ebabled, don't verticalize glyphs that
+ // are from complex text layout script, or whitespaces.
+ (allowVerticalPlacement && (util::i18n::isWhitespace(codePoint) || util::i18n::isCharInComplexShapingScript(codePoint)))) {
shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale, sectionIndex);
x += glyph.metrics.advance * section.scale + spacing;
} else {
@@ -377,7 +383,8 @@ const Shaping getShaping(const TaggedString& formattedString,
const Point<float>& translate,
const WritingModeType writingMode,
BiDi& bidi,
- const GlyphMap& glyphs) {
+ const GlyphMap& glyphs,
+ bool allowVerticalPlacement) {
std::vector<TaggedString> reorderedLines;
if (formattedString.sectionCount() == 1) {
auto untaggedLines = bidi.processText(formattedString.rawText(),
@@ -394,7 +401,7 @@ const Shaping getShaping(const TaggedString& formattedString,
}
Shaping shaping(translate.x, translate.y, writingMode, reorderedLines.size());
shapeLines(shaping, reorderedLines, spacing, lineHeight, textAnchor,
- textJustify, writingMode, glyphs);
+ textJustify, writingMode, glyphs, allowVerticalPlacement);
return shaping;
}