Support data URI images with filenames

master
M66B 1 week ago
parent 3da2792d1a
commit 7a16d86224

@ -655,7 +655,7 @@ class ImageHelper {
} }
static ByteArrayInputStream getDataUriStream(String source) { static ByteArrayInputStream getDataUriStream(String source) {
// "<img src=\"data:image/png;base64,iVBORw0KGgoAAA" + // "<img src=\"data:image/png;filename=dot.png;base64,iVBORw0KGgoAAA" +
// "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" + // "ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
// "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" + // "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
// "5ErkJggg==\" alt=\"Red dot\" />"; // "5ErkJggg==\" alt=\"Red dot\" />";
@ -667,19 +667,21 @@ class ImageHelper {
try { try {
// data:[<mediatype>][;base64],<data> // data:[<mediatype>][;base64],<data>
int comma = source.indexOf(','); int comma = source.indexOf(',');
int colon = source.indexOf(':');
int semi = source.indexOf(';');
if (comma < 0) if (comma < 0)
throw new IllegalArgumentException("Comma missing"); throw new IllegalArgumentException("Comma missing");
String header = source.substring(0, comma);
int colon = header.indexOf(':');
int fsemi = header.indexOf(';');
int lsemi = header.lastIndexOf(';');
String type = null; String type = null;
if (colon > 0 && semi > colon) if (colon > 0 && fsemi > colon)
type = source.substring(colon + 1, semi).trim(); type = source.substring(colon + 1, fsemi).trim();
else if (colon > 0 && comma > colon) else if (colon > 0)
type = source.substring(colon + 1, comma).trim(); type = source.substring(colon + 1, comma).trim();
String enc = (semi > 0 && comma > semi ? source.substring(semi + 1, comma).trim() : null); String enc = (lsemi > 0 ? source.substring(lsemi + 1, comma).trim() : null);
if ("image/svg".equalsIgnoreCase(type) && if ("image/svg".equalsIgnoreCase(type) &&
(TextUtils.isEmpty(enc) /* ASCII */ || "utf8".equalsIgnoreCase(enc))) { (TextUtils.isEmpty(enc) /* ASCII */ || "utf8".equalsIgnoreCase(enc))) {

Loading…
Cancel
Save