Re: Issues with NSTextView Attachments
Re: Issues with NSTextView Attachments
- Subject: Re: Issues with NSTextView Attachments
- From: Kyle Sluder <email@hidden>
- Date: Sat, 10 Aug 2013 12:40:25 -0700
On Sat, Aug 10, 2013, at 10:31 AM, Gordon Apple wrote:
> Using NSTextView¹s native ability to embed image attachments, we have
> successfully implemented resizing of the image by using a resizable frame
> with a drag handle, and using setSize on the NSImage. Works great. Only
> one problem, re-archiving the NSAttributableString loses the image size
> change. Any way to fix this? Internally, in a CoreData auxiliary file
> folder, we archive NSAttributableString. Would we be better off storing
> it
> as RTFD?
You could store it as a custom attribute on the attachment character.
>
> I also see allusions to subclasses of NSTextAttachment, but I see no way
> to
> tell NSTextView, or its associates, to use such a subclass.
You will need to create the attachment object yourself and assign it as
the value of the NSTextAttachmentAttributeName for the attachment
character.
You could do this in an implementation of -[<NSTextDelegate>
didChangeText:] so that user drag-and-drop of images still results in
your custom attachment class being created.
> NSTextAttachmentCell is a protocol. But who adopts this protocol? For
> an
> image, is this really a NSImageCell adopting this protocol? Or is it the
> NSTextAttachment? Confusion here. Documentation on attachments is
> sparse.
The current architecture dates back to when NSCell was a useful class to
instantiate directly. I believe NSCell still implements
<NSTextAttachmentCell>, but it might actually be NSImageCell. But yes,
that's the gist of the design.
>
> We would also like to have the ability to set the baseline when an image
> is
> inserted, and change it when the image is resized. Certain
> NSPDFImageReps
> contain baseline info in private dictionaries, which we would like to
> use,
> when available. In view of the above, should we abandon NSTextView¹s
> paste/drag-in capabilities for images and override all the relevant
> methods
> to do our own attachment inserts using a custom NSAttachment class?
Maybe. See above for one idea of how to continue using NSTextView's drag
and drop support.
>
> Related question about NSImage. I¹ve never understood setSize in
> NSImage.
> Does this just affect the cached image, or does it have any impact on the
> underlying imageRep, such as resizing and remapping a bitmap?
NSImage.size is a semantic property. It tells the caller how big the
image is in device-independent points. It is no longer related to
caching. See the App Kit release notes for 10.6, section titled "NSImage
Behavior: Simplifying caching and related interfaces":
<https://developer.apple.com/library/mac/releasenotes/Cocoa/AppKitOlderNotes.html>
>
> One more: I¹ve never found a straightforward way to make a textView
> re-layout all or a portion of the text. The best way I¹ve found is to
> call
> textContainerChangedGeometry. Works, but seems rather obtuse.
NSLayoutManager has many invalidation methods.
--Kyle Sluder
_______________________________________________
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