dompdf / php-font-lib

A library to read, parse, export and make subsets of different types of font files.
GNU Lesser General Public License v2.1
1.73k stars 256 forks source link

Add support for other `cmap` formats (only format 4 is supported) #40

Open oxygen opened 8 years ago

oxygen commented 8 years ago

https://github.com/google/fonts/tree/master/apache/droidsansjapanese

My code:

$fontFile=\FontLib\Font::load("DroidSansJapanese.ttf");
$fontFile->parse();

$fontFile->setSubset("DroidSansJapanese");
$fontFile->reduce();

$fontFile->open($tmp, FontLib\BinaryStream::modeWrite);
$fontFile->encode(array("OS/2"));
$fontFile->close();

50MB stack trace, didn't include it all:

Invalid argument supplied for foreach()

Array
(
    [0] => Array
        (
            [file] => /mnt/autofs/ExportVHosts/adrese.kakao.ro/PHPFontLib/src/FontLib/Table/Type/cmap.php
            [line] => 129
            [function] => {closure}
            [args] => Array
                (
                    [0] => 2
                    [1] => Invalid argument supplied for foreach()
                    [2] => /mnt/autofs/ExportVHosts/adrese.kakao.ro/PHPFontLib/src/FontLib/Table/Type/cmap.php
                    [3] => 129
                    [4] => Array
                        (

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/30615912-add-support-for-other-cmap-formats-only-format-4-is-supported?utm_campaign=plugin&utm_content=tracker%2F317728&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F317728&utm_medium=issues&utm_source=github).
oxygen commented 8 years ago

I think you might need to set error reporting to E_STRICT (or -1).

PhenX commented 8 years ago

This issue is related to cmap version used in this font. Its format is 12, while the lib only supports the version 4 (see the spec), section "Format 12: Segmented coverage". The code is here : https://github.com/PhenX/php-font-lib/blob/master/src/FontLib/Table/Type/cmap.php#L56

bsweeney commented 6 months ago

Note: formats 2, 4, and 12 are currently supported. I'll look to implement other formats as samples are provided that use them.

Tracking general TrueType support in #123.