⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 numericshaper.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)NumericShaper.java	1.9 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.font;/** * The <code>NumericShaper</code> class is used to convert Latin-1 (European)  * digits to other Unicode decimal digits.  Users of this class will * primarily be people who wish to present data using * national digit shapes, but find it more convenient to represent the * data internally using Latin-1 (European) digits.  This does not * interpret the deprecated numeric shape selector character (U+206E). * <p> * Instances of <code>NumericShaper</code> are typically applied  * as attributes to text with the * {@link TextAttribute#NUMERIC_SHAPING NUMERIC_SHAPING} attribute * of the <code>TextAttribute</code> class.   * For example, this code snippet causes a <code>TextLayout</code> to  * shape European digits to Arabic in an Arabic context:<br> * <blockquote><pre> * Map map = new HashMap(); * map.put(TextAttribute.NUMERIC_SHAPING,  *     NumericShaper.getContextualShaper(NumericShaper.ARABIC)); * FontRenderContext frc = ...; * TextLayout layout = new TextLayout(text, map, frc); * layout.draw(g2d, x, y); * </pre></blockquote> * <br> * It is also possible to perform numeric shaping explicitly using instances  * of <code>NumericShaper</code>, as this code snippet demonstrates:<br> * <blockquote><pre> *   char[] text = ...; *   // shape all EUROPEAN digits (except zero) to ARABIC digits *   NumericShaper shaper = NumericShaper.getShaper(NumericShaper.ARABIC); *   shaper.shape(text, start, count); * *   // shape European digits to ARABIC digits if preceeding text is Arabic, or *   // shape European digits to TAMIL digits if preceeding text is Tamil, or *   // leave European digits alone if there is no preceeding text, or  *   // preceeding text is neither Arabic nor Tamil *   NumericShaper shaper =  *      NumericShaper.getContextualShaper(NumericShaper.ARABIC |  *                                              NumericShaper.TAMIL, *                                              NumericShaper.EUROPEAN); *   shaper.shape(text. start, count); * </pre></blockquote> * * @since 1.4 */public final class NumericShaper implements java.io.Serializable {    /** index of context for contextual shaping - values range from 0 to 18 */    private int key;    /** flag indicating whether to shape contextually (high bit) and which      *  digit ranges to shape (bits 0-18)      */    private int mask;    /** Identifies the Latin-1 (European) and extended range, and      *  Latin-1 (European) decimal base.      */    public static final int EUROPEAN = 1<<0;    /** Identifies the ARABIC range and decimal base. */    public static final int ARABIC = 1<<1;    /** Identifies the ARABIC range and ARABIC_EXTENDED decimal base. */    public static final int EASTERN_ARABIC = 1<<2;    /** Identifies the DEVANAGARI range and decimal base. */    public static final int DEVANAGARI = 1<<3;    /** Identifies the BENGALI range and decimal base. */    public static final int BENGALI = 1<<4;    /** Identifies the GURMUKHI range and decimal base. */    public static final int GURMUKHI = 1<<5;    /** Identifies the GUJARATI range and decimal base. */    public static final int GUJARATI = 1<<6;    /** Identifies the ORIYA range and decimal base. */    public static final int ORIYA = 1<<7;    /** Identifies the TAMIL range and decimal base. Tamil does not have a      *  decimal digit 0 so Latin-1 (European) 0 is used.      */    public static final int TAMIL = 1<<8;    /** Identifies the TELUGU range and decimal base. */    public static final int TELUGU = 1<<9;    /** Identifies the KANNADA range and decimal base. */    public static final int KANNADA = 1<<10;    /** Identifies the MALAYALAM range and decimal base. */    public static final int MALAYALAM = 1<<11;    /** Identifies the THAI range and decimal base. */    public static final int THAI = 1<<12;    /** Identifies the LAO range and decimal base. */    public static final int LAO = 1<<13;    /** Identifies the TIBETAN range and decimal base. */    public static final int TIBETAN = 1<<14;    /** Identifies the MYANMAR range and decimal base. */    public static final int MYANMAR = 1<<15;    /** Identifies the ETHIOPIC range and decimal base. */    public static final int ETHIOPIC = 1<<16;    /** Identifies the KHMER range and decimal base. */    public static final int KHMER = 1<<17;    /** Identifies the MONGOLIAN range and decimal base. */    public static final int MONGOLIAN = 1<<18;    /** Identifies all ranges, for full contextual shaping. */    public static final int ALL_RANGES = 0x0007ffff;    private static final int EUROPEAN_KEY = 0;    private static final int ARABIC_KEY = 1;    private static final int EASTERN_ARABIC_KEY = 2;    private static final int DEVANAGARI_KEY = 3;    private static final int BENGALI_KEY = 4;    private static final int GURMUKHI_KEY = 5;    private static final int GUJARATI_KEY = 6;    private static final int ORIYA_KEY = 7;    private static final int TAMIL_KEY = 8;    private static final int TELUGU_KEY = 9;    private static final int KANNADA_KEY = 10;    private static final int MALAYALAM_KEY = 11;    private static final int THAI_KEY = 12;    private static final int LAO_KEY = 13;    private static final int TIBETAN_KEY = 14;    private static final int MYANMAR_KEY = 15;    private static final int ETHIOPIC_KEY = 16;    private static final int KHMER_KEY = 17;    private static final int MONGOLIAN_KEY = 18;    private static final int NUM_KEYS = 19;    private static final String[] keyNames = {	"EUROPEAN",	"ARABIC",	"EASTERN_ARABIC",	"DEVANAGARI",	"BENGALI",	"GURMUKHI",	"GUJARATI",	"ORIYA",	"TAMIL",	"TELUGU",	"KANNADA",	"MALAYALAM",	"THAI",	"LAO",	"TIBETAN",	"MYANMAR",	"ETHIOPIC",	"KHMER",	"MONGOLIAN"    };    private static final int CONTEXTUAL_MASK = 1<<31;    private static final char[] bases = {	'\u0030' - '\u0030', // EUROPEAN	'\u0660' - '\u0030', // ARABIC	'\u06f0' - '\u0030', // EASTERN_ARABIC	'\u0966' - '\u0030', // DEVANAGARI	'\u09e6' - '\u0030', // BENGALI	'\u0a66' - '\u0030', // GURMUKHI	'\u0ae6' - '\u0030', // GUJARATI	'\u0b66' - '\u0030', // ORIYA	'\u0be7' - '\u0030', // TAMIL - note missing zero	'\u0c66' - '\u0030', // TELUGU	'\u0ce6' - '\u0030', // KANNADA	'\u0d66' - '\u0030', // MALAYALAM	'\u0e50' - '\u0030', // THAI	'\u0ed0' - '\u0030', // LAO	'\u0f20' - '\u0030', // TIBETAN	'\u1040' - '\u0030', // MYANMAR	'\u1369' - '\u0030', // ETHIOPIC	'\u17e0' - '\u0030', // KHMER	'\u1810' - '\u0030', // MONGOLIAN    };    // some ranges adjoin or overlap, rethink if we want to do a binary search on this    private static final char[] contexts = {	'\u0000', '\u0300', // 'EUROPEAN' (really latin-1 and extended)	'\u0600', '\u0700', // ARABIC	'\u0600', '\u0700', // EASTERN_ARABIC -- note overlap with arabic	'\u0900', '\u0980', // DEVANAGARI	'\u0980', '\u0a00', // BENGALI	'\u0a00', '\u0a80', // GURMUKHI	'\u0a80', '\u0b00', // GUJARATI	'\u0b00', '\u0b80', // ORIYA	'\u0b80', '\u0c00', // TAMIL - note missing zero	'\u0c00', '\u0c80', // TELUGU	'\u0c80', '\u0d00', // KANNADA	'\u0d00', '\u0d80', // MALAYALAM	'\u0e00', '\u0e80', // THAI	'\u0e80', '\u0f00', // LAO	'\u0f00', '\u1000', // TIBETAN	'\u1000', '\u1080', // MYANMAR	'\u1200', '\u1380', // ETHIOPIC	'\u1780', '\u1800', // KHMER	'\u1800', '\u1900', // MONGOLIAN	'\uffff',    };    // assume most characters are near each other so probing the cache is infrequent,    // and a linear probe is ok.    private static int ctCache = 0;    private static int ctCacheLimit = contexts.length - 2;    // warning, synchronize access to this as it modifies state    private static int getContextKey(char c) {	if (c < contexts[ctCache]) {	    while (ctCache > 0 && c < contexts[ctCache]) --ctCache;	} else if (c >= contexts[ctCache + 1]) {	    while (ctCache < ctCacheLimit && c >= contexts[ctCache + 1]) ++ctCache;	}		// if we're not in a known range, then return EUROPEAN as the range key	return (ctCache & 0x1) == 0 ? (ctCache / 2) : EUROPEAN_KEY;    }    /*     * A range table of strong directional characters (types L, R, AL).     * Even (left) indexes are starts of ranges of non-strong-directional (or undefined)     * characters, odd (right) indexes are starts of ranges of strong directional     * characters.     */    private static char[] strongTable = {	'\u0000', '\u0041',	'\u005b', '\u0061',	'\u007b', '\u00aa',	'\u00ab', '\u00b5',	'\u00b6', '\u00ba',	'\u00bb', '\u00c0',	'\u00d7', '\u00d8',	'\u00f7', '\u00f8',	'\u0220', '\u0222',	'\u0234', '\u0250',	'\u02ae', '\u02b0',	'\u02b9', '\u02bb',	'\u02c2', '\u02d0',	'\u02d2', '\u02e0',	'\u02e5', '\u02ee',	'\u02ef', '\u037a',	'\u037b', '\u0386',	'\u0387', '\u0388',	'\u038b', '\u038c',	'\u038d', '\u038e',	'\u03a2', '\u03a3',	'\u03cf', '\u03d0',	'\u03d8', '\u03da',	'\u03f4', '\u0400',	'\u0483', '\u048c',	'\u04c5', '\u04c7',	'\u04c9', '\u04cb',	'\u04cd', '\u04d0',	'\u04f6', '\u04f8',	'\u04fa', '\u0531',	'\u0557', '\u0559',	'\u0560', '\u0561',	'\u0588', '\u0589',	'\u058a', '\u05be',	'\u05bf', '\u05c0',	'\u05c1', '\u05c3',	'\u05c4', '\u05d0',	'\u05eb', '\u05f0',	'\u05f5', '\u061b',	'\u061c', '\u061f',	'\u0620', '\u0621',	'\u063b', '\u0640',	'\u064b', '\u066d',	'\u066e', '\u0671',	'\u06d6', '\u06e5',	'\u06e7', '\u06fa',	'\u06ff', '\u0700',	'\u070e', '\u0710',	'\u0711', '\u0712',	'\u072d', '\u0780',	'\u07a6', '\u0903',	'\u0904', '\u0905',	'\u093a', '\u093d',	'\u0941', '\u0949', 	'\u094d', '\u0950',	'\u0951', '\u0958',	'\u0962', '\u0964',	'\u0971', '\u0982',	'\u0984', '\u0985',	'\u098d', '\u098f',	'\u0991', '\u0993',	'\u09a9', '\u09aa',	'\u09b1', '\u09b2',	'\u09b3', '\u09b6',	'\u09ba', '\u09be',	'\u09c1', '\u09c7',	'\u09c9', '\u09cb',	'\u09cd', '\u09d7',	'\u09d8', '\u09dc',	'\u09de', '\u09df',	'\u09e2', '\u09e6',	'\u09f2', '\u09f4',	'\u09fb', '\u0a05',	'\u0a0b', '\u0a0f',	'\u0a11', '\u0a13',	'\u0a29', '\u0a2a',	'\u0a31', '\u0a32',	'\u0a34', '\u0a35',	'\u0a37', '\u0a38',	'\u0a3a', '\u0a3e',	'\u0a41', '\u0a59',	'\u0a5d', '\u0a5e',	'\u0a5f', '\u0a66',	'\u0a70', '\u0a72',	'\u0a75', '\u0a83',	'\u0a84', '\u0a85',	'\u0a8c', '\u0a8d',	'\u0a8e', '\u0a8f',	'\u0a92', '\u0a93',	'\u0aa9', '\u0aaa',	'\u0ab1', '\u0ab2',	'\u0ab4', '\u0ab5',	'\u0aba', '\u0abd',	'\u0ac1', '\u0ac9',	'\u0aca', '\u0acb',	'\u0acd', '\u0ad0',	'\u0ad1', '\u0ae0',	'\u0ae1', '\u0ae6',	'\u0af0', '\u0b02',	'\u0b04', '\u0b05',	'\u0b0d', '\u0b0f',	'\u0b11', '\u0b13',	'\u0b29', '\u0b2a',	'\u0b31', '\u0b32',	'\u0b34', '\u0b36',	'\u0b3a', '\u0b3d',	'\u0b3f', '\u0b40',	'\u0b41', '\u0b47',	'\u0b49', '\u0b4b',	'\u0b4d', '\u0b57',	'\u0b58', '\u0b5c',	'\u0b5e', '\u0b5f',	'\u0b62', '\u0b66',	'\u0b71', '\u0b83',	'\u0b84', '\u0b85',	'\u0b8b', '\u0b8e',	'\u0b91', '\u0b92',	'\u0b96', '\u0b99',	'\u0b9b', '\u0b9c',	'\u0b9d', '\u0b9e',	'\u0ba0', '\u0ba3',	'\u0ba5', '\u0ba8',	'\u0bab', '\u0bae',	'\u0bb6', '\u0bb7',	'\u0bba', '\u0bbe',	'\u0bc0', '\u0bc1',	'\u0bc3', '\u0bc6',	'\u0bc9', '\u0bca',	'\u0bcd', '\u0bd7',	'\u0bd8', '\u0be7',	'\u0bf3', '\u0c01',	'\u0c04', '\u0c05',	'\u0c0d', '\u0c0e',	'\u0c11', '\u0c12',	'\u0c29', '\u0c2a',	'\u0c34', '\u0c35',	'\u0c3a', '\u0c41',	'\u0c45', '\u0c60',	'\u0c62', '\u0c66',	'\u0c70', '\u0c82',	'\u0c84', '\u0c85',	'\u0c8d', '\u0c8e',	'\u0c91', '\u0c92',	'\u0ca9', '\u0caa',	'\u0cb4', '\u0cb5',	'\u0cba', '\u0cbe',	'\u0cbf', '\u0cc0',	'\u0cc5', '\u0cc7',	'\u0cc9', '\u0cca',	'\u0ccc', '\u0cd5',	'\u0cd7', '\u0cde',	'\u0cdf', '\u0ce0',	'\u0ce2', '\u0ce6',	'\u0cf0', '\u0d02',	'\u0d04', '\u0d05',	'\u0d0d', '\u0d0e',	'\u0d11', '\u0d12',	'\u0d29', '\u0d2a',	'\u0d3a', '\u0d3e',	'\u0d41', '\u0d46',	'\u0d49', '\u0d4a',	'\u0d4d', '\u0d57',	'\u0d58', '\u0d60',	'\u0d62', '\u0d66',	'\u0d70', '\u0d82',	'\u0d84', '\u0d85',	'\u0d97', '\u0d9a',	'\u0db2', '\u0db3',	'\u0dbc', '\u0dbd',	'\u0dbe', '\u0dc0',	'\u0dc7', '\u0dcf',	'\u0dd2', '\u0dd8',	'\u0de0', '\u0df2',	'\u0df5', '\u0e01',	'\u0e31', '\u0e32',	'\u0e34', '\u0e40',	'\u0e47', '\u0e4f',	'\u0e5c', '\u0e81',	'\u0e83', '\u0e84',	'\u0e85', '\u0e87',	'\u0e89', '\u0e8a',	'\u0e8b', '\u0e8d',	'\u0e8e', '\u0e94',	'\u0e98', '\u0e99',	'\u0ea0', '\u0ea1',	'\u0ea4', '\u0ea5',	'\u0ea6', '\u0ea7',	'\u0ea8', '\u0eaa',	'\u0eac', '\u0ead',	'\u0eb1', '\u0eb2',	'\u0eb4', '\u0ebd',	'\u0ebe', '\u0ec0',	'\u0ec5', '\u0ec6',	'\u0ec7', '\u0ed0',	'\u0eda', '\u0edc',	'\u0ede', '\u0f00',	'\u0f18', '\u0f1a',	'\u0f35', '\u0f36',	'\u0f37', '\u0f38',	'\u0f39', '\u0f3e',	'\u0f48', '\u0f49',	'\u0f6b', '\u0f7f',	'\u0f80', '\u0f85',	'\u0f86', '\u0f88',	'\u0f8c', '\u0fbe',	'\u0fc6', '\u0fc7',	'\u0fcd', '\u0fcf',	'\u0fd0', '\u1000',	'\u1022', '\u1023',	'\u1028', '\u1029',	'\u102b', '\u102c',	'\u102d', '\u1031',	'\u1032', '\u1038',	'\u1039', '\u1040',	'\u1058', '\u10a0',	'\u10c6', '\u10d0',	'\u10f7', '\u10fb',	'\u10fc', '\u1100',

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -