Skip to content

Commit

Permalink
Merge pull request #952 from wordpress-mobile/feature/heading-span-re…
Browse files Browse the repository at this point in the history
…store-metrics-for-spacing-updates

Heading Span - Reset previous font metrics if the font spacing changes
  • Loading branch information
Gerardo Pacheco authored Jan 31, 2022
2 parents b3d5ca6 + 52a7e6b commit 3f004c8
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ open class AztecHeadingSpan(

var previousFontMetrics: Paint.FontMetricsInt? = null
var previousTextScale: Float = 1.0f
var previousSpacing: Float? = null

enum class Heading constructor(internal val scale: Float, internal val tag: String) {
H1(SCALE_H1, "h1"),
Expand Down Expand Up @@ -163,10 +164,11 @@ open class AztecHeadingSpan(

override fun updateMeasureState(textPaint: TextPaint) {
// when font size changes - reset cached font metrics to reapply vertical padding
if (previousTextScale != heading.scale) {
if (previousTextScale != heading.scale || previousSpacing != textPaint.fontSpacing) {
previousFontMetrics = null
}
previousTextScale = heading.scale
previousSpacing = textPaint.fontSpacing

textPaint.textSize *= heading.scale
}
Expand Down

0 comments on commit 3f004c8

Please sign in to comment.