UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

46 lines (41 loc) 3.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.DefaultCanvasRichTextRender = void 0; const rect_1 = require("../../../common/shape/rect"), theme_1 = require("../../../graphic/theme"), constants_1 = require("../../../graphic/constants"), utils_1 = require("./utils"), base_render_1 = require("./base-render"), text_contribution_render_1 = require("./contributions/text-contribution-render"); class DefaultCanvasRichTextRender extends base_render_1.BaseRender { constructor() { super(), this.numberType = constants_1.RICHTEXT_NUMBER_TYPE, this.builtinContributions = [ text_contribution_render_1.defaultTextBackgroundRenderContribution ], this.init(); } drawShape(richtext, context, x, y, drawContext) { const richtextAttribute = (0, theme_1.getTheme)(richtext).richtext, {strokeOpacity: strokeOpacity = richtextAttribute.strokeOpacity, opacity: opacity = richtextAttribute.opacity, fillOpacity: fillOpacity = richtextAttribute.fillOpacity, visible: visible = richtextAttribute.visible} = richtext.attribute; if (!richtext.valid || !visible) return; const fVisible = (0, utils_1.fillVisible)(opacity, fillOpacity, !0), sVisible = (0, utils_1.fillVisible)(opacity, strokeOpacity, !0); if (!fVisible) return; context.setShadowBlendStyle && context.setShadowBlendStyle(richtext, richtext.attribute, richtextAttribute), context.translate(x, y), this.beforeRenderStep(richtext, context, x, y, fVisible, sVisible, fVisible, sVisible, richtextAttribute, drawContext); richtext.getFrameCache().draw(context, this.drawIcon), this.afterRenderStep(richtext, context, x, y, fVisible, sVisible, fVisible, sVisible, richtextAttribute, drawContext); } drawIcon(icon, context, x, y, baseline) { var _a; const richtextIconAttribute = (0, theme_1.getTheme)(icon).richtextIcon, {width: width = richtextIconAttribute.width, height: height = richtextIconAttribute.height, opacity: opacity = richtextIconAttribute.opacity, image: url, backgroundFill: backgroundFill = richtextIconAttribute.backgroundFill, backgroundFillOpacity: backgroundFillOpacity = richtextIconAttribute.backgroundFillOpacity, backgroundStroke: backgroundStroke = richtextIconAttribute.backgroundStroke, backgroundStrokeOpacity: backgroundStrokeOpacity = richtextIconAttribute.backgroundStrokeOpacity, backgroundRadius: backgroundRadius = richtextIconAttribute.backgroundRadius, margin: margin} = icon.attribute, {backgroundWidth: backgroundWidth = width, backgroundHeight: backgroundHeight = height} = icon.attribute; if (margin && (x += icon._marginArray[3], y += icon._marginArray[0]), icon._hovered) { const expandX = (backgroundWidth - width) / 2, expandY = (backgroundHeight - height) / 2; 0 === backgroundRadius ? (context.beginPath(), context.rect(x - expandX, y - expandY, backgroundWidth, backgroundHeight)) : (context.beginPath(), (0, rect_1.createRectPath)(context, x - expandX, y - expandY, backgroundWidth, backgroundHeight, backgroundRadius, !0)), backgroundFill && (context.globalAlpha = backgroundFillOpacity, context.fillStyle = backgroundFill, context.fill()), backgroundStroke && (context.globalAlpha = backgroundStrokeOpacity, context.strokeStyle = backgroundStroke, context.stroke()); } const res = url && (null === (_a = null == icon ? void 0 : icon.resources) || void 0 === _a ? void 0 : _a.get(url)); res && "success" === res.state && (context.globalAlpha = opacity, context.drawImage(res.data, x, y, width, height)); } draw(richtext, renderService, drawContext) { const richtextAttribute = (0, theme_1.getTheme)(richtext).richtext; this._draw(richtext, richtextAttribute, !1, drawContext); } } exports.DefaultCanvasRichTextRender = DefaultCanvasRichTextRender; //# sourceMappingURL=richtext-render.js.map