Skip to main content



      Home
Home » Eclipse Projects » GEF » PrintFigureOperation doesn't print whole figure.
PrintFigureOperation doesn't print whole figure. [message #53082] Thu, 09 January 2003 10:37 Go to next message
Eclipse UserFriend
Originally posted by: sven.e-sven.net

I've got an IFigure which is larger than my Page. So I'd like the
Printing to be split over several pages, but PrintFigureOperation prints
only one page with the top-left part of my figure.

Is there a way to tell the Operation to split the figure or do i have to
do this by myself, using a normal PrintOperation?

Thanks for your help.

Sven\ 8)
Re: PrintFigureOperation doesn't print whole figure. [message #53109 is a reply to message #53082] Thu, 09 January 2003 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: noone.ibm.com

The PrintFigureOperation will only print one page, with your IFigure aligned
to the top-left corner of the page. The setupPrinterGraphicsFor() method
performs the scaling and top-left alignment, and printPages() prints it out.
In order to split your IFigure into several pages, you would have to
subclass PrintFigureOperation and override printPages() and/or
setupPrinterGraphicsFor().

So printPages() would become something like:

//
// Code to split printSource IFigure into n IFigures
//
for( int i=0; i < n; i++){
getPrinter.startPage();
figure[n].paint(printerGraphics);
getPrinter.endPage();
}

This type of printing should be supported in draw2d at some point. Feel free
to contribute if you implement this.
"Sven M
Re: PrintFigureOperation doesn't print whole figure. [message #53183 is a reply to message #53109] Thu, 09 January 2003 11:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hudsonr.us.eye-bee-em.com

"Dan Lee" <noone@ibm.com> wrote in message
news:avk6b5$gqn$1@rogue.oti.com...
> The PrintFigureOperation will only print one page, with your IFigure
aligned
> to the top-left corner of the page. The setupPrinterGraphicsFor() method
> performs the scaling and top-left alignment, and printPages() prints it
out.
> In order to split your IFigure into several pages, you would have to
> subclass PrintFigureOperation and override printPages() and/or
> setupPrinterGraphicsFor().
>
> So printPages() would become something like:
>
> //
> // Code to split printSource IFigure into n IFigures
> //
> for( int i=0; i < n; i++){
> getPrinter.startPage();
> figure[n].paint(printerGraphics);

You probably want to print the same figure over and over on different pages.
You would still have a single print source. The only difference would be
that the PrinterGraphics would be translated to different "windows" of the
print source.

Another nice-to-have feature would be a zoom-to-fit option that would
squeeze a diagram onto one page. We would like to have this in draw2d
eventually, and like Dan said, feel free to submit any code to either the
newsgroup or mailin glist.

> getPrinter.endPage();
> }
>
> This type of printing should be supported in draw2d at some point. Feel
free
> to contribute if you implement this.
> "Sven M
Re: PrintFigureOperation doesn't print whole figure. [message #53340 is a reply to message #53183] Fri, 10 January 2003 07:35 Go to previous message
Eclipse UserFriend
Originally posted by: sven.e-sven.net

Here is my implementation of a PrintBigFigureOperation...

Sven\ 8)

import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PrintFigureOperation;
import org.eclipse.draw2d.PrinterGraphics;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.swt.widgets.Display;

/**
* Druckt eine IFigure über mehrere Seiten.
* @author Sven Müller
*/
public class PrintBigFigureOperation extends PrintFigureOperation {

private double scale;
/**
* @see org.eclipse.draw2d.PrintOperation#printPages()
*/
protected void printPages() {
IFigure figure = getPrintSource();
boolean nextPage = true;
Point offset = figure.getBounds().getLocation().getCopy();
scale =
(double) getPrinter().getDPI().x / Display.getDefault().getDPI().x;
int x =
(int) (figure.getBounds().getSize().width
/ (getPrintRegion().width / scale));
int y =
(int) (figure.getBounds().getSize().height
/ (getPrintRegion().height / scale));

int memX1 = x;
int memX2 = offset.x;
PrinterGraphics g = getFreshPrinterGraphics();
List childs = figure.getChildren();
while (nextPage) {
g.pushState();
getPrinter().startPage();
g.setForegroundColor(figure.getForegroundColor());
g.setBackgroundColor(figure.getBackgroundColor());
g.setFont(figure.getFont());
g.scale(scale);
figure.translate(offset.x, offset.y);
for (int i = 0; i < childs.size(); i++)
((IFigure) childs.get(i)).translate(-offset.x, -offset.y);
g.translate(figure.getBounds().getLocation().getCopy().negat e());
g.clipRect(figure.getBounds());
figure.paint(g);
getPrinter().endPage();
g.restoreState();
if (x > 0) {
x--;
offset.x = (int) (getPrintRegion().width / scale);
} else if (y > 0) {
y--;
x = memX1;
figure.translate(-x * offset.x, 0);
for (int i = 0; i < childs.size(); i++)
((IFigure) childs.get(i)).translate(x * offset.x, 0);
offset.x = memX2;
offset.y = (int) (getPrintRegion().height / scale);
} else {
nextPage = false;
}
}
}
}
Previous Topic:TextTransfer Drag and Drop Question in Logic Editor Example
Next Topic:How can i support IPropertySource in GEF?
Goto Forum:
  


Current Time: Thu May 08 07:20:57 EDT 2025

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

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

Back to the top