On 22.01.2007 09:16:25 Vincent Hennebert wrote:
> Hi Daniel,
> 
> Daniel Noll a écrit :
> > Hi all.
> > 
> > There is a requirement in our system where PDF and TIFF output must have
> > the same content on every page.  Because of this, we need to use
> > identical font metrics for these two renderers.
> > 
> > By default, the two render differently.  The widths of the fonts are
> > slightly different, so they wrap slightly differently, and once you have
> > one word wrapping to the next page, it cascades.
> > 
> > Anyway, I was thinking, why can't I just do this?
> > 
> >   private class MyPDFRenderer extends PDFRenderer {
> >     public void setupFontInfo(FontInfo inFontInfo) {
> >       // Code copied from Java2DRenderer
> >       fontInfo = inFontInfo;
> >       BufferedImage fontImage = new BufferedImage(100, 100,
> >                                        BufferedImage.TYPE_INT_RGB);
> >       Graphics2D g = fontImage.createGraphics();
> >       g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
> >                          RenderingHints.VALUE_FRACTIONALMETRICS_ON);
> >       FontSetup.setup(fontInfo, g);
> >     }
> >   }
> > 
> > If I substitute this renderer in, then the PDF and TIFF outputs look
> > identical, and I can't see any noticeable problems with the PDF.  As an
> > added bonus, it means I don't even need the XML files hanging around,
> > which have been a pain to manage.
> > 
> > So what I want to know is, is there a drawback for performing this hack?
> 
> One major drawback I can think of is that you can't embed fonts in the
> PDF file, as you don't have access to the font files. That's why we
> can't use that method by default, but if it works for you I guess it's
> perfectly ok.
> 
> FWIW, I think the difference we can see between the PDF and Java2D
> renderers is due to hinting/anti-aliasing performed by the latter one.
> AFAIU Java2D takes an image with a given number of pixels as a basis, so
> has to deal with a potentially poor resolution (similar to screens).
> I'll let Java2D specialists complement/correct my guess.

Actually, that only applies if you work on the AWT plane where
everything is in pixels. When you work in the Java2D plane you can have
fractional values which gives better results. The problem is simply that
the font metrics Java2D provides are different than what we get be
working with the fonts directly. There's a lot of mapping inside Java2D
which unfortunately results in loss of information that we want for our
layout engine. There's also the problem of differences between JDK
versions which makes the whole thing even more complicated. That's why
working with our own controllable font subsystem is much safer.

> Another possibility would be to render only into PDF and convert the PDF
> file into TIFF with ghostscript. You should also get identical results
> that way.
> 
> Vincent

Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to