From f44ad49b978c5ffbed717ef6b17a85602be04fb8 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 6 Jun 2024 21:14:34 +0200 Subject: [PATCH] Added fail safe --- .../faircode/email/FragmentDialogPrint.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogPrint.java b/app/src/main/java/eu/faircode/email/FragmentDialogPrint.java index e8c70c654c..f21d5e9fe8 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogPrint.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogPrint.java @@ -356,33 +356,37 @@ public class FragmentDialogPrint extends FragmentDialogBase { for (EntityAttachment attachment : attachments) if (attachment.isAttachment()) { - int resid = 0; - Bitmap bm = null; - if (print_html_images) { - String extension = Helper.guessExtension(attachment.getMimeType()); - if (extension != null) - resid = context.getResources().getIdentifier("file_" + extension, "drawable", context.getPackageName()); - Drawable d = ContextCompat.getDrawable(context, resid == 0 ? R.drawable.file_bin : resid); - if (d != null) { - int h = Helper.dp2pixels(context, 12); - int w = h * d.getIntrinsicWidth() / d.getIntrinsicHeight(); - bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bm); - d.setBounds(0, 0, w, h); - d.draw(canvas); + String uri = null; + if (print_html_images) + try { + int resid = 0; + String extension = Helper.guessExtension(attachment.getMimeType()); + if (extension != null) + resid = context.getResources().getIdentifier("file_" + extension, "drawable", context.getPackageName()); + Drawable d = ContextCompat.getDrawable(context, resid == 0 ? R.drawable.file_bin : resid); + if (d != null) { + int h = Helper.dp2pixels(context, 12); + int w = h * d.getIntrinsicWidth() / d.getIntrinsicHeight(); + Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bm); + d.setBounds(0, 0, w, h); + d.draw(canvas); + + Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream(); + bm.compress(Bitmap.CompressFormat.PNG, 90, bos); + uri = ImageHelper.getDataUri(bos.getInputStream(), "image/png"); + } + } catch (Throwable ex) { + Log.e(ex); } - } Element span = document.createElement("span"); - if (bm == null) { + if (uri == null) { Element strong = document.createElement("strong"); strong.text(context.getString(R.string.title_attachment)); span.appendChild(strong); } else { Element img = document.createElement("img"); - Helper.ByteArrayInOutStream bos = new Helper.ByteArrayInOutStream(); - bm.compress(Bitmap.CompressFormat.PNG, 90, bos); - String uri = ImageHelper.getDataUri(bos.getInputStream(), "image/png"); img.attr("src", uri); img.attr("style", "vertical-align: middle; padding-top: 3px; padding-bottom: 3px;"); span.appendChild(img);