On Wed, 11 Nov 2009 08:53:37 -0500, Bill Cheeseman <b...@cheeseman.name> said: >Over the past 5 years, according to Google, many people have asked why -[NSAttributedString boundingRectWithSize:options] does not honor the proposed height constraint, but nobody has posted the answer. Can somebody explain this to me? > >The bounding rect of myMutableAttributedString is {{0, 0}, {450.117, 1285}}, when the width is constrained to 486 and the height is not contrained (i.e., height is set to 0.0). When I eyeball the string in its window on the screen, these dimensions appear to be about right. > >With a printing page height of 612, it should take 3 pages to print. To get the bounding rect for the first page to print, I run this code fragment in my printing NSView object: > >NSSize proposedSize = NSMakeSize(486, 612); >NSLog(@"proposedSize: %@", NSStringFromSize(proposedSize)); >NSRect pageRect = [myMutableAttributedString boundingRectWithSize:proposedSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingDisableScreenFontSubstitution]; >NSLog(@"pageRect: %@", NSStringFromRect(pageRect)); > >These values are logged in the console: > >proposedSize: {486, 612] >pageRect: {{0, 0}, {450.117, 1285}} > >Why isn't pageRect being returned as something close to {{0, 0}, {450.117, 612}? -- where the 612 page height would of course be expected to come out a little less than 612 to accommodate the vertical line heights. > >Including NSStringDrawingTruncatesLastVisibleLine in options doesn't change anything. > >The documentation leaves me with the impression that the whole point of this method is to return the largest rect that will honor the size constraint by cutting off the text at the height constraint while it is being laid out within the width constraint. Have I misunderstood?
More like wishful thinking? I don't see anything in the documentation that would give you that impression. Perhaps the problem here is just a wish to avoid using the text system? It really is not at all difficult. The text system will lay out text for you in a container of a given size (if you don't want to use a view that already does this for you). See "Text System Overview," "Text Layout Programming Guide," etc. m. -- matt neuburg, phd = m...@tidbits.com, <http://www.tidbits.com/matt/> A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com