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 - hack for special JasperReports case



Hi Bernd.

This looks very interesting. I'll try it and let you know if it fixes the printing for me. I suppose it will!
Thanks!
:-)


On 1/25/08, Bernd Gründling <email@hidden> wrote:
>
Hello all,

Earlier today I wrote

> 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.

I tried to understand what JasperReport 1.3.1 is doing. While I had no
perfect success, I found a hack which may help me out until an
official fix is there.

In net.sf.jasperreports.engine.export.TextRenderer#renderParagraph (
     AttributedCharacterIterator allParagraphs,
     int lastParagraphStart, String lastParagraphText)

I replaced

     draw(layout);

with

     // temporary "fix" for bug #122: wrong fonts when printing under
Leopard
     // put the correct font into the graphics context

     // caution: TextAttributes contain FAMILY and SIZE only, STYLE
appears
     // to be missing. Fractions in font sizes are ignored.
     // does not work with multi-style paragraphs

     paragraph.setIndex (paragraph.first()); // we always get the
first font, if any
     Object fam = paragraph.getAttribute (TextAttribute.FAMILY);
     Object siz = paragraph.getAttribute (TextAttribute.SIZE);
     if ((fam != null) && (siz!=null))
     {
         int s = ((Float)siz).intValue (); // not fractional sizes any
more
         grx.setFont (new Font ((String)fam, 0, s));
     }

     draw(layout);

This is ugly, and from my comments you can tell I am not sure it will
work under all circumstances. Fortunately, for now it may be
sufficient for my special case.


Why did I do that? During rendering, JasperReports keeps the graphics
context object grx around (java.awt.Graphics2D), and the rendering
methods have a java.awt.font.TextLayout derived from a
java.text.AttributedCharacterIterator#paragraph which gives access to
the styled text we are going to print.

Interestingly, the TextLayout knows about the correct font, whereas
the Graphics2D says "Lucida Grande" all the time. Of course, when it
comes to drawing, only the Graphics2D object is used...

What do you think?


Regards,
Bernd





_______________________________________________
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



--
DCIT Corporation
Software Solutions & Technology
Services to Support Your Business
http://www.dcit.com

** Log in at http://www.dcit.com for the latest information and updates **
 _______________________________________________
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

References: 
 >Re: java printing font issue on leopard - hack for special JasperReports case (From: Bernd Gründling <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.