core - CustomTypefaceSpan polishing

This commit is contained in:
Dimitry Ivanov 2020-10-09 15:42:37 +03:00
parent 132756af4e
commit c4cb4420b1
3 changed files with 35 additions and 4 deletions

View File

@ -1,5 +1,20 @@
# Changelog # Changelog
# $SNAPSHOT;
#### Changed
* `core` - `CustomTypefaceSpan` new `mergeStyles` functionality and new factory method([#298])<br>Thanks [@c-b-h]
#### Deprecated
* `code` - `CustomTypefaceSpan(Typeface)` constructor, use `CustomTypefaceSpan.create(Typeface)`
or `CustomTypefaceSpan.create(Typeface, boolean)` factory methods instead
[#298]: https://github.com/noties/Markwon/pull/298
[@c-b-h]: https://github.com/c-b-h
# 4.6.0 # 4.6.0
#### Added #### Added

View File

@ -8,7 +8,7 @@ android.enableJetifier=true
android.enableBuildCache=true android.enableBuildCache=true
android.buildCacheDir=build/pre-dex-cache android.buildCacheDir=build/pre-dex-cache
VERSION_NAME=4.6.0 VERSION_NAME=4.6.1-SNAPSHOT
GROUP=io.noties.markwon GROUP=io.noties.markwon
POM_DESCRIPTION=Markwon markdown for Android POM_DESCRIPTION=Markwon markdown for Android

View File

@ -12,7 +12,7 @@ import androidx.annotation.NonNull;
* not used directly by the library, it\'s helpful for customizations. * not used directly by the library, it\'s helpful for customizations.
* <p> * <p>
* Please note that this implementation does not validate current paint state * Please note that this implementation does not validate current paint state
* and won\'t be updating/modifying supplied Typeface. * and won\'t be updating/modifying supplied Typeface unless {@code mergeStyles} is specified
* *
* @since 3.0.0 * @since 3.0.0
*/ */
@ -20,9 +20,19 @@ public class CustomTypefaceSpan extends MetricAffectingSpan {
@NonNull @NonNull
public static CustomTypefaceSpan create(@NonNull Typeface typeface) { public static CustomTypefaceSpan create(@NonNull Typeface typeface) {
return new CustomTypefaceSpan(typeface); return create(typeface, false);
} }
/**
* <strong>NB!</strong> in order to <em>merge</em> typeface styles, supplied typeface must be
* able to be created via {@code Typeface.create(Typeface, int)} method. This would mean that bundled fonts
* inside {@code assets} folder would be able to display styles properly.
*
* @param mergeStyles control if typeface styles must be merged, for example, if
* this span (bold) is contained by other span (italic),
* {@code mergeStyles=true} would result in bold-italic
* @since $SNAPSHOT;
*/
@NonNull @NonNull
public static CustomTypefaceSpan create(@NonNull Typeface typeface, boolean mergeStyles) { public static CustomTypefaceSpan create(@NonNull Typeface typeface, boolean mergeStyles) {
return new CustomTypefaceSpan(typeface, mergeStyles); return new CustomTypefaceSpan(typeface, mergeStyles);
@ -32,11 +42,17 @@ public class CustomTypefaceSpan extends MetricAffectingSpan {
private final boolean mergeStyles; private final boolean mergeStyles;
/**
* @deprecated $SNAPSHOT; use {{@link #create(Typeface)}}
* or {@link #create(Typeface, boolean)} factory method
*/
@Deprecated
public CustomTypefaceSpan(@NonNull Typeface typeface) { public CustomTypefaceSpan(@NonNull Typeface typeface) {
this(typeface, false); this(typeface, false);
} }
public CustomTypefaceSpan(@NonNull Typeface typeface, boolean mergeStyles) { // @since $SNAPSHOT;
CustomTypefaceSpan(@NonNull Typeface typeface, boolean mergeStyles) {
this.typeface = typeface; this.typeface = typeface;
this.mergeStyles = mergeStyles; this.mergeStyles = mergeStyles;
} }