• 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: Font scaling and string size problem?!?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Font scaling and string size problem?!?


  • Subject: Re: Font scaling and string size problem?!?
  • From: glenn andreas <email@hidden>
  • Date: Sat, 17 Sep 2005 16:40:55 -0500


On Sep 17, 2005, at 3:37 PM, Gerriet M. Denkmann wrote:


On 17.09.2005, at 19:49, glenn andreas wrote:



On Sep 17, 2005, at 1:53 AM, Gerriet M. Denkmann wrote:



On 17.09.2005, at 07:15, glenn andreas <email@hidden> wrote:



So as a result, the metrics of a font changes with the size in a non-
linear form for both practical and aesthetic reasons, so it would be
extremely rare if a string in 60pt text were exactly 6 times wider
than 10pt text (sometimes you're lucky if it is 6 time taller).




Well I have been lucky to find 3 of these rare fonts where "a string in 60pt text is exactly 6 times wider than 10pt text",


I found that:

[[NSFont userFontOfSize: fsize ] advancementForGlyph: [ffs glyphWithName: @"m" ]].width == 0.833008 * fsize

regardless for fsize. Tested for fsize = 3 ... 60pt in steps of 3 on Panther.

Same for systemFontOfSize: CGS LucidaGrande with a constant factor of 0.933594.
Same for CGS Times-Roman with a constant factor of 0.777832.


Could you tell me a font which actually has this non-linear behaviour you were mentioning?


Pretty much all of them. You're looking at advancementForGlyph, which isn't the same as the width of a string (since advancementForGlyph is "the nominal spacing"


Given this code, which measures the width of both 10 and 60 point versions of the same string

NSEnumerator *allFontsEnum =[[[NSFontManager sharedFontManager] availableFonts] objectEnumerator];
NSString *fontName;
NSString *testMessage = @"Hello World!";
while ((fontName = [allFontsEnum nextObject]) != NULL) {
NSFont *font10 = [NSFont fontWithName:fontName size:10.0];
NSFont *font60 = [NSFont fontWithName: fontName size:60.0];
NSSize size10 = [testMessage sizeWithAttributes:[NSDictionary dictionaryWithObject:font10 forKey:NSFontAttributeName]];
NSSize size60 = [testMessage sizeWithAttributes:[NSDictionary dictionaryWithObject:font60 forKey:NSFontAttributeName]];
NSLog(@"Font %@, 10 pt = %g, 60 pt = %g, ratio: %g",fontName, size10.width, size60.width, size60.width / size10.width);
}



Here's what I see (10.4.2):

2005-09-17 12:43:10.388 TestFontWidth[1389] Font Sathu, 10 pt = 55, 60 pt = 336.64, ratio: 6.12073
2005-09-17 12:43:10.399 TestFontWidth[1389] Font CharcoalCY, 10 pt = 61, 60 pt = 367.178, ratio: 6.01931


[...]

Well, and when I run on 10.3.9 a slightly different program:

NSEnumerator *allFontsEnum =[[[NSFontManager sharedFontManager] availableFonts] objectEnumerator];
NSString *fontName;
NSString *testMessage = @"Hello World!";
while ((fontName = [allFontsEnum nextObject]) != NULL)
{
NSFont *font10 = [NSFont fontWithName:fontName size:17.0];
NSFont *font60 = [NSFont fontWithName: fontName size:102.0];
NSSize size10 = [testMessage sizeWithAttributes:
[NSDictionary dictionaryWithObject:font10 forKey:NSFontAttributeName]];
NSSize size60 = [testMessage sizeWithAttributes:
[NSDictionary dictionaryWithObject:font60 forKey:NSFontAttributeName]];
fprintf(stderr,"ratio: %5.3f 17 pt = %6.2f, 102 pt = %6.2f, Font %s \n",
size60.width / size10.width, size10.width, size60.width,
[ fontName UTF8String ] );
}


I get:
ratio: 6.000 17 pt = 95.38, 102 pt = 572.29, Font Sathu
ratio: 6.000 17 pt = 104.03, 102 pt = 624.20, Font CharcoalCY
ratio: 6.000 17 pt = 122.42, 102 pt = 734.52, Font CourierNewPS- ItalicMT
ratio: 6.000 17 pt = 91.11, 102 pt = 546.66, Font Symbol
ratio: 6.000 17 pt = 100.47, 102 pt = 602.84, Font Futura-Medium
ratio: 6.000 17 pt = 105.88, 102 pt = 635.31, Font Charcoal
....
continues for a long time without any change in the ratio of 6.000.


My theory is that:

1. fonts should not just scale (here absolutely I agree with you)
2. fonts just scale anyway
3. fonts ≤ 16pt are replaced by screen-fonts, which, in order to have integral width, have quite different metrics. (This is the reason why my program compares 17pt and 102pt).

Tweaking a bit more, if you use 16.01 and 1601, you get a ratio of 100 (like expected), but 16.0 and 1600 gets different results. However, there isn't anything such as "screen fonts" in OS X (there use to be bitmap fonts in Classic, but everything is suppose to be outline now - and even bitmap fonts didn't have integral widths - think back to the term "fractional widths" which I hope to never have to deal with again).



So it appears that (at least on some systems) the threshold for pixel level hinting is 16.0, but that appears to be an implementation detail that one probably shouldn't depend on. Furthermore, there is no evidence that any of the default fonts include optical hinting (which would cause different results > 16.0), or if they do, that they are used, but obviously that could change as well. Perhaps asking on the printing list might yield an answer.





Glenn Andreas email@hidden <http://www.gandreas.com/> wicked fun! quadrium | build, mutate, evolve | images, textures, backgrounds, art

_______________________________________________
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


  • Follow-Ups:
    • Re: Font scaling and string size problem?!?
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >Re: Font scaling and string size problem?!? (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: Font scaling and string size problem?!? (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Font scaling and string size problem?!?
  • Next by Date: retain & release
  • Previous by thread: Re: Font scaling and string size problem?!?
  • Next by thread: Re: Font scaling and string size problem?!?
  • Index(es):
    • Date
    • Thread