From 6dd6bc5768a6e8eb60945171a1ee65346bf921b4 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Mon, 4 Dec 2023 13:40:13 +0000 Subject: [PATCH] refactor: Guard previousFontMetrics against null --- .../wordpress/aztec/spans/AztecHeadingSpan.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt index b8e4e2a67..fa28f9a6b 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt @@ -127,10 +127,10 @@ open class AztecHeadingSpan( // save original font metrics if (previousFontMetrics == null) { previousFontMetrics = Paint.FontMetricsInt() - previousFontMetrics!!.top = fm.top - previousFontMetrics!!.ascent = fm.ascent - previousFontMetrics!!.bottom = fm.bottom - previousFontMetrics!!.descent = fm.descent + previousFontMetrics?.top = fm.top + previousFontMetrics?.ascent = fm.ascent + previousFontMetrics?.bottom = fm.bottom + previousFontMetrics?.descent = fm.descent } var addedTopPadding = false @@ -151,13 +151,17 @@ open class AztecHeadingSpan( // apply original font metrics to lines that should not have vertical padding if (!addedTopPadding) { - fm.ascent = previousFontMetrics!!.ascent - fm.top = previousFontMetrics!!.top + previousFontMetrics?.let { + fm.ascent = it.ascent + fm.top = it.top + } } if (!addedBottomPadding) { - fm.descent = previousFontMetrics!!.descent - fm.bottom = previousFontMetrics!!.bottom + previousFontMetrics?.let { + fm.descent = it.descent + fm.bottom = it.bottom + } } }