SGraphyTextItems.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * 线条
  3. */
  4. import SGraphyItem from '../../node-templete/SGraphy/SGraphyItem'
  5. import SRect from '../../node-templete/SGraphy/types/SRect';
  6. export default class SGraphyTextItem extends SGraphyItem {
  7. /**
  8. * 构造函数
  9. *
  10. * @param X 文字的开始点X
  11. * @param Y 文字的开始点Y
  12. * @param width 文字的宽度
  13. *
  14. * @param color 文字的颜色
  15. * @param text 文字的文字
  16. */
  17. constructor(X, Y, width, color, text, falg, font, parent = null) {
  18. super(parent)
  19. this.X = X
  20. this.Y = Y
  21. this.lineWidth = width
  22. this.color = color
  23. this.font = font ? font : "6px 宋体"
  24. this.text = falg ? text + '→' : text
  25. }
  26. /**
  27. * Item对象边界区域
  28. *
  29. * @return SRect
  30. */
  31. boundingRect() {
  32. return new SRect(this.X, this.Y, 0, 0)
  33. }
  34. /**
  35. * 绘制线条
  36. *
  37. * @param canvas 画布
  38. * @param rect 绘制区域
  39. */
  40. onDraw(canvas, rect) {
  41. if (!!this.text) {
  42. canvas.font = this.font;
  43. canvas.fillStyle = this.color
  44. canvas.fillText(this.text, this.X, this.Y);
  45. }
  46. }
  47. }