public void print(Printer printer) { this.printer = printer; if (printer.startJob("StyledText")) { Rectangle clientArea = printer.getClientArea(); Rectangle trim = printer.computeTrim(0, 0, 0, 0); Point dpi = printer.getDPI(); leftMargin = dpi.x + trim.x; rightMargin = clientArea.width - dpi.x + trim.x + trim.width; topMargin = dpi.y + trim.y; bottomMargin = clientArea.height - dpi.y + trim.y + trim.height;   styledText.getDisplay().syncExec(new Runnable() { public void run() { tabSize = styledText.getTabs(); } }); StringBuffer tabBuffer = new StringBuffer(tabSize); for (int i = 0; i < tabSize; i++) tabBuffer.append(' '); tabs = tabBuffer.toString();   gc = new GC(printer); x = leftMargin; y = topMargin; printer.startPage(); printStyledTextRTF(); if (y + lineHeight <= bottomMargin) { printer.endPage(); } printer.endJob();   gc.dispose(); for (int i = 0; i < 4; i++) { fontTable[currentFont][i].dispose(); } for (int i = 0; i < colorTable.size(); i++) { ((Color)colorTable.elementAt(i)).dispose(); } }
static void print(StyledText styledText) { Printer printer = new Printer(); new StyledTextPrinter(styledText, printer).run(); printer.dispose();
	public void print(Printer printer) {		this.printer = printer;		if (printer.startJob("StyledText")) {			Rectangle clientArea = printer.getClientArea();			Rectangle trim = printer.computeTrim(0, 0, 0, 0);			Point dpi = printer.getDPI();			leftMargin = dpi.x + trim.x; // one inch from left side of paper			rightMargin = clientArea.width - dpi.x + trim.x + trim.width; // one inch from right side of paper			topMargin = dpi.y + trim.y; // one inch from top edge of paper			bottomMargin = clientArea.height - dpi.y + trim.y + trim.height; // one inch from bottom edge of paper						/* Create a buffer for computing tab width. */			styledText.getDisplay().syncExec(new Runnable() {				public void run() {					tabSize = styledText.getTabs();				}			});			StringBuffer tabBuffer = new StringBuffer(tabSize);			for (int i = 0; i < tabSize; i++) tabBuffer.append(' ');			tabs = tabBuffer.toString();			/* Get RTF from the StyledText, determine what fonts and colors we need, and print. */			gc = new GC(printer);			x = leftMargin;			y = topMargin;			printer.startPage();			printStyledTextRTF();			if (y + lineHeight <= bottomMargin) {				printer.endPage();			}			printer.endJob();			/* Cleanup */			gc.dispose();			for (int i = 0; i < 4; i++) {				fontTable[currentFont][i].dispose();			}			for (int i = 0; i < colorTable.size(); i++) {				((Color)colorTable.elementAt(i)).dispose();			}		}	}