Re: determining availability of a given glyph via NSFont
Re: determining availability of a given glyph via NSFont
- Subject: Re: determining availability of a given glyph via NSFont
- From: Andy <email@hidden>
- Date: Thu, 07 Feb 2002 01:31:18 -0500
Douglas Davidson wrote:
>
--if you want to determine whether a
>
particular string of characters can be represented using a particular
>
font, fixFontAttributeInRange: will tell you.
I've been thinking about this for a while, and I'm really not sure I
follow how I can use this method to detect which characters are supported.
After all, its a (void) method and there's no spec for how it does what
it does that I can find.
I'm trying to think of something I could do by adding my own class to
the NSMutableAttributedString cluster, but even then I draw a blank.
I can only think of 2 things I could do:
Is -fixFontAttributeInRange only called when Cocoa has detected that
there is work to do on a range of chars? ie, is the mere fact it gets
called at all for a range an indication that the chacters in the range
cannot be supported by the font currently set on the range? This doesn't
seem right as I note the method is called from endEditing and I guess it
just passes in all the text that changed.
My other idea is I'm supposed to override[1] this method and examine the
characters in the range before and after calling the superclass
implementation. If the font changes, the original font didn't support
the chars in the range. If the font remains the same, I can assume it
supports the chars in the range.
Hrm, so having written all that, I found this in an obscure corner of
the docs (well OK, in Accessing Attributes in the Attributed Strings topic):
NSAttributedString *attrStr;
unsigned int length;
NSRange effectiveRange;
id attributeValue;
length = [attrStr length];
effectiveRange = NSMakeRange(0, 0);
while (NSMaxRange(effectiveRange) < length) {
attributeValue = [attrStr attribute:NSFontAttributeName
atIndex:NSMaxRange(effectiveRange) effectiveRange:&effectiveRange];
[analyzer tallyCharacterRange:effectiveRange font:attributeValue];
}
(according to the docs, here "analyzer" is a ficticious class which is
going to count the characters in effective range and tally them per font encountered)
Well, this looks like pretty much what I want. But I need sleep before I
can try it, so does anyone have any comments on why this might not work
for me?
[1] obviously, this being a class cluster its probably easier to wrap an
NSMutableAttributedString and delegate to it, but let's just pretend
subclassing is the best option for the sake of discussion (unless it
needs to be a true subclass?)
One thing that should be clear from all of this: quite a few of us want
an API to work out what is in a font, and we're really not finding it
easy with what's documented at present. (stumbling over a convenitent
example is little use if its located nowgere near NSFont - its taken me
a month to find it) Perhaps this just means we need better
documentation, perhaps it means we need a better API...
--
AndyT (lordpixel - the cat who walks through walls)
A little bigger on the inside
I think we finally found the killer app for Flash: animated stick men
_______________________________________________
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.