import Shape from './shape'; import { TextOptions } from '../models/painter'; class Text extends Shape { draw(): void { const { text = '', x = 0, y = 0, textBaseline = 'middle', fontSize = 12, fontFamily = 'PingFang SC', fontWeight = 'normal', fontStyle = '#000000', textAlign = 'start', rotate = 0, } = this.config as TextOptions; const { ctx } = this; ctx.save(); ctx.beginPath(); ctx.fillStyle = fontStyle || '#232A35'; ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`; ctx.textBaseline = textBaseline; ctx.textAlign = textAlign; if (rotate) { ctx.translate(x, y); ctx.rotate(rotate); ctx.fillText( text, 0, 0, ); } else { ctx.fillText( text, x, y, ); } ctx.closePath(); ctx.restore(); } } export default Text;