Skip to content

Commit

Permalink
refix to circular ref in textProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
dhowe committed Dec 29, 2024
1 parent 8aadc26 commit 41d9c3b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/type/text2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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];
}
}
});

Expand Down

0 comments on commit 41d9c3b

Please sign in to comment.