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
26 package sun.print;
27
28 import java.lang.ref.SoftReference;
29 import java.util.Hashtable;
30 import sun.font.CharToGlyphMapper;
31 import sun.font.CompositeFont;
32 import sun.font.Font2D;
33 import sun.font.Font2DHandle;
34 import sun.font.FontManager;
35
36 import java.awt.Color;
37 import java.awt.Font;
38 import java.awt.Graphics2D;
39 import java.awt.Image;
40 import java.awt.Paint;
41 import java.awt.Polygon;
42 import java.awt.Shape;
43
44 import java.text.AttributedCharacterIterator;
45
46 import java.awt.font.FontRenderContext;
47 import java.awt.font.GlyphVector;
48 import java.awt.font.TextAttribute;
49 import java.awt.font.TextLayout;
50
51 import java.awt.geom.AffineTransform;
52 import java.awt.geom.Arc2D;
53 import java.awt.geom.Ellipse2D;
54 import java.awt.geom.Line2D;
681 * Failing that, if we can directly send glyph codes to the printer
682 * then we do that (printGlyphVector).
683 * As a last resort we return false and let the caller print as filled
684 * shapes.
685 */
686 boolean printedSimpleGlyphVector(GlyphVector g, float x, float y) {
687
688 int flags = g.getLayoutFlags();
689
690 /* We can't handle RTL, re-ordering, complex glyphs etc by
691 * reconstituting glyphs into a String. So if any flags besides
692 * position adjustments are set, see if we can directly
693 * print the GlyphVector as glyph codes, using the positions
694 * layout has assigned. If that fails return false;
695 */
696 if (flags != 0 && flags != GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) {
697 return printGlyphVector(g, x, y);
698 }
699
700 Font font = g.getFont();
701 Font2D font2D = FontManager.getFont2D(font);
702 if (font2D.handle.font2D != font2D) {
703 /* suspicious, may be a bad font. lets bail */
704 return false;
705 }
706 Hashtable<Font2DHandle,Object> fontMap;
707 synchronized (PathGraphics.class) {
708 fontMap = fontMapRef.get();
709 if (fontMap == null) {
710 fontMap = new Hashtable<Font2DHandle,Object>();
711 fontMapRef =
712 new SoftReference<Hashtable<Font2DHandle,Object>>(fontMap);
713 }
714 }
715
716 int numGlyphs = g.getNumGlyphs();
717 int[] glyphCodes = g.getGlyphCodes(0, numGlyphs, null);
718
719 char[] glyphToCharMap = null;
720 char[][] mapArray = null;
721 CompositeFont cf = null;
916
917 /* If positions have not been explicitly assigned, we can
918 * ask the string to be drawn adjusted to this width.
919 * This call is supported only in the PS generator.
920 * GDI has API to specify the advance for each glyph in a
921 * string which could be used here too, but that is not yet
922 * implemented, and we'd need to update the signature of the
923 * drawString method to take the advances (ie relative positions)
924 * and use that instead of the width.
925 */
926 if (numFonts == 1 && canDrawStringToWidth() && noPositionAdjustments) {
927 drawString(str, x, y, font, gvFrc, gvAdvanceX);
928 return true;
929 }
930
931 /* In some scripts chars drawn individually do not have the
932 * same representation (glyphs) as when combined with other chars.
933 * The logic here is erring on the side of caution, in particular
934 * in including supplementary characters.
935 */
936 if (FontManager.isComplexText(chars, 0, chars.length)) {
937 return printGlyphVector(g, x, y);
938 }
939
940 /* If we reach here we have mapped all the glyphs back
941 * one-to-one to simple unicode chars that we know are in the font.
942 * We can call "drawChars" on each one of them in turn, setting
943 * the position based on the glyph positions.
944 * There's typically overhead in this. If numGlyphs is 'large',
945 * it may even be better to try printGlyphVector() in this case.
946 * This may be less recoverable for apps, but sophisticated apps
947 * should be able to recover the text from simple glyph vectors
948 * and we can avoid penalising the more common case - although
949 * this is already a minority case.
950 */
951 if (numGlyphs > 10 && printGlyphVector(g, x, y)) {
952 return true;
953 }
954
955 for (int i=0; i<numGlyphs; i++) {
956 String s = new String(chars, i, 1);
|
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
26 package sun.print;
27
28 import java.lang.ref.SoftReference;
29 import java.util.Hashtable;
30 import sun.font.CharToGlyphMapper;
31 import sun.font.CompositeFont;
32 import sun.font.Font2D;
33 import sun.font.Font2DHandle;
34 import sun.font.FontManager;
35 import sun.font.FontManagerFactory;
36 import sun.font.FontUtilities;
37
38 import java.awt.Color;
39 import java.awt.Font;
40 import java.awt.Graphics2D;
41 import java.awt.Image;
42 import java.awt.Paint;
43 import java.awt.Polygon;
44 import java.awt.Shape;
45
46 import java.text.AttributedCharacterIterator;
47
48 import java.awt.font.FontRenderContext;
49 import java.awt.font.GlyphVector;
50 import java.awt.font.TextAttribute;
51 import java.awt.font.TextLayout;
52
53 import java.awt.geom.AffineTransform;
54 import java.awt.geom.Arc2D;
55 import java.awt.geom.Ellipse2D;
56 import java.awt.geom.Line2D;
683 * Failing that, if we can directly send glyph codes to the printer
684 * then we do that (printGlyphVector).
685 * As a last resort we return false and let the caller print as filled
686 * shapes.
687 */
688 boolean printedSimpleGlyphVector(GlyphVector g, float x, float y) {
689
690 int flags = g.getLayoutFlags();
691
692 /* We can't handle RTL, re-ordering, complex glyphs etc by
693 * reconstituting glyphs into a String. So if any flags besides
694 * position adjustments are set, see if we can directly
695 * print the GlyphVector as glyph codes, using the positions
696 * layout has assigned. If that fails return false;
697 */
698 if (flags != 0 && flags != GlyphVector.FLAG_HAS_POSITION_ADJUSTMENTS) {
699 return printGlyphVector(g, x, y);
700 }
701
702 Font font = g.getFont();
703 Font2D font2D = FontUtilities.getFont2D(font);
704 if (font2D.handle.font2D != font2D) {
705 /* suspicious, may be a bad font. lets bail */
706 return false;
707 }
708 Hashtable<Font2DHandle,Object> fontMap;
709 synchronized (PathGraphics.class) {
710 fontMap = fontMapRef.get();
711 if (fontMap == null) {
712 fontMap = new Hashtable<Font2DHandle,Object>();
713 fontMapRef =
714 new SoftReference<Hashtable<Font2DHandle,Object>>(fontMap);
715 }
716 }
717
718 int numGlyphs = g.getNumGlyphs();
719 int[] glyphCodes = g.getGlyphCodes(0, numGlyphs, null);
720
721 char[] glyphToCharMap = null;
722 char[][] mapArray = null;
723 CompositeFont cf = null;
918
919 /* If positions have not been explicitly assigned, we can
920 * ask the string to be drawn adjusted to this width.
921 * This call is supported only in the PS generator.
922 * GDI has API to specify the advance for each glyph in a
923 * string which could be used here too, but that is not yet
924 * implemented, and we'd need to update the signature of the
925 * drawString method to take the advances (ie relative positions)
926 * and use that instead of the width.
927 */
928 if (numFonts == 1 && canDrawStringToWidth() && noPositionAdjustments) {
929 drawString(str, x, y, font, gvFrc, gvAdvanceX);
930 return true;
931 }
932
933 /* In some scripts chars drawn individually do not have the
934 * same representation (glyphs) as when combined with other chars.
935 * The logic here is erring on the side of caution, in particular
936 * in including supplementary characters.
937 */
938 if (FontUtilities.isComplexText(chars, 0, chars.length)) {
939 return printGlyphVector(g, x, y);
940 }
941
942 /* If we reach here we have mapped all the glyphs back
943 * one-to-one to simple unicode chars that we know are in the font.
944 * We can call "drawChars" on each one of them in turn, setting
945 * the position based on the glyph positions.
946 * There's typically overhead in this. If numGlyphs is 'large',
947 * it may even be better to try printGlyphVector() in this case.
948 * This may be less recoverable for apps, but sophisticated apps
949 * should be able to recover the text from simple glyph vectors
950 * and we can avoid penalising the more common case - although
951 * this is already a minority case.
952 */
953 if (numGlyphs > 10 && printGlyphVector(g, x, y)) {
954 return true;
955 }
956
957 for (int i=0; i<numGlyphs; i++) {
958 String s = new String(chars, i, 1);
|