@visactor/vrender-kits
Version:
## Description
68 lines (62 loc) • 4.52 kB
JavaScript
;
var __importDefault = this && this.__importDefault || function(mod) {
return mod && mod.__esModule ? mod : {
default: mod
};
};
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.RoughBaseRender = void 0;
const vrender_core_1 = require("@visactor/vrender-core"), roughjs_1 = __importDefault(require("roughjs")), context_1 = require("./context"), config_1 = require("./config");
class RoughBaseRender {
drawShape(graphic, ctx, x, y, drawContext, params, fillCb, strokeCb) {
if (this.canvasRenderer.drawShape) return this.canvasRenderer.drawShape(graphic, ctx, x, y, drawContext, params, fillCb, strokeCb);
}
doDraw(graphic, renderService, drawContext, params) {
const {context: context} = drawContext;
if (!context) return;
const canvas = context.canvas.nativeCanvas, rc = roughjs_1.default.canvas(canvas), customPath = new vrender_core_1.CustomPath2D, roughContext = new context_1.RoughContext2d(context, customPath);
context.save(), context.transformFromMatrix(graphic.transMatrix, !0);
const {fill: fill, stroke: stroke, roughStyle: roughStyle = {}, lineWidth: lineWidth} = graphic.attribute, {maxRandomnessOffset: maxRandomnessOffset = config_1.defaultRouthThemeSpec.maxRandomnessOffset, roughness: roughness = config_1.defaultRouthThemeSpec.roughness, bowing: bowing = config_1.defaultRouthThemeSpec.bowing, curveFitting: curveFitting = config_1.defaultRouthThemeSpec.curveFitting, curveTightness: curveTightness = config_1.defaultRouthThemeSpec.curveTightness, curveStepCount: curveStepCount = config_1.defaultRouthThemeSpec.curveStepCount, fillStyle: fillStyle = config_1.defaultRouthThemeSpec.fillStyle, fillWeight: fillWeight = config_1.defaultRouthThemeSpec.fillWeight, hachureAngle: hachureAngle = config_1.defaultRouthThemeSpec.hachureAngle, hachureGap: hachureGap = config_1.defaultRouthThemeSpec.hachureGap, simplification: simplification = config_1.defaultRouthThemeSpec.simplification, dashOffset: dashOffset = config_1.defaultRouthThemeSpec.dashOffset, dashGap: dashGap = config_1.defaultRouthThemeSpec.dashGap, zigzagOffset: zigzagOffset = config_1.defaultRouthThemeSpec.zigzagOffset, seed: seed = config_1.defaultRouthThemeSpec.seed, fillLineDash: fillLineDash = config_1.defaultRouthThemeSpec.fillLineDash, fillLineDashOffset: fillLineDashOffset = config_1.defaultRouthThemeSpec.fillLineDashOffset, disableMultiStroke: disableMultiStroke = config_1.defaultRouthThemeSpec.disableMultiStroke, disableMultiStrokeFill: disableMultiStrokeFill = config_1.defaultRouthThemeSpec.disableMultiStrokeFill, preserveVertices: preserveVertices = config_1.defaultRouthThemeSpec.preserveVertices, fixedDecimalPlaceDigits: fixedDecimalPlaceDigits = config_1.defaultRouthThemeSpec.fixedDecimalPlaceDigits} = roughStyle;
let rendered = !1;
const doRender = () => {
if (rendered) return;
rendered = !0;
const path = customPath.toString();
context.beginPath(), rc.path(path, {
fill: fill,
stroke: stroke,
strokeWidth: lineWidth,
maxRandomnessOffset: maxRandomnessOffset,
roughness: roughness,
bowing: bowing,
curveFitting: curveFitting,
curveTightness: curveTightness,
curveStepCount: curveStepCount,
fillStyle: fillStyle,
fillWeight: fillWeight,
hachureAngle: hachureAngle,
hachureGap: hachureGap,
simplification: simplification,
dashOffset: dashOffset,
dashGap: dashGap,
zigzagOffset: zigzagOffset,
seed: seed,
fillLineDash: fillLineDash,
fillLineDashOffset: fillLineDashOffset,
disableMultiStroke: disableMultiStroke,
disableMultiStrokeFill: disableMultiStrokeFill,
preserveVertices: preserveVertices,
fixedDecimalPlaceDigits: fixedDecimalPlaceDigits
});
};
this.canvasRenderer.drawShape(graphic, roughContext, 0, 0, drawContext, params, (() => (doRender(),
!1)), (() => (doRender(), !1))), context.restore();
}
reInit() {
var _a;
null === (_a = this.canvasRenderer) || void 0 === _a || _a.reInit();
}
}
exports.RoughBaseRender = RoughBaseRender;
//# sourceMappingURL=base-render.js.map