php-font-lib icon indicating copy to clipboard operation
php-font-lib copied to clipboard

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

Open oxygen opened this issue 8 years ago • 3 comments

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 avatar Feb 07 '16 01:02 oxygen

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

oxygen avatar Feb 07 '16 01:02 oxygen

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

PhenX avatar Feb 13 '16 15:02 PhenX

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.

bsweeney avatar Jan 11 '24 03:01 bsweeney