import * as React from "react"; import {Glyph} from "./Glyph"; import {RectF, PointF} from "../../drawing/Unit"; import {DesignerStyleSettings} from "../DesignerStyleSettings"; import {SnapLineGlyphType} from "./Enums"; import {Cursor} from "../../drawing/Cursor"; import {ReportItemBaseDesigner} from "../designer/ReportItemBaseDesigner"; const Konva = require('konva'); export class SnapLineGlyph extends Glyph { x1:number; y1:number; x2:number; y2:number; type = SnapLineGlyphType.Standard; originalBounds = RectF.Empty; designer:ReportItemBaseDesigner; tag:string; constructor(type:SnapLineGlyphType, x1:number, y1:number, x2:number, y2:number) { super(null); this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; this.type = type; } /** * 返回 line1 和 line2 重叠部分的线 * @param line1 * @param line2 * @returns {any} */ static overlap(line1:SnapLineGlyph, line2:SnapLineGlyph):SnapLineGlyph { if (line1.type === line2.type) { if (line1.type != SnapLineGlyphType.Standard && line1.type != SnapLineGlyphType.Baseline) return null; if (line1.x1 === line1.x2 && line2.x1 === line2.x2 && line1.x1 === line2.x1) { return new SnapLineGlyph(line1.type , line1.x1 , Math.min(line1.y1, line2.y1) , line1.x1 , Math.max(line1.y2, line2.y2)); } if (line1.y1 === line1.y2 && line2.y1 === line2.y2 && line1.y1 === line2.y1) { return new SnapLineGlyph(line1.type , Math.min(line1.x1, line2.x1) , line1.y1 , Math.max(line1.x2, line2.x2) , line1.y1); } } return null; } hitTest(pt:PointF):Cursor { return null; } render(parentNode):void { if (this.type == SnapLineGlyphType.Padding) { const dragBounds = this.designer.getBounds().clone(); const rc = this.originalBounds.clone(); if (this.x1 === this.x2) { if (this.tag === "Padding.Left") { rc.width = dragBounds.left - rc.left; } else { rc.width = rc.right - dragBounds.right; rc.x = dragBounds.right; } rc.width = Math.max(rc.width, 1); } else { if (this.tag === "Padding.Top") { rc.height = dragBounds.top - rc.top; } else { rc.height = rc.bottom - dragBounds.bottom; rc.y = dragBounds.bottom; } } rc.width = Math.max(rc.width, 1); rc.height = Math.max(rc.height, 1); parentNode.add(this.fillRectangle(DesignerStyleSettings.SnapLinePaddingBrush, rc)); } else if (this.type === SnapLineGlyphType.Margin) { const dragBounds = this.designer.getBounds().clone(); const rc = new RectF(); if (this.x1 === this.x2) { rc.y = Math.min(dragBounds.top, this.originalBounds.top); rc.height = Math.max(dragBounds.bottom, this.originalBounds.bottom) - rc.y; const x1 = Math.min(dragBounds.right, this.originalBounds.right); const x2 = Math.max(dragBounds.left, this.originalBounds.left); rc.x = Math.min(x1, x2); rc.width = Math.max(1, Math.abs(x1 - x2)); } else { rc.x = Math.min(this.originalBounds.left, dragBounds.left); rc.width = Math.max(this.originalBounds.right, dragBounds.right) - rc.x; const y1 = Math.min(dragBounds.bottom, this.originalBounds.bottom); const y2 = Math.max(dragBounds.top, this.originalBounds.top); rc.y = Math.min(y1, y2); rc.height = Math.max(1, Math.abs(y1 - y2)); } parentNode.add(this.fillRectangle(DesignerStyleSettings.SnapLinePaddingBrush, rc)); } else { const pen = (this.type === SnapLineGlyphType.Baseline ? DesignerStyleSettings.SnapLineBaseLinePen : DesignerStyleSettings.SnapLineNormalPen); parentNode.add(this.drawLine(pen, this.x1, this.y1, this.x2, this.y2)); } } }