• 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: Getting exact height of NSAttributedString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting exact height of NSAttributedString


  • Subject: Re: Getting exact height of NSAttributedString
  • From: Ivan Kourtev <email@hidden>
  • Date: Fri, 21 Apr 2006 15:55:08 -0400

To me, the boundingRectWithSize:options: method is still completely incomprehensible as well (not to mention that its documentation omits important details).

I settled for the size method. The only "complaint" I have is that size: seems to return a bounding box that will accommodate glyphs extending below and much above the baseline (even if such glyphs are not present). So in other words, it seems to me that size will return the about the same bounding box (at least in the vertical direction) for "cara" as it will for say 'Agap'

It will be great if anyone would describe how boundingRectWithSize:options: should work.

Cheers,

--
ivan

On Apr 21, 2006, at 11:10 AM, Shawn Erickson wrote:

On 2/8/06, Aki Inoue <email@hidden> wrote:
We added a new method in Tiger exactly to solve this issue.

-[NSAttributedString boundingRectWithSize:options:].  You can specify
NSStringDrawingUsesDeviceMetrics to get union of all glyph bounds.

On 2/8/06, Aki Inoue <email@hidden> wrote:
If you don't need to limit either dimension, you can just pass
NSZeroSize.

It specify maximum bounds if the value is larger than 0.0.

I am trying to use boundingRectWithSize:options: and the documentation and real world behavior has me confused...

1) The parameter named "options" implies that I can supply multiple
options and the definition of the option constants ( ,etc.) are bits
so it looks like one should be able to OR them together however the
options parameter is defined to be the enum named
NSStringDrawingOptions which implies only one can be specified from
the set define in the enum (and the compiler flags ORing as an error).
Does it really support multiple options ORed together?

2) and I cannot seem to get it to give me what I expect.

For example given the following code I get the following log output
(textField is in an actively displayed view loaded from a nib)...

NSRect bounds = [textField bounds];
NSAttributedString* tmp = [textField attributedStringValue];
NSLog(@"Attributed String: %@", tmp);
NSLog(@"Control Bounds:%@, String Size:%@, Needed Bounds:%@",
    NSStringFromRect(bounds),
    NSStringFromSize([tmp size]),
    NSStringFromRect([tmp
boundingRectWithSize:NSMakeSize(bounds.size.width, 0.0)
        options:NSStringDrawingUsesFontLeading]));

2006-04-21 07:54:37.815 XXXXX[1764] Attributed String: Meeting ID# 107-163-059
123456789 123456789 123456789 123456789 123456789
123456789 123456789 123456789 123456789 123456789
123456789 123456789 123456789 123456789 123456789
123456789 123456789 123456789 123456789 123456789 {
NSColor = NSNamedColorSpace System controlTextColor;
NSFont = "LucidaGrande 11.00 pt. P [] (0x054dde10)
fobj=0x054ddd90, spc=3.48";
NSOriginalFont = "LucidaGrande 11.00 pt. P [] (0x054dde10)
fobj=0x054ddd90, spc=3.48";
NSParagraphStyle = Alignment 2, LineSpacing 0, ParagraphSpacing 0,
ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0,
FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0,
LineBreakMode 0, Tabs (28L, 56L, 84L, 112L, 140L, 168L, 196L, 224L,
252L, 280L, 308L, 336L), DefaultTabInterval 0, Blocks (null), Lists
(null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor
0.05, HeaderLevel 0;
}
2006-04-21 07:54:37.816 XXXXX[1764] Control Bounds:{{0, 0}, {317,
28}}, String Size:{330.403, 70}, Needed Bounds:{{0, -3}, {143.365,
14}}


As you can see the unbounded size of the attributed string is 330 by
70 yet what I get back from boundingRectWithSize:options: makes no
sense to me. If I change the "options" to
NSStringDrawingUsesDeviceMetrics I get the following...

2006-04-21 07:58:11.470 XXXXX[1919] Control Bounds:{{0, 0}, {317,
28}}, String Size:{330.403, 70}, Needed Bounds:{{86.8174, -3},
{143.41, 12}}

Which again makes no sense to me... Why did the origin change? Why is
the height and width so far off from what is needed? So far I haven't
found the right incantation to get it return something I would expect
to see.

Does this method need to be called while a particular view is focused?
Note I did try that and it made no difference that I can see.

Help :)

-Shawn
 _______________________________________________
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

_______________________________________________ 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
  • Follow-Ups:
    • Re: Getting exact height of NSAttributedString
      • From: Ricky Sharp <email@hidden>
References: 
 >Re: Getting exact height of NSAttributedString (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: NSUserDefaultsController problems
  • Next by Date: Re: Getting exact height of NSAttributedString
  • Previous by thread: Re: Getting exact height of NSAttributedString
  • Next by thread: Re: Getting exact height of NSAttributedString
  • Index(es):
    • Date
    • Thread