### Eclipse Workspace Patch 1.0 #P org.eclipse.draw2d Index: src/org/eclipse/draw2d/text/BidiProcessor.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/text/BidiProcessor.java,v retrieving revision 1.24 diff -u -r1.24 BidiProcessor.java --- src/org/eclipse/draw2d/text/BidiProcessor.java 14 Feb 2011 20:49:17 -0000 1.24 +++ src/org/eclipse/draw2d/text/BidiProcessor.java 31 Mar 2011 15:34:08 -0000 @@ -10,10 +10,13 @@ *******************************************************************************/ package org.eclipse.draw2d.text; +import com.ibm.icu.text.ArabicShaping; +import com.ibm.icu.text.ArabicShapingException; import com.ibm.icu.text.Bidi; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.TextLayout; @@ -185,6 +188,61 @@ return begin > 0 && isJoiningCharacter(bidiText.charAt(begin - 1)); } + public String normalizeDigits(String text) { + ArabicShaping shaper; + if (text == null) + return text; + // Normalize the numbers + shaper = new ArabicShaping(ArabicShaping.DIGITS_AN2EN); + try { + text = shaper.shape(text); + + } catch (ArabicShapingException e) { + e.printStackTrace(); + } + return text; + } + + /** + * if the system locale is Arabic and the selected digit substitution that + * is contextual then apply contextual numeral shaping + */ + public String shapeArabicDigitsContextually(String text) { + + return shapeArabicDigitsContextually(text, orientation); + } + + public String shapeArabicDigitsContextually(String text, int orient) { + ArabicShaping shaper; + if (text == null) + return text; + if (!Bidi.requiresBidi(text.toCharArray(), 0, text.length() - 1)) + return text; + + // Normalize the numbers + text = normalizeDigits(text); + + TextLayout layout = FlowUtilities.getTextLayout(); + // if locale is not Arabic, then no need to perform contextual numeral + // shaping + if (!(Locale.getDefault()).getLanguage().equalsIgnoreCase("ar")) //$NON-NLS-1$ + return text; + + if (layout.isContextDigitSubistitution()) { + if (orient == SWT.RIGHT_TO_LEFT) + shaper = new ArabicShaping(ArabicShaping.DIGITS_EN2AN_INIT_AL); + else + shaper = new ArabicShaping(ArabicShaping.DIGITS_EN2AN_INIT_LR); + try { + + text = shaper.shape(text); + } catch (ArabicShapingException e) { + e.printStackTrace(); + } + } + return text; + } + /** * Processes the contributed text, determines the Bidi levels, and assigns * them to the FlowFigures that made thet contributions. This class is for @@ -197,6 +255,7 @@ try { if (bidiText.length() == 0) return; + bidiText = new StringBuffer(normalizeDigits(bidiText.toString())); char[] chars = new char[bidiText.length()]; bidiText.getChars(0, bidiText.length(), chars, 0); Index: src/org/eclipse/draw2d/text/TextFlow.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/text/TextFlow.java,v retrieving revision 1.62 diff -u -r1.62 TextFlow.java --- src/org/eclipse/draw2d/text/TextFlow.java 19 May 2010 20:28:20 -0000 1.62 +++ src/org/eclipse/draw2d/text/TextFlow.java 31 Mar 2011 15:34:09 -0000 @@ -502,6 +502,8 @@ * @return the String being displayed; will not be null */ public String getText() { + // Applying Numeral shaping if needed + text = BidiProcessor.INSTANCE.shapeArabicDigitsContextually(text); return text; }