Added text size and color actions

This commit is contained in:
M66B
2019-05-01 15:58:41 +02:00
parent 35df7935df
commit 79df5c58c8
2 changed files with 73 additions and 1 deletions

View File

@@ -630,6 +630,27 @@ public class HtmlHelper {
}
static String toHtml(Spanned spanned) {
return HtmlCompat.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
String html = HtmlCompat.toHtml(spanned, TO_HTML_PARAGRAPH_LINES_CONSECUTIVE);
// @Google: why convert size to and from in a different way?
Document doc = Jsoup.parse(html);
for (Element element : doc.select("span")) {
String style = element.attr("style");
if (style.startsWith("font-size:")) {
int colon = style.indexOf(':');
int semi = style.indexOf("em;", colon);
if (semi > colon)
try {
String hsize = style.substring(colon + 1, semi).replace(',', '.');
float size = Float.parseFloat(hsize);
element.tagName(size < 1.0f ? "small" : "big");
element.attributes().remove("style");
} catch (NumberFormatException ex) {
Log.e(ex);
}
}
}
return doc.outerHtml();
}
}