字符到字形映射表

发布于 2024-10-22 04:57:07 字数 4970 浏览 11 评论 0原文

我正在关注 apple.com 上的文档

我设法获得了“cmap”编码子表。我知道 platformID、platformSpecificID 100% 是正确的,但 offset 是可疑的。数据如下:

array(3) {
  [0]=>
  array(3) {
    ["platform_id"]=>
    int(0)
    ["specific_id"]=>
    int(3)
    ["offset"]=>
    int(532)
  }
  [1]=>
  array(3) {
    ["platform_id"]=>
    int(1)
    ["specific_id"]=>
    int(0)
    ["offset"]=>
    int(28)
  }
  [2]=>
  array(3) {
    ["platform_id"]=>
    int(3)
    ["specific_id"]=>
    int(1)
    ["offset"]=>
    int(532)
  }
}

两个表的偏移量相同,532。谁能给我解释一下吗?这是从当前位置还是从文件开头的偏移量?

第 2 部分

好的。因此,我设法使用以下命令获取 format 表:

private function parseCmapTable($table)
{
    $this->position         = $table['offset'];

    // http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html
    // General table information

    $data   = array
    (
        'version'           => $this->getUint16(),
        'number_subtables'  => $this->getUint16(),
    );

    $sub_tables = array();

    for($i = 0; $i < $data['number_subtables']; $i++)
    {

        // http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html
        // The 'cmap' encoding subtables

        $sub_tables[]   = array
        (
            'platform_id'       => $this->getUint16(),
            'specific_id'       => $this->getUint16(),
            'offset'            => $this->getUint32(),
        );

    }

    // http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html
    // The 'cmap' formats

    $formats                = array();

    foreach($sub_tables as $t)
    {
        // http://stackoverflow.com/questions/5322019/character-to-glyph-mapping-table/5322267#5322267

        $this->position = $table['offset'] + $t['offset'];

        $format = array
        (
            'format'                    => $this->getUint16(),
            'length'                    => $this->getUint16(),
            'language'                  => $this->getUint16(),
        );

        if($format['format'] == 4)
        {
            $format     += array
            (
                'seg_count_X2'                  => $this->getUint16(),
                'search_range'                  => $this->getUint16(),
                'entry_selector'                => $this->getUint16(),
                'range_shift'                   => $this->getUint16(),
                'end_code[segCount]'            => $this->getUint16(),
                'reserved_pad'                  => $this->getUint16(),
                'start_code[segCount]'          => $this->getUint16(),
                'id_delta[segCount]'            => $this->getUint16(),
                'id_range_offset[segCount]'     => $this->getUint16(),
                'glyph_index_array[variable]'   => $this->getUint16(),
            );

            $backup = $format;

            $format['seg_count_X2']     = $backup['seg_count_X2']*2;
            $format['search_range']     = 2 * (2 * floor(log($backup['seg_count_X2'], 2)));
            $format['entry_selector']   = log($backup['search_range']/2, 2);
            $format['range_shift']      = (2 * $backup['seg_count_X2']) - $backup['search_range'];
        }

        $formats[$t['offset']]  = $format;
    }       

    die(var_dump( $sub_tables, $formats ));

输出:

array(3) {
[0]=>
  array(3) {
    ["platform_id"]=>
    int(0)
    ["specific_id"]=>
    int(3)
    ["offset"]=>
    int(532)
  }
  [1]=>
  array(3) {
    ["platform_id"]=>
    int(1)
    ["specific_id"]=>
    int(0)
    ["offset"]=>
    int(28)
  }
  [2]=>
  array(3) {
    ["platform_id"]=>
    int(3)
    ["specific_id"]=>
    int(1)
    ["offset"]=>
    int(532)
  }
}
array(2) {
  [532]=>
  array(13) {
    ["format"]=>
    int(4)
    ["length"]=>
    int(658)
    ["language"]=>
    int(0)
    ["seg_count_X2"]=>
    int(192)
    ["search_range"]=>
    float(24)
    ["entry_selector"]=>
    float(5)
    ["range_shift"]=>
    int(128)
    ["end_code[segCount]"]=>
    int(48)
    ["reserved_pad"]=>
    int(58)
    ["start_code[segCount]"]=>
    int(64)
    ["id_delta[segCount]"]=>
    int(69)
    ["id_range_offset[segCount]"]=>
    int(70)
    ["glyph_index_array[variable]"]=>
    int(90)
  }
  [28]=>
  array(3) {
    ["format"]=>
    int(6)
    ["length"]=>
    int(504)
    ["language"]=>
    int(0)
  }
}

现在,我如何从这里获取字符 Unicode 代码?我尝试阅读文档,但对于新手来说太模糊了。

http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html

I am following the documentation on apple.com.

I managed to get The 'cmap' encoding subtables. I know 100% that platformID, platformSpecificID are correct, but offset is suspicious. Here is the data:

array(3) {
  [0]=>
  array(3) {
    ["platform_id"]=>
    int(0)
    ["specific_id"]=>
    int(3)
    ["offset"]=>
    int(532)
  }
  [1]=>
  array(3) {
    ["platform_id"]=>
    int(1)
    ["specific_id"]=>
    int(0)
    ["offset"]=>
    int(28)
  }
  [2]=>
  array(3) {
    ["platform_id"]=>
    int(3)
    ["specific_id"]=>
    int(1)
    ["offset"]=>
    int(532)
  }
}

Offset for two tables is the same, 532. Can anyone explain me this? And is this offset from current position or from the beginning of the file?

part 2

Ok. So I managed to get to the format tables using this:

private function parseCmapTable($table)
{
    $this->position         = $table['offset'];

    // http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html
    // General table information

    $data   = array
    (
        'version'           => $this->getUint16(),
        'number_subtables'  => $this->getUint16(),
    );

    $sub_tables = array();

    for($i = 0; $i < $data['number_subtables']; $i++)
    {

        // http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html
        // The 'cmap' encoding subtables

        $sub_tables[]   = array
        (
            'platform_id'       => $this->getUint16(),
            'specific_id'       => $this->getUint16(),
            'offset'            => $this->getUint32(),
        );

    }

    // http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html
    // The 'cmap' formats

    $formats                = array();

    foreach($sub_tables as $t)
    {
        // http://stackoverflow.com/questions/5322019/character-to-glyph-mapping-table/5322267#5322267

        $this->position = $table['offset'] + $t['offset'];

        $format = array
        (
            'format'                    => $this->getUint16(),
            'length'                    => $this->getUint16(),
            'language'                  => $this->getUint16(),
        );

        if($format['format'] == 4)
        {
            $format     += array
            (
                'seg_count_X2'                  => $this->getUint16(),
                'search_range'                  => $this->getUint16(),
                'entry_selector'                => $this->getUint16(),
                'range_shift'                   => $this->getUint16(),
                'end_code[segCount]'            => $this->getUint16(),
                'reserved_pad'                  => $this->getUint16(),
                'start_code[segCount]'          => $this->getUint16(),
                'id_delta[segCount]'            => $this->getUint16(),
                'id_range_offset[segCount]'     => $this->getUint16(),
                'glyph_index_array[variable]'   => $this->getUint16(),
            );

            $backup = $format;

            $format['seg_count_X2']     = $backup['seg_count_X2']*2;
            $format['search_range']     = 2 * (2 * floor(log($backup['seg_count_X2'], 2)));
            $format['entry_selector']   = log($backup['search_range']/2, 2);
            $format['range_shift']      = (2 * $backup['seg_count_X2']) - $backup['search_range'];
        }

        $formats[$t['offset']]  = $format;
    }       

    die(var_dump( $sub_tables, $formats ));

The output:

array(3) {
[0]=>
  array(3) {
    ["platform_id"]=>
    int(0)
    ["specific_id"]=>
    int(3)
    ["offset"]=>
    int(532)
  }
  [1]=>
  array(3) {
    ["platform_id"]=>
    int(1)
    ["specific_id"]=>
    int(0)
    ["offset"]=>
    int(28)
  }
  [2]=>
  array(3) {
    ["platform_id"]=>
    int(3)
    ["specific_id"]=>
    int(1)
    ["offset"]=>
    int(532)
  }
}
array(2) {
  [532]=>
  array(13) {
    ["format"]=>
    int(4)
    ["length"]=>
    int(658)
    ["language"]=>
    int(0)
    ["seg_count_X2"]=>
    int(192)
    ["search_range"]=>
    float(24)
    ["entry_selector"]=>
    float(5)
    ["range_shift"]=>
    int(128)
    ["end_code[segCount]"]=>
    int(48)
    ["reserved_pad"]=>
    int(58)
    ["start_code[segCount]"]=>
    int(64)
    ["id_delta[segCount]"]=>
    int(69)
    ["id_range_offset[segCount]"]=>
    int(70)
    ["glyph_index_array[variable]"]=>
    int(90)
  }
  [28]=>
  array(3) {
    ["format"]=>
    int(6)
    ["length"]=>
    int(504)
    ["language"]=>
    int(0)
  }
}

Now, how do I get from here, to getting character Unicode codes? I tried reading the documentation, but it is too vague for a novice.

http://developer.apple.com/fonts/ttrefman/RM06/Chap6cmap.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栩栩如生 2024-10-29 04:57:07

偏移量是从表的开头开始的。您的数据表明 Mac 表 (platformId 1) 从偏移量 28 开始,而 Unicode (platformId 0) 和 Windows (platformId 3) 映射共享从字节偏移量 532 开始的同一个表。

The offset is from the beginning of the table. What your data is saying is that the Mac table (platformId 1) starts at offset 28, while the Unicode (platformId 0) and Windows (platformId 3) mappings share the same table that starts at byte offset 532.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文