Skip to content

Commit

Permalink
Merge pull request #1071 from wordpress-mobile/refactor/guard-previou…
Browse files Browse the repository at this point in the history
…sfontmetrics-against-null

Address `NullPointerException` crash in `AztecHeadingSpan`
  • Loading branch information
Siobhan Bamber authored Dec 4, 2023
2 parents d93ce9f + 6dd6bc5 commit 79eddba
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}

Expand Down

0 comments on commit 79eddba

Please sign in to comment.