Saturday 1 November 2008

Geoff on GEF pt. V

Erk! Hit a really difficult problem now. I've been working on printing a draw2d figure from my app for a few days now (on and off). I have managed, through debugging, to show that the figures are all being laid out as expected. My output is producing the correct number of blank pages and I have managed to display all text on screen once, before re-writing slightly, but I have not yet managed to produce the required text on the pages.

The following shows what I have so far:


Printer printer = new Printer(data);
Graphics graphics = new PrinterGraphics(new SWTGraphics(new GC(printer, SWT.LEFT_TO_RIGHT)), printer);
Rectangle printRegion = getPrintRegion(printer);

printer.startJob(TournamentManager.get().getTournament().getDefinition()
.getName()
+ " Score Cards");

Figure root = new Figure();
root.setLayoutManager(new ToolbarLayout(false));
root.setForegroundColor(new Color(printer, 0,0,0));
root.setFont(printer.getSystemFont());

for (CompetitorStatus status : competitorStatuses) {
graphics.pushState();
IFigure page = buildFigure(status);
root.add(page);

Canvas c = new Canvas(new Shell(), SWT.None);
c.setLayout(new FillLayout());
LightweightSystem lwsTmp = new LightweightSystem(c);
lwsTmp.setContents(page);
c.setBounds(printRegion.x, printRegion.y, printRegion.width, printRegion.height);
c.layout();
printer.startPage();

graphics.translate(-printRegion.x, -printRegion.y);
graphics.getClip(printRegion);
printRegion.setLocation(printRegion.x, printRegion.y);
graphics.clipRect(printRegion);
page.paint(graphics);
printer.endPage();
graphics.popState();
}
printer.endJob();

No comments: