• 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: Determining required physical space for a HTML segment
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining required physical space for a HTML segment


  • Subject: Re: Determining required physical space for a HTML segment
  • From: Michael Tyson <email@hidden>
  • Date: Sun, 13 May 2007 23:50:31 +1000

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!



On 13/05/2007, at 11:07 PM, Mike Tyson wrote:

Hi!

I'm working on an application that, among other things, involves the layout of items in HTML segments. I'm going to be using an algorithm that searches through the set of possible layouts for an optimum.

In order to do that though, I first need to calculate the space each HTML segment requires, and preferably for several different aspect ratios.

I see that this can be performed using plain text, at a given font/ size using NSLayoutManager (http://developer.apple.com/ documentation/Cocoa/Conceptual/TextLayout/Tasks/StringHeight.html).

This is a good start, but I would like to be able to apply it to HTML, which is far less well-behaved and homogenous.

Does anyone know of a way to take a (rebellious) chunk of HTML (possibly containing images, and maybe even flash content, and maybe with some accompanying CSS) and, for example, a desired width, and return the minimum dimensions (bounds rectangle) required to display that chunk with that width (or closest to it)?

That is, something like:

- (void)requiredDimensionsForWidth:(int)width htmlSegment:(NSString *)htmlSegment result:(NSSize *)size

or

- (void)requiredDimensionsForHeight:(int)width htmlSegment: (NSString *)htmlSegment result:(NSSize *)size

Am I being too optimistic?

Many thanks in advance,

Michael

--
Michael Tyson | michael.tyson.id.au

m: (+61) 0407 754 124
e: email@hidden


_______________________________________________

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

-- Michael Tyson | michael.tyson.id.au

m: (+61) 0407 754 124
e: email@hidden


Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________

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

  • Follow-Ups:
    • Re: Determining required physical space for a HTML segment
      • From: Douglas Davidson <email@hidden>
References: 
 >Determining required physical space for a HTML segment (From: Mike Tyson <email@hidden>)

  • Prev by Date: Re: two questions about child windows
  • Next by Date: Re:NSbezierpath segements
  • Previous by thread: Re: Determining required physical space for a HTML segment
  • Next by thread: Re: Determining required physical space for a HTML segment
  • Index(es):
    • Date
    • Thread