MCPcopy Create free account
hub / github.com/M66B/FairEmail / getFontSize

Method getFontSize

app/src/main/java/eu/faircode/email/HtmlHelper.java:2067–2133  ·  view source on GitHub ↗
(String value, float current)

Source from the content-addressed store, hash-verified

2065 }
2066
2067 static Float getFontSize(String value, float current) {
2068 // https://developer.mozilla.org/en-US/docs/Web/CSS/font-size
2069 if (TextUtils.isEmpty(value))
2070 return null;
2071
2072 if (value.contains("calc") ||
2073 "none".equals(value) ||
2074 "auto".equals(value) ||
2075 "unset".equals(value) ||
2076 "initial".equals(value) ||
2077 "inherit".equals(value))
2078 return null;
2079
2080 // Absolute
2081 switch (value) {
2082 case "xx-small":
2083 case "x-small":
2084 return FONT_XSMALL;
2085 case "small":
2086 return FONT_SMALL;
2087 case "medium":
2088 return 1.0f;
2089 case "large":
2090 return FONT_LARGE;
2091 case "x-large":
2092 case "xx-large":
2093 case "xxx-large":
2094 return FONT_XLARGE;
2095 }
2096
2097 // Relative
2098 switch (value) {
2099 case "smaller":
2100 return FONT_SMALL * current;
2101 case "larger":
2102 return FONT_LARGE * current;
2103 }
2104
2105 try {
2106 if (value.endsWith("%"))
2107 return Float.parseFloat(value.substring(0, value.length() - 1).trim()) / 100 * current;
2108 if (value.endsWith("rem"))
2109 return Float.parseFloat(value.substring(0, value.length() - 3).trim());
2110 if (value.endsWith("em"))
2111 return Float.parseFloat(value.substring(0, value.length() - 2).trim()) * current;
2112 if (value.endsWith("ex")) // 1 ex = 0.5 em
2113 return Float.parseFloat(value.substring(0, value.length() - 2).trim()) / 2 * current;
2114 if (value.endsWith("pt"))
2115 return Float.parseFloat(value.substring(0, value.length() - 2).trim()) / DEFAULT_FONT_SIZE_PT;
2116 if (value.endsWith("px"))
2117 return Float.parseFloat(value.substring(0, value.length() - 2).trim()) / DEFAULT_FONT_SIZE;
2118
2119 // https://www.w3.org/Style/Examples/007/units.en.html
2120 if (value.endsWith("pc")) // 6 pc = 72 pt
2121 return Float.parseFloat(value.substring(0, value.length() - 2).trim()) / 12 / DEFAULT_FONT_SIZE_PT;
2122 if (value.endsWith("cm")) // 1 inch = 2.54 cm
2123 return Float.parseFloat(value.substring(0, value.length() - 2).trim()) / 2.54f * 72 / DEFAULT_FONT_SIZE_PT;
2124 if (value.endsWith("mm")) // 1 inch = 25.4 mm

Callers 3

sanitizeMethod · 0.95
hasBorderMethod · 0.95
onCreateViewMethod · 0.95

Calls 6

iMethod · 0.95
trimMethod · 0.80
isEmptyMethod · 0.45
containsMethod · 0.45
equalsMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected