Re: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
Re: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
- Subject: Re: NSLayoutManager's setDefaultAttachmentScaling: not working in custom PDF NSContexts.
- From: Ken Ferry <email@hidden>
- Date: Tue, 31 Jan 2012 05:59:29 -0800
On Jan 31, 2012, at 5:57 AM, Ken Ferry <email@hidden> wrote:
> On Jan 30, 2012, at 3:58 PM, Gus Mueller <email@hidden> wrote:
>
>>
>> On Jan 30, 2012, at 2:22 PM, Michael Nickerson wrote:
>>
>>> 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:
>>>
>>> <snip>
>>>
>>> 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?
>>
>> That's what I was thinking, but snooping around didn't show anything obviously different between contexts.
>>
>> However, thanks to your snippet of code I've come up with a quick workaround:
>>
>> - (void)showAttachmentCell:(NSCell *)cell inRect:(NSRect)rect characterIndex:(NSUInteger)attachmentIndex {
>> [[cell image] setSize:rect.size];
>> [super showAttachmentCell:cell inRect:rect characterIndex:attachmentIndex];
>> }
>>
>> I'll file a bug on this as Aki suggests. Hopefully this workaround doesn't cause any strange side effects. Since the attributed string is never saved out, modifying the cell this way won't hurt in my case.
>
> Sounds like a good workaround, with the exception that an NSImage should only be treated as mutable right after you create it, before it's leaked out to the app at large. Calling setSize: here might affect other parts of the app, and, for example, isn't threadsafe. Something you don't know about could be drawing the image on another thread.
>
> So consider copying the image and modifying the copy, unless you know really a _lot_ about what's going on with that image.
..and it is worth noting, copying an NSImage doesn't copy its backing data, just a light shell.
-ken
>
> -Ken
> Cocoa Frameworks.. emeritus?
>
>>
>> -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
_______________________________________________
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