Added relative image sizes

This commit is contained in:
M66B 2021-05-16 08:04:56 +02:00
parent 7c0b5a505b
commit b247745b4d
1 changed files with 8 additions and 2 deletions

View File

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