[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform.swt] Re: Printing content of the Composite...
|
Sergei,
Looking at the snippet, the mBuffer should be created on the printer, not
the display. See
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/faq.html#noprintimage
If this does not solve your problem then please follow up.
Grant
user@xxxxxxxxxxxxxx wrote:
> I try to print the content of my Composite.
> I try to send to the printer Image mBuffer produced with my method,
> which called during redrawing.
> But printer shows nothing. what is the plausible reason?
> Sergei.
> PrintDialog dialog = new PrintDialog(this.getShell(), SWT.NULL);
> PrinterData printerData = dialog.open();
> if (printerData == null)
> return;
> Printer printer = new Printer(printerData);
> Point screenDPI = this.getDisplay().getDPI();
> Point printerDPI = printer.getDPI();
> int scaleFactor = printerDPI.x / screenDPI.x;
> Rectangle trim = printer.computeTrim(0, 0, 0, 0);
> if (printer.startJob("Print FlowComposite")) {
> if (printer.startPage()) {
> GC gc = new GC(printer);
> Image mBuffer = new Image(
> FlowComposite.this.getDisplay(),
> size.x,
> size.y);
> GC gc2 = new GC(mBuffer);
> onPaint(gc2);
> gc2.dispose();
> gc.drawImage(
> mBuffer,
> 0,
> 0,
> mBuffer.getImageData().width,
> mBuffer.getImageData().height,
> -trim.x,
> -trim.y,
> scaleFactor * mBuffer.getImageData().width,
> scaleFactor * mBuffer.getImageData().height);
> gc.dispose();
> printer.endPage();
> }
> printer.endJob();
> }
> printer.dispose();
> } catch (SWTError e) {
> e.printStackTrace();
> }