- 使用CSS样式来定义

context.font = [CSS font property]
context.font = [font-style font-variant font-weight font-size font-family ]

属性名:font-style/font-variant/font-weight/font-size/font-family

只有font-size和font-family是必须的
如果指定的字体找不到会使用默认的字体
可以指定网络路径字体 @font-face{fontfamily:Scriptina;src:url('fonts/scriptina.ttf');}

--- 水平对齐方式

- textAlign属性用于判断水平对齐方式
context.textAlign = [left|right|center|*start|end]

- 修改浏览器字体排列方向
document.dir = [*|tr|rtl]

--- 垂直对齐方式

- textBaseline 指定垂直对齐方式
context.textBaseline = [top|middle|*alphabetic|bottom|hanging|ideographic]

--- 绘制文字

- 类似于绘制图形,首先fill然后stroke
context.fillText(text,x,y,maxwidth)
context.strokeText(text,x,y,maxwidth)

- 测量文字宽度
TextWidth = context.measureText(text).width

 

相关文章:

  • 2021-11-29
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-01-12
  • 2022-02-07
  • 2021-07-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2021-12-04
  • 2021-04-25
  • 2021-05-16
  • 2021-12-25
相关资源
相似解决方案