2011-03-16 147 views
2

我正在關注documentation on apple.com字符映射表映射表

我設法得到The 'cmap' encoding subtables。我知道100%是platformID, platformSpecificID是正確的,但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

回答

2

偏移量是從的開始。您的數據說的是,Mac表(platformId 1)從偏移量28開始,而Unicode(platformId 0)和Windows(platformId 3)映射共享相同的表,從字節偏移量532開始。

+0

謝謝Gabe 。你似乎知道這個東西。你能看看這個問題的第二部分嗎? – Gajus 2011-03-16 12:29:04

+0

@Guy:與其將這個問題變成一個完全不同的問題,請問第二個問題,並張貼各個鏈接。 – Gabe 2011-03-16 13:24:18