ImageSizeResolver change (accept async-drawable)
This commit is contained in:
parent
4fec46fb4d
commit
213f5cf281
@ -11,3 +11,5 @@
|
|||||||
* TagHandler now has `supportedTags()` method
|
* TagHandler now has `supportedTags()` method
|
||||||
* html is moved completely to html-plugin
|
* html is moved completely to html-plugin
|
||||||
* OnTextAddedListener
|
* OnTextAddedListener
|
||||||
|
* ImageSizeResolver signature change (accept AsyncDrawable)
|
||||||
|
* JLatexMathPlugin builder has vertical & horizontal padding
|
@ -53,7 +53,7 @@ public class AsyncDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 3.1.0-SNAPSHOT
|
* @since 4.0.0-SNAPSHOT
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public ImageSize getImageSize() {
|
public ImageSize getImageSize() {
|
||||||
@ -61,7 +61,7 @@ public class AsyncDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 3.1.0-SNAPSHOT
|
* @since 4.0.0-SNAPSHOT
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public ImageSizeResolver getImageSizeResolver() {
|
public ImageSizeResolver getImageSizeResolver() {
|
||||||
@ -69,7 +69,7 @@ public class AsyncDrawable extends Drawable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 3.1.0-SNAPSHOT
|
* @since 4.0.0-SNAPSHOT
|
||||||
*/
|
*/
|
||||||
public boolean hasKnownDimentions() {
|
public boolean hasKnownDimentions() {
|
||||||
return canvasWidth > 0;
|
return canvasWidth > 0;
|
||||||
@ -77,7 +77,7 @@ public class AsyncDrawable extends Drawable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #hasKnownDimentions()
|
* @see #hasKnownDimentions()
|
||||||
* @since 3.1.0-SNAPSHOT
|
* @since 4.0.0-SNAPSHOT
|
||||||
*/
|
*/
|
||||||
public int getLastKnownCanvasWidth() {
|
public int getLastKnownCanvasWidth() {
|
||||||
return canvasWidth;
|
return canvasWidth;
|
||||||
@ -85,7 +85,7 @@ public class AsyncDrawable extends Drawable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #hasKnownDimentions()
|
* @see #hasKnownDimentions()
|
||||||
* @since 3.1.0-SNAPSHOT
|
* @since 4.0.0-SNAPSHOT
|
||||||
*/
|
*/
|
||||||
public float getLastKnowTextSize() {
|
public float getLastKnowTextSize() {
|
||||||
return textSize;
|
return textSize;
|
||||||
@ -285,13 +285,10 @@ public class AsyncDrawable extends Drawable {
|
|||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private Rect resolveBounds() {
|
private Rect resolveBounds() {
|
||||||
|
|
||||||
// @since 2.0.0 previously we were checking if image is greater than canvas width here
|
// @since 2.0.0 previously we were checking if image is greater than canvas width here
|
||||||
// but as imageSizeResolver won't be null anymore, we should transfer this logic
|
// but as imageSizeResolver won't be null anymore, we should transfer this logic
|
||||||
// there
|
// there
|
||||||
return imageSizeResolver != null
|
return imageSizeResolver.resolveImageSize(this);
|
||||||
? imageSizeResolver.resolveImageSize(imageSize, result.getBounds(), canvasWidth, textSize)
|
|
||||||
: result.getBounds();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,7 +3,6 @@ package io.noties.markwon.image;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 1.0.1
|
* @since 1.0.1
|
||||||
@ -12,19 +11,8 @@ import androidx.annotation.Nullable;
|
|||||||
public abstract class ImageSizeResolver {
|
public abstract class ImageSizeResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We do not expose canvas height deliberately. As we cannot rely on this value very much
|
* @since 4.0.0-SNAPSHOT
|
||||||
*
|
|
||||||
* @param imageSize {@link ImageSize} parsed from HTML
|
|
||||||
* @param imageBounds original image bounds
|
|
||||||
* @param canvasWidth width of the canvas
|
|
||||||
* @param textSize current font size
|
|
||||||
* @return resolved image bounds
|
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract Rect resolveImageSize(
|
public abstract Rect resolveImageSize(@NonNull AsyncDrawable drawable);
|
||||||
@Nullable ImageSize imageSize,
|
|
||||||
@NonNull Rect imageBounds,
|
|
||||||
int canvasWidth,
|
|
||||||
float textSize
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,16 @@ public class ImageSizeResolverDef extends ImageSizeResolver {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Rect resolveImageSize(
|
public Rect resolveImageSize(@NonNull AsyncDrawable drawable) {
|
||||||
|
return resolveImageSize(
|
||||||
|
drawable.getImageSize(),
|
||||||
|
drawable.getResult().getBounds(),
|
||||||
|
drawable.getLastKnownCanvasWidth(),
|
||||||
|
drawable.getLastKnowTextSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected Rect resolveImageSize(
|
||||||
@Nullable ImageSize imageSize,
|
@Nullable ImageSize imageSize,
|
||||||
@NonNull Rect imageBounds,
|
@NonNull Rect imageBounds,
|
||||||
int canvasWidth,
|
int canvasWidth,
|
||||||
|
@ -27,7 +27,6 @@ import io.noties.markwon.image.AsyncDrawable;
|
|||||||
import io.noties.markwon.image.AsyncDrawableLoader;
|
import io.noties.markwon.image.AsyncDrawableLoader;
|
||||||
import io.noties.markwon.image.AsyncDrawableScheduler;
|
import io.noties.markwon.image.AsyncDrawableScheduler;
|
||||||
import io.noties.markwon.image.AsyncDrawableSpan;
|
import io.noties.markwon.image.AsyncDrawableSpan;
|
||||||
import io.noties.markwon.image.ImageSize;
|
|
||||||
import io.noties.markwon.image.ImageSizeResolver;
|
import io.noties.markwon.image.ImageSizeResolver;
|
||||||
import ru.noties.jlatexmath.JLatexMathDrawable;
|
import ru.noties.jlatexmath.JLatexMathDrawable;
|
||||||
|
|
||||||
@ -82,7 +81,11 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
|||||||
|
|
||||||
private final boolean fitCanvas;
|
private final boolean fitCanvas;
|
||||||
|
|
||||||
private final int padding;
|
// @since 4.0.0-SNAPSHOT
|
||||||
|
private final int paddingHorizontal;
|
||||||
|
// @since 4.0.0-SNAPSHOT
|
||||||
|
|
||||||
|
private final int paddingVertical;
|
||||||
|
|
||||||
// @since 4.0.0-SNAPSHOT
|
// @since 4.0.0-SNAPSHOT
|
||||||
private final ExecutorService executorService;
|
private final ExecutorService executorService;
|
||||||
@ -92,7 +95,8 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
|||||||
this.backgroundProvider = builder.backgroundProvider;
|
this.backgroundProvider = builder.backgroundProvider;
|
||||||
this.align = builder.align;
|
this.align = builder.align;
|
||||||
this.fitCanvas = builder.fitCanvas;
|
this.fitCanvas = builder.fitCanvas;
|
||||||
this.padding = builder.padding;
|
this.paddingHorizontal = builder.paddingHorizontal;
|
||||||
|
this.paddingVertical = builder.paddingVertical;
|
||||||
|
|
||||||
// @since 4.0.0-SNAPSHOT
|
// @since 4.0.0-SNAPSHOT
|
||||||
ExecutorService executorService = builder.executorService;
|
ExecutorService executorService = builder.executorService;
|
||||||
@ -168,7 +172,11 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
|||||||
|
|
||||||
private boolean fitCanvas = true;
|
private boolean fitCanvas = true;
|
||||||
|
|
||||||
private int padding;
|
// @since 4.0.0-SNAPSHOT
|
||||||
|
private int paddingHorizontal;
|
||||||
|
|
||||||
|
// @since 4.0.0-SNAPSHOT
|
||||||
|
private int paddingVertical;
|
||||||
|
|
||||||
// @since 4.0.0-SNAPSHOT
|
// @since 4.0.0-SNAPSHOT
|
||||||
private ExecutorService executorService;
|
private ExecutorService executorService;
|
||||||
@ -197,7 +205,18 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Builder padding(@Px int padding) {
|
public Builder padding(@Px int padding) {
|
||||||
this.padding = padding;
|
this.paddingHorizontal = padding;
|
||||||
|
this.paddingVertical = padding;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 4.0.0-SNAPSHOT
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public Builder builder(@Px int paddingHorizontal, @Px int paddingVertical) {
|
||||||
|
this.paddingHorizontal = paddingHorizontal;
|
||||||
|
this.paddingVertical = paddingVertical;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +270,11 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
|||||||
.background(config.backgroundProvider.provide())
|
.background(config.backgroundProvider.provide())
|
||||||
.align(config.align)
|
.align(config.align)
|
||||||
.fitCanvas(config.fitCanvas)
|
.fitCanvas(config.fitCanvas)
|
||||||
.padding(config.padding)
|
.padding(
|
||||||
|
config.paddingHorizontal,
|
||||||
|
config.paddingVertical,
|
||||||
|
config.paddingHorizontal,
|
||||||
|
config.paddingVertical)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// we must post to handler, but also have a way to identify the drawable
|
// we must post to handler, but also have a way to identify the drawable
|
||||||
@ -305,11 +328,10 @@ public class JLatexMathPlugin extends AbstractMarkwonPlugin {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Rect resolveImageSize(
|
public Rect resolveImageSize(@NonNull AsyncDrawable drawable) {
|
||||||
@Nullable ImageSize imageSize,
|
|
||||||
@NonNull Rect imageBounds,
|
final Rect imageBounds = drawable.getResult().getBounds();
|
||||||
int canvasWidth,
|
final int canvasWidth = drawable.getLastKnownCanvasWidth();
|
||||||
float textSize) {
|
|
||||||
|
|
||||||
if (fitCanvas
|
if (fitCanvas
|
||||||
&& imageBounds.width() < canvasWidth) {
|
&& imageBounds.width() < canvasWidth) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user