Skip to content

Commit dece61c

Browse files
committed
Fixed issue with vertical padding being applied to all the lines.
1 parent 7a6266d commit dece61c

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecPreformatSpan.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,48 @@ open class AztecPreformatSpan(
5858
override var endBeforeBleed: Int = -1
5959
override var startBeforeCollapse: Int = -1
6060

61+
var originalAscent: Int = 0
62+
var originalTop: Int = 0
63+
var originalDescent: Int = 0
64+
var originalBottom: Int = 0
65+
6166
override fun chooseHeight(text: CharSequence, start: Int, end: Int, spanstartv: Int, v: Int,
6267
fm: Paint.FontMetricsInt) {
6368
val spanned = text as Spanned
6469
val spanStart = spanned.getSpanStart(this)
6570
val spanEnd = spanned.getSpanEnd(this)
71+
val isFirstLine = start <= spanStart
72+
val isLastLine = spanEnd <= end
73+
74+
if (isFirstLine) {
75+
originalAscent = fm.ascent
76+
originalTop = fm.top
77+
originalDescent = fm.descent
78+
originalBottom = fm.bottom
6679

67-
if (start == spanStart || start < spanStart) {
6880
fm.ascent -= preformatStyle.verticalPadding
6981
fm.top -= preformatStyle.verticalPadding
70-
}
7182

72-
if (end == spanEnd || spanEnd < end) {
83+
if(!isLastLine){
84+
fm.descent = originalDescent
85+
fm.bottom = originalBottom
86+
}
87+
}
88+
if (isLastLine) {
7389
fm.descent += preformatStyle.verticalPadding
7490
fm.bottom += preformatStyle.verticalPadding
91+
92+
if(!isFirstLine){
93+
fm.ascent = originalAscent
94+
fm.top = originalTop
95+
}
96+
}
97+
98+
if (!isFirstLine && !isLastLine) {
99+
fm.ascent = originalAscent
100+
fm.top = originalTop
101+
fm.descent = originalDescent
102+
fm.bottom = originalBottom
75103
}
76104
}
77105

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecQuoteSpan.kt

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,48 @@ open class AztecQuoteSpan(
8888

8989
override val TAG: String = "blockquote"
9090

91-
override fun chooseHeight(text: CharSequence, start: Int, end: Int, spanstartv: Int, v: Int, fm: Paint.FontMetricsInt) {
91+
var originalAscent: Int = 0
92+
var originalTop: Int = 0
93+
var originalDescent: Int = 0
94+
var originalBottom: Int = 0
95+
96+
override fun chooseHeight(text: CharSequence, start: Int, end: Int, spanstartv: Int, v: Int,
97+
fm: Paint.FontMetricsInt) {
9298
val spanned = text as Spanned
9399
val spanStart = spanned.getSpanStart(this)
94100
val spanEnd = spanned.getSpanEnd(this)
101+
val isFirstLine = start <= spanStart
102+
val isLastLine = spanEnd <= end
103+
104+
if (isFirstLine) {
105+
originalAscent = fm.ascent
106+
originalTop = fm.top
107+
originalDescent = fm.descent
108+
originalBottom = fm.bottom
95109

96-
if (start == spanStart || start < spanStart) {
97110
fm.ascent -= quoteStyle.verticalPadding
98111
fm.top -= quoteStyle.verticalPadding
112+
113+
if(!isLastLine){
114+
fm.descent = originalDescent
115+
fm.bottom = originalBottom
116+
}
99117
}
100-
if (end == spanEnd || spanEnd < end) {
118+
if (isLastLine) {
101119
fm.descent += quoteStyle.verticalPadding
102120
fm.bottom += quoteStyle.verticalPadding
121+
122+
if(!isFirstLine){
123+
fm.ascent = originalAscent
124+
fm.top = originalTop
125+
}
126+
}
127+
128+
if (!isFirstLine && !isLastLine) {
129+
fm.ascent = originalAscent
130+
fm.top = originalTop
131+
fm.descent = originalDescent
132+
fm.bottom = originalBottom
103133
}
104134
}
105135

0 commit comments

Comments
 (0)