@@ -4921,58 +4921,53 @@ var typographyattributes = function (require, core, constants) {
49214921 } ;
49224922 return p5 ;
49234923 } ( { } , core , constants ) ;
4924- var typographyloading_displaying = function ( require , core , canvas ) {
4924+ var typographyloading_displaying = function ( require , core ) {
49254925 'use strict' ;
49264926 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 ++ ) {
49384935 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 ( ' ' ) ;
49414937 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 ;
49534953 }
4954- line = words [ n ] + ' ' ;
4955- y += this . _textLeading ;
4956- } else {
4957- line = testLine ;
49584954 }
49594955 }
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 ) ;
49674958 }
4959+ if ( this . _doStroke ) {
4960+ this . drawingContext . strokeText ( line , x , y ) ;
4961+ }
4962+ y += this . _textLeading ;
49684963 }
49694964 } ;
49704965 p5 . prototype . textFont = function ( str ) {
49714966 this . _setProperty ( '_textFont' , str ) ;
49724967 this . _applyTextProperties ( ) ;
49734968 } ;
49744969 return p5 ;
4975- } ( { } , core , canvas ) ;
4970+ } ( { } , core ) ;
49764971var 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 ) {
49774972 'use strict' ;
49784973 var p5 = core ;
0 commit comments