I want to have rotatable text edit area like in Adobe Illustrator. I tried several things including subclassing NSTextView and adding coordinate system rotation before the drawing code like this:
@implementation MyNSTextView
-(void)drawRect:(NSRect)dirtyRect
{
NSAffineTransform * trafo = [NSAffineTransform transform];
[trafo rotateByDegrees:45];
[trafo concat];
[super drawRect:dirtyRect];
}
-(void)drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag
{
NSAffineTransform * trafo = [NSAffineTransform transform];
[trafo rotateByDegrees:45];
[trafo concat];
[super drawInsertionPointInRect:rect color:color turnedOn:flag];
}
Which results in corrupted display of the text. I also tried to implement the functionality myself by subclassing NSView and assembling the text architecture programmatically. I draw the string with the drawGlyphsForRange: method of my NSLayoutManager. This partly works but gets complicated because I have to rotate the coordinates for the drawing and for handling the mouse clicks I have to convert the mouse location back to old coordinates.
So is this the best way to do it or is there something else?
Edit: I now tried to use CALayer like this:
@implementation MyNSTextView
-(id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self) {
CALayer *myLayer = [CALayer layer];
myLayer.transform = CATransform3DMakeRotation(1.6,1,0,1.0);
[self setLayer:myLayer];
[self setWantsLayer:YES];
}
return self;
}
But this yields a TextView which doesn't show any text (only a cursor) and is not rotated. Is there something else to add to make it work??