<AWT Dev> font attributes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

<AWT Dev> font attributes

Alan Snyder-3
If I run the following code (on macOS), I get no useful information.

Font[] fonts = ge.getAllFonts();
for (Font f : fonts) {
String family = f.getFamily();
if ("Lato".equals(family)) {
Map<TextAttribute,?> attributeMap = f.getAttributes();
Object o = attributeMap.get(TextAttribute.WEIGHT);
System.err.println(f.getFontName() + ": " + o);
}
}
The only attributes with non-null values are the family (which is wrong, it is the font name, e.g. Lato-Black) and the size (which is 1, as expected).

I know that other information is available, but is there a way to get it using public APIs?

If not, why not?

  Alan

Reply | Threaded
Open this post in threaded view
|

Re: <AWT Dev> font attributes

Phil Race
I'm surprised font name is reported for FAMILY - leaving aside the Apple oddity of it
being the postscript name.

Maybe a bug there but most apps will call getFamily() for that.

The attributes such as WEIGHT really should be populated.
I think that'll only be populated if you create a font specifying BOLD.
Same for POSTURE & ITALIC.

Width is one that would be useful too ..

If you'd like to file a bug it may be a good candidate to fix as it would help
apps choose fonts more intelligently.

-phil.



On 12/21/2017 10:49 AM, Alan Snyder wrote:
If I run the following code (on macOS), I get no useful information.

Font[] fonts = ge.getAllFonts();
for (Font f : fonts) {
 String family = f.getFamily();
 if ("Lato".equals(family)) {
  Map<TextAttribute,?> attributeMap = f.getAttributes();
  Object o = attributeMap.get(TextAttribute.WEIGHT);
  System.err.println(f.getFontName() + ": " + o);
 }
}
The only attributes with non-null values are the family (which is wrong, it is the font name, e.g. Lato-Black) and the size (which is 1, as expected).

I know that other information is available, but is there a way to get it using public APIs?

If not, why not?

  Alan