java.awt.Font#getStyle ( )源码实例Demo

下面列出了java.awt.Font#getStyle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: Font2D.java
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);
    }
 
源代码2 项目: dragonwell8_jdk   文件: Font2D.java
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);
    }
 
源代码3 项目: openjdk-jdk8u-backup   文件: Font2D.java
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);
}
 
源代码4 项目: buffer_bci   文件: JThermometer.java
/**
 * 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);
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: Font2D.java
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);
}
 
源代码6 项目: ghidra   文件: OptionType.java
@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();
}
 
源代码7 项目: netbeans   文件: ComponentLine.java
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);
}
 
源代码8 项目: osrsclient   文件: NotesPanel.java
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);
    }
}
 
源代码9 项目: netbeans   文件: Coloring.java
/** 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()
           );
}
 
源代码10 项目: seaglass   文件: DerivedFont.java
/**
 * @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;
    }
}
 
源代码11 项目: geomajas-project-server   文件: FontConverter.java
@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();
}
 
源代码12 项目: jdk8u60   文件: Font2D.java
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);
}
 
源代码13 项目: sldeditor   文件: LegendManager.java
/**
 * 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;
}
 
源代码14 项目: hottub   文件: WPathGraphics.java
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);
}
 
源代码15 项目: netbeans   文件: ProfilerXYTooltipPainter.java
private static Font smallerFont(Font font) {
    return new Font(font.getName(), font.getStyle(), font.getSize() - 2);
}
 
源代码16 项目: jdk8u-jdk   文件: PSPrinterJob.java
/**
* 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;
}
 
源代码17 项目: dragonwell8_jdk   文件: WindowsLookAndFeel.java
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);
}
 
源代码18 项目: osp   文件: ConstantParser.java
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));
}
 
源代码19 项目: openjdk-8   文件: WPathGraphics.java
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);
}
 
源代码20 项目: openjdk-8   文件: PSPrinterJob.java
/**
* 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;
}