<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FSWT%2FPrint</id>
		<title>Java Tutorial/SWT/Print - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FSWT%2FPrint"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/SWT/Print&amp;action=history"/>
		<updated>2026-04-21T15:47:56Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/SWT/Print&amp;diff=3209&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/SWT/Print&amp;diff=3209&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:26Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 17:44, 31 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/SWT/Print&amp;diff=3210&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/SWT/Print&amp;diff=3210&amp;oldid=prev"/>
				<updated>2010-05-31T15:22:05Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== 17. Get the entire printable area of the page for the selected printer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.printing.PrintDialog;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Display display = new Display();&lt;br /&gt;
    Shell shell = new Shell(display);&lt;br /&gt;
    PrintDialog dlg = new PrintDialog(shell);&lt;br /&gt;
    &lt;br /&gt;
    dlg.setScope(PrinterData.SELECTION);&lt;br /&gt;
    &lt;br /&gt;
    PrinterData printerData = dlg.open();&lt;br /&gt;
    if (printerData != null) {&lt;br /&gt;
       Printer printer = new Printer(printerData);&lt;br /&gt;
       System.out.println(printer.getClientArea());&lt;br /&gt;
       printer.dispose();&lt;br /&gt;
    }&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch()) {&lt;br /&gt;
        display.sleep();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Place one-inch margins on the page ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;If you need centimeters instead of inches, &lt;br /&gt;
multiply each inch value by 2.54 to get the number of centimeters.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.graphics.Point;&lt;br /&gt;
import org.eclipse.swt.graphics.Rectangle;&lt;br /&gt;
import org.eclipse.swt.printing.PrintDialog;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Display display = new Display();&lt;br /&gt;
    Shell shell = new Shell(display);&lt;br /&gt;
    PrintDialog dlg = new PrintDialog(shell);&lt;br /&gt;
    dlg.setScope(PrinterData.SELECTION);&lt;br /&gt;
    PrinterData printerData = dlg.open();&lt;br /&gt;
    if (printerData != null) {&lt;br /&gt;
      Printer printer = new Printer(printerData);&lt;br /&gt;
      System.out.println(printer.getClientArea());&lt;br /&gt;
      Point dpi = printer.getDPI(); // Get the DPI&lt;br /&gt;
      Rectangle rect = printer.getClientArea(); // Get the printable area&lt;br /&gt;
      Rectangle trim = printer.ruputeTrim(0, 0, 0, 0); // Get the whole page&lt;br /&gt;
      int left = trim.x + dpi.x; // Set left margin one inch from left side of paper&lt;br /&gt;
      int top = trim.y + dpi.y; // Set top margin&lt;br /&gt;
      int right = (rect.width + trim.x + trim.width) - dpi.x; // 1st three&lt;br /&gt;
                                                              // values give&lt;br /&gt;
      // you the right side of the page&lt;br /&gt;
      int bottom = (rect.height + trim.y + trim.height) - dpi.y; // Set bottom&lt;br /&gt;
                                                                  // margin&lt;br /&gt;
      // use left, top, right, and bottom as the boundaries that govern where&lt;br /&gt;
      // you draw on the page.&lt;br /&gt;
      printer.dispose();&lt;br /&gt;
    }&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch()) {&lt;br /&gt;
        display.sleep();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Print DPI ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.graphics.Point;&lt;br /&gt;
import org.eclipse.swt.graphics.Rectangle;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class PrinterDPI{&lt;br /&gt;
public static void main (String [] args) {&lt;br /&gt;
  Display display = new Display();&lt;br /&gt;
  Shell shell = new Shell(display);&lt;br /&gt;
  shell.open ();&lt;br /&gt;
  PrinterData data = Printer.getDefaultPrinterData();&lt;br /&gt;
  if (data == null) {&lt;br /&gt;
    return;&lt;br /&gt;
  }&lt;br /&gt;
  Printer printer = new Printer(data);&lt;br /&gt;
  if (printer.startJob(&amp;quot;SWT Printing Snippet&amp;quot;)) {&lt;br /&gt;
    Rectangle trim = printer.ruputeTrim(0, 0, 0, 0);&lt;br /&gt;
    Point dpi = printer.getDPI();&lt;br /&gt;
    System.out.println(trim);&lt;br /&gt;
    System.out.println(dpi);&lt;br /&gt;
    printer.endJob();&lt;br /&gt;
    }&lt;br /&gt;
  printer.dispose();&lt;br /&gt;
  while (!shell.isDisposed ()) {&lt;br /&gt;
    if (!display.readAndDispatch ()) display.sleep ();&lt;br /&gt;
  }&lt;br /&gt;
  display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Printing ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;Printer, PrinterData and PrintDialog are three main classes related to Printing.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Printer descends from Device. &lt;br /&gt;
You can create a graphical context from it and draw on the graphical context.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
public class DrawTextToPrint {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Printer printer = new Printer();&lt;br /&gt;
    if (printer.startJob(&amp;quot;Printing . . .&amp;quot;)) {&lt;br /&gt;
      GC gc = new GC(printer);&lt;br /&gt;
      if (printer.startPage()) {&lt;br /&gt;
        gc.drawText(&amp;quot;Hello, World!&amp;quot;, 20, 20);&lt;br /&gt;
        printer.endPage();&lt;br /&gt;
      }&lt;br /&gt;
      gc.dispose();&lt;br /&gt;
    }&lt;br /&gt;
    printer.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Printing Graphics ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;scale any images according to the printer&amp;quot;s DPI to fit the page.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.graphics.Image;&lt;br /&gt;
import org.eclipse.swt.graphics.ImageData;&lt;br /&gt;
import org.eclipse.swt.graphics.Point;&lt;br /&gt;
import org.eclipse.swt.graphics.Rectangle;&lt;br /&gt;
import org.eclipse.swt.printing.PrintDialog;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Display display = new Display();&lt;br /&gt;
    Shell shell = new Shell(display);&lt;br /&gt;
    Image image = new Image(display, &amp;quot;fileName.gif&amp;quot;);&lt;br /&gt;
    ImageData imageData = image.getImageData();&lt;br /&gt;
    PrintDialog dialog = new PrintDialog(shell, SWT.NULL);&lt;br /&gt;
    PrinterData printerData = dialog.open();&lt;br /&gt;
    Printer printer = new Printer(printerData);&lt;br /&gt;
    Point screenDPI = display.getDPI();&lt;br /&gt;
    Point printerDPI = printer.getDPI();&lt;br /&gt;
    int scaleFactor = printerDPI.x / screenDPI.x;&lt;br /&gt;
    Rectangle trim = printer.ruputeTrim(0, 0, 0, 0);&lt;br /&gt;
    if (printer.startJob(&amp;quot;fileName&amp;quot;)) {&lt;br /&gt;
      if (printer.startPage()) {&lt;br /&gt;
        GC gc = new GC(printer);&lt;br /&gt;
        Image printerImage = new Image(printer, imageData);&lt;br /&gt;
        // Draw the image&lt;br /&gt;
        gc.drawImage(printerImage, 0, 0, imageData.width, imageData.height, -trim.x, -trim.y,&lt;br /&gt;
            scaleFactor * imageData.width, scaleFactor * imageData.height);&lt;br /&gt;
        // Clean up&lt;br /&gt;
        printerImage.dispose();&lt;br /&gt;
        gc.dispose();&lt;br /&gt;
        printer.endPage();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    // End the job and dispose the printer&lt;br /&gt;
    printer.endJob();&lt;br /&gt;
    printer.dispose();&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch()) {&lt;br /&gt;
        display.sleep();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Printing Text ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Use GC.drawString() or GC.drawText() to print text.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;wrap text on word boundaries to fit the target printer and page.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.graphics.Point;&lt;br /&gt;
import org.eclipse.swt.graphics.Rectangle;&lt;br /&gt;
import org.eclipse.swt.printing.PrintDialog;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.MessageBox;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Display display = new Display();&lt;br /&gt;
    Shell shell = new Shell(display);&lt;br /&gt;
    PrintDialog dialog = new PrintDialog(shell);&lt;br /&gt;
    PrinterData printerData = dialog.open();&lt;br /&gt;
    if (printerData != null) {&lt;br /&gt;
      // Create the printer&lt;br /&gt;
      Printer printer = new Printer(printerData);&lt;br /&gt;
      try {&lt;br /&gt;
        // Print the contents of the file&lt;br /&gt;
        new WrappingPrinter(printer).print();&lt;br /&gt;
      } catch (Exception e) {&lt;br /&gt;
        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);&lt;br /&gt;
        mb.setMessage(e.getMessage());&lt;br /&gt;
        mb.open();&lt;br /&gt;
      }&lt;br /&gt;
      // Dispose the printer&lt;br /&gt;
      printer.dispose();&lt;br /&gt;
    }&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch()) {&lt;br /&gt;
        display.sleep();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/**&lt;br /&gt;
 * This class performs the printing, wrapping text as necessary Code revised&lt;br /&gt;
 * from /* The Definitive Guide to SWT and JFace by Robert Harris and Rob Warner&lt;br /&gt;
 * Apress 2004&lt;br /&gt;
 */&lt;br /&gt;
class WrappingPrinter {&lt;br /&gt;
  private Printer printer; // The printer&lt;br /&gt;
  private String fileName; // The name of the file to print&lt;br /&gt;
  private String contents; // The contents of the file to print&lt;br /&gt;
  private GC gc; // The GC to print on&lt;br /&gt;
  private int xPos, yPos; // The current x and y locations for print&lt;br /&gt;
  private Rectangle bounds; // The boundaries for the print&lt;br /&gt;
  private StringBuffer buf; // Holds a word at a time&lt;br /&gt;
  private int lineHeight; // The height of a line of text&lt;br /&gt;
  /**&lt;br /&gt;
   * WrappingPrinter constructor&lt;br /&gt;
   * &lt;br /&gt;
   * @param printer&lt;br /&gt;
   *          the printer&lt;br /&gt;
   * @param fileName&lt;br /&gt;
   *          the fileName&lt;br /&gt;
   * @param contents&lt;br /&gt;
   *          the contents&lt;br /&gt;
   */&lt;br /&gt;
  WrappingPrinter(Printer printer) {&lt;br /&gt;
    this.printer = printer;&lt;br /&gt;
    this.fileName = &amp;quot;yourfilename.txt&amp;quot;;&lt;br /&gt;
    this.contents = &amp;quot;long content to wrap&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Prints the file&lt;br /&gt;
   */&lt;br /&gt;
  void print() {&lt;br /&gt;
    // Start the print job&lt;br /&gt;
    if (printer.startJob(fileName)) {&lt;br /&gt;
      // Determine print area, with margins&lt;br /&gt;
      bounds = computePrintArea(printer);&lt;br /&gt;
      xPos = bounds.x;&lt;br /&gt;
      yPos = bounds.y;&lt;br /&gt;
      // Create the GC&lt;br /&gt;
      gc = new GC(printer);&lt;br /&gt;
      // Determine line height&lt;br /&gt;
      lineHeight = gc.getFontMetrics().getHeight();&lt;br /&gt;
      // Determine tab width--use three spaces for tabs&lt;br /&gt;
      int tabWidth = gc.stringExtent(&amp;quot; &amp;quot;).x;&lt;br /&gt;
      // Print the text&lt;br /&gt;
      printer.startPage();&lt;br /&gt;
      buf = new StringBuffer();&lt;br /&gt;
      char c;&lt;br /&gt;
      for (int i = 0, n = contents.length(); i &amp;lt; n; i++) {&lt;br /&gt;
        // Get the next character&lt;br /&gt;
        c = contents.charAt(i);&lt;br /&gt;
        // Check for newline&lt;br /&gt;
        if (c == &amp;quot;\n&amp;quot;) {&lt;br /&gt;
          printBuffer();&lt;br /&gt;
          printNewline();&lt;br /&gt;
        }&lt;br /&gt;
        // Check for tab&lt;br /&gt;
        else if (c == &amp;quot;\t&amp;quot;) {&lt;br /&gt;
          xPos += tabWidth;&lt;br /&gt;
        } else {&lt;br /&gt;
          buf.append(c);&lt;br /&gt;
          // Check for space&lt;br /&gt;
          if (Character.isWhitespace(c)) {&lt;br /&gt;
            printBuffer();&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      printer.endPage();&lt;br /&gt;
      printer.endJob();&lt;br /&gt;
      gc.dispose();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Prints the contents of the buffer&lt;br /&gt;
   */&lt;br /&gt;
  void printBuffer() {&lt;br /&gt;
    // Get the width of the rendered buffer&lt;br /&gt;
    int width = gc.stringExtent(buf.toString()).x;&lt;br /&gt;
    // Determine if it fits&lt;br /&gt;
    if (xPos + width &amp;gt; bounds.x + bounds.width) {&lt;br /&gt;
      // Doesn&amp;quot;t fit--wrap&lt;br /&gt;
      printNewline();&lt;br /&gt;
    }&lt;br /&gt;
    // Print the buffer&lt;br /&gt;
    gc.drawString(buf.toString(), xPos, yPos, false);&lt;br /&gt;
    xPos += width;&lt;br /&gt;
    buf.setLength(0);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Prints a newline&lt;br /&gt;
   */&lt;br /&gt;
  void printNewline() {&lt;br /&gt;
    // Reset x and y locations to next line&lt;br /&gt;
    xPos = bounds.x;&lt;br /&gt;
    yPos += lineHeight;&lt;br /&gt;
    // Have we gone to the next page?&lt;br /&gt;
    if (yPos &amp;gt; bounds.y + bounds.height) {&lt;br /&gt;
      yPos = bounds.y;&lt;br /&gt;
      printer.endPage();&lt;br /&gt;
      printer.startPage();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Computes the print area, including margins&lt;br /&gt;
   * &lt;br /&gt;
   * @param printer&lt;br /&gt;
   *          the printer&lt;br /&gt;
   * @return Rectangle&lt;br /&gt;
   */&lt;br /&gt;
  Rectangle computePrintArea(Printer printer) {&lt;br /&gt;
    // Get the printable area&lt;br /&gt;
    Rectangle rect = printer.getClientArea();&lt;br /&gt;
    // Compute the trim&lt;br /&gt;
    Rectangle trim = printer.ruputeTrim(0, 0, 0, 0);&lt;br /&gt;
    // Get the printer&amp;quot;s DPI&lt;br /&gt;
    Point dpi = printer.getDPI();&lt;br /&gt;
    // Calculate the printable area, using 1 inch margins&lt;br /&gt;
    int left = trim.x + dpi.x;&lt;br /&gt;
    if (left &amp;lt; rect.x)&lt;br /&gt;
      left = rect.x;&lt;br /&gt;
    int right = (rect.width + trim.x + trim.width) - dpi.x;&lt;br /&gt;
    if (right &amp;gt; rect.width)&lt;br /&gt;
      right = rect.width;&lt;br /&gt;
    int top = trim.y + dpi.y;&lt;br /&gt;
    if (top &amp;lt; rect.y)&lt;br /&gt;
      top = rect.y;&lt;br /&gt;
    int bottom = (rect.height + trim.y + trim.height) - dpi.y;&lt;br /&gt;
    if (bottom &amp;gt; rect.height)&lt;br /&gt;
      bottom = rect.height;&lt;br /&gt;
    return new Rectangle(left, top, right - left, bottom - top);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Print out String ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.graphics.Color;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
public class StringPrint {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    Display display = new Display();&lt;br /&gt;
    Shell shell = new Shell(display);&lt;br /&gt;
    shell.open();&lt;br /&gt;
    PrinterData data = Printer.getDefaultPrinterData();&lt;br /&gt;
    if (data == null) {&lt;br /&gt;
      System.out.println(&amp;quot;Warning: No default printer.&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    Printer printer = new Printer(data);&lt;br /&gt;
    if (printer.startJob(&amp;quot;SWT Printing Snippet&amp;quot;)) {&lt;br /&gt;
      Color black = printer.getSystemColor(SWT.COLOR_BLACK);&lt;br /&gt;
      GC gc = new GC(printer);&lt;br /&gt;
      if (printer.startPage()) {&lt;br /&gt;
        gc.setForeground(black);&lt;br /&gt;
        String testString = &amp;quot;Hello World!&amp;quot;;&lt;br /&gt;
        gc.drawString(testString, 200, 200);&lt;br /&gt;
        printer.endPage();&lt;br /&gt;
      }&lt;br /&gt;
      gc.dispose();&lt;br /&gt;
      printer.endJob();&lt;br /&gt;
    }&lt;br /&gt;
    printer.dispose();&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch())&lt;br /&gt;
        display.sleep();&lt;br /&gt;
    }&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== 17. Print text to printer, with word wrap and pagination ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/*******************************************************************************&lt;br /&gt;
 * Copyright (c) 2000, 2004 IBM Corporation and others.&lt;br /&gt;
 * All rights reserved. This program and the accompanying materials&lt;br /&gt;
 * are made available under the terms of the Eclipse Public License v1.0&lt;br /&gt;
 * which accompanies this distribution, and is available at&lt;br /&gt;
 * http://www.eclipse.org/legal/epl-v10.html&lt;br /&gt;
 *&lt;br /&gt;
 * Contributors:&lt;br /&gt;
 *     IBM Corporation - initial API and implementation&lt;br /&gt;
 *******************************************************************************/&lt;br /&gt;
//package org.eclipse.swt.snippets;&lt;br /&gt;
/*&lt;br /&gt;
 * Printing example snippet: print text to printer, with word wrap and pagination&lt;br /&gt;
 *&lt;br /&gt;
 * For a list of all SWT example snippets see&lt;br /&gt;
 * http://www.eclipse.org/swt/snippets/&lt;br /&gt;
 */&lt;br /&gt;
import java.io.BufferedReader;&lt;br /&gt;
import java.io.File;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileNotFoundException;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStreamReader;&lt;br /&gt;
import java.io.Reader;&lt;br /&gt;
import org.eclipse.swt.SWT;&lt;br /&gt;
import org.eclipse.swt.events.SelectionAdapter;&lt;br /&gt;
import org.eclipse.swt.events.SelectionEvent;&lt;br /&gt;
import org.eclipse.swt.graphics.Color;&lt;br /&gt;
import org.eclipse.swt.graphics.Font;&lt;br /&gt;
import org.eclipse.swt.graphics.FontData;&lt;br /&gt;
import org.eclipse.swt.graphics.GC;&lt;br /&gt;
import org.eclipse.swt.graphics.Point;&lt;br /&gt;
import org.eclipse.swt.graphics.RGB;&lt;br /&gt;
import org.eclipse.swt.graphics.Rectangle;&lt;br /&gt;
import org.eclipse.swt.layout.FillLayout;&lt;br /&gt;
import org.eclipse.swt.printing.PrintDialog;&lt;br /&gt;
import org.eclipse.swt.printing.Printer;&lt;br /&gt;
import org.eclipse.swt.printing.PrinterData;&lt;br /&gt;
import org.eclipse.swt.widgets.ColorDialog;&lt;br /&gt;
import org.eclipse.swt.widgets.Display;&lt;br /&gt;
import org.eclipse.swt.widgets.FileDialog;&lt;br /&gt;
import org.eclipse.swt.widgets.FontDialog;&lt;br /&gt;
import org.eclipse.swt.widgets.Menu;&lt;br /&gt;
import org.eclipse.swt.widgets.MenuItem;&lt;br /&gt;
import org.eclipse.swt.widgets.MessageBox;&lt;br /&gt;
import org.eclipse.swt.widgets.Shell;&lt;br /&gt;
import org.eclipse.swt.widgets.Text;&lt;br /&gt;
public class PrintTextWrapPagetation {&lt;br /&gt;
  Display display;&lt;br /&gt;
  Shell shell;&lt;br /&gt;
  Text text;&lt;br /&gt;
  Font font;&lt;br /&gt;
  Color foregroundColor, backgroundColor;&lt;br /&gt;
  Printer printer;&lt;br /&gt;
  GC gc;&lt;br /&gt;
  FontData[] printerFontData;&lt;br /&gt;
  RGB printerForeground, printerBackground;&lt;br /&gt;
  int lineHeight = 0;&lt;br /&gt;
  int tabWidth = 0;&lt;br /&gt;
  int leftMargin, rightMargin, topMargin, bottomMargin;&lt;br /&gt;
  int x, y;&lt;br /&gt;
  int index, end;&lt;br /&gt;
  String textToPrint;&lt;br /&gt;
  String tabs;&lt;br /&gt;
  StringBuffer wordBuffer;&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    new Snippet133().open();&lt;br /&gt;
  }&lt;br /&gt;
  void open() {&lt;br /&gt;
    display = new Display();&lt;br /&gt;
    shell = new Shell(display);&lt;br /&gt;
    shell.setLayout(new FillLayout());&lt;br /&gt;
    shell.setText(&amp;quot;Print Text&amp;quot;);&lt;br /&gt;
    text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);&lt;br /&gt;
    Menu menuBar = new Menu(shell, SWT.BAR);&lt;br /&gt;
    shell.setMenuBar(menuBar);&lt;br /&gt;
    MenuItem item = new MenuItem(menuBar, SWT.CASCADE);&lt;br /&gt;
    item.setText(&amp;quot;&amp;amp;File&amp;quot;);&lt;br /&gt;
    Menu fileMenu = new Menu(shell, SWT.DROP_DOWN);&lt;br /&gt;
    item.setMenu(fileMenu);&lt;br /&gt;
    item = new MenuItem(fileMenu, SWT.PUSH);&lt;br /&gt;
    item.setText(&amp;quot;&amp;amp;Open...&amp;quot;);&lt;br /&gt;
    item.setAccelerator(SWT.CTRL + &amp;quot;O&amp;quot;);&lt;br /&gt;
    item.addSelectionListener(new SelectionAdapter() {&lt;br /&gt;
      public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
        menuOpen();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    item = new MenuItem(fileMenu, SWT.PUSH);&lt;br /&gt;
    item.setText(&amp;quot;Font...&amp;quot;);&lt;br /&gt;
    item.addSelectionListener(new SelectionAdapter() {&lt;br /&gt;
      public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
        menuFont();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    item = new MenuItem(fileMenu, SWT.PUSH);&lt;br /&gt;
    item.setText(&amp;quot;Foreground Color...&amp;quot;);&lt;br /&gt;
    item.addSelectionListener(new SelectionAdapter() {&lt;br /&gt;
      public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
        menuForegroundColor();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    item = new MenuItem(fileMenu, SWT.PUSH);&lt;br /&gt;
    item.setText(&amp;quot;Background Color...&amp;quot;);&lt;br /&gt;
    item.addSelectionListener(new SelectionAdapter() {&lt;br /&gt;
      public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
        menuBackgroundColor();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    item = new MenuItem(fileMenu, SWT.PUSH);&lt;br /&gt;
    item.setText(&amp;quot;&amp;amp;Print...&amp;quot;);&lt;br /&gt;
    item.setAccelerator(SWT.CTRL + &amp;quot;P&amp;quot;);&lt;br /&gt;
    item.addSelectionListener(new SelectionAdapter() {&lt;br /&gt;
      public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
        menuPrint();&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    new MenuItem(fileMenu, SWT.SEPARATOR);&lt;br /&gt;
    item = new MenuItem(fileMenu, SWT.PUSH);&lt;br /&gt;
    item.setText(&amp;quot;E&amp;amp;xit&amp;quot;);&lt;br /&gt;
    item.addSelectionListener(new SelectionAdapter() {&lt;br /&gt;
      public void widgetSelected(SelectionEvent event) {&lt;br /&gt;
        System.exit(0);&lt;br /&gt;
      }&lt;br /&gt;
    });&lt;br /&gt;
    shell.open();&lt;br /&gt;
    while (!shell.isDisposed()) {&lt;br /&gt;
      if (!display.readAndDispatch())&lt;br /&gt;
        display.sleep();&lt;br /&gt;
    }&lt;br /&gt;
    if (font != null)&lt;br /&gt;
      font.dispose();&lt;br /&gt;
    if (foregroundColor != null)&lt;br /&gt;
      foregroundColor.dispose();&lt;br /&gt;
    if (backgroundColor != null)&lt;br /&gt;
      backgroundColor.dispose();&lt;br /&gt;
    display.dispose();&lt;br /&gt;
  }&lt;br /&gt;
  void menuOpen() {&lt;br /&gt;
    final String textString;&lt;br /&gt;
    FileDialog dialog = new FileDialog(shell, SWT.OPEN);&lt;br /&gt;
    dialog.setFilterExtensions(new String[] { &amp;quot;*.java&amp;quot;, &amp;quot;*.*&amp;quot; });&lt;br /&gt;
    String name = dialog.open();&lt;br /&gt;
    if ((name == null) || (name.length() == 0))&lt;br /&gt;
      return;&lt;br /&gt;
    try {&lt;br /&gt;
      File file = new File(name);&lt;br /&gt;
      FileInputStream stream = new FileInputStream(file.getPath());&lt;br /&gt;
      try {&lt;br /&gt;
        Reader in = new BufferedReader(new InputStreamReader(stream));&lt;br /&gt;
        char[] readBuffer = new char[2048];&lt;br /&gt;
        StringBuffer buffer = new StringBuffer((int) file.length());&lt;br /&gt;
        int n;&lt;br /&gt;
        while ((n = in.read(readBuffer)) &amp;gt; 0) {&lt;br /&gt;
          buffer.append(readBuffer, 0, n);&lt;br /&gt;
        }&lt;br /&gt;
        textString = buffer.toString();&lt;br /&gt;
        stream.close();&lt;br /&gt;
      } catch (IOException e) {&lt;br /&gt;
        MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);&lt;br /&gt;
        box.setMessage(&amp;quot;Error reading file:\n&amp;quot; + name);&lt;br /&gt;
        box.open();&lt;br /&gt;
        return;&lt;br /&gt;
      }&lt;br /&gt;
    } catch (FileNotFoundException e) {&lt;br /&gt;
      MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);&lt;br /&gt;
      box.setMessage(&amp;quot;File not found:\n&amp;quot; + name);&lt;br /&gt;
      box.open();&lt;br /&gt;
      return;&lt;br /&gt;
    }&lt;br /&gt;
    text.setText(textString);&lt;br /&gt;
  }&lt;br /&gt;
  void menuFont() {&lt;br /&gt;
    FontDialog fontDialog = new FontDialog(shell);&lt;br /&gt;
    fontDialog.setFontList(text.getFont().getFontData());&lt;br /&gt;
    FontData fontData = fontDialog.open();&lt;br /&gt;
    if (fontData != null) {&lt;br /&gt;
      if (font != null)&lt;br /&gt;
        font.dispose();&lt;br /&gt;
      font = new Font(display, fontData);&lt;br /&gt;
      text.setFont(font);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void menuForegroundColor() {&lt;br /&gt;
    ColorDialog colorDialog = new ColorDialog(shell);&lt;br /&gt;
    colorDialog.setRGB(text.getForeground().getRGB());&lt;br /&gt;
    RGB rgb = colorDialog.open();&lt;br /&gt;
    if (rgb != null) {&lt;br /&gt;
      if (foregroundColor != null)&lt;br /&gt;
        foregroundColor.dispose();&lt;br /&gt;
      foregroundColor = new Color(display, rgb);&lt;br /&gt;
      text.setForeground(foregroundColor);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void menuBackgroundColor() {&lt;br /&gt;
    ColorDialog colorDialog = new ColorDialog(shell);&lt;br /&gt;
    colorDialog.setRGB(text.getBackground().getRGB());&lt;br /&gt;
    RGB rgb = colorDialog.open();&lt;br /&gt;
    if (rgb != null) {&lt;br /&gt;
      if (backgroundColor != null)&lt;br /&gt;
        backgroundColor.dispose();&lt;br /&gt;
      backgroundColor = new Color(display, rgb);&lt;br /&gt;
      text.setBackground(backgroundColor);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void menuPrint() {&lt;br /&gt;
    PrintDialog dialog = new PrintDialog(shell, SWT.NONE);&lt;br /&gt;
    PrinterData data = dialog.open();&lt;br /&gt;
    if (data == null)&lt;br /&gt;
      return;&lt;br /&gt;
    if (data.printToFile) {&lt;br /&gt;
      data.fileName = &amp;quot;print.out&amp;quot;; // you probably want to ask the user for a&lt;br /&gt;
                                    // filename&lt;br /&gt;
    }&lt;br /&gt;
    /*&lt;br /&gt;
     * Get the text to print from the Text widget (you could get it from&lt;br /&gt;
     * anywhere, i.e. your java model)&lt;br /&gt;
     */&lt;br /&gt;
    textToPrint = text.getText();&lt;br /&gt;
    /* Get the font &amp;amp; foreground &amp;amp; background data. */&lt;br /&gt;
    printerFontData = text.getFont().getFontData();&lt;br /&gt;
    printerForeground = text.getForeground().getRGB();&lt;br /&gt;
    printerBackground = text.getBackground().getRGB();&lt;br /&gt;
    /*&lt;br /&gt;
     * Do the printing in a background thread so that spooling does not freeze&lt;br /&gt;
     * the UI.&lt;br /&gt;
     */&lt;br /&gt;
    printer = new Printer(data);&lt;br /&gt;
    Thread printingThread = new Thread(&amp;quot;Printing&amp;quot;) {&lt;br /&gt;
      public void run() {&lt;br /&gt;
        print(printer);&lt;br /&gt;
        printer.dispose();&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
    printingThread.start();&lt;br /&gt;
  }&lt;br /&gt;
  void print(Printer printer) {&lt;br /&gt;
    if (printer.startJob(&amp;quot;Text&amp;quot;)) { // the string is the job name - shows up in&lt;br /&gt;
                                    // the printer&amp;quot;s job list&lt;br /&gt;
      Rectangle clientArea = printer.getClientArea();&lt;br /&gt;
      Rectangle trim = printer.ruputeTrim(0, 0, 0, 0);&lt;br /&gt;
      Point dpi = printer.getDPI();&lt;br /&gt;
      leftMargin = dpi.x + trim.x; // one inch from left side of paper&lt;br /&gt;
      rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch&lt;br /&gt;
                                                                    // from&lt;br /&gt;
                                                                    // right&lt;br /&gt;
                                                                    // side of&lt;br /&gt;
                                                                    // paper&lt;br /&gt;
      topMargin = dpi.y + trim.y; // one inch from top edge of paper&lt;br /&gt;
      bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one&lt;br /&gt;
                                                                        // inch&lt;br /&gt;
                                                                        // from&lt;br /&gt;
                                                                        // bottom&lt;br /&gt;
                                                                        // edge&lt;br /&gt;
                                                                        // of&lt;br /&gt;
                                                                        // paper&lt;br /&gt;
      /* Create a buffer for computing tab width. */&lt;br /&gt;
      int tabSize = 4; // is tab width a user setting in your UI?&lt;br /&gt;
      StringBuffer tabBuffer = new StringBuffer(tabSize);&lt;br /&gt;
      for (int i = 0; i &amp;lt; tabSize; i++)&lt;br /&gt;
        tabBuffer.append(&amp;quot; &amp;quot;);&lt;br /&gt;
      tabs = tabBuffer.toString();&lt;br /&gt;
      /*&lt;br /&gt;
       * Create printer GC, and create and set the printer font &amp;amp; foreground&lt;br /&gt;
       * color.&lt;br /&gt;
       */&lt;br /&gt;
      gc = new GC(printer);&lt;br /&gt;
      Font printerFont = new Font(printer, printerFontData);&lt;br /&gt;
      Color printerForegroundColor = new Color(printer, printerForeground);&lt;br /&gt;
      Color printerBackgroundColor = new Color(printer, printerBackground);&lt;br /&gt;
      gc.setFont(printerFont);&lt;br /&gt;
      gc.setForeground(printerForegroundColor);&lt;br /&gt;
      gc.setBackground(printerBackgroundColor);&lt;br /&gt;
      tabWidth = gc.stringExtent(tabs).x;&lt;br /&gt;
      lineHeight = gc.getFontMetrics().getHeight();&lt;br /&gt;
      /* Print text to current gc using word wrap */&lt;br /&gt;
      printText();&lt;br /&gt;
      printer.endJob();&lt;br /&gt;
      /* Cleanup graphics resources used in printing */&lt;br /&gt;
      printerFont.dispose();&lt;br /&gt;
      printerForegroundColor.dispose();&lt;br /&gt;
      printerBackgroundColor.dispose();&lt;br /&gt;
      gc.dispose();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void printText() {&lt;br /&gt;
    printer.startPage();&lt;br /&gt;
    wordBuffer = new StringBuffer();&lt;br /&gt;
    x = leftMargin;&lt;br /&gt;
    y = topMargin;&lt;br /&gt;
    index = 0;&lt;br /&gt;
    end = textToPrint.length();&lt;br /&gt;
    while (index &amp;lt; end) {&lt;br /&gt;
      char c = textToPrint.charAt(index);&lt;br /&gt;
      index++;&lt;br /&gt;
      if (c != 0) {&lt;br /&gt;
        if (c == 0x0a || c == 0x0d) {&lt;br /&gt;
          if (c == 0x0d &amp;amp;&amp;amp; index &amp;lt; end &amp;amp;&amp;amp; textToPrint.charAt(index) == 0x0a) {&lt;br /&gt;
            index++; // if this is cr-lf, skip the lf&lt;br /&gt;
          }&lt;br /&gt;
          printWordBuffer();&lt;br /&gt;
          newline();&lt;br /&gt;
        } else {&lt;br /&gt;
          if (c != &amp;quot;\t&amp;quot;) {&lt;br /&gt;
            wordBuffer.append(c);&lt;br /&gt;
          }&lt;br /&gt;
          if (Character.isWhitespace(c)) {&lt;br /&gt;
            printWordBuffer();&lt;br /&gt;
            if (c == &amp;quot;\t&amp;quot;) {&lt;br /&gt;
              x += tabWidth;&lt;br /&gt;
            }&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    if (y + lineHeight &amp;lt;= bottomMargin) {&lt;br /&gt;
      printer.endPage();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void printWordBuffer() {&lt;br /&gt;
    if (wordBuffer.length() &amp;gt; 0) {&lt;br /&gt;
      String word = wordBuffer.toString();&lt;br /&gt;
      int wordWidth = gc.stringExtent(word).x;&lt;br /&gt;
      if (x + wordWidth &amp;gt; rightMargin) {&lt;br /&gt;
        /* word doesn&amp;quot;t fit on current line, so wrap */&lt;br /&gt;
        newline();&lt;br /&gt;
      }&lt;br /&gt;
      gc.drawString(word, x, y, false);&lt;br /&gt;
      x += wordWidth;&lt;br /&gt;
      wordBuffer = new StringBuffer();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void newline() {&lt;br /&gt;
    x = leftMargin;&lt;br /&gt;
    y += lineHeight;&lt;br /&gt;
    if (y + lineHeight &amp;gt; bottomMargin) {&lt;br /&gt;
      printer.endPage();&lt;br /&gt;
      if (index + 1 &amp;lt; end) {&lt;br /&gt;
        y = topMargin;&lt;br /&gt;
        printer.startPage();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>