Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ inline bool areTextAttributesEquivalentLayoutWise(const TextAttributes &lhs, con
lhs.fontVariationSettings,
lhs.allowFontScaling,
lhs.dynamicTypeRamp,
lhs.textTransform,
lhs.baseWritingDirection,
lhs.lineBreakStrategy,
lhs.lineBreakMode,
lhs.layoutDirection,
lhs.alignment) ==
std::tie(
rhs.fontFamily,
Expand All @@ -139,16 +144,20 @@ inline bool areTextAttributesEquivalentLayoutWise(const TextAttributes &lhs, con
rhs.fontVariationSettings,
rhs.allowFontScaling,
rhs.dynamicTypeRamp,
rhs.textTransform,
rhs.baseWritingDirection,
rhs.lineBreakStrategy,
rhs.lineBreakMode,
rhs.layoutDirection,
rhs.alignment) &&
floatEquality(lhs.fontSize, rhs.fontSize) && floatEquality(lhs.fontSizeMultiplier, rhs.fontSizeMultiplier) &&
floatEquality(lhs.letterSpacing, rhs.letterSpacing) && floatEquality(lhs.lineHeight, rhs.lineHeight) &&
floatEquality(lhs.maxFontSizeMultiplier, rhs.maxFontSizeMultiplier);
floatEquality(lhs.maxFontSizeMultiplier, rhs.maxFontSizeMultiplier) && lhs.textEffects == rhs.textEffects;
}

inline size_t textAttributesHashLayoutWise(const TextAttributes &textAttributes)
{
// Taking into account the same props as
// `areTextAttributesEquivalentLayoutWise` mentions.
// Hash a subset of the attributes compared by `areTextAttributesEquivalentLayoutWise`.
// The optionals are folded into one presence mask rather than being chained individually, so
// that the properties a given text run does not set stay off the hash's dependency chain. This
// is the hot path: it runs on every measurement-cache probe.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TEST(TextLayoutManagerTest, emptyFontVariationSettingsClearInheritedSettings) {
EXPECT_TRUE(parent.fontVariationSettings->empty());
}

TEST(TextLayoutManagerTest, everyLayoutAttributeAffectsEqualityAndHash) {
TEST(TextLayoutManagerTest, hashedLayoutAttributesAffectCacheKeys) {
TextAttributes baseline;
baseline.fontFamily = "Inter";
baseline.fontSize = 16;
Expand Down Expand Up @@ -175,6 +175,63 @@ TEST(TextLayoutManagerTest, everyLayoutAttributeAffectsEqualityAndHash) {
}
}

TEST(TextLayoutManagerTest, additionalLayoutAttributesAffectCacheKeyEquality) {
AttributedString baseline;
baseline.appendFragment({.string = "Text"});

struct TestCase {
const char* name;
void (*mutate)(TextAttributes&);
};
const std::array<TestCase, 6> testCases{{
{.name = "textTransform",
.mutate =
[](TextAttributes& attributes) {
attributes.textTransform = TextTransform::Uppercase;
}},
{.name = "baseWritingDirection",
.mutate =
[](TextAttributes& attributes) {
attributes.baseWritingDirection = WritingDirection::RightToLeft;
}},
{.name = "lineBreakStrategy",
.mutate =
[](TextAttributes& attributes) {
attributes.lineBreakStrategy =
LineBreakStrategy::HangulWordPriority;
}},
{.name = "lineBreakMode",
.mutate =
[](TextAttributes& attributes) {
attributes.lineBreakMode = LineBreakMode::Char;
}},
{.name = "layoutDirection",
.mutate =
[](TextAttributes& attributes) {
attributes.layoutDirection = LayoutDirection::RightToLeft;
}},
{.name = "textEffects",
.mutate =
[](TextAttributes& attributes) {
attributes.textEffects.push_back(
{.name = "scale", .props = nullptr});
}},
}};

for (const auto& testCase : testCases) {
SCOPED_TRACE(testCase.name);
auto changed = baseline;
testCase.mutate(changed.getFragments().front().textAttributes);

EXPECT_FALSE(
TextMeasureCacheKey{.attributedString = baseline} ==
TextMeasureCacheKey{.attributedString = changed});
EXPECT_FALSE(
LineMeasureCacheKey{.attributedString = baseline} ==
LineMeasureCacheKey{.attributedString = changed});
}
}

TEST(TextLayoutManagerTest, equivalentPopulatedLayoutAttributesHashEqually) {
TextAttributes lhs;
lhs.fontFamily = "Inter";
Expand Down
Loading