java.text.Bidi
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ori_Argov
Posted On:   Saturday, July 19, 2003 04:08 PM

Does anyone has a better explanation than the API on how

to use this class?

I just have a line of text in logical order
(could be either RTL LTR or mixed) and I need to convert
it to visual order. What do the parameters to
reorderVisualy(..) mean?

Thanks,

Ori

Re: java.text.Bidi

Posted By:   Anonymous  
Posted On:   Sunday, October 12, 2003 06:30 AM

I would be hard-pressed to disprove the claim that the real purpose of this class was to have something around which IBM and Sun could write mystifying documentation. However, the class can indeed be meaningfully used.




The central parameter of method reorderVisually() is the Object array objects, which are to be reördered according to Bidi levels. This array could have been a String array, but it is possible to assign Bidi levels to things other than Strings. (These things could be Objects that wrap sets of chars, such as arrays or AttributedCharacterIterators; but they could actually be other things. This static method thus has a level of generality that does not characterize the rest of the class.)


In the case that objects is an array of Strings, these would typically have been got as substrings of a paragraph or somesuch which has been broken into parts by Bidi level. (The class has other methods for such analysis.)


The byte array levels is an array of Bidi levels to be assigned to the elements of objects. This array might have been geenrated in the process whereby the original paragraph was analyzed into subparts.


The reördering might not in fact be over the whole of objects, nor guided by the whole of levels. The int count tells how elements of objects are to be reördered. The int objectStart identifies the first element of objects to reörder. The int levelStart identifies the first element of levels to heed in reördering.




Here's how one might use the class:

/* String logicalText is in logical order. */
Bidi bidi = new Bidi(logicalText,
Bidi.DIRECTION_LEFT_TO_RIGHT);
int count = bidi.getRunCount();
byte[] levels = new byte[count];
int count = levels.length;
String[] objects = new String[count];
for (int i = 0; i < count; ++i)
{
levels[i] = (byte)bidi.getRunLevel(i);
object[i] = text.substring(bidi.getRunStart(i),
bidi.getRunLimit(i));
}
Bidi.reorderVisually(levels,0,objects,0,count);
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < count; ++i)
buffer.append(objects[i]);
String visualText = buffer.toString();
/* String visualText is in visual order. */
About | Sitemap | Contact