⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fontfactory.java

📁 How to get the java home dir.
💻 JAVA
字号:
package com.mindprod.common11;

import java.awt.Font;

/**
 * Modifies Java's logical font mapping
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0, 2008-08-20
 *          Created with IntelliJ IDEA.
 */
public class FontFactory
    {
    // -------------------------- PUBLIC STATIC METHODS --------------------------

    /**
     * Creates a new <code>Font</code> from the specified name, style and
     * point size.  Like new Font, but modifies the mapping of logical fonts.
     * <p/>
     *
     * @param fontFamilyName the font name.  This can be a font face name or a font
     *                       family name, and may represent either a logical font or a physical
     *                       font
     *                       The family names for logical fonts are: Dialog, DialogInput,
     *                       Monospaced, Serif, or SansSerif.
     * @param style          the style constant for the <code>Font</code>
     *                       The style argument is an integer bitmask that may
     *                       be PLAIN, or a bitwise union of BOLD and/or ITALIC
     *                       (for example, ITALIC or BOLD|ITALIC).
     * @param size           the point size of the <code>Font</code>
     * @return corresponding Font, with logical fonts remapped for Windows Vista to new native high res fonts.
     */
    public static Font build( String fontFamilyName, final int style, final int size )
        {
        String os = System.getProperty( "os.name", "unknown" );

        /* we meddle with Vista logical font mapping.  Potentially we could meddle with others.
         AIX
         Digital Unix
         FreeBSD
         HP UX
         Irix
         Linux
         Mac OS
         Mac OS X
         MPE/iX
         Netware 4.11
         OS/2
         Solaris
         Windows 2000
         Windows 95
         Windows 98
         Windows NT
         Windows Vista
         Windows XP
         */
        if ( os.equals( "Windows Vista" ) )
            {
            /* potentially meddle with various logical font mappings: Dialog DialogInput Monospaced	SansSerif Serif
              and adjust sizes. */
            if ( fontFamilyName.equals( "Dialog" ) )
                {
                fontFamilyName = "Segoe UI";
                }
            else if ( fontFamilyName.equals( "DialogInput" ) )
                {
                fontFamilyName = "Consolas";
                }
            else if ( fontFamilyName.equals( "Monospaced" ) )
                {
                fontFamilyName = "Consolas";
                }
            else if ( fontFamilyName.equals( "SanSerif" ) )
                {
                fontFamilyName = "Arial";
                }
            else if ( fontFamilyName.equals( "Serif" ) )
                {
                fontFamilyName = "Constantia";
                }
            }
        // we could also cache fonts, or weakly cache them.
        return new Font( fontFamilyName, style, size );
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -