Skip to content

Commit e7042e2

Browse files
committed
Added support for text size to preformat.
1 parent a7bc145 commit e7042e2

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
491491
resources.getDimensionPixelSize(R.dimen.preformat_leading_margin)),
492492
styles.getColor(R.styleable.AztecText_preformatBorderColor, 0),
493493
styles.getDimensionPixelSize(R.styleable.AztecText_preformatBorderRadius, 0),
494-
styles.getDimensionPixelSize(R.styleable.AztecText_preformatBorderThickness, 0)
494+
styles.getDimensionPixelSize(R.styleable.AztecText_preformatBorderThickness, 0),
495+
styles.getDimensionPixelSize(R.styleable.AztecText_preformatTextSize, textSize.toInt())
495496
),
496497
alignmentRendering = alignmentRendering,
497498
exclusiveBlockStyles = BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false), verticalParagraphPadding),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class BlockFormatter(editor: AztecText,
6161
}
6262

6363
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)
64-
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 )
64+
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)
6565
data class HeaderStyles(val verticalPadding: Int, val styles: Map<AztecHeadingSpan.Heading, HeadingStyle>) {
6666
data class HeadingStyle(val fontSize: Int, val fontColor: Int)
6767
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import android.graphics.Paint
77
import android.graphics.Path
88
import android.text.Layout
99
import android.text.Spanned
10+
import android.text.TextPaint
11+
import android.text.style.AbsoluteSizeSpan
1012
import android.text.style.LeadingMarginSpan
1113
import android.text.style.LineBackgroundSpan
1214
import android.text.style.LineHeightSpan
@@ -21,7 +23,7 @@ fun createPreformatSpan(
2123
nestingLevel: Int,
2224
alignmentRendering: AlignmentRendering,
2325
attributes: AztecAttributes = AztecAttributes(),
24-
preformatStyle: BlockFormatter.PreformatStyle = BlockFormatter.PreformatStyle(0, 0f, 0, 0, 0, 0, 0, 0)
26+
preformatStyle: BlockFormatter.PreformatStyle = BlockFormatter.PreformatStyle(0, 0f, 0, 0, 0, 0, 0, 0, 0)
2527
): AztecPreformatSpan =
2628
when (alignmentRendering) {
2729
AlignmentRendering.SPAN_LEVEL -> AztecPreformatSpanAligned(nestingLevel, attributes, preformatStyle)
@@ -74,6 +76,16 @@ open class AztecPreformatSpan(
7476
}
7577
}
7678

79+
override fun updateDrawState(ds: TextPaint) {
80+
super.updateDrawState(ds)
81+
ds.textSize = preformatStyle.preformatTextSize.toFloat()
82+
}
83+
84+
override fun updateMeasureState(paint: TextPaint) {
85+
super.updateMeasureState(paint)
86+
paint.textSize = preformatStyle.preformatTextSize.toFloat()
87+
}
88+
7789
private val strokePaint = Paint().apply {
7890
isAntiAlias = true
7991
style = Paint.Style.STROKE

aztec/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<attr name="preformatBorderRadius" format="reference|dimension" />
3232
<attr name="preformatBorderThickness" format="reference|dimension" />
3333
<attr name="preformatLeadingMargin" format="reference|dimension" />
34+
<attr name="preformatTextSize" format="reference|dimension" />
3435
<attr name="quoteBackground" format="reference|color" />
3536
<attr name="quoteBackgroundAlpha" format="reference|fraction" />
3637
<attr name="quoteColor" format="reference|color" />

aztec/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<dimen name="margin_extra_large">16dp</dimen>
4747

4848
<dimen name="preformat_leading_margin">8dp</dimen>
49+
<dimen name="preformat_text_size">16sp</dimen>
4950

5051
<dimen name="text_dialog">14sp</dimen>
5152

aztec/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<item name="preformatBorderRadius">2dp</item>
4646
<item name="preformatBorderThickness">1dp</item>
4747
<item name="preformatLeadingMargin">@dimen/preformat_leading_margin</item>
48+
<item name="preformatTextSize">@dimen/preformat_text_size</item>
4849
<!-- Quote -->
4950
<item name="quoteBackground">@color/blue_wordpress</item>
5051
<item name="quoteBackgroundAlpha">75%</item>

0 commit comments

Comments
 (0)