Skip to content

Commit 079ab05

Browse files
committed
fix(android): NPE fix
1 parent e88a037 commit 079ab05

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

plugin/platforms/android/java/com/nativescript/label/HtmlToSpannedConverter.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import java.util.LinkedList;
3737
import java.util.List;
3838

39+
import android.util.Log;
40+
3941
class HtmlToSpannedConverter extends DefaultHandler {
4042
private final String TAG = "HtmlToSpannedConverter";
4143

@@ -479,7 +481,7 @@ private Object getStyleSpan(Attributes attr) {
479481
needsFontSpan = true;
480482
break;
481483
case "font-size":
482-
fontSize = Float.parseFloat(value.replace("px", "").replace("pt", ""));
484+
fontSize = Float.parseFloat(value.replace("px", "").replace("pt", "").trim()) * density;
483485
needsFontSpan = true;
484486
break;
485487
case "font-weight":
@@ -504,16 +506,16 @@ private Object getStyleSpan(Attributes attr) {
504506

505507
}
506508
if (needsFontSpan) {
507-
boolean isBold = fontWeight != null && fontWeight.equals("bold") || fontWeight.equals("700");
509+
boolean isBold = fontWeight != null && (fontWeight.equals("bold") || fontWeight.equals("700"));
508510
if (fontFamily != null) {
509511
result.add(new CustomTypefaceSpan(fontFamily, Font.createTypeface(this.context, this.fontFolder, fontFamily, fontWeight, isBold, false)));
510512
} else {
511-
if (fontWeight.equals("bold") || fontWeight.equals("700")) {
513+
if (isBold) {
512514
result.add(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD));
513515
}
514516
}
515517
if (fontSize != 0) {
516-
result.add(new AbsoluteSizeSpan(Math.round(fontSize * density)));
518+
result.add(new AbsoluteSizeSpan(Math.round(fontSize)));
517519
}
518520
if (color != null) {
519521
result.add(new ForegroundColorSpan(Color.parseColor(color)));

0 commit comments

Comments
 (0)