@@ -4,6 +4,8 @@ import android.content.Context
44import android.graphics.Typeface
55import android.graphics.text.LineBreaker
66import android.os.Build
7+ import android.text.Spannable
8+ import android.text.SpannableString
79import android.text.StaticLayout
810import android.text.TextPaint
911import android.text.TextUtils
@@ -21,6 +23,7 @@ import com.swmansion.enriched.common.GumboNormalizer
2123import com.swmansion.enriched.common.allowFontScalingFromProps
2224import com.swmansion.enriched.common.parser.EnrichedParser
2325import com.swmansion.enriched.common.pixelFromSpOrDp
26+ import com.swmansion.enriched.textinput.spans.EnrichedLineHeightSpan
2427import kotlin.math.ceil
2528
2629object MeasurementStore {
@@ -134,6 +137,13 @@ object MeasurementStore {
134137 return props.getBoolean(" useHtmlNormalizer" )
135138 }
136139
140+ private fun lineHeightFromProps (props : ReadableMap ? ): Float {
141+ if (props == null || ! props.hasKey(" lineHeight" ) || props.isNull(" lineHeight" )) {
142+ return 0f
143+ }
144+ return props.getDouble(" lineHeight" ).toFloat()
145+ }
146+
137147 private fun getInitialFontSize (props : ReadableMap ? ): Float {
138148 val propsFontSize = props?.getDouble(" fontSize" )?.toFloat() ? : EnrichedConstants .TEXT_DEFAULT_FONT_SIZE
139149 val fontSize =
@@ -151,15 +161,31 @@ object MeasurementStore {
151161 props : ReadableMap ? ,
152162 ): Long {
153163 val fontSize = getInitialFontSize(props)
154- val text = getInitialText(context, fontSize.toInt(), props)
164+ val rawText = getInitialText(context, fontSize.toInt(), props)
165+ val lineHeight = lineHeightFromProps(props)
166+ val allowFontScaling = allowFontScalingFromProps(props)
167+
168+ val measuredText: CharSequence =
169+ if (lineHeight > 0f ) {
170+ val spannable = SpannableString (rawText)
171+ spannable.setSpan(
172+ EnrichedLineHeightSpan (lineHeight, allowFontScaling),
173+ 0 ,
174+ spannable.length,
175+ Spannable .SPAN_INCLUSIVE_INCLUSIVE ,
176+ )
177+ spannable
178+ } else {
179+ rawText
180+ }
155181
156182 val fontFamily = props?.getString(" fontFamily" )
157183 val numberOfLines = props?.getInt(" numberOfLines" ) ? : 0
158184 val ellipsizeMode = props?.getString(" ellipsizeMode" )
159185 val fontStyle = parseFontStyle(props?.getString(" fontStyle" ))
160186 val fontWeight = parseFontWeight(props?.getString(" fontWeight" ))
161187 val typeface = applyStyles(null , fontStyle, fontWeight, fontFamily, context.assets)
162- val size = measure(width, text , typeface, fontSize, numberOfLines, ellipsizeMode)
188+ val size = measure(width, measuredText , typeface, fontSize, numberOfLines, ellipsizeMode)
163189
164190 return size
165191 }
0 commit comments