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