* @function LevelRenderer.Shape.prototype.drawText * @description 绘制附加文本。 * * @param {CanvasRenderingContext2D} ctx - Context2D 上下文。 * @param {string} style - 样式。 * @param {string} normalStyle - normalStyle 默认样式,用于定位文字显示。
(ctx, style, normalStyle)
| 583 | * @param {string} normalStyle - normalStyle 默认样式,用于定位文字显示。 |
| 584 | */ |
| 585 | drawText(ctx, style, normalStyle) { |
| 586 | if (typeof(style.text) == 'undefined' || style.text === false) { |
| 587 | return; |
| 588 | } |
| 589 | // 字体颜色策略 |
| 590 | var textColor = style.textColor || style.color || style.strokeColor; |
| 591 | ctx.fillStyle = textColor; |
| 592 | |
| 593 | // 文本与图形间空白间隙 |
| 594 | var dd = 10; |
| 595 | var al; // 文本水平对齐 |
| 596 | var bl; // 文本垂直对齐 |
| 597 | var tx; // 文本横坐标 |
| 598 | var ty; // 文本纵坐标 |
| 599 | |
| 600 | var textPosition = style.textPosition // 用户定义 |
| 601 | || this.textPosition // shape默认 |
| 602 | || 'top'; // 全局默认 |
| 603 | |
| 604 | // Smic 方法修改 -start |
| 605 | var __OP = []; |
| 606 | if (!this.refOriginalPosition || this.refOriginalPosition.length !== 2) { |
| 607 | __OP = [0, 0]; |
| 608 | } else { |
| 609 | __OP = this.refOriginalPosition; |
| 610 | } |
| 611 | //原代码: |
| 612 | // Smic 方法修改 -end |
| 613 | |
| 614 | switch (textPosition) { |
| 615 | case 'inside': |
| 616 | case 'top': |
| 617 | case 'bottom': |
| 618 | case 'left': |
| 619 | case 'right': |
| 620 | if (this.getRect) { |
| 621 | var rect = (normalStyle || style).__rect |
| 622 | || this.getRect(normalStyle || style); |
| 623 | |
| 624 | switch (textPosition) { |
| 625 | case 'inside': |
| 626 | tx = rect.x + rect.width / 2; |
| 627 | ty = rect.y + rect.height / 2; |
| 628 | al = 'center'; |
| 629 | bl = 'middle'; |
| 630 | if (style.brushType != 'stroke' |
| 631 | && textColor == style.color |
| 632 | ) { |
| 633 | ctx.fillStyle = '#fff'; |
| 634 | } |
| 635 | break; |
| 636 | case 'left': |
| 637 | tx = rect.x - dd; |
| 638 | ty = rect.y + rect.height / 2; |
| 639 | al = 'end'; |
| 640 | bl = 'middle'; |
| 641 | break; |
| 642 | case 'right': |