• 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: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sun, 18 Sep 2005 00:20:10 +0200


On 17.09.2005, at 23:40, glenn andreas wrote:

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
Well, there is -[NSFont screenFont], -[NSLayoutManager setUsesScreenFonts:]

(there used to be bitmap fonts in Classic, but everything is suppose to be outline now -
There is GB18030 Bitmap and VT100 which look like bitmaps

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.



Using [NSLayoutManager setUsesScreenFonts: NO] I found out that for fonts > 8pt the ratio [ layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: textContainer ].size.width / fontSize is constant.


With setUsesScreenFonts = YES this ratio is constant for fontSize > 16pt

float fontSize ;
for( fontSize = 1.0; fontSize < 18.3; fontSize += 0.5 )
{
NSTextStorage *textStorage = [[NSTextStorage alloc] initWithString:@"Hello World!"];
[ textStorage addAttribute: NSFontAttributeName
value: [ NSFont userFontOfSize: fontSize ]
range: NSMakeRange(0, [ textStorage length ])
];


NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
NSTextContainer *textContainer = [[NSTextContainer alloc] init];
[layoutManager addTextContainer:textContainer];
[textContainer release];
[textStorage addLayoutManager:layoutManager];
[layoutManager release];
[ layoutManager setUsesScreenFonts: NO ]; // > 8pt --> scaled linear
//[ layoutManager setUsesScreenFonts: YES ]; // > 16pt --> scaled linear


NSRange glyphRange = [ layoutManager glyphRangeForTextContainer: textContainer ];
NSRect hh = [ layoutManager boundingRectForGlyphRange: glyphRange inTextContainer: textContainer ];
fprintf(stderr,"ratio: %5.3f %4.1f pt %s\n", hh.size.width / fontSize, fontSize,
[ NSStringFromSize(hh.size) UTF8String ]);
};



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


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>)
 >Re: Font scaling and string size problem?!? (From: glenn andreas <email@hidden>)

  • Prev by Date: retain & release
  • Next by Date: Starting a Spotlight search
  • Previous by thread: Re: Font scaling and string size problem?!?
  • Next by thread: Adding menus to main menu
  • Index(es):
    • Date
    • Thread