[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).
This commit is contained in:
Alexander Shalamov
2019-08-04 14:44:22 +03:00
parent 03bb17f8c5
commit 1b9d4d792c
6 changed files with 31 additions and 8 deletions

View File

@@ -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;
}