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 import java.awt.FontFormatException; 29 import java.awt.geom.GeneralPath; 30 import java.awt.geom.Point2D; 31 import java.awt.geom.Rectangle2D; 32 import java.io.FileInputStream; 33 import java.lang.ref.WeakReference; 34 import java.nio.ByteBuffer; 35 import java.nio.channels.FileChannel; 36 37 public abstract class PhysicalFont extends Font2D { 38 39 protected String platName; 40 // nativeNames is a String or a (possibly null) String[]. 41 protected Object nativeNames; 42 equals(Object o)43 public boolean equals(Object o) { 44 if (o == null || o.getClass() != this.getClass()) { 45 return false; 46 } 47 PhysicalFont other = (PhysicalFont)o; 48 return 49 (this.fullName.equals(other.fullName)) && 50 ((this.platName == null && other.platName == null) || 51 (this.platName != null && this.platName.equals(other.platName))); 52 } 53 hashCode()54 public int hashCode() { 55 return fullName.hashCode() + 56 (platName != null ? platName.hashCode() : 0); 57 } 58 59 /** 60 * Opens the file (temporarily) and does basic verification. 61 * Initializes the CMAP 62 * @throws FontFormatException if the font can't be opened 63 * or fails verification, or there's no usable cmap 64 */ PhysicalFont(String platname, Object nativeNames)65 PhysicalFont(String platname, Object nativeNames) 66 throws FontFormatException { 67 68 handle = new Font2DHandle(this); 69 this.platName = platname; 70 this.nativeNames = nativeNames; 71 } 72 PhysicalFont()73 protected PhysicalFont() { 74 handle = new Font2DHandle(this); 75 } 76 77 /* The following methods are delegated to the font by the strike 78 * for physical fonts as the PhysicalFont holds a shared reference 79 * to the native resource, so all invocations need to be directed 80 * through a synchronization point. Implementations of these methods 81 * will typically be "synchronized native" 82 */ 83 getGlyphPoint(long pScalerContext, int glyphCode, int ptNumber)84 Point2D.Float getGlyphPoint(long pScalerContext, 85 int glyphCode, int ptNumber) { 86 return new Point2D.Float(); 87 } 88 89 /* These 3 metrics methods should be implemented to return 90 * values in user space. 91 */ getFontMetrics(long pScalerContext)92 abstract StrikeMetrics getFontMetrics(long pScalerContext); 93 getGlyphAdvance(long pScalerContext, int glyphCode)94 abstract float getGlyphAdvance(long pScalerContext, int glyphCode); 95 getGlyphMetrics(long pScalerContext, int glyphCode, Point2D.Float metrics)96 abstract void getGlyphMetrics(long pScalerContext, int glyphCode, 97 Point2D.Float metrics); 98 getGlyphImage(long pScalerContext, int glyphCode)99 abstract long getGlyphImage(long pScalerContext, int glyphCode); 100 101 /* These 3 outline methods should be implemented to return 102 * values in device space. Callers need to be aware of this 103 * as typically Java client code will need to have them in user space. 104 */ getGlyphOutlineBounds(long pScalerContext, int glyphCode)105 abstract Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext, 106 int glyphCode); 107 getGlyphOutline(long pScalerContext, int glyphCode, float x, float y)108 abstract GeneralPath getGlyphOutline(long pScalerContext, int glyphCode, 109 float x, float y); 110 getGlyphVectorOutline(long pScalerContext, int[] glyphs, int numGlyphs, float x, float y)111 abstract GeneralPath getGlyphVectorOutline(long pScalerContext, 112 int[] glyphs, int numGlyphs, 113 float x, float y); 114 } 115