Re: Fonts getting scaled when going XHTML -> NSAttribString
Re: Fonts getting scaled when going XHTML -> NSAttribString
- Subject: Re: Fonts getting scaled when going XHTML -> NSAttribString
- From: Douglas Davidson <email@hidden>
- Date: Fri, 18 Nov 2005 11:17:18 -0800
On Nov 18, 2005, at 9:40 AM, Glen Simmons wrote:
I'm creating an NSAttributedString from XHTML that includes style
attributes like this:
<p><font face="Times New Roman" size="4"><span style="font-size:
16pt">Times New Roman 16</span></font></p>
The attributed string gets created with the correct font, but the
size is wrong; it's increased by 33%.
Also, when I ask the attributed string for html data, it gives me
this:
<p><font face="Times New Roman" size="6" style="font: 21.3px Times
New Roman">Times New Roman 16</font></p>
which uses "px" instead of "pt". I need it to be "pt".
The source of confusion here is the manner in which CSS refers to
font sizes (and to dimensions in general). The basic CSS unit of
length is px. CSS also has what is refers to as "absolute length
units", namely in, cm, mm, pt, and pc. In practice, CSS pt is 4/3
px, and similar ratios hold for the other units; this is how browsers
behave, and so it is the de facto standard.
NSAttributedString has chosen to work exclusively in px, primarily to
synchronize the on-screen appearance of HTML between WebView and
NSTextView. If you need some other scaling of font sizes, set the
NSTextSizeMultiplierDocumentOption when creating your
NSAttributedString. If you need to use some other units in your
generated HTML, you will need to modify the output yourself.
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