Font2DHandle.java revision 2362
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class is used so that a java.awt.Font does not directly 0N/A * reference a Font2D object. This introduces occasional minor 0N/A * de-referencing overhead but increases robustness of the 0N/A * implementation when "bad fonts" are encountered. 0N/A * A handle is created by a Font2D constructor and references 0N/A * the Font2D itself. In the event that the Font2D implementation 0N/A * determines it the font resource has errors (a bad font file) 0N/A * it makes its handle point at another "stable" Font2D. 0N/A * Once all referers no longer have a reference to the Font2D it 0N/A * may be GC'd and its resources freed. 0N/A * This does not immediately help in the case that objects are 0N/A * already using a bad Font2D (ie have already dereferenced the 0N/A * handle) so there is a window for more problems. However this 0N/A * is already the case as this is the code which must detect the 0N/A * However there is also the possibility of intercepting problems 0N/A * even when a font2D reference is already directly held. Certain 0N/A * validation points may check that font2Dhandle.font2D == font2D 0N/A * If this is not true, then this font2D is not valid. Arguably 0N/A * this check also just needs to be a de-referencing assignment : 0N/A * font2D = font2DHandle.font2D. 0N/A * The net effect of these steps is that very soon after a font 0N/A * is identified as bad, that references and uses of it will be 0N/A * In the initial implementation a Font2DHandle is what is held by 0N/A * - FontFamily objects 0N/A * - FontManager.registeredFonts map 0N/A * - FontInfo object on a SunGraphics2D 0N/A * On discovering a bad font, all but the latter remove references to 0N/A * the font. See FontManager.deRegisterBadFont(Font2D)