Code injection between java.text and java.awt.font to remove dependency of Bidi on AWT. eliminateswing
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 22 Jun 2009 16:46:50 +0200
brancheliminateswing
changeset 125529da1ab1c5bb
parent 1254 62cdc894375c
child 1256 a4d32dc556eb
Code injection between java.text and java.awt.font to remove dependency of Bidi on AWT.
build.xml
src/share/classes/META-INF/services/sun.text.BidiProxy
src/share/classes/java/text/Bidi.java
src/share/classes/sun/font/BidiProxyImpl.java
src/share/classes/sun/text/BidiProxy.java
     1.1 --- a/build.xml	Mon Jun 22 14:00:07 2009 +0200
     1.2 +++ b/build.xml	Mon Jun 22 16:46:50 2009 +0200
     1.3 @@ -153,7 +153,6 @@
     1.4                  <filename name="com/sun/swing/**"/>
     1.5                  <filename name="com/sun/java/swing/**"/>
     1.6                  <filename name="com/sun/xml/internal/xsom/impl/util/**"/>
     1.7 -                <!--<filename name="com/sun/security/auth/callback/**"/>-->
     1.8                  <filename name="com/sun/security/auth/callback/DialogCallbackHandler*"/>
     1.9                  <filename name="com/sun/inputmethods/internal/**"/>
    1.10                  <filename name="com/sun/xml/internal/bind/**"/>
    1.11 @@ -185,6 +184,8 @@
    1.12                  <filename name="com/sun/beans/**"/>
    1.13                  <!-- bridge between jmx and beans -->
    1.14                  <filename name="META-INF/services/com.sun.jmx.mbeanserver.IntrospectorProxy"/>
    1.15 +                <!-- bridge between java.text and java.awt.font for Bidi -->
    1.16 +                <filename name="META-INF/services/sun.text.BidiProxy"/>
    1.17              </or>
    1.18              <none>
    1.19                  <filename name="java/awt/AWTPermission*"/>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/classes/META-INF/services/sun.text.BidiProxy	Mon Jun 22 16:46:50 2009 +0200
     2.3 @@ -0,0 +1,2 @@
     2.4 +sun.font.BidiProxyImpl
     2.5 +
     3.1 --- a/src/share/classes/java/text/Bidi.java	Mon Jun 22 14:00:07 2009 +0200
     3.2 +++ b/src/share/classes/java/text/Bidi.java	Mon Jun 22 16:46:50 2009 +0200
     3.3 @@ -35,10 +35,8 @@
     3.4  
     3.5  package java.text;
     3.6  
     3.7 -import java.awt.Toolkit;
     3.8 -import java.awt.font.TextAttribute;
     3.9 -import java.awt.font.NumericShaper;
    3.10  import sun.text.CodePointIterator;
    3.11 +import sun.text.BidiProxy;
    3.12  
    3.13  /**
    3.14   * This class implements the Unicode Bidirectional Algorithm.
    3.15 @@ -69,7 +67,7 @@
    3.16      int[] cws;
    3.17  
    3.18      static {
    3.19 -         sun.font.FontManagerNativeLibrary.load();
    3.20 +        BidiProxy.getDefault().init();
    3.21      }
    3.22  
    3.23      /** Constant indicating base direction is left-to-right. */
    3.24 @@ -156,51 +154,20 @@
    3.25  
    3.26          paragraph.first();
    3.27          try {
    3.28 -            Boolean runDirection = (Boolean)paragraph.getAttribute(TextAttribute.RUN_DIRECTION);
    3.29 -            if (runDirection != null) {
    3.30 -                if (TextAttribute.RUN_DIRECTION_LTR.equals(runDirection)) {
    3.31 -                    flags = DIRECTION_LEFT_TO_RIGHT; // clears default setting
    3.32 -                } else {
    3.33 -                    flags = DIRECTION_RIGHT_TO_LEFT;
    3.34 -                }
    3.35 +            Integer f = BidiProxy.getDefault().findDirection(paragraph);
    3.36 +            if (f != null) {
    3.37 +                flags = f;
    3.38              }
    3.39          }
    3.40          catch (ClassCastException e) {
    3.41          }
    3.42  
    3.43          try {
    3.44 -            NumericShaper shaper = (NumericShaper)paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING);
    3.45 -            if (shaper != null) {
    3.46 -                shaper.shape(text, 0, text.length);
    3.47 -            }
    3.48 +            BidiProxy.getDefault().shapeText(paragraph, text);
    3.49          }
    3.50          catch (ClassCastException e) {
    3.51          }
    3.52 -
    3.53 -        int pos = start;
    3.54 -        do {
    3.55 -            paragraph.setIndex(pos);
    3.56 -            Object embeddingLevel = paragraph.getAttribute(TextAttribute.BIDI_EMBEDDING);
    3.57 -            int newpos = paragraph.getRunLimit(TextAttribute.BIDI_EMBEDDING);
    3.58 -
    3.59 -            if (embeddingLevel != null) {
    3.60 -                try {
    3.61 -                    int intLevel = ((Integer)embeddingLevel).intValue();
    3.62 -                    if (intLevel >= -61 && intLevel < 61) {
    3.63 -                        byte level = (byte)(intLevel < 0 ? (-intLevel | 0x80) : intLevel);
    3.64 -                        if (embeddings == null) {
    3.65 -                            embeddings = new byte[length];
    3.66 -                        }
    3.67 -                        for (int i = pos - start; i < newpos - start; ++i) {
    3.68 -                            embeddings[i] = level;
    3.69 -                        }
    3.70 -                    }
    3.71 -                }
    3.72 -                catch (ClassCastException e) {
    3.73 -                }
    3.74 -            }
    3.75 -            pos = newpos;
    3.76 -        } while (pos < limit);
    3.77 +        embeddings = BidiProxy.getDefault().embedding(start, paragraph, embeddings, length, limit);
    3.78  
    3.79          nativeBidiChars(this, text, 0, embeddings, 0, text.length, flags);
    3.80      }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/share/classes/sun/font/BidiProxyImpl.java	Mon Jun 22 16:46:50 2009 +0200
     4.3 @@ -0,0 +1,96 @@
     4.4 +/*
     4.5 + * Copyright 2000-2003 Sun Microsystems, Inc.  All Rights Reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.  Sun designates this
    4.11 + * particular file as subject to the "Classpath" exception as provided
    4.12 + * by Sun in the LICENSE file that accompanied this code.
    4.13 + *
    4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.17 + * version 2 for more details (a copy is included in the LICENSE file that
    4.18 + * accompanied this code).
    4.19 + *
    4.20 + * You should have received a copy of the GNU General Public License version
    4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.23 + *
    4.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    4.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    4.26 + * have any questions.
    4.27 + */
    4.28 +
    4.29 +package sun.font;
    4.30 +
    4.31 +import java.awt.font.NumericShaper;
    4.32 +import java.awt.font.TextAttribute;
    4.33 +import java.text.AttributedCharacterIterator;
    4.34 +import java.text.Bidi;
    4.35 +import sun.text.BidiProxy;
    4.36 +
    4.37 +/*
    4.38 + * (C) Copyright IBM Corp. 1999-2003 - All Rights Reserved
    4.39 + *
    4.40 + * The original version of this source code and documentation is
    4.41 + * copyrighted and owned by IBM. These materials are provided
    4.42 + * under terms of a License Agreement between IBM and Sun.
    4.43 + * This technology is protected by multiple US and International
    4.44 + * patents. This notice and attribution to IBM may not be removed.
    4.45 + */
    4.46 +public abstract class BidiProxyImpl extends BidiProxy {
    4.47 +
    4.48 +    public void init() {
    4.49 +        sun.font.FontManagerNativeLibrary.load();
    4.50 +    }
    4.51 +
    4.52 +    public Integer findDirection(AttributedCharacterIterator paragraph) {
    4.53 +        Boolean runDirection = (Boolean)paragraph.getAttribute(TextAttribute.RUN_DIRECTION);
    4.54 +        if (runDirection != null) {
    4.55 +            if (TextAttribute.RUN_DIRECTION_LTR.equals(runDirection)) {
    4.56 +                return Bidi.DIRECTION_LEFT_TO_RIGHT; // clears default setting
    4.57 +                } else {
    4.58 +                return Bidi.DIRECTION_RIGHT_TO_LEFT;
    4.59 +            }
    4.60 +        }
    4.61 +        return null;
    4.62 +    }
    4.63 +
    4.64 +    public void shapeText(AttributedCharacterIterator paragraph, char[] text) {
    4.65 +        NumericShaper shaper = (NumericShaper) paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING);
    4.66 +        if (shaper != null) {
    4.67 +            shaper.shape(text, 0, text.length);
    4.68 +        }
    4.69 +    }
    4.70 +
    4.71 +
    4.72 +    public byte[] embedding(int start, AttributedCharacterIterator paragraph, byte[] embeddings, int length, int limit) {
    4.73 +        int pos = start;
    4.74 +        do {
    4.75 +            paragraph.setIndex(pos);
    4.76 +            Object embeddingLevel = paragraph.getAttribute(TextAttribute.BIDI_EMBEDDING);
    4.77 +            int newpos = paragraph.getRunLimit(TextAttribute.BIDI_EMBEDDING);
    4.78 +            if (embeddingLevel != null) {
    4.79 +                try {
    4.80 +                    int intLevel = ((Integer) embeddingLevel).intValue();
    4.81 +                    if (intLevel >= -61 && intLevel < 61) {
    4.82 +                        byte level = (byte) (intLevel < 0 ? (-intLevel | 0x80) : intLevel);
    4.83 +                        if (embeddings == null) {
    4.84 +                            embeddings = new byte[length];
    4.85 +                        }
    4.86 +                        for (int i = pos - start; i < newpos - start; ++i) {
    4.87 +                            embeddings[i] = level;
    4.88 +                        }
    4.89 +                    }
    4.90 +                } catch (ClassCastException e) {
    4.91 +                }
    4.92 +            }
    4.93 +            pos = newpos;
    4.94 +        } while (pos < limit);
    4.95 +        return embeddings;
    4.96 +    }
    4.97 +
    4.98 +}
    4.99 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/share/classes/sun/text/BidiProxy.java	Mon Jun 22 16:46:50 2009 +0200
     5.3 @@ -0,0 +1,74 @@
     5.4 +/*
     5.5 + * Copyright 2000-2003 Sun Microsystems, Inc.  All Rights Reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.  Sun designates this
    5.11 + * particular file as subject to the "Classpath" exception as provided
    5.12 + * by Sun in the LICENSE file that accompanied this code.
    5.13 + *
    5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 + * version 2 for more details (a copy is included in the LICENSE file that
    5.18 + * accompanied this code).
    5.19 + *
    5.20 + * You should have received a copy of the GNU General Public License version
    5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 + *
    5.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    5.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    5.26 + * have any questions.
    5.27 + */
    5.28 +
    5.29 +package sun.text;
    5.30 +
    5.31 +import java.text.AttributedCharacterIterator;
    5.32 +import java.util.Iterator;
    5.33 +import java.util.ServiceLoader;
    5.34 +
    5.35 +/*
    5.36 + * (C) Copyright IBM Corp. 1999-2003 - All Rights Reserved
    5.37 + *
    5.38 + * The original version of this source code and documentation is
    5.39 + * copyrighted and owned by IBM. These materials are provided
    5.40 + * under terms of a License Agreement between IBM and Sun.
    5.41 + * This technology is protected by multiple US and International
    5.42 + * patents. This notice and attribution to IBM may not be removed.
    5.43 + */
    5.44 +public abstract class BidiProxy {
    5.45 +    public static BidiProxy getDefault() {
    5.46 +        Iterator<BidiProxy> it = ServiceLoader.load(BidiProxy.class).iterator();
    5.47 +        return it.hasNext() ? it.next() : new DefaultBidiProxy();
    5.48 +    }
    5.49 +
    5.50 +    public abstract void init();
    5.51 +    public abstract Integer findDirection(AttributedCharacterIterator paragraph);
    5.52 +    public abstract void shapeText(AttributedCharacterIterator paragraph, char[] text);
    5.53 +    public abstract byte[] embedding(int start, AttributedCharacterIterator paragraph, byte[] embeddings, int length, int limit);
    5.54 +
    5.55 +
    5.56 +    private static final class DefaultBidiProxy extends BidiProxy {
    5.57 +
    5.58 +        @Override
    5.59 +        public void init() {
    5.60 +        }
    5.61 +
    5.62 +        @Override
    5.63 +        public Integer findDirection(AttributedCharacterIterator paragraph) {
    5.64 +            return null;
    5.65 +        }
    5.66 +
    5.67 +        @Override
    5.68 +        public void shapeText(AttributedCharacterIterator paragraph, char[] text) {
    5.69 +        }
    5.70 +
    5.71 +        @Override
    5.72 +        public byte[] embedding(int start, AttributedCharacterIterator paragraph, byte[] embeddings, int length, int limit) {
    5.73 +            return embeddings;
    5.74 +        }
    5.75 +    }
    5.76 +}
    5.77 +