From 98d9b43c486154713823ac0aa890edc7e9c36617 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 22 Apr 2020 10:50:58 +0200 Subject: [PATCH] Improved font size calculation --- app/src/main/java/eu/faircode/email/HtmlHelper.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 248612f9a7..13ec8133a9 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1049,9 +1049,15 @@ public class HtmlHelper { } private static Float getFontSize(String value, Integer current) { + // https://developer.mozilla.org/en-US/docs/Web/CSS/font-size if (TextUtils.isEmpty(value)) return null; + if (value.contains("calc") || + "auto".equals(value) || + "inherit".equals(value)) + return null; + float _current = (current == null ? 1.0f : current / (float) DEFAULT_FONT_SIZE); // Absolute @@ -1084,8 +1090,10 @@ public class HtmlHelper { return Float.parseFloat(value.substring(0, value.length() - 2).trim()) * _current; if (value.endsWith("rem")) return Float.parseFloat(value.substring(0, value.length() - 3).trim()); - if (value.endsWith("px")) + if (value.endsWith("px") || value.endsWith("pt")) return Integer.parseInt(value.substring(0, value.length() - 2).trim()) / (float) DEFAULT_FONT_SIZE; + if (value.endsWith("cm") || value.endsWith("in")) + return null; return Integer.parseInt(value.trim()) / (float) DEFAULT_FONT_SIZE; } catch (NumberFormatException ex) { Log.w(ex);