mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fix: ios crash when creating font descriptor
This commit is contained in:
@ -9,8 +9,8 @@ export class Span extends spanCommon.Span {
|
||||
public updateSpanModifiers(parent: formattedString.FormattedString) {
|
||||
super.updateSpanModifiers(parent);
|
||||
var realFontFamily = this.fontFamily || (parent ? parent.fontFamily : undefined);
|
||||
var realFontSize = this.fontSize ||
|
||||
(parent ? parent.fontSize : undefined) ||
|
||||
var realFontSize = this.fontSize ||
|
||||
(parent ? parent.fontSize : undefined) ||
|
||||
(parent && parent.parent ? parent.parent.style.fontSize : undefined);
|
||||
|
||||
var realFontAttributes = this.fontAttributes || (parent ? parent.fontAttributes : undefined);
|
||||
@ -25,10 +25,10 @@ export class Span extends spanCommon.Span {
|
||||
else {
|
||||
var fontDescriptor = UIFontDescriptor.new();
|
||||
var symbolicTraits;
|
||||
if (realFontAttributes & enums.FontAttributes.Bold) {
|
||||
if (realFontAttributes & enums.FontAttributes.Bold) {
|
||||
symbolicTraits |= UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitBold;
|
||||
}
|
||||
if (realFontAttributes & enums.FontAttributes.Italic) {
|
||||
if (realFontAttributes & enums.FontAttributes.Italic) {
|
||||
symbolicTraits |= UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitItalic;
|
||||
}
|
||||
font = UIFont.fontWithDescriptorSize(fontDescriptor.fontDescriptorWithSymbolicTraits(symbolicTraits), realFontSize);
|
||||
@ -41,7 +41,7 @@ export class Span extends spanCommon.Span {
|
||||
}
|
||||
}
|
||||
|
||||
var realForegroundColor = this.foregroundColor ||
|
||||
var realForegroundColor = this.foregroundColor ||
|
||||
(parent ? parent.foregroundColor : undefined) ||
|
||||
(parent && parent.parent ? parent.parent.style.color : undefined);
|
||||
if (realForegroundColor) {
|
||||
@ -51,7 +51,7 @@ export class Span extends spanCommon.Span {
|
||||
});
|
||||
}
|
||||
|
||||
var realBackgroundColor = this.backgroundColor ||
|
||||
var realBackgroundColor = this.backgroundColor ||
|
||||
(parent ? parent.backgroundColor : undefined) ||
|
||||
(parent && parent.parent ? parent.parent.style.backgroundColor : undefined);
|
||||
if (realBackgroundColor) {
|
||||
|
@ -13,20 +13,14 @@ export class Font extends common.Font {
|
||||
private _android: android.graphics.Typeface;
|
||||
get android(): android.graphics.Typeface {
|
||||
if (!this._android) {
|
||||
var style: number;
|
||||
var style: number = 0;
|
||||
|
||||
if (this.isBold) {
|
||||
if (this.isItalic) {
|
||||
style = android.graphics.Typeface.BOLD_ITALIC;
|
||||
}
|
||||
else {
|
||||
style = android.graphics.Typeface.BOLD;
|
||||
}
|
||||
style |= android.graphics.Typeface.BOLD;
|
||||
}
|
||||
else if (this.isItalic) {
|
||||
style = android.graphics.Typeface.ITALIC;
|
||||
}
|
||||
else {
|
||||
style = android.graphics.Typeface.NORMAL;
|
||||
|
||||
if (this.isItalic) {
|
||||
style |= android.graphics.Typeface.ITALIC;
|
||||
}
|
||||
|
||||
var typeFace = this.getTypeFace(this.fontFamily);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import enums = require("ui/enums");
|
||||
import common = require("ui/styling/font-common");
|
||||
import utils = require("utils/utils");
|
||||
|
||||
var DEFAULT_SERIF = "Times New Roman";
|
||||
var DEFAULT_SANS_SERIF = "Helvetica";
|
||||
@ -12,21 +13,24 @@ export class Font extends common.Font {
|
||||
get ios(): UIFontDescriptor {
|
||||
if (!this._ios) {
|
||||
var fontFamily = this.getFontFamilyRespectingGenericFonts(this.fontFamily);
|
||||
this._ios = UIFontDescriptor.fontDescriptorWithNameSize(fontFamily, 0);
|
||||
|
||||
var symbolicTraits: number = 0;
|
||||
if (this.isBold) {
|
||||
if (this.isItalic) {
|
||||
this._ios = this._ios.fontDescriptorWithSymbolicTraits(
|
||||
UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitItalic |
|
||||
UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitBold);
|
||||
}
|
||||
else {
|
||||
this._ios = this._ios.fontDescriptorWithSymbolicTraits(
|
||||
UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitBold);
|
||||
symbolicTraits |= UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitBold;
|
||||
}
|
||||
if (this.isItalic) {
|
||||
symbolicTraits |= UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitItalic;
|
||||
}
|
||||
|
||||
if (fontFamily) {
|
||||
this._ios = UIFontDescriptor.fontDescriptorWithNameSize(fontFamily, 0);
|
||||
if (symbolicTraits) {
|
||||
this._ios = this._ios.fontDescriptorWithSymbolicTraits(symbolicTraits);
|
||||
}
|
||||
}
|
||||
else if (this.isItalic) {
|
||||
this._ios = this._ios.fontDescriptorWithSymbolicTraits(
|
||||
UIFontDescriptorSymbolicTraits.UIFontDescriptorTraitItalic);
|
||||
|
||||
if(!this._ios) {
|
||||
this._ios = UIFontDescriptor.new().fontDescriptorWithSymbolicTraits(symbolicTraits);
|
||||
}
|
||||
}
|
||||
return this._ios;
|
||||
|
@ -39,7 +39,7 @@ export module ios {
|
||||
export function nsArrayToJSArray(a: any): string[] {
|
||||
var arr = [];
|
||||
if ("undefined" !== typeof a) {
|
||||
for (var i = 0; i < a.count(); i++) {
|
||||
for (var i = 0; i < a.count; i++) {
|
||||
arr.push(a.objectAtIndex(i));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user