@@ -123,48 +123,40 @@ - (void)uiManagerWillPerformMounting
123
123
124
124
- (void )postprocessAttributedText : (NSMutableAttributedString *)attributedText
125
125
{
126
- __block CGFloat maximumLineHeight = 0 ;
127
-
128
- [attributedText enumerateAttribute: NSParagraphStyleAttributeName
129
- inRange: NSMakeRange (0 , attributedText.length)
130
- options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
131
- usingBlock: ^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
132
- if (!paragraphStyle) {
133
- return ;
134
- }
135
-
136
- maximumLineHeight = MAX (paragraphStyle.maximumLineHeight , maximumLineHeight);
137
- }];
138
-
139
- if (maximumLineHeight == 0 ) {
140
- // `lineHeight` was not specified, nothing to do.
141
- return ;
142
- }
143
-
144
- __block CGFloat maximumFontLineHeight = 0 ;
145
-
146
- [attributedText enumerateAttribute: NSFontAttributeName
147
- inRange: NSMakeRange (0 , attributedText.length)
148
- options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
149
- usingBlock: ^(UIFont *font, NSRange range, __unused BOOL *stop) {
150
- if (!font) {
151
- return ;
152
- }
153
-
154
- if (maximumFontLineHeight <= font.lineHeight ) {
155
- maximumFontLineHeight = font.lineHeight ;
156
- }
157
- }];
158
-
159
- if (maximumLineHeight < maximumFontLineHeight) {
160
- return ;
161
- }
162
-
163
- CGFloat baseLineOffset = maximumLineHeight / 2.0 - maximumFontLineHeight / 2.0 ;
164
-
165
- [attributedText addAttribute: NSBaselineOffsetAttributeName
166
- value: @(baseLineOffset)
167
- range: NSMakeRange (0 , attributedText.length)];
126
+ // Retrieve paragraph line height value
127
+ __block CGFloat paragraphLineHeight = 0 ;
128
+ [attributedText enumerateAttribute: NSParagraphStyleAttributeName
129
+ inRange: NSMakeRange (0 , attributedText.length)
130
+ options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
131
+ usingBlock: ^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
132
+ if (!paragraphStyle) {
133
+ return ;
134
+ }
135
+
136
+ paragraphLineHeight = paragraphStyle.maximumLineHeight ;
137
+ }];
138
+
139
+ // Retrieve font size and font line height values
140
+ __block CGFloat fontSize = 0 ;
141
+ __block CGFloat fontLineHeight = 0 ;
142
+ [attributedText enumerateAttribute: NSFontAttributeName
143
+ inRange: NSMakeRange (0 , attributedText.length)
144
+ options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
145
+ usingBlock: ^(UIFont *font, NSRange range, __unused BOOL *stop) {
146
+ if (!font) {
147
+ return ;
148
+ }
149
+
150
+ fontSize = font.pointSize ;
151
+ fontLineHeight = font.lineHeight ;
152
+ }];
153
+
154
+ // Calculate baseline offset based on font size and maximum available line height value
155
+ CGFloat maximumLineHeight = MAX (paragraphLineHeight, fontLineHeight);
156
+ CGFloat baselineOffset = (fontSize - maximumLineHeight) / 1.5 ;
157
+ [attributedText addAttribute: NSBaselineOffsetAttributeName
158
+ value: @(baselineOffset)
159
+ range: NSMakeRange (0 , attributedText.length)];
168
160
}
169
161
170
162
- (NSAttributedString *)attributedTextWithMeasuredAttachmentsThatFitSize : (CGSize)size
0 commit comments