Printing routine flips my text by 180 degrees

Discussion in 'Java' started by lemmi, Mar 29, 2007.

  1. lemmi

    lemmi Guest

    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
     
    lemmi, Mar 29, 2007
    #1
    1. Advertising

  2. lemmi

    Daniel Pitts Guest

    On Mar 29, 7:18 am, "lemmi" <> wrote:
    > 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


    If you post an sscce <http://www.physci.org/codes/sscce.html>, it
    might help us make suggestions for you.
     
    Daniel Pitts, Mar 29, 2007
    #2
    1. Advertising

  3. Daniel Pitts schrieb:
    > On Mar 29, 7:18 am, "lemmi" <> wrote:
    >> 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

    >
    > 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
     
    =?ISO-8859-1?Q?Alexander_Sch=F6lling?=, Apr 18, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kent Johnson

    180 Session memvar..?

    Kent Johnson, Nov 23, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    290
    Alvin Bruney
    Nov 23, 2003
  2. long eddy
    Replies:
    3
    Views:
    746
    dorayme
    Jan 10, 2006
  3. JustSomeGuy
    Replies:
    2
    Views:
    470
    Howard
    Jun 3, 2004
  4. Mel
    Replies:
    2
    Views:
    104
    Lasse Reichstein Nielsen
    May 5, 2004
  5. Leo Koolsbergen

    how to rotate an image 180 degrees

    Leo Koolsbergen, Dec 21, 2004, in forum: Javascript
    Replies:
    6
    Views:
    376
    Leo Koolsbergen
    Dec 22, 2004
Loading...

Share This Page