On Jan 29, 2012, at 1:03 PM, Gus Mueller wrote:
> I have an issue where using NSLayoutManager's
> setDefaultAttachmentScaling:NSImageScaleProportionallyDown doesn't seem to
> work if I setup my own NSGraphicsContext + CGPDFContext.
>
> The problem is that large inline images are not scaled down when drawn like
> they would be in an NSTextView. Text after the image is positioned as if it
> was scaled though, so I end up with text that is drawn over an image.
>
>
> Can anyone shed some light on what I'm doing wrong?
> This is on 10.7.2 btw.
>
Hmm, I don't have an answer for you, but I looked at the code. I did a little
subclassing of NSLayoutManager, and it looks like the text attachment cell is
just ignoring the size given to draw the image in and drawing it full size.
Here's what I used:
@interface DSLayoutManager : NSLayoutManager {
}
@end
@implementation DSLayoutManager
- (void)showAttachmentCell:(NSCell *)cell inRect:(NSRect)rect
characterIndex:(NSUInteger)attachmentIndex
{
[super showAttachmentCell:cell inRect:rect characterIndex:attachmentIndex];
[NSGraphicsContext saveGraphicsState];
CGContextTranslateCTM([[NSGraphicsContext currentContext] graphicsPort], 0,
-rect.size.height);
[[NSColor blackColor] set];
[NSBezierPath strokeRect:rect];
[NSGraphicsContext restoreGraphicsState];
}
@end
Add that to the top, and change the layout manager to use it, and it'll draw
the rect the layout manager is telling the attachment cell to draw in.
Maybe there's some sort of context related setting that's different between the
text view and the PDF context?
--------------------------------------
Darkshadow
(aka Michael Nickerson)
http://www.nightproductions.net
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]