Skip to content

Commit 5b2fed0

Browse files
committed
Wired text modifier to text and heading sizes.
1 parent f642dc4 commit 5b2fed0

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import android.text.TextWatcher
4444
import android.text.style.SuggestionSpan
4545
import android.util.AttributeSet
4646
import android.util.DisplayMetrics
47+
import android.util.TypedValue
4748
import android.view.KeyEvent
4849
import android.view.LayoutInflater
4950
import android.view.MotionEvent
@@ -479,6 +480,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
479480
styles.getBoolean(R.styleable.AztecText_taskListStrikethroughChecked, false),
480481
styles.getColor(R.styleable.AztecText_taskListCheckedTextColor, 0))
481482

483+
val textSizeModifier = styles.getDimensionPixelSize(R.styleable.AztecText_textSizeModifier, 0)
484+
482485
blockFormatter = BlockFormatter(editor = this,
483486
listStyle = listStyle,
484487
listItemStyle = listItemStyle,
@@ -495,26 +498,32 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
495498
headerStyle = BlockFormatter.HeaderStyles(verticalHeadingMargin, mapOf(
496499
AztecHeadingSpan.Heading.H1 to BlockFormatter.HeaderStyles.HeadingStyle(
497500
styles.getDimensionPixelSize(R.styleable.AztecText_headingOneFontSize, 0),
501+
textSizeModifier,
498502
styles.getColor(R.styleable.AztecText_headingOneFontColor, 0)
499503
),
500504
AztecHeadingSpan.Heading.H2 to BlockFormatter.HeaderStyles.HeadingStyle(
501505
styles.getDimensionPixelSize(R.styleable.AztecText_headingTwoFontSize, 0),
506+
textSizeModifier,
502507
styles.getColor(R.styleable.AztecText_headingTwoFontColor, 0)
503508
),
504509
AztecHeadingSpan.Heading.H3 to BlockFormatter.HeaderStyles.HeadingStyle(
505510
styles.getDimensionPixelSize(R.styleable.AztecText_headingThreeFontSize, 0),
511+
textSizeModifier,
506512
styles.getColor(R.styleable.AztecText_headingThreeFontColor, 0)
507513
),
508514
AztecHeadingSpan.Heading.H4 to BlockFormatter.HeaderStyles.HeadingStyle(
509515
styles.getDimensionPixelSize(R.styleable.AztecText_headingFourFontSize, 0),
516+
textSizeModifier,
510517
styles.getColor(R.styleable.AztecText_headingFourFontColor, 0)
511518
),
512519
AztecHeadingSpan.Heading.H5 to BlockFormatter.HeaderStyles.HeadingStyle(
513520
styles.getDimensionPixelSize(R.styleable.AztecText_headingFiveFontSize, 0),
521+
textSizeModifier,
514522
styles.getColor(R.styleable.AztecText_headingFiveFontColor, 0)
515523
),
516524
AztecHeadingSpan.Heading.H6 to BlockFormatter.HeaderStyles.HeadingStyle(
517525
styles.getDimensionPixelSize(R.styleable.AztecText_headingSixFontSize, 0),
526+
textSizeModifier,
518527
styles.getColor(R.styleable.AztecText_headingSixFontColor, 0)
519528
)
520529
)),
@@ -528,7 +537,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
528537
styles.getColor(R.styleable.AztecText_preformatBorderColor, 0),
529538
styles.getDimensionPixelSize(R.styleable.AztecText_preformatBorderRadius, 0),
530539
styles.getDimensionPixelSize(R.styleable.AztecText_preformatBorderThickness, 0),
531-
styles.getDimensionPixelSize(R.styleable.AztecText_preformatTextSize, textSize.toInt())
540+
styles.getDimensionPixelSize(R.styleable.AztecText_preformatTextSize, textSize.toInt()) + textSizeModifier
532541
),
533542
alignmentRendering = alignmentRendering,
534543
exclusiveBlockStyles = BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false), verticalParagraphPadding),
@@ -614,6 +623,12 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
614623

615624
enableTextChangedListener()
616625

626+
if (textSize + textSizeModifier >= 0) {
627+
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + textSizeModifier)
628+
} else {
629+
setTextSize(TypedValue.COMPLEX_UNIT_PX, 0f)
630+
}
631+
617632
isViewInitialized = true
618633
}
619634

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BlockFormatter(editor: AztecText,
6565
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)
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, val fontSizeModifier: Int, val fontColor: Int)
6969
}
7070
data class ExclusiveBlockStyles(val enabled: Boolean = false, val verticalParagraphMargin: Int)
7171
data class ParagraphStyle(val verticalMargin: Int)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ 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 -> {
170-
textPaint.textSize = headingSize.value.toFloat()
175+
textPaint.textSize = headingSize.value.toFloat() + getSizeModifier()
171176
}
172177
}
173178
textPaint.isFakeBoldText = true
@@ -202,6 +207,10 @@ open class AztecHeadingSpan(
202207
?: HeadingSize.Scale(heading.scale)
203208
}
204209

210+
private fun getSizeModifier(): Int {
211+
return headerStyle.styles[heading]?.fontSizeModifier ?: 0
212+
}
213+
205214
private fun getHeadingColor(): Int? {
206215
return headerStyle.styles[heading]?.fontColor?.takeIf { it != 0 }
207216
}

0 commit comments

Comments
 (0)