Java Code Examples for java.awt.Font#getStyle()
The following examples show how to use
java.awt.Font#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: Font2D.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public FontStrike getStrike(Font font, FontRenderContext frc) { AffineTransform at = frc.getTransform(); double ptSize = font.getSize2D(); at.scale(ptSize, ptSize); if (font.isTransformed()) { at.concatenate(font.getTransform()); if (at.getTranslateX() != 0 || at.getTranslateY() != 0) { at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), 0.0, 0.0); } } int aa = FontStrikeDesc.getAAHintIntVal(this, font, frc); int fm = FontStrikeDesc.getFMHintIntVal(frc.getFractionalMetricsHint()); FontStrikeDesc desc = new FontStrikeDesc(frc.getTransform(), at, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 2
Source File: Font2D.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public FontStrike getStrike(Font font, FontRenderContext frc) { AffineTransform at = frc.getTransform(); double ptSize = font.getSize2D(); at.scale(ptSize, ptSize); if (font.isTransformed()) { at.concatenate(font.getTransform()); if (at.getTranslateX() != 0 || at.getTranslateY() != 0) { at.setTransform(at.getScaleX(), at.getShearY(), at.getShearX(), at.getScaleY(), 0.0, 0.0); } } int aa = FontStrikeDesc.getAAHintIntVal(this, font, frc); int fm = FontStrikeDesc.getFMHintIntVal(frc.getFractionalMetricsHint()); FontStrikeDesc desc = new FontStrikeDesc(frc.getTransform(), at, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 3
Source File: Font2D.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm) { /* Create the descriptor which is used to identify a strike * in the strike cache/map. A strike is fully described by * the attributes of this descriptor. */ /* REMIND: generating garbage and doing computation here in order * to include pt size in the tx just for a lookup! Figure out a * better way. */ double ptSize = font.getSize2D(); AffineTransform glyphTx = (AffineTransform)devTx.clone(); glyphTx.scale(ptSize, ptSize); if (font.isTransformed()) { glyphTx.concatenate(font.getTransform()); } if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) { glyphTx.setTransform(glyphTx.getScaleX(), glyphTx.getShearY(), glyphTx.getShearX(), glyphTx.getScaleY(), 0.0, 0.0); } FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 4
Source File: Font2D.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public FontStrike getStrike(Font font, AffineTransform devTx, int aa, int fm) { /* Create the descriptor which is used to identify a strike * in the strike cache/map. A strike is fully described by * the attributes of this descriptor. */ /* REMIND: generating garbage and doing computation here in order * to include pt size in the tx just for a lookup! Figure out a * better way. */ double ptSize = font.getSize2D(); AffineTransform glyphTx = (AffineTransform)devTx.clone(); glyphTx.scale(ptSize, ptSize); if (font.isTransformed()) { glyphTx.concatenate(font.getTransform()); } if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) { glyphTx.setTransform(glyphTx.getScaleX(), glyphTx.getShearY(), glyphTx.getShearX(), glyphTx.getScaleY(), 0.0, 0.0); } FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 5
Source File: FontConverter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Override public String toString(Object obj) { Font font = (Font) obj; if (obj == null) { return null; } String style = null; if (font.getStyle() == Font.BOLD) { style = "bold"; } else if (font.getStyle() == Font.ITALIC) { style = "italic"; } return font.getName() + (style == null ? "" : "," + style) + "," + font.getSize(); }
Example 6
Source File: DerivedFont.java From seaglass with Apache License 2.0 | 5 votes |
/** * @inheritDoc */ @Override public Object createValue(UIDefaults defaults) { Font f = UIManager.getFont(parentKey); if (f != null) { // always round size for now so we have exact int font size // (or we may have lame looking fonts) float size = Math.round(f.getSize2D() * sizeOffset); int style = f.getStyle(); if (bold != null) { if (bold.booleanValue()) { style = style | Font.BOLD; } else { style = style & ~Font.BOLD; } } if (italic != null) { if (italic.booleanValue()) { style = style | Font.ITALIC; } else { style = style & ~Font.ITALIC; } } return f.deriveFont(style, size); } else { return null; } }
Example 7
Source File: Coloring.java From netbeans with Apache License 2.0 | 5 votes |
/** Modify the given font according to the font-mode */ private Font modifyFont(Font f) { return new Font( ((fontMode & FONT_MODE_APPLY_NAME) != 0) ? font.getName() : f.getName(), ((fontMode & FONT_MODE_APPLY_STYLE) != 0) ? font.getStyle() : f.getStyle(), ((fontMode & FONT_MODE_APPLY_SIZE) != 0) ? font.getSize() : f.getSize() ); }
Example 8
Source File: NotesPanel.java From osrsclient with GNU General Public License v2.0 | 5 votes |
public void actionPerformed(ActionEvent e){ Font f = notewindow.getFont(); if(f.getSize() < 30){ Font f2 = new Font(f.getFontName(), f.getStyle(), f.getSize() + 2); notewindow.setFont(f2); } }
Example 9
Source File: ComponentLine.java From netbeans with Apache License 2.0 | 5 votes |
private Font createFont(Font attrFont, Font defaultFont) { if ( !Config.getDefault().isUseFont()) { return defaultFont; } String name = defaultFont.getName(); int size = defaultFont.getSize(); int style = attrFont.getStyle(); return new Font(name, style, size); }
Example 10
Source File: OptionType.java From ghidra with Apache License 2.0 | 5 votes |
@Override String objectToString(Object object) { Font font = (Font) object; String fontName = font.getFamily(); int style = font.getStyle(); int size = font.getSize(); StringBuffer buf = new StringBuffer(); buf.append(fontName); buf.append("-"); buf.append(STYLES[style]); buf.append("-"); buf.append(size); return buf.toString(); }
Example 11
Source File: JThermometer.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Increases or decreases the tick font size. * * @param delta the change in size. */ public void changeTickFontSize(int delta) { Font f = getTickLabelFont(); String fName = f.getFontName(); Font newFont = new Font(fName, f.getStyle(), (f.getSize() + delta)); setTickLabelFont(newFont); }
Example 12
Source File: Font2D.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public FontStrike getStrike(Font font, AffineTransform devTx, AffineTransform glyphTx, int aa, int fm) { /* Create the descriptor which is used to identify a strike * in the strike cache/map. A strike is fully described by * the attributes of this descriptor. */ FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx, font.getStyle(), aa, fm); return getStrike(desc, false); }
Example 13
Source File: ConstantParser.java From osp with GNU General Public License v3.0 | 4 votes |
static public Value fontConstant(Font _currentFont, String _value) { if(_value.indexOf(',')<0) { return null; // No commas, not a valid constant } if(_currentFont==null) { _currentFont = defaultFont; } int style = _currentFont.getStyle(); int size = _currentFont.getSize(); String name = null; StringTokenizer t = new StringTokenizer(_value, ",", true); //$NON-NLS-1$ if(t.hasMoreTokens()) { name = t.nextToken(); if(name.equals(",")) { //$NON-NLS-1$ name = _currentFont.getName(); } else if(t.hasMoreTokens()) { t.nextToken(); // read out next ',' } } else { name = _currentFont.getName(); } if(t.hasMoreTokens()) { String styleStr = t.nextToken().toLowerCase(); style = _currentFont.getStyle(); if(!styleStr.equals(",")) { //$NON-NLS-1$ if(styleStr.indexOf("plain")!=-1) { //$NON-NLS-1$ style = java.awt.Font.PLAIN; } if(styleStr.indexOf("bold")!=-1) { //$NON-NLS-1$ style = java.awt.Font.BOLD; } if(styleStr.indexOf("italic")!=-1) { //$NON-NLS-1$ style = style|java.awt.Font.ITALIC; } if(t.hasMoreTokens()) { t.nextToken(); // read out next ',' } } } if(t.hasMoreTokens()) { try { size = Integer.parseInt(t.nextToken()); } catch(Exception exc) { size = _currentFont.getSize(); } } return new ObjectValue(new Font(name, style, size)); }
Example 14
Source File: WindowsLookAndFeel.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
protected Object configureValue(Object value) { if (value instanceof Font) { Font font = (Font)value; if ("MS Sans Serif".equals(font.getName())) { int size = font.getSize(); // 4950968: Workaround to mimic the way Windows maps the default // font size of 6 pts to the smallest available bitmap font size. // This happens mostly on Win 98/Me & NT. int dpi; try { dpi = Toolkit.getDefaultToolkit().getScreenResolution(); } catch (HeadlessException ex) { dpi = 96; } if (Math.round(size * 72F / dpi) < 8) { size = Math.round(8 * dpi / 72F); } Font msFont = new FontUIResource("Microsoft Sans Serif", font.getStyle(), size); if (msFont.getName() != null && msFont.getName().equals(msFont.getFamily())) { font = msFont; } else if (size != font.getSize()) { font = new FontUIResource("MS Sans Serif", font.getStyle(), size); } } if (FontUtilities.fontSupportsDefaultEncoding(font)) { if (!(font instanceof UIResource)) { font = new FontUIResource(font); } } else { font = FontUtilities.getCompositeFontUIResource(font); } return font; } return super.configureValue(value); }
Example 15
Source File: PSPrinterJob.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Given an array of CharsetStrings that make up a run * of text, this routine converts each CharsetString to * an index into our PostScript font list. If one or more * CharsetStrings can not be represented by a PostScript * font, then this routine will return a null array. */ private int[] getPSFontIndexArray(Font font, CharsetString[] charSet) { int[] psFont = null; if (mFontProps != null) { psFont = new int[charSet.length]; } for (int i = 0; i < charSet.length && psFont != null; i++){ /* Get the encoding of the run of text. */ CharsetString cs = charSet[i]; CharsetEncoder fontCS = cs.fontDescriptor.encoder; String charsetName = cs.fontDescriptor.getFontCharsetName(); /* * sun.awt.Symbol perhaps should return "symbol" for encoding. * Similarly X11Dingbats should return "dingbats" * Forced to check for win32 & x/unix names for these converters. */ if ("Symbol".equals(charsetName)) { charsetName = "symbol"; } else if ("WingDings".equals(charsetName) || "X11Dingbats".equals(charsetName)) { charsetName = "dingbats"; } else { charsetName = makeCharsetName(charsetName, cs.charsetChars); } int styleMask = font.getStyle() | FontUtilities.getFont2D(font).getStyle(); String style = FontConfiguration.getStyleString(styleMask); /* First we map the font name through the properties file. * This mapping provides alias names for fonts, for example, * "timesroman" is mapped to "serif". */ String fontName = font.getFamily().toLowerCase(Locale.ENGLISH); fontName = fontName.replace(' ', '_'); String name = mFontProps.getProperty(fontName, ""); /* Now map the alias name, character set name, and style * to a PostScript name. */ String psName = mFontProps.getProperty(name + "." + charsetName + "." + style, null); if (psName != null) { /* Get the PostScript font index for the PostScript font. */ try { psFont[i] = Integer.parseInt(mFontProps.getProperty(psName)); /* If there is no PostScript font for this font name, * then we want to termintate the loop and the method * indicating our failure. Setting the array to null * is used to indicate these failures. */ } catch(NumberFormatException e){ psFont = null; } /* There was no PostScript name for the font, character set, * and style so give up. */ } else { psFont = null; } } return psFont; }
Example 16
Source File: ProfilerXYTooltipPainter.java From netbeans with Apache License 2.0 | 4 votes |
private static Font smallerFont(Font font) { return new Font(font.getName(), font.getStyle(), font.getSize() - 2); }
Example 17
Source File: WPathGraphics.java From hottub with GNU General Public License v2.0 | 4 votes |
private void textOut(String str, Font font, PhysicalFont font2D, FontRenderContext frc, float deviceSize, int rotation, float awScale, double scaleFactorX, double scaleFactorY, float userx, float usery, float devx, float devy, float targetW) { String family = font2D.getFamilyName(null); int style = font.getStyle() | font2D.getStyle(); WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob(); boolean setFont = wPrinterJob.setFont(family, deviceSize, style, rotation, awScale); if (!setFont) { super.drawString(str, userx, usery, font, frc, targetW); return; } float[] glyphPos = null; if (!okGDIMetrics(str, font, frc, scaleFactorX)) { /* If there is a 1:1 char->glyph mapping then char positions * are the same as glyph positions and we can tell GDI * where to place the glyphs. * On drawing we remove control chars so these need to be * removed now so the string and positions are the same length. * For other cases we need to pass glyph codes to GDI. */ str = wPrinterJob.removeControlChars(str); char[] chars = str.toCharArray(); int len = chars.length; GlyphVector gv = null; if (!FontUtilities.isComplexText(chars, 0, len)) { gv = font.createGlyphVector(frc, str); } if (gv == null) { super.drawString(str, userx, usery, font, frc, targetW); return; } glyphPos = gv.getGlyphPositions(0, len, null); Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs()); /* GDI advances must not include device space rotation. * See earlier comment in printGlyphVector() for details. */ AffineTransform advanceTransform = AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY); float[] glyphAdvPos = new float[glyphPos.length]; advanceTransform.transform(glyphPos, 0, //source glyphAdvPos, 0, //destination glyphPos.length/2); //num points glyphPos = glyphAdvPos; } wPrinterJob.textOut(str, devx, devy, glyphPos); }
Example 18
Source File: LegendManager.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Creates the legend. * * @param sld the sld * @param heading the heading * @param filename the filename * @param separateSymbolizers the separate symbolizers * @return the map */ public Map<String, BufferedImage> createLegend( StyledLayerDescriptor sld, String heading, String filename, boolean separateSymbolizers) { Map<String, BufferedImage> imageMap = new HashMap<>(); // // Set legend options // Map<String, Object> legendOptions = new HashMap<>(); if (heading != null) { legendOptions.put("heading", heading); } if (filename != null) { legendOptions.put("filename", filename); } if (legendOptionData == null) { legendOptionData = new LegendOptionData(); } GetLegendGraphicRequest request = new GetLegendGraphicRequest(); request.setWidth(legendOptionData.getImageWidth()); request.setHeight(legendOptionData.getImageHeight()); request.setTransparent(legendOptionData.isTransparent()); request.setStrict(false); legendOptions.put( "bgColor", ColourUtils.fromColour(legendOptionData.getBackgroundColour())); legendOptions.put( "fontColor", ColourUtils.fromColour(legendOptionData.getLabelFontColour())); // // Label Font // Font font = legendOptionData.getLabelFont(); legendOptions.put("fontName", font.getFontName()); String styleValue = null; if ((font.getStyle() & java.awt.Font.BOLD) == java.awt.Font.BOLD) { styleValue = "bold"; } if ((font.getStyle() & java.awt.Font.ITALIC) == java.awt.Font.ITALIC) { styleValue = "italic"; } if (styleValue != null) { legendOptions.put("fontStyle", styleValue); } legendOptions.put("fontSize", String.valueOf(font.getSize())); legendOptions.put("dpi", Integer.valueOf(legendOptionData.getDpi())); legendOptions.put( "fontAntiAliasing", getBooleanValueOnOff(legendOptionData.isFontAntiAliasing())); legendOptions.put("forceLabels", getBooleanValueOnOff(legendOptionData.isShowLabels())); legendOptions.put("forceTitles", getBooleanValueOnOff(legendOptionData.isShowTitle())); legendOptions.put( "bandInfo", getBooleanValueTrueFalse(legendOptionData.isBandInformation())); legendOptions.put("border", getBooleanValueTrueFalse(legendOptionData.isBorder())); legendOptions.put( "borderColor", ColourUtils.fromColour(legendOptionData.getBorderColour())); legendOptions.put( "imageSizeFactor", String.valueOf(legendOptionData.getImageSize() / 100.0)); request.setLegendOptions(legendOptions); if (sld != null) { Map<String, Style> styleMap = new LinkedHashMap<>(); StyledLayer selectedStyledLayer = SelectedSymbol.getInstance().getStyledLayer(); Style selectedStyle = SelectedSymbol.getInstance().getStyle(); if (selectedStyle != null) { createSingleStyleLegend(styleMap, selectedStyledLayer, selectedStyle); } else { createMultipleStyleLegend(sld, styleMap, selectedStyledLayer); } // Merge symbolizers into 1 image if (!separateSymbolizers) { mergeSymbolizers(imageMap, request, styleMap); } else { separateSymbolizers(imageMap, request, styleMap); } } return imageMap; }
Example 19
Source File: WPathGraphics.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private void textOut(String str, Font font, PhysicalFont font2D, FontRenderContext frc, float deviceSize, int rotation, float awScale, AffineTransform deviceTransform, double scaleFactorX, float userx, float usery, float devx, float devy, float targetW) { String family = font2D.getFamilyName(null); int style = font.getStyle() | font2D.getStyle(); WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob(); boolean setFont = wPrinterJob.setFont(family, deviceSize, style, rotation, awScale); if (!setFont) { super.drawString(str, userx, usery, font, frc, targetW); return; } float[] glyphPos = null; if (!okGDIMetrics(str, font, frc, scaleFactorX)) { /* If there is a 1:1 char->glyph mapping then char positions * are the same as glyph positions and we can tell GDI * where to place the glyphs. * On drawing we remove control chars so these need to be * removed now so the string and positions are the same length. * For other cases we need to pass glyph codes to GDI. */ str = wPrinterJob.removeControlChars(str); char[] chars = str.toCharArray(); int len = chars.length; GlyphVector gv = null; if (!FontUtilities.isComplexText(chars, 0, len)) { gv = font.createGlyphVector(frc, str); } if (gv == null) { super.drawString(str, userx, usery, font, frc, targetW); return; } glyphPos = gv.getGlyphPositions(0, len, null); Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs()); /* GDI advances must not include device space rotation. * See earlier comment in printGlyphVector() for details. */ AffineTransform advanceTransform = new AffineTransform(deviceTransform); advanceTransform.rotate(rotation*Math.PI/1800.0); float[] glyphAdvPos = new float[glyphPos.length]; advanceTransform.transform(glyphPos, 0, //source glyphAdvPos, 0, //destination glyphPos.length/2); //num points glyphPos = glyphAdvPos; } wPrinterJob.textOut(str, devx, devy, glyphPos); }
Example 20
Source File: PSPrinterJob.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Given an array of CharsetStrings that make up a run * of text, this routine converts each CharsetString to * an index into our PostScript font list. If one or more * CharsetStrings can not be represented by a PostScript * font, then this routine will return a null array. */ private int[] getPSFontIndexArray(Font font, CharsetString[] charSet) { int[] psFont = null; if (mFontProps != null) { psFont = new int[charSet.length]; } for (int i = 0; i < charSet.length && psFont != null; i++){ /* Get the encoding of the run of text. */ CharsetString cs = charSet[i]; CharsetEncoder fontCS = cs.fontDescriptor.encoder; String charsetName = cs.fontDescriptor.getFontCharsetName(); /* * sun.awt.Symbol perhaps should return "symbol" for encoding. * Similarly X11Dingbats should return "dingbats" * Forced to check for win32 & x/unix names for these converters. */ if ("Symbol".equals(charsetName)) { charsetName = "symbol"; } else if ("WingDings".equals(charsetName) || "X11Dingbats".equals(charsetName)) { charsetName = "dingbats"; } else { charsetName = makeCharsetName(charsetName, cs.charsetChars); } int styleMask = font.getStyle() | FontUtilities.getFont2D(font).getStyle(); String style = FontConfiguration.getStyleString(styleMask); /* First we map the font name through the properties file. * This mapping provides alias names for fonts, for example, * "timesroman" is mapped to "serif". */ String fontName = font.getFamily().toLowerCase(Locale.ENGLISH); fontName = fontName.replace(' ', '_'); String name = mFontProps.getProperty(fontName, ""); /* Now map the alias name, character set name, and style * to a PostScript name. */ String psName = mFontProps.getProperty(name + "." + charsetName + "." + style, null); if (psName != null) { /* Get the PostScript font index for the PostScript font. */ try { psFont[i] = Integer.parseInt(mFontProps.getProperty(psName)); /* If there is no PostScript font for this font name, * then we want to termintate the loop and the method * indicating our failure. Setting the array to null * is used to indicate these failures. */ } catch(NumberFormatException e){ psFont = null; } /* There was no PostScript name for the font, character set, * and style so give up. */ } else { psFont = null; } } return psFont; }