Java Code Examples for com.ibm.icu.text.Bidi#DIRECTION_RIGHT_TO_LEFT

The following examples show how to use com.ibm.icu.text.Bidi#DIRECTION_RIGHT_TO_LEFT . 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: 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 2
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 3
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 4
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 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 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 7
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 8
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 9
Source File: BidiBase.java    From openjdk-8 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 10
Source File: BidiBase.java    From openjdk-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 11
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 12
Source File: BidiBase.java    From jdk8u-dev-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 13
Source File: BidiBase.java    From openjdk-jdk8u-backup 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 14
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 15
Source File: BidiBase.java    From openjdk-jdk8u-backup 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 16
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 17
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 18
Source File: BidiBase.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return true if the line is all right-to-left text, and the base direction
 * is right-to-left
 *
 * @return true if the line is all right-to-left text, and the base
 *         direction is right-to-left
 *
 * @throws IllegalStateException if this call is not preceded by a successful
 *         call to <code>setPara</code>
 * @stable ICU 3.8
 */
public boolean isRightToLeft()
{
    return (getDirection() == Bidi.DIRECTION_RIGHT_TO_LEFT && (paraLevel & 1) == 1);
}
 
Example 19
Source File: BidiBase.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return true if the line is all right-to-left text, and the base direction
 * is right-to-left
 *
 * @return true if the line is all right-to-left text, and the base
 *         direction is right-to-left
 *
 * @throws IllegalStateException if this call is not preceded by a successful
 *         call to <code>setPara</code>
 * @stable ICU 3.8
 */
public boolean isRightToLeft()
{
    return (getDirection() == Bidi.DIRECTION_RIGHT_TO_LEFT && (paraLevel & 1) == 1);
}
 
Example 20
Source File: BidiBase.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return true if the line is all right-to-left text, and the base direction
 * is right-to-left
 *
 * @return true if the line is all right-to-left text, and the base
 *         direction is right-to-left
 *
 * @throws IllegalStateException if this call is not preceded by a successful
 *         call to <code>setPara</code>
 * @stable ICU 3.8
 */
public boolean isRightToLeft()
{
    return (getDirection() == Bidi.DIRECTION_RIGHT_TO_LEFT && (paraLevel & 1) == 1);
}