14
14
15
15
#include < unicode.h>
16
16
17
+ constexpr float cDefaultMaxFontSizeMultiplier = 0 .0f ;
18
+
17
19
namespace facebook ::react {
18
20
19
21
// Creates an empty InlineObject since RN handles actually rendering the Inline object, this just reserves space for it.
@@ -81,6 +83,20 @@ void TextLayoutManager::GetTextLayout(
81
83
style = DWRITE_FONT_STYLE_OBLIQUE;
82
84
83
85
winrt::com_ptr<IDWriteTextFormat> spTextFormat;
86
+
87
+ float fontSizeText = outerFragment.textAttributes .fontSize ;
88
+ if (outerFragment.textAttributes .allowFontScaling .value_or (true ) &&
89
+ !std::isnan (outerFragment.textAttributes .fontSizeMultiplier )) {
90
+ float maxFontSizeMultiplierText = cDefaultMaxFontSizeMultiplier;
91
+ maxFontSizeMultiplierText =
92
+ (!std::isnan (outerFragment.textAttributes .maxFontSizeMultiplier )
93
+ ? outerFragment.textAttributes .maxFontSizeMultiplier
94
+ : cDefaultMaxFontSizeMultiplier);
95
+ fontSizeText *= (maxFontSizeMultiplierText >= 1 .0f )
96
+ ? std::min (maxFontSizeMultiplierText, outerFragment.textAttributes .fontSizeMultiplier )
97
+ : outerFragment.textAttributes .fontSizeMultiplier ;
98
+ }
99
+
84
100
winrt::check_hresult (Microsoft::ReactNative::DWriteFactory ()->CreateTextFormat (
85
101
outerFragment.textAttributes .fontFamily .empty ()
86
102
? L" Segoe UI"
@@ -90,10 +106,7 @@ void TextLayoutManager::GetTextLayout(
90
106
static_cast <facebook::react::FontWeight>(DWRITE_FONT_WEIGHT_REGULAR))),
91
107
style,
92
108
DWRITE_FONT_STRETCH_NORMAL,
93
- (outerFragment.textAttributes .allowFontScaling .value_or (true ) &&
94
- !std::isnan (outerFragment.textAttributes .fontSizeMultiplier ))
95
- ? (outerFragment.textAttributes .fontSizeMultiplier * outerFragment.textAttributes .fontSize )
96
- : outerFragment.textAttributes .fontSize ,
109
+ fontSizeText,
97
110
L" " ,
98
111
spTextFormat.put ()));
99
112
@@ -206,11 +219,18 @@ void TextLayoutManager::GetTextLayout(
206
219
attributes.fontWeight .value_or (static_cast <facebook::react::FontWeight>(DWRITE_FONT_WEIGHT_REGULAR))),
207
220
range));
208
221
winrt::check_hresult (spTextLayout->SetFontStyle (fragmentStyle, range));
209
- winrt::check_hresult (spTextLayout->SetFontSize (
210
- (attributes.allowFontScaling .value_or (true ) && !std::isnan (attributes.fontSizeMultiplier ))
211
- ? (attributes.fontSizeMultiplier * attributes.fontSize )
212
- : attributes.fontSize ,
213
- range));
222
+
223
+ float maxFontSizeMultiplier = cDefaultMaxFontSizeMultiplier;
224
+ maxFontSizeMultiplier =
225
+ (!std::isnan (attributes.maxFontSizeMultiplier ) ? attributes.maxFontSizeMultiplier
226
+ : cDefaultMaxFontSizeMultiplier);
227
+ float fontSize = attributes.fontSize ;
228
+ if (attributes.allowFontScaling .value_or (true ) && (!std::isnan (attributes.fontSizeMultiplier ))) {
229
+ fontSize *= (maxFontSizeMultiplier >= 1 .0f ) ? std::min (maxFontSizeMultiplier, attributes.fontSizeMultiplier )
230
+ : attributes.fontSizeMultiplier ;
231
+ }
232
+
233
+ winrt::check_hresult (spTextLayout->SetFontSize (fontSize, range));
214
234
215
235
if (!isnan (attributes.letterSpacing )) {
216
236
winrt::check_hresult (
0 commit comments