Added extra small/large

pull/209/head
M66B 2 years ago
parent 126a5901a0
commit b01c121d0d

@ -446,7 +446,12 @@ public class HtmlEx {
}
if (style[j] instanceof RelativeSizeSpan) {
float sizeEm = ((RelativeSizeSpan) style[j]).getSizeChange();
out.append(String.format("<span style=\"font-size:%.2fem;\">", sizeEm));
if (sizeEm < 1)
out.append(String.format("<span style=\"font-size:%s;\">",
sizeEm < HtmlHelper.FONT_SMALL ? "x-small" : "small"));
else if (sizeEm > 1)
out.append(String.format("<span style=\"font-size:%s;\">",
sizeEm > HtmlHelper.FONT_LARGE ? "x-large" : "large"));
}
if (style[j] instanceof ForegroundColorSpan) {
int color = ((ForegroundColorSpan) style[j]).getForegroundColor();

@ -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

@ -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;

@ -7,6 +7,10 @@
android:title="@string/title_style_size">
<menu>
<group android:id="@+id/group_style_size">
<item
android:id="@+id/menu_style_size_xsmall"
android:title="@string/title_style_size_xsmall" />
<item
android:id="@+id/menu_style_size_small"
android:title="@string/title_style_size_small" />
@ -18,6 +22,10 @@
<item
android:id="@+id/menu_style_size_large"
android:title="@string/title_style_size_large" />
<item
android:id="@+id/menu_style_size_xlarge"
android:title="@string/title_style_size_xlarge" />
</group>
</menu>
</item>

@ -1412,9 +1412,11 @@
<string name="title_style_underline">Underline</string>
<string name="title_style_size">Size</string>
<string name="title_style_size_xsmall">Extra small</string>
<string name="title_style_size_small">Small</string>
<string name="title_style_size_medium">Medium</string>
<string name="title_style_size_large">Large</string>
<string name="title_style_size_xlarge">Extra large</string>
<string name="title_style_align">Align</string>
<string name="title_style_align_start">Start</string>
<string name="title_style_align_center">Center</string>

Loading…
Cancel
Save