discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to know the geometry of a string on the screen ?


From: Josh Freeman
Subject: Re: How to know the geometry of a string on the screen ?
Date: Fri, 27 Oct 2017 15:34:56 -0400

I think you meant to use 'string', not '[NSString string]' - the latter returns an empty string.

stringSize=[[NSString string] sizeWithAttributes:attributes];
   ->
stringSize=[string sizeWithAttributes:attributes];


   Alternatively, since string's an NSAttributedString:

stringSize=[string sizeWithAttributes:attributes];
   ->
stringSize=[string size];


On Oct 27, 2017, at 1:49 PM, Bertrand Gmail wrote:

Hello everyone.

I want to know the length of the string @"GNUstep" on the screen with sizeWithAttributes and the following code doesn't work :

NSFont *menuFont=[NSFont menuFontOfSize:0];
NSMutableDictionary *attributes ;
attributes = [NSMutableDictionary new];
[attributes setObject :menuFont
                     forKey:NSFontAttributeName];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString: @"GNUstep" ]; [string setAttributes:attributes range:NSMakeRange(0,[string length])];
NSSize stringSize;
stringSize=[[NSString string] sizeWithAttributes:attributes];
/*Debug*/
printf("stringSize.width : %f \n", stringSize.width);
/*Debug end*/


stringSize.width returns 1 for now. Why ?

Could somone please help me ?

Cheers, Bertrand Dekoninck


_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep





reply via email to

[Prev in Thread] Current Thread [Next in Thread]