Java Code Examples for org.eclipse.swt.graphics.FontData#getStyle()
The following examples show how to use
org.eclipse.swt.graphics.FontData#getStyle() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridPropertyHandler.java From nebula with Eclipse Public License 2.0 | 6 votes |
private boolean applyCSSPropertyWeight(final Object element, final Grid grid, final CSSValue value, String target) throws Exception { if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { final FontData fd = CSSEngineHelper.getFontData(grid); boolean modified = false; if ("bold".equals(value.getCssText()) || "bolder".equals(value.getCssText())) { modified = (fd.getStyle() & SWT.BOLD) != SWT.BOLD; if (modified) { fd.setStyle(fd.getStyle() | SWT.BOLD); } } else { modified = (fd.getStyle() & SWT.BOLD) == SWT.BOLD; if (modified) { fd.setStyle(fd.getStyle() | ~SWT.BOLD); } } if (modified) { applyFont(grid, fd, target); } } return true; }
Example 2
Source File: TableComboPropertyHandler.java From nebula with Eclipse Public License 2.0 | 6 votes |
private boolean applyCSSPropertyWeight(final Object element, final Control widget, final CSSValue value) throws Exception { if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) { final FontData fd = CSSEngineHelper.getFontData(widget); boolean modified = false; if ("bold".equals(value.getCssText()) || "bolder".equals(value.getCssText())) { modified = (fd.getStyle() & SWT.BOLD) != SWT.BOLD; if (modified) { fd.setStyle(fd.getStyle() | SWT.BOLD); } } else { modified = (fd.getStyle() & SWT.BOLD) == SWT.BOLD; if (modified) { fd.setStyle(fd.getStyle() | ~SWT.BOLD); } } if (modified) { applyFont(widget, fd); } } return true; }
Example 3
Source File: PreviewLabel.java From birt with Eclipse Public License 1.0 | 6 votes |
private void initFields( ) { try { FontData fd = getFont( ).getFontData( )[0]; fontFamily = fd.getName( ); fontSize = fd.getHeight( ); isBold = ( fd.getStyle( ) & SWT.BOLD ) != 0; isItalic = ( fd.getStyle( ) & SWT.ITALIC ) != 0; } catch ( Exception e ) { /** * Does nothing. */ } }
Example 4
Source File: PTFontEditor.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * @see org.eclipse.nebula.widgets.opal.propertytable.editor.PTChooserEditor#getTextFor(org.eclipse.nebula.widgets.opal.propertytable.PTProperty) */ @Override protected String getTextFor(final PTProperty property) { if (property.getValue() == null) { return ""; } final FontData fontData = (FontData) property.getValue(); final StringBuilder sb = new StringBuilder(); if (fontData != null) { sb.append(fontData.getName()).append(",").append(fontData.getHeight()).append(" pt"); if ((fontData.getStyle() & SWT.BOLD) == SWT.BOLD) { sb.append(", ").append(ResourceManager.getLabel(ResourceManager.BOLD)); } if ((fontData.getStyle() & SWT.ITALIC) == SWT.ITALIC) { sb.append(", ").append(ResourceManager.getLabel(ResourceManager.ITALIC)); } } return sb.toString(); }
Example 5
Source File: SWTUtils.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * 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); }
Example 6
Source File: FontScalingUtil.java From statecharts with Eclipse Public License 1.0 | 5 votes |
public static FontData scaleFont(FontData fontData, int style) { if (OPERATING_SYSTEM.indexOf("win") == -1 || DiagramActivator.getDefault().getPreferenceStore() .getBoolean(StatechartPreferenceConstants.PREF_FONT_SCALING)) { return new FontData(fontData.getName(), fontData.getHeight(), fontData.getStyle() | style); } int DPI = Display.getCurrent().getDPI().y; if (DPI != WINDOWS_DEFAULT_DPI) { double factor = (double) WINDOWS_DEFAULT_DPI / DPI; return new FontData(fontData.getName(), (int) (fontData.getHeight() * factor), fontData.getStyle() | style); } return new FontData(fontData.getName(), fontData.getHeight(), fontData.getStyle() | style); }
Example 7
Source File: SWTUtils.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * 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); }
Example 8
Source File: SWTUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 9
Source File: ExcelExporter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private String getFontInCSSFormat(Font font) { FontData fontData = font.getFontData()[0]; String fontName = fontData.getName(); int fontStyle = fontData.getStyle(); String HTML_STYLES[] = new String[] { "NORMAL", "BOLD", "ITALIC" }; return String.format("font: %s; font-family: %s", fontStyle <= 2 ? HTML_STYLES[fontStyle] : HTML_STYLES[0], fontName); }
Example 10
Source File: ExcelExporter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private String getFontInCSSFormat(Font font) { FontData fontData = font.getFontData()[0]; String fontName = fontData.getName(); int fontStyle = fontData.getStyle(); String HTML_STYLES[] = new String[] { "NORMAL", "BOLD", "ITALIC" }; return String.format("font: %s; font-family: %s", fontStyle <= 2 ? HTML_STYLES[fontStyle] : HTML_STYLES[0], fontName); }
Example 11
Source File: ProgressCircle.java From nebula with Eclipse Public License 2.0 | 5 votes |
private Font createDefaultFont() { final FontData fontData = getFont().getFontData()[0]; final Font newFont = new Font(getDisplay(), fontData.getName(), Math.max(fontData.getHeight(), 20), fontData.getStyle()); addDisposeListener(e -> { if (!newFont.isDisposed()) { newFont.dispose(); } }); return newFont; }
Example 12
Source File: FontPicker.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
private Font createDisplayFont(FontData data) { FontData resizedData = new FontData(data.getName(), 8, data.getStyle()); displayFont = GUIHelper.getFont(resizedData); return displayFont; }
Example 13
Source File: GraphicsHelper.java From gama with GNU General Public License v3.0 | 4 votes |
/** * 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(final Device device, final FontData fontData, final boolean ensureSameSize) { int style; switch (fontData.getStyle()) { case SWT.NORMAL: style = java.awt.Font.PLAIN; break; case SWT.ITALIC: style = java.awt.Font.ITALIC; break; case SWT.BOLD: style = java.awt.Font.BOLD; break; default: style = java.awt.Font.PLAIN; break; } 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) { final GC tmpGC = new GC(device); final Font tmpFont = new Font(device, fontData); tmpGC.setFont(tmpFont); final JPanel DUMMY_PANEL = new JPanel(); java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(), style, 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(), style, 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(), style, height); } } tmpFont.dispose(); tmpGC.dispose(); } return new java.awt.Font(fontData.getName(), style, height); }
Example 14
Source File: Styles.java From http4e with Apache License 2.0 | 4 votes |
private Styles(Shell shell) { Font font = shell.getDisplay().getSystemFont(); FontData fd = font.getFontData()[0]; fontStyle = new FontStyle(fd.getName(), fd.getHeight(), fd.getStyle()); }
Example 15
Source File: FontFactoryTest.java From swt-bling with MIT License | 4 votes |
private boolean isFontDataMatch(Font font, int size, int style) { final FontData fontData = font.getFontData()[0]; return size == fontData.getHeight() && style == fontData.getStyle(); }
Example 16
Source File: GamlHighlightingConfiguration.java From gama with GNU General Public License v3.0 | 4 votes |
public static GamaFont get(final FontData fd) { return fd == null ? getDefaultFont() : new GamaFont(fd.getName(), fd.getStyle(), fd.getHeight()); }
Example 17
Source File: VerticalLabel.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
/** * Fix the issues in the ImageUtilities where the size of the image is the * ascent of the font instead of being its height. * * Also uses the GC for the rotation. * * The biggest issue is the very idea of using an image. The size of the * font should be given by the mapmode, not in absolute device pixel as it * does look ugly when zooming in. * * * @param string * the String to be rendered * @param font * the font * @param foreground * the text's color * @param background * the background color * @param useGCTransform * true to use the Transform on the GC object. * false to rely on the homemade algorithm. Transform seems to * not be supported in eclipse-3.2 except on windows. * It is working on macos-3.3M3. * @return an Image which must be disposed */ public Image createRotatedImageOfString(Graphics g, String string, Font font, Color foreground, Color background, boolean useGCTransform) { Display display = Display.getCurrent(); if (display == null) { SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS); } List<FontData> fontDatas = new ArrayList<FontData>(); // take all font datas, mac and linux specific for (FontData data : font.getFontData()) { FontData data2 = new FontData(data.getName(), (int) (data.getHeight() * g.getAbsoluteScale()), data.getStyle()); fontDatas.add(data2); } // create the new font Font zoomedFont = new Font(display, fontDatas.toArray(new FontData[fontDatas.size()])); // get the dimension in this font Dimension strDim = FigureUtilities .getTextExtents(string, zoomedFont); if (strDim.width == 0 || strDim.height == 0) { strDim = FigureUtilities .getTextExtents(string, font); } Image srcImage = useGCTransform ? new Image(display, strDim.height, strDim.width) : new Image(display, strDim.width, strDim.height); GC gc = new GC(srcImage); if (useGCTransform) { Transform transform = new Transform(display); transform.rotate(-90); gc.setTransform(transform); } gc.setFont(zoomedFont); gc.setForeground(foreground); gc.setBackground(background); gc.fillRectangle(gc.getClipping()); gc.drawText(string, gc.getClipping().x, gc.getClipping().y // - metrics.getLeading() ); gc.dispose(); if (useGCTransform) { srcImage.dispose(); zoomedFont.dispose(); return srcImage; } disposeImage(); Image rotated = ImageUtilities.createRotatedImage(srcImage); srcImage.dispose(); zoomedFont.dispose(); return rotated; }
Example 18
Source File: FontPicker.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
private Font createDisplayFont(FontData data) { FontData resizedData = new FontData(data.getName(), 8, data.getStyle()); displayFont = GUIHelper.getFont(resizedData); return displayFont; }
Example 19
Source File: HTMLPrinter.java From goclipse with Eclipse Public License 1.0 | 3 votes |
/** * Replaces the following style attributes of the font definition of the <code>html</code> * element: * <ul> * <li>font-size</li> * <li>font-weight</li> * <li>font-style</li> * <li>font-family</li> * </ul> * The font's name is used as font family, a <code>sans-serif</code> default font family is * appended for the case that the given font name is not available. * <p> * If the listed font attributes are not contained in the passed style list, nothing happens. * </p> * * @param styles CSS style definitions * @param fontData the font information to use * @return the modified style definitions * @since 3.3 */ public static String convertTopLevelFont(String styles, FontData fontData) { boolean bold= (fontData.getStyle() & SWT.BOLD) != 0; boolean italic= (fontData.getStyle() & SWT.ITALIC) != 0; String size= Integer.toString(fontData.getHeight()) + UNIT; String family= "'" + fontData.getName() + "',sans-serif"; //$NON-NLS-1$ //$NON-NLS-2$ styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-size:\\s*)\\d+pt(\\;?.*\\})", "$1" + size + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-weight:\\s*)\\w+(\\;?.*\\})", "$1" + (bold ? "bold" : "normal") + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-style:\\s*)\\w+(\\;?.*\\})", "$1" + (italic ? "italic" : "normal") + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ styles= styles.replaceFirst("(html\\s*\\{.*(?:\\s|;)font-family:\\s*).+?(;.*\\})", "$1" + family + "$2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return styles; }
Example 20
Source File: SWTUtil.java From nebula with Eclipse Public License 2.0 | 2 votes |
/** * Returns a defensive copy of the passed in FontData. * * @param fontData * the FontData to copy. May be null. * @return a copy of the passed in FontData, or null if the argument was * null. */ public static FontData copy(FontData fontData) { return fontData == null ? null : new FontData(fontData.getName(), fontData.getHeight(), fontData.getStyle()); }