Unwanted clip of rotated text
Unwanted clip of rotated text
- Subject: Unwanted clip of rotated text
- From: Erez Anzel <email@hidden>
- Date: Mon, 23 Feb 2004 12:58:56 -0500
I want to draw rotated strings into a vertical ruler. But the text
appears to get clipped by the unrotated clipping rect.
I'd be grateful for any solutions, workarounds or hints, such as how to
rotate the clipping rect (which I'll refer to as clipRect). This must
run on Mac OS X 10.2 minimum.
The thicker the ruler, the wider the clipRect. The wider the clipRect,
the higher I can place the text in the ruler (i.e. towards the top of
the screen). It appears that the x value of the NSPoint which I pass to
NSString's drawAtPoint is limited to the x value of the clipRect,
before the text doesn't get drawn.
I can't figure out how to get the clipRect to be effectively rotated by
the same rotation which I apply to the graphics context.
I am using an approach which I found in the cocoa-dev archives from
2002 when searching for "rotated text". For testing I wrote the
following, which only gets called for the vertical case of my
NSRulerView subclass's drawHashMarksAndLabelsInRect method:
NSAffineTransform *transform = [NSAffineTransform transform];
NSGraphicsContext *context = [NSGraphicsContext currentContext];
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
// Rotate counterclockwise so text reads from bottom to top
// instead of left to right
[transform rotateByDegrees:90.0];
[context saveGraphicsState];
[transform concat];
int x;
for (x = 0; x <= 10; x++) {
[[NSString stringWithFormat:@"%i", x]
drawAtPoint:NSMakePoint(((float)x * 10.0) + 0.5, -13.5)
withAttributes:attr];
}
[context restoreGraphicsState];
The NSRulerView method drawHashMarksAndLabelsInRect is passed an NSRect
which, in this case, represents the entire area of the vertical ruler,
in its own coordinate system. Typically it has an origin of {0.0, 0.0}
and a size of {16.0, 400.0} for the case when the entire vertical ruler
has to be redrawn. To see more text, I sent the message
setRuleThickness:64.0 to the vertical ruler when my custom view (which
is inside an NSScrollView) was told to awakeFromNib.
For each increase of 10.0 in the ruler's thickness, I get to see
another digit drawn up the ruler, starting with "0". The only text
which appears does so if its starting point is within the imaginary
square at the bottom of the ruler (the square's edge length is equal to
the ruler's thickness). If the string is long, it does NOT get clipped,
as long as it begins within the square. A long string can appear up the
full length of the ruler.
TIA...Erez
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.