Add headingTextSizes
This commit is contained in:
parent
a071646fee
commit
9bd5644150
@ -176,6 +176,11 @@ public class SpannableTheme {
|
|||||||
// by default, whatever typeface is set on the TextView
|
// by default, whatever typeface is set on the TextView
|
||||||
protected final Typeface headingTypeface;
|
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`
|
// by default `SCRIPT_DEF_TEXT_SIZE_RATIO`
|
||||||
protected final float scriptTextSizeRatio;
|
protected final float scriptTextSizeRatio;
|
||||||
|
|
||||||
@ -218,6 +223,7 @@ public class SpannableTheme {
|
|||||||
this.headingBreakHeight = builder.headingBreakHeight;
|
this.headingBreakHeight = builder.headingBreakHeight;
|
||||||
this.headingBreakColor = builder.headingBreakColor;
|
this.headingBreakColor = builder.headingBreakColor;
|
||||||
this.headingTypeface = builder.headingTypeface;
|
this.headingTypeface = builder.headingTypeface;
|
||||||
|
this.headingTextSizes = builder.headingTextSizes;
|
||||||
this.scriptTextSizeRatio = builder.scriptTextSizeRatio;
|
this.scriptTextSizeRatio = builder.scriptTextSizeRatio;
|
||||||
this.thematicBreakColor = builder.thematicBreakColor;
|
this.thematicBreakColor = builder.thematicBreakColor;
|
||||||
this.thematicBreakHeight = builder.thematicBreakHeight;
|
this.thematicBreakHeight = builder.thematicBreakHeight;
|
||||||
@ -377,8 +383,12 @@ public class SpannableTheme {
|
|||||||
} else {
|
} else {
|
||||||
paint.setTypeface(headingTypeface);
|
paint.setTypeface(headingTypeface);
|
||||||
}
|
}
|
||||||
|
if (headingTextSizes != null && headingTextSizes.length >= level) {
|
||||||
|
paint.setTextSize(headingTextSizes[level - 1]);
|
||||||
|
} else {
|
||||||
paint.setTextSize(paint.getTextSize() * HEADING_SIZES[level - 1]);
|
paint.setTextSize(paint.getTextSize() * HEADING_SIZES[level - 1]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void applyHeadingBreakStyle(@NonNull Paint paint) {
|
public void applyHeadingBreakStyle(@NonNull Paint paint) {
|
||||||
final int color;
|
final int color;
|
||||||
@ -500,6 +510,7 @@ public class SpannableTheme {
|
|||||||
private int headingBreakHeight = -1;
|
private int headingBreakHeight = -1;
|
||||||
private int headingBreakColor;
|
private int headingBreakColor;
|
||||||
private Typeface headingTypeface;
|
private Typeface headingTypeface;
|
||||||
|
private float[] headingTextSizes;
|
||||||
private float scriptTextSizeRatio;
|
private float scriptTextSizeRatio;
|
||||||
private int thematicBreakColor;
|
private int thematicBreakColor;
|
||||||
private int thematicBreakHeight = -1;
|
private int thematicBreakHeight = -1;
|
||||||
@ -530,6 +541,7 @@ public class SpannableTheme {
|
|||||||
this.headingBreakHeight = theme.headingBreakHeight;
|
this.headingBreakHeight = theme.headingBreakHeight;
|
||||||
this.headingBreakColor = theme.headingBreakColor;
|
this.headingBreakColor = theme.headingBreakColor;
|
||||||
this.headingTypeface = theme.headingTypeface;
|
this.headingTypeface = theme.headingTypeface;
|
||||||
|
this.headingTextSizes = theme.headingTextSizes;
|
||||||
this.scriptTextSizeRatio = theme.scriptTextSizeRatio;
|
this.scriptTextSizeRatio = theme.scriptTextSizeRatio;
|
||||||
this.thematicBreakColor = theme.thematicBreakColor;
|
this.thematicBreakColor = theme.thematicBreakColor;
|
||||||
this.thematicBreakHeight = theme.thematicBreakHeight;
|
this.thematicBreakHeight = theme.thematicBreakHeight;
|
||||||
@ -650,6 +662,12 @@ public class SpannableTheme {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Builder headingTextSizes(float[] headingTextSizes) {
|
||||||
|
this.headingTextSizes = headingTextSizes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder scriptTextSizeRatio(@FloatRange(from = .0F, to = Float.MAX_VALUE) float scriptTextSizeRatio) {
|
public Builder scriptTextSizeRatio(@FloatRange(from = .0F, to = Float.MAX_VALUE) float scriptTextSizeRatio) {
|
||||||
this.scriptTextSizeRatio = scriptTextSizeRatio;
|
this.scriptTextSizeRatio = scriptTextSizeRatio;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user