Path: blob/master/src/java.desktop/share/classes/sun/font/Font2DHandle.java
41154 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.font;2627/*28* This class is used so that a java.awt.Font does not directly29* reference a Font2D object. This introduces occasional minor30* de-referencing overhead but increases robustness of the31* implementation when "bad fonts" are encountered.32* A handle is created by a Font2D constructor and references33* the Font2D itself. In the event that the Font2D implementation34* determines it the font resource has errors (a bad font file)35* it makes its handle point at another "stable" Font2D.36* Once all referers no longer have a reference to the Font2D it37* may be GC'd and its resources freed.38* This does not immediately help in the case that objects are39* already using a bad Font2D (ie have already dereferenced the40* handle) so there is a window for more problems. However this41* is already the case as this is the code which must detect the42* problem.43* However there is also the possibility of intercepting problems44* even when a font2D reference is already directly held. Certain45* validation points may check that font2Dhandle.font2D == font2D46* If this is not true, then this font2D is not valid. Arguably47* this check also just needs to be a de-referencing assignment :48* font2D = font2DHandle.font2D.49* The net effect of these steps is that very soon after a font50* is identified as bad, that references and uses of it will be51* eliminated.52* In the initial implementation a Font2DHandle is what is held by53* - java.awt.Font54* - FontManager.initialisedFonts map55* Font2D is held by56* - FontFamily objects57* - FontManager.registeredFonts map58* - FontInfo object on a SunGraphics2D59*60* On discovering a bad font, all but the latter remove references to61* the font. See FontManager.deRegisterBadFont(Font2D)62*/6364public final class Font2DHandle {6566public Font2D font2D;6768public Font2DHandle(Font2D font) {69font2D = font;70}71}727374