org.eclipse.swt.custom
Class StyledTextBidi

java.lang.Object
  |
  +--org.eclipse.swt.custom.StyledTextBidi

class StyledTextBidi
extends Object


Field Summary
private  int[] bidiSegments
           
private  byte[] classBuffer
           
private  int[] dx
           
private  GC gc
           
private  char[] glyphBuffer
           
private  int[] order
           
private  int[] renderPositions
           
 
Constructor Summary
StyledTextBidi(GC gc, int tabWidth, String text, StyleRange[] ranges, Font boldFont, int[] offsets)
          Constructs an instance of this class for a line of text.
StyledTextBidi(GC gc, String text, int[] offsets)
          Constructs an instance of this class for a line of text.
 
Method Summary
(package private) static void addLanguageListener(Control control, Runnable runnable)
          Adds a listener that should be called when the user changes the keyboard layout for the specified window.
private  void calculateRenderPositions()
          Calculates render positions using the glyph distance values in the dx array.
private  void calculateTabStops(String text, int tabWidth)
          Calculate the line's tab stops and adjust the dx array to reflect the width of tab characters.
(package private)  void drawBidiText(int logicalStart, int length, int xOffset, int yOffset)
          Renders the specified text segment.
private  void drawGlyphs(int visualStart, int length, int x, int y)
          Renders a segment of glyphs.
(package private)  void fillBackground(int logicalStart, int length, int xOffset, int yOffset, int height)
          Fills a rectangle spanning the given logical range.
(package private)  int[] getCaretOffsetAndDirectionAtX(int x)
          Returns the offset and direction that will be used to position the caret for the given x location.
private  Vector getDirectionRuns(int logicalStart, int length)
          Returns the direction segments that are in the specified text range.
(package private) static int getKeyboardLanguageDirection()
          Answers the direction of the active keyboard language - either L2R or R2L.
(package private)  int getLigatureEndOffset(int offset)
          Returns the offset of the last character comprising a ligature.
(package private)  int getLigatureStartOffset(int offset)
          Returns the offset of the first character comprising a ligature.
private  int getLogicalOffset(int visualOffset)
          Returns the logical offset of the character at the specified visual offset.
(package private)  int getOffsetAtX(int x)
          Returns the offset of the character at the specified x location.
private  int[] getRenderIndexesFor(int start, int length)
          Returns the reordering indices that map between logical and visual index of characters in the specified range.
private  StyleRange[] getSegmentedRangesFor(StyleRange[] ranges)
          Break up the given ranges such that each range is fully contained within a bidi segment.
private  int getTextLength()
          Returns the number of characters in the line.
(package private)  int getTextPosition(int logicalOffset)
          Returns the x position at the specified offset in the line.
(package private)  int getTextPosition(int logicalOffset, int direction)
          Returns the x position at the specified offset in the line.
(package private)  int getTextWidth()
          Returns the width in pixels of the line.
private  int getVisualOffsetAtX(int x)
          Returns the visual offset of the character at the specified x location.
(package private) static boolean isBidiPlatform()
          Returns whether the current platform supports a bidi language.
(package private) static boolean isCharacterShaped(GC gc)
          Returns whether the font set in the specified gc supports character shaping.
(package private) static boolean isLigated(GC gc)
          Returns whether the font set in the specified gc contains ligatured glyphs.
(package private)  boolean isLocalNumber(int logicalIndex)
          Returns if the character at the given offset is a local number.
(package private)  boolean isRightToLeft(int logicalIndex)
          Returns the direction of the character at the specified index.
(package private)  boolean isRightToLeftInput(int logicalIndex)
          Returns the direction of the character at the specified index.
private  boolean isStartOfBidiSegment(int logicalIndex)
          Returns whether the specified index is the start of a user specified direction segment.
private  void prepareFontStyledText(String textline, int logicalStart, int length)
          Reorders and calculates render positions for the specified sub-line of text.
(package private)  void redrawRange(Control parent, int logicalStart, int length, int xOffset, int yOffset, int height)
          Redraws a rectangle spanning the given logical range.
(package private) static void removeLanguageListener(Control control)
          Removes the keyboard language listener for the specified window.
(package private)  void setKeyboardLanguage(int logicalIndex)
          Sets the keyboard language to match the codepage of the character at the specified offset.
 String toString()
          Returns a string representation of the receiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gc

private GC gc

bidiSegments

private int[] bidiSegments

renderPositions

private int[] renderPositions

order

private int[] order

dx

private int[] dx

classBuffer

private byte[] classBuffer

glyphBuffer

private char[] glyphBuffer
Constructor Detail

StyledTextBidi

public StyledTextBidi(GC gc,
                      int tabWidth,
                      String text,
                      StyleRange[] ranges,
                      Font boldFont,
                      int[] offsets)
Constructs an instance of this class for a line of text. The text is reordered to reflect how it will be displayed.

Parameters:
gc - the GC to use for rendering and measuring of this line.
tabWidth - tab width in number of spaces, used to calculate tab stops
text - line that bidi data should be calculated for
boldFont - font that bold text will be rendered in, needed for proper measuring of bold text segments.

StyledTextBidi

public StyledTextBidi(GC gc,
                      String text,
                      int[] offsets)
Constructs an instance of this class for a line of text. This constructor should be used when only ordering (not rendering) information is needed. Only the class and order arrays will be filled during this call.

Parameters:
gc - the GC to use for rendering and measuring of this line.
text - line that bidi data should be calculated for
Method Detail

addLanguageListener

static void addLanguageListener(Control control,
                                Runnable runnable)
Adds a listener that should be called when the user changes the keyboard layout for the specified window.

Parameters:
control - Control to add the keyboard language listener for. Each window has its own keyboard language setting.
runnable - the listener that should be called when the user changes the keyboard layout.

getKeyboardLanguageDirection

static int getKeyboardLanguageDirection()
Answers the direction of the active keyboard language - either L2R or R2L. The active keyboard language determines the direction of the caret and can be changed by the user (e.g., via Alt-Shift on Win32 platforms).

Returns:
the direction of the active keyboard language. SWT.LEFT (for L2R language) or SWT.RIGHT (for R2L language) or SWT.DEFAULT if no R2L languages are installed.

isBidiPlatform

static boolean isBidiPlatform()
Returns whether the current platform supports a bidi language.

Returns:
true=bidi is supported, false otherwise.

isCharacterShaped

static boolean isCharacterShaped(GC gc)
Returns whether the font set in the specified gc supports character shaping.

Parameters:
gc - the GC that should be tested for character shaping.
Returns:
true=the font set in the specified gc supports character shaped glyphs false=the font set in the specified gc doesn't support character shaped glyphs

isLigated

static boolean isLigated(GC gc)
Returns whether the font set in the specified gc contains ligatured glyphs.

Parameters:
gc - the GC that should be tested for ligatures.
Returns:
true=the font set in the specified gc contains ligatured glyphs. false=the font set in the specified gc doesn't contain ligatured glyphs.

removeLanguageListener

static void removeLanguageListener(Control control)
Removes the keyboard language listener for the specified window.

Parameters:
control - window to remove the keyboard language listener from.

calculateRenderPositions

private void calculateRenderPositions()
Calculates render positions using the glyph distance values in the dx array.


calculateTabStops

private void calculateTabStops(String text,
                               int tabWidth)
Calculate the line's tab stops and adjust the dx array to reflect the width of tab characters.

Parameters:
text - the original line text (not reordered) containing tab characters.
tabWidth - number of pixels that one tab character represents

drawBidiText

void drawBidiText(int logicalStart,
                  int length,
                  int xOffset,
                  int yOffset)
Renders the specified text segment. All text is rendered L2R regardless of the direction of the text. The rendered text may be visually discontiguous if the text segment is bidirectional.

Parameters:
logicalStart - start offset in the logical text
length - number of logical characters to render
xOffset - x location of the line start
yOffset - y location of the line start

drawGlyphs

private void drawGlyphs(int visualStart,
                        int length,
                        int x,
                        int y)
Renders a segment of glyphs. Glyphs are visual objects so the start and length are visual as well. Glyphs are always rendered L2R.

Parameters:
visualStart - start offset of the glyphs to render relative to the line start.
length - number of glyphs to render
x - x location to render at
y - y location to render at

fillBackground

void fillBackground(int logicalStart,
                    int length,
                    int xOffset,
                    int yOffset,
                    int height)
Fills a rectangle spanning the given logical range. The rectangle may be visually discontiguous if the text segment is bidirectional.

Parameters:
logicalStart - logcial start offset of the rectangle
length - number of logical characters the rectangle should span
xOffset - x location of the line start
yOffset - y location of the line start
height - height of the rectangle

getCaretOffsetAndDirectionAtX

int[] getCaretOffsetAndDirectionAtX(int x)
Returns the offset and direction that will be used to position the caret for the given x location. The caret will be placed in front of or behind the character at location x depending on what type of character (i.e., R2L or L2R) is at location x. This method is used for positioning the caret when a mouse click occurs within the widget.

Parameters:
x - the x location of the character in the line.
Returns:
array containing the caret offset and direction for the x location. index 0: offset relative to the start of the line index 1: direction, either ST.COLUMN_NEXT or ST.COLUMN_PREVIOUS. The direction is used to control the caret position at direction boundaries. The semantics follow the behavior for keyboard cursor navigation. Example: RRRLLL Pressing cursor left (COLUMN_PREVIOUS) in the L2R segment places the cursor in front of the first character of the L2R segment. Pressing cursor right (COLUMN_NEXT) in a R2L segment places the cursor behind the last character of the R2L segment. However, both are the same logical offset.

getDirectionRuns

private Vector getDirectionRuns(int logicalStart,
                                int length)
Returns the direction segments that are in the specified text range. The text range may be visually discontiguous if the text is bidirectional. Each returned direction run has a single direction and the runs all go from left to right, regardless of the direction of the text in the segment. User specified segments (via BidiSegmentListener) are taken into account and result in separate direction runs.

Parameters:
logicalStart - offset of the logcial start of the first direction segment
length - length of the text included in the direction segments
Returns:
the direction segments that are in the specified text range, each segment has a single direction.

getLigatureEndOffset

int getLigatureEndOffset(int offset)
Returns the offset of the last character comprising a ligature.

Parameters:
offset - the logical offset of a character that may be a ligature.
Returns:
the offset of the last character comprising a ligature.

getLigatureStartOffset

int getLigatureStartOffset(int offset)
Returns the offset of the first character comprising a ligature.

Parameters:
offset - the logical offset of a character that may be a ligature.
Returns:
the offset of the first character comprising a ligature.

getLogicalOffset

private int getLogicalOffset(int visualOffset)
Returns the logical offset of the character at the specified visual offset.

Parameters:
visualOffset - the visual offset
Returns:
the logical offset of the character at visualOffset.

getOffsetAtX

int getOffsetAtX(int x)
Returns the offset of the character at the specified x location.

Parameters:
x - the location of the character
Returns:
the logical offset of the character at the specified x location.

getRenderIndexesFor

private int[] getRenderIndexesFor(int start,
                                  int length)
Returns the reordering indices that map between logical and visual index of characters in the specified range.

Parameters:
start - start offset of the reordering indices
length - number of reordering indices to return
Returns:
the reordering indices that map between logical and visual index of characters in the specified range. Relative to the start of the range.

getSegmentedRangesFor

private StyleRange[] getSegmentedRangesFor(StyleRange[] ranges)
Break up the given ranges such that each range is fully contained within a bidi segment.


getTextLength

private int getTextLength()
Returns the number of characters in the line.

Returns:
the number of characters in the line.

getTextPosition

int getTextPosition(int logicalOffset)
Returns the x position at the specified offset in the line.

Parameters:
logicalOffset - offset of the character in the line.
Returns:
the x position at the specified offset in the line.

getTextPosition

int getTextPosition(int logicalOffset,
                    int direction)
Returns the x position at the specified offset in the line. The direction parameter is used to determine the position at direction boundaries. If the logical offset is between a R2L and a L2R segment, pressing cursor left in the L2R segment places the position in front of the first character of the L2R segment; whereas pressing cursor right in the R2L segment places the position behind the last character of the R2L segment. However, both x positions are at the same logical offset.

Parameters:
logicalOffset - offset of the character in the line
direction - direction the caret moved to the specified location. either ST.COLUMN_NEXT (right cursor key) or ST.COLUMN_PREVIOUS (left cursor key) .
Returns:
the x position at the specified offset in the line, taking the direction into account as described above.

getTextWidth

int getTextWidth()
Returns the width in pixels of the line.

Returns:
the width in pixels of the line.

getVisualOffsetAtX

private int getVisualOffsetAtX(int x)
Returns the visual offset of the character at the specified x location.

Parameters:
x - the location of the character
Returns:
the visual offset of the character at the specified x location.

isLocalNumber

boolean isLocalNumber(int logicalIndex)
Returns if the character at the given offset is a local number.

Parameters:
logicalIndex - the index of the character
Returns:
true=the character at the specified index is a local number false=the character at the specified index is not a local number

isRightToLeft

boolean isRightToLeft(int logicalIndex)
Returns the direction of the character at the specified index. Used for rendering and caret positioning where local numbers (e.g., national Arabic, or Hindi, numbers) are considered left-to-right.

Parameters:
logicalIndex - the index of the character
Returns:
true=the character at the specified index is in a right-to-left codepage (e.g., Hebrew, Arabic). false=the character at the specified index is in a left-to-right/latin codepage.

isRightToLeftInput

boolean isRightToLeftInput(int logicalIndex)
Returns the direction of the character at the specified index. Used for setting the keyboard language where local numbers (e.g., national Arabic, or Hindi, numbers) are considered right-to-left.

Parameters:
logicalIndex - the index of the character
Returns:
true=the character at the specified index is in a right-to-left codepage (e.g., Hebrew, Arabic). false=the character at the specified index is in a left-to-right/latin codepage.

isStartOfBidiSegment

private boolean isStartOfBidiSegment(int logicalIndex)
Returns whether the specified index is the start of a user specified direction segment.

Parameters:
logicalIndex - the index to test
Returns:
true=the specified index is the start of a user specified direction segment, false otherwise

prepareFontStyledText

private void prepareFontStyledText(String textline,
                                   int logicalStart,
                                   int length)
Reorders and calculates render positions for the specified sub-line of text. The results will be merged with the data for the rest of the line .

Parameters:
textline - the entire line of text that this object represents.
logicalStart - the start offset of the first character to reorder.
length - the number of characters to reorder

redrawRange

void redrawRange(Control parent,
                 int logicalStart,
                 int length,
                 int xOffset,
                 int yOffset,
                 int height)
Redraws a rectangle spanning the given logical range. The rectangle may be visually discontiguous if the text segment is bidirectional.

Parameters:
parent - window that should be invalidated
logicalStart - logcial start offset of the rectangle
length - number of logical characters the rectangle should span
xOffset - x location of the line start
yOffset - y location of the line start
height - height of the invalidated rectangle

setKeyboardLanguage

void setKeyboardLanguage(int logicalIndex)
Sets the keyboard language to match the codepage of the character at the specified offset. Only distinguishes between left-to-right and right-to-left characters and sets the keyboard language to a bidi or non-bidi language.

Parameters:
logicalIndex - logical offset of the character to use for determining the new keyboard language.

toString

public String toString()
Returns a string representation of the receiver.

Overrides:
toString in class Object
Returns:
a string representation of the receiver for debugging purposes. The output order of the StyledTextbidi values is as follows: order, render position, dx, character class, glyphs.


comments?