Donate Share

TCPDF - PHP class for PDF

The forum address has changed, you have been automatically redirected. Please update any bookmarks to use the new URL.

Subscribe

Using font files?

  1. nobody

    2006-12-11 22:31:12 UTC
    Hi,

    I've been trying to realize how to use some font files I have here. In short I'm creating a simple PDF, but I need to use a specific font. I have some files which are fonts of type "Postscript Type 1". Having read the feature list of TCPDF I understand that this is/should be supported :)

    But I'm at loss on how to use these files.. The Documentation for TCPDF->AddFont() says "Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility". Reading this it seems this is the place to import my font, but it says that I need to generate some definitions using the utility I believe is makefontuni.php.

    I have looked at makefontuni.php and read some of its code, part of which is:

    function MakeFont($fontfile,$ufmfile)
    {
    //Generate a font definition file
    set_magic_quotes_runtime(0);
    if(!file_exists($ufmfile))
    die('<B>Error:</B> UFM file not found: '.$ufmfile);
    $cidtogidmap = '';
    $fm=ReadUFM($ufmfile, $cidtogidmap);
    $fd=MakeFontDescriptor($fm);
    //Find font type
    if($fontfile)
    {
    $ext=strtolower(substr($fontfile,-3));
    if($ext=='ttf')
    $type='TrueTypeUnicode';
    else
    die('<B>Error:</B> not a truetype font: '.$ext);
    }
    else
    {
    if($type!='TrueTypeUnicode')
    die('<B>Error:</B> incorrect font type: '.$type);
    }

    Looking at this i don't see how it can ever continue execution beyond this unless it is given a TTF file (this because in the else-statement, $type is checked and, as far as I can see in the rest of the code, it will not be "TrueTypeUnicode", and the die() will execute. And if we give it ($fontfile) a file which is not .ttf then it will die() also..).

    So, could someone please give me some hints on how i should/can use my Type 1 font files in TCPDF?

    A couple of starting questions (have Googled, but without much luck):
    1) What is this UFM that is mentioned quite a lot? TTF seems to be a font file format, which I would also guess Type 1 to be, but is Type 1 and UFM the same?
    2) What's this Font Suitcase thing? Do I need it to use my font file with TCPDF? If so, in what way/how?

    I truly appreciate any pointers/help! Thank you :)

    // Leo
  2. 2006-12-14 15:14:26 UTC
    I'm sorry, makefont.php was missing.

    I've just released the TCPDF 1.53.0.TC027 that contains the old files to build type1 font descriptions. Please check the /fonts/old/makefont/ folder.
  3. nobody

    2006-12-21 20:28:23 UTC
    Hello again,

    I'm sorry to say that I've been unsuccessful in all my attempts at getting my fonts usable with TCPDF :/

    First off I realized that the font information of the files I have in OS X are stored in the resource fork of the files, and I didn't know how to get that info into a data-fork-only file, so that PHP could read it. I finally did a `cp FontFile/rsrc NewFontFile, and it at least put some contents into the new file. When I ran this through makefont.php though, using MakeFont('', NewFontFile, ''), ReadAFM() says "FontName not found". This pretty much made me give up hope as of now, and move on to trying to get a simple TTF font usable, using the instructions from/with makefontuni.php.

    As I'm on OS X and neither ttf2ufm.exe nor ttf2ufm (the binary) works here I fired up Virtual PC. I first tried using a ACaslonPro-Regular.otf (OpenType font), calling it like: `ttf2ufm -a -F ACaslonPro-Regular.otf`. This gave me "Can't detect front-end parser, using 'bdf' by default. ... ****file does not contain the CHARS definition". I tried again using: `ttf2ufm -a -F -p ttf ACaslonPro-Regular.otf`, but of course this didn't work, I got: "****Unknown File Version number [4f54544f], or not a TrueType file". This file is in Linotype FontExplorer X marked as "OpenType (PostScript flavored)".

    I retried the previous thing using a .ttf-file I got by doing `cp ComicSansMS/rsrc > ComicSansMS.ttf`, but I got almost the same error message, "****Unknown File Version number [10000], or not a TrueType file". This file is in Linotype FontExplorer X marked as "TrueType (Mac)".

    I then tried `ttf2ufm -a -F Chalkboard.ttf`, a from-the-start .ttf-file, and this seems to have worked with ttf2ufm. I got some new files, same basename but suffixes .afm, .t1a, .ufm. Then I ran `makefontuni.php Chalkboard.ttf Chalkboard.ufm`, and got "Font file compressed (Chalkboard.z), CIDToGIDMap created and compressed (Chalkboard.ctg.z), Font definition file generated (Chalkboard.php)", i.e. a positive reply. However, using this font with AddFont() and SetFont() only gets me a square box for each char (which is plain a-z) when I try it out.

    Can someone please help me out? My main question right now is: Howcome my Chalkboard test doesn't display any chars?
    Also I'm still a bit lost as to what exactly I need to do, and what (kind of) files I need to, be able to use custom Type 1 fonts with TCPDF. To sum it up i only got half-way with a true TTF, nothing with Type 1 yet.
  4. nobody

    2006-12-21 22:02:32 UTC
    Hmm, perhaps a bit closer to my goal..

    I downloaded FontForge (http://fontforge.sourceforge.net/), opened my font file and selected Generate Font from the File menu. Here I got to choose generating a Type 1 font and that an AFM file should be generated. So I did, and was then able to run makefont.php (in the old/makefont/ folder), and got a .php-file for my font. It seems though that theres a whole bunch of (I guess glyph, or something like that) references like: chr(x)=>, chr(y)=>, i.e. where the value of the reference in the $cw array isn't present. I'm not sure what this means or what I should do about it, I'll continue to play around in FontForge to see if there's anything there to do, or I'll try just adding something to the references..
  5. nobody

    2006-12-22 13:20:48 UTC
    Yay, using FontForge I've been able to generate TTF files for the fonts I have tried so far, and then used ttf2ufm to create a .ufm file, and then makefontuni.php <ttf> <ufm> to get the .z, .ctg.z and .php files and then successfully use them in my PDF. It seems that the old tool, makefont.php, doesn't handle Unicode at all? Or I'm just lost. In any case, if generating TTF from Type1 using FontForge doesn't screw up the fonts or anything, I guess this is the way to go.

    One thing though, is it possible to build a non-Windows binary of the ttf2ufm sources? I couldn't find "ttf2ufm" in anywhere but once in winbuild.bat. If possible, how? Personally I would need an OS X and FreeBSD binary :9
< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.