blob: 551102717c4ab3f1bee1402adcf72e3bc9e7350b [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.font;
27
28import java.awt.FontFormatException;
29import java.awt.geom.GeneralPath;
30import java.awt.geom.Point2D;
31import java.awt.geom.Rectangle2D;
32import java.io.FileInputStream;
33import java.lang.ref.WeakReference;
34import java.nio.ByteBuffer;
35import java.nio.channels.FileChannel;
36
37public 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
43 public boolean equals(Object o) {
44 return (o != null && o.getClass() == this.getClass() &&
45 ((Font2D)o).fullName.equals(this.fullName));
46 }
47
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 */
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
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
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 */
85 abstract StrikeMetrics getFontMetrics(long pScalerContext);
86
87 abstract float getGlyphAdvance(long pScalerContext, int glyphCode);
88
89 abstract void getGlyphMetrics(long pScalerContext, int glyphCode,
90 Point2D.Float metrics);
91
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 */
98 abstract Rectangle2D.Float getGlyphOutlineBounds(long pScalerContext,
99 int glyphCode);
100
101 abstract GeneralPath getGlyphOutline(long pScalerContext, int glyphCode,
102 float x, float y);
103
104 abstract GeneralPath getGlyphVectorOutline(long pScalerContext,
105 int[] glyphs, int numGlyphs,
106 float x, float y);
107}