• 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: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ?


  • Subject: Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ?
  • From: Rua Haszard Morris <email@hidden>
  • Date: Wed, 23 Jul 2008 09:56:35 +1200

I need to support arbitrary superscript, not just squared...

I should be clear:
- I initially only set superscript attribute for the characters that are superscript, i.e. part of a larger string.
- When this attributed string was given to an NSTextField (static non editable), the textfield draws it with the baseline offset downward, so the text looks incorrectly aligned alongside a neighbouring text field.
- So, I experimented with setting NSBaselineOffsetAttributeName for the entire string to correct the problem (as I don't want to get into font and individual offset calculations unless I have to).


What I discovered was that baseline offset has three effects: above, at or below normal position, corresponding negative, zero, or positive values, which seems to conflict with the documentation. However, setting a negative value fixes my issue, so I'm happy, if a little concerned.

Note I just checked what happens if I set NSBaselineOffsetAttributeName and don't set NSSuperscriptAttributeName; it has no effect no matter what the value is...

Thanks for the info
Rua HM.

On Jul 23, 2008, at 4:43 AM, Ross Carter wrote:

The strange thing is that there only seem to be 3 baseline positions supported by NSTextField; any positive value, 0, and any negative value.


I assume you've seen this, from http://developer.apple.com/documentation/Cocoa/Conceptual/AttributedStrings/Articles/standardAttributes.html#/ /apple_ref/doc/uid/TP40004903

"The superscript attribute indicates an abstract level for both super- and subscripts. The user of the attributed string can interpret this as desired, adjusting the baseline by the same or a different amount for each level, changing the font size, or both."

Are you perhaps setting a baseline attribute _and_ a superscript attribute? It sounds like the Cocoa text system is adjusting the baseline according to its notion of superscripts and ignoring your baseline attribute value.

Personally, I don't think NSSuperscriptAttributeName is particularly useful. I just adjust the baseline and font size: newFontSize = oldFontSize * 0.75, baseline for superscript += 0.4 * oldFontSize, baseline for subscript -= 0.3 * oldFontSize.

If the only thing you need to draw is a superscript 2, I like Andrew's solution.

Ross

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ? (From: Rua Haszard Morris <email@hidden>)
 >Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ? (From: Andrew Farmer <email@hidden>)
 >Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ? (From: Ross Carter <email@hidden>)

  • Prev by Date: NSThread (was Re: NSTask)
  • Next by Date: Problem on clearing points and paths on a NSView
  • Previous by thread: Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ?
  • Next by thread: Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ?
  • Index(es):
    • Date
    • Thread