Skip to content

Commit f9c6347

Browse files
committed
Added an option to programmatically set modifier.
1 parent 5b2fed0 commit f9c6347

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,15 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
632632
isViewInitialized = true
633633
}
634634

635+
fun setTextSizeModifier(textSizeModifierPx: Int) {
636+
blockFormatter.setTextSizeModifier(textSizeModifierPx)
637+
if (textSize + textSizeModifierPx >= 0) {
638+
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + textSizeModifierPx)
639+
} else {
640+
setTextSize(TypedValue.COMPLEX_UNIT_PX, 0f)
641+
}
642+
}
643+
635644
private fun <T> selectionHasExactlyOneMarker(start: Int, end: Int, type: Class<T>): Boolean {
636645
val spanFound: Array<T> = editableText.getSpans(
637646
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 fontSizeModifier: 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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ open class AztecHeadingSpan(
172172
}
173173
}
174174
is HeadingSize.Size -> {
175-
textPaint.textSize = headingSize.value.toFloat() + getSizeModifier()
175+
textPaint.textSize = headingSize.value.toFloat()
176176
}
177177
}
178178
textPaint.isFakeBoldText = true
@@ -192,6 +192,11 @@ open class AztecHeadingSpan(
192192
when (headingSize) {
193193
is HeadingSize.Scale -> {
194194
paint.textSize *= heading.scale
195+
if (paint.textSize + getSizeModifier() >= 0) {
196+
paint.textSize += getSizeModifier()
197+
} else {
198+
paint.textSize = 0f
199+
}
195200
}
196201
is HeadingSize.Size -> {
197202
paint.textSize = headingSize.value.toFloat()
@@ -203,7 +208,7 @@ open class AztecHeadingSpan(
203208
}
204209

205210
private fun getHeadingSize(): HeadingSize {
206-
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()) }
207212
?: HeadingSize.Scale(heading.scale)
208213
}
209214

0 commit comments

Comments
 (0)