Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST ONLY] Logging around chooseHeight method #1070

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,15 +125,19 @@ 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
previousFontMetrics!!.bottom = fm.bottom
previousFontMetrics!!.descent = fm.descent
}

previousFontMetrics = null

var addedTopPadding = false
var addedBottomPadding = false

Expand All @@ -151,13 +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
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
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
}
}
}

Expand All @@ -184,9 +203,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) {
Expand Down
Loading