php类映射表,php – 字符到字形映射表

我设法获得’cmap’编码子表.我知道100%的platformID,platformSpecificID是正确的,但偏移是可疑的.这是数据:

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部分

好.所以我设法使用这个来到格式表:

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)

{

// https://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代码?我试过阅读文档,但对于新手来说太模糊了.

解决方法:

偏移量来自表格的开头.您的数据所说的是Mac表(platformId 1)从偏移量28开始,而Unicode(platformId 0)和Windows(platformId 3)映射共享从字节偏移量532开始的相同表.

标签:php,opentype,imagettftext

来源: https://codeday.me/bug/20191008/1874178.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值