Path: blob/master/src/java.desktop/share/classes/sun/font/PhysicalFont.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;2627import java.awt.FontFormatException;28import java.awt.geom.GeneralPath;29import java.awt.geom.Point2D;30import java.awt.geom.Rectangle2D;31import java.io.FileInputStream;32import java.lang.ref.WeakReference;33import java.nio.ByteBuffer;34import java.nio.channels.FileChannel;3536public abstract class PhysicalFont extends Font2D {3738protected String platName;39// nativeNames is a String or a (possibly null) String[].40protected Object nativeNames;4142public boolean equals(Object o) {43if (o == null || o.getClass() != this.getClass()) {44return false;45}46PhysicalFont other = (PhysicalFont)o;47return48(this.fullName.equals(other.fullName)) &&49((this.platName == null && other.platName == null) ||50(this.platName != null && this.platName.equals(other.platName)));51}5253public int hashCode() {54return fullName.hashCode() +55(platName != null ? platName.hashCode() : 0);56}5758/**59* Opens the file (temporarily) and does basic verification.60* Initializes the CMAP61* @throws FontFormatException if the font can't be opened62* or fails verification, or there's no usable cmap63*/64PhysicalFont(String platname, Object nativeNames)65throws FontFormatException {6667handle = new Font2DHandle(this);68this.platName = platname;69this.nativeNames = nativeNames;70}7172protected PhysicalFont() {73handle = new Font2DHandle(this);74}7576/* The following methods are delegated to the font by the strike77* for physical fonts as the PhysicalFont holds a shared reference78* to the native resource, so all invocations need to be directed79* through a synchronization point. Implementations of these methods80* will typically be "synchronized native"81*/8283Point2D.Float getGlyphPoint(long pScalerContext,84int glyphCode, int ptNumber) {85return new Point2D.Float();86}8788/* These 3 metrics methods should be implemented to return89* values in user space.90*/91abstract StrikeMetrics getFontMetrics(long pScalerContext);9293abstract float getGlyphAdvance(long pScalerContext, int glyphCode);9495abstract void getGlyphMetrics(long pScalerContext, int glyphCode,96Point2D.Float metrics);9798abstract long getGlyphImage(long pScalerContext, int glyphCode);99100/* These 3 outline methods should be implemented to return101* values in device space. Callers need to be aware of this102* as typically Java client code will need to have them in user space.103*/104abstract Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext,105int glyphCode);106107abstract GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,108float x, float y);109110abstract GeneralPath getGlyphVectorOutline(long pScalerContext,111int[] glyphs, int numGlyphs,112float x, float y);113}114115116