Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mac Fonts: which can be made bold?



Hmmm.  Thanks.  This seems to work fine.

Which is strange in itself, because using a similar approach with these non-deprecated methods failed:
java.awt.Font.getLineMetrics(...)
java.awt.Font.createGlyphVector(...)


(At least they failed for Comic Sans, which is a a big deal for us since one of our programs only uses websafe fonts.)

On Aug 16, 2005, at 1:45 PM, Gary Dusbabek wrote:

On 8/16/05, Jeremy Wood <email@hidden> wrote:

Does anyone know of a similar approach we can try to see if a font supports the bold attribute on Mac?



If you don't mind another hack, and are willing to assume that glyph widths for bold fonts are naturally wider than plain fonts, this will work...

private static boolean hasBold(String fontName)
{
Font bold = new Font(fontName,Font.BOLD,36);
Font normal = new Font(fontName,Font.PLAIN,36);
char[] c = {'a','b','c','d','e','f','g'};
int normalWidth =
Toolkit.getDefaultToolkit().getFontMetrics(normal).charsWidth(c,0,c.len gth);
int boldWidth =
Toolkit.getDefaultToolkit().getFontMetrics(bold).charsWidth(c,0,c.lengt h);
return boldWidth > normalWidth;
}


Keep in mind that Toolkit.getFontMetrics(...) is deprecated.  I tried
it with "Times" (returns true) and "Geneva" (returns false).  I don't
know that the assumptions I have made will always hold though.

Gary Dusbabek
Digital Technology International
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/ email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Mac Fonts: which can be made bold? (From: Jeremy Wood <email@hidden>)
 >Re: Mac Fonts: which can be made bold? (From: Gary Dusbabek <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.