Printing routine flips my text by 180 degrees

L

lemmi

Hi,

I have a problem with a printing routine I wrote for a Swing
component. For some reason all text elements (g.drawString()) appear
rotated (by 180 degrees) when I use LANDSCAPE orientation. Has anyone
seen this before?

Dirk
 
?

=?ISO-8859-1?Q?Alexander_Sch=F6lling?=

Daniel said:
If you post an sscce <http://www.physci.org/codes/sscce.html>, it
might help us make suggestions for you.
The following code exhibits this problem:

------
/*
* GraphPageable.java
*
* Created on 27. Februar 2007, 10:07
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package de.gpkom.graph;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import org.jfree.chart.JFreeChart;

/**
* Printer class for a graph
* @author Alexander Schölling
*/
public class GraphPageable implements Printable {

/**
* Creates a new instance of GraphPageable
* @param g Graph
*/
public GraphPageable(JFreeChart g) {
graph=g;
}

/**
* Printing dialogs and printing
* @throws java.awt.print.PrinterException Passed through from
PrinterJob.print()
*/
public void print() throws PrinterException {
PrinterJob job=PrinterJob.getPrinterJob();
PageFormat alt=job.defaultPage();
PageFormat format=job.pageDialog(alt);
if (format.equals(alt)) return;
job.setPrintable(this, format);
if (job.printDialog()) {
job.print();
}
}

/**
* Printing
* @param graphics GraphicsContext
* @param pageFormat PaqeFormat
* @param i Page number
* @throws java.awt.print.PrinterException Passed through
* @return Printable.NO_SUCH_PAGE or Printable.PAGE_EXISTS
*/
public int print(Graphics graphics, PageFormat pageFormat, int i)
throws PrinterException {
if (i>0) return Printable.NO_SUCH_PAGE;
Graphics2D g2=(Graphics2D)graphics;
g2.translate(pageFormat.getImageableX(),
pageFormat.getImageableY());
graph.draw(g2, new
Rectangle((int)pageFormat.getImageableWidth(),
(int)pageFormat.getImageableHeight()));
return Printable.PAGE_EXISTS;
}

private JFreeChart graph;
}
-----

As soon as I change the orientation from portrait to landscape _in the
print dialog_, the strings (Graph label, title, etc.) are turned upside
down. Even the diagonally printed strings are turned 180°.

Yours,

Alexander
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top