Skip to content

Commit cff5d94

Browse files
authored
Merge branch 'trunk' into issue/disabled-autocorrect-on-certain-samsung-devices
2 parents 73c889a + caf8f43 commit cff5d94

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import android.text.TextWatcher
4545
import android.text.style.SuggestionSpan
4646
import android.util.AttributeSet
4747
import android.util.DisplayMetrics
48+
import android.util.TypedValue
4849
import android.view.KeyEvent
4950
import android.view.LayoutInflater
5051
import android.view.MotionEvent
@@ -496,26 +497,32 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
496497
headerStyle = BlockFormatter.HeaderStyles(verticalHeadingMargin, mapOf(
497498
AztecHeadingSpan.Heading.H1 to BlockFormatter.HeaderStyles.HeadingStyle(
498499
styles.getDimensionPixelSize(R.styleable.AztecText_headingOneFontSize, 0),
500+
0,
499501
styles.getColor(R.styleable.AztecText_headingOneFontColor, 0)
500502
),
501503
AztecHeadingSpan.Heading.H2 to BlockFormatter.HeaderStyles.HeadingStyle(
502504
styles.getDimensionPixelSize(R.styleable.AztecText_headingTwoFontSize, 0),
505+
0,
503506
styles.getColor(R.styleable.AztecText_headingTwoFontColor, 0)
504507
),
505508
AztecHeadingSpan.Heading.H3 to BlockFormatter.HeaderStyles.HeadingStyle(
506509
styles.getDimensionPixelSize(R.styleable.AztecText_headingThreeFontSize, 0),
510+
0,
507511
styles.getColor(R.styleable.AztecText_headingThreeFontColor, 0)
508512
),
509513
AztecHeadingSpan.Heading.H4 to BlockFormatter.HeaderStyles.HeadingStyle(
510514
styles.getDimensionPixelSize(R.styleable.AztecText_headingFourFontSize, 0),
515+
0,
511516
styles.getColor(R.styleable.AztecText_headingFourFontColor, 0)
512517
),
513518
AztecHeadingSpan.Heading.H5 to BlockFormatter.HeaderStyles.HeadingStyle(
514519
styles.getDimensionPixelSize(R.styleable.AztecText_headingFiveFontSize, 0),
520+
0,
515521
styles.getColor(R.styleable.AztecText_headingFiveFontColor, 0)
516522
),
517523
AztecHeadingSpan.Heading.H6 to BlockFormatter.HeaderStyles.HeadingStyle(
518524
styles.getDimensionPixelSize(R.styleable.AztecText_headingSixFontSize, 0),
525+
0,
519526
styles.getColor(R.styleable.AztecText_headingSixFontColor, 0)
520527
)
521528
)),
@@ -618,6 +625,21 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
618625
isViewInitialized = true
619626
}
620627

628+
/**
629+
Sets the modifier that will be added to the base text size.
630+
This is useful for situations where you have specified heading font size, instead or relying on default scaling.
631+
632+
Params: – textSizeModifierPx: the modifier in pixels
633+
*/
634+
fun setTextSizeModifier(textSizeModifierPx: Int) {
635+
blockFormatter.setTextSizeModifier(textSizeModifierPx)
636+
if (textSize + textSizeModifierPx >= 0) {
637+
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + textSizeModifierPx)
638+
} else {
639+
setTextSize(TypedValue.COMPLEX_UNIT_PX, 0f)
640+
}
641+
}
642+
621643
private fun <T> selectionHasExactlyOneMarker(start: Int, end: Int, type: Class<T>): Boolean {
622644
val spanFound: Array<T> = editableText.getSpans(
623645
start,

aztec/src/main/kotlin/org/wordpress/aztec/formatting/BlockFormatter.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class BlockFormatter(editor: AztecText,
6262
}
6363

6464
data class QuoteStyle(val quoteBackground: Int, val quoteColor: Int, val quoteTextColor: Int, val quoteBackgroundAlpha: Float, val quoteMargin: Int, val quotePadding: Int, val quoteWidth: Int, val verticalPadding: Int)
65-
data class PreformatStyle(val preformatBackground: Int, val preformatBackgroundAlpha: Float, val preformatColor: Int, val verticalPadding: Int, val leadingMargin: Int, val preformatBorderColor: Int, val preformatBorderRadius: Int, val preformatBorderThickness: Int, val preformatTextSize: Int)
65+
data class PreformatStyle(val preformatBackground: Int, val preformatBackgroundAlpha: Float, val preformatColor: Int, val verticalPadding: Int, val leadingMargin: Int, val preformatBorderColor: Int, val preformatBorderRadius: Int, val preformatBorderThickness: Int, var preformatTextSize: Int)
6666
data class ListItemStyle(val strikeThroughCheckedItems: Boolean, val checkedItemsTextColor: Int)
6767
data class HeaderStyles(val verticalPadding: Int, val styles: Map<AztecHeadingSpan.Heading, HeadingStyle>) {
68-
data class HeadingStyle(val fontSize: Int, val fontColor: Int)
68+
data class HeadingStyle(val fontSize: Int, var fontSizeModifier: Int, val fontColor: Int)
6969
}
7070
data class ExclusiveBlockStyles(val enabled: Boolean = false, val verticalParagraphMargin: Int)
7171
data class ParagraphStyle(val verticalMargin: Int)
@@ -1251,4 +1251,11 @@ class BlockFormatter(editor: AztecText,
12511251
}
12521252
}
12531253
}
1254+
1255+
fun setTextSizeModifier(modifier: Int) {
1256+
headerStyle.styles.forEach {
1257+
it.value.fontSizeModifier = modifier
1258+
}
1259+
preformatStyle.preformatTextSize += modifier
1260+
}
12541261
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ open class AztecHeadingSpan(
165165
when (val headingSize = getHeadingSize()) {
166166
is HeadingSize.Scale -> {
167167
textPaint.textSize *= heading.scale
168+
if (textPaint.textSize + getSizeModifier() >= 0) {
169+
textPaint.textSize += getSizeModifier()
170+
} else {
171+
textPaint.textSize = 0f
172+
}
168173
}
169174
is HeadingSize.Size -> {
170175
textPaint.textSize = headingSize.value.toFloat()
@@ -187,6 +192,11 @@ open class AztecHeadingSpan(
187192
when (headingSize) {
188193
is HeadingSize.Scale -> {
189194
paint.textSize *= heading.scale
195+
if (paint.textSize + getSizeModifier() >= 0) {
196+
paint.textSize += getSizeModifier()
197+
} else {
198+
paint.textSize = 0f
199+
}
190200
}
191201
is HeadingSize.Size -> {
192202
paint.textSize = headingSize.value.toFloat()
@@ -198,10 +208,14 @@ open class AztecHeadingSpan(
198208
}
199209

200210
private fun getHeadingSize(): HeadingSize {
201-
return headerStyle.styles[heading]?.fontSize?.takeIf { it > 0 }?.let { HeadingSize.Size(it) }
211+
return headerStyle.styles[heading]?.fontSize?.takeIf { it > 0 }?.let { HeadingSize.Size(it + getSizeModifier()) }
202212
?: HeadingSize.Scale(heading.scale)
203213
}
204214

215+
private fun getSizeModifier(): Int {
216+
return headerStyle.styles[heading]?.fontSizeModifier ?: 0
217+
}
218+
205219
private fun getHeadingColor(): Int? {
206220
return headerStyle.styles[heading]?.fontColor?.takeIf { it != 0 }
207221
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ open class AztecTaskListSpan(
111111
} else {
112112
0.2 to 0.8
113113
}
114-
d.setBounds((leftBound - drawableHeight * startShift).toInt(), (baseline - drawableHeight * 0.8).toInt(), (leftBound + drawableHeight * endShift).toInt(), (baseline + drawableHeight * 0.2).toInt())
114+
115+
d.setBounds((leftBound - drawableHeight * startShift).toInt().coerceAtLeast(0),
116+
(baseline - drawableHeight * 0.8).toInt(),
117+
(leftBound + drawableHeight * endShift).toInt(),
118+
(baseline + drawableHeight * 0.2).toInt())
115119
d.draw(c)
116120

117121
p.color = oldColor

0 commit comments

Comments
 (0)