* 绘制进度文本
()
| 166 | * 绘制进度文本 |
| 167 | */ |
| 168 | private drawText() { |
| 169 | const { ctx, canvasWidth, halfCH, progress } = this |
| 170 | const { font, textFormatter, textColor } = this.options |
| 171 | |
| 172 | if (!isString(textFormatter) || !textFormatter) return |
| 173 | |
| 174 | // 替换文本模板真实值 |
| 175 | const text = textFormatter.replace(/%d/g, String(Math.floor(progress))) |
| 176 | |
| 177 | ctx.save() |
| 178 | ctx.font = font |
| 179 | |
| 180 | const textWidth = ctx.measureText(text).width |
| 181 | const x = (canvasWidth - textWidth) / 2 |
| 182 | |
| 183 | ctx.textBaseline = 'middle' |
| 184 | ctx.fillStyle = textColor |
| 185 | ctx.font = font |
| 186 | ctx.fillText(text, x, halfCH) |
| 187 | ctx.restore() |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * 计算进度值 |