Package java.awt.font

Examples of java.awt.font.NumericShaper


    /*
     * Test method for 'java.awt.font.NumericShaper.getShaper(int)'
     */
    public final void testGetShaper() {
        NumericShaper ns;
        ns = NumericShaper.getShaper(NumericShaper.EASTERN_ARABIC);
        assertNotNull(ns);
       
        assertEquals("Ranges are different", NumericShaper.EASTERN_ARABIC, ns.getRanges());
        assertFalse("Simple shaper can not be contextual", ns.isContextual());
       
        try{
            ns = NumericShaper.getShaper(NumericShaper.EASTERN_ARABIC | NumericShaper.BENGALI);
            fail("IlligalArgumentException wasn't thrown with invalid shaper value");
        } catch (IllegalArgumentException e){
View Full Code Here


    /*
     * Test method for 'java.awt.font.NumericShaper.isContextual()'
     */
    public final void testIsContextual() {
        NumericShaper ns;

        // Simple shapers
        ns = NumericShaper.getShaper(NumericShaper.EASTERN_ARABIC);
        assertFalse("Simple shapers may not be contextual", ns.isContextual());
       
        // Context shapers with default context
        ns = NumericShaper.getContextualShaper(NumericShaper.ARABIC | NumericShaper.TAMIL);
        assertTrue("Default context shapers must be contextual", ns.isContextual());
           
        // Context shapers with context
        ns = NumericShaper.getContextualShaper(NumericShaper.ARABIC | NumericShaper.TAMIL, NumericShaper.EASTERN_ARABIC);
        assertTrue("Context shapers must be contextual", ns.isContextual());
    }
View Full Code Here

    /*
     * Test method for 'java.awt.font.NumericShaper.shape(char[], int, int, int)'
     */
    public final void testShapeCharArrayIntIntInt() {
        NumericShaper ns;
       
        int context = NumericShaper.DEVANAGARI;
       
        // non-contextual shaper - context ignored
        ns = NumericShaper.getShaper(NumericShaper.BENGALI);
       
        // test text that starts with the digit char and ends with nonDigit char
        char[] chars = testStringNoContext1.toCharArray();

        ns.shape(chars, 0, chars.length, context);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliStringNoContext1.charAt(i), chars[i]);
        }

        // shaper without default context
        ns = NumericShaper.getContextualShaper(NumericShaper.TAMIL | NumericShaper.DEVANAGARI);
       
        // test text starts with the TAMIL context digit char and ends with nonDigit char
        chars = testStringContext3.toCharArray();

        ns.shape(chars, 0, chars.length, context);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenTamilDevanagariStringContext3.charAt(i), chars[i]);
        }


        // offset >= length
        try{
            ns.shape(chars, chars.length + 1, 1, context);
            fail("IndexOutOfBoundsException expected but wasn't thrown!");
        } catch (IndexOutOfBoundsException e){
            // expected
        }
       
        // offset < 0
        try{
            ns.shape(chars, -1, 1, context);
            fail("IndexOutOfBoundsException expected but wasn't thrown!");
        } catch (IndexOutOfBoundsException e){
            // expected
        }

        // offset+length out of range
        try{
            ns.shape(chars, chars.length -1, 2);
            fail("IndexOutOfBoundsException expected but wasn't thrown!");
        } catch (IndexOutOfBoundsException e){
            // expected
        }

View Full Code Here

    /*
     * Test method for 'java.awt.font.NumericShaper.shape(char[], int, int)'
     */
    public final void testShapeCharArrayIntInt() {
        NumericShaper ns;
       
        /*************************/
        /* Non-Contextual shaper */ 
        /*************************/

        ns = NumericShaper.getShaper(NumericShaper.BENGALI);
       
        // test text that starts with the digit char and ends with nonDigit char
        char[] chars = testStringNoContext1.toCharArray();

        ns.shape(chars, 0, chars.length);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliStringNoContext1.charAt(i), chars[i]);
        }

        // text starts with the nonDigit char and ends with digit char
        chars = testStringNoContext2.toCharArray();
        ns.shape(chars, 0, chars.length);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliStringNoContext2.charAt(i), chars[i]);
        }

        /*********************/
        /* Contextual shaper */ 
        /*********************/
       
        // shaper without default context
        ns = NumericShaper.getContextualShaper(NumericShaper.BENGALI | NumericShaper.DEVANAGARI);
       
        // test text starts with the BENGALI context digit char and ends with nonDigit char
        chars = testStringContext1.toCharArray();

        ns.shape(chars, 0, chars.length);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliDevanagariStringContext1.charAt(i), chars[i]);
        }

        // text starts with the nonDigit char and ends with digit char
        // the first set of digits in text folows by "\u0909" char from the DEVANGARI script
        // the second set of digits in text folows by "\u0983" char from the BENGALI script
        chars = testStringContext2.toCharArray();

        ns.shape(chars, 0, chars.length);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliDevanagariStringContext2.charAt(i), chars[i]);
        }

        // shaper with acceptable default context
        ns = NumericShaper.getContextualShaper(NumericShaper.TAMIL | NumericShaper.DEVANAGARI, NumericShaper.DEVANAGARI);
       
        // text starts with Digit char and ends with digit char
        // These digits must be replaced with default context digits
        chars = testStringContext3.toCharArray();
       
        ns.shape(chars, 0, chars.length);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenTamilDevanagariStringContext3.charAt(i), chars[i]);
        }
       
        // shaper with nonacceptable default context
        ns = NumericShaper.getContextualShaper(NumericShaper.TAMIL | NumericShaper.DEVANAGARI, NumericShaper.KANNADA);
       
        // text starts with Digit char and ends with digit char
        // All digits must stay without changes
        chars = testStringContext3.toCharArray();
       
        ns.shape(chars, 0, chars.length);
       
        for (int i=0; i < chars.length; i++){
            assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)testStringContext3.charAt(i), chars[i]);
        }
       
        // offset >= length
        try{
            ns.shape(chars, chars.length + 1, 1);
            fail("IndexOutOfBoundsException expected but wasn't thrown!");
        } catch (IndexOutOfBoundsException e){
            // expected
        }
       
        // offset < 0
        try{
            ns.shape(chars, -1, 1);
            fail("IndexOutOfBoundsException expected but wasn't thrown!");
        } catch (IndexOutOfBoundsException e){
            // expected
        }

        // offset+length out of range
        try{
            ns.shape(chars, chars.length -1, 2);
            fail("IndexOutOfBoundsException expected but wasn't thrown!");
        } catch (IndexOutOfBoundsException e){
            // expected
        }
       
View Full Code Here

     * illegal parameters.
     */
    public final void testShapeCharArrayIntInt_IllegalArguments() {
        // regression test for Harmony-1584
        int ranges = NumericShaper.ARABIC;
        NumericShaper localNumericShaper = NumericShaper
                .getContextualShaper(ranges);
        char[] chars = new char[] {};
        int start = 0;
        int count = 1;
        try {
            localNumericShaper.shape(chars, start, count);
            fail("len = 0: ArrayIndexOutOfBoundsException expected!");
        } catch (ArrayIndexOutOfBoundsException expectedException) {
            // expected
        }

        chars = new char[] {'a', 'b', 'c'};
        start = -1;
        count = 1;
        try {
            localNumericShaper.shape(chars, start, count);
            fail("start < 0: ArrayIndexOutOfBoundsException expected!");
        } catch (ArrayIndexOutOfBoundsException expectedException) {
            // expected
        }

        // count < 0: silent run expected
        start = 1;
        count = -1;
        localNumericShaper.shape(chars, start, count);

        start = 3;
        count = 5;
        try {
            localNumericShaper.shape(chars, start, count);
            fail("start + count > len: ArrayIndexOutOfBoundsException expected!");
        } catch (ArrayIndexOutOfBoundsException expectedException) {
            // expected
        }

View Full Code Here

     * illegal parameters.
     */
    public final void testShapeCharArrayIntIntInt_IllegalArguments() {
        // regression test for Harmony-1584
        int ranges = NumericShaper.ARABIC;
        NumericShaper localNumericShaper = NumericShaper
                .getContextualShaper(ranges);
        char[] chars = new char[] {};
        int start = 0;
        int count = 1;
        int index = NumericShaper.ARABIC;
        try {
            localNumericShaper.shape(chars, start, count, index);
            fail("len = 0: ArrayIndexOutOfBoundsException expected!");
        } catch (ArrayIndexOutOfBoundsException expectedException) {
            //expected
        }

        chars = new char[] {'a', 'b', 'c'};
        start = -1;
        count = 1;
        try {
            localNumericShaper.shape(chars, start, count, index);
            fail("start < 0: ArrayIndexOutOfBoundsException expected!");
        } catch (ArrayIndexOutOfBoundsException expectedException) {
            // expected
        }

        // count < 0: silent run expected
        start = 1;
        count = -1;
        localNumericShaper.shape(chars, start, count, index);

        start = 3;
        count = 5;
        try {
            localNumericShaper.shape(chars, start, count, index);
            fail("start + count > len: ArrayIndexOutOfBoundsException expected!");
        } catch (ArrayIndexOutOfBoundsException expectedException) {
            // expected
        }

View Full Code Here

            }
            ch = paragraph.next();
            ++i;
        }

        NumericShaper shaper = (NumericShaper) paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING);
        if (shaper != null) {
            shaper.shape(txt, 0, len);
        }
        setPara(txt, paraLvl, lvls);
    }
View Full Code Here

      this.flags = DIRECTION_DEFAULT_LEFT_TO_RIGHT;

    // Likewise this attribute should be specified on the whole text.
    // We read it here and then, if it is set, we apply the numeric shaper
    // to the text before processing it.
    NumericShaper shaper = null;
    val = iter.getAttribute(TextAttribute.NUMERIC_SHAPING);
    if (val instanceof NumericShaper)
      shaper = (NumericShaper) val;

    this.text = new char[iter.getEndIndex() - iter.getBeginIndex()];
    this.embeddings = new byte[this.text.length];
    this.embeddingOffset = 0;
    this.length = text.length;
    for (int i = 0; i < this.text.length; ++i)
      {
        this.text[i] = iter.current();

        val = iter.getAttribute(TextAttribute.BIDI_EMBEDDING);
        if (val instanceof Integer)
          {
            int ival = ((Integer) val).intValue();
            byte bval;
            if (ival < -62 || ival > 62)
              bval = 0;
            else
              bval = (byte) ival;
            this.embeddings[i] = bval;
          }
      }

    // Invoke the numeric shaper, if specified.
    if (shaper != null)
      shaper.shape(this.text, 0, this.length);

    runBidi();
  }
View Full Code Here

      this.flags = DIRECTION_DEFAULT_LEFT_TO_RIGHT;

    // Likewise this attribute should be specified on the whole text.
    // We read it here and then, if it is set, we apply the numeric shaper
    // to the text before processing it.
    NumericShaper shaper = null;
    val = iter.getAttribute(TextAttribute.NUMERIC_SHAPING);
    if (val instanceof NumericShaper)
      shaper = (NumericShaper) val;

    char[] text = new char[iter.getEndIndex() - iter.getBeginIndex()];
    this.embeddings = new byte[this.text.length];
    this.embeddingOffset = 0;
    this.length = text.length;
    for (int i = 0; i < this.text.length; ++i)
      {
        this.text[i] = iter.current();

        val = iter.getAttribute(TextAttribute.BIDI_EMBEDDING);
        if (val instanceof Integer)
          {
            int ival = ((Integer) val).intValue();
            byte bval;
            if (ival < -62 || ival > 62)
              bval = 0;
            else
              bval = (byte) ival;
            this.embeddings[i] = bval;
          }
      }

    // Invoke the numeric shaper, if specified.
    if (shaper != null)
      shaper.shape(this.text, 0, this.length);

    runBidi();
  }
View Full Code Here

        }
        catch (ClassCastException e) {
        }

        try {
            NumericShaper shaper = (NumericShaper)paragraph.getAttribute(TextAttribute.NUMERIC_SHAPING);
            if (shaper != null) {
                shaper.shape(text, 0, text.length);
            }
        }
        catch (ClassCastException e) {
        }
View Full Code Here

TOP

Related Classes of java.awt.font.NumericShaper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.