From 41d9c3be52cbe40e79576b5d2d65b06aef58a424 Mon Sep 17 00:00:00 2001 From: dhowe Date: Sun, 29 Dec 2024 12:03:19 -0500 Subject: [PATCH] refix to circular ref in textProperties --- src/type/text2d.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/type/text2d.js b/src/type/text2d.js index 8d055357d4..c94032e2b6 100644 --- a/src/type/text2d.js +++ b/src/type/text2d.js @@ -442,6 +442,10 @@ function text2d(p5, fn) { return modified ? this._applyTextProperties() : this._pInst; }; + /** + * Batch set/get text properties for the renderer. + * The properties can be either on `states` or `drawingContext` + */ /** * Batch set/get text properties for the renderer. * The properties can be either on `states` or `drawingContext` @@ -456,17 +460,27 @@ function text2d(p5, fn) { return this._pInst; } - // getter: get props from this.textDrawingContext() + // getter: get props from drawingContext + let context = this.textDrawingContext(); properties = ContextTextProps.reduce((props, p) => { - props[p] = this.textDrawingContext()[p]; + props[p] = context[p]; return props; }, {}); - // add renderer.states props + // add renderer props Object.keys(RendererTextProps).forEach(p => { - properties[p] = this.states[p]; if (RendererTextProps[p]?.type === 'Context2d') { - properties[p] = this.textDrawingContext()[p]; + properties[p] = context[p]; + } + else { // a renderer.states property + if (p === 'textFont') { + // avoid circular ref. inside textFont + properties[p] = Object.assign({}, this._currentTextFont()); + delete properties[p]._pInst; + } + else { + properties[p] = this.states[p]; + } } });