Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: java printing font issue on leopard



Hi all,

I also have this problem printing from JasperReports. I have had a look at the PDF file and found the spacing to be that of the font and size I declared in the report definition, but the font actually printed to PDF was Lucida Grande 12pt, no matter which font I requested. So the character placement is done with the correct font.

This works:

import java.awt.print.*;
import java.awt.*;

public class PrintTest implements Printable {

    public static void main(String[] args) {
        PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(new PrintTest());

        try {
            printJob.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }

public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}


        Graphics2D g2d = (Graphics2D) g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());

int yPosition = 100;
int fontSize = 8;
while (fontSize <= 14) {
g.setFont(new Font("Arial", Font.PLAIN, fontSize));
g.drawString(fontSize + "pt Arial: The quick brown fox jumped over the lazy old dog.", 100, yPosition);


            yPosition += 50;
            fontSize++;
        }

        return PAGE_EXISTS;
    }
}


which seems to be consistent to what Raffi Minassian reported:

Peter Mycue from DBSolutions, Inc. was kind enough to share the following
info with me about this issue...
" ... the root problem seems to be that the font context is not updated when
you change fonts in a graphics context."




By the way, calling JasperExportManager.exportReportToPdfFile works perfectly, only JasperPrintManager.printReport does not.


In Jasper, JRXmlDigesterFactory, I found these conspicously looking lines:


digester.addFactoryCreate("*/textElement/font", JRFontFactory.TextElementFontFactory.class.getName());
//digester.addSetNext("*/textElement/font", "setFont", JRFont.class.getName());


Why is setFont commented out? Removing the comment does not help, of course.


While this does not solve the problem, it might shed a little bit more light on it.



Kind regards, Bernd Gründling _______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.