Re: Small caps in NSTextView
Re: Small caps in NSTextView
- Subject: Re: Small caps in NSTextView
- From: Ross Carter <email@hidden>
- Date: Thu, 22 Jul 2010 12:24:22 -0400
On Jul 22, 2010, at 11:44 AM, Vincent Habchi wrote:
> I'd like to highlight some text in a NSTextView by showing it in small caps. It seems this is not a standard text attribute, so this is not possible unless changing [NSTextView string] contents. Is this right?
No, you do not have to modify the string, and in fact I do not recommend it. You do have to modify the attributes on the string.
Small caps is not a trivial thing to implement, especially if you care about how they look.
Regarding how they look, there are four approaches:
(1) Just change the lowercase characters to uppercase and reduce the font size. This produces ugly text, because that is not how true small caps look.
(2) In addition to (1), tweak the weight and spacing of the small caps letters. This is better than (1), but not nearly as good as using a real small caps font. Any choice of weight and spacing adjustments will look OK in some fonts and awful in others.
(3) Use a small caps font. Some fonts, such as Hoefler Text, contain small caps characters, but you must use CTFontDescriptor functions to find them.
(4) Use (3) if possible, and fall back to (2). IMHO, this is the only acceptable approach, and it requires a good understanding of the text system.
Regarding modifying the text storage contents: the problem is not so much with changing text to small caps, but rather with changing it back. If you modify the string to change Apple to APPLE, then you cannot know whether APPLE should be changed back to Apple or apple. This problem can be solved by subclassing NSGlyphGenerator to return an uppercase character if a custom SmallCaps attribute is present in the attributed string.
Proper use of small caps lends elegance and beauty to a printed document. I'm not convinced that they look that good on a 100dpi display. Like italics, they add contextual meaning while reading a span of text. They do not necessarily orient the reader's eye on the page, as does boldface.
Depending on what you need to do, you might find that temporary attributes do a better job of drawing the eye to important runs of text. Because temporary attributes do not change the glyphs (they change color and underlining, as you see denoting misspellings), they can be set and cleared without requiring relayout of the text.
-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