use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.
the class PangoFonts method lookupFont.
/**
* Parses a String containing a pango font description and returns
* a Font object.
*
* @param pangoName a String describing a pango font
* e.g. "Sans Italic 10"
* @return a Font object as a FontUIResource
* or null if no suitable font could be created.
*/
static Font lookupFont(String pangoName) {
String family = "";
int style = Font.PLAIN;
int size = 10;
StringTokenizer tok = new StringTokenizer(pangoName);
while (tok.hasMoreTokens()) {
String word = tok.nextToken();
if (word.equalsIgnoreCase("italic")) {
style |= Font.ITALIC;
} else if (word.equalsIgnoreCase("bold")) {
style |= Font.BOLD;
} else if (CHARS_DIGITS.indexOf(word.charAt(0)) != -1) {
try {
size = Integer.parseInt(word);
} catch (NumberFormatException ex) {
}
} else {
if (family.length() > 0) {
family += " ";
}
family += word;
}
}
/*
* Java 2D font point sizes are in a user-space scale of 72dpi.
* GTK allows a user to configure a "dpi" property used to scale
* the fonts used to match a user's preference.
* To match the font size of GTK apps we need to obtain this DPI and
* adjust as follows:
* Some versions of GTK use XSETTINGS if available to dynamically
* monitor user-initiated changes in the DPI to be used by GTK
* apps. This value is also made available as the Xft.dpi X resource.
* This is presumably a function of the font preferences API and/or
* the manner in which it requests the toolkit to update the default
* for the desktop. This dual approach is probably necessary since
* other versions of GTK - or perhaps some apps - determine the size
* to use only at start-up from that X resource.
* If that resource is not set then GTK scales for the DPI resolution
* reported by the Xserver using the formula
* DisplayHeight(dpy, screen) / DisplayHeightMM(dpy, screen) * 25.4
* (25.4mm == 1 inch).
* JDK tracks the Xft.dpi XSETTINGS property directly so it can
* dynamically change font size by tracking just that value.
* If that resource is not available use the same fall back formula
* as GTK (see calculation for fontScale).
*
* GTK's default setting for Xft.dpi is 96 dpi (and it seems -1
* apparently also can mean that "default"). However this default
* isn't used if there's no property set. The real default in the
* absence of a resource is the Xserver reported dpi.
* Finally this DPI is used to calculate the nearest Java 2D font
* 72 dpi font size.
* There are cases in which JDK behaviour may not exactly mimic
* GTK native app behaviour :
* 1) When a GTK app is not able to dynamically track the changes
* (does not use XSETTINGS), JDK will resize but other apps will
* not. This is OK as JDK is exhibiting preferred behaviour and
* this is probably how all later GTK apps will behave
* 2) When a GTK app does not use XSETTINGS and for some reason
* the XRDB property is not present. JDK will pick up XSETTINGS
* and the GTK app will use the Xserver default. Since its
* impossible for JDK to know that some other GTK app is not
* using XSETTINGS its impossible to account for this and in any
* case for it to be a problem the values would have to be different.
* It also seems unlikely to arise except when a user explicitly
* deletes the X resource database entry.
* There also some other issues to be aware of for the future:
* GTK specifies the Xft.dpi value as server-wide which when used
* on systems with 2 distinct X screens with different physical DPI
* the font sizes will inevitably appear different. It would have
* been a more user-friendly design to further adjust that one
* setting depending on the screen resolution to achieve perceived
* equivalent sizes. If such a change were ever to be made in GTK
* we would need to update for that.
*/
double dsize = size;
int dpi = 96;
Object value = Toolkit.getDefaultToolkit().getDesktopProperty("gnome.Xft/DPI");
if (!(value instanceof Integer)) {
value = GTKEngine.INSTANCE.getSetting(GTKEngine.Settings.GTK_XFT_DPI);
}
if (value instanceof Integer) {
dpi = ((Integer) value).intValue() / 1024;
if (dpi == -1) {
dpi = 96;
}
if (dpi < 50) {
/* 50 dpi is the minimum value gnome allows */
dpi = 50;
}
/* The Java rasteriser assumes pts are in a user space of
* 72 dpi, so we need to adjust for that.
*/
dsize = ((double) (dpi * size) / 72.0);
} else {
/* If there's no property, GTK scales for the resolution
* reported by the Xserver using the formula listed above.
* fontScale already accounts for the 72 dpi Java 2D space.
*/
dsize = size * fontScale;
}
/* Round size to nearest integer pt size */
size = (int) (dsize + 0.5);
if (size < 1) {
size = 1;
}
String fcFamilyLC = family.toLowerCase();
if (FontUtilities.mapFcName(fcFamilyLC) != null) {
/* family is a Fc/Pango logical font which we need to expand. */
Font font = FontUtilities.getFontConfigFUIR(fcFamilyLC, style, size);
font = font.deriveFont(style, (float) dsize);
return new FontUIResource(font);
} else {
/* It's a physical font which we will create with a fallback */
Font font = new Font(family, style, size);
/* a roundabout way to set the font size in floating points */
font = font.deriveFont(style, (float) dsize);
FontUIResource fuir = new FontUIResource(font);
return FontUtilities.getCompositeFontUIResource(fuir);
}
}
use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.
the class FontUtilities method getCompositeFontUIResource.
public static FontUIResource getCompositeFontUIResource(Font font) {
FontUIResource fuir = new FontUIResource(font);
Font2D font2D = FontUtilities.getFont2D(font);
if (!(font2D instanceof PhysicalFont)) {
/* Swing should only be calling this when a font is obtained
* from desktop properties, so should generally be a physical font,
* an exception might be for names like "MS Serif" which are
* automatically mapped to "Serif", so there's no need to do
* anything special in that case. But note that suggested usage
* is first to call fontSupportsDefaultEncoding(Font) and this
* method should not be called if that were to return true.
*/
return fuir;
}
FontManager fm = FontManagerFactory.getInstance();
Font2D dialog = fm.findFont2D("dialog", font.getStyle(), FontManager.NO_FALLBACK);
// Should never be null, but MACOSX fonts are not CompositeFonts
if (dialog == null || !(dialog instanceof CompositeFont)) {
return fuir;
}
CompositeFont dialog2D = (CompositeFont) dialog;
PhysicalFont physicalFont = (PhysicalFont) font2D;
ConcurrentHashMap<PhysicalFont, CompositeFont> compMap = compMapRef.get();
if (compMap == null) {
// Its been collected.
compMap = new ConcurrentHashMap<PhysicalFont, CompositeFont>();
compMapRef = new SoftReference(compMap);
}
CompositeFont compFont = compMap.get(physicalFont);
if (compFont == null) {
compFont = new CompositeFont(physicalFont, dialog2D);
compMap.put(physicalFont, compFont);
}
FontAccess.getFontAccess().setFont2D(fuir, compFont.handle);
/* marking this as a created font is needed as only created fonts
* copy their creator's handles.
*/
FontAccess.getFontAccess().setCreatedFont(fuir);
return fuir;
}
use of javax.swing.plaf.FontUIResource in project jdk8u_jdk by JetBrains.
the class FontUtilities method getFontConfigFUIR.
/* This is called by Swing passing in a fontconfig family name
* such as "sans". In return Swing gets a FontUIResource instance
* that has queried fontconfig to resolve the font(s) used for this.
* Fontconfig will if asked return a list of fonts to give the largest
* possible code point coverage.
* For now we use only the first font returned by fontconfig, and
* back it up with the most closely matching JDK logical font.
* Essentially this means pre-pending what we return now with fontconfig's
* preferred physical font. This could lead to some duplication in cases,
* if we already included that font later. We probably should remove such
* duplicates, but it is not a significant problem. It can be addressed
* later as part of creating a Composite which uses more of the
* same fonts as fontconfig. At that time we also should pay more
* attention to the special rendering instructions fontconfig returns,
* such as whether we should prefer embedded bitmaps over antialiasing.
* There's no way to express that via a Font at present.
*/
public static FontUIResource getFontConfigFUIR(String fcFamily, int style, int size) {
String mapped = mapFcName(fcFamily);
if (mapped == null) {
mapped = "sansserif";
}
FontUIResource fuir;
FontManager fm = FontManagerFactory.getInstance();
if (fm instanceof SunFontManager) {
SunFontManager sfm = (SunFontManager) fm;
fuir = sfm.getFontConfigFUIR(mapped, style, size);
} else {
fuir = new FontUIResource(mapped, style, size);
}
return fuir;
}
use of javax.swing.plaf.FontUIResource in project Botnak by Gocnak.
the class GraphiteDefaultTheme method setUpColor.
public void setUpColor() {
super.setUpColor();
// showFocusFrame = true;
foregroundColor = black;
backgroundColor = new ColorUIResource(224, 224, 224);
backgroundColorLight = white;
backgroundColorDark = lightGray;
alterBackgroundColor = new ColorUIResource(220, 220, 220);
disabledForegroundColor = new ColorUIResource(128, 128, 128);
disabledBackgroundColor = new ColorUIResource(240, 240, 240);
inputBackgroundColor = white;
inputForegroundColor = black;
selectionForegroundColor = white;
selectionBackgroundColor = new ColorUIResource(80, 80, 80);
selectionBackgroundColorLight = new ColorUIResource(96, 96, 96);
selectionBackgroundColorDark = new ColorUIResource(64, 64, 64);
focusColor = orange;
focusCellColor = orange;
frameColor = new ColorUIResource(144, 144, 144);
gridColor = new ColorUIResource(200, 200, 200);
rolloverColor = orange;
rolloverColorLight = new ColorUIResource(255, 213, 113);
rolloverColorDark = new ColorUIResource(240, 168, 0);
buttonForegroundColor = black;
buttonBackgroundColor = extraLightGray;
buttonColorLight = white;
buttonColorDark = extraLightGray;
controlForegroundColor = black;
controlBackgroundColor = extraLightGray;
controlShadowColor = new ColorUIResource(164, 164, 164);
controlDarkShadowColor = new ColorUIResource(64, 64, 64);
controlColorLight = new ColorUIResource(96, 96, 96);
controlColorDark = new ColorUIResource(40, 40, 40);
windowTitleForegroundColor = white;
windowTitleBackgroundColor = gray;
windowTitleColorLight = new ColorUIResource(88, 88, 88);
windowTitleColorDark = new ColorUIResource(24, 24, 24);
windowBorderColor = black;
windowIconColor = white;
windowIconShadowColor = black;
windowIconRolloverColor = orange;
windowInactiveTitleForegroundColor = white;
windowInactiveTitleBackgroundColor = new ColorUIResource(224, 224, 224);
windowInactiveTitleColorLight = new ColorUIResource(64, 64, 64);
windowInactiveTitleColorDark = new ColorUIResource(0, 0, 0);
windowInactiveBorderColor = black;
menuForegroundColor = black;
menuBackgroundColor = new ColorUIResource(240, 240, 240);
menuSelectionForegroundColor = black;
menuSelectionBackgroundColor = new ColorUIResource(32, 32, 32);
menuSelectionBackgroundColorLight = new ColorUIResource(255, 213, 113);
menuSelectionBackgroundColorDark = new ColorUIResource(240, 168, 0);
menuColorLight = new ColorUIResource(240, 240, 240);
menuColorDark = new ColorUIResource(220, 220, 220);
toolbarForegroundColor = black;
toolbarBackgroundColor = backgroundColor;
toolbarColorLight = menuColorLight;
toolbarColorDark = menuColorDark;
tabAreaBackgroundColor = backgroundColor;
tabSelectionForegroundColor = white;
desktopColor = backgroundColor;
tooltipForegroundColor = black;
tooltipBackgroundColor = yellow;
controlFont = new FontUIResource("Dialog", Font.PLAIN, 13);
systemFont = new FontUIResource("Dialog", Font.PLAIN, 13);
userFont = new FontUIResource("Dialog", Font.PLAIN, 13);
smallFont = new FontUIResource("Dialog", Font.PLAIN, 12);
menuFont = new FontUIResource("Dialog", Font.PLAIN, 13);
windowTitleFont = new FontUIResource("Dialog", Font.BOLD, 13);
}
use of javax.swing.plaf.FontUIResource in project intellij-community by JetBrains.
the class TogglePresentationModeAction method tweakUIDefaults.
private static void tweakUIDefaults(UISettings settings, boolean inPresentation) {
UIDefaults defaults = UIManager.getDefaults();
Enumeration<Object> keys = defaults.keys();
if (inPresentation) {
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof String) {
String name = (String) key;
if (name.endsWith(".font")) {
Font font = defaults.getFont(key);
ourSavedValues.put(key, font);
} else if (name.endsWith(".rowHeight")) {
ourSavedValues.put(key, defaults.getInt(key));
}
}
}
float scaleFactor = settings.getPresentationModeFontSize() / UIUtil.DEF_SYSTEM_FONT_SIZE;
ourSavedScaleFactor = JBUI.scale(1f);
JBUI.setUserScaleFactor(scaleFactor);
for (Object key : ourSavedValues.keySet()) {
Object v = ourSavedValues.get(key);
if (v instanceof Font) {
Font font = (Font) v;
defaults.put(key, new FontUIResource(font.getName(), font.getStyle(), JBUI.scale(font.getSize())));
} else if (v instanceof Integer) {
defaults.put(key, JBUI.scale(((Integer) v).intValue()));
}
}
} else {
for (Object key : ourSavedValues.keySet()) {
defaults.put(key, ourSavedValues.get(key));
}
JBUI.setUserScaleFactor(ourSavedScaleFactor);
ourSavedValues.clear();
}
}
Aggregations