diff --git a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java index 0701ed39..9eb36b3a 100644 --- a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java +++ b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java @@ -173,6 +173,9 @@ public class SpannableTheme { // by default, text color with `HEADING_DEF_BREAK_COLOR_ALPHA` applied alpha protected final int headingBreakColor; + // by default, whatever typeface is set on the TextView + protected final Typeface headingTypeface; + // by default `SCRIPT_DEF_TEXT_SIZE_RATIO` protected final float scriptTextSizeRatio; @@ -214,6 +217,7 @@ public class SpannableTheme { this.codeTextSize = builder.codeTextSize; this.headingBreakHeight = builder.headingBreakHeight; this.headingBreakColor = builder.headingBreakColor; + this.headingTypeface = builder.headingTypeface; this.scriptTextSizeRatio = builder.scriptTextSizeRatio; this.thematicBreakColor = builder.thematicBreakColor; this.thematicBreakHeight = builder.thematicBreakHeight; @@ -368,7 +372,11 @@ public class SpannableTheme { } public void applyHeadingTextStyle(@NonNull Paint paint, @IntRange(from = 1, to = 6) int level) { - paint.setFakeBoldText(true); + if (headingTypeface == null) { + paint.setFakeBoldText(true); + } else { + paint.setTypeface(headingTypeface); + } paint.setTextSize(paint.getTextSize() * HEADING_SIZES[level - 1]); } @@ -491,6 +499,7 @@ public class SpannableTheme { private int codeTextSize; private int headingBreakHeight = -1; private int headingBreakColor; + private Typeface headingTypeface; private float scriptTextSizeRatio; private int thematicBreakColor; private int thematicBreakHeight = -1; @@ -520,6 +529,7 @@ public class SpannableTheme { this.codeTextSize = theme.codeTextSize; this.headingBreakHeight = theme.headingBreakHeight; this.headingBreakColor = theme.headingBreakColor; + this.headingTypeface = theme.headingTypeface; this.scriptTextSizeRatio = theme.scriptTextSizeRatio; this.thematicBreakColor = theme.thematicBreakColor; this.thematicBreakHeight = theme.thematicBreakHeight; @@ -634,6 +644,12 @@ public class SpannableTheme { return this; } + @NonNull + public Builder headingTypeface(Typeface headingTypeface) { + this.headingTypeface = headingTypeface; + return this; + } + @NonNull public Builder scriptTextSizeRatio(@FloatRange(from = .0F, to = Float.MAX_VALUE) float scriptTextSizeRatio) { this.scriptTextSizeRatio = scriptTextSizeRatio; diff --git a/sample-custom-extension/src/main/java/ru/noties/markwon/sample/extension/MainActivity.java b/sample-custom-extension/src/main/java/ru/noties/markwon/sample/extension/MainActivity.java index a81f8eb0..f6eb0b7c 100644 --- a/sample-custom-extension/src/main/java/ru/noties/markwon/sample/extension/MainActivity.java +++ b/sample-custom-extension/src/main/java/ru/noties/markwon/sample/extension/MainActivity.java @@ -1,6 +1,7 @@ package ru.noties.markwon.sample.extension; import android.app.Activity; +import android.graphics.Typeface; import android.os.Bundle; import android.widget.TextView; @@ -13,6 +14,7 @@ import java.util.Arrays; import ru.noties.markwon.SpannableBuilder; import ru.noties.markwon.SpannableConfiguration; +import ru.noties.markwon.spans.SpannableTheme; import ru.noties.markwon.tasklist.TaskListExtension; public class MainActivity extends Activity { @@ -51,8 +53,13 @@ public class MainActivity extends Activity { final IconSpanProvider spanProvider = IconSpanProvider.create(this, 0); // create an instance of visitor to process parsed markdown + SpannableConfiguration configuration = SpannableConfiguration.builder(this) + .theme(SpannableTheme.builder() + .headingTypeface(Typeface.MONOSPACE) + .build()) + .build(); final IconVisitor visitor = new IconVisitor( - SpannableConfiguration.create(this), + configuration, builder, spanProvider ); diff --git a/sample-custom-extension/src/main/res/layout/activity_main.xml b/sample-custom-extension/src/main/res/layout/activity_main.xml index 439dac71..e4f2a936 100644 --- a/sample-custom-extension/src/main/res/layout/activity_main.xml +++ b/sample-custom-extension/src/main/res/layout/activity_main.xml @@ -11,6 +11,7 @@ android:layout_height="wrap_content" android:padding="8dip" android:textAppearance="?android:attr/textAppearanceMedium" + android:textSize="15sp" tools:text="@string/input"/> - \ No newline at end of file + diff --git a/sample-custom-extension/src/main/res/values/strings.xml b/sample-custom-extension/src/main/res/values/strings.xml index 7dc177e7..fdc01039 100644 --- a/sample-custom-extension/src/main/res/values/strings.xml +++ b/sample-custom-extension/src/main/res/values/strings.xml @@ -6,6 +6,7 @@ # Hello! @ic-android-black-24\n\n Home 36 black: @ic-home-black-36\n\n Memory 48 black: @ic-memory-black-48\n\n + ### I AM ANOTHER HEADER\n\n Sentiment Satisfied 64 red: @ic-sentiment_satisfied-red-64 ]]>