UNPKG

@visactor/vtable

Version:

canvas table width high performance

73 lines (67 loc) 5.51 kB
"use strict"; var __decorate = this && this.__decorate || function(decorators, target, key, desc) { var d, c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r); return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.SuffixTextBeforeRenderContribution = void 0; const vrender_1 = require("./../../../vrender"), vutils_1 = require("@visactor/vutils"), text_measure_1 = require("../../utils/text-measure"); let SuffixTextBeforeRenderContribution = class { constructor() { this.time = vrender_1.BaseRenderContributionTime.afterFillStroke, this.useStyle = !0, this.order = 0; } drawShape(text, context, x, y, doFill, doStroke, fVisible, sVisible, textAttribute, drawContext, fillCb, strokeCb, doFillOrStroke) { var _a, _b; const {text: str, underline: underline = textAttribute.underline, lineThrough: lineThrough = textAttribute.lineThrough, direction: direction = textAttribute.direction, whiteSpace: whiteSpace = textAttribute.whiteSpace, fontSize: fontSize = textAttribute.fontSize, verticalMode: verticalMode = textAttribute.verticalMode, ellipsis: ellipsis = textAttribute.ellipsis, textAlign: textAlign = textAttribute.textAlign, textBaseline: textBaseline = textAttribute.textBaseline, x: originX = textAttribute.x, y: originY = textAttribute.y} = text.attribute; let isEmpty = !1; if (Array.isArray(text)) { const layoutData = null === (_a = text.cache) || void 0 === _a ? void 0 : _a.layoutData; ellipsis && layoutData && layoutData.lines.every((line => "" === line.str)) && (isEmpty = !0); } else { const {cache: cache} = text; ellipsis && cache && "" === cache.clipedText && 0 === cache.clipedWidth && (isEmpty = !0); } if (!isEmpty) return; const textStr = (0, vutils_1.isString)(ellipsis) ? ellipsis : "...", lineHeight = null !== (_b = (0, vrender_1.calculateLineHeight)(text.attribute.lineHeight, fontSize)) && void 0 !== _b ? _b : fontSize; let dy = 0; lineHeight !== fontSize && ("top" === textBaseline ? dy = (lineHeight - fontSize) / 2 : "middle" === textBaseline || "bottom" === textBaseline && (dy = -(lineHeight - fontSize) / 2)), doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.strokeText(textStr, originX, originY + dy))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.fillText(textStr, originX, originY + dy), this.drawUnderLine(underline, lineThrough, text, originX, originY + dy, 0, textAttribute, context, textStr))); } drawUnderLine(underline, lineThrough, text, x, y, z, textAttribute, context, textStr) { if (lineThrough + underline <= 0) return; const {textAlign: textAlign = textAttribute.textAlign, textBaseline: textBaseline = textAttribute.textBaseline, fontSize: fontSize = textAttribute.fontSize, fontFamily: fontFamily = textAttribute.fontFamily, fontWeight: fontWeight = textAttribute.fontWeight, fontStyle: fontStyle = textAttribute.fontStyle, fill: fill = textAttribute.fill, opacity: opacity = textAttribute.opacity, underlineOffset: underlineOffset = textAttribute.underlineOffset, underlineDash: underlineDash = textAttribute.underlineDash, fillOpacity: fillOpacity = textAttribute.fillOpacity} = text.attribute; if (!underline && !lineThrough) return; const w = text_measure_1.textMeasure.measureTextWidth(textStr, { fontSize: fontSize, fontFamily: fontFamily, fontWeight: fontWeight, fontStyle: fontStyle }), offsetX = (0, vrender_1.textDrawOffsetX)(textAlign, w), offsetY = (0, vrender_1.textLayoutOffsetY)(textBaseline, fontSize, fontSize), attribute = { lineWidth: 0, stroke: fill, opacity: opacity, strokeOpacity: fillOpacity }; if (underline) { attribute.lineWidth = underline, context.setStrokeStyle(text, attribute, x, y, textAttribute), context.setLineDash(underlineDash), context.beginPath(); const dy = y + offsetY + fontSize + underlineOffset; context.moveTo(x + offsetX, dy, z), context.lineTo(x + offsetX + w, dy, z), context.stroke(); } if (lineThrough) { attribute.lineWidth = lineThrough, context.setStrokeStyle(text, attribute, x, y, textAttribute), context.beginPath(); const dy = y + offsetY + fontSize / 2; context.moveTo(x + offsetX, dy, z), context.lineTo(x + offsetX + w, dy, z), context.stroke(); } } }; SuffixTextBeforeRenderContribution = __decorate([ (0, vrender_1.injectable)() ], SuffixTextBeforeRenderContribution), exports.SuffixTextBeforeRenderContribution = SuffixTextBeforeRenderContribution; //# sourceMappingURL=text-contribution-render.js.map