On Thu, Jan 24, 2013, at 11:52 AM, Kyle Sluder wrote:
> > I expect this method to tell me the size of a rectangle (e.g. a bitmap
> > context) such that if I draw my attributed string into that rectangle, it
> > will all fit. When I say "all" I mean "all", including the margins.
> 
> Considering the method is named -boundingRect…, I wouldn't expect this.
> What you're looking for is the line fragment rect, and I can understand
> why you would think passing NSStringDrawingUsesLineFragmentOrigin as an
> option would yield this information. Instead, it seems to offer the
> bounding rect of the glyph range in line fragment coordinates, which I
> would surmise is more useful information in NSStringDrawing's primary
> intended use cases.

Huh, I just tried this in python and I got results that more closely
match _your_ expectation, not _mine_:

>>> ps = AppKit.NSMutableParagraphStyle.alloc().init()
>>> ps.setHeadIndent_(20)
>>> ps.setFirstLineHeadIndent_(30)
>>> attrs = {AppKit.NSParagraphStyleAttributeName : ps}
>>> attributedString = 
>>> Foundation.NSAttributedString.alloc().initWithString_attributes_("A", attrs)
>>> attributedString.boundingRectWithSize_options_(Foundation.NSMakeSize(1000, 
>>> 1000), AppKit.NSStringDrawingUsesLineFragmentOrigin)
<NSRect origin=<NSPoint x=0.0 y=0.0> size=<NSSize width=38.00390625
height=15.0>>

>>> attributedString.boundingRectWithSize_options_(Foundation.NSMakeSize(1000, 
>>> 1000), 0)
<NSRect origin=<NSPoint x=0.0 y=-3.0> size=<NSSize width=8.00390625
height=15.0>>

Note that when I pass NSStringDrawingUsesLineFragmentOrigin, I get a
width of 38 points, whereas if I omit it, I get a width of 8.

But if I then add a tailIndent of 40, my metrics don't grow at all:

>>> ps.setTailIndent_(40)
>>> attributedString.boundingRectWithSize_options_(Foundation.NSMakeSize(1000, 
>>> 1000), AppKit.NSStringDrawingUsesLineFragmentOrigin)
<NSRect origin=<NSPoint x=0.0 y=0.0> size=<NSSize width=38.00390625
height=15.0>>

>>> attributedString.boundingRectWithSize_options_(Foundation.NSMakeSize(1000, 
>>> 1000), 0)
<NSRect origin=<NSPoint x=0.0 y=-3.0> size=<NSSize width=8.00390625
height=15.0>>

So my current theory is that the advancement of the glyph is taken into
account when computing the glyph's bounding box in line fragment origin
mode. But that makes me a little surprised that the x-coordinate of the
origin of the baseline-relative rect is 0 in all cases; I would expect
it to include the glyph advancement (30).

--Kyle Sluder

_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to