Returning a value
in
Programming Questions
•
10 months ago
Hi all,
i have a code fragment I am referencing (credit given below) and I would like to use a returned value from it in the main draw.
However, it doesn't seem to be returned , except as zero perhaps. it's the calculateTextHeight below that I want. It would seem to be returned as textHeight unless I am wrong.
I'm using the below fragment in a class called Node, and am calling other values from the class in draw, but this one has me stumped.
It's a float if that matters, but I feel I am doing something basic wrong.
//from steven http://processing.org/discourse/beta/num_1195937999.html
int calculateTextHeight(String nodeString, int specificWidth, int fontSize, int lineSpacing) {
String[] wordsArray;
String tempString = "";
int numLines = 0;
float textHeight;
wordsArray = split(nodeString, " ");
for (int i=0; i < wordsArray.length; i++) {
if (textWidth(tempString + wordsArray[i]) < specificWidth) {
tempString += wordsArray[i] + " ";
}
else {
tempString = wordsArray[i] + " ";
numLines++;
}
}
numLines++;
textHeight = numLines * (textDescent() + textAscent() + lineSpacing);
return(round(textHeight));
}
}
1