Menu

Invisible emoji font

Help
Anders
2014-11-18
2014-11-18
  • Anders

    Anders - 2014-11-18

    I am trying to use https://github.com/MorbZ/OpenSansEmoji for rendering emoji that can easily be input on an iPad.

    This test program shows two issues:
    1) The OpenSansEmoji font does not render any glyphs at all.
    2) The emoji character U+1F60A (smiling face in iOS) is apparently rendered as two glyphs, making it unlikely that it would render correctly, even if the OpenSansEmoji font was visible.

    What am I doing wrong?

    Tested on tcpdf_6_0_099.

    <?php
    
    date_default_timezone_set('UTC');
    
    require_once('tcpdf/tcpdf.php');
    
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->AddPage();
    
    $emoji = json_decode('"Heart:\u2665 Snowman:\u2603 Smile:\ud83d\ude0a"');
    
    foreach (array('OpenSansEmoji.ttf', 'Arial.ttf') as $i => $ttf) {
        $fontname = $pdf->addTTFfont($ttf, 'TrueTypeUnicode', '', 32);
    
        $pdf->SetFont('helvetica', '', 14);
        $pdf->Text(50,100+25*$i, $ttf);
    
        $pdf->SetFont($fontname, '', 14);
        $pdf->Text(100,100+25*$i, $emoji);
    }
    
    $pdf->Output('emoji.pdf', 'F');
    
    ?>
    
     
  • Jim Hanlon

    Jim Hanlon - 2014-11-18

    I'm going to guess that there are assumptions in the TCPDF TrueType parsing code , and maybe even the Unicode string handling code more generally, that cause it to only consider glyphs in the "basic multilingual plane" BMP) of a Unicode encoded font -- i.e. \u0000 to \uFFFF -- the first 64K codepoints. The emoji you are trying to use are in the "supplemental multilingual plane" (SMP) that requires codepoints larger than \uFFFF. I'm guessing that you see "two glyphs" because the codepoint is being handled as two codepoints, not one.

    Hopefully my hunch will be enough that you can poke at the code and find the problem(s).

     

Log in to post a comment.