Java Code Examples for org.eclipse.draw2d.Graphics#scale()

The following examples show how to use org.eclipse.draw2d.Graphics#scale() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReportPrintGraphicalViewerOperation.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets up Graphics object for the given IFigure.
 * 
 * @param graphics
 *            The Graphics to setup
 * @param figure
 *            The IFigure used to setup graphics
 */
protected void setupPrinterGraphicsFor( Graphics graphics, IFigure figure )
{
	// Because the ScaleGraphics don't support the scale(float h,float v),so
	// now suppoer fit the page.
	Rectangle printRegion = getPrintRegion( );

	Rectangle bounds = figure.getBounds( );
	double xScale = (double) printRegion.width / bounds.width;
	double yScale = (double) printRegion.height / bounds.height;
	graphics.scale( Math.min( xScale, yScale ) );

	// float xScale = (float) printRegion.width / bounds.width;
	// float yScale = (float) printRegion.height / bounds.height;
	// graphics.scale( xScale, yScale );

	graphics.setForegroundColor( figure.getForegroundColor( ) );
	graphics.setBackgroundColor( figure.getBackgroundColor( ) );
	graphics.setFont( figure.getFont( ) );
}
 
Example 2
Source File: PrintERDiagramOperation.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void setupPrinterGraphicsFor(final Graphics graphics, final IFigure figure) {
    final ERDiagram diagram = getDiagram();
    final PageSetting pageSetting = diagram.getPageSetting();

    final double dpiScale = (double) getPrinter().getDPI().x / Display.getCurrent().getDPI().x * pageSetting.getScale() / 100;

    final Rectangle printRegion = getPrintRegion();
    // put the print region in display coordinates
    printRegion.width /= dpiScale;
    printRegion.height /= dpiScale;

    final Rectangle bounds = figure.getBounds();
    final double xScale = (double) printRegion.width / bounds.width;
    final double yScale = (double) printRegion.height / bounds.height;
    switch (getPrintMode()) {
        case FIT_PAGE:
            graphics.scale(Math.min(xScale, yScale) * dpiScale);
            break;
        case FIT_WIDTH:
            graphics.scale(xScale * dpiScale);
            break;
        case FIT_HEIGHT:
            graphics.scale(yScale * dpiScale);
            break;
        default:
            graphics.scale(dpiScale);
    }
    graphics.setForegroundColor(figure.getForegroundColor());
    graphics.setBackgroundColor(figure.getBackgroundColor());
    graphics.setFont(figure.getFont());
}
 
Example 3
Source File: PrintERDiagramOperation.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
    final ERDiagram diagram = getDiagram();
    final PageSettings pageSetting = diagram.getPageSetting();

    final double dpiScale = (double) getPrinter().getDPI().x / Display.getCurrent().getDPI().x * pageSetting.getScale() / 100;

    final Rectangle printRegion = getPrintRegion();
    // put the print region in display coordinates
    printRegion.width /= dpiScale;
    printRegion.height /= dpiScale;

    final Rectangle bounds = figure.getBounds();
    final double xScale = (double) printRegion.width / bounds.width;
    final double yScale = (double) printRegion.height / bounds.height;
    switch (getPrintMode()) {
    case FIT_PAGE:
        graphics.scale(Math.min(xScale, yScale) * dpiScale);
        break;
    case FIT_WIDTH:
        graphics.scale(xScale * dpiScale);
        break;
    case FIT_HEIGHT:
        graphics.scale(yScale * dpiScale);
        break;
    default:
        graphics.scale(dpiScale);
    }
    graphics.setForegroundColor(figure.getForegroundColor());
    graphics.setBackgroundColor(figure.getBackgroundColor());
    graphics.setFont(figure.getFont());
}
 
Example 4
Source File: PrintERDiagramOperation.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void setupPrinterGraphicsFor(Graphics graphics, IFigure figure) {
	ERDiagram diagram = this.getDiagram();
	PageSetting pageSetting = diagram.getPageSetting();

	double dpiScale = (double) getPrinter().getDPI().x
			/ Display.getCurrent().getDPI().x * pageSetting.getScale()
			/ 100;

	Rectangle printRegion = getPrintRegion();
	// put the print region in display coordinates
	printRegion.width /= dpiScale;
	printRegion.height /= dpiScale;

	Rectangle bounds = figure.getBounds();
	double xScale = (double) printRegion.width / bounds.width;
	double yScale = (double) printRegion.height / bounds.height;
	switch (getPrintMode()) {
	case FIT_PAGE:
		graphics.scale(Math.min(xScale, yScale) * dpiScale);
		break;
	case FIT_WIDTH:
		graphics.scale(xScale * dpiScale);
		break;
	case FIT_HEIGHT:
		graphics.scale(yScale * dpiScale);
		break;
	default:
		graphics.scale(dpiScale);
	}
	graphics.setForegroundColor(figure.getForegroundColor());
	graphics.setBackgroundColor(figure.getBackgroundColor());
	graphics.setFont(figure.getFont());
}