可以给font设置属性font-weight,参考文档中的font:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-canvasrenderingcontext2d-V5\#属性demo:// xxx.ets @Entry @Component struct Fonts { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) .width('100%') .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ this.context.font = '30vp bold sans-serif' this.context.fillText("Hello Word", 20, 100) this.context.font = '30vp sans-serif' this.context.fillText("Hello Word", 20, 300) }) } .width('100%') .height('100%') } }
可以给font设置属性font-weight,参考文档中的font:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-canvasrenderingcontext2d-V5\#属性
demo: