latex, expose text color customization

This commit is contained in:
Dimitry Ivanov 2020-03-08 13:03:40 +03:00
parent 12c7c8909b
commit a94090a746
4 changed files with 69 additions and 6 deletions

View File

@ -18,10 +18,12 @@
* `LinkResolverDef` defaults to `https` when a link does not have scheme information ([#75]) * `LinkResolverDef` defaults to `https` when a link does not have scheme information ([#75])
* add `option` abstraction for `sample` module allowing switching of multiple cases in runtime via menu * add `option` abstraction for `sample` module allowing switching of multiple cases in runtime via menu
* non-empty bounds for `AsyncDrawable` when no dimensions are not yet available ([#189]) * non-empty bounds for `AsyncDrawable` when no dimensions are not yet available ([#189])
* `JLatexMathPlugin` add text color customization ([#207])
[#189]: https://github.com/noties/Markwon/issues/189 [#189]: https://github.com/noties/Markwon/issues/189
[#75]: https://github.com/noties/Markwon/issues/75 [#75]: https://github.com/noties/Markwon/issues/75
[#204]: https://github.com/noties/Markwon/issues/204 [#204]: https://github.com/noties/Markwon/issues/204
[#207]: https://github.com/noties/Markwon/issues/207
# 4.2.2 # 4.2.2

View File

@ -454,6 +454,7 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
final JLatexMathTheme.BackgroundProvider backgroundProvider = theme.blockBackgroundProvider(); final JLatexMathTheme.BackgroundProvider backgroundProvider = theme.blockBackgroundProvider();
final JLatexMathTheme.Padding padding = theme.blockPadding(); final JLatexMathTheme.Padding padding = theme.blockPadding();
final int color = theme.blockTextColor();
final JLatexMathDrawable.Builder builder = JLatexMathDrawable.builder(latex) final JLatexMathDrawable.Builder builder = JLatexMathDrawable.builder(latex)
.textSize(theme.blockTextSize()) .textSize(theme.blockTextSize())
@ -468,6 +469,10 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
builder.padding(padding.left, padding.top, padding.right, padding.bottom); builder.padding(padding.left, padding.top, padding.right, padding.bottom);
} }
if (color != 0) {
builder.color(color);
}
return builder.build(); return builder.build();
} }
@ -479,6 +484,7 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
final JLatexMathTheme.BackgroundProvider backgroundProvider = theme.inlineBackgroundProvider(); final JLatexMathTheme.BackgroundProvider backgroundProvider = theme.inlineBackgroundProvider();
final JLatexMathTheme.Padding padding = theme.inlinePadding(); final JLatexMathTheme.Padding padding = theme.inlinePadding();
final int color = theme.inlineTextColor();
final JLatexMathDrawable.Builder builder = JLatexMathDrawable.builder(latex) final JLatexMathDrawable.Builder builder = JLatexMathDrawable.builder(latex)
.textSize(theme.inlineTextSize()) .textSize(theme.inlineTextSize())
@ -492,6 +498,10 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
builder.padding(padding.left, padding.top, padding.right, padding.bottom); builder.padding(padding.left, padding.top, padding.right, padding.bottom);
} }
if (color != 0) {
builder.color(color);
}
return builder.build(); return builder.build();
} }

View File

@ -2,6 +2,7 @@ package io.noties.markwon.ext.latex;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.Px; import androidx.annotation.Px;
@ -118,6 +119,11 @@ public abstract class JLatexMathTheme {
@Nullable @Nullable
public abstract Padding blockPadding(); public abstract Padding blockPadding();
@ColorInt
public abstract int inlineTextColor();
@ColorInt
public abstract int blockTextColor();
public static class Builder { public static class Builder {
private final float textSize; private final float textSize;
@ -136,6 +142,10 @@ public abstract class JLatexMathTheme {
private Padding inlinePadding; private Padding inlinePadding;
private Padding blockPadding; private Padding blockPadding;
private int textColor = 0xFF000000;
private int inlineTextColor;
private int blockTextColor;
Builder(float textSize, float inlineTextSize, float blockTextSize) { Builder(float textSize, float inlineTextSize, float blockTextSize) {
this.textSize = textSize; this.textSize = textSize;
this.inlineTextSize = inlineTextSize; this.inlineTextSize = inlineTextSize;
@ -194,6 +204,24 @@ public abstract class JLatexMathTheme {
return this; return this;
} }
@NonNull
public Builder textColor(@ColorInt int textColor) {
this.textColor = textColor;
return this;
}
@NonNull
public Builder inlineTextColor(@ColorInt int inlineTextColor) {
this.inlineTextColor = inlineTextColor;
return this;
}
@NonNull
public Builder blockTextColor(@ColorInt int blockTextColor) {
this.blockTextColor = blockTextColor;
return this;
}
@NonNull @NonNull
public JLatexMathTheme build() { public JLatexMathTheme build() {
return new Impl(this); return new Impl(this);
@ -218,6 +246,10 @@ public abstract class JLatexMathTheme {
private final Padding inlinePadding; private final Padding inlinePadding;
private final Padding blockPadding; private final Padding blockPadding;
private final int textColor;
private final int inlineTextColor;
private final int blockTextColor;
Impl(@NonNull Builder builder) { Impl(@NonNull Builder builder) {
this.textSize = builder.textSize; this.textSize = builder.textSize;
this.inlineTextSize = builder.inlineTextSize; this.inlineTextSize = builder.inlineTextSize;
@ -230,6 +262,9 @@ public abstract class JLatexMathTheme {
this.padding = builder.padding; this.padding = builder.padding;
this.inlinePadding = builder.inlinePadding; this.inlinePadding = builder.inlinePadding;
this.blockPadding = builder.blockPadding; this.blockPadding = builder.blockPadding;
this.textColor = builder.textColor;
this.inlineTextColor = builder.inlineTextColor;
this.blockTextColor = builder.blockTextColor;
} }
@Override @Override
@ -293,5 +328,21 @@ public abstract class JLatexMathTheme {
} }
return padding; return padding;
} }
@Override
public int inlineTextColor() {
if (inlineTextColor != 0) {
return inlineTextColor;
}
return textColor;
}
@Override
public int blockTextColor() {
if (blockTextColor != 0) {
return blockTextColor;
}
return textColor;
}
} }
} }

View File

@ -1,6 +1,7 @@
package io.noties.markwon.sample.latex; package io.noties.markwon.sample.latex;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
@ -141,12 +142,11 @@ public class LatexActivity extends ActivityWithMenuOptions {
final String md = wrapLatexInSampleMarkdown(LATEX_LONG_DIVISION); final String md = wrapLatexInSampleMarkdown(LATEX_LONG_DIVISION);
final Markwon markwon = Markwon.builder(this) final Markwon markwon = Markwon.builder(this)
.usePlugin(MarkwonInlineParserPlugin.create()) .usePlugin(MarkwonInlineParserPlugin.create())
.usePlugin(JLatexMathPlugin.create(textView.getTextSize(), new JLatexMathPlugin.BuilderConfigure() { .usePlugin(JLatexMathPlugin.create(textView.getTextSize(), builder -> builder.theme()
@Override .inlineTextColor(Color.RED)
public void configureBuilder(@NonNull JLatexMathPlugin.Builder builder) { .blockTextColor(Color.GREEN)
.inlineBackgroundProvider(() -> new ColorDrawable(Color.YELLOW))
} .blockBackgroundProvider(() -> new ColorDrawable(Color.GRAY))))
}))
.build(); .build();
markwon.setMarkdown(textView, md); markwon.setMarkdown(textView, md);
} }