Re: A Tab after 4 SPACEs
Re: A Tab after 4 SPACEs
- Subject: Re: A Tab after 4 SPACEs
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Thu, 27 Mar 2008 17:12:36 +0100
On 27 Mar 2008, at 10:08, Uli Kusterer wrote:
On 27.03.2008, at 09:32, Gerriet M. Denkmann wrote:
float widthOfTab = [usedFont advancementForGlyph:(NSGlyph)'
'].width * 4;
I'm pretty new to the text engine myself, but I don't think an
NSGlyph can be generated by typecasting a char. Since Monaco or
Courier are monospaced, it just so happens that you get the same
width as the space would be. But the glyph with number 0x20 is
probably a completely different width than the glyph corresponding
to a space in other languages.
Yes. You are certainly right. Silly mistake of mine.
There should be something like: -[NSFont glyphForChar: (NSString *)
aString ] which returns NSNotFound if the font does not contain the
first char in aString.
But I did not find any such method.
Have you tried asking the glyph storage (I think that's a category
that the layout manager adheres to, or maybe it was the text
storage) for the correct glyph for the character ' ' ?
Current I am using:
NSString *dummyString = [ NSString stringWithUTF8String: " " ];
NSTextView *dummyTextView = [ [ NSTextView alloc ] initWithFrame:
NSMakeRect(0,0,1e4,1e4) ];
[ dummyTextView setString: dummyString ];
[ dummyTextView setFont: usedFont ];
NSLayoutManager *dummyLayoutManager = [ dummyTextView layoutManager ];
[ dummyLayoutManager setUsesScreenFonts: useScreenFont ];
unsigned int length = [ dummyString length ];
NSRange glyphRange = [ dummyLayoutManager
glyphRangeForCharacterRange: NSMakeRange(0,length)
actualCharacterRange: NULL ];
unsigned int glyphIndex = glyphRange.location;
NSTextContainer *aTextContainer = [ dummyLayoutManager
textContainerForGlyphAtIndex: glyphIndex effectiveRange: NULL ];
NSRect boundingRect = [ dummyLayoutManager
boundingRectForGlyphRange: glyphRange inTextContainer:
aTextContainer];
[dummyTextView release];
float widtOfDummyString = boundingRect.size.width;
This looks incredible clumsy. Do you know of any better way?
Kind regards,
Gerriet.
_______________________________________________
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