• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: A Tab after 4 SPACEs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Tab after 4 SPACEs


  • Subject: Re: A Tab after 4 SPACEs
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 27 Mar 2008 23:53:14 +0000

On 27 Mar 2008, at 16:12, Gerriet M. Denkmann wrote:

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?

How about the following (largely untested; I did check that the glyph returned seemed sane):


  NSGlyph glyph = [usedFont glyphWithName:@"space"];
  NSSize size;

  [usedFont getAdvancements:&size forGlyphs:&glyph count:1];

("space" is the standard PostScript name for the space glyph; see, e.g. <http://www.adobe.com/devnet/opentype/archives/glyph.html>)

Alternatively you could use the Core Text function CTFontGetGlyphsForCharacters() (but you'd need a CTFontRef rather than an NSFont), or you could implement a lightweight NSGlyphStorage and use either the shared NSGlyphGenerator or the one from your layout manager.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

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


  • Follow-Ups:
    • Re: A Tab after 4 SPACEs
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >A Tab after 4 SPACEs (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: A Tab after 4 SPACEs (From: Uli Kusterer <email@hidden>)
 >Re: A Tab after 4 SPACEs (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: NSScroller question
  • Next by Date: Core Data faulting and bindings: recursive KVO notifications?
  • Previous by thread: Re: A Tab after 4 SPACEs
  • Next by thread: Re: A Tab after 4 SPACEs
  • Index(es):
    • Date
    • Thread