org.eclipse.swt.custom
Class PrintRenderer

java.lang.Object
  |
  +--org.eclipse.swt.custom.StyledTextRenderer
        |
        +--org.eclipse.swt.custom.PrintRenderer

class PrintRenderer
extends StyledTextRenderer


Field Summary
(package private)  Hashtable bidiSegments
           
protected  Font boldFont
           
(package private)  Rectangle clientArea
           
(package private)  WrappedContent content
           
(package private)  GC gc
           
(package private)  Hashtable lineBackgrounds
           
(package private)  Hashtable lineStyles
           
(package private)  StyledTextContent logicalContent
           
protected  Font regularFont
           
 
Constructor Summary
(package private) PrintRenderer(Device device, Font regularFont, boolean isBidi, GC gc, StyledTextContent logicalContent, Hashtable lineBackgrounds, Hashtable lineStyles, Hashtable bidiSegments, int tabLength, Rectangle clientArea)
          Creates an instance of PrintRenderer.
 
Method Summary
(package private)  void calculateLineHeight()
          Calculates the line height and space width.
protected  void dispose()
          Disposes the resource created by the receiver.
protected  void disposeGC(GC gc)
          Do nothing.
(package private)  void drawLine(String line, int lineIndex, int paintY, GC gc, Color widgetBackground, Color widgetForeground, boolean clearBackground)
          Draws a line of text at the specified location.
protected  void drawLineSelectionBackground(String line, int lineOffset, StyleRange[] styles, int paintY, GC gc, StyledTextBidi bidi)
          Do not print the selection.
(package private)  StyleRange[] filterLineStyles(StyleRange[] styles)
          Filter the given style ranges based on the font style and return the unchanged styles only if there is at least one non-regular (e.g., bold) font.
protected  int[] getBidiSegments(int lineOffset, String lineText)
          Returns from cache the text segments that should be treated as if they had a different direction than the surrounding text.
protected  Rectangle getClientArea()
          Returns the printer client area.
protected  StyledTextContent getContent()
          Returns the StyledTextContent to use for line offset calculations.
protected  int getCurrentFontStyle()
          Return the font style that is currently set on the active gc.
(package private)  Device getDevice()
          Returns the Device that is being rendered on.
protected  GC getGC()
          Returns the printer GC to use for rendering and measuring.
protected  int getHorizontalPixel()
          Returns 0.
(package private)  int getLeftMargin()
          Method getLeftMargin.
protected  StyledTextEvent getLineBackgroundData(int lineOffset, String line)
          Return cached line background data.
(package private)  int getLineEndSpaceWidth()
          Returns the width in pixels of the space used to represent line delimiters.
(package private)  int getLineHeight()
          Returns the height in pixels of a line.
protected  StyledTextEvent getLineStyleData(int lineOffset, String line)
          Return cached line style background data.
(package private)  StyledTextEvent getLineStyleData(StyledTextEvent event, int lineOffset, String line)
          Returns the line style data for the specified line.
private  int getLogicalLineOffset(int visualLineOffset)
          Returns the start offset of the line at the given offset.
protected  Point getSelection()
          Selection is not printed.
(package private)  StyledTextBidi getStyledTextBidi(String lineText, int lineOffset, GC gc, StyleRange[] styles)
          Returns a StyledTextBidi object for the specified line.
protected  int getStyledTextWidth(String text, int textStartOffset, StyleRange[] lineStyles, int paintX, GC gc)
          Returns the width of the specified text segment.
(package private)  int getTextPosition(String text, int lineOffset, int length, StyleRange[] lineStyles, GC gc)
          Returns the x position of the character at the specified offset relative to the first character in the line.
(package private)  int getTextWidth(String text, int lineOffset, int startOffset, int length, StyleRange[] lineStyles, int startXOffset, GC gc)
          Returns the width of the specified text range.
(package private)  StyleRange[] getVisualLineStyleData(StyleRange[] logicalStyles, int lineOffset, int lineLength)
          Returns styles for the specified visual (wrapped) line.
protected  boolean getWordWrap()
          Printed content is always wrapped.
(package private)  boolean isBidi()
          Returns whether the widget is running on a bidi platform.
protected  boolean isFullLineSelection()
          Selection is not printed.
protected  StyleRange[] mergeSelectionLineStyles(StyleRange[] styles)
          Do not print the selection.
protected  void setCurrentFontStyle(int style)
          Set the font style that is set for the active gc.
(package private)  void setLineFont(GC gc, int style)
          Sets the font of the specified GC if it is not already set.
(package private)  void setTabLength(int tabLength)
          Calculates the width in pixel of a tab character
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logicalContent

StyledTextContent logicalContent

content

WrappedContent content

clientArea

Rectangle clientArea

gc

GC gc

lineBackgrounds

Hashtable lineBackgrounds

lineStyles

Hashtable lineStyles

bidiSegments

Hashtable bidiSegments

regularFont

protected Font regularFont

boldFont

protected Font boldFont
Constructor Detail

PrintRenderer

PrintRenderer(Device device,
              Font regularFont,
              boolean isBidi,
              GC gc,
              StyledTextContent logicalContent,
              Hashtable lineBackgrounds,
              Hashtable lineStyles,
              Hashtable bidiSegments,
              int tabLength,
              Rectangle clientArea)
Creates an instance of PrintRenderer.

Parameters:
device - Device to render on
regularFont - Font to use for regular (non-bold) text.
isBidi - true=bidi platform, false=no bidi platform.
gc - printer GC to use for rendering. There can be only one GC for each printer device at any given time.
logicalContent - StyledTextContent to print.
lineBackgrounds - line background colors to use during rendering.
lineStyles - line styles colors to use during rendering.
bidiSegments - bidi segments to use during rendering on bidi platforms.
tabLength - length in characters of a tab character
clientArea - the printer client area.
Method Detail

dispose

protected void dispose()
Disposes the resource created by the receiver.

Overrides:
dispose in class StyledTextRenderer

disposeGC

protected void disposeGC(GC gc)
Do nothing. PrintRenderer does not create GCs.

Specified by:
disposeGC in class StyledTextRenderer
Parameters:
gc - GC to dispose.
See Also:
StyledTextRenderer.disposeGC(org.eclipse.swt.graphics.GC)

drawLineSelectionBackground

protected void drawLineSelectionBackground(String line,
                                           int lineOffset,
                                           StyleRange[] styles,
                                           int paintY,
                                           GC gc,
                                           StyledTextBidi bidi)
Do not print the selection.

Specified by:
drawLineSelectionBackground in class StyledTextRenderer
Parameters:
line - the line to draw
lineOffset - offset of the first character in the line. Relative to the start of the document.
styles - line styles
paintY - y location to draw at
gc - GC to draw on
bidi - the bidi object to use for measuring and rendering text in bidi locales. null when not in bidi mode.
See Also:
StyledTextRenderer.drawLineSelectionBackground(java.lang.String, int, org.eclipse.swt.custom.StyleRange[], int, org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledTextBidi)

getBidiSegments

protected int[] getBidiSegments(int lineOffset,
                                String lineText)
Returns from cache the text segments that should be treated as if they had a different direction than the surrounding text.

Use cached data.

Specified by:
getBidiSegments in class StyledTextRenderer
Parameters:
lineOffset - offset of the first character in the line. 0 based from the beginning of the document.
Returns:
text segments that should be treated as if they had a different direction than the surrounding text. Only the start index of a segment is specified, relative to the start of the line. Always starts with 0 and ends with the line length.

getClientArea

protected Rectangle getClientArea()
Returns the printer client area.

Specified by:
getClientArea in class StyledTextRenderer
Returns:
the visible client area that can be used for rendering.
See Also:
StyledTextRenderer.getClientArea()

getContent

protected StyledTextContent getContent()
Returns the StyledTextContent to use for line offset calculations. This is the wrapped content, calculated in the constructor from the logical printing content.

Specified by:
getContent in class StyledTextRenderer
Returns:
the StyledTextContent to use for line offset calculations.

getGC

protected GC getGC()
Returns the printer GC to use for rendering and measuring. There can be only one GC for each printer device at any given time.

Specified by:
getGC in class StyledTextRenderer
Returns:
the printer GC to use for rendering and measuring.

getHorizontalPixel

protected int getHorizontalPixel()
Returns 0. Scrolling does not affect printing. Text is wrapped for printing.

Specified by:
getHorizontalPixel in class StyledTextRenderer
Returns:
0
See Also:
StyledTextRenderer.getHorizontalPixel()

getLogicalLineOffset

private int getLogicalLineOffset(int visualLineOffset)
Returns the start offset of the line at the given offset.

Parameters:
visualLineOffset - an offset that may be anywhere within a line.
Returns:
the start offset of the line at the given offset, relative to the start of the document.

getLineBackgroundData

protected StyledTextEvent getLineBackgroundData(int lineOffset,
                                                String line)
Return cached line background data.

Specified by:
getLineBackgroundData in class StyledTextRenderer
Parameters:
lineOffset - offset of the line start relative to the start of the content.
line - line to get line background data for
Returns:
line background data for the given line. may return null
See Also:
StyledTextRenderer.getLineBackgroundData(int, java.lang.String)

getLineStyleData

protected StyledTextEvent getLineStyleData(int lineOffset,
                                           String line)
Return cached line style background data.

Specified by:
getLineStyleData in class StyledTextRenderer
Parameters:
lineOffset - offset of the line start relative to the start of the content.
line - line to get line styles for
Returns:
line style data for the given line. Styles may start before line start and end after line end
See Also:
StyledTextRenderer.getLineStyleData(org.eclipse.swt.custom.StyledTextEvent, int, java.lang.String)

getSelection

protected Point getSelection()
Selection is not printed.

Specified by:
getSelection in class StyledTextRenderer
Returns:
Point(0,0)
See Also:
StyledTextRenderer.getSelection()

getStyledTextWidth

protected int getStyledTextWidth(String text,
                                 int textStartOffset,
                                 StyleRange[] lineStyles,
                                 int paintX,
                                 GC gc)
Returns the width of the specified text segment. Expands tabs to tab stops using the widget tab width.

Specified by:
getStyledTextWidth in class StyledTextRenderer
Parameters:
text - text to measure
textStartOffset - offset of the first character in text relative to the first character in the document
lineStyles - styles of the line
paintX - x location to start drawing at
gc - GC to measure with
Returns:
the width of the specified text segment.

mergeSelectionLineStyles

protected StyleRange[] mergeSelectionLineStyles(StyleRange[] styles)
Do not print the selection. Returns the styles that were passed into the method without modifications.

Specified by:
mergeSelectionLineStyles in class StyledTextRenderer
Parameters:
styles - the existing styles that the selection should be applied to.
Returns:
the same styles that were passed into the method.
See Also:
StyledTextRenderer#getSelectionLineStyles

getWordWrap

protected boolean getWordWrap()
Printed content is always wrapped.

Specified by:
getWordWrap in class StyledTextRenderer
Returns:
true
See Also:
StyledTextRenderer.getWordWrap()

isFullLineSelection

protected boolean isFullLineSelection()
Selection is not printed. Returns false.

Specified by:
isFullLineSelection in class StyledTextRenderer
Returns:
false
See Also:
StyledTextRenderer.isFullLineSelection()

calculateLineHeight

void calculateLineHeight()
Calculates the line height and space width.


drawLine

void drawLine(String line,
              int lineIndex,
              int paintY,
              GC gc,
              Color widgetBackground,
              Color widgetForeground,
              boolean clearBackground)
Draws a line of text at the specified location.

Parameters:
line - the line to draw
lineIndex - index of the line to draw
paintY - y location to draw at
gc - GC to draw on
widgetBackground - the widget background color. Used as the default rendering color.
widgetForeground - the widget foreground color. Used as the default rendering color.
clearBackground - true if the line background should be drawn explicitly.

filterLineStyles

StyleRange[] filterLineStyles(StyleRange[] styles)
Filter the given style ranges based on the font style and return the unchanged styles only if there is at least one non-regular (e.g., bold) font.

Parameters:
styles - styles that may contain font styles.
Returns:
null if the styles contain only regular font styles, the unchanged styles otherwise.

getCurrentFontStyle

protected int getCurrentFontStyle()
Return the font style that is currently set on the active gc. Font style cached for performance reasons.

Returns:
int SWT.BOLD, SWT.NORMAL

getDevice

Device getDevice()
Returns the Device that is being rendered on.

Returns:
the Device that is being rendered on.

getLeftMargin

int getLeftMargin()
Method getLeftMargin.

Returns:
int

getLineEndSpaceWidth

int getLineEndSpaceWidth()
Returns the width in pixels of the space used to represent line delimiters.

Returns:
the width in pixels of the space used to represent line delimiters.

getLineHeight

int getLineHeight()
Returns the height in pixels of a line.

Returns:
the height in pixels of a line.

getLineStyleData

StyledTextEvent getLineStyleData(StyledTextEvent event,
                                 int lineOffset,
                                 String line)
Returns the line style data for the specified line. The lineOffset and line may specify a segment of a logical line stored in the StyledTextContent of the widget. The returned styles are guaranteed to be at least partially on the segment.

Parameters:
event - the styles for the logical line
lineOffset - offset of the line start relative to the start of the content.
line - line to get line styles for
Returns:
line style data for the given line segment. Styles may start before line start and end after line end but are guaranteed to be at least partially on the line.

getStyledTextBidi

StyledTextBidi getStyledTextBidi(String lineText,
                                 int lineOffset,
                                 GC gc,
                                 StyleRange[] styles)
Returns a StyledTextBidi object for the specified line.

Parameters:
lineText - the line that the StyledTextBidi object should work on.
lineOffset - offset of the beginning of the line, relative to the beginning of the document
gc - GC to use when creating a new StyledTextBidi object.
styles - StyleRanges to use when creating a new StyledTextBidi object.
Returns:
a StyledTextBidi object for the specified line.

getTextPosition

int getTextPosition(String text,
                    int lineOffset,
                    int length,
                    StyleRange[] lineStyles,
                    GC gc)
Returns the x position of the character at the specified offset relative to the first character in the line. Expands tabs to tab stops using the widget tab width.

Parameters:
text - text to be measured.
lineOffset - offset of the first character in the line.
length - number of characters to measure. Tabs are counted as one character in this parameter.
gc - GC to use for measuring text
Returns:
x position of the character at the specified offset with tabs expanded to tab stops. 0 if the length is outside the specified text.

getTextWidth

int getTextWidth(String text,
                 int lineOffset,
                 int startOffset,
                 int length,
                 StyleRange[] lineStyles,
                 int startXOffset,
                 GC gc)
Returns the width of the specified text range. Expand tabs to tab stops using the widget tab width.

Parameters:
text - text to be measured.
lineOffset - offset of the first character in the line.
startOffset - offset of the character to start measuring and expand tabs.
length - number of characters to measure. Tabs are counted as one character in this parameter.
startXOffset - x position of "startOffset" in "text". Used for calculating tab stops
gc - GC to use for measuring text
Returns:
width of the text range with tabs expanded to tab stops or 0 if the startOffset or length is outside the specified text.

getVisualLineStyleData

StyleRange[] getVisualLineStyleData(StyleRange[] logicalStyles,
                                    int lineOffset,
                                    int lineLength)
Returns styles for the specified visual (wrapped) line.

Parameters:
logicalStyles - the styles for a logical (unwrapped) line
lineOffset - offset of the visual line
lineLength - length of the visual line
Returns:
styles in the logicalStyles array that are at least partially on the specified visual line.

isBidi

boolean isBidi()
Returns whether the widget is running on a bidi platform.

Returns:
true=the widget is running on a bidi platform, false=otherwise.

setCurrentFontStyle

protected void setCurrentFontStyle(int style)
Set the font style that is set for the active gc. Font style cached for performance reasons.

Parameters:
style - SWT.BOLD, SWT.NORMAL

setLineFont

void setLineFont(GC gc,
                 int style)
Sets the font of the specified GC if it is not already set.

Parameters:
gc - GC to set the font in
style - desired style of the font in gc. Can be one of SWT.NORMAL, SWT. BOLD

setTabLength

void setTabLength(int tabLength)
Calculates the width in pixel of a tab character

Parameters:
tabLength - number of space characters represented by a tab character.


comments?