A Tab after 4 SPACEs
A Tab after 4 SPACEs
- Subject: A Tab after 4 SPACEs
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Thu, 27 Mar 2008 09:32:44 +0100
I would like to put an NSLeftTabStopType after every 4 blanks (' '
Unicode: SPACE) into my NSTextField.
So I do:
NSFont *usedFont = [ layoutManager substituteFontForFont: font ];
float widthOfTab = [usedFont advancementForGlyph:(NSGlyph)' '].width
* 4;
and so on.
Works perfectly for Monaco or Courier.
Does not work at all for almost all other fonts.
Monaco 10.00 pt. S ... spc=6.00
advancementForGlyph = 6.000000 -- Note: same as spc above
Monaco 11.00 pt. P ... spc=6.60
advancementForGlyph = 6.601074 -- Note: printer font has (almost)
same as spc
LucidaGrande 14.00 pt. P ... spc=4.43
advancementForGlyph = 11.128906 -- looks like the real width of a
blank is more like 4.43
Times-Roman 14.00 pt. S ... spc=4.00
advancementForGlyph = 8.000000 -- 4.0 works much better.
Thonburi 10.00 pt. S ... spc=1.00
advancementForGlyph = 6.000000 -- huge difference. 1.0 is probably
correct
So I have the strong feeling that the real width of a blank (SPACE)
is the value reported by [font description] as spc=n.nn and that
either advancementForGlyph or my usage of it is somehow crooked.
How can I get the width of a SPACE in a given font?
Kind regards,
Gerriet.
P.S. Currently I am parsing [font description] but this really does
not seem the correct way.
_______________________________________________
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