• 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: -[NSAttributedString initWithData:...] compresses spaces?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSAttributedString initWithData:...] compresses spaces?


  • Subject: Re: -[NSAttributedString initWithData:...] compresses spaces?
  • From: Glen Simmons <email@hidden>
  • Date: Thu, 27 Apr 2006 17:34:02 -0500


On Apr 27, 2006, at 5:28 PM, Douglas Davidson wrote:


On Apr 27, 2006, at 3:12 PM, Glen Simmons wrote:

I'm using -[NSAttributedString initWithData:options:documentAttributes:error:] with some XHTML that looks like this:
<html xmlns="http://www.w3.org/1999/xhtml";>
<p>
<font face="Lucida Grande" size="5">a</font>
<font face="Garamond" size="5"> </font>
<font face="Lucida Grande" size="5">a</font>
</p>
</html>


The problem is that the NSAttributedString I end up with only has one space between the two a's instead of the 4 that it should. How can I get it to preserve the spaces?


NSAttributedString is behaving correctly here; any browser would do the same. If you like you could spend some quality time with the HTML, XHTML, and XML specs, and find out exactly what they specify with regard to treatment of whitespace, but I warn you that it's not pretty.


The usual way to get multiple spaces in HTML is to use non-breaking spaces (either literal or &nbsp; entities), or a mixture of nbsp and ordinary spaces, in such a way as never to have consecutive ordinary spaces. That's what NSAttributedString does when it writes out HTML.

If you really want your whitespace to be read in as ordinary spaces rather than as nbsp and spaces, there is an Apple-specific mechanism for that. Surround your mixture of nbsp and spaces with <span class="Apple-converted-space"></span>, and it will be converted back into spaces when NSAttributedString reads it in.

Try saving as HTML in TextEdit, and you'll see all of this in action. You can control what flavor of HTML is generated, and whether <span class="Apple-converted-space"> is used, by manipulating the "HTML saving options" in the "Open and Save" portion of TextEdit's preferences.

As usual, Douglas is there with the answer. :) I kind of figured it was something like that. Thanks for the info.


Glen
_______________________________________________
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: 
 >-[NSAttributedString initWithData:...] compresses spaces? (From: Glen Simmons <email@hidden>)
 >Re: -[NSAttributedString initWithData:...] compresses spaces? (From: Douglas Davidson <email@hidden>)

  • Prev by Date: Re: call C application
  • Next by Date: How to select last inserted item in table with core data
  • Previous by thread: Re: -[NSAttributedString initWithData:...] compresses spaces?
  • Next by thread: How to access the value that a pointer is pointing to
  • Index(es):
    • Date
    • Thread