jdk/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
author tdv
Wed, 14 May 2008 16:05:07 -0700
changeset 557 800259d3792b
parent 550 e85f91b9bb95
child 883 c3e81f0acd3d
child 715 f16baef3a20e
permissions -rw-r--r--
6675596: SurfaceManagerFactory should allow plugging in different implementations Reviewed-by: tdv, campbell Contributed-by: Roman Kennke <roman.kennke@aicas.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ListIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.DisplayChangedListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.SunDisplayChanger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.windows.WFontConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.windows.WPrinterJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.awt.windows.WToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.font.FontManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.java2d.SunGraphicsEnvironment;
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 550
diff changeset
    45
import sun.java2d.SurfaceManagerFactory;
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 550
diff changeset
    46
import sun.java2d.WindowsSurfaceManagerFactory;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.java2d.windows.WindowsFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This is an implementation of a GraphicsEnvironment object for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * default local GraphicsEnvironment used by the Java Runtime Environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * for Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class Win32GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    extends SunGraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        // Ensure awt is loaded already.  Also, this forces static init
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        // of WToolkit and Toolkit, which we depend upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        WToolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // setup flags before initializing native layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        WindowsFlags.initFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        initDisplayWrapper();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        eudcFontFileName = getEUDCFontFile();
557
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 550
diff changeset
    69
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 550
diff changeset
    70
        // Install correct surface manager factory.
800259d3792b 6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents: 550
diff changeset
    71
        SurfaceManagerFactory.setInstance(new WindowsSurfaceManagerFactory());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Noop function that just acts as an entry point for someone to force
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * a static initialization of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static void init() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Initializes native components of the graphics environment.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * includes everything from the native GraphicsDevice elements to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * the DirectX rendering layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static native void initDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static boolean displayInitialized;      // = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static void initDisplayWrapper() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (!displayInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            displayInitialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            initDisplay();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public Win32GraphicsEnvironment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected native int getNumScreens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected native int getDefaultScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public GraphicsDevice getDefaultScreenDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return getScreenDevices()[getDefaultScreen()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns the number of pixels per logical inch along the screen width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * In a system with multiple display monitors, this value is the same for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * all monitors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @returns number of pixels per logical inch in X direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public native int getXResolution();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Returns the number of pixels per logical inch along the screen height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * In a system with multiple display monitors, this value is the same for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * all monitors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @returns number of pixels per logical inch in Y direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public native int getYResolution();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * ----DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // list of invalidated graphics devices (those which were removed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private ArrayList<WeakReference<Win32GraphicsDevice>> oldDevices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * From DisplayChangeListener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Called from WToolkit and executed on the event thread when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * display settings are changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // getNumScreens() will return the correct current number of screens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        GraphicsDevice oldScreens[] = screens;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // go through the list of current devices and determine if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // could be reused, or will have to be replaced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (oldScreens != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            for (int i = 0; i < oldScreens.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                if (!(screens[i] instanceof Win32GraphicsDevice)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    // REMIND: can we ever have anything other than Win32GD?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    assert (false) : oldScreens[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                Win32GraphicsDevice gd = (Win32GraphicsDevice)oldScreens[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                // devices may be invalidated from the native code when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                // display change happens (device add/removal also causes a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                // display change)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                if (!gd.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    if (oldDevices == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        oldDevices =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                            new ArrayList<WeakReference<Win32GraphicsDevice>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    oldDevices.add(new WeakReference<Win32GraphicsDevice>(gd));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                } else if (i < newDevices.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    // reuse the device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    newDevices[i] = gd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            oldScreens = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        // create the new devices (those that weren't reused)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        for (int i = 0; i < newDevices.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if (newDevices[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                newDevices[i] = makeScreenDevice(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // install the new array of devices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        // Note: no synchronization here, it doesn't matter if a thread gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // a new or an old array this time around
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        screens = newDevices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        for (GraphicsDevice gd : screens) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (gd instanceof DisplayChangedListener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                ((DisplayChangedListener)gd).displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // re-invalidate all old devices. It's needed because those in the list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        // may become "invalid" again - if the current default device is removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        // for example. Also, they need to be notified about display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // changes as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (oldDevices != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            int defScreen = getDefaultScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            for (ListIterator<WeakReference<Win32GraphicsDevice>> it =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    oldDevices.listIterator(); it.hasNext();)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                Win32GraphicsDevice gd = it.next().get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                if (gd != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    gd.invalidate(defScreen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    gd.displayChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                    // no more references to this device, remove it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // Reset the static GC for the (possibly new) default screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        WToolkit.resetGC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        // notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // CachingSurfaceManagers) about the display change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        displayChanger.notifyListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        // note: do not call super.displayChanged, we've already done everything
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * ----END DISPLAY CHANGE SUPPORT----
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /* Used on Windows to obtain from the windows registry the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * of a file containing the system EUFC font. If running in one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * the locales for which this applies, and one is defined, the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * defined by this file is appended to all composite fonts as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * fallback component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private static native String getEUDCFontFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Whether registerFontFile expects absolute or relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * font file names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    protected boolean useAbsoluteFontFileNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /* Unlike the shared code version, this expects a base file name -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * not a full path name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * The font configuration file has base file names and the FontConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * class reports these back to the GraphicsEnvironment, so these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * are the componentFileNames of CompositeFonts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    protected void registerFontFile(String fontFileName, String[] nativeNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                                    int fontRank, boolean defer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        // REMIND: case compare depends on platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (registeredFontFiles.contains(fontFileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        registeredFontFiles.add(fontFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        int fontFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (ttFilter.accept(null, fontFileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            fontFormat = FontManager.FONTFORMAT_TRUETYPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else if (t1Filter.accept(null, fontFileName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            fontFormat = FontManager.FONTFORMAT_TYPE1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            /* on windows we don't use/register native fonts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (fontPath == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            fontPath = getPlatformFontPath(noType1Font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        /* Look in the JRE font directory first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * This is playing it safe as we would want to find fonts in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * JRE font directory ahead of those in the system directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        StringTokenizer parser = new StringTokenizer(tmpFontPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                                     File.pathSeparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            while (!found && parser.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                String newPath = parser.nextToken();
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 548
diff changeset
   268
                boolean ujr = newPath.equals(jreFontDirName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                File theFile = new File(newPath, fontFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                if (theFile.canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    String path = theFile.getAbsolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    if (defer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                        FontManager.registerDeferredFont(fontFileName, path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                                         nativeNames,
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 548
diff changeset
   276
                                                         fontFormat, ujr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                                         fontRank);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                        FontManager.registerFontFile(path, nativeNames,
550
e85f91b9bb95 6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents: 548
diff changeset
   280
                                                     fontFormat, ujr,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                                     fontRank);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        } catch (NoSuchElementException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            System.err.println(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            addToMissingFontFileList(fontFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /* register only TrueType/OpenType fonts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Because these need to be registed just for use when printing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * we defer the actual registration and the static initialiser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * for the printing class makes the call to registerJREFontsForPrinting()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    static String fontsForPrinting = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    protected void registerJREFontsWithPlatform(String pathName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        fontsForPrinting = pathName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public static void registerJREFontsForPrinting() {
548
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   305
        final String pathName;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        synchronized (Win32GraphicsEnvironment.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (fontsForPrinting == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            pathName = fontsForPrinting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            fontsForPrinting = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
548
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   314
        java.security.AccessController.doPrivileged(
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   315
            new java.security.PrivilegedAction() {
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   316
                public Object run() {
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   317
                    File f1 = new File(pathName);
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   318
                    String[] ls = f1.list(new TTFilter());
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   319
                    if (ls == null) {
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   320
                        return null;
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   321
                    }
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   322
                    for (int i=0; i <ls.length; i++ ) {
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   323
                        File fontFile = new File(f1, ls[i]);
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   324
                        registerFontWithPlatform(fontFile.getAbsolutePath());
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   325
                    }
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   326
                    return null;
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   327
                }
caed182cee6e 6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents: 2
diff changeset
   328
         });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    protected static native void registerFontWithPlatform(String fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    protected static native void deRegisterFontWithPlatform(String fontName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    protected GraphicsDevice makeScreenDevice(int screennum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return new Win32GraphicsDevice(screennum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    // Implements SunGraphicsEnvironment.createFontConfiguration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    protected FontConfiguration createFontConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return new WFontConfiguration(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public FontConfiguration createFontConfiguration(boolean preferLocaleFonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                                     boolean preferPropFonts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return new WFontConfiguration(this, preferLocaleFonts,preferPropFonts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}