• 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
Re: Overriding HTML translation in NSAttributedString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Overriding HTML translation in NSAttributedString


  • Subject: Re: Overriding HTML translation in NSAttributedString
  • From: Douglas Davidson <email@hidden>
  • Date: Fri, 11 Nov 2005 14:34:21 -0800


On Nov 11, 2005, at 2:01 PM, Glen Simmons wrote:

I'm using NSAttributedString to get some XHTML into an NSTextView. It's working well, but I need to tweak one thing. The XHTML has some tags like this:
<img src="foo://bar.png" ...
The "foo:" scheme tells me that the image is actually part of my internal data, not a file on disk. I'd like to step in at the point when NSAttributedString is translating this into an NSTextAttachment and supply the image, rather than getting the little blue square with question mark. Is there a good way to do this?



Try this: for each of your images, create the data that would be the content of a file, if that image had been stored as a file, and a suitable filename. (What image format you use is up to you.) From that, create a WebResource with that data, the "foo://bar.png" URL, a suitable MIME type, and nil textEncodingName and frameName. Also create a WebResource for your main XHTML data, with a suitable base URL, MIME type, textEncodingName, and nil frameName. Create a WebArchive with the main resource, an array of the image resources for subresources, and nil for subframeArchives. Create your NSAttributedString from the WebArchive's -data.


If it's not convenient to get the file contents for your images, you can instead use placeholder file contents, just something sufficient to recognize the file. Then you can postprocess the attributed string, go through it looking for attachments, and replace the placeholders with the actual images.

Douglas Davidson

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Overriding HTML translation in NSAttributedString (From: Glen Simmons <email@hidden>)

  • Prev by Date: Overriding HTML translation in NSAttributedString
  • Next by Date: mlRe: Correct way to scale an NSTextView
  • Previous by thread: Overriding HTML translation in NSAttributedString
  • Next by thread: Re: Overriding HTML translation in NSAttributedString
  • Index(es):
    • Date
    • Thread