Help save net neutrality! Learn more.

Missing spaces after some chars with Frutiger 45/55/65 Unicode TTF and Firefox

  • cpw

    cpw - 2013-03-21


    I ran into an odd problem with TCPDF 6.0.002 and Firefox's (19.0.2) internal PDF-viewer when using an unicode TTF of Frutiger 45/55/65 (the "standard"-version Win/TT from and I'm not sure if the problem is Firefox, TCPDF, the font or some combination of all three:

    First of all I converted my TTFs with addTTFfont:

    TCPDF::addTTFfont($fontfile="./fontimport/frutiger45.ttf", $fonttype = 'TrueTypeUnicode', $enc = '', $flags = 32, $outpath = '', $platid = 3, $encid = 1, $addcbbox = false);


    $pdf = new TCPDF($orientation = "P", $unit = "mm", $format = "A4", $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false);
    $pdf->setFontSubsetting(false);     // Required for Firefox; it doesn't seem to like font-subsetting
    $pdf->AddPage("P", "A4");
    $pdf->SetXY(19.8, 110, true);
    $pdf->SetTextColor(000, 000, 000);
    $pdf->Cell($width = 32, $height = 3.1, $text = "This is text in Frutiger 45 äöüß & something ! ' § $ % & / ( ) = ? abcd", $border = 0,  $ln = 1, $align = "L");

    (The PHP-source's encoding is UTF-8)

    Adobe Reader X (10.1.6) and Chrome's internal PDF-renderer show this text as expected.

    The problem:

    The internal PDF-Renderer in Firefox does not show any/enough space(s) between some chars like the ampersand, the dollar- and the percentage-char. The percentage-char and the ampersand even collide. Other "special" chars (§, /, (, ), =, ?) do have a correct spacing behind them:

    Adobe Reader - Firefox

    First of all this seemed to be a bug in Firefox, but while trying different things I found some oddities:

    1. If I don't set a specific font, everything is fine in both viewers - so here it looks like the problem is the font or its conversion.

    2. If I import/add the font file as "TrueType" instead of "TrueTypeUnicode" (or just change $type in the PHP font-file accordingly), the spacings are correct in both viewers. Next odd thing here: Adobe Reader neither shows the german "umlauts" ä, ö and ü nor the sz-ligature ß - which is to be expected because of a wrong encoding (ISO-8859 vs. UTF-8). Surprisingly Firefox does show these chars...

    3. If I run my testscript in FPDF 1.7 (with slight syntactic changes to the TCPDF syntax) - importing the font there and converting the string from UTF-8 to ISO-8859-1 with iconv() - there are no problems with missing spaces or umlauts. So here it seems this problem is somehow specific to some changes/additions in TCPDF?

    I'm using a german Windows 7 x64 if that matters in some way.

    Any suggestions?

    Last edit: cpw 2013-03-21
  • Liam Vans

    Liam Vans - 2013-03-21

    I can confirm this, not only in FireFox but also in Safari and Chrome in my case. Some of it was fixed in 6.0003 but it's still far from ideal. Try the euro sign for instance, same thing.

  • cpw

    cpw - 2013-03-21

    I just switched to .003 and re-added/-converted the fonts - no changes here.

    For me the problem neither occurs in Chrome (25.0.1364.172 m) nor in Safari (5.1.7 (7534.57.2)) - the €-sign in Firefox is OK as well...

    I also narrowed the problematic characters down: From all characters on my (german) keyboard it's just

    # $ % &

    all the others seem to be OK.

    Which leads me to a pattern:

    Theses characters are direct "neighbours" in as well as :

    # 0x0023 (35 Decimal)

    $ 0x0024 (36 Decimal)

    % 0x0025 (37 Decimal)

    & 0x0026 (38 Decimal)

    ...although I'm not sure what to make of that.

    Last edit: cpw 2013-03-21
  • Nicola Asuni

    Nicola Asuni - 2013-03-21

    Is the doument working witht the default fonts?
    Additionally, are you sure that all characters are correctly encoded in UTF-8?

    Last edit: Nicola Asuni 2013-03-21
  • cpw

    cpw - 2013-03-21

    Is the doument working witht the default fonts?

    First I tried setting no font at all, now I also tried





    Everything is perfectly fine with these fonts.

    Additionally, are you sure that all characters are correctly encoded in UTF-8?

    Yes - I'm using an Eclipse-setup with all editors set to UTF-8. If the source-encoding was wrong, it should fail en-/decoding ä,ö,ü and ß.

    Last edit: cpw 2013-03-21
  • cpw

    cpw - 2013-03-22

    Some other testing to make things even more weird: ;-)

    Frutiger 55 (Roman) is OK - of the three Frutiger fonts I own, only 45 (Light) and 65 (Bold) are having the space-problems in Firefox.

    I converted my Windows 7 Arial - everything is fine with that.

    If I use to convert Frutiger 45 (resulting in a .afm-file instead of a .ctg.z next to the .z- and .php-file), it's fine. If I convert Frutiger 55 here, there's a space missing behind the dollar char - in Firefox and Adobe Reader.

    Furthermore I'd like to try some other commercial fonts I own, like Neue Helvetica 35 and 45, but they are in OpenType-(.otf-)Format. On the one hand states that OpenType is supported, on the other hand the docs for addTTFFont() ( ) do not mention OpenType - if I run addTTFfont() on an .otf-file, it finishes without any error message, but the result is just a .z File, the CIDToGIDMap (.ctg.z) and the font definition PHP-file are missing and I can't use the font.

    // EDIT: I just noticed there's a version .004 now - I'll give that a try.

    // EDIT 2: No, still the same.

    Last edit: cpw 2013-03-22
  • cpw

    cpw - 2013-03-22

    It seems to have something to do with $type = 'TrueType' vs. $type = 'TrueTypeUnicode'.

    I compared the TCPDF generated font-PHP-file to the one generated by Next to some different contents in $desc and $cw the type is "TrueType" instead of "TrueTypeUnicode" and $enc is set to "cp1252". Setting this in the TCPDF generated file nearly works - now it's just the Euro-sign € that has no space behind it, in Firefox as well as in Chrome and Adobe Reader.

  • Liam Vans

    Liam Vans - 2013-03-22

    The problem with OpenType fonts is that they are not supported, unless they're in TrueType format. The OpenType standard does not specify the outline data format. Rather, it accommodates any of several existing standards. Sometimes terms like "OpenType (PostScript flavor)", "Type 1 OpenType", "OpenType CFF", or "OpenType (TrueType flavor)" are used to indicate which outline format a particular OpenType font file contains. Only the OpenType TrueType flavor is supported by TCPDF, rendering the use of OpenType fonts next to useless.

    The reason why the addTTFFont function returns nothing can be found here: It's becuase you are using a CFF font. The first 4 characters in a OpenType CFF font are 'OTTO', you can recognise them by that.

    I've noticed that even some TrueType fonts are not supported by TCPDF, that's why I always convert my fonts to PFB/AFM first and then use them in TCPDF. Annoying, but so... At least this works.

    The Euro sign thingy, that's a bug for sure. The encoding tables used in TCPDF are the cause of that I think.

    Last edit: Liam Vans 2013-03-22
  • cpw

    cpw - 2013-03-23

    that's why I always convert my fonts to PFB/AFM first and then use them in TCPDF. Annoying, but so... At least this works.

    Not for me I'm afraid... What converter do you use for that?

    My first attempt was ttf2pt1 from the GnuWin32-package ( ) called with the b-Option:

    ttf2pt1 -b "D:\frutiger45.ttf"

    The results are a PFB- an an AFM-file. Processing the PFB-File with addTTFfont() (regardless if $fonttype left blank for auto detection or explicitly set to Type1) gives me a notice:

    Notice: Undefined offset: 0 in D:\workspace\theproject\tcpdf\include\tcpdf_fonts.php on line 331

    creates a .z- and a broken PHP-font-description-file:

    $desc=array('Flags'=>32,'FontBBox'=>'[-31 -250 1000 911]','ItalicAngle'=>0,'Ascent'=>911,'Descent'=>-250,'Leading'=>0,'CapHeight'=>720,'XHeight'=>0,'StemV'=>70,'StemH'=>55,'AvgWidth'=>-35,'MaxWidth'=>75,'MissingWidth'=>);

    without a closing PHP-Tag (?>), so it seems to stop outputting at some point.

    Next I tried FontForge, opening my TTF and generating it as PS Type 1 (Binary):

    Your font has a 2 byte encoding, but you are attempting to save it in a format that only supports one byte encodings. This means that you won't be able to access anything after the first 256 characters without reencoding the font.

    The resulting PFB-file imports without any notices, the PDF-Result is as in the attached screenshot.

    The only other FontForge output format with a PFB-extension is PS Type 1 (Multiple). While creating it asks for a "sub font definition file", whatever that might be.

    // EDIT:

    Also no luck with, and Either addTTFFont() returns FALSE or I end up with nearly no spaces at all (see attachment).

    Funny thing: I can't find another TTF having the problem with missing spaces... I also used to convert my other Linotype-OTF-Fonts (Neue Helvetica 35 & 45, Trade Gothic Light) to TTF and imported them - no problems here.

    Last edit: cpw 2013-03-24
  • Liam Vans

    Liam Vans - 2013-03-25

    I use ttf2pt1 also, try this:

    ttf2pt1 -l latin1 -F -b "D:\frutiger45.ttf"

    The missing spaces can be solved by adding them to the translation tables. Sometimes character 32 is set als 'null' or 'nbrspace'. Change that to 'space' and that'll solve that issue.

  • cpw

    cpw - 2013-03-25

    No, definitively doesn't work and does exactly the same thing as before: a notice and a broken PHP-file with missing values as a description. I also tried this with various other converted TTFs, it's always the same.

    Anyway it seems I found a solution:

    I compared the generated PHP-files of Frutiger 45 (doesn't work properly) and 55 (works fine): I noticed that the value of 0 in the $cw-array is 500 in Frutiger 45, 278 in Frutiger 55. So I changed this value to 278 in Frutiger 45 - now there are spaces where they belong.

    Although I don't really get what's happening there - in what way does the NUL-value have an influence on spaces after exactly four characters (35 to 38)? And why only in Firefox?

    Last edit: cpw 2013-03-25
  • Nicola Asuni

    Nicola Asuni - 2013-03-26

    Did you try to convert the font using AddTTFFont and setting all the correct values for the Type1 font?

  • cpw

    cpw - 2013-03-27

    First I converted the TTF to PTB/AFM with ttf2pt1 like Liam suggested:

    ttf2pt1 -l latin1 -F -b "D:\arial.ttf"

    (I tried Arial coming with Windows 7 and several other TTFs to be sure the problems aren't caused by a potentially broken Frutiger-font)

    My import script for the resulting PFB looks like this:

    $pdf = new TCPDF("P", "mm", "A4");
    var_dump($pdf->addTTFfont($fontfile="./fontimport/arial.pfb", $fonttype = 'Type1', $enc = '', $flags = 32, $outpath = '', $platid = 3, $encid = 1, $addcbbox = false));     

Log in to post a comment.