sun.font.FontUtilities Java Examples

The following examples show how to use sun.font.FontUtilities. 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: FontConfiguration.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public FontConfiguration(SunFontManager fm) {
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger()
            .info("Creating standard Font Configuration");
    }
    if (FontUtilities.debugFonts() && logger == null) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    fontManager = fm;
    setOsNameAndVersion();  /* static initialization */
    setEncoding();          /* static initialization */
    /* Separating out the file location from the rest of the
     * initialisation, so the caller has the option of doing
     * something else if a suitable file isn't found.
     */
    findFontConfigFile();
}
 
Example #2
Source File: FontConfiguration.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public FontConfiguration(SunFontManager fm,
                         boolean preferLocaleFonts,
                         boolean preferPropFonts) {
    fontManager = fm;
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger()
            .info("Creating alternate Font Configuration");
    }
    this.preferLocaleFonts = preferLocaleFonts;
    this.preferPropFonts = preferPropFonts;
    /* fontConfig should be initialised by default constructor, and
     * its data tables can be shared, since readFontConfigFile doesn't
     * update any other state. Also avoid a doPrivileged block.
     */
    initFontConfig();
}
 
Example #3
Source File: SwingUtilities2.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static FontRenderContext getFRCProperty(JComponent c) {
    if (c != null) {
        GraphicsConfiguration gc = c.getGraphicsConfiguration();
        AffineTransform tx = (gc == null) ? null : gc.getDefaultTransform();
        // [tav] workaround deadlock on MacOSX until fixed, JRE-226
        if (!FontUtilities.isMacOSX && tx == null && !GraphicsEnvironment.isHeadless()) {
            tx =  GraphicsEnvironment
                    .getLocalGraphicsEnvironment()
                    .getDefaultScreenDevice()
                    .getDefaultConfiguration()
                    .getDefaultTransform();
        }
        AATextInfo info = (AATextInfo)c.getClientProperty(AA_TEXT_PROPERTY_KEY);
        if (info != null) {
            return info.getFRC(tx);
        }
    }
    return null;
}
 
Example #4
Source File: FontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public FontConfiguration(SunFontManager fm,
                         boolean preferLocaleFonts,
                         boolean preferPropFonts) {
    fontManager = fm;
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger()
            .info("Creating alternate Font Configuration");
    }
    this.preferLocaleFonts = preferLocaleFonts;
    this.preferPropFonts = preferPropFonts;
    /* fontConfig should be initialised by default constructor, and
     * its data tables can be shared, since readFontConfigFile doesn't
     * update any other state. Also avoid a doPrivileged block.
     */
    initFontConfig();
}
 
Example #5
Source File: FontConfiguration.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public FontConfiguration(SunFontManager fm) {
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger()
            .info("Creating standard Font Configuration");
    }
    if (FontUtilities.debugFonts() && logger == null) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    fontManager = fm;
    setOsNameAndVersion();  /* static initialization */
    setEncoding();          /* static initialization */
    /* Separating out the file location from the rest of the
     * initialisation, so the caller has the option of doing
     * something else if a suitable file isn't found.
     */
    findFontConfigFile();
}
 
Example #6
Source File: FontConfiguration.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public FontConfiguration(SunFontManager fm) {
    if (FontUtilities.debugFonts()) {
        FontUtilities.getLogger()
            .info("Creating standard Font Configuration");
    }
    if (FontUtilities.debugFonts() && logger == null) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    fontManager = fm;
    setOsNameAndVersion();  /* static initialization */
    setEncoding();          /* static initialization */
    /* Separating out the file location from the rest of the
     * initialisation, so the caller has the option of doing
     * something else if a suitable file isn't found.
     */
    findFontConfigFile();
}
 
Example #7
Source File: X11FontManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void getPlatformFontPathFromFontConfig() {
    if (fontConfigDirs == null) {
        fontConfigDirs = getFontConfiguration().getAWTFontPathSet();
        if (FontUtilities.debugFonts() && fontConfigDirs != null) {
            String[] names = fontConfigDirs.toArray(new String[0]);
            for (int i=0;i<names.length;i++) {
                FontUtilities.getLogger().info("awtfontpath : " + names[i]);
            }
        }
    }
}
 
Example #8
Source File: X11FontManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected FontConfiguration createFontConfiguration() {
    /* The logic here decides whether to use a preconfigured
     * fontconfig.properties file, or synthesise one using platform APIs.
     * On Solaris (as opposed to OpenSolaris) we try to use the
     * pre-configured ones, but if the files it specifies are missing
     * we fail-safe to synthesising one. This might happen if Solaris
     * changes its fonts.
     * For OpenSolaris I don't expect us to ever create fontconfig files,
     * so it will always synthesise. Note that if we misidentify
     * OpenSolaris as Solaris, then the test for the presence of
     * Solaris-only font files will correct this.
     * For Linux we require an exact match of distro and version to
     * use the preconfigured file, and also that it points to
     * existent fonts.
     * If synthesising fails, we fall back to any preconfigured file
     * and do the best we can. For the commercial JDK this will be
     * fine as it includes the Lucida fonts. OpenJDK should not hit
     * this as the synthesis should always work on its platforms.
     */
    FontConfiguration mFontConfig = new MFontConfiguration(this);
    if (FontUtilities.isOpenSolaris ||
        (FontUtilities.isLinux &&
         (!mFontConfig.foundOsSpecificFile() ||
          !mFontConfig.fontFilesArePresent()) ||
         (FontUtilities.isSolaris && !mFontConfig.fontFilesArePresent()))) {
        FcFontConfiguration fcFontConfig =
            new FcFontConfiguration(this);
        if (fcFontConfig.init()) {
            return fcFontConfig;
        }
    }
    mFontConfig.init();
    return mFontConfig;
}
 
Example #9
Source File: SunGraphics2D.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setFont(Font font) {
    /* replacing the reference equality test font != this.font with
     * !font.equals(this.font) did not yield any measurable difference
     * in testing, but there may be yet to be identified cases where it
     * is beneficial.
     */
    if (font != null && font!=this.font/*!font.equals(this.font)*/) {
        /* In the GASP AA case the textpipe depends on the glyph size
         * as determined by graphics and font transforms as well as the
         * font size, and information in the font. But we may invalidate
         * the pipe only to find that it made no difference.
         * Deferring pipe invalidation to checkFontInfo won't work because
         * when called we may already be rendering to the wrong pipe.
         * So, if the font is transformed, or the graphics has more than
         * a simple scale, we'll take that as enough of a hint to
         * revalidate everything. But if they aren't we will
         * use the font's point size to query the gasp table and see if
         * what it says matches what's currently being used, in which
         * case there's no need to invalidate the textpipe.
         * This should be sufficient for all typical uses cases.
         */
        if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
            textpipe != invalidpipe &&
            (transformState > TRANSFORM_ANY_TRANSLATE ||
             font.isTransformed() ||
             fontInfo == null || // Precaution, if true shouldn't get here
             (fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
                 FontUtilities.getFont2D(font).
                     useAAForPtSize(font.getSize()))) {
            textpipe = invalidpipe;
        }
        this.font = font;
        this.fontMetrics = null;
        this.validFontInfo = false;
    }
}
 
Example #10
Source File: X11FontManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void registerPlatformFontsUsedByFontConfiguration() {
    // Lazily initialize fontConfigDirs.
    getPlatformFontPathFromFontConfig();
    if (fontConfigDirs == null) {
        return;
    }
    if (FontUtilities.isLinux) {
        fontConfigDirs.add(jreLibDirName+File.separator+"oblique-fonts");
    }
    fontdirs = (String[])fontConfigDirs.toArray(new String[0]);
}
 
Example #11
Source File: MFontConfiguration.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm) {
    super(fm);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #12
Source File: Font.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified <code>FontRenderContext</code>.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * <code>TextLayout</code>.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified <code>FontRenderContext</code>
 * @return a <code>Rectangle2D</code> that is the bounding box of the
 * specified array of characters in the specified
 * <code>FontRenderContext</code>.
 * @throws IndexOutOfBoundsException if <code>beginIndex</code> is
 *         less than zero, or <code>limit</code> is greater than the
 *         length of <code>chars</code>, or <code>beginIndex</code>
 *         is greater than <code>limit</code>.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex,
                                                 limit - beginIndex, frc);
        return gv.getLogicalBounds();
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example #13
Source File: Font.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the logical bounds of the specified array of characters
 * in the specified {@code FontRenderContext}.  The logical
 * bounds contains the origin, ascent, advance, and height, which
 * includes the leading.  The logical bounds does not always enclose
 * all the text.  For example, in some languages and in some fonts,
 * accent marks can be positioned above the ascent or below the
 * descent.  To obtain a visual bounding box, which encloses all the
 * text, use the {@link TextLayout#getBounds() getBounds} method of
 * {@code TextLayout}.
 * <p>Note: The returned bounds is in baseline-relative coordinates
 * (see {@link java.awt.Font class notes}).
 * @param chars an array of characters
 * @param beginIndex the initial offset in the array of
 * characters
 * @param limit the end offset in the array of characters
 * @param frc the specified {@code FontRenderContext}
 * @return a {@code Rectangle2D} that is the bounding box of the
 * specified array of characters in the specified
 * {@code FontRenderContext}.
 * @throws IndexOutOfBoundsException if {@code beginIndex} is
 *         less than zero, or {@code limit} is greater than the
 *         length of {@code chars}, or {@code beginIndex}
 *         is greater than {@code limit}.
 * @see FontRenderContext
 * @see Font#createGlyphVector
 * @since 1.2
 */
public Rectangle2D getStringBounds(char [] chars,
                                int beginIndex, int limit,
                                   FontRenderContext frc) {
    if (beginIndex < 0) {
        throw new IndexOutOfBoundsException("beginIndex: " + beginIndex);
    }
    if (limit > chars.length) {
        throw new IndexOutOfBoundsException("limit: " + limit);
    }
    if (beginIndex > limit) {
        throw new IndexOutOfBoundsException("range length: " +
                                            (limit - beginIndex));
    }

    // this code should be in textlayout
    // quick check for simple text, assume GV ok to use if simple

    boolean simple = values == null ||
        (values.getKerning() == 0 && values.getLigatures() == 0 &&
          values.getBaselineTransform() == null);
    if (simple) {
        simple = ! FontUtilities.isComplexText(chars, beginIndex, limit);
    }

    if (simple) {
        FontDesignMetrics metrics = FontDesignMetrics.getMetrics(this, frc);
        return metrics.getSimpleBounds(chars, beginIndex, limit-beginIndex);
    } else {
        // need char array constructor on textlayout
        String str = new String(chars, beginIndex, limit - beginIndex);
        TextLayout tl = new TextLayout(str, this, frc);
        return new Rectangle2D.Float(0, -tl.getAscent(), tl.getAdvance(),
                                     tl.getAscent() + tl.getDescent() +
                                     tl.getLeading());
    }
}
 
Example #14
Source File: FontConfiguration.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean needToSearchForFile(String fileName) {
    if (!FontUtilities.isLinux) {
        return false;
    } else if (existsMap == null) {
       existsMap = new HashMap<String, Boolean>();
    }
    Boolean exists = existsMap.get(fileName);
    if (exists == null) {
        /* call getNumberCoreFonts() to ensure these are initialised, and
         * if this file isn't for a core component, ie, is a for a fallback
         * font which very typically isn't available, then can't afford
         * to take the start-up penalty to search for it.
         */
        getNumberCoreFonts();
        if (!coreFontFileNames.contains(fileName)) {
            exists = Boolean.TRUE;
        } else {
            exists = Boolean.valueOf((new File(fileName)).exists());
            existsMap.put(fileName, exists);
            if (FontUtilities.debugFonts() &&
                exists == Boolean.FALSE) {
                logger.warning("Couldn't locate font file " + fileName);
            }
        }
    }
    return exists == Boolean.FALSE;
}
 
Example #15
Source File: StyleContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a new font.  This returns a Font from a cache
 * if a cached font exists.  If not, a Font is added to
 * the cache.  This is basically a low-level cache for
 * 1.1 font features.
 *
 * @param family the font family (such as "Monospaced")
 * @param style the style of the font (such as Font.PLAIN)
 * @param size the point size &gt;= 1
 * @return the new font
 */
public Font getFont(String family, int style, int size) {
    fontSearch.setValue(family, style, size);
    Font f = fontTable.get(fontSearch);
    if (f == null) {
        // haven't seen this one yet.
        Style defaultStyle =
            getStyle(StyleContext.DEFAULT_STYLE);
        if (defaultStyle != null) {
            final String FONT_ATTRIBUTE_KEY = "FONT_ATTRIBUTE_KEY";
            Font defaultFont =
                (Font) defaultStyle.getAttribute(FONT_ATTRIBUTE_KEY);
            if (defaultFont != null
                  && defaultFont.getFamily().equalsIgnoreCase(family)) {
                f = defaultFont.deriveFont(style, size);
            }
        }
        if (f == null) {
            f = new Font(family, style, size);
        }
        if (! FontUtilities.fontSupportsDefaultEncoding(f)) {
            f = FontUtilities.getCompositeFontUIResource(f);
        }
        FontKey key = new FontKey(family, style, size);
        fontTable.put(key, f);
    }
    return f;
}
 
Example #16
Source File: X11FontManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void getPlatformFontPathFromFontConfig() {
    if (fontConfigDirs == null) {
        fontConfigDirs = getFontConfiguration().getAWTFontPathSet();
        if (FontUtilities.debugFonts() && fontConfigDirs != null) {
            String[] names = fontConfigDirs.toArray(new String[0]);
            for (int i=0;i<names.length;i++) {
                FontUtilities.getLogger().info("awtfontpath : " + names[i]);
            }
        }
    }
}
 
Example #17
Source File: StyleContext.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a new font.  This returns a Font from a cache
 * if a cached font exists.  If not, a Font is added to
 * the cache.  This is basically a low-level cache for
 * 1.1 font features.
 *
 * @param family the font family (such as "Monospaced")
 * @param style the style of the font (such as Font.PLAIN)
 * @param size the point size &gt;= 1
 * @return the new font
 */
public Font getFont(String family, int style, int size) {
    fontSearch.setValue(family, style, size);
    Font f = fontTable.get(fontSearch);
    if (f == null) {
        // haven't seen this one yet.
        Style defaultStyle =
            getStyle(StyleContext.DEFAULT_STYLE);
        if (defaultStyle != null) {
            final String FONT_ATTRIBUTE_KEY = "FONT_ATTRIBUTE_KEY";
            Font defaultFont =
                (Font) defaultStyle.getAttribute(FONT_ATTRIBUTE_KEY);
            if (defaultFont != null
                  && defaultFont.getFamily().equalsIgnoreCase(family)) {
                f = defaultFont.deriveFont(style, size);
            }
        }
        if (f == null) {
            f = new Font(family, style, size);
        }
        if (! FontUtilities.fontSupportsDefaultEncoding(f)) {
            f = FontUtilities.getCompositeFontUIResource(f);
        }
        FontKey key = new FontKey(family, style, size);
        fontTable.put(key, f);
    }
    return f;
}
 
Example #18
Source File: X11FontManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected FontConfiguration createFontConfiguration() {
    /* The logic here decides whether to use a preconfigured
     * fontconfig.properties file, or synthesise one using platform APIs.
     * On Solaris (as opposed to OpenSolaris) we try to use the
     * pre-configured ones, but if the files it specifies are missing
     * we fail-safe to synthesising one. This might happen if Solaris
     * changes its fonts.
     * For OpenSolaris I don't expect us to ever create fontconfig files,
     * so it will always synthesise. Note that if we misidentify
     * OpenSolaris as Solaris, then the test for the presence of
     * Solaris-only font files will correct this.
     * For Linux we require an exact match of distro and version to
     * use the preconfigured file, and also that it points to
     * existent fonts.
     * If synthesising fails, we fall back to any preconfigured file
     * and do the best we can.
     */
    FontConfiguration mFontConfig = new MFontConfiguration(this);
    if (FontUtilities.isOpenSolaris ||
        (FontUtilities.isLinux &&
         (!mFontConfig.foundOsSpecificFile() ||
          !mFontConfig.fontFilesArePresent()) ||
         (FontUtilities.isSolaris && !mFontConfig.fontFilesArePresent()))) {
        FcFontConfiguration fcFontConfig =
            new FcFontConfiguration(this);
        if (fcFontConfig.init()) {
            return fcFontConfig;
        }
    }
    mFontConfig.init();
    return mFontConfig;
}
 
Example #19
Source File: MFontConfiguration.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm) {
    super(fm);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #20
Source File: FontConfiguration.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void readFontConfigFile(File f) {
    /* This is invoked here as readFontConfigFile is only invoked
     * once per VM, and always in a privileged context, thus the
     * directory containing installed fall back fonts is accessed
     * from this context
     */
    getInstalledFallbackFonts(javaLib);

    if (f != null) {
        try {
            FileInputStream in = new FileInputStream(f.getPath());
            if (isProperties) {
                loadProperties(in);
            } else {
                loadBinary(in);
            }
            in.close();
            if (FontUtilities.debugFonts()) {
                logger.config("Read logical font configuration from " + f);
            }
        } catch (IOException e) {
            if (FontUtilities.debugFonts()) {
                logger.config("Failed to read logical font configuration from " + f);
            }
        }
    }
    String version = getVersion();
    if (!"1".equals(version) && FontUtilities.debugFonts()) {
        logger.config("Unsupported fontconfig version: " + version);
    }
}
 
Example #21
Source File: SunGraphics2D.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setFont(Font font) {
    /* replacing the reference equality test font != this.font with
     * !font.equals(this.font) did not yield any measurable difference
     * in testing, but there may be yet to be identified cases where it
     * is beneficial.
     */
    if (font != null && font!=this.font/*!font.equals(this.font)*/) {
        /* In the GASP AA case the textpipe depends on the glyph size
         * as determined by graphics and font transforms as well as the
         * font size, and information in the font. But we may invalidate
         * the pipe only to find that it made no difference.
         * Deferring pipe invalidation to checkFontInfo won't work because
         * when called we may already be rendering to the wrong pipe.
         * So, if the font is transformed, or the graphics has more than
         * a simple scale, we'll take that as enough of a hint to
         * revalidate everything. But if they aren't we will
         * use the font's point size to query the gasp table and see if
         * what it says matches what's currently being used, in which
         * case there's no need to invalidate the textpipe.
         * This should be sufficient for all typical uses cases.
         */
        if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
            textpipe != invalidpipe &&
            (transformState > TRANSFORM_ANY_TRANSLATE ||
             font.isTransformed() ||
             fontInfo == null || // Precaution, if true shouldn't get here
             (fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
                 FontUtilities.getFont2D(font).
                     useAAForPtSize(font.getSize()))) {
            textpipe = invalidpipe;
        }
        this.font = font;
        this.fontMetrics = null;
        this.validFontInfo = false;
    }
}
 
Example #22
Source File: MFontConfiguration.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm,
                          boolean preferLocaleFonts,
                          boolean preferPropFonts) {
    super(fm, preferLocaleFonts, preferPropFonts);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #23
Source File: MFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm) {
    super(fm);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #24
Source File: MFontConfiguration.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm) {
    super(fm);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #25
Source File: StyleContext.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a new font.  This returns a Font from a cache
 * if a cached font exists.  If not, a Font is added to
 * the cache.  This is basically a low-level cache for
 * 1.1 font features.
 *
 * @param family the font family (such as "Monospaced")
 * @param style the style of the font (such as Font.PLAIN)
 * @param size the point size &gt;= 1
 * @return the new font
 */
public Font getFont(String family, int style, int size) {
    fontSearch.setValue(family, style, size);
    Font f = fontTable.get(fontSearch);
    if (f == null) {
        // haven't seen this one yet.
        Style defaultStyle =
            getStyle(StyleContext.DEFAULT_STYLE);
        if (defaultStyle != null) {
            final String FONT_ATTRIBUTE_KEY = "FONT_ATTRIBUTE_KEY";
            Font defaultFont =
                (Font) defaultStyle.getAttribute(FONT_ATTRIBUTE_KEY);
            if (defaultFont != null
                  && defaultFont.getFamily().equalsIgnoreCase(family)) {
                f = defaultFont.deriveFont(style, size);
            }
        }
        if (f == null) {
            f = new Font(family, style, size);
        }
        if (! FontUtilities.fontSupportsDefaultEncoding(f)) {
            f = FontUtilities.getCompositeFontUIResource(f);
        }
        FontKey key = new FontKey(family, style, size);
        fontTable.put(key, f);
    }
    return f;
}
 
Example #26
Source File: X11FontManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected FontConfiguration createFontConfiguration() {
    /* The logic here decides whether to use a preconfigured
     * fontconfig.properties file, or synthesise one using platform APIs.
     * On Solaris (as opposed to OpenSolaris) we try to use the
     * pre-configured ones, but if the files it specifies are missing
     * we fail-safe to synthesising one. This might happen if Solaris
     * changes its fonts.
     * For OpenSolaris I don't expect us to ever create fontconfig files,
     * so it will always synthesise. Note that if we misidentify
     * OpenSolaris as Solaris, then the test for the presence of
     * Solaris-only font files will correct this.
     * For Linux we require an exact match of distro and version to
     * use the preconfigured file, and also that it points to
     * existent fonts.
     * If synthesising fails, we fall back to any preconfigured file
     * and do the best we can. For the commercial JDK this will be
     * fine as it includes the Lucida fonts. OpenJDK should not hit
     * this as the synthesis should always work on its platforms.
     */
    FontConfiguration mFontConfig = new MFontConfiguration(this);
    if (FontUtilities.isOpenSolaris ||
        (FontUtilities.isLinux &&
         (!mFontConfig.foundOsSpecificFile() ||
          !mFontConfig.fontFilesArePresent()) ||
         (FontUtilities.isSolaris && !mFontConfig.fontFilesArePresent()))) {
        FcFontConfiguration fcFontConfig =
            new FcFontConfiguration(this);
        if (fcFontConfig.init()) {
            return fcFontConfig;
        }
    }
    mFontConfig.init();
    return mFontConfig;
}
 
Example #27
Source File: FontConfiguration.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void readFontConfigFile(File f) {
    /* This is invoked here as readFontConfigFile is only invoked
     * once per VM, and always in a privileged context, thus the
     * directory containing installed fall back fonts is accessed
     * from this context
     */
    getInstalledFallbackFonts(javaLib);

    if (f != null) {
        try {
            FileInputStream in = new FileInputStream(f.getPath());
            if (isProperties) {
                loadProperties(in);
            } else {
                loadBinary(in);
            }
            in.close();
            if (FontUtilities.debugFonts()) {
                logger.config("Read logical font configuration from " + f);
            }
        } catch (IOException e) {
            if (FontUtilities.debugFonts()) {
                logger.config("Failed to read logical font configuration from " + f);
            }
        }
    }
    String version = getVersion();
    if (!"1".equals(version) && FontUtilities.debugFonts()) {
        logger.config("Unsupported fontconfig version: " + version);
    }
}
 
Example #28
Source File: MFontConfiguration.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm,
                          boolean preferLocaleFonts,
                          boolean preferPropFonts) {
    super(fm, preferLocaleFonts, preferPropFonts);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #29
Source File: MFontConfiguration.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public MFontConfiguration(SunFontManager fm,
                          boolean preferLocaleFonts,
                          boolean preferPropFonts) {
    super(fm, preferLocaleFonts, preferPropFonts);
    if (FontUtilities.debugFonts()) {
        logger = PlatformLogger.getLogger("sun.awt.FontConfiguration");
    }
    initTables();
}
 
Example #30
Source File: StyleContext.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a new font.  This returns a Font from a cache
 * if a cached font exists.  If not, a Font is added to
 * the cache.  This is basically a low-level cache for
 * 1.1 font features.
 *
 * @param family the font family (such as "Monospaced")
 * @param style the style of the font (such as Font.PLAIN)
 * @param size the point size &gt;= 1
 * @return the new font
 */
public Font getFont(String family, int style, int size) {
    fontSearch.setValue(family, style, size);
    Font f = fontTable.get(fontSearch);
    if (f == null) {
        // haven't seen this one yet.
        Style defaultStyle =
            getStyle(StyleContext.DEFAULT_STYLE);
        if (defaultStyle != null) {
            final String FONT_ATTRIBUTE_KEY = "FONT_ATTRIBUTE_KEY";
            Font defaultFont =
                (Font) defaultStyle.getAttribute(FONT_ATTRIBUTE_KEY);
            if (defaultFont != null
                  && defaultFont.getFamily().equalsIgnoreCase(family)) {
                f = defaultFont.deriveFont(style, size);
            }
        }
        if (f == null) {
            f = new Font(family, style, size);
        }
        if (! FontUtilities.fontSupportsDefaultEncoding(f)) {
            f = FontUtilities.getCompositeFontUIResource(f);
        }
        FontKey key = new FontKey(family, style, size);
        fontTable.put(key, f);
    }
    return f;
}