use of org.eclipse.swt.graphics.FontData in project dbeaver by serge-rider.
the class HexPreferencesManager method populateFixedCharWidthFontsAsync.
void populateFixedCharWidthFontsAsync() {
FontData fontData = getNextFontData();
if (!fontsRejected.contains(fontData.getName())) {
boolean isScalable = fontsListCurrent == fontsScalable;
int height = 10;
if (!isScalable)
height = fontData.getHeight();
Font font = new Font(Display.getCurrent(), fontData.getName(), height, SWT.NORMAL);
fontsGc.setFont(font);
int width = fontsGc.getAdvanceWidth((char) 0x020);
boolean isFixedWidth = true;
for (int j = 0x021; j < 0x0100 && isFixedWidth; ++j) {
if (((char) j) == '.' && j != '.')
continue;
if (width != fontsGc.getAdvanceWidth((char) j))
isFixedWidth = false;
}
font.dispose();
if (isFixedWidth) {
if (isScalable) {
fontsSorted.put(fontData.getName(), scalableSizes);
} else {
Set<Integer> heights = fontsSorted.get(fontData.getName());
if (heights == null) {
heights = new TreeSet<>();
fontsSorted.put(fontData.getName(), heights);
}
heights.add(fontData.getHeight());
}
if (!list.isDisposed())
list.setItems(fontsSorted.keySet().toArray(new String[fontsSorted.keySet().size()]));
refreshWidgets();
} else {
fontsRejected.add(fontData.getName());
}
}
if (fontsNonScalable.size() == 0 && fontsScalable.size() == 0) {
if (!parent.isDisposed())
fontsGc.dispose();
fontsGc = null;
fontsNonScalable = fontsScalable = fontsListCurrent = null;
fontsRejected = null;
} else {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
populateFixedCharWidthFontsAsync();
}
});
}
}
use of org.eclipse.swt.graphics.FontData in project dbeaver by serge-rider.
the class HexPreferencesManager method getNextFontData.
FontData getNextFontData() {
if (fontsListCurrent.size() == 0) {
fontsListCurrent = fontsScalable;
}
FontData aData = fontsListCurrent.get(0);
fontsListCurrent.remove(0);
while (fontsRejected.contains(aData.getName()) && fontsScalable.size() > 0) {
if (fontsListCurrent.size() == 0) {
fontsListCurrent = fontsScalable;
}
aData = fontsListCurrent.get(0);
fontsListCurrent.remove(0);
}
return aData;
}
use of org.eclipse.swt.graphics.FontData in project dbeaver by serge-rider.
the class HexPreferencesPage method getPrefFontData.
/**
* Get font data information common to all plugin editors. Data comes from preferences store.
*
* @return font data to be used by plugin editors. Returns null for default font data.
*/
public static FontData getPrefFontData() {
DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
String fontName = store.getString(DBeaverPreferences.HEX_FONT_NAME);
int fontStyle = store.getInt(DBeaverPreferences.HEX_FONT_STYLE);
int fontSize = store.getInt(DBeaverPreferences.HEX_FONT_SIZE);
if (!CommonUtils.isEmpty(fontName) && fontSize > 0) {
return new FontData(fontName, fontSize, fontStyle);
}
return null;
}
use of org.eclipse.swt.graphics.FontData in project otertool by wuntee.
the class SWTResourceManager method getFont.
/**
* Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
* flags are also supported.
*
* @param name
* the name of the font
* @param size
* the size of the font
* @param style
* the style of the font
* @param strikeout
* the strikeout flag (warning: Windows only)
* @param underline
* the underline flag (warning: Windows only)
* @return {@link Font} The font matching the name, height, style, strikeout and underline
*/
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
Font font = m_fontMap.get(fontName);
if (font == null) {
FontData fontData = new FontData(name, size, style);
if (strikeout || underline) {
try {
//$NON-NLS-1$
Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT");
//$NON-NLS-1$
Object logFont = FontData.class.getField("data").get(fontData);
if (logFont != null && logFontClass != null) {
if (strikeout) {
//$NON-NLS-1$
logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1));
}
if (underline) {
//$NON-NLS-1$
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1));
}
}
} catch (Throwable e) {
//$NON-NLS-1$ //$NON-NLS-2$
System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e);
}
}
font = new Font(Display.getCurrent(), fontData);
m_fontMap.put(fontName, font);
}
return font;
}
use of org.eclipse.swt.graphics.FontData in project otertool by wuntee.
the class SWTResourceManager method getBoldFont.
/**
* Returns a bold version of the given {@link Font}.
*
* @param baseFont
* the {@link Font} for which a bold version is desired
* @return the bold version of the given {@link Font}
*/
public static Font getBoldFont(Font baseFont) {
Font font = m_fontToBoldFontMap.get(baseFont);
if (font == null) {
FontData[] fontDatas = baseFont.getFontData();
FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_fontToBoldFontMap.put(baseFont, font);
}
return font;
}
Aggregations