Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT printing capabilities- followup
SWT printing capabilities- followup [message #506070] Wed, 06 January 2010 00:36 Go to next message
Doug M is currently offline Doug MFriend
Messages: 18
Registered: December 2009
Junior Member
Thanks to Eric Rizzo for moving my question here.

I have made some progress with Control.print(GC). I am simply calling print(gc) with a displayed Composite, where gc is the printer's gc. It prints the Composite containing Text and StyledText (including colors and multiple fonts) perfectly. The layout and content are rendered exactly, and can be captured as PDF (not a bitmap image). I did nothing special with scaling, printer fonts or colors. It just works as is.

On Windows XP, however, the same code prints the Composite's children on top of each other at (0,0), scaled to a tiny size. The content of each child (Text and StyledText) is rendered correctly.

My searches of the eclipse site and with google turned up no example of how to use print correctly to print, nor any documentation on its development status or current limitations.

I would very much appreciate any practical solutions, workarounds, and inside information that would help me to print a Composite containing Text and StyledText.
Re: SWT printing capabilities- followup [message #506256 is a reply to message #506070] Wed, 06 January 2010 17:13 Go to previous messageGo to next message
Carolyn MacLeod is currently offline Carolyn MacLeodFriend
Messages: 149
Registered: July 2009
Senior Member
Hi, Doug.

This seems to be a bug. I can replicate it with the snippet below.
I have opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=298968
Please CC yourself to this bug to follow progress.

Thanks!
Carolyn

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.printing.*;

public class ControlPrintStyledText {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
final Composite composite = new Composite(shell, SWT.BORDER);
composite.setLayout(new GridLayout());
Text text = new Text(composite, SWT.SINGLE | SWT.BORDER);
text.setText("This is a Text field");
StyledText styledtext = new StyledText(composite, SWT.BORDER);
styledtext.setText("This is a StyledText.\nIt has a few test lines\nin
it.");
Button button = new Button (shell, SWT.PUSH);
button.setText ("Print Composite");
button.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event e) {
PrinterData data = Printer.getDefaultPrinterData();
if (data == null) {
System.out.println("Warning: No default printer.");
display.dispose();
return;
}
Printer printer = new Printer(data);
if (printer.startJob("Print Composite")) {
GC gc = new GC(printer);
if (printer.startPage()) {
if (!composite.print (gc)) {
System.out.println("Warning: Control.print(GC) is not supported on
your platform.");
display.dispose();
return;
}
printer.endPage();
}
gc.dispose();
printer.endJob();
}
printer.dispose();
}
});
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}


"DougM" <eclipse@cssw.biz> wrote in message
news:hi0lu5$api$1@build.eclipse.org...
> Thanks to Eric Rizzo for moving my question here.
>
> I have made some progress with Control.print(GC). I am simply calling
> print(gc) with a displayed Composite, where gc is the printer's gc. It
> prints the Composite containing Text and StyledText (including colors and
> multiple fonts) perfectly. The layout and content are rendered exactly,
> and can be captured as PDF (not a bitmap image). I did nothing special
> with scaling, printer fonts or colors. It just works as is.
>
> On Windows XP, however, the same code prints the Composite's children on
> top of each other at (0,0), scaled to a tiny size. The content of each
> child (Text and StyledText) is rendered correctly.
>
> My searches of the eclipse site and with google turned up no example of
> how to use print correctly to print, nor any documentation on its
> development status or current limitations.
> I would very much appreciate any practical solutions, workarounds, and
> inside information that would help me to print a Composite containing Text
> and StyledText.
>
Re: SWT printing capabilities- followup [message #506327 is a reply to message #506070] Thu, 07 January 2010 01:24 Go to previous messageGo to next message
Doug M is currently offline Doug MFriend
Messages: 18
Registered: December 2009
Junior Member
Thank you Carolyn for investigating and making the bug report.

I accidentally posted this reply and followup in the old thread in Newcomers. Sorry.
------------------------------------------------------------ -------------
Hello Madhu,

Thanks for replying, and Happy New Year to you too.

I had a look at Snippet292 and tried that approach in my tester. Here's the relevant section in case you want to check it. cmp is the Composite that contains Text and StyledText.
gc = new GC(printer);
printer.startPage();
Image image = new Image(printer,cmp.getBounds ());
GC igc = new GC(image);
boolean success = cmp.print(igc);
igc.dispose();
gc.drawImage(image, 200, 300);
printer.endPage();
I hoped that Image would store the Composite's image as OS drawing commands (like a metafile), and therefore provide a workaround to the problems using print() directly. Alas, image gets drawn as screen pixels, and when printed all the characters have jaggies. Kind of nostalgic, but not something I can release in a commercial application.

I did find a partial workaround. After gc.setAdvanced(true), it is possible to set a Transform on the printer's GC that scales and translates a text Control to its correct size and location when print() is called. Then it's a matter of walking the Composite tree and printing the text areas to the page one at a time.

I think setAdvanced(true) requires a graphics processor. Does anyone know for sure?

Windows also provides coordinate transformations in ordinary (non-GDI+) HDC's, which would yield a universal workaround. I am comfortable coding this in C, but have no clue how to mess with the printer HDC through SWT. Is anyone willing to show me how?

Regards to all,
Doug
Re: SWT printing capabilities- followup [message #506694 is a reply to message #506327] Fri, 08 January 2010 20:02 Go to previous message
Carolyn MacLeod is currently offline Carolyn MacLeodFriend
Messages: 149
Registered: July 2009
Senior Member
No problem. Please add all comments to the bug report.
Thanks!
Carolyn

"DougM" <eclipse@cssw.biz> wrote in message
news:hi3d4e$vnh$1@build.eclipse.org...
> Thank you Carolyn for investigating and making the bug report.
>
> I accidentally posted this reply and followup in the old thread in
> Newcomers. Sorry.
> ------------------------------------------------------------ -------------
> Hello Madhu,
>
> Thanks for replying, and Happy New Year to you too.
>
> I had a look at Snippet292 and tried that approach in my tester. Here's
> the relevant section in case you want to check it. cmp is the Composite
> that contains Text and StyledText.
> gc = new GC(printer);
> printer.startPage();
> Image image = new Image(printer,cmp.getBounds ());
> GC igc = new GC(image);
> boolean success = cmp.print(igc);
> igc.dispose();
> gc.drawImage(image, 200, 300);
> printer.endPage();
> I hoped that Image would store the Composite's image as OS drawing
> commands (like a metafile), and therefore provide a workaround to the
> problems using print() directly. Alas, image gets drawn as screen pixels,
> and when printed all the characters have jaggies. Kind of nostalgic, but
> not something I can release in a commercial application.
>
> I did find a partial workaround. After gc.setAdvanced(true), it is
> possible to set a Transform on the printer's GC that scales and translates
> a text Control to its correct size and location when print() is called.
> Then it's a matter of walking the Composite tree and printing the text
> areas to the page one at a time.
>
> I think setAdvanced(true) requires a graphics processor. Does anyone know
> for sure?
>
> Windows also provides coordinate transformations in ordinary (non-GDI+)
> HDC's, which would yield a universal workaround. I am comfortable coding
> this in C, but have no clue how to mess with the printer HDC through SWT.
> Is anyone willing to show me how?
>
> Regards to all,
> Doug
Previous Topic:non-transparent image transfer
Next Topic:Re: OpenSolaris: Eclipse/SWT hangs in GTK OS call when trying to change fonts
Goto Forum:
  


Current Time: Thu Dec 18 02:27:25 GMT 2014

Powered by FUDForum. Page generated in 0.01665 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software