From ccc306c1381cf8d32122b047dc8a71f7def3e138 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Fri, 1 Dec 2023 21:26:52 +0000 Subject: [PATCH 1/3] test: Set previousFontMetrics to null + logging --- .../org/wordpress/aztec/spans/AztecHeadingSpan.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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..a0748a6e2 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt @@ -7,6 +7,7 @@ import android.text.TextPaint import android.text.style.LineHeightSpan import android.text.style.MetricAffectingSpan import android.text.style.UpdateLayout +import android.util.Log import org.wordpress.aztec.AlignmentRendering import org.wordpress.aztec.AztecAttributes import org.wordpress.aztec.AztecTextFormat @@ -124,8 +125,10 @@ open class AztecHeadingSpan( val spanStart = spanned.getSpanStart(this) val spanEnd = spanned.getSpanEnd(this) + Log.d("TESTING 101", "chooseHeight is called") // save original font metrics if (previousFontMetrics == null) { + Log.d("TESTING 101", "chooseHeight is called, inside previousFontMetrics null check") previousFontMetrics = Paint.FontMetricsInt() previousFontMetrics!!.top = fm.top previousFontMetrics!!.ascent = fm.ascent @@ -153,11 +156,13 @@ open class AztecHeadingSpan( if (!addedTopPadding) { fm.ascent = previousFontMetrics!!.ascent fm.top = previousFontMetrics!!.top + Log.d("TESTING 101", "chooseHeight is called, addedTopPadding") } if (!addedBottomPadding) { fm.descent = previousFontMetrics!!.descent fm.bottom = previousFontMetrics!!.bottom + Log.d("TESTING 101", "chooseHeight is called, addedBottomPadding") } } @@ -184,9 +189,12 @@ open class AztecHeadingSpan( override fun updateMeasureState(paint: TextPaint) { val headingSize = getHeadingSize() // when font size changes - reset cached font metrics to reapply vertical padding - if (headingSize != previousHeadingSize || previousSpacing != paint.fontSpacing) { + /* if (headingSize != previousHeadingSize || previousSpacing != paint.fontSpacing) { previousFontMetrics = null } + */ + previousFontMetrics = null + Log.d("TESTING 101", "updateMeasureState is called and previousFontMetrics set to null") previousHeadingSize = headingSize previousSpacing = paint.fontSpacing when (headingSize) { From 1dca6318a7769892c7e440ccdb0767057ff6b110 Mon Sep 17 00:00:00 2001 From: Siobhan Date: Fri, 1 Dec 2023 23:06:46 +0000 Subject: [PATCH 2/3] test: Set previousFontMetrics to null --- .../main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt | 2 ++ 1 file changed, 2 insertions(+) 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 a0748a6e2..a19ad2a26 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt @@ -136,6 +136,8 @@ open class AztecHeadingSpan( previousFontMetrics!!.descent = fm.descent } + previousFontMetrics = null + var addedTopPadding = false var addedBottomPadding = false From e05c8afb0960a2419c3a5fd13204ea4c35d0101f Mon Sep 17 00:00:00 2001 From: Siobhan Date: Fri, 1 Dec 2023 23:35:18 +0000 Subject: [PATCH 3/3] test: Add null check for previousFontMetrics --- .../wordpress/aztec/spans/AztecHeadingSpan.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 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 a19ad2a26..686d5b9e6 100644 --- a/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt +++ b/aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHeadingSpan.kt @@ -156,15 +156,27 @@ 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 - Log.d("TESTING 101", "chooseHeight is called, addedTopPadding") + previousFontMetrics?.let { + fm.ascent = it.ascent + fm.top = it.top + } ?: run { + // Handle the case where previousFontMetrics is null + Log.e("TESTING 101", "previousFontMetrics is null when processing top padding") + // Optionally, initialize previousFontMetrics here or take other corrective action + return + } } if (!addedBottomPadding) { - fm.descent = previousFontMetrics!!.descent - fm.bottom = previousFontMetrics!!.bottom - Log.d("TESTING 101", "chooseHeight is called, addedBottomPadding") + previousFontMetrics?.let { + fm.descent = it.descent + fm.bottom = it.bottom + } ?: run { + // Handle the case where previousFontMetrics is null + Log.e("TESTING 101", "previousFontMetrics is null when processing bottom padding") + // Optionally, initialize previousFontMetrics here or take other corrective action + return + } } }