/**
* Returns the font in form of an awt font created
* with the parameters of the font of the swt graphic
* composite.
* @see java.awt.Graphics#getFont()
*/
public Font getFont() {
// retrieve the swt font description in an os indept way
FontData[] fontData = gc.getFont().getFontData();
// create a new awt font with the appropiate data
return SWTUtils.toAwtFont(gc.getDevice(), fontData[0], true);
}
java类org.eclipse.swt.graphics.FontData的实例源码
SWTGraphics2D.java 文件源码
项目:parabuild-ci
阅读 25
收藏 0
点赞 0
评论 0
SubscriptionWizard.java 文件源码
项目:BiglyBT
阅读 23
收藏 0
点赞 0
评论 0
private void createFonts() {
FontData[] fDatas = shell.getFont().getFontData();
for(int i = 0 ; i < fDatas.length ; i++) {
fDatas[i].setStyle(SWT.BOLD);
}
boldFont = new Font(display,fDatas);
for(int i = 0 ; i < fDatas.length ; i++) {
if(com.biglybt.core.util.Constants.isOSX) {
fDatas[i].setHeight(12);
} else {
fDatas[i].setHeight(10);
}
}
subTitleFont = new Font(display,fDatas);
for(int i = 0 ; i < fDatas.length ; i++) {
if(com.biglybt.core.util.Constants.isOSX) {
fDatas[i].setHeight(17);
} else {
fDatas[i].setHeight(14);
}
}
titleFont = new Font(display,fDatas);
// When GTK3 can show a textbox without a border, we can remove the logic
textInputFont = FontUtils.getFontWithHeight(shell.getFont(), null, Utils.isGTK3 ? 12 : 14);
}
FontShop.java 文件源码
项目:openaudible
阅读 30
收藏 0
点赞 0
评论 0
private Font newStyledFont(int index, int style) {
Font f = regFonts[index];
if (isset(f)) {
FontData[] fontData = f.getFontData();
fontData[0].setStyle(style);
fontData[0].setLocale(Translate.getLocale().toString());
return new Font(Display.getDefault(), fontData);
} else {
Application.report("newBold failed. f=" + f);
}
return null;
}
SWTResourceManager.java 文件源码
项目:maf
阅读 30
收藏 0
点赞 0
评论 0
/**
* 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;
}
ComponentTitledSeparator.java 文件源码
项目:ARXPlugin
阅读 22
收藏 0
点赞 0
评论 0
/**
* Constructs a new instance of this class given its parent and a style
* value describing its behavior and appearance.
* <p>
* The style value is either one of the style constants defined in class
* <code>SWT</code> which is applicable to instances of this class, or must
* be built by <em>bitwise OR</em>'ing together (that is, using the
* <code>int</code> "|" operator) two or more of those <code>SWT</code>
* style constants. The class description lists the style constants that are
* applicable to the class. Style bits are also inherited from superclasses.
* </p>
*
* @param parent a composite control which will be the parent of the new
* instance (cannot be null)
* @param style the style of control to construct
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
* </ul>
* @exception SWTException <ul>
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
* thread that created the parent</li>
* </ul>
*
*/
public ComponentTitledSeparator(final Composite parent, final int style) {
super(parent, style);
this.alignment = SWT.LEFT;
final Color originalColor = new Color(getDisplay(), 0, 88, 150);
setForeground(originalColor);
final Font originalFont;
final FontData[] fontData = getFont().getFontData();
if (fontData != null && fontData.length > 0) {
final FontData fd = fontData[0];
fd.setStyle(SWT.BOLD);
originalFont = new Font(getDisplay(), fd);
setFont(originalFont);
} else {
originalFont = null;
}
this.addListener(SWT.Resize, new Listener() {
public void handleEvent(final Event event) {
redrawComposite();
}
});
this.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent arg0) {
if (originalColor != null && !originalColor.isDisposed()) {
originalColor.dispose();
}
if (originalFont != null && !originalFont.isDisposed()) {
originalFont.dispose();
}
}
});
}
SWTUtils.java 文件源码
项目:ccu-historian
阅读 29
收藏 0
点赞 0
评论 0
/**
* Create an awt font by converting as much information
* as possible from the provided swt <code>FontData</code>.
* <p>Generally speaking, given a font size, an swt font will
* display differently on the screen than the corresponding awt
* one. Because the SWT toolkit use native graphical ressources whenever
* it is possible, this fact is platform dependent. To address
* this issue, it is possible to enforce the method to return
* an awt font with the same height as the swt one.
*
* @param device The swt device being drawn on (display or gc device).
* @param fontData The swt font to convert.
* @param ensureSameSize A boolean used to enforce the same size
* (in pixels) between the swt font and the newly created awt font.
* @return An awt font converted from the provided swt font.
*/
public static java.awt.Font toAwtFont(Device device, FontData fontData,
boolean ensureSameSize) {
int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
/ 72.0);
// hack to ensure the newly created awt fonts will be rendered with the
// same height as the swt one
if (ensureSameSize) {
GC tmpGC = new GC(device);
Font tmpFont = new Font(device, fontData);
tmpGC.setFont(tmpFont);
JPanel DUMMY_PANEL = new JPanel();
java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
fontData.getStyle(), height);
if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
> tmpGC.textExtent(Az).x) {
while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
> tmpGC.textExtent(Az).x) {
height--;
tmpAwtFont = new java.awt.Font(fontData.getName(),
fontData.getStyle(), height);
}
}
else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
< tmpGC.textExtent(Az).x) {
while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
< tmpGC.textExtent(Az).x) {
height++;
tmpAwtFont = new java.awt.Font(fontData.getName(),
fontData.getStyle(), height);
}
}
tmpFont.dispose();
tmpGC.dispose();
}
return new java.awt.Font(fontData.getName(), fontData.getStyle(),
height);
}
Fonts.java 文件源码
项目:TranskribusSwtGui
阅读 24
收藏 0
点赞 0
评论 0
public static Font createFontWithHeight(Font f, int height) {
if (f.getFontData().length > 0) {
FontData fd = f.getFontData()[0];
fd.setHeight(height);
return createFont(fd);
}
return null;
}
SWTResourceManager.java 文件源码
项目:codegen-ecore
阅读 28
收藏 0
点赞 0
评论 0
/**
* 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 {
Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
if (logFont != null && logFontClass != null) {
if (strikeout) {
logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
}
if (underline) {
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
}
}
} catch (Throwable e) {
System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
font = new Font(Display.getCurrent(), fontData);
m_fontMap.put(fontName, font);
}
return font;
}
SWTResourceManager.java 文件源码
项目:codegen-ecore
阅读 28
收藏 0
点赞 0
评论 0
/**
* 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;
}
ArchitecturalLabelDecoratorBase.java 文件源码
项目:code
阅读 18
收藏 0
点赞 0
评论 0
private static FontData[] getModifiedFontData(int style) {
FontData[] styleData = new FontData[ArchitecturalLabelDecoratorBase.baseData.length];
for (int i = 0; i < styleData.length; i++) {
FontData base = ArchitecturalLabelDecoratorBase.baseData[i];
styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | style);
}
return styleData;
}