recursive problems

Ok, I have been fixing processing.js‘s textLeading function. I initially made a patch to implement this function, but it has some problems before it can be landed in the code.

Some short background info. I recently landed textAscent and textDescent. What these functions do are create an offscreen processing instance, write some text to it, then measure the pixels to get the true ascent and descent values.

textAscent is the number of pixels from the bottom of the letter “t”, to the top, and the textDescent is the bottom of the letter “t” to the bottom of the letter “j”. Text leading is the space between the letter “t” and the next line’s bottom of the letter “t”. So if you were to draw the words “text/ntext” in a processing sketch, the text Leading is the number of pixels used to separate the words on the newline(\n) character.

The way processing calculates the space between two lines is by adding ascent and descent then multiplying the sum by 1.275. There is a problem with this.

I will walk you through it. You want to write some text to the screen, so you give it a size. Size has changed, so textAscent and textDescent need to be recalculated. So we call ascent and descent, which draw an offscreen canvas on which to measure pixels, which calls size, which calculates textLeading, which calls ascent and descent, which creates an offscreen canvas, which calls size, which calculates textLeading, which… you get the idea…

TextSize -> textLeading -> ascent/descent -> textSize…

I need to brainstorm a solution to this.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: