Community
Participate
Working Groups
Our FontRegistry assumes that any FontData that we specify is valid. It makes this mistake in three places in createFont() FontData[] fixedFonts = display.getFontList(fd.getName(), false); if (isFixedFont(fixedFonts, fd)) { return new Font(display, fd); /********This test does a check and uses the FontData we have and not the one we lookup from the System. This has failed on NT for German and Japanese***********/. } FontData[] scalableFonts = display.getFontList(fd.getName(), true); if (scalableFonts.length > 0) { return new Font(display, fd); } /********This test does a check and uses the FontData we have and not the one we lookup from the System. This has failed on NT for German and Japanese***********/. } //unable to find a valid font. if (fonts.length > 0) { return new Font(display, fonts[0]); } else { //Failed to find any reasonable font. return null; /********This test returns a Font using the first value even if the first two are invalid***********/. This method should use the FontDatas we lookup by asking the display, not the ones we defined ourselves as we can't be sure it will be valid - the SWT provided ones are guaranteed. Also if we fail our lookup we should return null - the current code returns the font we defined regardless. The following methods fix these problems and have been released into the 2.0 stream /** * Creates a new font with the given font datas. */ private Font createFont(FontData[] fonts) { Display display = Display.getCurrent(); for (int i = 0; i < fonts.length; i++) { FontData fd = fonts[i]; if (fd == null) break; FontData[] fixedFonts = display.getFontList(fd.getName(), false); FontData fixedFont = getMatchingFont(fixedFonts,fd); if (fixedFont != null) { return new Font(display, fixedFont); } FontData[] scalableFonts = display.getFontList(fd.getName(), true); FontData scalableFont = getMatchingFont(scalableFonts,fd); if (scalableFont != null) { return new Font(display, scalableFont); } } //unable to find a valid font. return null; } /** * Returns the matching font from the list. Return null if it is not found. */ private FontData getMatchingFont(FontData[] fonts, FontData fd) { // Can't use FontData.equals() since some values aren't // set if a fontdata isn't used. int height = fd.getHeight(); String name = fd.getName(); for (int i = 0; i < fonts.length; i++) { FontData font = fonts[i]; if (font.getHeight() == height && font.getName().equals(name)) return font; } return null; } NOTES:
PRODUCT VERSION: 136a
This has been fixed in 20020115.