Inherit font properties form view inside spans

This commit is contained in:
vakrilov
2015-03-26 16:14:07 +02:00
parent 6841c66de8
commit 9eb66d8a46
6 changed files with 48 additions and 6 deletions

View File

@ -21,6 +21,17 @@ export class FormattedString extends observable.Observable implements definition
private _underline: number;
private _strikethrough: number;
private _fontAttributes: number;
private _parent: view.View;
get parent(): view.View {
return this._parent;
}
set parent(value: view.View) {
if (this._parent !== value) {
this._parent = value;
}
}
get fontFamily(): string {
return this._fontFamily;

View File

@ -6,6 +6,7 @@ declare module "text/formatted-string" {
import observable = require("data/observable");
import observableArray = require("data/observable-array");
import colorModule = require("color");
import view = require("ui/core/view");
/**
* A class used to create a formatted (rich text) string.
@ -66,5 +67,10 @@ declare module "text/formatted-string" {
* @param newBindingContext The value of the newly set binding context.
*/
public updateSpansBindingContext(newBindingContext: any): void
/**
* Gets the parent view of the formatted string.
*/
public parent: view.View;
}
}

View File

@ -13,18 +13,27 @@ export class Span extends spanCommon.Span {
if (realFontFamily) {
this.spanModifiers.push(new android.text.style.TypefaceSpan(realFontFamily));
}
var realFontSize = this.fontSize || (parent ? parent.fontSize : undefined);
var realFontSize = this.fontSize ||
(parent ? parent.fontSize : undefined) ||
(parent && parent.parent ? parent.parent.style.fontSize : undefined);
if (realFontSize) {
this.spanModifiers.push(new android.text.style.AbsoluteSizeSpan(realFontSize * utils.layout.getDisplayDensity()));
}
var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined);
var realForegroundColor = this.foregroundColor ||
(parent ? parent.foregroundColor : undefined) ||
(parent && parent.parent ? parent.parent.style.color : undefined);
if (realForegroundColor) {
this.spanModifiers.push(new android.text.style.ForegroundColorSpan(realForegroundColor.android));
}
var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined);
var realBackgroundColor = this.backgroundColor ||
(parent ? parent.backgroundColor : undefined) ||
(parent && parent.parent ? parent.parent.style.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)) {

View File

@ -9,7 +9,10 @@ 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);
if (realFontAttributes || realFontFamily || realFontSize) {
var font;
@ -37,20 +40,27 @@ export class Span extends spanCommon.Span {
});
}
}
var realForegroundColor = this.foregroundColor || (parent ? parent.foregroundColor : undefined);
var realForegroundColor = this.foregroundColor ||
(parent ? parent.foregroundColor : undefined) ||
(parent && parent.parent ? parent.parent.style.color : undefined);
if (realForegroundColor) {
this.spanModifiers.push({
key: NSForegroundColorAttributeName,
value: realForegroundColor.ios
});
}
var realBackgroundColor = this.backgroundColor || (parent ? parent.backgroundColor : undefined);
var realBackgroundColor = this.backgroundColor ||
(parent ? parent.backgroundColor : undefined) ||
(parent && parent.parent ? parent.parent.style.backgroundColor : undefined);
if (realBackgroundColor) {
this.spanModifiers.push({
key: NSBackgroundColorAttributeName,
value: realBackgroundColor.ios
});
}
var realUnderline = this.underline || (parent ? parent.underline : undefined);
if (realUnderline) {
this.spanModifiers.push({

View File

@ -110,6 +110,9 @@ export class Button extends view.View implements definition.Button {
}
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
if (data.newValue) {
(<formattedString.FormattedString>data.newValue).parent = this;
}
this.setFormattedTextPropertyToNative(data.newValue);
}
}

View File

@ -104,6 +104,9 @@ export class TextBase extends view.View implements definition.TextBase {
}
public _onFormattedTextPropertyChanged(data: dependencyObservable.PropertyChangeData) {
if (data.newValue) {
(<formattedString.FormattedString>data.newValue).parent = this;
}
this.setFormattedTextPropertyToNative(data.newValue);
}