@@ -14,6 +14,11 @@ function vtkTextActor(publicAPI, model) {
1414 // Set our className
1515 model . classHierarchy . push ( 'vtkTextActor' ) ;
1616
17+ const superDelete = publicAPI . delete ;
18+ const superGetProperty = publicAPI . getProperty ;
19+ const superSetProperty = publicAPI . setProperty ;
20+ let propertySubscription = null ;
21+
1722 publicAPI . makeProperty = vtkTextProperty . newInstance ;
1823
1924 const texture = vtkTexture . newInstance ( {
@@ -38,7 +43,7 @@ function vtkTextActor(publicAPI, model) {
3843 const backgroundColor = publicAPI . getProperty ( ) . getBackgroundColor ( ) ;
3944
4045 const dpr = Math . max ( window . devicePixelRatio || 1 , 1 ) ;
41- const ctx = canvas . getContext ( '2d' ) ;
46+ const ctx = canvas . getContext ( '2d' , { willReadFrequently : true } ) ;
4247
4348 // Set the text properties to measure
4449 const textSize = fontSizeScale ( resolution ) * dpr ;
@@ -110,15 +115,57 @@ function vtkTextActor(publicAPI, model) {
110115 return ImageHelper . canvasToImageData ( canvas ) ;
111116 }
112117
118+ function updateTexture ( ) {
119+ const image = createImageData ( model . input ) ;
120+ texture . setInputData ( image , 0 ) ;
121+ }
122+
123+ function bindProperty ( property ) {
124+ if ( propertySubscription ) {
125+ propertySubscription . unsubscribe ( ) ;
126+ propertySubscription = null ;
127+ }
128+
129+ if ( property ) {
130+ propertySubscription = property . onModified ( ( ) => {
131+ if ( model . input !== undefined ) {
132+ updateTexture ( ) ;
133+ }
134+ } ) ;
135+ }
136+ }
137+
113138 mapper . setInputConnection ( plane . getOutputPort ( ) ) ;
114139
115140 publicAPI . setMapper ( mapper ) ;
116141 publicAPI . addTexture ( texture ) ;
117142
118- model . _onInputChanged = ( _publicAPI , _model , value ) => {
119- const image = createImageData ( value ) ;
120- texture . setInputData ( image , 0 ) ;
143+ publicAPI . getProperty = ( ) => {
144+ const property = superGetProperty ( ) ;
145+ if ( model . property !== property || ! propertySubscription ) {
146+ bindProperty ( property ) ;
147+ }
148+ return property ;
149+ } ;
150+
151+ publicAPI . setProperty = ( property ) => {
152+ const changed = superSetProperty ( property ) ;
153+ bindProperty ( property ) ;
154+ if ( model . input !== undefined ) {
155+ updateTexture ( ) ;
156+ }
157+ return changed ;
121158 } ;
159+
160+ publicAPI . delete = ( ) => {
161+ if ( propertySubscription ) {
162+ propertySubscription . unsubscribe ( ) ;
163+ propertySubscription = null ;
164+ }
165+ superDelete ( ) ;
166+ } ;
167+
168+ model . _onInputChanged = updateTexture ;
122169}
123170
124171// Default property values
0 commit comments