28 import java.awt.font.FontRenderContext; |
28 import java.awt.font.FontRenderContext; |
29 import java.awt.font.GlyphVector; |
29 import java.awt.font.GlyphVector; |
30 import java.awt.font.LineMetrics; |
30 import java.awt.font.LineMetrics; |
31 import java.awt.font.TextAttribute; |
31 import java.awt.font.TextAttribute; |
32 import java.awt.font.TextLayout; |
32 import java.awt.font.TextLayout; |
33 import java.awt.font.TransformAttribute; |
|
34 import java.awt.geom.AffineTransform; |
33 import java.awt.geom.AffineTransform; |
35 import java.awt.geom.Point2D; |
34 import java.awt.geom.Point2D; |
36 import java.awt.geom.Rectangle2D; |
35 import java.awt.geom.Rectangle2D; |
37 import java.awt.peer.FontPeer; |
36 import java.awt.peer.FontPeer; |
38 import java.io.*; |
37 import java.io.*; |
40 import java.security.AccessController; |
39 import java.security.AccessController; |
41 import java.security.PrivilegedExceptionAction; |
40 import java.security.PrivilegedExceptionAction; |
42 import java.text.AttributedCharacterIterator.Attribute; |
41 import java.text.AttributedCharacterIterator.Attribute; |
43 import java.text.CharacterIterator; |
42 import java.text.CharacterIterator; |
44 import java.text.StringCharacterIterator; |
43 import java.text.StringCharacterIterator; |
45 import java.util.HashMap; |
|
46 import java.util.Hashtable; |
44 import java.util.Hashtable; |
47 import java.util.Locale; |
45 import java.util.Locale; |
48 import java.util.Map; |
46 import java.util.Map; |
49 import sun.font.StandardGlyphVector; |
47 import sun.font.StandardGlyphVector; |
50 import sun.java2d.FontSupport; |
|
51 |
48 |
52 import sun.font.AttributeMap; |
49 import sun.font.AttributeMap; |
53 import sun.font.AttributeValues; |
50 import sun.font.AttributeValues; |
54 import sun.font.EAttribute; |
|
55 import sun.font.CompositeFont; |
51 import sun.font.CompositeFont; |
56 import sun.font.CreatedFontTracker; |
52 import sun.font.CreatedFontTracker; |
57 import sun.font.Font2D; |
53 import sun.font.Font2D; |
58 import sun.font.Font2DHandle; |
54 import sun.font.Font2DHandle; |
|
55 import sun.font.FontAccess; |
59 import sun.font.FontManager; |
56 import sun.font.FontManager; |
|
57 import sun.font.FontManagerFactory; |
|
58 import sun.font.FontUtilities; |
60 import sun.font.GlyphLayout; |
59 import sun.font.GlyphLayout; |
61 import sun.font.FontLineMetrics; |
60 import sun.font.FontLineMetrics; |
62 import sun.font.CoreMetrics; |
61 import sun.font.CoreMetrics; |
63 |
62 |
64 import static sun.font.EAttribute.*; |
63 import static sun.font.EAttribute.*; |
221 * especially important are called out as having 'baseline-relative |
220 * especially important are called out as having 'baseline-relative |
222 * coordinates.' |
221 * coordinates.' |
223 */ |
222 */ |
224 public class Font implements java.io.Serializable |
223 public class Font implements java.io.Serializable |
225 { |
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 |
226 static { |
243 static { |
227 /* ensure that the necessary native libraries are loaded */ |
244 /* ensure that the necessary native libraries are loaded */ |
228 Toolkit.loadLibraries(); |
245 Toolkit.loadLibraries(); |
229 initIDs(); |
246 initIDs(); |
|
247 FontAccess.setFontAccess(new FontAccessImpl()); |
230 } |
248 } |
231 |
249 |
232 /** |
250 /** |
233 * This is now only used during serialization. Typically |
251 * This is now only used during serialization. Typically |
234 * it is null. |
252 * it is null. |
462 |
480 |
463 return values; |
481 return values; |
464 } |
482 } |
465 |
483 |
466 private Font2D getFont2D() { |
484 private Font2D getFont2D() { |
467 if (FontManager.usingPerAppContextComposites && |
485 FontManager fm = FontManagerFactory.getInstance(); |
|
486 if (fm.usingPerAppContextComposites() && |
468 font2DHandle != null && |
487 font2DHandle != null && |
469 font2DHandle.font2D instanceof CompositeFont && |
488 font2DHandle.font2D instanceof CompositeFont && |
470 ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) { |
489 ((CompositeFont)(font2DHandle.font2D)).isStdComposite()) { |
471 return FontManager.findFont2D(name, style, |
490 return fm.findFont2D(name, style, |
472 FontManager.LOGICAL_FALLBACK); |
491 FontManager.LOGICAL_FALLBACK); |
473 } else if (font2DHandle == null) { |
492 } else if (font2DHandle == null) { |
474 font2DHandle = |
493 font2DHandle = |
475 FontManager.findFont2D(name, style, |
494 fm.findFont2D(name, style, |
476 FontManager.LOGICAL_FALLBACK).handle; |
495 FontManager.LOGICAL_FALLBACK).handle; |
477 } |
496 } |
478 /* Do not cache the de-referenced font2D. It must be explicitly |
497 /* Do not cache the de-referenced font2D. It must be explicitly |
479 * de-referenced to pick up a valid font in the event that the |
498 * de-referenced to pick up a valid font in the event that the |
480 * original one is marked invalid |
499 * original one is marked invalid |
481 */ |
500 */ |
568 * always from "Font.createFont()" and shouldn't get this treatment. |
587 * always from "Font.createFont()" and shouldn't get this treatment. |
569 */ |
588 */ |
570 if (created) { |
589 if (created) { |
571 if (handle.font2D instanceof CompositeFont && |
590 if (handle.font2D instanceof CompositeFont && |
572 handle.font2D.getStyle() != style) { |
591 handle.font2D.getStyle() != style) { |
573 this.font2DHandle = |
592 FontManager fm = FontManagerFactory.getInstance(); |
574 FontManager.getNewComposite(null, style, handle); |
593 this.font2DHandle = fm.getNewComposite(null, style, handle); |
575 } else { |
594 } else { |
576 this.font2DHandle = handle; |
595 this.font2DHandle = handle; |
577 } |
596 } |
578 } |
597 } |
579 } |
598 } |
584 throws FontFormatException { |
603 throws FontFormatException { |
585 this.createdFont = true; |
604 this.createdFont = true; |
586 /* Font2D instances created by this method track their font file |
605 /* Font2D instances created by this method track their font file |
587 * so that when the Font2D is GC'd it can also remove the file. |
606 * so that when the Font2D is GC'd it can also remove the file. |
588 */ |
607 */ |
589 this.font2DHandle = |
608 FontManager fm = FontManagerFactory.getInstance(); |
590 FontManager.createFont2D(fontFile, fontFormat, |
609 this.font2DHandle = fm.createFont2D(fontFile, fontFormat, isCopy, |
591 isCopy, tracker).handle; |
610 tracker).handle; |
592 this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault()); |
611 this.name = this.font2DHandle.font2D.getFontName(Locale.getDefault()); |
593 this.style = Font.PLAIN; |
612 this.style = Font.PLAIN; |
594 this.size = 1; |
613 this.size = 1; |
595 this.pointSize = 1f; |
614 this.pointSize = 1f; |
596 } |
615 } |
638 if (values.getPosture() >= .2f) newStyle |= ITALIC; |
657 if (values.getPosture() >= .2f) newStyle |= ITALIC; |
639 if (oldStyle == newStyle) newStyle = -1; |
658 if (oldStyle == newStyle) newStyle = -1; |
640 } |
659 } |
641 if (handle.font2D instanceof CompositeFont) { |
660 if (handle.font2D instanceof CompositeFont) { |
642 if (newStyle != -1 || newName != null) { |
661 if (newStyle != -1 || newName != null) { |
|
662 FontManager fm = FontManagerFactory.getInstance(); |
643 this.font2DHandle = |
663 this.font2DHandle = |
644 FontManager.getNewComposite(newName, newStyle, handle); |
664 fm.getNewComposite(newName, newStyle, handle); |
645 } |
665 } |
646 } else if (newName != null) { |
666 } else if (newName != null) { |
647 this.createdFont = false; |
667 this.createdFont = false; |
648 this.font2DHandle = null; |
668 this.font2DHandle = null; |
649 } |
669 } |
850 if (fontFormat != Font.TRUETYPE_FONT && |
870 if (fontFormat != Font.TRUETYPE_FONT && |
851 fontFormat != Font.TYPE1_FONT) { |
871 fontFormat != Font.TYPE1_FONT) { |
852 throw new IllegalArgumentException ("font format not recognized"); |
872 throw new IllegalArgumentException ("font format not recognized"); |
853 } |
873 } |
854 boolean copiedFontData = false; |
874 boolean copiedFontData = false; |
855 |
|
856 try { |
875 try { |
857 final File tFile = AccessController.doPrivileged( |
876 final File tFile = AccessController.doPrivileged( |
858 new PrivilegedExceptionAction<File>() { |
877 new PrivilegedExceptionAction<File>() { |
859 public File run() throws IOException { |
878 public File run() throws IOException { |
860 return File.createTempFile("+~JF", ".tmp", null); |
879 return File.createTempFile("+~JF", ".tmp", null); |
2318 |
2337 |
2319 boolean simple = values == null || |
2338 boolean simple = values == null || |
2320 (values.getKerning() == 0 && values.getLigatures() == 0 && |
2339 (values.getKerning() == 0 && values.getLigatures() == 0 && |
2321 values.getBaselineTransform() == null); |
2340 values.getBaselineTransform() == null); |
2322 if (simple) { |
2341 if (simple) { |
2323 simple = !FontManager.isComplexText(chars, beginIndex, limit); |
2342 simple = ! FontUtilities.isComplexText(chars, beginIndex, limit); |
2324 } |
2343 } |
2325 |
2344 |
2326 if (simple) { |
2345 if (simple) { |
2327 GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex, |
2346 GlyphVector gv = new StandardGlyphVector(this, chars, beginIndex, |
2328 limit - beginIndex, frc); |
2347 limit - beginIndex, frc); |