The problem is that many fonts do not define super- and indexes or have some pretty funky (speaking incorrect) metrics for it.
A possible workaround is fake, as using the method below (in the category in NSMutableAttributedString). It has some disadvantages:
- The stroke width is not perfect, especially for large font sizes
- Harder to undo
- The calculated size and offset may not be ideal for some fonts.
On the positive side, this should work for all fonts, and if necessary, can be changed for certain purposes.
- (void)fakeSuperOrSubScript:(BOOL)superscript range:(NSRange)range defaultFont:(NSFont *)defaultFont { NSFontManager *fm=[NSFontManager sharedFontManager]; NSFont *font=[self attribute:NSFontAttributeName atIndex:range.location effectiveRange:NULL ]; if(!font) font=defaultFont; if(!font) { NSLog(@"ERROR: fakeSuperOrSubScript has no font to use!"); return; }
source share