@@ -4921,58 +4921,53 @@ var typographyattributes = function (require, core, constants) {
4921
4921
} ;
4922
4922
return p5 ;
4923
4923
} ( { } , core , constants ) ;
4924
- var typographyloading_displaying = function ( require , core , canvas ) {
4924
+ var typographyloading_displaying = function ( require , core ) {
4925
4925
'use strict' ;
4926
4926
var p5 = core ;
4927
- var canvas = canvas ;
4928
- p5 . prototype . text = function ( ) {
4929
- if ( arguments . length === 3 ) {
4930
- if ( this . _doFill ) {
4931
- this . drawingContext . fillText ( arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] ) ;
4932
- }
4933
- if ( this . _doStroke ) {
4934
- this . drawingContext . strokeText ( arguments [ 0 ] , arguments [ 1 ] , arguments [ 2 ] ) ;
4935
- }
4936
- } else if ( arguments . length === 5 ) {
4937
- var words = arguments [ 0 ] . split ( ' ' ) ;
4927
+ p5 . prototype . text = function ( str , x , y , maxWidth , maxHeight ) {
4928
+ if ( typeof maxWidth !== 'undefined' ) {
4929
+ y += this . _textLeading ;
4930
+ maxHeight += y ;
4931
+ }
4932
+ str = str . replace ( / ( \t ) / g, ' ' ) ;
4933
+ var cars = str . split ( '\n' ) ;
4934
+ for ( var ii = 0 ; ii < cars . length ; ii ++ ) {
4938
4935
var line = '' ;
4939
- var vals = canvas . modeAdjust ( arguments [ 1 ] , arguments [ 2 ] , arguments [ 3 ] , arguments [ 4 ] , this . _rectMode ) ;
4940
- var y = vals . y + this . _textLeading ;
4936
+ var words = cars [ ii ] . split ( ' ' ) ;
4941
4937
for ( var n = 0 ; n < words . length ; n ++ ) {
4942
- var testLine = line + words [ n ] + ' ' ;
4943
- var metrics = this . drawingContext . measureText ( testLine ) ;
4944
- var testWidth = metrics . width ;
4945
- if ( y > vals . y + vals . h ) {
4946
- break ;
4947
- } else if ( testWidth > vals . w && n > 0 ) {
4948
- if ( this . _doFill ) {
4949
- this . drawingContext . fillText ( line , vals . x , y ) ;
4950
- }
4951
- if ( this . _doStroke ) {
4952
- this . drawingContext . strokeText ( line , vals . x , y ) ;
4938
+ if ( y + this . _textLeading <= maxHeight || typeof maxHeight === 'undefined' ) {
4939
+ var testLine = line + words [ n ] + ' ' ;
4940
+ var metrics = this . drawingContext . measureText ( testLine ) ;
4941
+ var testWidth = metrics . width ;
4942
+ if ( typeof maxWidth !== 'undefined' && testWidth > maxWidth ) {
4943
+ if ( this . _doFill ) {
4944
+ this . drawingContext . fillText ( line , x , y ) ;
4945
+ }
4946
+ if ( this . _doStroke ) {
4947
+ this . drawingContext . strokeText ( line , x , y ) ;
4948
+ }
4949
+ line = words [ n ] + ' ' ;
4950
+ y += this . _textLeading ;
4951
+ } else {
4952
+ line = testLine ;
4953
4953
}
4954
- line = words [ n ] + ' ' ;
4955
- y += this . _textLeading ;
4956
- } else {
4957
- line = testLine ;
4958
4954
}
4959
4955
}
4960
- if ( y <= vals . y + vals . h ) {
4961
- if ( this . _doFill ) {
4962
- this . drawingContext . fillText ( line , vals . x , y ) ;
4963
- }
4964
- if ( this . _doStroke ) {
4965
- this . drawingContext . strokeText ( line , vals . x , y ) ;
4966
- }
4956
+ if ( this . _doFill ) {
4957
+ this . drawingContext . fillText ( line , x , y ) ;
4967
4958
}
4959
+ if ( this . _doStroke ) {
4960
+ this . drawingContext . strokeText ( line , x , y ) ;
4961
+ }
4962
+ y += this . _textLeading ;
4968
4963
}
4969
4964
} ;
4970
4965
p5 . prototype . textFont = function ( str ) {
4971
4966
this . _setProperty ( '_textFont' , str ) ;
4972
4967
this . _applyTextProperties ( ) ;
4973
4968
} ;
4974
4969
return p5 ;
4975
- } ( { } , core , canvas ) ;
4970
+ } ( { } , core ) ;
4976
4971
var src_app = function ( require , core , p5Color , p5Element , p5Graphics , p5Image , p5Vector , p5TableRow , p5Table , colorcreating_reading , colorsetting , constants , dataconversion , dataarray_functions , datastring_functions , environment , imageimage , imageloading_displaying , imagepixels , inputfiles , inputkeyboard , inputmouse , inputtime_date , inputtouch , mathmath , mathcalculation , mathrandom , mathnoise , mathtrigonometry , outputfiles , outputimage , outputtext_area , renderingrendering , shape2d_primitives , shapeattributes , shapecurves , shapevertex , structure , transform , typographyattributes , typographyloading_displaying ) {
4977
4972
'use strict' ;
4978
4973
var p5 = core ;
0 commit comments