mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-26 01:36:55 +00:00
Font weight improvements
This commit is contained in:
parent
97527274c9
commit
dbd88712b7
1 changed files with 34 additions and 13 deletions
|
@ -57,6 +57,7 @@ import android.text.style.TypefaceSpan;
|
||||||
import android.text.style.URLSpan;
|
import android.text.style.URLSpan;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
import android.util.Pair;
|
||||||
import android.util.Patterns;
|
import android.util.Patterns;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
@ -114,6 +115,7 @@ import java.text.ParsePosition;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -873,17 +875,8 @@ public class HtmlHelper {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "font-weight":
|
case "font-weight":
|
||||||
if (element.parent() != null) {
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight
|
||||||
Integer fweight = getFontWeight(value);
|
sb.append(key).append(":").append(value).append(";");
|
||||||
if (fweight != null && fweight >= 600) {
|
|
||||||
Element strong = new Element("strong");
|
|
||||||
for (Node child : new ArrayList<>(element.childNodes())) {
|
|
||||||
child.remove();
|
|
||||||
strong.appendChild(child);
|
|
||||||
}
|
|
||||||
element.appendChild(strong);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "font-family":
|
case "font-family":
|
||||||
|
@ -1889,6 +1882,8 @@ public class HtmlHelper {
|
||||||
return 300;
|
return 300;
|
||||||
case "normal":
|
case "normal":
|
||||||
case "regular":
|
case "regular":
|
||||||
|
case "unset":
|
||||||
|
case "initial":
|
||||||
return 400;
|
return 400;
|
||||||
case "bolder":
|
case "bolder":
|
||||||
case "strong":
|
case "strong":
|
||||||
|
@ -1899,8 +1894,6 @@ public class HtmlHelper {
|
||||||
return 900;
|
return 900;
|
||||||
case "none":
|
case "none":
|
||||||
case "auto":
|
case "auto":
|
||||||
case "unset":
|
|
||||||
case "initial":
|
|
||||||
case "inherit":
|
case "inherit":
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -3326,6 +3319,34 @@ public class HtmlHelper {
|
||||||
Log.i(ex);
|
Log.i(ex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "font-weight":
|
||||||
|
Integer fweight = getFontWeight(value);
|
||||||
|
if (fweight != null)
|
||||||
|
if (fweight >= 600) {
|
||||||
|
List<StyleSpan> spans = new ArrayList<>(Arrays.asList(ssb.getSpans(start, ssb.length(), StyleSpan.class)));
|
||||||
|
if (spans != null) {
|
||||||
|
Collections.sort(spans, new Comparator<StyleSpan>() {
|
||||||
|
@Override
|
||||||
|
public int compare(StyleSpan s1, StyleSpan s2) {
|
||||||
|
int s = Integer.compare(ssb.getSpanStart(s1), ssb.getSpanStart(s2));
|
||||||
|
if (s != 0)
|
||||||
|
return s;
|
||||||
|
return -Integer.compare(ssb.getSpanEnd(s1), ssb.getSpanEnd(s2));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (StyleSpan span : spans) {
|
||||||
|
int s = ssb.getSpanStart(span);
|
||||||
|
if (s > start && span.getStyle() == Typeface.NORMAL) {
|
||||||
|
setSpan(ssb, new StyleSpan(Typeface.BOLD), start, s);
|
||||||
|
start = ssb.getSpanEnd(span);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start < ssb.length())
|
||||||
|
setSpan(ssb, new StyleSpan(Typeface.BOLD), start, ssb.length());
|
||||||
|
} else
|
||||||
|
setSpan(ssb, new StyleSpan(Typeface.NORMAL), start, ssb.length());
|
||||||
|
break;
|
||||||
case "font-family":
|
case "font-family":
|
||||||
if ("wingdings".equalsIgnoreCase(value)) {
|
if ("wingdings".equalsIgnoreCase(value)) {
|
||||||
if (wingdings == null)
|
if (wingdings == null)
|
||||||
|
|
Loading…
Reference in a new issue