1 /*
2 * Copyright (c) 1995, 2014, 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
24 */
25
26 package java.awt;
27
28 import java.awt.font.FontRenderContext;
29 import java.awt.font.GlyphVector;
30 import java.awt.font.LineMetrics;
31 import java.awt.font.TextAttribute;
32 import java.awt.font.TextLayout;
33 import java.awt.geom.AffineTransform;
34 import java.awt.geom.Point2D;
35 import java.awt.geom.Rectangle2D;
36 import java.awt.peer.FontPeer;
37 import java.io.*;
38 import java.lang.ref.SoftReference;
39 import java.nio.file.Files;
40 import java.security.AccessController;
41 import java.security.PrivilegedExceptionAction;
42 import java.text.AttributedCharacterIterator.Attribute;
43 import java.text.CharacterIterator;
44 import java.text.StringCharacterIterator;
45 import java.util.Hashtable;
46 import java.util.Locale;
47 import java.util.Map;
48 import sun.font.StandardGlyphVector;
49
50 import sun.font.AttributeMap;
51 import sun.font.AttributeValues;
52 import sun.font.CompositeFont;
53 import sun.font.CreatedFontTracker;
54 import sun.font.Font2D;
55 import sun.font.Font2DHandle;
56 import sun.font.FontAccess;
57 import sun.font.FontManager;
58 import sun.font.FontManagerFactory;
59 import sun.font.FontUtilities;
60 import sun.font.GlyphLayout;
61 import sun.font.FontLineMetrics;
62 import sun.font.CoreMetrics;
63
64 import static sun.font.EAttribute.*;
222 * coordinates.'
223 */
224 public class Font implements java.io.Serializable
225 {
226 private static class FontAccessImpl extends FontAccess {
227 public Font2D getFont2D(Font font) {
228 return font.getFont2D();
229 }
230
231 public void setFont2D(Font font, Font2DHandle handle) {
232 font.font2DHandle = handle;
233 }
234
235 public void setCreatedFont(Font font) {
236 font.createdFont = true;
237 }
238
239 public boolean isCreatedFont(Font font) {
240 return font.createdFont;
241 }
242 }
243
244 static {
245 /* ensure that the necessary native libraries are loaded */
246 Toolkit.loadLibraries();
247 initIDs();
248 FontAccess.setFontAccess(new FontAccessImpl());
249 }
250
251 /**
252 * This is now only used during serialization. Typically
253 * it is null.
254 *
255 * @serial
256 * @see #getAttributes()
257 */
258 private Hashtable<Object, Object> fRequestedAttributes;
259
260 /*
261 * Constants to be used for logical font family names.
417
418 /*
419 * This is true if the font transform is not identity. It
420 * is used to avoid unnecessary instantiation of an AffineTransform.
421 */
422 private transient boolean nonIdentityTx;
423
424 /*
425 * A cached value used when a transform is required for internal
426 * use. This must not be exposed to callers since AffineTransform
427 * is mutable.
428 */
429 private static final AffineTransform identityTx = new AffineTransform();
430
431 /*
432 * JDK 1.1 serialVersionUID
433 */
434 private static final long serialVersionUID = -4206021311591459213L;
435
436 /**
437 * Gets the peer of this <code>Font</code>.
438 * @return the peer of the <code>Font</code>.
439 * @since 1.1
440 * @deprecated Font rendering is now platform independent.
441 */
442 @Deprecated
443 public FontPeer getPeer(){
444 return getPeer_NoClientCode();
445 }
446 // NOTE: This method is called by privileged threads.
447 // We implement this functionality in a package-private method
448 // to insure that it cannot be overridden by client subclasses.
449 // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
450 @SuppressWarnings("deprecation")
451 final FontPeer getPeer_NoClientCode() {
452 if(peer == null) {
453 Toolkit tk = Toolkit.getDefaultToolkit();
454 this.peer = tk.getFontPeer(name, style);
455 }
456 return peer;
457 }
458
459 /**
460 * Return the AttributeValues object associated with this
461 * font. Most of the time, the internal object is null.
462 * If required, it will be created from the 'standard'
463 * state on the font. Only non-default values will be
464 * set in the AttributeValues object.
465 *
466 * <p>Since the AttributeValues object is mutable, and it
467 * is cached in the font, care must be taken to ensure that
468 * it is not mutated.
469 */
470 private AttributeValues getAttributeValues() {
471 if (values == null) {
472 AttributeValues valuesTmp = new AttributeValues();
473 valuesTmp.setFamily(name);
474 valuesTmp.setSize(pointSize); // expects the float value.
|
1 /*
2 * Copyright (c) 1995, 2015, 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
24 */
25
26 package java.awt;
27
28 import java.awt.font.FontRenderContext;
29 import java.awt.font.GlyphVector;
30 import java.awt.font.LineMetrics;
31 import java.awt.font.TextAttribute;
32 import java.awt.font.TextLayout;
33 import java.awt.geom.AffineTransform;
34 import java.awt.geom.Point2D;
35 import java.awt.geom.Rectangle2D;
36 import java.awt.peer.FontPeer;
37 import java.io.*;
38 import java.lang.ref.SoftReference;
39 import java.nio.file.Files;
40 import java.security.AccessController;
41 import java.security.PrivilegedExceptionAction;
42 import java.text.AttributedCharacterIterator.Attribute;
43 import java.text.CharacterIterator;
44 import java.util.Hashtable;
45 import java.util.Locale;
46 import java.util.Map;
47 import sun.font.StandardGlyphVector;
48
49 import sun.font.AttributeMap;
50 import sun.font.AttributeValues;
51 import sun.font.CompositeFont;
52 import sun.font.CreatedFontTracker;
53 import sun.font.Font2D;
54 import sun.font.Font2DHandle;
55 import sun.font.FontAccess;
56 import sun.font.FontManager;
57 import sun.font.FontManagerFactory;
58 import sun.font.FontUtilities;
59 import sun.font.GlyphLayout;
60 import sun.font.FontLineMetrics;
61 import sun.font.CoreMetrics;
62
63 import static sun.font.EAttribute.*;
221 * coordinates.'
222 */
223 public class Font implements java.io.Serializable
224 {
225 private static class FontAccessImpl extends FontAccess {
226 public Font2D getFont2D(Font font) {
227 return font.getFont2D();
228 }
229
230 public void setFont2D(Font font, Font2DHandle handle) {
231 font.font2DHandle = handle;
232 }
233
234 public void setCreatedFont(Font font) {
235 font.createdFont = true;
236 }
237
238 public boolean isCreatedFont(Font font) {
239 return font.createdFont;
240 }
241
242 @Override
243 public FontPeer getFontPeer(final Font font) {
244 return font.getFontPeer();
245 }
246 }
247
248 static {
249 /* ensure that the necessary native libraries are loaded */
250 Toolkit.loadLibraries();
251 initIDs();
252 FontAccess.setFontAccess(new FontAccessImpl());
253 }
254
255 /**
256 * This is now only used during serialization. Typically
257 * it is null.
258 *
259 * @serial
260 * @see #getAttributes()
261 */
262 private Hashtable<Object, Object> fRequestedAttributes;
263
264 /*
265 * Constants to be used for logical font family names.
421
422 /*
423 * This is true if the font transform is not identity. It
424 * is used to avoid unnecessary instantiation of an AffineTransform.
425 */
426 private transient boolean nonIdentityTx;
427
428 /*
429 * A cached value used when a transform is required for internal
430 * use. This must not be exposed to callers since AffineTransform
431 * is mutable.
432 */
433 private static final AffineTransform identityTx = new AffineTransform();
434
435 /*
436 * JDK 1.1 serialVersionUID
437 */
438 private static final long serialVersionUID = -4206021311591459213L;
439
440 /**
441 * Gets the peer of this {@code Font}.
442 *
443 * @return the peer of the {@code Font}.
444 */
445 @SuppressWarnings("deprecation")
446 private FontPeer getFontPeer() {
447 if(peer == null) {
448 Toolkit tk = Toolkit.getDefaultToolkit();
449 peer = tk.getFontPeer(name, style);
450 }
451 return peer;
452 }
453
454 /**
455 * Return the AttributeValues object associated with this
456 * font. Most of the time, the internal object is null.
457 * If required, it will be created from the 'standard'
458 * state on the font. Only non-default values will be
459 * set in the AttributeValues object.
460 *
461 * <p>Since the AttributeValues object is mutable, and it
462 * is cached in the font, care must be taken to ensure that
463 * it is not mutated.
464 */
465 private AttributeValues getAttributeValues() {
466 if (values == null) {
467 AttributeValues valuesTmp = new AttributeValues();
468 valuesTmp.setFamily(name);
469 valuesTmp.setSize(pointSize); // expects the float value.
|