FIX: Span with unknown font-family crash

This commit is contained in:
vakrilov
2017-05-10 18:42:23 +03:00
parent d482c5334c
commit 6b10e94005
3 changed files with 23 additions and 4 deletions

View File

@ -78,7 +78,7 @@ var _createButtonFunc = function (): buttonModule.Button {
// >>button-create
var button = new buttonModule.Button();
// << button-create
button.text = "Button";
button.text = "Button";
return button;
}
@ -372,3 +372,21 @@ export function test_IntegrationTest_Transform_Decoration_Spacing_WithFormattedT
TKUnit.assertEqual(view.style.letterSpacing, 1, "LetterSpacing");
});
}
// Reported in https://github.com/NativeScript/NativeScript/issues/4109
export function test_setting_formattedText_With_UnknownFont_DoesNotCrash() {
let btn = new buttonModule.Button();
btn.style.fontFamily = "_UnknownFont";
helper.buildUIAndRunTest(btn, function (views) {
TKUnit.waitUntilReady(() => { return btn.isLayoutValid; });
let span = new spanModule.Span();
span.text = "Login";
let formattedString = new formattedStringModule.FormattedString();
formattedString.spans.push(span);
btn.formattedText = formattedString;
TKUnit.waitUntilReady(() => { return btn.isLayoutValid; });
});
}

View File

@ -6,10 +6,10 @@
"nativescript": {
"id": "org.nativescript.tests",
"tns-ios": {
"version": "2.5.0"
"version": "3.0.0"
},
"tns-android": {
"version": "2.5.0"
"version": "3.0.0"
}
},
"dependencies": {

View File

@ -320,7 +320,8 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span,
const fontFamily = span.fontFamily;
if (fontFamily) {
const font = new Font(fontFamily, 0, (italic) ? "italic" : "normal", (bold) ? "bold" : "normal");
const typefaceSpan: android.text.style.TypefaceSpan = new org.nativescript.widgets.CustomTypefaceSpan(fontFamily, font.getAndroidTypeface());
const typeface = font.getAndroidTypeface() || android.graphics.Typeface.create(fontFamily, 0);
const typefaceSpan: android.text.style.TypefaceSpan = new org.nativescript.widgets.CustomTypefaceSpan(fontFamily, typeface);
ssb.setSpan(typefaceSpan, start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}