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 9eb36b3a..06462f67 100644 --- a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java +++ b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java @@ -176,6 +176,11 @@ public class SpannableTheme { // by default, whatever typeface is set on the TextView protected final Typeface headingTypeface; + // by default, we use standard multipliers from the HTML spec (see HEADING_SIZES for values). + // this library supports 6 heading sizes, so make sure the array you pass here has 6 elements. + // note also that these values are in PIXELS, so you'll need to convert from SP first. + protected final float[] headingTextSizes; + // by default `SCRIPT_DEF_TEXT_SIZE_RATIO` protected final float scriptTextSizeRatio; @@ -218,6 +223,7 @@ public class SpannableTheme { this.headingBreakHeight = builder.headingBreakHeight; this.headingBreakColor = builder.headingBreakColor; this.headingTypeface = builder.headingTypeface; + this.headingTextSizes = builder.headingTextSizes; this.scriptTextSizeRatio = builder.scriptTextSizeRatio; this.thematicBreakColor = builder.thematicBreakColor; this.thematicBreakHeight = builder.thematicBreakHeight; @@ -377,7 +383,11 @@ public class SpannableTheme { } else { paint.setTypeface(headingTypeface); } - paint.setTextSize(paint.getTextSize() * HEADING_SIZES[level - 1]); + if (headingTextSizes != null && headingTextSizes.length >= level) { + paint.setTextSize(headingTextSizes[level - 1]); + } else { + paint.setTextSize(paint.getTextSize() * HEADING_SIZES[level - 1]); + } } public void applyHeadingBreakStyle(@NonNull Paint paint) { @@ -500,6 +510,7 @@ public class SpannableTheme { private int headingBreakHeight = -1; private int headingBreakColor; private Typeface headingTypeface; + private float[] headingTextSizes; private float scriptTextSizeRatio; private int thematicBreakColor; private int thematicBreakHeight = -1; @@ -530,6 +541,7 @@ public class SpannableTheme { this.headingBreakHeight = theme.headingBreakHeight; this.headingBreakColor = theme.headingBreakColor; this.headingTypeface = theme.headingTypeface; + this.headingTextSizes = theme.headingTextSizes; this.scriptTextSizeRatio = theme.scriptTextSizeRatio; this.thematicBreakColor = theme.thematicBreakColor; this.thematicBreakHeight = theme.thematicBreakHeight; @@ -650,6 +662,12 @@ public class SpannableTheme { return this; } + @NonNull + public Builder headingTextSizes(float[] headingTextSizes) { + this.headingTextSizes = headingTextSizes; + return this; + } + @NonNull public Builder scriptTextSizeRatio(@FloatRange(from = .0F, to = Float.MAX_VALUE) float scriptTextSizeRatio) { this.scriptTextSizeRatio = scriptTextSizeRatio;