java.awt.Font#SANS_SERIF源码实例Demo

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

源代码1 项目: mars-sim   文件: ResizedFontLabel.java
private BufferedImage createImage(String label) {
    Font font = new Font(Font.SANS_SERIF, Font.BOLD, SIZE);
    FontRenderContext frc = new FontRenderContext(null, true, true);
    TextLayout layout = new TextLayout(label, font, frc);
    Rectangle r = layout.getPixelBounds(null, 0, 0);
    //System.out.println(r);
    BufferedImage bi = new BufferedImage(
        r.width + 1, r.height + 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = (Graphics2D) bi.getGraphics();
    g2d.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(getBackground());
    g2d.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    g2d.setColor(getForeground());
    layout.draw(g2d, 0, -r.y);
    g2d.dispose();
    return bi;
}
 
源代码2 项目: libreveris   文件: TextFont.java
/**
 * Creates a font based on OCR font information.
 *
 * @param info OCR-based font information
 */
public TextFont (FontInfo info)
{
    this(
            info.isSerif ? Font.SERIF
            : (info.isMonospace ? Font.MONOSPACED : Font.SANS_SERIF),
            (info.isBold ? Font.BOLD : 0) | (info.isItalic ? Font.ITALIC : 0),
            info.pointsize);
}
 
源代码3 项目: ChatGameFontificator   文件: CollagePanel.java
public CollagePanel(ChatPanel chat)
{
    this.chat = chat;
    this.font = new Font(Font.SANS_SERIF, Font.PLAIN, 14);

    this.collageChooser = new JFileChooser();
    FileFilter pngFileFilter = new FileNameExtensionFilter("PNG Image (*.png)", "png");
    this.collageChooser.setFileFilter(pngFileFilter);

    images = new ArrayList<BufferedImage>();
    build();
}
 
源代码4 项目: openjdk-jdk8u   文件: ClassLoaderLeakTest.java
protected void doTest() {
    Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
    f.getNumGlyphs();
}
 
源代码5 项目: dragonwell8_jdk   文件: SunFontManager.java
/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
源代码6 项目: openjdk-8-source   文件: CSS.java
Object parseCssValue(String value) {
    int cIndex = value.indexOf(',');
    FontFamily ff = new FontFamily();
    ff.svalue = value;
    ff.family = null;

    if (cIndex == -1) {
        setFontName(ff, value);
    }
    else {
        boolean done = false;
        int lastIndex;
        int length = value.length();
        cIndex = 0;
        while (!done) {
            // skip ws.
            while (cIndex < length &&
                   Character.isWhitespace(value.charAt(cIndex)))
                cIndex++;
            // Find next ','
            lastIndex = cIndex;
            cIndex = value.indexOf(',', cIndex);
            if (cIndex == -1) {
                cIndex = length;
            }
            if (lastIndex < length) {
                if (lastIndex != cIndex) {
                    int lastCharIndex = cIndex;
                    if (cIndex > 0 && value.charAt(cIndex - 1) == ' '){
                        lastCharIndex--;
                    }
                    setFontName(ff, value.substring
                                (lastIndex, lastCharIndex));
                    done = (ff.family != null);
                }
                cIndex++;
            }
            else {
                done = true;
            }
        }
    }
    if (ff.family == null) {
        ff.family = Font.SANS_SERIF;
    }
    return ff;
}
 
源代码7 项目: dss   文件: PdfBoxFontMapper.java
public static PDType1Font getPDFont(Font javaFont) {
	switch (javaFont.getFamily()) {
		case Font.SERIF:
			if (javaFont.isPlain()) {
				return PDType1Font.TIMES_ROMAN;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.TIMES_BOLD_ITALIC;
				} else {
					return PDType1Font.TIMES_BOLD;
				}
			} else {
				return PDType1Font.TIMES_ITALIC;
			}
		case Font.SANS_SERIF:
			if (javaFont.isPlain()) {
				return PDType1Font.HELVETICA;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.HELVETICA_BOLD_OBLIQUE;
				} else {
					return PDType1Font.HELVETICA_BOLD;
				}
			} else {
				return PDType1Font.HELVETICA_OBLIQUE;
			}
		case Font.MONOSPACED:
			if (javaFont.isPlain()) {
				return PDType1Font.COURIER;
			} else if (javaFont.isBold()) {
				if (javaFont.isItalic()) {
					return PDType1Font.COURIER_BOLD_OBLIQUE;
				} else {
					return PDType1Font.COURIER_BOLD;
				}
			} else {
				return PDType1Font.COURIER_OBLIQUE;
			}
		case Font.DIALOG:
		case Font.DIALOG_INPUT:
			return PDType1Font.SYMBOL;
		default:
			throw new DSSException("The font is not supported! Please use DSSFileFont implementation for custom fonts.");
		}
}
 
源代码8 项目: dragonwell8_jdk   文件: ClassLoaderLeakTest.java
protected void doTest() {
    Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
    f.getNumGlyphs();
}
 
源代码9 项目: openjdk-jdk9   文件: CSS.java
/**
 * Returns the font for the values in the passed in AttributeSet.
 * It is assumed the keys will be CSS.Attribute keys.
 * <code>sc</code> is the StyleContext that will be messaged to get
 * the font once the size, name and style have been determined.
 */
Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
    ss = getStyleSheet(ss);
    int size = getFontSize(a, defaultSize, ss);

    /*
     * If the vertical alignment is set to either superscript or
     * subscript we reduce the font size by 2 points.
     */
    StringValue vAlignV = (StringValue)a.getAttribute
                          (CSS.Attribute.VERTICAL_ALIGN);
    if ((vAlignV != null)) {
        String vAlign = vAlignV.toString();
        if ((vAlign.indexOf("sup") >= 0) ||
            (vAlign.indexOf("sub") >= 0)) {
            size -= 2;
        }
    }

    FontFamily familyValue = (FontFamily)a.getAttribute
                                        (CSS.Attribute.FONT_FAMILY);
    String family = (familyValue != null) ? familyValue.getValue() :
                              Font.SANS_SERIF;
    int style = Font.PLAIN;
    FontWeight weightValue = (FontWeight) a.getAttribute
                              (CSS.Attribute.FONT_WEIGHT);
    if ((weightValue != null) && (weightValue.getValue() > 400)) {
        style |= Font.BOLD;
    }
    Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
    if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
        style |= Font.ITALIC;
    }
    if (family.equalsIgnoreCase("monospace")) {
        family = Font.MONOSPACED;
    }
    Font f = sc.getFont(family, style, size);
    if (f == null
        || (f.getFamily().equals(Font.DIALOG)
            && ! family.equalsIgnoreCase(Font.DIALOG))) {
        family = Font.SANS_SERIF;
        f = sc.getFont(family, style, size);
    }
    return f;
}
 
源代码10 项目: TencentKona-8   文件: SunFontManager.java
/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
源代码11 项目: openjdk-jdk9   文件: ClassLoaderLeakTest.java
protected void doTest() {
    Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
    f.getNumGlyphs();
}
 
源代码12 项目: jdk8u-jdk   文件: SunFontManager.java
/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
源代码13 项目: TeaStore   文件: ImageCreator.java
private static void makeText(Graphics2D graphics, ImageSize maxSize, Random rand) {
  switchColor(graphics, rand);

  String fontName = Font.SANS_SERIF;
  switch (rand.nextInt(4)) {
  case 0:
    fontName = Font.SANS_SERIF;
    break;
  case 1:
    fontName = Font.MONOSPACED;
    break;
  case 2:
    fontName = Font.SERIF;
    break;
  case 3:
    fontName = Font.DIALOG;
    break;
  default:
    fontName = Font.SANS_SERIF;
    break;
  }

  int fontStyle = Font.PLAIN;
  switch (rand.nextInt(3)) {
  case 0:
    fontStyle = Font.PLAIN;
    break;
  case 1:
    fontStyle = Font.BOLD;
    break;
  case 2:
    fontStyle = Font.ITALIC;
    break;
  default:
    fontStyle = Font.PLAIN;
    break;
  }

  int fontSize = rand.nextInt(MAX_FONT_SIZE + 1);

  graphics.setFont(new Font(fontName, fontStyle, fontSize));

  int textLength = rand.nextInt(MAX_TEXT_LENGTH + 1);
  String str = Stream.generate(() -> rand.nextInt(MAX_CHAR_SIZE)).limit(textLength)
      .map(i -> (char) i.intValue())
      .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();

  graphics.drawString(str, rand.nextInt(maxSize.getWidth()), rand.nextInt(maxSize.getHeight()));
}
 
源代码14 项目: jdk8u60   文件: SunFontManager.java
/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
源代码15 项目: openjdk-8   文件: CSS.java
/**
 * Returns the font for the values in the passed in AttributeSet.
 * It is assumed the keys will be CSS.Attribute keys.
 * <code>sc</code> is the StyleContext that will be messaged to get
 * the font once the size, name and style have been determined.
 */
Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
    ss = getStyleSheet(ss);
    int size = getFontSize(a, defaultSize, ss);

    /*
     * If the vertical alignment is set to either superscirpt or
     * subscript we reduce the font size by 2 points.
     */
    StringValue vAlignV = (StringValue)a.getAttribute
                          (CSS.Attribute.VERTICAL_ALIGN);
    if ((vAlignV != null)) {
        String vAlign = vAlignV.toString();
        if ((vAlign.indexOf("sup") >= 0) ||
            (vAlign.indexOf("sub") >= 0)) {
            size -= 2;
        }
    }

    FontFamily familyValue = (FontFamily)a.getAttribute
                                        (CSS.Attribute.FONT_FAMILY);
    String family = (familyValue != null) ? familyValue.getValue() :
                              Font.SANS_SERIF;
    int style = Font.PLAIN;
    FontWeight weightValue = (FontWeight) a.getAttribute
                              (CSS.Attribute.FONT_WEIGHT);
    if ((weightValue != null) && (weightValue.getValue() > 400)) {
        style |= Font.BOLD;
    }
    Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
    if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
        style |= Font.ITALIC;
    }
    if (family.equalsIgnoreCase("monospace")) {
        family = Font.MONOSPACED;
    }
    Font f = sc.getFont(family, style, size);
    if (f == null
        || (f.getFamily().equals(Font.DIALOG)
            && ! family.equalsIgnoreCase(Font.DIALOG))) {
        family = Font.SANS_SERIF;
        f = sc.getFont(family, style, size);
    }
    return f;
}
 
源代码16 项目: jdk8u-dev-jdk   文件: SunFontManager.java
/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
源代码17 项目: hottub   文件: CSS.java
/**
 * Returns the font for the values in the passed in AttributeSet.
 * It is assumed the keys will be CSS.Attribute keys.
 * <code>sc</code> is the StyleContext that will be messaged to get
 * the font once the size, name and style have been determined.
 */
Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
    ss = getStyleSheet(ss);
    int size = getFontSize(a, defaultSize, ss);

    /*
     * If the vertical alignment is set to either superscirpt or
     * subscript we reduce the font size by 2 points.
     */
    StringValue vAlignV = (StringValue)a.getAttribute
                          (CSS.Attribute.VERTICAL_ALIGN);
    if ((vAlignV != null)) {
        String vAlign = vAlignV.toString();
        if ((vAlign.indexOf("sup") >= 0) ||
            (vAlign.indexOf("sub") >= 0)) {
            size -= 2;
        }
    }

    FontFamily familyValue = (FontFamily)a.getAttribute
                                        (CSS.Attribute.FONT_FAMILY);
    String family = (familyValue != null) ? familyValue.getValue() :
                              Font.SANS_SERIF;
    int style = Font.PLAIN;
    FontWeight weightValue = (FontWeight) a.getAttribute
                              (CSS.Attribute.FONT_WEIGHT);
    if ((weightValue != null) && (weightValue.getValue() > 400)) {
        style |= Font.BOLD;
    }
    Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
    if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
        style |= Font.ITALIC;
    }
    if (family.equalsIgnoreCase("monospace")) {
        family = Font.MONOSPACED;
    }
    Font f = sc.getFont(family, style, size);
    if (f == null
        || (f.getFamily().equals(Font.DIALOG)
            && ! family.equalsIgnoreCase(Font.DIALOG))) {
        family = Font.SANS_SERIF;
        f = sc.getFont(family, style, size);
    }
    return f;
}
 
源代码18 项目: JDKSourceCode1.8   文件: CSS.java
/**
 * Returns the font for the values in the passed in AttributeSet.
 * It is assumed the keys will be CSS.Attribute keys.
 * <code>sc</code> is the StyleContext that will be messaged to get
 * the font once the size, name and style have been determined.
 */
Font getFont(StyleContext sc, AttributeSet a, int defaultSize, StyleSheet ss) {
    ss = getStyleSheet(ss);
    int size = getFontSize(a, defaultSize, ss);

    /*
     * If the vertical alignment is set to either superscirpt or
     * subscript we reduce the font size by 2 points.
     */
    StringValue vAlignV = (StringValue)a.getAttribute
                          (CSS.Attribute.VERTICAL_ALIGN);
    if ((vAlignV != null)) {
        String vAlign = vAlignV.toString();
        if ((vAlign.indexOf("sup") >= 0) ||
            (vAlign.indexOf("sub") >= 0)) {
            size -= 2;
        }
    }

    FontFamily familyValue = (FontFamily)a.getAttribute
                                        (CSS.Attribute.FONT_FAMILY);
    String family = (familyValue != null) ? familyValue.getValue() :
                              Font.SANS_SERIF;
    int style = Font.PLAIN;
    FontWeight weightValue = (FontWeight) a.getAttribute
                              (CSS.Attribute.FONT_WEIGHT);
    if ((weightValue != null) && (weightValue.getValue() > 400)) {
        style |= Font.BOLD;
    }
    Object fs = a.getAttribute(CSS.Attribute.FONT_STYLE);
    if ((fs != null) && (fs.toString().indexOf("italic") >= 0)) {
        style |= Font.ITALIC;
    }
    if (family.equalsIgnoreCase("monospace")) {
        family = Font.MONOSPACED;
    }
    Font f = sc.getFont(family, style, size);
    if (f == null
        || (f.getFamily().equals(Font.DIALOG)
            && ! family.equalsIgnoreCase(Font.DIALOG))) {
        family = Font.SANS_SERIF;
        f = sc.getFont(family, style, size);
    }
    return f;
}
 
源代码19 项目: JDKSourceCode1.8   文件: CSS.java
Object parseCssValue(String value) {
    int cIndex = value.indexOf(',');
    FontFamily ff = new FontFamily();
    ff.svalue = value;
    ff.family = null;

    if (cIndex == -1) {
        setFontName(ff, value);
    }
    else {
        boolean done = false;
        int lastIndex;
        int length = value.length();
        cIndex = 0;
        while (!done) {
            // skip ws.
            while (cIndex < length &&
                   Character.isWhitespace(value.charAt(cIndex)))
                cIndex++;
            // Find next ','
            lastIndex = cIndex;
            cIndex = value.indexOf(',', cIndex);
            if (cIndex == -1) {
                cIndex = length;
            }
            if (lastIndex < length) {
                if (lastIndex != cIndex) {
                    int lastCharIndex = cIndex;
                    if (cIndex > 0 && value.charAt(cIndex - 1) == ' '){
                        lastCharIndex--;
                    }
                    setFontName(ff, value.substring
                                (lastIndex, lastCharIndex));
                    done = (ff.family != null);
                }
                cIndex++;
            }
            else {
                done = true;
            }
        }
    }
    if (ff.family == null) {
        ff.family = Font.SANS_SERIF;
    }
    return ff;
}
 
源代码20 项目: hottub   文件: SunFontManager.java
/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}