use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.
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 yamcs-studio by yamcs.
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;
}
use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.
the class CustomMediaFactory method getFont.
/**
* Create the <code>Font</code> for the given information.
*
* @param name
* The font name.
* @param height
* The font height.
* @param style
* The font style.
* @return The <code>Font</code> for the given information.
*/
public Font getFont(final String name, final int height, final int style) {
// $NON-NLS-1$
assert name != null : "name!=null";
FontData fd = new FontData(name, height, style);
String key = String.valueOf(fd.hashCode());
if (!_fontRegistry.hasValueFor(key)) {
_fontRegistry.put(key, new FontData[] { fd });
}
return _fontRegistry.get(key);
}
use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.
the class CustomMediaFactory method getFont.
/**
* Create the <code>Font</code> for the given <code>FontData</code> and the
* given style code.
*
* @param fontData
* The <code>FontData</code>
* @param style
* The style code.
* @return The <code>Font</code> for the given <code>FontData</code> and the
* given style code.
*/
public Font getFont(final FontData[] fontData, final int style) {
FontData f = fontData[0];
Font font = getFont(f.getName(), f.getHeight(), style);
return font;
}
use of org.eclipse.swt.graphics.FontData in project yamcs-studio by yamcs.
the class FontProperty method writeToXML.
@Override
public void writeToXML(Element propElement) {
OPIFont opiFont = (OPIFont) getPropertyValue();
Element fontElement;
if (!opiFont.isPreDefined()) {
fontElement = new Element(XML_ELEMENT_FONT);
} else {
fontElement = new Element(XML_ELEMENT_FONTNAME);
fontElement.setText(opiFont.getFontMacroName());
}
FontData fontData = opiFont.getRawFontData();
fontElement.setAttribute(XML_ATTRIBUTE_FONT_NAME, fontData.getName());
fontElement.setAttribute(XML_ATTRIBUTE_FONT_HEIGHT, // $NON-NLS-1$
"" + fontData.getHeight());
fontElement.setAttribute(XML_ATTRIBUTE_FONT_STYLE, // $NON-NLS-1$
"" + fontData.getStyle());
fontElement.setAttribute(XML_ATTRIBUTE_FONT_PIXELS, "" + opiFont.isSizeInPixels());
propElement.addContent(fontElement);
}
Aggregations