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