@@ -22,14 +22,18 @@ import android.graphics.Color
2222import android.graphics.Paint
2323import android.graphics.Rect
2424import android.support.v4.text.TextDirectionHeuristicsCompat
25+ import android.support.v4.text.TextUtilsCompat
26+ import android.support.v4.view.ViewCompat
2527import android.text.Layout
2628import android.text.Spanned
29+ import android.text.TextUtils
2730import android.text.style.LineBackgroundSpan
2831import android.text.style.LineHeightSpan
2932import android.text.style.QuoteSpan
3033import android.text.style.UpdateLayout
3134import org.wordpress.aztec.AztecAttributes
3235import org.wordpress.aztec.formatting.BlockFormatter
36+ import java.util.Locale
3337
3438class AztecQuoteSpan (
3539 override var nestingLevel : Int ,
@@ -77,9 +81,9 @@ class AztecQuoteSpan(
7781 val marginStart: Float
7882 val marginEnd: Float
7983
80- if (TextDirectionHeuristicsCompat . FIRSTSTRONG_LTR .isRtl (text, start, end - start )) {
81- marginStart = (x - quoteStyle.quoteMargin).toFloat()
82- marginEnd = (x - quoteStyle.quoteMargin + dir * quoteStyle.quoteWidth ).toFloat()
84+ if (isRtlQuote (text, start, end)) {
85+ marginStart = (x - quoteStyle.quoteMargin + dir * quoteStyle.quoteWidth ).toFloat()
86+ marginEnd = (x - quoteStyle.quoteMargin).toFloat()
8387 } else {
8488 marginStart = (x + quoteStyle.quoteMargin).toFloat()
8589 marginEnd = (x + quoteStyle.quoteMargin + dir * quoteStyle.quoteWidth).toFloat()
@@ -93,7 +97,7 @@ class AztecQuoteSpan(
9397
9498 override fun drawBackground (c : Canvas , p : Paint , left : Int , right : Int ,
9599 top : Int , baseline : Int , bottom : Int ,
96- text : CharSequence? , start : Int , end : Int ,
100+ text : CharSequence , start : Int , end : Int ,
97101 lnum : Int ) {
98102 val alpha: Int = (quoteStyle.quoteBackgroundAlpha * 255 ).toInt()
99103
@@ -107,7 +111,7 @@ class AztecQuoteSpan(
107111 val quoteBackgroundStart: Int
108112 val quoteBackgroundEnd: Int
109113
110- if (TextDirectionHeuristicsCompat . FIRSTSTRONG_LTR .isRtl (text, start, end - start )) {
114+ if (isRtlQuote (text, start, end)) {
111115 quoteBackgroundStart = left
112116 quoteBackgroundEnd = right - quoteStyle.quoteMargin
113117 } else {
@@ -120,4 +124,13 @@ class AztecQuoteSpan(
120124 c.drawRect(rect, p)
121125 p.color = paintColor
122126 }
127+
128+ private fun isRtlQuote (text : CharSequence , start : Int , end : Int ): Boolean {
129+ return if (start == end || TextUtils .isEmpty(text) || text.substring(start, end) == " \n " ) {
130+ TextUtilsCompat .getLayoutDirectionFromLocale(Locale .getDefault()) == ViewCompat .LAYOUT_DIRECTION_RTL
131+ } else {
132+ TextDirectionHeuristicsCompat .FIRSTSTRONG_LTR .isRtl(text, start, end - start)
133+ }
134+ }
135+
123136}
0 commit comments