add android icon font support

This commit is contained in:
王劲鹏 2020-03-13 14:22:46 +08:00 committed by osborn
parent 4359eec700
commit 73c0a5e7ab
10 changed files with 50 additions and 2 deletions

View File

@ -20,11 +20,11 @@ import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.widget.TextView; import android.widget.TextView;
import com.github.pengfeizhou.jscore.JSValue;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
import com.github.pengfeizhou.jscore.JSValue;
/** /**
* @Description: widget * @Description: widget
* @Author: pengfei.zhou * @Author: pengfei.zhou
@ -76,6 +76,17 @@ public class TextNode extends ViewNode<TextView> {
} else { } else {
view.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); view.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
} }
break;
case "font":
String font = prop.asString().toString();
if (font.endsWith(".ttf")) {
Typeface iconFont = Typeface.createFromAsset(getContext().getAssets(), font);
view.setTypeface(iconFont);
} else {
Typeface iconFont = Typeface.createFromAsset(getContext().getAssets(), font + ".ttf");
view.setTypeface(iconFont);
}
break; break;
default: default:
super.blend(view, name, prop); super.blend(view, name, prop);

View File

@ -45,6 +45,15 @@ class TextDemo extends Panel {
textSize: 30, textSize: 30,
fontStyle: "bold_italic" fontStyle: "bold_italic"
}), }),
text({
text: "This is Icon Font text \ue631",
font: 'iconfont/iconfont.ttf'
}),
text({
text: "This is Icon Font text \ue631",
textSize: 30,
font: 'iconfont/iconfont.ttf'
}),
], ],
{ {
space: 10, space: 10,

View File

@ -1617,6 +1617,10 @@ var Text = /** @class */ (function (_super) {
Property, Property,
__metadata$3("design:type", String) __metadata$3("design:type", String)
], Text.prototype, "fontStyle", void 0); ], Text.prototype, "fontStyle", void 0);
__decorate$3([
Property,
__metadata$3("design:type", String)
], Text.prototype, "font", void 0);
return Text; return Text;
}(View)); }(View));
function text(config) { function text(config) {

View File

@ -1201,6 +1201,10 @@ __decorate$3([
Property, Property,
__metadata$3("design:type", String) __metadata$3("design:type", String)
], Text.prototype, "fontStyle", void 0); ], Text.prototype, "fontStyle", void 0);
__decorate$3([
Property,
__metadata$3("design:type", String)
], Text.prototype, "font", void 0);
function text(config) { function text(config) {
const ret = new Text; const ret = new Text;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

View File

@ -2660,6 +2660,10 @@ __decorate$3([
Property, Property,
__metadata$3("design:type", String) __metadata$3("design:type", String)
], Text.prototype, "fontStyle", void 0); ], Text.prototype, "fontStyle", void 0);
__decorate$3([
Property,
__metadata$3("design:type", String)
], Text.prototype, "font", void 0);
function text(config) { function text(config) {
const ret = new Text; const ret = new Text;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

2
doric-js/index.d.ts vendored
View File

@ -462,6 +462,7 @@ declare module 'doric/lib/src/widget/text' {
maxLines?: number; maxLines?: number;
textAlignment?: Gravity; textAlignment?: Gravity;
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"; fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
font?: string;
} }
export class Text extends View implements IText { export class Text extends View implements IText {
text?: string; text?: string;
@ -470,6 +471,7 @@ declare module 'doric/lib/src/widget/text' {
maxLines?: number; maxLines?: number;
textAlignment?: Gravity; textAlignment?: Gravity;
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"; fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
font?: string;
} }
export function text(config: IText): Text; export function text(config: IText): Text;
} }

View File

@ -8,6 +8,7 @@ export interface IText extends IView {
maxLines?: number; maxLines?: number;
textAlignment?: Gravity; textAlignment?: Gravity;
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"; fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
font?: string;
} }
export declare class Text extends View implements IText { export declare class Text extends View implements IText {
text?: string; text?: string;
@ -16,5 +17,6 @@ export declare class Text extends View implements IText {
maxLines?: number; maxLines?: number;
textAlignment?: Gravity; textAlignment?: Gravity;
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"; fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
font?: string;
} }
export declare function text(config: IText): Text; export declare function text(config: IText): Text;

View File

@ -52,6 +52,10 @@ __decorate([
Property, Property,
__metadata("design:type", String) __metadata("design:type", String)
], Text.prototype, "fontStyle", void 0); ], Text.prototype, "fontStyle", void 0);
__decorate([
Property,
__metadata("design:type", String)
], Text.prototype, "font", void 0);
export function text(config) { export function text(config) {
const ret = new Text; const ret = new Text;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();

View File

@ -25,6 +25,7 @@ export interface IText extends IView {
maxLines?: number maxLines?: number
textAlignment?: Gravity textAlignment?: Gravity
fontStyle?: "normal" | "bold" | "italic" | "bold_italic" fontStyle?: "normal" | "bold" | "italic" | "bold_italic"
font?: string
} }
export class Text extends View implements IText { export class Text extends View implements IText {
@ -45,6 +46,9 @@ export class Text extends View implements IText {
@Property @Property
fontStyle?: "normal" | "bold" | "italic" | "bold_italic" fontStyle?: "normal" | "bold" | "italic" | "bold_italic"
@Property
font?: string
} }
export function text(config: IText) { export function text(config: IText) {

View File

@ -2718,6 +2718,10 @@ __decorate$3([
Property, Property,
__metadata$3("design:type", String) __metadata$3("design:type", String)
], Text.prototype, "fontStyle", void 0); ], Text.prototype, "fontStyle", void 0);
__decorate$3([
Property,
__metadata$3("design:type", String)
], Text.prototype, "font", void 0);
function text(config) { function text(config) {
const ret = new Text; const ret = new Text;
ret.layoutConfig = layoutConfig().fit(); ret.layoutConfig = layoutConfig().fit();