com.ibm.icu.text.Bidi Java Examples

The following examples show how to use com.ibm.icu.text.Bidi. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LineArea.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void initialize( ) throws BirtException
{
	hasStyle = false;
	boxStyle = BoxStyle.DEFAULT;
	localProperties = LocalProperties.DEFAULT;
	maxAvaWidth = parent.getCurrentMaxContentWidth( );
	width = maxAvaWidth;
	// Derive the baseLevel from the parent content direction.
	if ( parent.content != null )
	{
		// IContent#isDirectionRTL already looks at computed style
		if ( parent.content.isDirectionRTL( ) )
			baseLevel = Bidi.DIRECTION_RIGHT_TO_LEFT;
	}
	//parent.add( this );
}
 
Example #2
Source File: LineLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void initialize( )
{
	int currentIP = 0;
	if(contextList.size()>0)
	{
		currentIP = contextList.get(contextList.size()-1).currentIP;
	}
	currentContext = new ContainerContext( );
	currentContext.currentIP = currentIP;
	contextList.add( currentContext );
	createRoot( );
	currentContext.maxAvaWidth = parent.getCurrentMaxContentWidth( );
	currentContext.maxAvaHeight = parent.getCurrentMaxContentHeight( );
	currentContext.root.setWidth( parent.getCurrentMaxContentWidth( ) );
	lineHeight = ( (BlockStackingLayout) parent ).getLineHeight( );

	 // Derive the baseLevel from the parent content direction.
	if ( parent.content != null )
	{
		if ( CSSConstants.CSS_RTL_VALUE.equals( parent.content
				.getComputedStyle( ).getDirection( ) ) )
			baseLevel = Bidi.DIRECTION_RIGHT_TO_LEFT;
	}
}
 
Example #3
Source File: BidiBase.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #4
Source File: BidiBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #5
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #6
Source File: BidiBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #7
Source File: BidiBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #8
Source File: BidiBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #9
Source File: BidiBase.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #10
Source File: BidiBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #11
Source File: BidiBase.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #12
Source File: BidiBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #13
Source File: JavaSourceViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void createControl(Composite parent, int styles) {

	// Use LEFT_TO_RIGHT unless otherwise specified.
	if ((styles & SWT.RIGHT_TO_LEFT) == 0 && (styles & SWT.LEFT_TO_RIGHT) == 0)
		styles |= SWT.LEFT_TO_RIGHT;

	final int baseLevel= (styles & SWT.RIGHT_TO_LEFT) != 0 ? Bidi.DIRECTION_RIGHT_TO_LEFT : Bidi.DIRECTION_LEFT_TO_RIGHT;

	super.createControl(parent, styles);

	fBackspaceManager= new SmartBackspaceManager();
	fBackspaceManager.install(this);

	StyledText text= getTextWidget();
	text.addBidiSegmentListener(new BidiSegmentListener() {
		public void lineGetSegments(BidiSegmentEvent event) {
			if (redraws()) {
				try {
					event.segments= getBidiLineSegments(getDocument(), baseLevel, widgetOffset2ModelOffset(event.lineOffset), event.lineText);
				} catch (BadLocationException e) {
					// don't touch the segments
				}
			}
		}
	});
}
 
Example #14
Source File: BidiBase.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #15
Source File: BidiBase.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #16
Source File: BidiBase.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #17
Source File: BidiBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #18
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #20
Source File: BidiBase.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private byte directionFromFlags() {
    /* if the text contains AN and neutrals, then some neutrals may become RTL */
    if (!((flags & MASK_RTL) != 0 ||
          ((flags & DirPropFlag(AN)) != 0 &&
           (flags & MASK_POSSIBLE_N) != 0))) {
        return Bidi.DIRECTION_LEFT_TO_RIGHT;
    } else if ((flags & MASK_LTR) == 0) {
        return Bidi.DIRECTION_RIGHT_TO_LEFT;
    } else {
        return MIXED;
    }
}
 
Example #21
Source File: BidiBase.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return true if the specified text requires bidi analysis. If this returns
 * false, the text will display left-to-right. Clients can then avoid
 * constructing a Bidi object. Text in the Arabic Presentation Forms area of
 * Unicode is presumed to already be shaped and ordered for display, and so
 * will not cause this method to return true.
 *
 * @param text the text containing the characters to test
 * @param start the start of the range of characters to test
 * @param limit the limit of the range of characters to test
 *
 * @return true if the range of characters requires bidi analysis
 *
 * @stable ICU 3.8
 */
public static boolean requiresBidi(char[] text,
        int start,
        int limit)
{
    final int RTLMask = (1 << Bidi.DIRECTION_RIGHT_TO_LEFT |
            1 << AL |
            1 << RLE |
            1 << RLO |
            1 << AN);

    if (0 > start || start > limit || limit > text.length) {
        throw new IllegalArgumentException("Value start " + start +
                  " is out of range 0 to " + limit);
    }
    for (int i = start; i < limit; ++i) {
        if (Character.isHighSurrogate(text[i]) && i < (limit-1) &&
            Character.isLowSurrogate(text[i+1])) {
            if (((1 << UCharacter.getDirection(Character.codePointAt(text, i))) & RTLMask) != 0) {
                return true;
            }
        } else if (((1 << UCharacter.getDirection(text[i])) & RTLMask) != 0) {
            return true;
        }
    }
    return false;
}
 
Example #22
Source File: ChunkGenerator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public ChunkGenerator( FontMappingManager fontManager,
		ITextContent textContent, boolean bidiProcessing,
		boolean fontSubstitution )
{
	this.fontManager = fontManager;
	this.textContent = textContent;
	this.text = textContent.getText();
	this.bidiProcessing = bidiProcessing;
	this.fontSubstitution = fontSubstitution;
	
	if ( text == null || text.length( ) == 0 )
		return;
	if ( bidiProcessing )
	{
		//FIXME implement the getDirection() method in ComputedStyle.
		if ( CSSConstants.CSS_RTL_VALUE.equals( textContent
				.getComputedStyle( ).getDirection( ) ) )
		{
			bidiSplitter = new BidiSplitter( new Chunk( text, 0,
					Bidi.DIRECTION_RIGHT_TO_LEFT,
					Bidi.DIRECTION_RIGHT_TO_LEFT ) );
		}
		else
		{
			bidiSplitter = new BidiSplitter( new Chunk( text, 0,
					Bidi.DIRECTION_LEFT_TO_RIGHT,
					Bidi.DIRECTION_LEFT_TO_RIGHT ) );
		}
	}
	
	if ( null == bidiSplitter )
	{
		fontSplitter = new FontSplitter( fontManager, new Chunk( text ),
				textContent, fontSubstitution );
	}
	else
	{
		if ( bidiSplitter.hasMore( ) )
		{
			fontSplitter = new FontSplitter( fontManager, bidiSplitter
					.getNext( ), textContent, fontSubstitution );
		}
	}		
			
}
 
Example #23
Source File: TextArea.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private String flip( String text )
{
	return Bidi
			.writeReverse( text, Bidi.OUTPUT_REVERSE | Bidi.DO_MIRRORING );
}
 
Example #24
Source File: BidiBase.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform the Unicode Bidi algorithm on a given paragraph, as defined in the
 * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
 * version 13,
 * also described in The Unicode Standard, Version 4.0 .<p>
 *
 * This method takes a paragraph of text and computes the
 * left-right-directionality of each character. The text should not
 * contain any Unicode block separators.<p>
 *
 * The RUN_DIRECTION attribute in the text, if present, determines the base
 * direction (left-to-right or right-to-left). If not present, the base
 * direction is computed using the Unicode Bidirectional Algorithm,
 * defaulting to left-to-right if there are no strong directional characters
 * in the text. This attribute, if present, must be applied to all the text
 * in the paragraph.<p>
 *
 * The BIDI_EMBEDDING attribute in the text, if present, represents
 * embedding level information. Negative values from -1 to -62 indicate
 * overrides at the absolute value of the level. Positive values from 1 to
 * 62 indicate embeddings. Where values are zero or not defined, the base
 * embedding level as determined by the base direction is assumed.<p>
 *
 * The NUMERIC_SHAPING attribute in the text, if present, converts European
 * digits to other decimal digits before running the bidi algorithm. This
 * attribute, if present, must be applied to all the text in the paragraph.
 *
 * If the entire text is all of the same directionality, then
 * the method may not perform all the steps described by the algorithm,
 * i.e., some levels may not be the same as if all steps were performed.
 * This is not relevant for unidirectional text.<br>
 * For example, in pure LTR text with numbers the numbers would get
 * a resolved level of 2 higher than the surrounding text according to
 * the algorithm. This implementation may set all resolved levels to
 * the same value in such a case.<p>
 *
 * @param paragraph a paragraph of text with optional character and
 *        paragraph attribute information
 * @stable ICU 3.8
 */
public void setPara(AttributedCharacterIterator paragraph)
{
    byte paraLvl;
    char ch = paragraph.first();
    Boolean runDirection =
        (Boolean) paragraph.getAttribute(TextAttributeConstants.RUN_DIRECTION);
    Object shaper = paragraph.getAttribute(TextAttributeConstants.NUMERIC_SHAPING);
    if (runDirection == null) {
        paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
    } else {
        paraLvl = (runDirection.equals(TextAttributeConstants.RUN_DIRECTION_LTR)) ?
                    (byte)Bidi.DIRECTION_LEFT_TO_RIGHT : (byte)Bidi.DIRECTION_RIGHT_TO_LEFT;
    }

    byte[] lvls = null;
    int len = paragraph.getEndIndex() - paragraph.getBeginIndex();
    byte[] embeddingLevels = new byte[len];
    char[] txt = new char[len];
    int i = 0;
    while (ch != AttributedCharacterIterator.DONE) {
        txt[i] = ch;
        Integer embedding =
            (Integer) paragraph.getAttribute(TextAttributeConstants.BIDI_EMBEDDING);
        if (embedding != null) {
            byte level = embedding.byteValue();
            if (level == 0) {
                /* no-op */
            } else if (level < 0) {
                lvls = embeddingLevels;
                embeddingLevels[i] = (byte)((0 - level) | INTERNAL_LEVEL_OVERRIDE);
            } else {
                lvls = embeddingLevels;
                embeddingLevels[i] = level;
            }
        }
        ch = paragraph.next();
        ++i;
    }

    if (shaper != null) {
        NumericShapings.shape(shaper, txt, 0, len);
    }
    setPara(txt, paraLvl, lvls);
}
 
Example #25
Source File: BidiBase.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create Bidi from the given text, embedding, and direction information.
 * The embeddings array may be null. If present, the values represent
 * embedding level information. Negative values from -1 to -61 indicate
 * overrides at the absolute value of the level. Positive values from 1 to
 * 61 indicate embeddings. Where values are zero, the base embedding level
 * as determined by the base direction is assumed.<p>
 *
 * Note: this constructor calls setPara() internally.
 *
 * @param text an array containing the paragraph of text to process.
 * @param textStart the index into the text array of the start of the
 *        paragraph.
 * @param embeddings an array containing embedding values for each character
 *        in the paragraph. This can be null, in which case it is assumed
 *        that there is no external embedding information.
 * @param embStart the index into the embedding array of the start of the
 *        paragraph.
 * @param paragraphLength the length of the paragraph in the text and
 *        embeddings arrays.
 * @param flags a collection of flags that control the algorithm. The
 *        algorithm understands the flags DIRECTION_LEFT_TO_RIGHT,
 *        DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and
 *        DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.
 *
 * @throws IllegalArgumentException if the values in embeddings are
 *         not within the allowed range
 *
 * @see #DIRECTION_LEFT_TO_RIGHT
 * @see #DIRECTION_RIGHT_TO_LEFT
 * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
 * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
 * @stable ICU 3.8
 */
public BidiBase(char[] text,
         int textStart,
         byte[] embeddings,
         int embStart,
         int paragraphLength,
         int flags)
 {
    this(0, 0);
    byte paraLvl;
    switch (flags) {
    case Bidi.DIRECTION_LEFT_TO_RIGHT:
    default:
        paraLvl = Bidi.DIRECTION_LEFT_TO_RIGHT;
        break;
    case Bidi.DIRECTION_RIGHT_TO_LEFT:
        paraLvl = Bidi.DIRECTION_RIGHT_TO_LEFT;
        break;
    case Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT:
        paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
        break;
    case Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT:
        paraLvl = INTERNAL_LEVEL_DEFAULT_RTL;
        break;
    }
    byte[] paraEmbeddings;
    if (embeddings == null) {
        paraEmbeddings = null;
    } else {
        paraEmbeddings = new byte[paragraphLength];
        byte lev;
        for (int i = 0; i < paragraphLength; i++) {
            lev = embeddings[i + embStart];
            if (lev < 0) {
                lev = (byte)((- lev) | INTERNAL_LEVEL_OVERRIDE);
            } else if (lev == 0) {
                lev = paraLvl;
                if (paraLvl > MAX_EXPLICIT_LEVEL) {
                    lev &= 1;
                }
            }
            paraEmbeddings[i] = lev;
        }
    }
    if (textStart == 0 && embStart == 0 && paragraphLength == text.length) {
        setPara(text, paraLvl, paraEmbeddings);
    } else {
        char[] paraText = new char[paragraphLength];
        System.arraycopy(text, textStart, paraText, 0, paragraphLength);
        setPara(paraText, paraLvl, paraEmbeddings);
    }
}
 
Example #26
Source File: BidiLevelIterator.java    From ttt with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public BidiLevelIterator() {
    this.bidi = new Bidi();
}
 
Example #27
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create Bidi from the given text, embedding, and direction information.
 * The embeddings array may be null. If present, the values represent
 * embedding level information. Negative values from -1 to -61 indicate
 * overrides at the absolute value of the level. Positive values from 1 to
 * 61 indicate embeddings. Where values are zero, the base embedding level
 * as determined by the base direction is assumed.<p>
 *
 * Note: this constructor calls setPara() internally.
 *
 * @param text an array containing the paragraph of text to process.
 * @param textStart the index into the text array of the start of the
 *        paragraph.
 * @param embeddings an array containing embedding values for each character
 *        in the paragraph. This can be null, in which case it is assumed
 *        that there is no external embedding information.
 * @param embStart the index into the embedding array of the start of the
 *        paragraph.
 * @param paragraphLength the length of the paragraph in the text and
 *        embeddings arrays.
 * @param flags a collection of flags that control the algorithm. The
 *        algorithm understands the flags DIRECTION_LEFT_TO_RIGHT,
 *        DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and
 *        DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.
 *
 * @throws IllegalArgumentException if the values in embeddings are
 *         not within the allowed range
 *
 * @see #DIRECTION_LEFT_TO_RIGHT
 * @see #DIRECTION_RIGHT_TO_LEFT
 * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
 * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
 * @stable ICU 3.8
 */
public BidiBase(char[] text,
         int textStart,
         byte[] embeddings,
         int embStart,
         int paragraphLength,
         int flags)
 {
    this(0, 0);
    byte paraLvl;
    switch (flags) {
    case Bidi.DIRECTION_LEFT_TO_RIGHT:
    default:
        paraLvl = Bidi.DIRECTION_LEFT_TO_RIGHT;
        break;
    case Bidi.DIRECTION_RIGHT_TO_LEFT:
        paraLvl = Bidi.DIRECTION_RIGHT_TO_LEFT;
        break;
    case Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT:
        paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
        break;
    case Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT:
        paraLvl = INTERNAL_LEVEL_DEFAULT_RTL;
        break;
    }
    byte[] paraEmbeddings;
    if (embeddings == null) {
        paraEmbeddings = null;
    } else {
        paraEmbeddings = new byte[paragraphLength];
        byte lev;
        for (int i = 0; i < paragraphLength; i++) {
            lev = embeddings[i + embStart];
            if (lev < 0) {
                lev = (byte)((- lev) | INTERNAL_LEVEL_OVERRIDE);
            } else if (lev == 0) {
                lev = paraLvl;
                if (paraLvl > MAX_EXPLICIT_LEVEL) {
                    lev &= 1;
                }
            }
            paraEmbeddings[i] = lev;
        }
    }
    if (textStart == 0 && embStart == 0 && paragraphLength == text.length) {
        setPara(text, paraLvl, paraEmbeddings);
    } else {
        char[] paraText = new char[paragraphLength];
        System.arraycopy(text, textStart, paraText, 0, paragraphLength);
        setPara(paraText, paraLvl, paraEmbeddings);
    }
}
 
Example #28
Source File: BidiBase.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Perform the Unicode Bidi algorithm on a given paragraph, as defined in the
 * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
 * version 13,
 * also described in The Unicode Standard, Version 4.0 .<p>
 *
 * This method takes a paragraph of text and computes the
 * left-right-directionality of each character. The text should not
 * contain any Unicode block separators.<p>
 *
 * The RUN_DIRECTION attribute in the text, if present, determines the base
 * direction (left-to-right or right-to-left). If not present, the base
 * direction is computed using the Unicode Bidirectional Algorithm,
 * defaulting to left-to-right if there are no strong directional characters
 * in the text. This attribute, if present, must be applied to all the text
 * in the paragraph.<p>
 *
 * The BIDI_EMBEDDING attribute in the text, if present, represents
 * embedding level information. Negative values from -1 to -62 indicate
 * overrides at the absolute value of the level. Positive values from 1 to
 * 62 indicate embeddings. Where values are zero or not defined, the base
 * embedding level as determined by the base direction is assumed.<p>
 *
 * The NUMERIC_SHAPING attribute in the text, if present, converts European
 * digits to other decimal digits before running the bidi algorithm. This
 * attribute, if present, must be applied to all the text in the paragraph.
 *
 * If the entire text is all of the same directionality, then
 * the method may not perform all the steps described by the algorithm,
 * i.e., some levels may not be the same as if all steps were performed.
 * This is not relevant for unidirectional text.<br>
 * For example, in pure LTR text with numbers the numbers would get
 * a resolved level of 2 higher than the surrounding text according to
 * the algorithm. This implementation may set all resolved levels to
 * the same value in such a case.<p>
 *
 * @param paragraph a paragraph of text with optional character and
 *        paragraph attribute information
 * @stable ICU 3.8
 */
public void setPara(AttributedCharacterIterator paragraph)
{
    byte paraLvl;
    char ch = paragraph.first();
    Boolean runDirection =
        (Boolean) paragraph.getAttribute(TextAttributeConstants.RUN_DIRECTION);
    Object shaper = paragraph.getAttribute(TextAttributeConstants.NUMERIC_SHAPING);
    if (runDirection == null) {
        paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
    } else {
        paraLvl = (runDirection.equals(TextAttributeConstants.RUN_DIRECTION_LTR)) ?
                    (byte)Bidi.DIRECTION_LEFT_TO_RIGHT : (byte)Bidi.DIRECTION_RIGHT_TO_LEFT;
    }

    byte[] lvls = null;
    int len = paragraph.getEndIndex() - paragraph.getBeginIndex();
    byte[] embeddingLevels = new byte[len];
    char[] txt = new char[len];
    int i = 0;
    while (ch != AttributedCharacterIterator.DONE) {
        txt[i] = ch;
        Integer embedding =
            (Integer) paragraph.getAttribute(TextAttributeConstants.BIDI_EMBEDDING);
        if (embedding != null) {
            byte level = embedding.byteValue();
            if (level == 0) {
                /* no-op */
            } else if (level < 0) {
                lvls = embeddingLevels;
                embeddingLevels[i] = (byte)((0 - level) | INTERNAL_LEVEL_OVERRIDE);
            } else {
                lvls = embeddingLevels;
                embeddingLevels[i] = level;
            }
        }
        ch = paragraph.next();
        ++i;
    }

    if (shaper != null) {
        NumericShapings.shape(shaper, txt, 0, len);
    }
    setPara(txt, paraLvl, lvls);
}
 
Example #29
Source File: LineLayout.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Puts container's child areas into the visual (display) order and
 * repositions them following that order horizontally.
 * 
 * @author Lina Kemmel
 */
private void reorderVisually( ContainerArea parent )
{
	int n = parent.getChildrenCount( );
	if ( n == 0 )
		return;

	int i = 0;
	AbstractArea[] children = new AbstractArea[n];
	byte[] levels = new byte[n];
	Iterator<?> iter = parent.getChildren( );
	
	for ( ; i < n && iter.hasNext( ); i++ )
	{
		children[i] = (AbstractArea) iter.next( );
		
		if ( children[i] instanceof TextArea )
			levels[i] = (byte) ( (TextArea) children[i] ).getRunLevel( );
		else
		{
			levels[i] = baseLevel;
			if ( children[i] instanceof ContainerArea )
			{
				// We assume that each inline container area should be
				// treated as an inline block-level element.
				reorderVisually( (ContainerArea) children[i] );
			}
		}
	}
	if ( n > 1 )
	{
		int x = children[0].getAllocatedX( );
		Bidi.reorderVisually( levels, 0, children, 0, n );

		for ( i = 0; i < n - 1; i++ )
		{
			children[i].setAllocatedPosition( x, children[i]
					.getAllocatedY( ) );
			x += children[i].getAllocatedWidth( );
		}
		children[i].setAllocatedPosition( x, children[i].getAllocatedY( ) );
	}
}
 
Example #30
Source File: BidiBase.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create Bidi from the given text, embedding, and direction information.
 * The embeddings array may be null. If present, the values represent
 * embedding level information. Negative values from -1 to -61 indicate
 * overrides at the absolute value of the level. Positive values from 1 to
 * 61 indicate embeddings. Where values are zero, the base embedding level
 * as determined by the base direction is assumed.<p>
 *
 * Note: this constructor calls setPara() internally.
 *
 * @param text an array containing the paragraph of text to process.
 * @param textStart the index into the text array of the start of the
 *        paragraph.
 * @param embeddings an array containing embedding values for each character
 *        in the paragraph. This can be null, in which case it is assumed
 *        that there is no external embedding information.
 * @param embStart the index into the embedding array of the start of the
 *        paragraph.
 * @param paragraphLength the length of the paragraph in the text and
 *        embeddings arrays.
 * @param flags a collection of flags that control the algorithm. The
 *        algorithm understands the flags DIRECTION_LEFT_TO_RIGHT,
 *        DIRECTION_RIGHT_TO_LEFT, DIRECTION_DEFAULT_LEFT_TO_RIGHT, and
 *        DIRECTION_DEFAULT_RIGHT_TO_LEFT. Other values are reserved.
 *
 * @throws IllegalArgumentException if the values in embeddings are
 *         not within the allowed range
 *
 * @see #DIRECTION_LEFT_TO_RIGHT
 * @see #DIRECTION_RIGHT_TO_LEFT
 * @see #DIRECTION_DEFAULT_LEFT_TO_RIGHT
 * @see #DIRECTION_DEFAULT_RIGHT_TO_LEFT
 * @stable ICU 3.8
 */
public BidiBase(char[] text,
         int textStart,
         byte[] embeddings,
         int embStart,
         int paragraphLength,
         int flags)
 {
    this(0, 0);
    byte paraLvl;
    switch (flags) {
    case Bidi.DIRECTION_LEFT_TO_RIGHT:
    default:
        paraLvl = Bidi.DIRECTION_LEFT_TO_RIGHT;
        break;
    case Bidi.DIRECTION_RIGHT_TO_LEFT:
        paraLvl = Bidi.DIRECTION_RIGHT_TO_LEFT;
        break;
    case Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT:
        paraLvl = INTERNAL_LEVEL_DEFAULT_LTR;
        break;
    case Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT:
        paraLvl = INTERNAL_LEVEL_DEFAULT_RTL;
        break;
    }
    byte[] paraEmbeddings;
    if (embeddings == null) {
        paraEmbeddings = null;
    } else {
        paraEmbeddings = new byte[paragraphLength];
        byte lev;
        for (int i = 0; i < paragraphLength; i++) {
            lev = embeddings[i + embStart];
            if (lev < 0) {
                lev = (byte)((- lev) | INTERNAL_LEVEL_OVERRIDE);
            } else if (lev == 0) {
                lev = paraLvl;
                if (paraLvl > MAX_EXPLICIT_LEVEL) {
                    lev &= 1;
                }
            }
            paraEmbeddings[i] = lev;
        }
    }
    if (textStart == 0 && embStart == 0 && paragraphLength == text.length) {
        setPara(text, paraLvl, paraEmbeddings);
    } else {
        char[] paraText = new char[paragraphLength];
        System.arraycopy(text, textStart, paraText, 0, paragraphLength);
        setPara(paraText, paraLvl, paraEmbeddings);
    }
}