NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
- Subject: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
- From: Gus Mueller <email@hidden>
- Date: Sun, 29 Jan 2012 10:03:29 -0800
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.
Here's the abbreviated code for what I'm doing:
.. make a CGPDFContext "ctx", wrap it up in a flipped NSGraphicsContext
.. load an NSTextStorage "contents" up with my RTFD file
NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init] autorelease];
[contents addLayoutManager:layoutManager];
[layoutManager setDefaultAttachmentScaling:NSImageScaleProportionallyDown];
BOOL clipped = NO;
do {
CGContextBeginPage(ctx, &box);
CGContextTranslateCTM( ctx, 0, box.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0 );
NSTextContainer *textContainer = [[[NSTextContainer alloc] initWithContainerSize:box.size] autorelease];
[layoutManager addTextContainer:textContainer];
[layoutManager ensureLayoutForTextContainer:textContainer];
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
NSRange charRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:nil];
[layoutManager drawGlyphsForGlyphRange:glyphRange atPoint:NSZeroPoint];
clipped = (NSMaxRange(charRange) < [contents length]);
CGContextEndPage(ctx);
}
while (clipped);
.. cleanup
I've got some very simple sample code which reproduces the behavior here:
http://gusmueller.com/stuff/NSLayoutImageScalingPDFProblem.zip
Can anyone shed some light on what I'm doing wrong?
This is on 10.7.2 btw.
thanks,
-gus
--
August 'Gus' Mueller
Flying Meat Inc.
http://flyingmeat.com/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden