Files
NativeScript/text/span.android.ts
2015-03-03 10:34:40 +02:00

49 lines
2.6 KiB
TypeScript

import spanCommon = require("text/span-common");
import enums = require("ui/enums");
import formattedString = require("text/formatted-string");
import utils = require("utils/utils");
declare var exports;
require("utils/module-merge").merge(spanCommon, exports);
export class Span extends spanCommon.Span {
public updateSpanModifiers(parent: formattedString.FormattedString) {
super.updateSpanModifiers(parent);
var realFontFamily = this.fontFamily || (parent ? parent.fontFamily : undefined);
if (realFontFamily) {
this.spanModifiers.push(new android.text.style.TypefaceSpan(realFontFamily));
}
var realFontSize = this.fontSize || (parent ? parent.fontSize : undefined);
if (realFontSize) {
this.spanModifiers.push(new android.text.style.AbsoluteSizeSpan(realFontSize * utils.layout.getDisplayDensity()));
}
var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined);
if (realForegroundColor) {
this.spanModifiers.push(new android.text.style.ForegroundColorSpan(realForegroundColor.android));
}
var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined);
if (realBackgroundColor) {
this.spanModifiers.push(new android.text.style.BackgroundColorSpan(realBackgroundColor.android));
}
var realFontAttributes = this.fontAttributes || (parent ? parent.fontAttributes : undefined);
if (realFontAttributes) {
if ((realFontAttributes & enums.FontAttributes.Bold) && (realFontAttributes & enums.FontAttributes.Italic)) {
this.spanModifiers.push(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD_ITALIC));
}
else if (realFontAttributes & enums.FontAttributes.Bold) {
this.spanModifiers.push(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD));
}
else if (realFontAttributes & enums.FontAttributes.Italic) {
this.spanModifiers.push(new android.text.style.StyleSpan(android.graphics.Typeface.ITALIC));
}
}
var realUnderline = this.underline || (parent ? parent.underline : undefined);
if (realUnderline) {
this.spanModifiers.push(new android.text.style.UnderlineSpan());
}
var realStrikethrough = this.strikethrough || (parent ? parent.strikethrough : undefined);
if (realStrikethrough) {
this.spanModifiers.push(new android.text.style.StrikethroughSpan());
}
}
}