Improved font size calculation

This commit is contained in:
M66B 2020-04-22 10:50:58 +02:00
parent a8dd066fcb
commit 98d9b43c48
1 changed files with 9 additions and 1 deletions

View File

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