Menu

#956 Monospaced fonts are not alignd at the baseline

v1.0_(example)
closed
nobody
None
1
2015-02-14
2014-07-29
No

Hello!
If I use a monospaced font inbetween other fonts, they are not aligned at their baselines.
See the attached screenshot and PDF for details. Using Write() and writeHTML() both produce the same error. I'm however not sure why they don't start on the same X-position, this might be another bug.

<?
include '../vendor/autoload.php';

$pdf = new TCPDF();

$pdf->addPage();
$html = 'Normal <span style="font-family: monospace">Monospace</span> Normal <span style="font-family: serif">Serif</span> Normal';

$pdf->writeHTML($html, true, false, true, false, 'L');

$pdf->Write(0, 'Normal ');

$pdf->SetFont('courier');
$pdf->Write(0, 'Monospace');

$pdf->SetFont('helvetica');
$pdf->Write(0, ' Normal ');

$pdf->SetFont('times');
$pdf->Write(0, 'Serif');

$pdf->SetFont('helvetica');
$pdf->Write(0, ' Normal');

$pdf->Output('monotest.pdf', 'F');
?>
2 Attachments

Discussion

  • Nicola Asuni

    Nicola Asuni - 2014-08-02

    This seems happening only with the courier font and not with other default monospaced fonts. Probably some metrics in the courier font are not quite right.

     
  • Nikolai Neff

    Nikolai Neff - 2014-08-03

    It also happens with Computer Modern Typewriter (see here for font files: http://cm-unicode.sourceforge.net/)

     
  • Nikolai Neff

    Nikolai Neff - 2014-08-05

    I'm having trouble finding unaffected fonts.

    At least these monospaced fonts are displayed above the baseline:
    Anonymous Pro
    Courier
    Computer Modern Typewriter
    Consolas
    FreeMono
    Lekton
    SaxMono

    Displayed below the baseline:
    DroidSansMono

    Not affected (as far as I can tell):
    DejaVu Mono
    UbuntuMono

     
  • Nikolai Neff

    Nikolai Neff - 2014-08-06

    A really, really bad workaround would be to manually set a lower Y-Position for the misaligned text and then retuning it afterwards, as the less-dirty (but still bad) CSS-Version using "vertical-align" has no effect.

    <?php
    $html = 'TEXT1 <span style="vertical-align: -10px;">SUB</span> TEXT2';
    
    $pdf->writeHTML($html, false, false, true);
    $x = $pdf->GetX();
    $pdf->SetY($pdf->GetY() +1);
    $pdf->SetX($x);
    
    $pdf->Write(0, 'TEXT3');
    
    $x = $pdf->GetX();
    $pdf->SetY($pdf->GetY() -1);
    $pdf->SetX($x);
    
    $pdf->Write(0, 'TEXT4');
    
     
  • Nicola Asuni

    Nicola Asuni - 2014-08-08

    Seems that the issue is caused by the "Ascent" and "Descent" values in the $desc array in courier.php font description file.
    You can manually adjust them to fix the issue.

     
  • Nicola Asuni

    Nicola Asuni - 2014-08-08
    • status: open --> pending
     
  • Nicola Asuni

    Nicola Asuni - 2014-09-01
    • status: pending --> closed
     
  • Nicola Asuni

    Nicola Asuni - 2014-09-01

    OK. Fixed in TCPDF 6.0.092.
    Thank you for reporting this issue.

     
  • Rainer Perske

    Rainer Perske - 2015-02-14

    I'm sorry: A fresh installed TCPDF 6.2.6 shows exactly this problem with the courier font. The files courier*.php in tcpdf/fonts are dated Oct 2, 2011. Perhaps 6.2.6 contains the uncorrected font files?

     

Log in to post a comment.