Say I'm writing a text viewer for iPhone using Core Text. Each time the user changes the size of the base font, I need to calculate how many pages (CGR) of a fixed size are needed to display the entire NSAttributedString with the given font sizes.
And I would like to do this in a separate NSOperation, so that the user will not experience unnecessary user interface delays.
Unfortunately, for page counting, I need to draw my frames (CTFrameDraw) using invisible text drawing mode, and then use CTFrameGetVisibleStringRange to count characters. But to draw text, I need a CGContext. And here the problems begin ...
I can get the CGContext in my drawRect by calling UIGraphicsGetCurrentContext, but in this case:
- I need to call any method that works with CGContext using the performSelectorOnMainThread function, right?
- Another thread must CFRetain this context. Is it acceptable to use the drawRect CGContext method outside of the drawRect method?
Any other solutions? Creating a separate CGContext in a workflow? How? CGBitmapContext? How can I be sure that all conditions (I don’t know the resolution? Etc.) will be the same as in drawRect CGContext so that the pages are correctly counted?
source
share