From b01c121d0d2e06b98409088766af308ac4a4840e Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 27 Aug 2022 17:48:36 +0200 Subject: [PATCH] Added extra small/large --- .../main/java/eu/faircode/email/HtmlEx.java | 7 ++++- .../java/eu/faircode/email/HtmlHelper.java | 27 ++++++++---------- .../java/eu/faircode/email/StyleHelper.java | 28 ++++++++++++++++--- app/src/main/res/menu/popup_style.xml | 8 ++++++ app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlEx.java b/app/src/main/java/eu/faircode/email/HtmlEx.java index c94a0db524..e5f47a91c1 100644 --- a/app/src/main/java/eu/faircode/email/HtmlEx.java +++ b/app/src/main/java/eu/faircode/email/HtmlEx.java @@ -446,7 +446,12 @@ public class HtmlEx { } if (style[j] instanceof RelativeSizeSpan) { float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange(); - out.append(String.format("", sizeEm)); + if (sizeEm < 1) + out.append(String.format("", + sizeEm < HtmlHelper.FONT_SMALL ? "x-small" : "small")); + else if (sizeEm > 1) + out.append(String.format("", + sizeEm > HtmlHelper.FONT_LARGE ? "x-large" : "large")); } if (style[j] instanceof ForegroundColorSpan) { int color = ((ForegroundColorSpan) style[j]).getForegroundColor(); diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index f43c3e2a1e..e14d025160 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -132,8 +132,12 @@ import javax.mail.internet.MimeUtility; public class HtmlHelper { static final int PREVIEW_SIZE = 500; // characters - static final float FONT_SMALL = 0.8f; - static final float FONT_LARGE = 1.25f; + // https://drafts.csswg.org/css-fonts/#absolute-size-mapping + static final float FONT_XSMALL = 0.6f; // 10px=0.625 + static final float FONT_SMALL = 0.8f; // 13px=0.8125 + // 16 px + static final float FONT_LARGE = 1.25f; // 20px=1.2 + static final float FONT_XLARGE = 1.50f; // 24px=1.5 static final int MAX_FULL_TEXT_SIZE = 1024 * 1024; // characters static final int MAX_SHARE_TEXT_SIZE = 50 * 1024; // characters @@ -848,9 +852,9 @@ public class HtmlHelper { } else { if (!view) { if (fsize < 1) - fsize = FONT_SMALL; + fsize = (fsize < FONT_SMALL ? FONT_XSMALL : FONT_SMALL); else if (fsize > 1) - fsize = FONT_LARGE; + fsize = (fsize > FONT_LARGE ? FONT_XLARGE : FONT_LARGE); } element.attr("x-font-size", Float.toString(fsize)); element.attr("x-font-size-rel", Float.toString(fsize / current)); @@ -1919,15 +1923,17 @@ public class HtmlHelper { switch (value) { case "xx-small": case "x-small": + return FONT_XSMALL; case "small": return FONT_SMALL; case "medium": return 1.0f; case "large": + return FONT_LARGE; case "x-large": case "xx-large": case "xxx-large": - return FONT_LARGE; + return FONT_XLARGE; } // Relative @@ -3780,17 +3786,6 @@ public class HtmlHelper { String value = param.substring(semi + 1).trim(); switch (key) { - case "font-size": - // @Google: why convert size to and from in a different way? - String v = value.replace(',', '.'); - Float size = getFontSize(v, 1.0f); - if (size != null) { - if (size < 1.0f) - span.tagName("small"); - else if (size > 1.0f) - span.tagName("big"); - } - break; case "text-align": sb.append(" display:block;"); // fall through diff --git a/app/src/main/java/eu/faircode/email/StyleHelper.java b/app/src/main/java/eu/faircode/email/StyleHelper.java index 1a588289ed..113e83d5c5 100644 --- a/app/src/main/java/eu/faircode/email/StyleHelper.java +++ b/app/src/main/java/eu/faircode/email/StyleHelper.java @@ -163,9 +163,25 @@ public class StyleHelper { { SubMenu smenu = popupMenu.getMenu().findItem(R.id.menu_style_size).getSubMenu(); smenu.clear(); - int[] ids = new int[]{R.id.menu_style_size_small, R.id.menu_style_size_medium, R.id.menu_style_size_large}; - int[] titles = new int[]{R.string.title_style_size_small, R.string.title_style_size_medium, R.string.title_style_size_large}; - float[] sizes = new float[]{HtmlHelper.FONT_SMALL, 1.0f, HtmlHelper.FONT_LARGE}; + int[] ids = new int[]{ + R.id.menu_style_size_xsmall, + R.id.menu_style_size_small, + R.id.menu_style_size_medium, + R.id.menu_style_size_large, + R.id.menu_style_size_xlarge + }; + int[] titles = new int[]{ + R.string.title_style_size_xsmall, + R.string.title_style_size_small, + R.string.title_style_size_medium, + R.string.title_style_size_large, + R.string.title_style_size_xlarge}; + float[] sizes = new float[]{ + HtmlHelper.FONT_XSMALL, + HtmlHelper.FONT_SMALL, + 1.0f, + HtmlHelper.FONT_LARGE, + HtmlHelper.FONT_XLARGE}; for (int i = 0; i < ids.length; i++) { SpannableStringBuilder ssb = new SpannableStringBuilderEx(context.getString(titles[i])); ssb.setSpan(new RelativeSizeSpan(sizes[i]), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); @@ -252,10 +268,14 @@ public class StyleHelper { Log.breadcrumb("style", "action", "size"); Float size; - if (item.getItemId() == R.id.menu_style_size_small) + if (item.getItemId() == R.id.menu_style_size_xsmall) + size = HtmlHelper.FONT_XSMALL; + else if (item.getItemId() == R.id.menu_style_size_small) size = HtmlHelper.FONT_SMALL; else if (item.getItemId() == R.id.menu_style_size_large) size = HtmlHelper.FONT_LARGE; + else if (item.getItemId() == R.id.menu_style_size_xlarge) + size = HtmlHelper.FONT_XLARGE; else size = null; diff --git a/app/src/main/res/menu/popup_style.xml b/app/src/main/res/menu/popup_style.xml index 19c34c442b..0fa1ebecc6 100644 --- a/app/src/main/res/menu/popup_style.xml +++ b/app/src/main/res/menu/popup_style.xml @@ -7,6 +7,10 @@ android:title="@string/title_style_size"> + + @@ -18,6 +22,10 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2e56a5f1f2..21d90c976a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1412,9 +1412,11 @@ Underline Size + Extra small Small Medium Large + Extra large Align Start Center