Font scaling and string size problem?!?
Font scaling and string size problem?!?
- Subject: Font scaling and string size problem?!?
- From: Ondra Cada <email@hidden>
- Date: Fri, 16 Sep 2005 12:12:52 +0200
Hello all,
I've always thought that fonts scale linearly, in the sense that if
"XYZ" in 10pt font happens to be an inch wide, then in the same font
scaled to 20pt it would be two inches. Right?
Wrong.
Or I am overlooking something pretty basic and important... anyway,
here's a simple example, Mac OS X 10.4.1:
359 /tmp> <q.m
#import <Cocoa/Cocoa.h>
int main() {
[NSAutoreleasePool new];
double size=5.5,scale=10./9.;
NSFont *normal=[NSFont fontWithName:@"Helvetica" size:size];
NSFont *scaled=[NSFont fontWithName:@"Helvetica"
size:size*scale];
NSString *s=@"0123456789 OOPS: This doesn't seem to work
quite right!";
NSLog(@"scaled after: %f",[normal widthOfString:s]*scale);
NSLog(@"scaled before: %f",[scaled widthOfString:s]);
return 0;
}
360 /tmp> cc -Wall -framework Cocoa q.m && ./a.out
2005-09-16 11:53:02.042 a.out[27121] scaled after: 148.888889
2005-09-16 11:53:02.048 a.out[27121] scaled before: 181.000000
361 /tmp>
What do I do wrong? (There's kinda similar problem with font heights.)
If this is my fault, please, help me to fix it. If it happens to be a
Cocoa font fault, is there a known work-around?
The reason is plain -- I need to generate some graphics including
texts in different preview sizes; the fact that text widths do not
scale the same way as (say) plain rectangles makes a *very big* problem.
(I've considered creating a fixed-size PDF result and scale it later,
but I am afraid it would be next to impossible, since the complete
graphics contains also some bitmap images selected on-the-fly
depending on the current resolution. So far, I haven't been able to
find another work-around... perhaps creating the fixed-size PDF with
texts and vector graphics, scale it, and only then superimpose all
the bitmaps, but that would be *lotta* work changing the current
code :( )
Thanks a big lot for any advice,
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden