On Jun 5, 2009, at 8:36 AM, Philip White wrote:

Is there any easy way, maybe using NSGlyphInfoAttributeName, to have a glyph not be drawn at all? Like maybe replacing it with some kind of empty glyph? You can't seem to get glyphs for invisible characters, so I don't really know how to go about this. I did a pretty extensive search, but can't seem to find much on this. When I was last working on this a few months ago, I thought I had found a discussion of this very topic, but I can't seem to locate it now. I should point out that I want to hide characters in a text view that do not cause any advancement: diacriticals and such.

As I understand it, what you want to do is not to affect layout at all, but simply to cause certain glyphs not to be displayed. In general this can be problematic, because without knowledge of the font involved one can't necessarily guarantee that a particular character will be represented by a single glyph or vice versa; if the diacritic you are interested in is only a part of a single precomposed glyph in the font, then suppressing it would be difficult. With that caveat, though, what you're asking should be possible.

There is a glyph-level attribute maintained by the layout manager via - setNotShownAttribute:forGlyphAtIndex:/ notShownAttributeForGlyphAtIndex:, that could in principle be used for something of this sort, but it is usually used exclusively by the typesetter and it might be difficult to coordinate independent use of it. What might be cleaner, if you can readily identify the glyphs you are interested in, would be to subclass NSLayoutManager and override one of the drawing methods, such as -drawGlyphsForGlyphRange:atPoint: or -showPackedGlyphs:..., and simply suppress drawing of certain glyphs.

Some issues: you would in general need to split up the range passed in and call the super method with the remaining ranges; you might need to decide what to do about decorations such as underlines or strikethroughs for the affected ranges; depending on what you were doing, you might produce odd user experiences when editing the glyphs involved. I've presented examples at past WWDCs of the use of overriding these methods to add extra decoration near or around the glyphs in question, and I would imagine they would be equally suitable to subtracting from the displayed glyphs.

Douglas Davidson

_______________________________________________

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 arch...@mail-archive.com

Reply via email to