My blog has been mentioned here before as an answer to questions. I cannot contact one of them because this form claims to be a spammer. Sigh. In any case, now I want to write the final blog post on drawing rotating text, so it can also be used for answers here (heh). Here is my first attempt:
http://www.platinumball.net/blog/2009/06/01/drawing-nsstrings-in-unusual-rotations/
This works well, it does everything I want, except that it uses CGContextSelectFont (), which restricts the output of text to MacRoman. This is The Sukk.
I’ve been looking for an answer to this problem for almost a year now, including searching this site several times, without success. I saw examples that seem close to what I want, but apparently I'm too stupid to persuade them to my will. I am including the main method from the NSString category that I wrote, and this shows what I am doing. If you need to see the rest of the code, you can download it with a link to my blog, which I gave above. Thank...
-(void)drawAtPoint:(CGPoint)point withFont:(UIFont*)font
orientation:(WBOrientation)orient
{
CGContextRef ctxt = [self contextSave];
const std::string tbuf = toStdString(self, NSMacOSRomanStringEncoding);
CGAffineTransform tran = CGAffineTransformMake(1, 0, 0, -1, 0, 0);
switch (orient)
{
case WBOrientUp:
break;
case WBOrientDown:
tran = CGAffineTransformRotate(tran, degreesToRadians(180.0));
break;
case WBOrientLeft:
tran = CGAffineTransformRotate(tran, degreesToRadians(90.0));
break;
case WBOrientRight:
tran = CGAffineTransformRotate(tran, degreesToRadians(-90.0));
break;
default:
assert(false);
break;
}
contextFont(ctxt, font);
CGContextSetTextDrawingMode(ctxt, kCGTextFill);
CGContextSetTextMatrix(ctxt, tran);
CGContextSetTextPosition(ctxt, point.x, point.y);
CGContextShowText(ctxt, tbuf.c_str(), tbuf.length());
[self contextRestore:ctxt];
}