@@ -66,6 +66,10 @@ class TextMeasureCacheKey final {
6666 AttributedString attributedString{};
6767 ParagraphAttributes paragraphAttributes{};
6868 LayoutConstraints layoutConstraints{};
69+ // The measured size depends on the pixel scale factor because layout metrics
70+ // are rounded to the pixel grid. Two otherwise-identical measures at different
71+ // densities are not interchangeable, so the scale factor is part of the key.
72+ Float pointScaleFactor{};
6973};
7074
7175// The Key type that is used for Line Measure Cache.
@@ -87,6 +91,9 @@ class PreparedTextCacheKey final {
8791 AttributedString attributedString{};
8892 ParagraphAttributes paragraphAttributes{};
8993 LayoutConstraints layoutConstraints{};
94+ // A prepared layout is rounded to the pixel grid, so it is only reusable at
95+ // the pixel scale factor it was laid out at.
96+ Float pointScaleFactor{};
9097};
9198
9299/*
@@ -252,7 +259,8 @@ inline size_t attributedStringHashDisplayWise(const AttributedString &attributed
252259inline bool operator ==(const TextMeasureCacheKey &lhs, const TextMeasureCacheKey &rhs)
253260{
254261 return areAttributedStringsEquivalentLayoutWise (lhs.attributedString , rhs.attributedString ) &&
255- lhs.paragraphAttributes == rhs.paragraphAttributes && lhs.layoutConstraints == rhs.layoutConstraints ;
262+ lhs.paragraphAttributes == rhs.paragraphAttributes && lhs.layoutConstraints == rhs.layoutConstraints &&
263+ floatEquality (lhs.pointScaleFactor , rhs.pointScaleFactor );
256264}
257265
258266inline bool operator ==(const LineMeasureCacheKey &lhs, const LineMeasureCacheKey &rhs)
@@ -264,7 +272,8 @@ inline bool operator==(const LineMeasureCacheKey &lhs, const LineMeasureCacheKey
264272inline bool operator ==(const PreparedTextCacheKey &lhs, const PreparedTextCacheKey &rhs)
265273{
266274 return areAttributedStringsEquivalentDisplayWise (lhs.attributedString , rhs.attributedString ) &&
267- lhs.paragraphAttributes == rhs.paragraphAttributes && lhs.layoutConstraints == rhs.layoutConstraints ;
275+ lhs.paragraphAttributes == rhs.paragraphAttributes && lhs.layoutConstraints == rhs.layoutConstraints &&
276+ floatEquality (lhs.pointScaleFactor , rhs.pointScaleFactor );
268277}
269278
270279} // namespace facebook::react
@@ -276,7 +285,10 @@ struct hash<facebook::react::TextMeasureCacheKey> {
276285 size_t operator ()(const facebook::react::TextMeasureCacheKey &key) const
277286 {
278287 return facebook::react::hash_combine (
279- attributedStringHashLayoutWise (key.attributedString ), key.paragraphAttributes , key.layoutConstraints );
288+ attributedStringHashLayoutWise (key.attributedString ),
289+ key.paragraphAttributes ,
290+ key.layoutConstraints ,
291+ key.pointScaleFactor );
280292 }
281293};
282294
@@ -294,7 +306,10 @@ struct hash<facebook::react::PreparedTextCacheKey> {
294306 size_t operator ()(const facebook::react::PreparedTextCacheKey &key) const
295307 {
296308 return facebook::react::hash_combine (
297- attributedStringHashDisplayWise (key.attributedString ), key.paragraphAttributes , key.layoutConstraints );
309+ attributedStringHashDisplayWise (key.attributedString ),
310+ key.paragraphAttributes ,
311+ key.layoutConstraints ,
312+ key.pointScaleFactor );
298313 }
299314};
300315
0 commit comments