feat: support element fontWeight desc

This commit is contained in:
chenshenhai 2021-07-26 12:05:22 +08:00
parent 1206369874
commit be4e0efa71
4 changed files with 6 additions and 4 deletions

View file

@ -198,9 +198,9 @@ class Context implements TypeContext {
}
}
setFont(opts: { fontSize: number, fontFamily?: string, fontWeight?: string }): void {
setFont(opts: { fontSize: number, fontFamily?: string, fontWeight?: 'bold' }): void {
const strList: string[] = [];
if (opts.fontWeight) {
if (opts.fontWeight === 'bold') {
strList.push(`${opts.fontWeight}`);
}
strList.push(`${this._doSize(opts.fontSize || 12)}px`);

View file

@ -12,7 +12,8 @@ const data = {
fontSize: 20,
color: "#333333",
text: "生活就像海洋,只有意志坚强的人,才能到达彼岸。",
fontFamily: "",
fontFamily: '',
fontWeight: 'bold',
borderRadius: 20,
borderWidth: 2,
borderColor: "#bd0b64",

View file

@ -29,6 +29,7 @@ export function drawText(
ctx.setFillStyle(elem.desc.color);
ctx.setTextBaseline('top');
ctx.setFont({
fontWeight: desc.fontWeight,
fontSize: desc.fontSize,
fontFamily: desc.fontFamily
});

View file

@ -40,7 +40,7 @@ type TypeElemDescText = {
color: string;
fontSize: number;
lineHeight?: number;
// fontWeight?: string;
fontWeight?: 'bold' | '';
fontFamily?: string;
textAlign?: 'center' | 'left' | 'right';
bgColor: string;