Showing the changes to java/pkg/sun/font/Font2DHandle.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,72 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package sun.font; | |
| 27 | + | |
| 28 | +/* | |
| 29 | + * This class is used so that a java.awt.Font does not directly | |
| 30 | + * reference a Font2D object. This introduces occasional minor | |
| 31 | + * de-referencing overhead but increases robustness of the | |
| 32 | + * implementation when "bad fonts" are encountered. | |
| 33 | + * A handle is created by a Font2D constructor and references | |
| 34 | + * the Font2D itself. In the event that the Font2D implementation | |
| 35 | + * determines it the font resource has errors (a bad font file) | |
| 36 | + * it makes its handle point at another "stable" Font2D. | |
| 37 | + * Once all referers no longer have a reference to the Font2D it | |
| 38 | + * may be GC'd and its resources freed. | |
| 39 | + * This does not immediately help in the case that objects are | |
| 40 | + * already using a bad Font2D (ie have already dereferenced the | |
| 41 | + * handle) so there is a window for more problems. However this | |
| 42 | + * is already the case as this is the code which must detect the | |
| 43 | + * problem. | |
| 44 | + * However there is also the possibility of intercepting problems | |
| 45 | + * even when a font2D reference is already directly held. Certain | |
| 46 | + * validation points may check that font2Dhandle.font2D == font2D | |
| 47 | + * If this is not true, then this font2D is not valid. Arguably | |
| 48 | + * this check also just needs to be a de-referencing assignment : | |
| 49 | + * font2D = font2DHandle.font2D. | |
| 50 | + * The net effect of these steps is that very soon after a font | |
| 51 | + * is identified as bad, that references and uses of it will be | |
| 52 | + * eliminated. | |
| 53 | + * In the initial implementation a Font2DHandle is what is held by | |
| 54 | + * - java.awt.Font | |
| 55 | + * - FontManager.initialisedFonts map | |
| 56 | + * Font2D is held by | |
| 57 | + * - FontFamily objects | |
| 58 | + * - FontManager.registeredFonts map | |
| 59 | + * - FontInfo object on a SunGraphics2D | |
| 60 | + * | |
| 61 | + * On discovering a bad font, all but the latter remove references to | |
| 62 | + * the font. See FontManager.deRegisterBadFont(Font2D) | |
| 63 | + */ | |
| 64 | + | |
| 65 | +public final class Font2DHandle { | |
| 66 | + | |
| 67 | + public Font2D font2D; | |
| 68 | + | |
| 69 | + public Font2DHandle(Font2D font) { | |
| 70 | + font2D = font; | |
| 71 | + } | |
| 72 | +} | |