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

2008-07-22 Thread Rua Haszard Morris

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 (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 [EMAIL PROTECTED]


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

2008-07-22 Thread Martin Wierschin
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.


I do something very similar, but instead of using the font size, the  
baseline is calculated using the ascender/descender:


baseline for superscript = font ascender * 0.4
baseline for subscript = font descender * 0.35  // descender is negative

I have no idea whether this is any better than using the font size-  
both methods seem a bit makeshift.


~Martin

___

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 [EMAIL PROTECTED]


NSBaselineOffsetAttributeName support in NSTextField - bug? Re: how to prevent baseline shift when using NSSuperscriptAttributeName on a NSTextView's NSAttributedString ?

2008-07-21 Thread Rua Haszard Morris

Update:

If I set the superscript attribute for the exponent, and set a  
negative value (any negative value), the baseline is appropriate (i.e.  
lines up with surrounding controls).


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


Is this correct behaviour? The documentation for  
NSBaselineOffsetAttribute name states that:


The baseline offset attribute is a literal distance, in pixels, by  
which the characters should be shifted above the baseline (for  
positive offsets) or below (for negative offsets).
http://developer.apple.com/documentation/Cocoa/Conceptual/AttributedStrings/Articles/standardAttributes.html#/ 
/apple_ref/doc/uid/TP40004903


I like the fact that I can specify a negative number and it appears to  
correctly account for my superscript exponent, but I'm concerned that  
the value may actually be used in future, and/or there is some  
complicated interaction between the attributes. Is there documentation  
on NSTextField's support for attributed strings that explains why this  
is happening? Or should I report this as a bug?


Can anyone shed any light on why this is happening?

thanks
Rua HM.

On Jul 21, 2008, at 4:27 PM, Rua Haszard Morris wrote:

I am using NSSuperscriptAttributeName to make part of a string  
displayed in an NSTextView label display as superscript (to show to  
the power of 2). I may also use a smaller font attribute to make  
the 2 char smaller.


My problem is that thebaseline of the text drawn in the NSTextView  
is moved down (presumably to accommodate the superscript 2) and the  
label now looks wrong as the text doesn't line up with the other  
edits and labels on the line in the dialog.


Is there a correct, standard way to keep the baseline fixed when  
using an NSAttributedString in a NSTextView used as a label?


I've tried using a multi-line NSTextView, but this makes no  
difference. There is the possibility of tweaking the  
NSBaselineAttribute, or even the position of the NSTextView, but  
both approaches seem hacky or overkill (i.e. I'd need to correctly  
determine the baseline offset by querying the font superscript  
offset? and converting to pixels?)


thanks
Rua HM.
___

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/r.haszardmorris%40adinstruments.com

This email sent to [EMAIL PROTECTED]


___

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 [EMAIL PROTECTED]


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

2008-07-21 Thread Andrew Farmer

On 20 Jul 08, at 21:27, Rua Haszard Morris wrote:
I am using NSSuperscriptAttributeName to make part of a string  
displayed in an NSTextView label display as superscript (to show to  
the power of 2). I may also use a smaller font attribute to make  
the 2 char smaller.


My problem is that thebaseline of the text drawn in the NSTextView  
is moved down (presumably to accommodate the superscript 2) and the  
label now looks wrong as the text doesn't line up with the other  
edits and labels on the line in the dialog.


Is there a correct, standard way to keep the baseline fixed when  
using an NSAttributedString in a NSTextView used as a label?


Devious solution: use the ² character (U+00B2, SUPERSCRIPT TWO). There  
are characters in Unicode for superscript and subscript 0-9.___


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 [EMAIL PROTECTED]


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

2008-07-20 Thread Rua Haszard Morris
I am using NSSuperscriptAttributeName to make part of a string  
displayed in an NSTextView label display as superscript (to show to  
the power of 2). I may also use a smaller font attribute to make the  
2 char smaller.


My problem is that thebaseline of the text drawn in the NSTextView is  
moved down (presumably to accommodate the superscript 2) and the label  
now looks wrong as the text doesn't line up with the other edits and  
labels on the line in the dialog.


Is there a correct, standard way to keep the baseline fixed when using  
an NSAttributedString in a NSTextView used as a label?


I've tried using a multi-line NSTextView, but this makes no  
difference. There is the possibility of tweaking the  
NSBaselineAttribute, or even the position of the NSTextView, but both  
approaches seem hacky or overkill (i.e. I'd need to correctly  
determine the baseline offset by querying the font superscript offset?  
and converting to pixels?)


thanks
Rua HM.
___

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 [EMAIL PROTECTED]