File tree Expand file tree Collapse file tree
android/src/main/java/com/nitrotext Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com.nitrotext
2+
3+ import android.graphics.Paint
4+ import android.text.style.LineHeightSpan
5+ import kotlin.math.ceil
6+ import kotlin.math.floor
7+
8+ /* *
9+ * Matches React Native's CustomLineHeightSpan so lineHeight behaves the same as <Text>.
10+ */
11+ class NitroLineHeightSpan (heightPx : Float ) : LineHeightSpan {
12+ private val lineHeight: Int = ceil(heightPx.toDouble()).toInt()
13+
14+ override fun chooseHeight (
15+ text : CharSequence ,
16+ start : Int ,
17+ end : Int ,
18+ spanstartv : Int ,
19+ v : Int ,
20+ fm : Paint .FontMetricsInt
21+ ) {
22+ val leading = lineHeight - ((- fm.ascent) + fm.descent)
23+ val halfLeading = leading / 2f
24+ fm.ascent - = ceil(halfLeading.toDouble()).toInt()
25+ fm.descent + = floor(halfLeading.toDouble()).toInt()
26+ if (start == 0 ) fm.top = fm.ascent
27+ if (end == text.length) fm.bottom = fm.descent
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments