Re: Determining required physical space for a HTML segment
Re: Determining required physical space for a HTML segment
- Subject: Re: Determining required physical space for a HTML segment
- From: Douglas Davidson <email@hidden>
- Date: Mon, 14 May 2007 10:12:47 -0700
On May 13, 2007, at 6:50 AM, Michael Tyson wrote:
To partially answer myself:
I should've noticed this earlier, but it turns out
NSAttributedString has a method which is added by WebKit.
- (id)initWithHTML:(NSData *)data baseURL:(NSURL *)aURL
documentAttributes:(NSDictionary **)docAttributes
Local docs link:
file:///Developer/ADC Reference Library/documentation/Cocoa/
Reference/ApplicationKit/Classes/NSAttributedString_AppKitAdditions/
Reference/Reference.html
This method doesn't work too badly - images are displayed and
tables and font stuff all works. CSS support seems to be primitive
at best, and there appears to be no support for image alignment.
Still, it's a start, although it will only give an approximate value.
Here's a test app with it working (NSLogs the calculated
dimensions): http://michael.tyson.id.au/files/HTMLRead.zip
If anyone else knows a more refined technique, please let me know!
The NSAttributedString method you mention is not added by WebKit, but
it uses WebKit to import HTML into attributed string format. The
word "import" is significant here; the representation of the HTML is
limited to those features that are supported by AppKit's
NSAttributedString attributes. If you want a full faithful rendering
of the HTML, you must use WebKit directly. I'm not sure whether you
can get the sizing information you want from WebKit, but as a general
rule, anything you could obtain using Javascript within a web page in
Safari is available from WebKit using the DOM APIs and so forth.
Douglas Davidson
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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