mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-01 01:06:11 +00:00
Added support for SVG data URI images
This commit is contained in:
parent
7865c2317f
commit
42a17c3a3d
1 changed files with 22 additions and 0 deletions
|
@ -70,6 +70,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
|
@ -662,6 +663,27 @@ class ImageHelper {
|
|||
if (comma < 0)
|
||||
throw new IllegalArgumentException("Comma missing");
|
||||
|
||||
int colon = source.indexOf(':');
|
||||
int semi = source.indexOf(';');
|
||||
String type = null;
|
||||
if (colon > 0 && semi > colon)
|
||||
type = source.substring(colon + 1, semi);
|
||||
else if (colon > 0 && comma > colon)
|
||||
type = source.substring(colon + 1, comma);
|
||||
String enc = (semi > 0 && comma > semi ? source.substring(semi + 1, comma) : null);
|
||||
|
||||
if ("image/svg".equalsIgnoreCase(type) &&
|
||||
(enc == null || "utf8".equalsIgnoreCase(enc)))
|
||||
try {
|
||||
InputStream is = new ByteArrayInputStream(source.substring(comma + 1).getBytes(StandardCharsets.UTF_8));
|
||||
Bitmap bm = ImageHelper.renderSvg(is, Color.WHITE, 1024);
|
||||
Helper.ByteArrayInOutStream s = new Helper.ByteArrayInOutStream();
|
||||
bm.compress(Bitmap.CompressFormat.PNG, 100, s);
|
||||
return s.getInputStream();
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalArgumentException("SVG", ex);
|
||||
}
|
||||
|
||||
String base64 = source.substring(comma + 1);
|
||||
byte[] bytes = Base64.decode(base64.getBytes(), 0);
|
||||
return new ByteArrayInputStream(bytes);
|
||||
|
|
Loading…
Reference in a new issue