ok, i found a solution:

   // this is the mapper to use when creating the Graphics2D
   lazy val fontMapper = {
      val res = new DefaultFontMapper()
      val parameters = new DefaultFontMapper.BaseFontParameters( new File( 
userFontDir, fontFile ).getAbsolutePath )
      parameters.encoding = BaseFont.IDENTITY_H
      res.putName( fontName, parameters )
      res
   }

   // this is AWT font to set for JFreeChart
   lazy val font = {
      val bf = BaseFont.createFont( new File( userFontDir, fontFile 
).getAbsolutePath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED )
      fontMapper.pdfToAwt( bf, 10 )
   }

  then

      val g2   = tp.createGraphics( width, height, fontMapper )


i'm not sure why there seems to be no translation between BaseFont and 
BaseFontParameters, so that i seem to be doing redundant things here by 
referring twice to the font file...?

best, -sciss-



On 22 Mar 2011, at 16:03, Sciss wrote:

> hi,
> 
> i need some help with a combo of JFreeChart and iTextPDF. Whenever I export 
> my charts as PDFs, I end up with files that use Helvetica all across the 
> place.
> 
> my initial approach was
> 
>   def createPDF( file: File, chart: JFreeChart, width: Int, height: Int ) {
>      val pageSize = new IRectangle( 0, 0, width, height )
>      val doc      = new IDocument( pageSize, 0, 0, 0, 0 )
>      val stream   = new FileOutputStream( file )
>      val writer   = PdfWriter.getInstance( doc, stream )
>      doc.open()
>      val cb      = writer.getDirectContent
>      val tp      = cb.createTemplate( width, height )
>      val g2      = tp.createGraphics( width, height )
>      val r2      = new Rectangle2D.Double( 0, 0, width, height )
>      chart.draw( g2, r2 )
>      g2.dispose
>      cb.addTemplate( tp, 0, 0 )
>      doc.close
>   }
> 
> i'm trying to set the AWT font like this
> 
>     val fontName = "Gulim"   // tried different ones, problem is not specific 
> to this one
> 
>      val axis = new CategoryAxis()
>      axis.setTickLabelFont( new Font( fontName, Font.PLAIN, 10 ))
>      plot.setDomainAxis( axis )
> 
> looking around on StackOverflow, i tried different things, like
> 
>   // my own ttfs and otfs are in here:
>     def userFontDir : File = new File( new File( System.getProperty( 
> "user.home" ), "Library" ), "Fonts" )
> 
>      val fntMap     = new DefaultFontMapper()
>      fntMap.insertDirectory( userFontDir.getAbsolutePath )
> 
> and
> 
>     FontFactory.registerDirectories()
> 
> and
> 
>     val fontFile = "Gulim.ttf"
>      fntMap.putName( fontName, new DefaultFontMapper.BaseFontParameters( new 
> File( userFontDir, fontFile ).getAbsolutePath ))
> 
> and
> 
>     writer.setAtLeastPdfVersion( PdfWriter.VERSION_1_7 )
> 
> ...
> 
> No luck, output PDF still shows Helvetica (I tried in Preview, Acrobat Pro 
> and Inkscape, all the same, Acrobat Doc info says the only font in the PDF is 
> Helvetica).
> The only thing that changes is the kerning which apparently comes from the 
> font I want, so it looks even more awful.
> 
> 
> Thanks for hints!
> 
> best, -sciss-
> 
> 
> ------------------------------------------------------------------------------
> Enable your software for Intel(R) Active Management Technology to meet the
> growing manageability and security demands of your customers. Businesses
> are taking advantage of Intel(R) vPro (TM) technology - will your software 
> be a part of the solution? Download the Intel(R) Manageability Checker 
> today! http://p.sf.net/sfu/intel-dev2devmar
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 
> iText(R) is a registered trademark of 1T3XT BVBA.
> Many questions posted to this list can (and will) be answered with a 
> reference to the iText book: http://www.itextpdf.com/book/
> Please check the keywords list before you ask for examples: 
> http://itextpdf.com/themes/keywords.php


------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to