Skip to content

Commit 7e02fc7

Browse files
conner1reimersmeta-codesync[bot]
authored andcommitted
Remove the unused maximumFontSize paragraph attribute (#58529)
Summary: Fabric's `ParagraphAttributes` carries a `maximumFontSize` field, but it is not exposed by the `<Text>` or `<TextInput>` APIs, so normal JS usage leaves it as `NaN`. On iOS, `RCTTextLayoutManager` falls back to a 96pt maximum when it is `NaN`. On Android, the C++ side serializes it into MapBuffer key 7, but `TextLayoutManager` never reads that key. This PR removes the attribute: the `ParagraphAttributes` field, its raw-prop parsing in `conversions.h`, the paragraph and text input prop entries, and MapBuffer key 7 on both the C++ and Kotlin sides. - **iOS**: `RCTTextLayoutManager` now passes the largest font size in the attributed string to `scaleFontSizeToFitSize:` as the maximum instead of 96pt. `scaleFontSizeToFitSize:` returns early when the text already fits; otherwise `scaleFontSizeWithRatio:` applies `MIN(pointSize * ratio, maximumFontSize)` on each pass of a bisection over the ratio. With 96pt, fonts above 96pt were clamped to 96pt on every pass, and when that clamp alone made the text fit, the search went on to ratios above 1.0 and grew the remaining fonts up to 96pt. With the largest font size as the maximum the clamp is a no-op, the ratio-1.0 pass reproduces the original text, which is known not to fit, and every later pass shrinks. Fonts above 96pt are now scaled proportionally rather than capped, and text is never grown. Text at 96pt or smaller is unaffected. - **Android**: `PA_KEY_MAXIMUM_FONT_SIZE` is removed. Nothing reads it, so there is no behavior change. Split out of #58492. #58492 builds on this and reuses the largest-font-size helper for `minimumFontScale`. ## Changelog: [GENERAL] [REMOVED] - Remove the unused `maximumFontSize` paragraph attribute Pull Request resolved: #58529 Test Plan: **Unit tests** - Updated `ParagraphAttributesTest.cpp` for the removed field. - Regenerated the C++ API snapshots (`yarn cxx-api-build`). ```sh ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.text.*' ``` All 38 `com.facebook.react.views.text` tests pass. Reviewed By: cipolleschi Differential Revision: D120127100 Pulled By: javache fbshipit-source-id: 44e7de2c21c95500e721d5c6f4b4e207da369713
1 parent b9adf95 commit 7e02fc7

19 files changed

Lines changed: 21 additions & 60 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextLayoutManager.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ internal object TextLayoutManager {
9494
const val PA_KEY_INCLUDE_FONT_PADDING: Int = 4
9595
const val PA_KEY_HYPHENATION_FREQUENCY: Int = 5
9696
const val PA_KEY_MINIMUM_FONT_SIZE: Int = 6
97-
const val PA_KEY_MAXIMUM_FONT_SIZE: Int = 7
9897
const val PA_KEY_TEXT_ALIGN_VERTICAL: Int = 8
9998
const val PA_KEY_TEXT_WIDTH_MODE: Int = 9
10099

packages/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ bool ParagraphAttributes::operator==(const ParagraphAttributes& rhs) const {
3434
rhs.android_hyphenationFrequency,
3535
rhs.textAlignVertical) &&
3636
floatEquality(minimumFontSize, rhs.minimumFontSize) &&
37-
floatEquality(maximumFontSize, rhs.maximumFontSize) &&
3837
floatEquality(minimumFontScale, rhs.minimumFontScale);
3938
}
4039

@@ -64,10 +63,6 @@ SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const {
6463
"minimumFontSize",
6564
minimumFontSize,
6665
paragraphAttributes.minimumFontSize),
67-
debugStringConvertibleItem(
68-
"maximumFontSize",
69-
maximumFontSize,
70-
paragraphAttributes.maximumFontSize),
7166
debugStringConvertibleItem(
7267
"includeFontPadding",
7368
includeFontPadding,

packages/react-native/ReactCommon/react/renderer/attributedstring/ParagraphAttributes.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,9 @@ class ParagraphAttributes : public DebugStringConvertible {
6868
HyphenationFrequency android_hyphenationFrequency{};
6969

7070
/*
71-
* In case of font size adjustment enabled, defines minimum and maximum
72-
* font sizes.
71+
* In case of font size adjustment enabled, defines the minimum font size.
7372
*/
7473
Float minimumFontSize{std::numeric_limits<Float>::quiet_NaN()};
75-
Float maximumFontSize{std::numeric_limits<Float>::quiet_NaN()};
7674

7775
/*
7876
* Specifies the smallest possible scale a font can reach when
@@ -110,7 +108,6 @@ struct hash<facebook::react::ParagraphAttributes> {
110108
attributes.textWidthMode,
111109
attributes.adjustsFontSizeToFit,
112110
attributes.minimumFontSize,
113-
attributes.maximumFontSize,
114111
attributes.includeFontPadding,
115112
attributes.android_hyphenationFrequency,
116113
attributes.minimumFontScale,

packages/react-native/ReactCommon/react/renderer/attributedstring/conversions.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,12 +1091,6 @@ inline ParagraphAttributes convertRawProp(
10911091
"minimumFontSize",
10921092
sourceParagraphAttributes.minimumFontSize,
10931093
defaultParagraphAttributes.minimumFontSize);
1094-
paragraphAttributes.maximumFontSize = convertRawProp(
1095-
context,
1096-
rawProps,
1097-
"maximumFontSize",
1098-
sourceParagraphAttributes.maximumFontSize,
1099-
defaultParagraphAttributes.maximumFontSize);
11001094
paragraphAttributes.includeFontPadding = convertRawProp(
11011095
context,
11021096
rawProps,
@@ -1200,7 +1194,6 @@ constexpr static MapBuffer::Key PA_KEY_ADJUST_FONT_SIZE_TO_FIT = 3;
12001194
constexpr static MapBuffer::Key PA_KEY_INCLUDE_FONT_PADDING = 4;
12011195
constexpr static MapBuffer::Key PA_KEY_HYPHENATION_FREQUENCY = 5;
12021196
constexpr static MapBuffer::Key PA_KEY_MINIMUM_FONT_SIZE = 6;
1203-
constexpr static MapBuffer::Key PA_KEY_MAXIMUM_FONT_SIZE = 7;
12041197
constexpr static MapBuffer::Key PA_KEY_TEXT_ALIGN_VERTICAL = 8;
12051198
constexpr static MapBuffer::Key PA_KEY_TEXT_WIDTH_MODE = 9;
12061199

@@ -1218,7 +1211,6 @@ inline MapBuffer toMapBuffer(const ParagraphAttributes &paragraphAttributes)
12181211
builder.putString(PA_KEY_TEXT_ALIGN_VERTICAL, toString(*paragraphAttributes.textAlignVertical));
12191212
}
12201213
builder.putDouble(PA_KEY_MINIMUM_FONT_SIZE, paragraphAttributes.minimumFontSize);
1221-
builder.putDouble(PA_KEY_MAXIMUM_FONT_SIZE, paragraphAttributes.maximumFontSize);
12221214

12231215
return builder.build();
12241216
}

packages/react-native/ReactCommon/react/renderer/attributedstring/tests/ParagraphAttributesTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace facebook::react {
1313

14-
// The three Float fields default to NaN, and NaN != NaN under IEEE-754.
14+
// The two Float fields default to NaN, and NaN != NaN under IEEE-754.
1515
// operator== must special-case NaN via floatEquality so two freshly
1616
// default-constructed ParagraphAttributes compare equal.
1717
TEST(
@@ -31,12 +31,10 @@ TEST(
3131
testOperatorEqualsFloatFieldsUseEpsilonComparison) {
3232
ParagraphAttributes a{};
3333
a.minimumFontSize = 12.0f;
34-
a.maximumFontSize = 48.0f;
3534
a.minimumFontScale = 0.5f;
3635
auto b = a;
3736

3837
b.minimumFontSize = a.minimumFontSize + 0.001f;
39-
b.maximumFontSize = a.maximumFontSize + 0.001f;
4038
b.minimumFontScale = a.minimumFontScale + 0.001f;
4139
EXPECT_TRUE(a == b);
4240

@@ -46,8 +44,8 @@ TEST(
4644
}
4745

4846
// floatEquality returns true only when *both* operands are NaN or when
49-
// *neither* is. A NaN-vs-finite mismatch in any of the three float fields
50-
// must therefore make the instances unequal, even though both operands are
47+
// *neither* is. A NaN-vs-finite mismatch in either float field must
48+
// therefore make the instances unequal, even though both operands are
5149
// "invalid" font sizes.
5250
TEST(
5351
ParagraphAttributesTest,

packages/react-native/ReactCommon/react/renderer/components/text/BaseParagraphProps.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,6 @@ void BaseParagraphProps::setProp(
104104
paragraphAttributes,
105105
minimumFontSize,
106106
"minimumFontSize");
107-
REBUILD_FIELD_SWITCH_CASE(
108-
paDefaults,
109-
value,
110-
paragraphAttributes,
111-
maximumFontSize,
112-
"maximumFontSize");
113107
REBUILD_FIELD_SWITCH_CASE(
114108
paDefaults,
115109
value,

packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/HostPlatformParagraphProps.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ folly::dynamic HostPlatformParagraphProps::getDiffProps(
128128
result["minimumFontSize"] = paragraphAttributes.minimumFontSize;
129129
}
130130

131-
if (!floatEquality(
132-
paragraphAttributes.maximumFontSize,
133-
oldProps->paragraphAttributes.maximumFontSize)) {
134-
result["maximumFontSize"] = paragraphAttributes.maximumFontSize;
135-
}
136-
137131
if (paragraphAttributes.includeFontPadding !=
138132
oldProps->paragraphAttributes.includeFontPadding) {
139133
result["includeFontPadding"] = paragraphAttributes.includeFontPadding;

packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputProps.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,6 @@ void BaseTextInputProps::setProp(
179179
paragraphAttributes,
180180
minimumFontSize,
181181
"minimumFontSize");
182-
REBUILD_FIELD_SWITCH_CASE(
183-
paDefaults,
184-
value,
185-
paragraphAttributes,
186-
maximumFontSize,
187-
"maximumFontSize");
188182
REBUILD_FIELD_SWITCH_CASE(
189183
paDefaults,
190184
value,

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,6 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
395395
result["minimumFontSize"] = paragraphAttributes.minimumFontSize;
396396
}
397397

398-
if (!floatEquality(
399-
paragraphAttributes.maximumFontSize,
400-
oldProps->paragraphAttributes.maximumFontSize)) {
401-
result["maximumFontSize"] = paragraphAttributes.maximumFontSize;
402-
}
403-
404398
if (paragraphAttributes.includeFontPadding !=
405399
oldProps->paragraphAttributes.includeFontPadding) {
406400
result["includeFontPadding"] = paragraphAttributes.includeFontPadding;

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,22 @@ - (LinesMeasurements)getLinesForAttributedString:(facebook::react::AttributedStr
415415
return paragraphLines;
416416
}
417417

418+
- (CGFloat)_maximumFontSizeInAttributedString:(NSAttributedString *)attributedString
419+
{
420+
__block CGFloat maximumFontSize = 0.0;
421+
[attributedString enumerateAttribute:NSFontAttributeName
422+
inRange:NSMakeRange(0, attributedString.length)
423+
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
424+
usingBlock:^(id _Nullable value, NSRange range, BOOL *_Nonnull stop) {
425+
CGFloat fontSize = ((UIFont *)value).pointSize;
426+
if (fontSize > maximumFontSize) {
427+
maximumFontSize = fontSize;
428+
}
429+
}];
430+
431+
return maximumFontSize;
432+
}
433+
418434
- (NSTextStorage *)_textStorageAndLayoutManagerWithAttributesString:(NSAttributedString *)attributedString
419435
paragraphAttributes:(ParagraphAttributes)paragraphAttributes
420436
size:(CGSize)size
@@ -439,7 +455,7 @@ - (NSTextStorage *)_textStorageAndLayoutManagerWithAttributesString:(NSAttribute
439455

440456
if (paragraphAttributes.adjustsFontSizeToFit) {
441457
CGFloat minimumFontSize = !isnan(paragraphAttributes.minimumFontSize) ? paragraphAttributes.minimumFontSize : 4.0;
442-
CGFloat maximumFontSize = !isnan(paragraphAttributes.maximumFontSize) ? paragraphAttributes.maximumFontSize : 96.0;
458+
CGFloat maximumFontSize = [self _maximumFontSizeInAttributedString:attributedString];
443459
[textStorage scaleFontSizeToFitSize:size minimumFontSize:minimumFontSize maximumFontSize:maximumFontSize];
444460
}
445461

0 commit comments

Comments
 (0)