src/share/classes/java/awt/font/NumericShaper.java

Print this page
rev 10196 : [mq]: 8038092
   1 /*
   2  * Copyright (c) 2000, 2013, 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
  23  * questions.
  24  */
  25 
  26 package java.awt.font;
  27 
  28 import java.io.IOException;
  29 import java.io.ObjectOutputStream;
  30 import java.util.Arrays;
  31 import java.util.Comparator;
  32 import java.util.EnumSet;
  33 import java.util.Set;

  34 
  35 /**
  36  * The <code>NumericShaper</code> class is used to convert Latin-1 (European)
  37  * digits to other Unicode decimal digits.  Users of this class will
  38  * primarily be people who wish to present data using
  39  * national digit shapes, but find it more convenient to represent the
  40  * data internally using Latin-1 (European) digits.  This does not
  41  * interpret the deprecated numeric shape selector character (U+206E).
  42  * <p>
  43  * Instances of <code>NumericShaper</code> are typically applied
  44  * as attributes to text with the
  45  * {@link TextAttribute#NUMERIC_SHAPING NUMERIC_SHAPING} attribute
  46  * of the <code>TextAttribute</code> class.
  47  * For example, this code snippet causes a <code>TextLayout</code> to
  48  * shape European digits to Arabic in an Arabic context:<br>
  49  * <blockquote><pre>
  50  * Map map = new HashMap();
  51  * map.put(TextAttribute.NUMERIC_SHAPING,
  52  *     NumericShaper.getContextualShaper(NumericShaper.ARABIC));
  53  * FontRenderContext frc = ...;


 117  *           {@link NumericShaper#EASTERN_ARABIC NumericShaper.EASTERN_ARABIC}</td>
 118  *       <td>{@link NumericShaper#EASTERN_ARABIC NumericShaper.EASTERN_ARABIC}</td>
 119  *    </tr>
 120  *    <tr>
 121  *       <td>{@link NumericShaper.Range#ARABIC}<br>
 122  *           {@link NumericShaper.Range#EASTERN_ARABIC}</td>
 123  *       <td>{@link NumericShaper.Range#EASTERN_ARABIC}</td>
 124  *    </tr>
 125  *    <tr>
 126  *       <td>Tai Tham</td>
 127  *       <td>{@link NumericShaper.Range#TAI_THAM_HORA}<br>
 128  *           {@link NumericShaper.Range#TAI_THAM_THAM}</td>
 129  *       <td>{@link NumericShaper.Range#TAI_THAM_THAM}</td>
 130  *    </tr>
 131  * </table>
 132  *
 133  * @since 1.4
 134  */
 135 
 136 public final class NumericShaper implements java.io.Serializable {








 137     /**
 138      * A {@code NumericShaper.Range} represents a Unicode range of a
 139      * script having its own decimal digits. For example, the {@link
 140      * NumericShaper.Range#THAI} range has the Thai digits, THAI DIGIT
 141      * ZERO (U+0E50) to THAI DIGIT NINE (U+0E59).
 142      *
 143      * <p>The <code>Range</code> enum replaces the traditional bit
 144      * mask-based values (e.g., {@link NumericShaper#ARABIC}), and
 145      * supports more Unicode ranges than the bit mask-based ones. For
 146      * example, the following code using the bit mask:
 147      * <blockquote><pre>
 148      * NumericShaper.getContextualShaper(NumericShaper.ARABIC |
 149      *                                     NumericShaper.TAMIL,
 150      *                                   NumericShaper.EUROPEAN);
 151      * </pre></blockquote>
 152      * can be written using this enum as:
 153      * <blockquote><pre>
 154      * NumericShaper.getContextualShaper(EnumSet.of(
 155      *                                     NumericShaper.Range.ARABIC,
 156      *                                     NumericShaper.Range.TAMIL),


   1 /*
   2  * Copyright (c) 2000, 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
  23  * questions.
  24  */
  25 
  26 package java.awt.font;
  27 
  28 import java.io.IOException;
  29 import java.io.ObjectOutputStream;
  30 import java.util.Arrays;
  31 import java.util.Comparator;
  32 import java.util.EnumSet;
  33 import java.util.Set;
  34 import sun.misc.SharedSecrets;
  35 
  36 /**
  37  * The <code>NumericShaper</code> class is used to convert Latin-1 (European)
  38  * digits to other Unicode decimal digits.  Users of this class will
  39  * primarily be people who wish to present data using
  40  * national digit shapes, but find it more convenient to represent the
  41  * data internally using Latin-1 (European) digits.  This does not
  42  * interpret the deprecated numeric shape selector character (U+206E).
  43  * <p>
  44  * Instances of <code>NumericShaper</code> are typically applied
  45  * as attributes to text with the
  46  * {@link TextAttribute#NUMERIC_SHAPING NUMERIC_SHAPING} attribute
  47  * of the <code>TextAttribute</code> class.
  48  * For example, this code snippet causes a <code>TextLayout</code> to
  49  * shape European digits to Arabic in an Arabic context:<br>
  50  * <blockquote><pre>
  51  * Map map = new HashMap();
  52  * map.put(TextAttribute.NUMERIC_SHAPING,
  53  *     NumericShaper.getContextualShaper(NumericShaper.ARABIC));
  54  * FontRenderContext frc = ...;


 118  *           {@link NumericShaper#EASTERN_ARABIC NumericShaper.EASTERN_ARABIC}</td>
 119  *       <td>{@link NumericShaper#EASTERN_ARABIC NumericShaper.EASTERN_ARABIC}</td>
 120  *    </tr>
 121  *    <tr>
 122  *       <td>{@link NumericShaper.Range#ARABIC}<br>
 123  *           {@link NumericShaper.Range#EASTERN_ARABIC}</td>
 124  *       <td>{@link NumericShaper.Range#EASTERN_ARABIC}</td>
 125  *    </tr>
 126  *    <tr>
 127  *       <td>Tai Tham</td>
 128  *       <td>{@link NumericShaper.Range#TAI_THAM_HORA}<br>
 129  *           {@link NumericShaper.Range#TAI_THAM_THAM}</td>
 130  *       <td>{@link NumericShaper.Range#TAI_THAM_THAM}</td>
 131  *    </tr>
 132  * </table>
 133  *
 134  * @since 1.4
 135  */
 136 
 137 public final class NumericShaper implements java.io.Serializable {
 138 
 139     // For access from java.text.Bidi
 140     static {
 141         if (SharedSecrets.getJavaAWTFontAccess() == null) {
 142             SharedSecrets.setJavaAWTFontAccess(new JavaAWTFontAccessImpl());
 143         }
 144     }
 145 
 146     /**
 147      * A {@code NumericShaper.Range} represents a Unicode range of a
 148      * script having its own decimal digits. For example, the {@link
 149      * NumericShaper.Range#THAI} range has the Thai digits, THAI DIGIT
 150      * ZERO (U+0E50) to THAI DIGIT NINE (U+0E59).
 151      *
 152      * <p>The <code>Range</code> enum replaces the traditional bit
 153      * mask-based values (e.g., {@link NumericShaper#ARABIC}), and
 154      * supports more Unicode ranges than the bit mask-based ones. For
 155      * example, the following code using the bit mask:
 156      * <blockquote><pre>
 157      * NumericShaper.getContextualShaper(NumericShaper.ARABIC |
 158      *                                     NumericShaper.TAMIL,
 159      *                                   NumericShaper.EUROPEAN);
 160      * </pre></blockquote>
 161      * can be written using this enum as:
 162      * <blockquote><pre>
 163      * NumericShaper.getContextualShaper(EnumSet.of(
 164      *                                     NumericShaper.Range.ARABIC,
 165      *                                     NumericShaper.Range.TAMIL),