Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced styling of headings #992

Merged
merged 15 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
android:scrollbars="vertical"
android:imeOptions="flagNoExtractUi"
aztec:historyEnable="true"
aztec:historySize="10"/>
aztec:historySize="10"
aztec:headingOneFontSize="24sp"
khaykov marked this conversation as resolved.
Show resolved Hide resolved
aztec:headingOneFontColor="@color/blue_light"
aztec:headingThreeFontSize="16sp"
aztec:headingThreeFontColor="#F09389"/>

<org.wordpress.aztec.source.SourceViewEditText
android:id="@+id/source"
Expand Down
56 changes: 43 additions & 13 deletions aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import org.wordpress.aztec.spans.AztecAudioSpan
import org.wordpress.aztec.spans.AztecCodeSpan
import org.wordpress.aztec.spans.AztecCursorSpan
import org.wordpress.aztec.spans.AztecDynamicImageSpan
import org.wordpress.aztec.spans.AztecHeadingSpan
import org.wordpress.aztec.spans.AztecImageSpan
import org.wordpress.aztec.spans.AztecListItemSpan
import org.wordpress.aztec.spans.AztecMediaClickableSpan
Expand Down Expand Up @@ -289,6 +290,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown

var widthMeasureSpec: Int = 0

var verticalParagraphPadding: Int = 0
var verticalParagraphMargin: Int = 0
var verticalHeadingMargin: Int = 0

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

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

verticalParagraphMargin = styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding,
verticalParagraphPadding = styles.getDimensionPixelSize(R.styleable.AztecText_blockVerticalPadding,
resources.getDimensionPixelSize(R.dimen.block_vertical_padding))
verticalParagraphMargin = styles.getDimensionPixelSize(R.styleable.AztecText_paragraphVerticalMargin,
resources.getDimensionPixelSize(R.dimen.block_vertical_margin))
verticalHeadingMargin = styles.getDimensionPixelSize(R.styleable.AztecText_headingVerticalPadding,
resources.getDimensionPixelSize(R.dimen.heading_vertical_padding))

Expand All @@ -437,25 +441,51 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
styles.getDimensionPixelSize(R.styleable.AztecText_bulletMargin, 0),
styles.getDimensionPixelSize(R.styleable.AztecText_bulletPadding, 0),
styles.getDimensionPixelSize(R.styleable.AztecText_bulletWidth, 0),
verticalParagraphMargin)
blockFormatter = BlockFormatter(this,
listStyle,
BlockFormatter.QuoteStyle(
verticalParagraphPadding)
blockFormatter = BlockFormatter(editor = this,
listStyle = listStyle,
quoteStyle = BlockFormatter.QuoteStyle(
styles.getColor(R.styleable.AztecText_quoteBackground, 0),
styles.getColor(R.styleable.AztecText_quoteColor, 0),
styles.getFraction(R.styleable.AztecText_quoteBackgroundAlpha, 1, 1, 0f),
styles.getDimensionPixelSize(R.styleable.AztecText_quoteMargin, 0),
styles.getDimensionPixelSize(R.styleable.AztecText_quotePadding, 0),
styles.getDimensionPixelSize(R.styleable.AztecText_quoteWidth, 0),
verticalParagraphMargin),
BlockFormatter.HeaderStyle(verticalHeadingMargin),
BlockFormatter.PreformatStyle(
verticalParagraphPadding),
headerStyle = BlockFormatter.HeaderStyles(verticalHeadingMargin, mapOf(
AztecHeadingSpan.Heading.H1 to BlockFormatter.HeaderStyles.HeadingStyle(
styles.getDimensionPixelSize(R.styleable.AztecText_headingOneFontSize, 0),
styles.getColor(R.styleable.AztecText_headingOneFontColor, 0)
),
AztecHeadingSpan.Heading.H2 to BlockFormatter.HeaderStyles.HeadingStyle(
styles.getDimensionPixelSize(R.styleable.AztecText_headingTwoFontSize, 0),
styles.getColor(R.styleable.AztecText_headingTwoFontColor, 0)
),
AztecHeadingSpan.Heading.H3 to BlockFormatter.HeaderStyles.HeadingStyle(
styles.getDimensionPixelSize(R.styleable.AztecText_headingThreeFontSize, 0),
styles.getColor(R.styleable.AztecText_headingThreeFontColor, 0)
),
AztecHeadingSpan.Heading.H4 to BlockFormatter.HeaderStyles.HeadingStyle(
styles.getDimensionPixelSize(R.styleable.AztecText_headingFourFontSize, 0),
styles.getColor(R.styleable.AztecText_headingFourFontColor, 0)
),
AztecHeadingSpan.Heading.H5 to BlockFormatter.HeaderStyles.HeadingStyle(
styles.getDimensionPixelSize(R.styleable.AztecText_headingFiveFontSize, 0),
styles.getColor(R.styleable.AztecText_headingFiveFontColor, 0)
),
AztecHeadingSpan.Heading.H6 to BlockFormatter.HeaderStyles.HeadingStyle(
styles.getDimensionPixelSize(R.styleable.AztecText_headingSixFontSize, 0),
styles.getColor(R.styleable.AztecText_headingSixFontColor, 0)
)
)),
preformatStyle = BlockFormatter.PreformatStyle(
styles.getColor(R.styleable.AztecText_preformatBackground, 0),
getPreformatBackgroundAlpha(styles),
styles.getColor(R.styleable.AztecText_preformatColor, 0),
verticalParagraphMargin),
alignmentRendering,
BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false))
verticalParagraphPadding),
alignmentRendering = alignmentRendering,
exclusiveBlockStyles = BlockFormatter.ExclusiveBlockStyles(styles.getBoolean(R.styleable.AztecText_exclusiveBlocks, false), verticalParagraphPadding),
paragraphStyle = BlockFormatter.ParagraphStyle(verticalParagraphMargin)
)
EnhancedMovementMethod.taskListClickHandler = TaskListClickHandler(listStyle)

Expand Down Expand Up @@ -727,7 +757,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
ParagraphBleedAdjuster.install(this)
ParagraphCollapseAdjuster.install(this)

EndOfParagraphMarkerAdder.install(this, verticalParagraphMargin)
EndOfParagraphMarkerAdder.install(this, verticalParagraphPadding)

SuggestionWatcher.install(this)

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

private fun switchToAztecStyle(editable: Editable, start: Int, end: Int) {
editable.getSpans(start, end, IAztecBlockSpan::class.java).forEach { blockFormatter.setBlockStyle(it) }
editable.getSpans(start, end, EndOfParagraphMarker::class.java).forEach { it.verticalPadding = verticalParagraphMargin }
editable.getSpans(start, end, EndOfParagraphMarker::class.java).forEach { it.verticalPadding = verticalParagraphPadding }
editable.getSpans(start, end, AztecURLSpan::class.java).forEach { it.linkStyle = linkFormatter.linkStyle }
editable.getSpans(start, end, AztecCodeSpan::class.java).forEach { it.codeStyle = inlineFormatter.codeStyle }

Expand Down
Loading