import * as React from "react"; // import {Rect, Line, Text} from 'react-konva'; import {PointF, RectF, SizeF} from "../../drawing/Unit"; import {Behavior} from "./Behavior"; import {Cursor} from "../../drawing/Cursor"; import {IDisposable} from "../../interfaces/Interfaces"; import {RectObjectPool, TextObjectPool, LineObjectPool} from "../../drawing/KonvaObjectPools"; const uuid = require('uuid'); const Konva = require('konva'); const dumpText = new Konva.Text(); export abstract class Glyph implements IDisposable { _objectId = uuid.v1(); private _behavior: Behavior; constructor(behavior:Behavior) { this._behavior = behavior; } get objectId():string { return this._objectId; } get behavior():Behavior { return this._behavior; } hitTest(pt:PointF):Cursor { return null; } render(parentNode?:any): any { return null; } dispose() { } static measureString(str:string, props:any):SizeF { // const txtProps = {}; // Object.assign(txtProps, props); // txtProps['text'] = str; dumpText.text(str); dumpText.fontSize(props.fontSize); return new SizeF(dumpText.getWidth(), dumpText.getHeight()); } static drawString(s:string, font:{}, brush:{}, bounds:RectF, config:{}):any { const txtProps = { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, }; Object.assign(txtProps, font); Object.assign(txtProps, brush); Object.assign(txtProps, config); txtProps['text'] = s; // return ( // // ) return TextObjectPool.get(txtProps); } static drawLine(pen:{}, x1:number, y1:number, x2:number, y2:number):any { const props = {}; Object.assign(props, pen); props['points'] = [Math.floor(x1) + 0.5, Math.floor(y1) + 0.5, Math.floor(x2) + 0.5, Math.floor(y2) + 0.5]; return LineObjectPool.get(props); } static fillRectangle(brush:{}, bounds:RectF, config?: {}):any { const props = {}; Object.assign(props, { x: bounds.x, y: bounds.y, width: bounds.width, height: bounds.height, }); Object.assign(props, brush); Object.assign(props, config); // return ( // // ) // return new Konva.Rect(props); return RectObjectPool.get(props); } protected drawLine(pen:{}, x1:number, y1:number, x2:number, y2:number):any { return Glyph.drawLine(pen, x1, y1, x2, y2); } protected fillRectangle(brush:{}, bounds:RectF):any { return Glyph.fillRectangle(brush, bounds); } }