Re: Screen trash with some fonts
Re: Screen trash with some fonts
- Subject: Re: Screen trash with some fonts
- From: Steve Sims <email@hidden>
- Date: Fri, 14 May 2004 11:37:27 -0400
Hi Scott,
When I started writing this message I thought I could only sympathise,
since I have what I thought may be a related problem, but I think I
might have just worked out what your problem is.
As you noticed with Zapfino the letters all run together. The word
"Zapfino" does not actually come out as a single glyph though, rather
the characters just overlap.
Now one would think that the bounding box you got should contain the
entire character, but a little experimentation with TextEdit seems to
imply that it doesn't: the selection boxes for Zapfino characters do
not contain all the curly bits, just the main bulk of the character.
I'm presuming here that the selection boxes are obtained by using
boundingRectForGlyphRange.
So the solution is to discover the real bounding rectangle. :-) Off
the top of my head the way that I'd do this is to get the position of
the each character with NSLayoutManager's locationForGlyphAtIndex, and
create an NSBezierPath containing them by moving to that position and
then using appendBezierPathWithGlyph. One potential gotcha here is the
font-fixing feature of Cocoa whereby the layout management system
automatically adds font attributes for glyphs that don't exist in the
selected font, so you need to do this one character at a time reading
the font attribute. The bounding box of the bezier will be the real
bounding box.
You may find that NSFont's boundingRectForGlyph works too, and that
being the case you wouldn't need the bezier.
My own problem is how do I support a font like Wingdings or Webdings
which replace standard characters with non-standard ones. TextEdit
won't even let me type letters in this font, or enter them via the
character palette. Within my own app the character palette either
complains that it can't set the font in my app, or my app doesn't
support glyph variants. Try as I might, I can't find meaningful
documentation on supporting glyph variants. This problem isn't a high
priority for me though right now, and probably isn't at all related to
yours.
Anyway, I hope this bounding box thing works.
Good luck!
Steve
On 13 May 2004, at 17:45, Scott Thompson wrote:
I'm working with some code that draws, and more importantly erases,
text. To draw the text I am constructing my own textContainer, layout
manager, etc... then asking that whole structure to render the text
for me.
When it is time to erase the text I have just drawn, I used the same
layout structure and call the method
boundingRectForGlyphRange:inTextContainer: to try and get a rectangle
that covers the entire area to be redrawn.
It works in about 98% of the cases. There are still a few that don't
quite work. Most notably, if you use the Zapfino font and actually
type in word "Zapfino" you get a lovely swash-y swoopy ligature that I
presume is a single glyph. That glyph does not "fit" inside of the
rectangle returned by boundingRectForGlyphRange:inTextContainer:.
My understanding from reading the documentation is that
boundingRectForGlyphRange:inTextContainer: is the routine to call when
trying to invalidate the font area. Is this the case, or is there an
even better routine I should be using?
Scott
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.