Java Code Examples for java.awt.Font#SANS_SERIF

The following examples show how to use java.awt.Font#SANS_SERIF . 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: ResizedFontLabel.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: TextFont.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: CollagePanel.java    From ChatGameFontificator with The Unlicense 5 votes vote down vote up
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();
}
 
Example 4
Source File: SunFontManager.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: ClassLoaderLeakTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected void doTest() {
    Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
    f.getNumGlyphs();
}
 
Example 6
Source File: CSS.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
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;
}
 
Example 7
Source File: CSS.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: CSS.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: SunFontManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: CSS.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: SunFontManager.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: ImageCreator.java    From TeaStore with Apache License 2.0 4 votes vote down vote up
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()));
}
 
Example 13
Source File: SunFontManager.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: ClassLoaderLeakTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected void doTest() {
    Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
    f.getNumGlyphs();
}
 
Example 15
Source File: SunFontManager.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: CSS.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: ClassLoaderLeakTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void doTest() {
    Font f = new Font(Font.SANS_SERIF, Font.ITALIC, 24);
    f.getNumGlyphs();
}
 
Example 18
Source File: PdfBoxFontMapper.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
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.");
		}
}
 
Example 19
Source File: CSS.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 20
Source File: SunFontManager.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}