FontManager.java 6.0 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Oracle designates this
D
duke 已提交
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Oracle in the LICENSE file that accompanied this code.
D
duke 已提交
10 11 12 13 14 15 16 17 18 19 20
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
21 22 23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
24 25 26 27 28 29 30 31 32
 */
package sun.font;

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.util.Locale;
import java.util.TreeMap;

R
rkennke 已提交
33
import javax.swing.plaf.FontUIResource;
D
duke 已提交
34

35 36
import javax.tools.annotation.GenerateNativeHeader;

R
rkennke 已提交
37
/**
D
duke 已提交
38 39 40
 * Interface between Java Fonts (java.awt.Font) and the underlying
 * font files/native font resources and the Java and native font scalers.
 */
41 42
/* No native methods here, but the constants are needed in the supporting JNI code */
@GenerateNativeHeader
R
rkennke 已提交
43
public interface FontManager {
D
duke 已提交
44

R
rkennke 已提交
45 46 47 48
    // These constants are used in findFont().
    public static final int NO_FALLBACK = 0;
    public static final int PHYSICAL_FALLBACK = 1;
    public static final int LOGICAL_FALLBACK = 2;
D
duke 已提交
49 50

    /**
R
rkennke 已提交
51 52 53 54 55
     * Register a new font. Please, note that {@code null} is not a valid
     * argument, and it's caller's responsibility to ensure that, but to keep
     * compatibility, if {@code null} is passed as an argument, {@code false}
     * is returned, and no {@link NullPointerException}
     * is thrown.
D
duke 已提交
56
     *
R
rkennke 已提交
57 58
     * As additional note, an implementation should ensure that this font
     * cannot override existing installed fonts.
D
duke 已提交
59
     *
R
rkennke 已提交
60 61 62
     * @param font
     * @return {@code true} is the font is successfully registered,
     * {@code false} otherwise.
D
duke 已提交
63
     */
R
rkennke 已提交
64
    public boolean registerFont(Font font);
D
duke 已提交
65

R
rkennke 已提交
66
    public void deRegisterBadFont(Font2D font2D);
D
duke 已提交
67 68 69 70 71 72 73 74

    /**
     * The client supplies a name and a style.
     * The name could be a family name, or a full name.
     * A font may exist with the specified style, or it may
     * exist only in some other style. For non-native fonts the scaler
     * may be able to emulate the required style.
     */
R
rkennke 已提交
75
    public Font2D findFont2D(String name, int style, int fallback);
D
duke 已提交
76

R
rkennke 已提交
77 78 79 80 81 82 83
    /**
     * Creates a Font2D for the specified font file, that is expected
     * to be in the specified font format (according to the constants
     * in java.awt.Font). The parameter {@code isCopy} is set to true
     * when the specified font file is actually a copy of the font data
     * and needs to be deleted afterwards. This method is called
     * for the Font.createFont() methods.
D
duke 已提交
84
     *
R
rkennke 已提交
85 86 87 88
     * @param fontFile the file holding the font data
     * @param fontFormat the expected font format
     * @param isCopy {@code true} if the file is a copy and needs to be
     *        deleted, {@code false} otherwise
D
duke 已提交
89
     *
R
rkennke 已提交
90
     * @return the created Font2D instance
D
duke 已提交
91
     */
R
rkennke 已提交
92 93 94
    public Font2D createFont2D(File fontFile, int fontFormat,
                               boolean isCopy, CreatedFontTracker tracker)
        throws FontFormatException;
D
duke 已提交
95 96

    /**
R
rkennke 已提交
97 98 99
     * If usingPerAppContextComposites is true, we are in "applet"
     * (eg browser) enviroment and at least one context has selected
     * an alternate composite font behaviour.
D
duke 已提交
100
     */
R
rkennke 已提交
101
    public boolean usingPerAppContextComposites();
D
duke 已提交
102 103

    /**
R
rkennke 已提交
104 105 106 107 108 109 110
     * Creates a derived composite font from the specified font (handle).
     *
     * @param family the font family of the derived font
     * @param style the font style of the derived font
     * @param handle the original font (handle)
     *
     * @return the handle for the derived font
D
duke 已提交
111
     */
R
rkennke 已提交
112 113
    public Font2DHandle getNewComposite(String family, int style,
                                        Font2DHandle handle);
D
duke 已提交
114 115

    /**
R
rkennke 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
     * Indicates a preference for locale-specific fonts in the mapping of
     * logical fonts to physical fonts. Calling this method indicates that font
     * rendering should primarily use fonts specific to the primary writing
     * system (the one indicated by the default encoding and the initial
     * default locale). For example, if the primary writing system is
     * Japanese, then characters should be rendered using a Japanese font
     * if possible, and other fonts should only be used for characters for
     * which the Japanese font doesn't have glyphs.
     * <p>
     * The actual change in font rendering behavior resulting from a call
     * to this method is implementation dependent; it may have no effect at
     * all, or the requested behavior may already match the default behavior.
     * The behavior may differ between font rendering in lightweight
     * and peered components.  Since calling this method requests a
     * different font, clients should expect different metrics, and may need
     * to recalculate window sizes and layout. Therefore this method should
     * be called before user interface initialisation.
     *
     * @see #preferProportionalFonts()
     * @since 1.5
D
duke 已提交
136
     */
R
rkennke 已提交
137
    public void preferLocaleFonts();
D
duke 已提交
138 139

    /**
R
rkennke 已提交
140 141 142 143 144 145
     * preferLocaleFonts() and preferProportionalFonts() are called to inform
     * that the application could be using an alternate set of composite
     * fonts, and so the implementation should try to create a CompositeFonts
     * with this directive in mind.
     *
     * @see #preferLocaleFonts()
D
duke 已提交
146
     */
R
rkennke 已提交
147
    public void preferProportionalFonts();
D
duke 已提交
148 149

}