Sounds like a bug.

File a bug report.

Thanks,

Aki

On Jan 29, 2012, at 10:03 AM, Gus Mueller <g...@flyingmeat.com> 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.
> 
> 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 (Cocoa-dev@lists.apple.com)
> 
> 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/aki%40apple.com
> 
> This email sent to a...@apple.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to