TienLung has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, I have recently discovered the ability to use 'ttf' fonts when creating a PDF with PDF::API2. Everything seemed to be going very well, until I realised an issue with the kerning. Namely that there is no kerning.
my $headline_text = $page->text; my $tmpFont=$pdf->ttfont("../pdf/API2/fonts/Exmouth.ttf"); $headline_text->font( $tmpFont, 12 / pt ); $headline_text->fillcolor('black'); $headline_text->translate( 95 / mm, 131 / mm ); $headline_text->text_center('Testing Testing');
This correctly embeds the Exmouth ttf font, and correctly uses it. The resulting PDF uses the font (i.e. the letters look ok) however the character spacing is uniform..i.e. no kerning. I have tried various methods, including adding a -dokern option to the font. .. To no avail. Has anyone any experience in embedding ttf fonts? or come up against this issue? Many thanks in advance

Replies are listed 'Best First'.
Re: PDF API2 Kerning
by rpnoble419 (Pilgrim) on Dec 14, 2009 at 21:08 UTC
    Kerning is handled by the application that creates the PDF. That is why when you bring a PDF file into Adobe Illustrator that was created in InDesign or Quark you will see the text line is broken into many smaller text blocks (if the kerning was done by hand). Having done kerning tables for ITC in my past life, you may have to update the TTF font with the kerning you want as the actual pairs may not exist and you are use to seeing "auto Kern" (i hate auto kern). You many want to use FontForge (fontforge.sourceforge.net) or another font editor to view the existing kerning tables. Most fonts ship with a pitiful kerning table. I used to use Fontographer, but it is no longer supported last update 2006, but the company has its FontLab product or a basic font editor you may want to look into (http://www.fontlab.com/font-editor/)

      Fontographer++.

      Many thanks indeed for this reply, I will look into those suggestions straight away
Re: PDF API2 Kerning
by Anonymous Monk on Dec 14, 2009 at 16:55 UTC
      Indeed, that is the Kerning code.. but it isn't working. Someone else I know has got the whole thing working, and they didnt have to change anything. However, somehow using the same ttf file as they are, the kerning is not being applied
        I looked at the docs for PDF::API2::Basic::TTF::Kern, and it seems that it'll read and output to file information on kerning tables 0 and 2. There are no support functions that do anything with the kerning tables at this time. The author calls it a "bug".
Re: PDF API2 Kerning
by Neighbour (Friar) on May 20, 2010 at 06:48 UTC

    Sorry for waking up this old thread :)

    I recently had the same experience with PDF::API2, and some further digging shows that it's not actually a kerning problem....well, maybe kerning is -also- not working properly, but that's not all.
    The ttf-font loader seems to be broken and is ignoring the glyph width information, or something to that effect. This results in any ttf (or otf) font becoming monospaced, even though the font itself isn't.
    Using fontforge to convert the font to a .pfb/.pfm pair and using $pdf->psfont to load those results in proper glyph width usage.

    Maybe someone brave and knowledgeable enough on ttf internals can descend onto PDF/API2/Resource/CIDFont/TrueType/FontFile.pm and fix this.