8012351: Bold fonts everywhere in GTK L&F on Ubuntu with JDK 7
Reviewed-by: bae, serb
--- a/jdk/src/share/classes/sun/font/FontFamily.java Mon Feb 10 15:02:24 2014 +0000
+++ b/jdk/src/share/classes/sun/font/FontFamily.java Tue Feb 11 10:43:15 2014 -0800
@@ -25,6 +25,7 @@
package sun.font;
+import java.io.File;
import java.awt.Font;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -105,8 +106,39 @@
return familyRank;
}
+ private boolean isFromSameSource(Font2D font) {
+ if (!(font instanceof FileFont)) {
+ return false;
+ }
+
+ FileFont existingFont = null;
+ if (plain instanceof FileFont) {
+ existingFont = (FileFont)plain;
+ } else if (bold instanceof FileFont) {
+ existingFont = (FileFont)bold;
+ } else if (italic instanceof FileFont) {
+ existingFont = (FileFont)italic;
+ } else if (bolditalic instanceof FileFont) {
+ existingFont = (FileFont)bolditalic;
+ }
+ // A family isn't created until there's a font.
+ // So if we didn't find a file font it means this
+ // isn't a file-based family.
+ if (existingFont == null) {
+ return false;
+ }
+ File existDir = (new File(existingFont.platName)).getParentFile();
+
+ FileFont newFont = (FileFont)font;
+ File newDir = (new File(newFont.platName)).getParentFile();
+ return java.util.Objects.equals(newDir, existDir);
+ }
+
public void setFont(Font2D font, int style) {
- if (font.getRank() > familyRank) {
+ /* Allow a lower-rank font only if its a file font
+ * from the exact same source as any previous font.
+ */
+ if ((font.getRank() > familyRank) && !isFromSameSource(font)) {
if (FontUtilities.isLogging()) {
FontUtilities.getLogger()
.warning("Rejecting adding " + font +
--- a/jdk/src/share/classes/sun/font/SunFontManager.java Mon Feb 10 15:02:24 2014 +0000
+++ b/jdk/src/share/classes/sun/font/SunFontManager.java Tue Feb 11 10:43:15 2014 -0800
@@ -762,7 +762,7 @@
if (family == null) {
family = new FontFamily(familyName, false, rank);
family.setFont(f, f.style);
- } else if (family.getRank() >= rank) {
+ } else {
family.setFont(f, f.style);
}
fullNameToFont.put(fontName.toLowerCase(Locale.ENGLISH), f);
@@ -853,7 +853,7 @@
if (family == null) {
family = new FontFamily(familyName, false, rank);
family.setFont(newFont, newFont.style);
- } else if (family.getRank() >= rank) {
+ } else {
family.setFont(newFont, newFont.style);
}
return newFont;