jdk/src/java.desktop/share/classes/sun/font/Font2DHandle.java
author prr
Wed, 09 Nov 2016 11:28:13 -0800
changeset 42208 7c1017f0ade5
parent 25859 3317bb8137f4
permissions -rw-r--r--
8155874: Fix java.desktop deprecation warnings about Class.newInstance Reviewed-by: serb, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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.font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This class is used so that a java.awt.Font does not directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * reference a Font2D object. This introduces occasional minor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * de-referencing overhead but increases robustness of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * implementation when "bad fonts" are encountered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A handle is created by a Font2D constructor and references
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * the Font2D itself. In the event that the Font2D implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * determines it the font resource has errors (a bad font file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * it makes its handle point at another "stable" Font2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Once all referers no longer have a reference to the Font2D it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * may be GC'd and its resources freed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This does not immediately help in the case that objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * already using a bad Font2D (ie have already dereferenced the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * handle) so there is a window for more problems. However this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * is already the case as this is the code which must detect the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * problem.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * However there is also the possibility of intercepting problems
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * even when a font2D reference is already directly held. Certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * validation points may check that font2Dhandle.font2D == font2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * If this is not true, then this font2D is not valid. Arguably
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * this check also just needs to be a de-referencing assignment :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * font2D = font2DHandle.font2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The net effect of these steps is that very soon after a font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * is identified as bad, that references and uses of it will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * eliminated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * In the initial implementation a Font2DHandle is what is held by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * - java.awt.Font
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * - FontManager.initialisedFonts map
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Font2D is held by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * - FontFamily objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * - FontManager.registeredFonts map
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * - FontInfo object on a SunGraphics2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * On discovering a bad font, all but the latter remove references to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the font. See FontManager.deRegisterBadFont(Font2D)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public final class Font2DHandle {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public Font2D font2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public Font2DHandle(Font2D font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        font2D = font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}