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?



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.length);
        int boldWidth =
Toolkit.getDefaultToolkit().getFontMetrics(bold).charsWidth(c,0,c.length);
        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

References: 
 >Mac Fonts: which can be made bold? (From: Jeremy Wood <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.