@@ -24,7 +24,11 @@ var propertyMap = {
2424 fixedWidth : [ 'fixedWidth' , false ] ,
2525 fixedHeight : [ 'fixedHeight' , false ] ,
2626 rtl : [ 'rtl' , false ] ,
27- testString : [ 'testString' , '|MÉqgy' ]
27+ testString : [ 'testString' , '|MÉqgy' ] ,
28+ wordWrapWidth : [ 'wordWrap.width' , null ] ,
29+ wordWrapCallback : [ 'wordWrap.callback' , null ] ,
30+ wordWrapCallbackScope : [ 'wordWrap.callbackScope' , null ] ,
31+ wordWrapUseAdvanced : [ 'wordWrap.useAdvancedWrap' , false ]
2832} ;
2933
3034var TextStyle = new Class ( {
@@ -90,7 +94,15 @@ var TextStyle = new Class({
9094
9195 for ( var key in propertyMap )
9296 {
93- this [ key ] = GetAdvancedValue ( style , propertyMap [ key ] [ 0 ] , propertyMap [ key ] [ 1 ] ) ;
97+ if ( key === 'wordWrapCallback' || key === 'wordWrapCallbackScope' )
98+ {
99+ // Callback & scope should be set without processing the values
100+ this [ key ] = GetValue ( style , propertyMap [ key ] [ 0 ] , propertyMap [ key ] [ 1 ] ) ;
101+ }
102+ else
103+ {
104+ this [ key ] = GetAdvancedValue ( style , propertyMap [ key ] [ 0 ] , propertyMap [ key ] [ 1 ] ) ;
105+ }
94106 }
95107
96108 // Allow for 'font' override
@@ -124,6 +136,10 @@ var TextStyle = new Class({
124136 syncFont : function ( canvas , context )
125137 {
126138 context . font = this . _font ;
139+ } ,
140+
141+ syncStyle : function ( canvas , context )
142+ {
127143 context . textBaseline = 'alphabetic' ;
128144
129145 context . fillStyle = this . color ;
@@ -335,6 +351,47 @@ var TextStyle = new Class({
335351 return this . update ( false ) ;
336352 } ,
337353
354+ /**
355+ * Set the width (in pixels) to use for wrapping lines. Pass in null to remove wrapping by
356+ * width.
357+ *
358+ * @param {number|null } width - The maximum width of a line in pixels. Set to null to remove
359+ * wrapping.
360+ * @param {boolean } [useAdvancedWrap=false] - Whether or not to use the advanced wrapping
361+ * algorithm. If true, spaces are collapsed and whitespace is trimmed from lines. If false,
362+ * spaces and whitespace are left as is.
363+ * @return {this }
364+ */
365+ setWordWrapWidth : function ( width , useAdvancedWrap )
366+ {
367+ if ( useAdvancedWrap === undefined ) { useAdvancedWrap = false ; }
368+
369+ this . wordWrapWidth = width ;
370+ this . wordWrapUseAdvanced = useAdvancedWrap ;
371+
372+ return this . update ( false ) ;
373+ } ,
374+
375+ /**
376+ * Set a custom callback for wrapping lines. Pass in null to remove wrapping by callback.
377+ *
378+ * @param {function } callback - A custom function that will be responsible for wrapping the
379+ * text. It will receive two arguments: text (the string to wrap), textObject (this Text
380+ * instance). It should return the wrapped lines either as an array of lines or as a string with
381+ * newline characters in place to indicate where breaks should happen.
382+ * @param {object } [scope=null] - The scope that will be applied when the callback is invoked.
383+ * @return {this }
384+ */
385+ setWordWrapCallback : function ( callback , scope )
386+ {
387+ if ( scope === undefined ) { scope = null ; }
388+
389+ this . wordWrapCallback = callback ;
390+ this . wordWrapCallbackScope = scope ;
391+
392+ return this . update ( false ) ;
393+ } ,
394+
338395 setAlign : function ( align )
339396 {
340397 if ( align === undefined ) { align = 'left' ; }
0 commit comments