• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
      • From: Aki Inoue <email@hidden>
    • Re: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
      • From: Michael Nickerson <email@hidden>
  • Prev by Date: Re: Drag and drop in collectionview
  • Next by Date: Re: Use of Application nib file template
  • Previous by thread: Re: Subclassing IKImageView
  • Next by thread: Re: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
  • Index(es):
    • Date
    • Thread