function text$6(str, x, y, width, height, z) {
      // 'fail' on 0-valued dimensions
      if (str.length === 0 || width === 0 || height === 0) {
        return;
      }
      // also 'fail' if the text height is larger than the bounding height
      if(curTextSize > height) {
        return;
      }

      var spaceMark = -1;
      var start = 0;
      var lineWidth = 0;
      var drawCommands = [];

      // run through text, character-by-character
      for (var charPos=0, len=str.length; charPos < len; charPos++)
      {
        var currentChar = str[charPos];
        var spaceChar = (currentChar === " ");
        var letterWidth = curTextFont.measureTextWidth(currentChar);

        // if we aren't looking at a newline, and the text still fits, keep processing
        if (currentChar !== "\n" && (lineWidth + letterWidth <= width)) {
          if (spaceChar) { spaceMark = charPos; }
          lineWidth += letterWidth;
        }

        // if we're looking at a newline, or the text no longer fits, push the section that fit into the drawcommand list
        else
        {
          if (spaceMark + 1 === start) {
            if(charPos>0) {
              // Whole line without spaces so far.
              spaceMark = charPos;
            } else {
              // 'fail', because the line can't even fit the first character
              return;
            }
          }

          if (currentChar === "\n") {
            drawCommands.push({text:str.substring(start, charPos), width: lineWidth});
            start = charPos + 1;
          } else {
            // current is not a newline, which means the line doesn't fit in box. push text.
            // In Processing 1.5.1, the space is also pushed, so we push up to spaceMark+1,
            // rather than up to spaceMark, as was the case for Processing 1.5 and earlier.
            drawCommands.push({text:str.substring(start, spaceMark+1), width: lineWidth});
            start = spaceMark + 1;
          }

          // newline + return
          lineWidth = 0;
          charPos = start - 1;
        }
      }

      // push the remaining text
      if (start < len) {
        drawCommands.push({text:str.substring(start), width: lineWidth});
      }

      // resolve horizontal alignment
      var xOffset = 1,
          yOffset = curTextAscent;
      if (horizontalTextAlignment === PConstants.CENTER) {
        xOffset = width/2;
      } else if (horizontalTextAlignment === PConstants.RIGHT) {
        xOffset = width;
      }

      // resolve vertical alignment
      var linesCount = drawCommands.length,
          visibleLines = Math.min(linesCount, Math.floor(height/curTextLeading));
      if(verticalTextAlignment === PConstants.TOP) {
        yOffset = curTextAscent + curTextDescent;
      } else if(verticalTextAlignment === PConstants.CENTER) {
        yOffset = (height/2) - curTextLeading * (visibleLines/2 - 1);
      } else if(verticalTextAlignment === PConstants.BOTTOM) {
        yOffset = curTextDescent + curTextLeading;
      }

      var command,
          drawCommand,
          leading;
      for (command = 0; command < linesCount; command++) {
        leading = command * curTextLeading;
        // stop if not enough space for one more line draw
        if (yOffset + leading > height - curTextDescent) {
          break;
        }
        drawCommand = drawCommands[command];
        drawing.text$line(drawCommand.text, x + xOffset, y + yOffset + leading, z, horizontalTextAlignment);
      }
    }
/**
    * box-bounded text function (z is an optional argument)
    */
box-bounded text function (z is an optional argument)
box - bounded text function ( z is an optional argument )
function text$6(str, x, y, width, height, z) {
      if (str.length === 0 || width === 0 || height === 0) {
        return;
      }
      if(curTextSize > height) {
        return;
      }
      var spaceMark = -1;
      var start = 0;
      var lineWidth = 0;
      var drawCommands = [];
      for (var charPos=0, len=str.length; charPos < len; charPos++)
      {
        var currentChar = str[charPos];
        var spaceChar = (currentChar === " ");
        var letterWidth = curTextFont.measureTextWidth(currentChar);
        if (currentChar !== "\n" && (lineWidth + letterWidth <= width)) {
          if (spaceChar) { spaceMark = charPos; }
          lineWidth += letterWidth;
        }
        else
        {
          if (spaceMark + 1 === start) {
            if(charPos>0) {
              spaceMark = charPos;
            } else {
              return;
            }
          }
          if (currentChar === "\n") {
            drawCommands.push({text:str.substring(start, charPos), width: lineWidth});
            start = charPos + 1;
          } else {
            drawCommands.push({text:str.substring(start, spaceMark+1), width: lineWidth});
            start = spaceMark + 1;
          }
          lineWidth = 0;
          charPos = start - 1;
        }
      }
      if (start < len) {
        drawCommands.push({text:str.substring(start), width: lineWidth});
      }
      var xOffset = 1,
          yOffset = curTextAscent;
      if (horizontalTextAlignment === PConstants.CENTER) {
        xOffset = width/2;
      } else if (horizontalTextAlignment === PConstants.RIGHT) {
        xOffset = width;
      }
      var linesCount = drawCommands.length,
          visibleLines = Math.min(linesCount, Math.floor(height/curTextLeading));
      if(verticalTextAlignment === PConstants.TOP) {
        yOffset = curTextAscent + curTextDescent;
      } else if(verticalTextAlignment === PConstants.CENTER) {
        yOffset = (height/2) - curTextLeading * (visibleLines/2 - 1);
      } else if(verticalTextAlignment === PConstants.BOTTOM) {
        yOffset = curTextDescent + curTextLeading;
      }
      var command,
          drawCommand,
          leading;
      for (command = 0; command < linesCount; command++) {
        leading = command * curTextLeading;
        if (yOffset + leading > height - curTextDescent) {
          break;
        }
        drawCommand = drawCommands[command];
        drawing.text$line(drawCommand.text, x + xOffset, y + yOffset + leading, z, horizontalTextAlignment);
      }
    }
function text$6 ( str , x , y , width , height , z ) { if ( str . length === 0 || width === 0 || height === 0 ) { return ; } if ( curTextSize > height ) { return ; } var spaceMark = - 1 ; var start = 0 ; var lineWidth = 0 ; var drawCommands = [ ] ; for ( var charPos = 0 , len = str . length ; charPos < len ; charPos ++ ) { var currentChar = str [ charPos ] ; var spaceChar = ( currentChar === " " ) ; var letterWidth = curTextFont . measureTextWidth ( currentChar ) ; if ( currentChar !== "\n" && ( lineWidth + letterWidth <= width ) ) { if ( spaceChar ) { spaceMark = charPos ; } lineWidth += letterWidth ; } else { if ( spaceMark + 1 === start ) { if ( charPos > 0 ) { spaceMark = charPos ; } else { return ; } } if ( currentChar === "\n" ) { drawCommands . push ( { text : str . substring ( start , charPos ) , width : lineWidth } ) ; start = charPos + 1 ; } else { drawCommands . push ( { text : str . substring ( start , spaceMark + 1 ) , width : lineWidth } ) ; start = spaceMark + 1 ; } lineWidth = 0 ; charPos = start - 1 ; } } if ( start < len ) { drawCommands . push ( { text : str . substring ( start ) , width : lineWidth } ) ; } var xOffset = 1 , yOffset = curTextAscent ; if ( horizontalTextAlignment === PConstants . CENTER ) { xOffset = width / 2 ; } else if ( horizontalTextAlignment === PConstants . RIGHT ) { xOffset = width ; } var linesCount = drawCommands . length , visibleLines = Math . min ( linesCount , Math . floor ( height / curTextLeading ) ) ; if ( verticalTextAlignment === PConstants . TOP ) { yOffset = curTextAscent + curTextDescent ; } else if ( verticalTextAlignment === PConstants . CENTER ) { yOffset = ( height / 2 ) - curTextLeading * ( visibleLines / 2 - 1 ) ; } else if ( verticalTextAlignment === PConstants . BOTTOM ) { yOffset = curTextDescent + curTextLeading ; } var command , drawCommand , leading ; for ( command = 0 ; command < linesCount ; command ++ ) { leading = command * curTextLeading ; if ( yOffset + leading > height - curTextDescent ) { break ; } drawCommand = drawCommands [ command ] ; drawing . text$line ( drawCommand . text , x + xOffset , y + yOffset + leading , z , horizontalTextAlignment ) ; } }
box-bounded text function (z is an optional argument)
box - bounded text function ( z is an optional argument )
// 'fail' on 0-valued dimensions // also 'fail' if the text height is larger than the bounding height // run through text, character-by-character // if we aren't looking at a newline, and the text still fits, keep processing // if we're looking at a newline, or the text no longer fits, push the section that fit into the drawcommand list // Whole line without spaces so far. // 'fail', because the line can't even fit the first character // current is not a newline, which means the line doesn't fit in box. push text. // In Processing 1.5.1, the space is also pushed, so we push up to spaceMark+1, // rather than up to spaceMark, as was the case for Processing 1.5 and earlier. // newline + return // push the remaining text // resolve horizontal alignment // resolve vertical alignment // stop if not enough space for one more line draw