Articles about Quartz

Strange surprises

Technorati:  - - -

In some docs about Quartz 2D, Apple suggests how to do text measurement before inserting it in a graphic context:

1) Obtain current text position by calling CGContextGetTextPosition.

2) Set text drawing mode to kCGTextInvisible by calling CGContextSetTextDrawingMode.

3) Draw the text.

4) Obtain final text position with CGContextGetTextPosition.

5) Calculate text lenght by subtracting the coordinate obtained at step 4 and the one obtained at step 1.

The first time I read about this method, I really thought this was such a brute approach to the problem. :(

Anyway, since a friend of mine was trying to print a pdf file from a set of data, I explained the procedure to him. After an hour or two, he told me that doing cut and paste from the pdf to another application, he was able to see all the hidden words we used to compute word width calculations (!).

Maybe we have to use another graphic context for calculations or to use ATSUI? 

Weblog Koan Projects Photos Contacts map