Use image size for relative sizes

This commit is contained in:
M66B 2021-05-16 09:46:22 +02:00
parent e8df52fc8c
commit c040b8206c
1 changed files with 8 additions and 8 deletions

View File

@ -49,7 +49,6 @@ import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Patterns;
import androidx.annotation.NonNull;
@ -993,7 +992,6 @@ public class HtmlHelper {
// Images
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
DisplayMetrics dm = context.getResources().getDisplayMetrics();
for (Element img : document.select("img")) {
String alt = img.attr("alt");
String src = img.attr("src");
@ -1043,23 +1041,25 @@ public class HtmlHelper {
int width = 0;
int height = 0;
// Relative sizes (%) = use image size
String awidth = img.attr("width").replace(" ", "");
for (int i = 0; i < awidth.length(); i++)
if (Character.isDigit(awidth.charAt(i)))
width = width * 10 + (byte) awidth.charAt(i) - (byte) '0';
else
else {
width = 0;
break;
if (awidth.endsWith("%"))
width = Math.round(dm.widthPixels / dm.density * width / 100);
}
String aheight = img.attr("height").replace(" ", "");
for (int i = 0; i < aheight.length(); i++)
if (Character.isDigit(aheight.charAt(i)))
height = height * 10 + (byte) aheight.charAt(i) - (byte) '0';
else
else {
height = 0;
break;
if (aheight.endsWith("%"))
height = Math.round(dm.heightPixels / dm.density * height / 100);
}
if (width != 0 || height != 0) {
ImageHelper.AnnotatedSource a = new ImageHelper.AnnotatedSource(