[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSAttributedString size
From: |
Stéphane Goujet |
Subject: |
NSAttributedString size |
Date: |
Tue, 19 Apr 2005 13:56:17 +0300 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
Hello,
I have troubles using NSAttributedString's size method to get the
area the string needs for display.
It seems that it just does not work but maybe I do not use it the
right way. The way I use it, it produces good results with Cocoa, but
very bad ones with GNUstep.
In the test program, I try to initialize the NSAttributedString :
1st, without attributes ;
2nd, with a font attribute, which should be the same as the default one
used in the 1st case ;
3rd, with a font attribute, the size of which is twice as big.
All those succeed with Cocoa, all fail with GNUstep. Any idea ?
--------------------- Linux/GNUstep results ------------------------
astr size: w=16564.000000, h=14.000000
astra H12 size: w=16564.000000, h=14.000000
astra H24 size: w=5666.000000, h=27.000000
------------------------- Cocoa results ----------------------------
astr size: w=56.000000, h=15.000000
astra H12 size: w=56.000000, h=15.000000
astra H24 size: w=112.030998, h=30.000000
------------------------ Test program ------------------------------
#include <AppKit/AppKit.h>
#include <stdio.h>
int main(void) {
NSAutoreleasePool *pool;
NSString *str;
NSAttributedString *astr, *astra;
NSFont *font;
NSArray *val;
NSArray *key;
NSDictionary *attr;
NSSize size;
pool=[NSAutoreleasePool new];
[NSApplication sharedApplication];
str=[[NSString alloc] initWithString:@"Test string"];
astr=[[NSAttributedString alloc] initWithString:str];
size=[astr size];
printf("astr size: w=%f, h=%f\n", size.width, size.height);
font=[NSFont fontWithName:@"Helvetica" size:12];
key=[[NSArray alloc] initWithObjects:NSFontAttributeName, nil];
val=[[NSArray alloc] initWithObjects:font, nil];
attr=[[NSDictionary alloc] initWithObjects:val forKeys:key];
astra=[[NSAttributedString alloc] initWithString:str attributes:attr];
size=[astra size];
printf("astra H12 size: w=%f, h=%f\n", size.width, size.height);
font=[NSFont fontWithName:@"Helvetica" size:24];
val=[[NSArray alloc] initWithObjects:font, nil];
attr=[[NSDictionary alloc] initWithObjects:val forKeys:key];
astra=[[NSAttributedString alloc] initWithString:str attributes:attr];
size=[astra size];
printf("astra H24 size: w=%f, h=%f\n", size.width, size.height);
[pool release];
return 0;
}
- NSAttributedString size,
Stéphane Goujet <=