Skip to content

Commit

Permalink
Turning text-spacing properties into font properties
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=252660
rdar://105722440

Reviewed by Antti Koivisto.

We need turn text-spacing properties into font properties such that
they are accessible during FontCascade width calculations.

* Source/WebCore/css/CSSProperties.json:
* Source/WebCore/platform/graphics/FontCascade.h:
(WebCore::FontCascade::textSpacingTrim const):
(WebCore::FontCascade::textAutospace const):
* Source/WebCore/platform/graphics/FontCascadeDescription.h:
(WebCore::FontCascadeDescription::initialTextSpacingTrim):
(WebCore::FontCascadeDescription::initialTextAutospace):
* Source/WebCore/platform/graphics/FontDescription.h:
(WebCore::FontDescription::textSpacingTrim const):
(WebCore::FontDescription::textAutospace const):
(WebCore::FontDescription::setTextSpacingTrim):
(WebCore::FontDescription::setTextAutospace):
(WebCore::FontDescription::operator== const):
(WebCore::FontDescription::encode const):
(WebCore::FontDescription::decode):
* Source/WebCore/rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::textSpacingTrim const):
(WebCore::RenderStyle::textAutospace const):
(WebCore::RenderStyle::setTextSpacingTrim):
(WebCore::RenderStyle::setTextAutospace):
* Source/WebCore/rendering/style/RenderStyle.h:
(WebCore::RenderStyle::initialTextOrientation):
(WebCore::RenderStyle::setTextSpacingTrim): Deleted.
(WebCore::RenderStyle::setTextAutospace): Deleted.
(WebCore::RenderStyle::initialTextSpacingTrim): Deleted.
(WebCore::RenderStyle::initialTextAutospace): Deleted.
* Source/WebCore/rendering/style/StyleRareInheritedData.cpp:
(WebCore::StyleRareInheritedData::StyleRareInheritedData):
(WebCore::StyleRareInheritedData::operator== const):
* Source/WebCore/rendering/style/StyleRareInheritedData.h:

Canonical link: https://commits.webkit.org/267224@main
  • Loading branch information
vitorroriz committed Aug 24, 2023
1 parent 5be7328 commit 61c1b82
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 23 deletions.
6 changes: 6 additions & 0 deletions Source/WebCore/css/CSSProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,9 @@
],
"codegen-properties": {
"settings-flag": "cssTextSpacingEnabled",
"font-property": true,
"high-priority": true,
"sink-priority": true,
"converter": "TextSpacingTrim",
"parser-function": "consumeTextSpacingTrim",
"parser-grammar-unused": "auto | space-all | trim-all | [ allow-end || space-first ]",
Expand All @@ -1223,6 +1226,9 @@
],
"codegen-properties": {
"settings-flag": "cssTextSpacingEnabled",
"font-property": true,
"high-priority": true,
"sink-priority": true,
"converter": "TextAutospace",
"parser-function": "consumeTextAutospace",
"parser-grammar-unused": "normal | auto | no-autospace | [ [ ideograph-alpha || ideograph-numeric || punctuation ] || [ insert | replace ] ]",
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/platform/graphics/FontCascade.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "FontCascadeDescription.h"
#include "FontCascadeFonts.h"
#include "Path.h"
#include "TextSpacing.h"
#include <optional>
#include <wtf/HashSet.h>
#include <wtf/WeakPtr.h>
Expand Down Expand Up @@ -151,6 +152,8 @@ class FontCascade : public CanMakeWeakPtr<FontCascade> {

float wordSpacing() const { return m_wordSpacing; }
float letterSpacing() const { return m_letterSpacing; }
TextSpacingTrim textSpacingTrim() const { return m_fontDescription.textSpacingTrim(); }
TextAutospace textAutospace() const { return m_fontDescription.textAutospace(); }
void setWordSpacing(float s) { m_wordSpacing = s; }
void setLetterSpacing(float s) { m_letterSpacing = s; }
bool isFixedPitch() const;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/graphics/FontCascadeDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct SameSizeAsFontCascadeDescription {
AtomString string2;
int16_t fontSelectionRequest[3];
float size;
TextSpacingTrim textSpacingTrim;
TextAutospace textAutospace;
unsigned bitfields1;
unsigned bitfields2 : 22;
void* array;
Expand Down
2 changes: 2 additions & 0 deletions Source/WebCore/platform/graphics/FontCascadeDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class FontCascadeDescription : public FontDescription {
static const AtomString& initialSpecifiedLocale() { return nullAtom(); }
static FontPalette initialFontPalette() { return { FontPalette::Type::Normal, nullAtom() }; }
static FontSizeAdjust initialFontSizeAdjust() { return { FontSizeAdjust::Metric::ExHeight }; }
static TextSpacingTrim initialTextSpacingTrim() { return { }; }
static TextAutospace initialTextAutospace() { return { }; }

private:
Ref<RefCountedFixedVector<AtomString>> m_families;
Expand Down
25 changes: 24 additions & 1 deletion Source/WebCore/platform/graphics/FontDescription.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "FontSizeAdjust.h"
#include "FontTaggedSettings.h"
#include "TextFlags.h"
#include "TextSpacing.h"
#include "WebKitFontFamilyNames.h"
#include <unicode/uscript.h>
#include <wtf/MathExtras.h>
Expand All @@ -51,6 +52,8 @@ class FontDescription {
FontSelectionValue weight() const { return m_fontSelectionRequest.weight; }
FontSelectionRequest fontSelectionRequest() const { return m_fontSelectionRequest; }
TextRenderingMode textRenderingMode() const { return static_cast<TextRenderingMode>(m_textRendering); }
TextSpacingTrim textSpacingTrim() const { return m_textSpacingTrim; }
TextAutospace textAutospace() const { return m_textAutospace; }
UScriptCode script() const { return static_cast<UScriptCode>(m_script); }
const AtomString& computedLocale() const { return m_locale; } // This is what you should be using for things like text shaping and font fallback
const AtomString& specifiedLocale() const { return m_specifiedLocale; } // This is what you should be using for web-exposed things like -webkit-locale
Expand Down Expand Up @@ -107,6 +110,8 @@ class FontDescription {
FontSizeAdjust fontSizeAdjust() const { return m_sizeAdjust; }

void setComputedSize(float s) { m_computedSize = clampToFloat(s); }
void setTextSpacingTrim(TextSpacingTrim v) { m_textSpacingTrim = v; }
void setTextAutospace(TextAutospace v) { m_textAutospace = v; }
void setItalic(std::optional<FontSelectionValue> italic) { m_fontSelectionRequest.slope = italic; }
void setStretch(FontSelectionValue stretch) { m_fontSelectionRequest.width = stretch; }
void setIsItalic(bool isItalic) { setItalic(isItalic ? std::optional<FontSelectionValue> { italicValue() } : std::optional<FontSelectionValue> { }); }
Expand Down Expand Up @@ -162,6 +167,8 @@ class FontDescription {
AtomString m_specifiedLocale;

FontSelectionRequest m_fontSelectionRequest;
TextSpacingTrim m_textSpacingTrim;
TextAutospace m_textAutospace;
float m_computedSize { 0 }; // Computed size adjusted for the minimum font size and the zoom factor.
unsigned m_orientation : 1; // FontOrientation - Whether the font is rendering on a horizontal line or a vertical line.
unsigned m_nonCJKGlyphOrientation : 1; // NonCJKGlyphOrientation - Only used by vertical text. Determines the default orientation for non-ideograph glyphs.
Expand Down Expand Up @@ -225,7 +232,9 @@ inline bool FontDescription::operator==(const FontDescription& other) const
&& m_shouldAllowUserInstalledFonts == other.m_shouldAllowUserInstalledFonts
&& m_shouldDisableLigaturesForSpacing == other.m_shouldDisableLigaturesForSpacing
&& m_fontPalette == other.m_fontPalette
&& m_sizeAdjust == other.m_sizeAdjust;
&& m_sizeAdjust == other.m_sizeAdjust
&& m_textSpacingTrim == other.m_textSpacingTrim
&& m_textAutospace == other.m_textAutospace;
}

template<class Encoder>
Expand Down Expand Up @@ -266,6 +275,8 @@ void FontDescription::encode(Encoder& encoder) const
encoder << shouldDisableLigaturesForSpacing();
encoder << fontPalette();
encoder << fontSizeAdjust();
encoder << textAutospace();
encoder << textSpacingTrim();
}

template<class Decoder>
Expand Down Expand Up @@ -447,6 +458,16 @@ std::optional<FontDescription> FontDescription::decode(Decoder& decoder)
if (!fontPalette)
return std::nullopt;

std::optional<TextSpacingTrim> textSpacingTrim;
decoder >> textSpacingTrim;
if (!textSpacingTrim)
return std::nullopt;

std::optional<TextAutospace> textAutospace;
decoder >> textAutospace;
if (!textAutospace)
return std::nullopt;

fontDescription.setFeatureSettings(WTFMove(*featureSettings));
fontDescription.setVariationSettings(WTFMove(*variationSettings));
fontDescription.setSpecifiedLocale(*locale);
Expand Down Expand Up @@ -482,6 +503,8 @@ std::optional<FontDescription> FontDescription::decode(Decoder& decoder)
fontDescription.setShouldDisableLigaturesForSpacing(*shouldDisableLigaturesForSpacing);
fontDescription.setFontPalette(*fontPalette);
fontDescription.setFontSizeAdjust(*sizeAdjust);
fontDescription.setTextAutospace(*textAutospace);
fontDescription.setTextSpacingTrim(*textSpacingTrim);

return fontDescription;
}
Expand Down
24 changes: 22 additions & 2 deletions Source/WebCore/rendering/style/RenderStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,12 +2061,12 @@ float RenderStyle::letterSpacing() const

TextSpacingTrim RenderStyle::textSpacingTrim() const
{
return m_rareInheritedData->textSpacingTrim;
return fontDescription().textSpacingTrim();
}

TextAutospace RenderStyle::textAutospace() const
{
return m_rareInheritedData->textAutospace;
return fontDescription().textAutospace();
}

bool RenderStyle::setFontDescription(FontCascadeDescription&& description)
Expand Down Expand Up @@ -2183,6 +2183,26 @@ void RenderStyle::setLetterSpacing(float letterSpacing)
setLetterSpacingWithoutUpdatingFontDescription(letterSpacing);
}

void RenderStyle::setTextSpacingTrim(TextSpacingTrim value)
{
auto selector = fontCascade().fontSelector();
auto description = fontDescription();
description.setTextSpacingTrim(value);

setFontDescription(WTFMove(description));
fontCascade().update(selector);
}

void RenderStyle::setTextAutospace(TextAutospace value)
{
auto selector = fontCascade().fontSelector();
auto description = fontDescription();
description.setTextAutospace(value);

setFontDescription(WTFMove(description));
fontCascade().update(selector);
}

void RenderStyle::setLetterSpacingWithoutUpdatingFontDescription(float letterSpacing)
{
m_inheritedData.access().fontCascade.setLetterSpacing(letterSpacing);
Expand Down
6 changes: 2 additions & 4 deletions Source/WebCore/rendering/style/RenderStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -1755,8 +1755,8 @@ class RenderStyle {

inline void setMathStyle(const MathStyle&);

inline void setTextSpacingTrim(TextSpacingTrim);
inline void setTextAutospace(TextAutospace);
void setTextSpacingTrim(TextSpacingTrim v);
void setTextAutospace(TextAutospace v);

static constexpr Overflow initialOverflowX();
static constexpr Overflow initialOverflowY();
Expand Down Expand Up @@ -1784,8 +1784,6 @@ class RenderStyle {
static constexpr WritingMode initialWritingMode();
static constexpr TextCombine initialTextCombine();
static constexpr TextOrientation initialTextOrientation();
static constexpr TextSpacingTrim initialTextSpacingTrim();
static constexpr TextAutospace initialTextAutospace();
static constexpr ObjectFit initialObjectFit();
static inline LengthPoint initialObjectPosition();
static constexpr EmptyCell initialEmptyCells();
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/rendering/style/RenderStyleInlines.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ constexpr TabSize RenderStyle::initialTabSize() { return 8; }
constexpr TableLayoutType RenderStyle::initialTableLayout() { return TableLayoutType::Auto; }
constexpr TextAlignMode RenderStyle::initialTextAlign() { return TextAlignMode::Start; }
constexpr TextAlignLast RenderStyle::initialTextAlignLast() { return TextAlignLast::Auto; }
constexpr TextAutospace RenderStyle::initialTextAutospace() { return { }; }
constexpr TextBoxTrim RenderStyle::initialTextBoxTrim() { return TextBoxTrim::None; }
constexpr TextCombine RenderStyle::initialTextCombine() { return TextCombine::None; }
inline StyleColor RenderStyle::initialTextDecorationColor() { return StyleColor::currentColor(); }
Expand All @@ -475,7 +474,6 @@ constexpr TextJustify RenderStyle::initialTextJustify() { return TextJustify::Au
constexpr TextOrientation RenderStyle::initialTextOrientation() { return TextOrientation::Mixed; }
constexpr TextOverflow RenderStyle::initialTextOverflow() { return TextOverflow::Clip; }
constexpr TextSecurity RenderStyle::initialTextSecurity() { return TextSecurity::None; }
constexpr TextSpacingTrim RenderStyle::initialTextSpacingTrim() { return { }; }
inline StyleColor RenderStyle::initialTextStrokeColor() { return StyleColor::currentColor(); }
constexpr OptionSet<TextTransform> RenderStyle::initialTextTransform() { return { }; }
constexpr TextUnderlineOffset RenderStyle::initialTextUnderlineOffset() { return TextUnderlineOffset::createWithAuto(); }
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/rendering/style/RenderStyleSetters.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ inline void RenderStyle::setStrokeMiterLimit(float value) { SET(m_rareInheritedD
inline void RenderStyle::setStrokeWidth(Length&& width) { SET(m_rareInheritedData, strokeWidth, WTFMove(width)); }
inline void RenderStyle::setTabSize(const TabSize& size) { SET(m_rareInheritedData, tabSize, size); }
inline void RenderStyle::setTextAlignLast(TextAlignLast value) { SET(m_rareInheritedData, textAlignLast, static_cast<unsigned>(value)); }
inline void RenderStyle::setTextAutospace(TextAutospace value) { SET(m_rareInheritedData, textAutospace, value); }
inline void RenderStyle::setTextBoxTrim(TextBoxTrim value) { SET_NESTED(m_nonInheritedData, rareData, textBoxTrim, static_cast<unsigned>(value)); }
inline void RenderStyle::setTextCombine(TextCombine value) { SET(m_rareInheritedData, textCombine, static_cast<unsigned>(value)); }
inline void RenderStyle::setTextDecorationColor(const StyleColor& color) { SET_NESTED(m_nonInheritedData, rareData, textDecorationColor, color); }
Expand All @@ -307,7 +306,6 @@ inline void RenderStyle::setTextIndentType(TextIndentType value) { SET(m_rareInh
inline void RenderStyle::setTextJustify(TextJustify value) { SET(m_rareInheritedData, textJustify, static_cast<unsigned>(value)); }
inline void RenderStyle::setTextOverflow(TextOverflow overflow) { SET_NESTED(m_nonInheritedData, miscData, textOverflow, static_cast<unsigned>(overflow)); }
inline void RenderStyle::setTextSecurity(TextSecurity security) { SET(m_rareInheritedData, textSecurity, static_cast<unsigned>(security)); }
inline void RenderStyle::setTextSpacingTrim(TextSpacingTrim value) { SET(m_rareInheritedData, textSpacingTrim, value); }
inline void RenderStyle::setTextStrokeColor(const StyleColor& c) { SET(m_rareInheritedData, textStrokeColor, c); }
inline void RenderStyle::setTextStrokeWidth(float value) { SET(m_rareInheritedData, textStrokeWidth, value); }
inline void RenderStyle::setTextTransform(OptionSet<TextTransform> value) { m_inheritedFlags.textTransform = value.toRaw(); }
Expand Down
9 changes: 0 additions & 9 deletions Source/WebCore/rendering/style/StyleRareInheritedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ struct GreaterThanOrSameSizeAsStyleRareInheritedData : public RefCounted<Greater
#if ENABLE(DARK_MODE_CSS)
StyleColorScheme colorScheme;
#endif
TextSpacingTrim textSpacingTrim;
TextAutospace textAutospace;

ListStyleType listStyleType;

Markable<ScrollbarColor> scrollbarColor;
Expand Down Expand Up @@ -156,8 +153,6 @@ StyleRareInheritedData::StyleRareInheritedData()
#if ENABLE(TOUCH_EVENTS)
, tapHighlightColor(RenderStyle::initialTapHighlightColor())
#endif
, textSpacingTrim(RenderStyle::initialTextSpacingTrim())
, textAutospace(RenderStyle::initialTextAutospace())
, listStyleType(RenderStyle::initialListStyleType())
, scrollbarColor(RenderStyle::initialScrollbarColor())
{
Expand Down Expand Up @@ -256,8 +251,6 @@ inline StyleRareInheritedData::StyleRareInheritedData(const StyleRareInheritedDa
#if ENABLE(TOUCH_EVENTS)
, tapHighlightColor(o.tapHighlightColor)
#endif
, textSpacingTrim(o.textSpacingTrim)
, textAutospace(o.textAutospace)
, listStyleType(o.listStyleType)
, scrollbarColor(o.scrollbarColor)
{
Expand Down Expand Up @@ -366,8 +359,6 @@ bool StyleRareInheritedData::operator==(const StyleRareInheritedData& o) const
&& customProperties == o.customProperties
&& arePointingToEqualData(listStyleImage, o.listStyleImage)
&& listStyleType == o.listStyleType
&& textSpacingTrim == o.textSpacingTrim
&& textAutospace == o.textAutospace
&& scrollbarColor == o.scrollbarColor;
}

Expand Down
3 changes: 0 additions & 3 deletions Source/WebCore/rendering/style/StyleRareInheritedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "StyleCustomPropertyData.h"
#include "StyleTextBoxEdge.h"
#include "TabSize.h"
#include "TextSpacing.h"
#include "TextUnderlineOffset.h"
#include "TouchAction.h"
#include <wtf/DataRef.h>
Expand Down Expand Up @@ -197,8 +196,6 @@ class StyleRareInheritedData : public RefCounted<StyleRareInheritedData> {
#if ENABLE(TOUCH_EVENTS)
StyleColor tapHighlightColor;
#endif
TextSpacingTrim textSpacingTrim;
TextAutospace textAutospace;

ListStyleType listStyleType;

Expand Down

0 comments on commit 61c1b82

Please sign in to comment.