Java Code Examples for java.text.AttributedCharacterIterator#DONE
The following examples show how to use
java.text.AttributedCharacterIterator#DONE .
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: PdfGraphics2D.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * @see Graphics2D#drawString(AttributedCharacterIterator, float, float) */ @Override public void drawString( final AttributedCharacterIterator iter, float x, final float y ) { /* * StringBuffer sb = new StringBuffer(); for(char c = iter.first(); c != AttributedCharacterIterator.DONE; c = * iter.next()) { sb.append(c); } drawString(sb.toString(),x,y); */ final StringBuilder stringbuffer = new StringBuilder( iter.getEndIndex() ); for ( char c = iter.first(); c != AttributedCharacterIterator.DONE; c = iter.next() ) { if ( iter.getIndex() == iter.getRunStart() ) { if ( stringbuffer.length() > 0 ) { drawString( stringbuffer.toString(), x, y ); final FontMetrics fontmetrics = getFontMetrics(); x = (float) ( x + fontmetrics.getStringBounds( stringbuffer.toString(), this ).getWidth() ); stringbuffer.delete( 0, stringbuffer.length() ); } doAttributes( iter ); } stringbuffer.append( c ); } drawString( stringbuffer.toString(), x, y ); underline = false; }
Example 2
Source File: BidiBase.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 3
Source File: BidiBase.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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 4
Source File: BidiBase.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * 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 5
Source File: BidiBase.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * 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 6
Source File: BidiBase.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * 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 7
Source File: BidiBase.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 8
Source File: BidiBase.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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-source with GNU General Public License v2.0 | 4 votes |
/** * 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 10
Source File: BidiBase.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * 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: BidiBase.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 12
Source File: BidiBase.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 13
Source File: BidiBase.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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); }