How can I draw rotated text without restricting the MacRoman character set?

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:
        // nothing to do
        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];
}
+3
source share
2 answers

just a few days after I did it myself =)

this is how i solved it:

view.layer.transform = CATransform3DRotate(view.layer.transform, 3.1415, 0,0,1); // this is for 180 degrees.
+1
source

CGContext , UIGraphicsPushContext, UIKit, , UIGraphicsPopContext.

AppKit (Mac) , NSGraphicsContext 1 AppKit NSString 2. -[NSView drawRect:] 3 ( CGContext NSGraphicsPort 1, , ); , PDF-, NSGraphicsPort (setCurrentContext:) 1, 3.

+1

Source: https://habr.com/ru/post/1730549/


All Articles