diff options
author | Kim Horne | 2004-11-08 16:52:15 +0000 |
---|---|---|
committer | Kim Horne | 2004-11-08 16:52:15 +0000 |
commit | dcd6ff837faea8d9dfc6537c9de1743646db7625 (patch) | |
tree | 31da6c363132541a9db42c84d1a994aef7ec0b96 /bundles/org.eclipse.jface/src | |
parent | 395752c69c18e611d18b31d3c7da61039de22c60 (diff) | |
download | eclipse.platform.ui-dcd6ff837faea8d9dfc6537c9de1743646db7625.tar.gz eclipse.platform.ui-dcd6ff837faea8d9dfc6537c9de1743646db7625.tar.xz eclipse.platform.ui-dcd6ff837faea8d9dfc6537c9de1743646db7625.zip |
Fix for 56973 - [Themes] FontRegistry.bestDataArray() chops off all but the first "good" font
Diffstat (limited to 'bundles/org.eclipse.jface/src')
-rw-r--r-- | bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FontFieldEditor.java | 2 | ||||
-rw-r--r-- | bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java | 49 |
2 files changed, 48 insertions, 3 deletions
diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FontFieldEditor.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FontFieldEditor.java index 3af1a8842cc..9a9f93cb9bc 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FontFieldEditor.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/preference/FontFieldEditor.java @@ -354,7 +354,7 @@ public class FontFieldEditor extends FieldEditor { * @param font The FontData[] to update with. */ private void updateFont(FontData font[]) { - FontData[] bestFont = JFaceResources.getFontRegistry().bestDataArray( + FontData[] bestFont = JFaceResources.getFontRegistry().filterData( font, valueControl.getDisplay()); //if we have nothing valid do as best we can diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java index 44ece6c50b3..20c2c0b1f26 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FontRegistry.java @@ -379,6 +379,8 @@ public class FontRegistry extends ResourceRegistry { * Find the first valid fontData in the provided list. * If none are valid return the first one regardless. * If the list is empty return null. + * @deprecated use filterData in order to preserve + * multiple entry fonts on Motif */ public FontData[] bestDataArray(FontData[] fonts, Display display) { @@ -391,6 +393,49 @@ public class FontRegistry extends ResourceRegistry { return datas; } } + + /** + * Removes from the list all fonts that do not exist in this system. + * If none are valid, return the first irregardless. If the list is + * empty return <code>null</code>. + * + * @param fonts the fonts to check + * @param display the display to check against + * @return the list of fonts that have been found on this system + * @since 3.1 + */ + public FontData [] filterData(FontData [] fonts, Display display) { + ArrayList good = new ArrayList(fonts.length); + for (int i = 0; i < fonts.length; i++) { + FontData fd = fonts[i]; + + if (fd == null) + continue; + + FontData[] fixedFonts = display.getFontList(fd.getName(), false); + if (isFixedFont(fixedFonts, fd)) { + good.add(fd); + } + + FontData[] scalableFonts = display.getFontList(fd.getName(), true); + if (scalableFonts.length > 0) { + good.add(fd); + } + } + + + //None of the provided datas are valid. Return the + //first one as it is at least the first choice. + if (good.isEmpty() && fonts.length > 0) { + good.add(fonts[0]); + } + else if (fonts.length == 0) { + return null; + } + + return (FontData[]) good.toArray(new FontData[good.size()]); + } + /** * Creates a new font with the given font datas or <code>null</code> @@ -402,8 +447,8 @@ public class FontRegistry extends ResourceRegistry { if (display == null) return null; - FontData[] validData = bestDataArray(fonts, display); - if (validData == null) { + FontData[] validData = filterData(fonts, display); + if (validData.length == 0) { //Nothing specified return null; } else { |