import * as React from "react"; // import {Text, Group} from 'react-konva'; import {ReportItemDesigner} from "./ReportItemDesigner"; import {RectF, SizeF} from "../../drawing/Unit"; import {KonvaMapping} from "../../drawing/KonvaMapping"; import {VerticalTextAlignEnum} from "../../items/properties/enums"; import {BoxItemDesigner} from "./BoxItemDesigner"; import {PaddingDrawer} from "./decorates/PaddingDrawer"; import {GroupObjectPool, TextObjectPool} from "../../drawing/KonvaObjectPools"; import TextFieldItem from "../../items/TextFieldItem"; import {TextProperty} from "../../items/properties/define"; import {DesignerHost} from "../DesignerHost"; export class TextItemDesigner extends BoxItemDesigner { // @BorderDrawer @PaddingDrawer render(rect: RectF): any { const bounds = rect.clone(); const zoom = this.behaviorService.zoom; const item = this.item as TextFieldItem; var text = item.getPropertyValue(TextProperty.text); if (text.indexOf("=") === 0) { // 英文转中文 const dataSource = DesignerHost.instance().uiModel.dataSourceModel.dataSource; const fieldValue = dataSource.convertEngToCn(text.substr(1)); text = fieldValue ? `[=${fieldValue}]` : text; } const font = item.style.font; const fontSize = font.fontSize.pixels;// * this.behaviorService.zoom; bounds.width = bounds.width / zoom; bounds.height = bounds.height / zoom; const textHeight = ReportItemDesigner.calculateTextHeight(text, fontSize, bounds.width); //水平对齐属性 let alignProps = KonvaMapping.getTextAlignValue(item.style.hAlign); let verticalAlignProps; switch (item.style.vAlign) { //顶部对齐 case VerticalTextAlignEnum.Top: verticalAlignProps = bounds.top; break; //居中对齐 case VerticalTextAlignEnum.Middle: verticalAlignProps = bounds.top + (bounds.height * zoom - textHeight * zoom) / 2; break; //底部对齐 case VerticalTextAlignEnum.Bottom: verticalAlignProps = Math.max(0, bounds.top + bounds.height * zoom - textHeight * zoom); break; case VerticalTextAlignEnum.Justified: //@TODO justify可能需要计算lineHeight进行调整 verticalAlignProps = 0; break; } let fontStyle = ""; fontStyle += font.isBold ? "bold" : ""; fontStyle += font.isItalic ? " italic" : ""; const props = { text: text, fontSize: fontSize, fontStyle: fontStyle, fill: item.style.color, align: alignProps, width: bounds.width, listening: false, scaleX: this.behaviorService.zoom, scaleY: this.behaviorService.zoom, }; const tempGroup = GroupObjectPool.get({ x: bounds.x, y: verticalAlignProps, width: bounds.width, height: bounds.height }); tempGroup.add(TextObjectPool.get(props)); return tempGroup; } getDisplayName() { const value = this.item.displayName(); const dataSource = DesignerHost.instance().uiModel.dataSourceModel.dataSource; if (dataSource && value.indexOf('=') === 0) { const getDataName = dataSource.convertEngToCn(value.substr(1)); if (getDataName && getDataName !== '') { return `[=${getDataName}]`; } } return value; } }