Skip to content

Commit

Permalink
fix(android): NPE fix
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed May 28, 2020
1 parent e88a037 commit 079ab05
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.LinkedList;
import java.util.List;

import android.util.Log;

class HtmlToSpannedConverter extends DefaultHandler {
private final String TAG = "HtmlToSpannedConverter";

Expand Down Expand Up @@ -479,7 +481,7 @@ private Object getStyleSpan(Attributes attr) {
needsFontSpan = true;
break;
case "font-size":
fontSize = Float.parseFloat(value.replace("px", "").replace("pt", ""));
fontSize = Float.parseFloat(value.replace("px", "").replace("pt", "").trim()) * density;
needsFontSpan = true;
break;
case "font-weight":
Expand All @@ -504,16 +506,16 @@ private Object getStyleSpan(Attributes attr) {

}
if (needsFontSpan) {
boolean isBold = fontWeight != null && fontWeight.equals("bold") || fontWeight.equals("700");
boolean isBold = fontWeight != null && (fontWeight.equals("bold") || fontWeight.equals("700"));
if (fontFamily != null) {
result.add(new CustomTypefaceSpan(fontFamily, Font.createTypeface(this.context, this.fontFolder, fontFamily, fontWeight, isBold, false)));
} else {
if (fontWeight.equals("bold") || fontWeight.equals("700")) {
if (isBold) {
result.add(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD));
}
}
if (fontSize != 0) {
result.add(new AbsoluteSizeSpan(Math.round(fontSize * density)));
result.add(new AbsoluteSizeSpan(Math.round(fontSize)));
}
if (color != null) {
result.add(new ForegroundColorSpan(Color.parseColor(color)));
Expand Down

0 comments on commit 079ab05

Please sign in to comment.