From 3cc891383f9dba8faa641ab422b699cc5142a24c Mon Sep 17 00:00:00 2001 From: Jun Gu <2dxgujun@gmail.com> Date: Thu, 18 Jan 2018 14:03:12 +0800 Subject: [PATCH] v1.2 release, fix line height bug --- README.md | 2 +- span/build.gradle | 2 +- span/src/main/kotlin/me/gujun/android/span/span.kt | 1 + .../me/gujun/android/span/style/LineSpacingSpan.kt | 12 +++++++++++- .../gujun/android/span/style/VerticalPaddingSpan.kt | 9 ++++++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b144ad0..726c4c3 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ val text = span { You can grab it via Gradle: ``` -implementation 'me.gujun.android:span:1.1' +implementation 'me.gujun.android:span:1.2' ``` ### Usage diff --git a/span/build.gradle b/span/build.gradle index a104c9a..c6413b5 100644 --- a/span/build.gradle +++ b/span/build.gradle @@ -23,7 +23,7 @@ dependencies { def GROUP = 'me.gujun.android' def ARTIFACTID = 'span' -def VERSION = '1.1' +def VERSION = '1.2' group = GROUP version = VERSION diff --git a/span/src/main/kotlin/me/gujun/android/span/span.kt b/span/src/main/kotlin/me/gujun/android/span/span.kt index 853f6f3..994286c 100644 --- a/span/src/main/kotlin/me/gujun/android/span/span.kt +++ b/span/src/main/kotlin/me/gujun/android/span/span.kt @@ -26,6 +26,7 @@ import me.gujun.android.span.style.LineSpacingSpan import me.gujun.android.span.style.TextDecorationLineSpan import me.gujun.android.span.style.VerticalPaddingSpan +// TODO Save styles class Span(val parent: Span? = null) : SpannableStringBuilder() { companion object { diff --git a/span/src/main/kotlin/me/gujun/android/span/style/LineSpacingSpan.kt b/span/src/main/kotlin/me/gujun/android/span/style/LineSpacingSpan.kt index 1bdc38c..128edd7 100644 --- a/span/src/main/kotlin/me/gujun/android/span/style/LineSpacingSpan.kt +++ b/span/src/main/kotlin/me/gujun/android/span/style/LineSpacingSpan.kt @@ -12,8 +12,18 @@ class LineSpacingSpan(private val add: Int) : LineHeightSpan { val spanStart = text.getSpanStart(this) val spanEnd = text.getSpanEnd(this) - if (start >= spanStart && end <= spanEnd) { +// Log.d("DEBUG", "text: \n$text") +// Log.d("DEBUG", "spanStart: $spanStart") +// Log.d("DEBUG", "spanEnd: $spanEnd") +// Log.d("DEBUG", "start: $start") +// Log.d("DEBUG", "end: $end") // end may include the \n character +// Log.d("DEBUG", "spanstartv: $spanstartv") +// Log.d("DEBUG", "v: $v") +// Log.d("DEBUG", "-----------------------") + + if (start >= spanStart && end < spanEnd) { fm.descent += add + fm.bottom += add } } } \ No newline at end of file diff --git a/span/src/main/kotlin/me/gujun/android/span/style/VerticalPaddingSpan.kt b/span/src/main/kotlin/me/gujun/android/span/style/VerticalPaddingSpan.kt index e23e142..9ea1cb2 100644 --- a/span/src/main/kotlin/me/gujun/android/span/style/VerticalPaddingSpan.kt +++ b/span/src/main/kotlin/me/gujun/android/span/style/VerticalPaddingSpan.kt @@ -13,18 +13,21 @@ class VerticalPaddingSpan(private val paddingTop: Int, val spanStart = text.getSpanStart(this) val spanEnd = text.getSpanEnd(this) -// Log.d("DEBUG", "text: $text") +// Log.d("DEBUG", "text: \n$text") // Log.d("DEBUG", "spanStart: $spanStart") // Log.d("DEBUG", "spanEnd: $spanEnd") // Log.d("DEBUG", "start: $start") -// Log.d("DEBUG", "end: $end") +// Log.d("DEBUG", "end: $end") // end may include the \n character // Log.d("DEBUG", "spanstartv: $spanstartv") // Log.d("DEBUG", "v: $v") +// Log.d("DEBUG", "-----------------------") if (spanStart == start) { + fm.top -= paddingTop fm.ascent -= paddingTop } - if (spanEnd == end - 1) { + if (spanEnd == end || spanEnd == end - 1) { + fm.bottom += paddingBottom fm.descent += paddingBottom } }