Re: Font scaling and string size problem?!?
Re: Font scaling and string size problem?!?
- Subject: Re: Font scaling and string size problem?!?
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Fri, 16 Sep 2005 18:37:00 +0200
On 16.09.2005, at 15:25, Ondra Cada <email@hidden> wrote:
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?
Yes, for real fonts this should be true. Screen fonts do behave
differently.
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,
I had a similar problem once - I think the problem was that someone
substituted screen-fonts and used these for sizing.
I circumvented this problem by using a big font (≥ 18 points -
obviously at this size screen fonts either do not exist, or have same
measurements as normal fonts), calculating the size of a string in this
big font, and then scaling the sizes back to my small font.
This worked quite well for me.
Kind regards,
Gerriet.
_______________________________________________
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