Skip to content

Commit f230855

Browse files
authored
Merge pull request #992 from wordpress-mobile/feature/advanced-formatting
Advanced styling of headings
2 parents 873a858 + 8b6f7bc commit f230855

File tree

8 files changed

+274
-126
lines changed

8 files changed

+274
-126
lines changed

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

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import org.wordpress.aztec.spans.AztecAudioSpan
8181
import org.wordpress.aztec.spans.AztecCodeSpan
8282
import org.wordpress.aztec.spans.AztecCursorSpan
8383
import org.wordpress.aztec.spans.AztecDynamicImageSpan
84+
import org.wordpress.aztec.spans.AztecHeadingSpan
8485
import org.wordpress.aztec.spans.AztecImageSpan
8586
import org.wordpress.aztec.spans.AztecListItemSpan
8687
import org.wordpress.aztec.spans.AztecMediaClickableSpan
@@ -289,6 +290,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
289290

290291
var widthMeasureSpec: Int = 0
291292

293+
var verticalParagraphPadding: Int = 0
292294
var verticalParagraphMargin: Int = 0
293295
var verticalHeadingMargin: Int = 0
294296

@@ -420,8 +422,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
420422

421423
commentsVisible = styles.getBoolean(R.styleable.AztecText_commentsVisible, commentsVisible)
422424

423-
verticalParagraphMargin = styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding,
425+
verticalParagraphPadding = styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding,
424426
resources.getDimensionPixelSize(R.dimen.block_vertical_padding))
427+
verticalParagraphMargin = styles.getDimensionPixelSize(R.styleable.AztecText_paragraphVerticalMargin,
428+
resources.getDimensionPixelSize(R.dimen.block_vertical_margin))
425429
verticalHeadingMargin = styles.getDimensionPixelSize(R.styleable.AztecText_headingVerticalPadding,
426430
resources.getDimensionPixelSize(R.dimen.heading_vertical_padding))
427431

@@ -437,25 +441,51 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
437441
styles.getDimensionPixelSize(R.styleable.AztecText_bulletMargin, 0),
438442
styles.getDimensionPixelSize(R.styleable.AztecText_bulletPadding, 0),
439443
styles.getDimensionPixelSize(R.styleable.AztecText_bulletWidth, 0),
440-
verticalParagraphMargin)
441-
blockFormatter = BlockFormatter(this,
442-
listStyle,
443-
BlockFormatter.QuoteStyle(
444+
verticalParagraphPadding)
445+
blockFormatter = BlockFormatter(editor = this,
446+
listStyle = listStyle,
447+
quoteStyle = BlockFormatter.QuoteStyle(
444448
styles.getColor(R.styleable.AztecText_quoteBackground, 0),
445449
styles.getColor(R.styleable.AztecText_quoteColor, 0),
446450
styles.getFraction(R.styleable.AztecText_quoteBackgroundAlpha, 1, 1, 0f),
447451
styles.getDimensionPixelSize(R.styleable.AztecText_quoteMargin, 0),
448452
styles.getDimensionPixelSize(R.styleable.AztecText_quotePadding, 0),
449453
styles.getDimensionPixelSize(R.styleable.AztecText_quoteWidth, 0),
450-
verticalParagraphMargin),
451-
BlockFormatter.HeaderStyle(verticalHeadingMargin),
452-
BlockFormatter.PreformatStyle(
454+
verticalParagraphPadding),
455+
headerStyle = BlockFormatter.HeaderStyles(verticalHeadingMargin, mapOf(
456+
AztecHeadingSpan.Heading.H1 to BlockFormatter.HeaderStyles.HeadingStyle(
457+
styles.getDimensionPixelSize(R.styleable.AztecText_headingOneFontSize, 0),
458+
styles.getColor(R.styleable.AztecText_headingOneFontColor, 0)
459+
),
460+
AztecHeadingSpan.Heading.H2 to BlockFormatter.HeaderStyles.HeadingStyle(
461+
styles.getDimensionPixelSize(R.styleable.AztecText_headingTwoFontSize, 0),
462+
styles.getColor(R.styleable.AztecText_headingTwoFontColor, 0)
463+
),
464+
AztecHeadingSpan.Heading.H3 to BlockFormatter.HeaderStyles.HeadingStyle(
465+
styles.getDimensionPixelSize(R.styleable.AztecText_headingThreeFontSize, 0),
466+
styles.getColor(R.styleable.AztecText_headingThreeFontColor, 0)
467+
),
468+
AztecHeadingSpan.Heading.H4 to BlockFormatter.HeaderStyles.HeadingStyle(
469+
styles.getDimensionPixelSize(R.styleable.AztecText_headingFourFontSize, 0),
470+
styles.getColor(R.styleable.AztecText_headingFourFontColor, 0)
471+
),
472+
AztecHeadingSpan.Heading.H5 to BlockFormatter.HeaderStyles.HeadingStyle(
473+
styles.getDimensionPixelSize(R.styleable.AztecText_headingFiveFontSize, 0),
474+
styles.getColor(R.styleable.AztecText_headingFiveFontColor, 0)
475+
),
476+
AztecHeadingSpan.Heading.H6 to BlockFormatter.HeaderStyles.HeadingStyle(
477+
styles.getDimensionPixelSize(R.styleable.AztecText_headingSixFontSize, 0),
478+
styles.getColor(R.styleable.AztecText_headingSixFontColor, 0)
479+
)
480+
)),
481+
preformatStyle = BlockFormatter.PreformatStyle(
453482
styles.getColor(R.styleable.AztecText_preformatBackground, 0),
454483
getPreformatBackgroundAlpha(styles),
455484
styles.getColor(R.styleable.AztecText_preformatColor, 0),
456-
verticalParagraphMargin),
457-
alignmentRendering,
458-
BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false))
485+
verticalParagraphPadding),
486+
alignmentRendering = alignmentRendering,
487+
exclusiveBlockStyles = BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false), verticalParagraphPadding),
488+
paragraphStyle = BlockFormatter.ParagraphStyle(verticalParagraphMargin)
459489
)
460490
EnhancedMovementMethod.taskListClickHandler = TaskListClickHandler(listStyle)
461491

@@ -727,7 +757,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
727757
ParagraphBleedAdjuster.install(this)
728758
ParagraphCollapseAdjuster.install(this)
729759

730-
EndOfParagraphMarkerAdder.install(this, verticalParagraphMargin)
760+
EndOfParagraphMarkerAdder.install(this, verticalParagraphPadding)
731761

732762
SuggestionWatcher.install(this)
733763

@@ -1547,7 +1577,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15471577

15481578
private fun switchToAztecStyle(editable: Editable, start: Int, end: Int) {
15491579
editable.getSpans(start, end, IAztecBlockSpan::class.java).forEach { blockFormatter.setBlockStyle(it) }
1550-
editable.getSpans(start, end, EndOfParagraphMarker::class.java).forEach { it.verticalPadding = verticalParagraphMargin }
1580+
editable.getSpans(start, end, EndOfParagraphMarker::class.java).forEach { it.verticalPadding = verticalParagraphPadding }
15511581
editable.getSpans(start, end, AztecURLSpan::class.java).forEach { it.linkStyle = linkFormatter.linkStyle }
15521582
editable.getSpans(start, end, AztecCodeSpan::class.java).forEach { it.codeStyle = inlineFormatter.codeStyle }
15531583

0 commit comments

Comments
 (0)