Skip to content

Commit 1aeae88

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
text-combine-upright should ignore letter-spacing
https://bugs.webkit.org/show_bug.cgi?id=262765 rdar://problem/116562622 Reviewed by Vitor Roriz and Alan Baradlay. This patch aligns WebKit with Web Specification [1]: "the glyphs of the combined text are bidi-isolated and composed horizontally (ignoring letter-spacing and any forced line breaks, but using the specified font settings)" [1] https://drafts.csswg.org/css-writing-modes-3/#text-combine-layout This patch fixes it by setting letter spacing to ignore. * Source/WebCore/rendering/RenderCombineText.cpp: (WebCore::RenderCombineText::combineTextIfNeeded): * LayoutTests/imported/w3c/web-platform-tests/css/css-writing-modes/text-combine-upright-letter-spacing-001-expected.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-writing-modes/text-combine-upright-letter-spacing-001-ref.html: Added. * LayoutTests/imported/w3c/web-platform-tests/css/css-writing-modes/text-combine-upright-letter-spacing-001.html: Added. Canonical link: https://commits.webkit.org/305116@main
1 parent b9d9f81 commit 1aeae88

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>CSS Writing Modes Test: text-combine-upright ignores letter-spacing (reference)</title>
4+
<style>
5+
span { text-combine-upright: all; }
6+
</style>
7+
<p style="writing-mode: vertical-rl">test <span>this</span> <span>this</span></p>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>CSS Writing Modes Test: text-combine-upright ignores letter-spacing (reference)</title>
4+
<style>
5+
span { text-combine-upright: all; }
6+
</style>
7+
<p style="writing-mode: vertical-rl">test <span>this</span> <span>this</span></p>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>CSS Writing Modes Test: text-combine-upright ignores letter-spacing</title>
4+
<link rel="help" href="https://www.w3.org/TR/css-writing-modes-3/#text-combine-layout">
5+
<link rel="match" href="text-combine-upright-letter-spacing-001-ref.html">
6+
<meta name="assert" content="text-combine-upright should ignore letter-spacing when composing text horizontally.">
7+
<style>
8+
span { text-combine-upright: all; }
9+
</style>
10+
<p style="writing-mode: vertical-rl">test <span style="letter-spacing: 2px">this</span> <span>this</span></p>

Source/WebCore/rendering/RenderCombineText.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2011 Apple Inc. All rights reserved.
2+
* Copyright (C) 2011-2025 Apple Inc. All rights reserved.
33
*
44
* This library is free software; you can redistribute it and/or
55
* modify it under the terms of the GNU Library General Public
@@ -121,6 +121,7 @@ void RenderCombineText::combineTextIfNeeded()
121121

122122
FontCascade horizontalFont(FontCascadeDescription { description }, style().fontCascade());
123123
horizontalFont.update(fontSelector.copyRef());
124+
horizontalFont.setLetterSpacing(0);
124125

125126
GlyphOverflow glyphOverflow;
126127
glyphOverflow.computeBounds = true;
@@ -131,16 +132,18 @@ void RenderCombineText::combineTextIfNeeded()
131132

132133
m_isCombined = combinedTextWidth <= emWidth;
133134

134-
if (m_isCombined)
135+
if (m_isCombined) {
135136
m_combineFontStyle->setFontDescription(WTF::move(description)); // Need to change font orientation to horizontal.
136-
else {
137+
m_combineFontStyle->mutableFontCascadeWithoutUpdate().setLetterSpacing(0);
138+
} else {
137139
// Need to try compressed glyphs.
138140
static constexpr auto widthVariants = std::to_array<FontWidthVariant>({ FontWidthVariant::HalfWidth, FontWidthVariant::ThirdWidth, FontWidthVariant::QuarterWidth });
139141
for (auto widthVariant : widthVariants) {
140142
description.setWidthVariant(widthVariant); // When modifying this, make sure to keep it in sync with FontPlatformData::isForTextCombine()!
141143

142144
FontCascade compressedFont(FontCascadeDescription { description }, style().fontCascade());
143145
compressedFont.update(fontSelector.copyRef());
146+
compressedFont.setLetterSpacing(0);
144147

145148
glyphOverflow.left = glyphOverflow.top = glyphOverflow.right = glyphOverflow.bottom = 0;
146149
float runWidth = width(0, text().length(), compressedFont, 0, nullptr, &glyphOverflow);
@@ -150,6 +153,7 @@ void RenderCombineText::combineTextIfNeeded()
150153

151154
// Replace my font with the new one.
152155
m_combineFontStyle->setFontDescription(WTF::move(description));
156+
m_combineFontStyle->mutableFontCascadeWithoutUpdate().setLetterSpacing(0);
153157
break;
154158
}
155159

@@ -171,12 +175,14 @@ void RenderCombineText::combineTextIfNeeded()
171175

172176
FontCascade compressedFont(FontCascadeDescription { bestFitDescription }, style().fontCascade());
173177
compressedFont.update(fontSelector.copyRef());
178+
compressedFont.setLetterSpacing(0);
174179

175180
glyphOverflow.left = glyphOverflow.top = glyphOverflow.right = glyphOverflow.bottom = 0;
176181
float runWidth = width(0, text().length(), compressedFont, 0, nullptr, &glyphOverflow);
177182
if (runWidth <= emWidth) {
178183
combinedTextWidth = runWidth;
179184
m_isCombined = true;
185+
m_combineFontStyle->mutableFontCascadeWithoutUpdate().setLetterSpacing(0);
180186
break;
181187
}
182188
scaleFactor -= 0.05f;

0 commit comments

Comments
 (0)