prawnpdf/ttfunk — pull request #22 by javan (2014-09-20 20:04:14+00:00)
Title: Parse bitmap data from sbix tables

I set out to find an effective way of extracting emoji images from Apple's "Apple Color Emoji.ttf" font, and found that the data necessary data is in the [sbix table](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6sbix.html).

> This table provides access to bitmap data in a standard graphics format (such as PNG, JPEG, TIFF).

```ruby
emoji_font = Pathname.new("/System/Library/Fonts/Apple Color Emoji.ttf")
ttf = TTFunk::File.open(emoji_font)

char_code = "\u{1f4a9}".codepoints.first
glyph_id = ttf.cmap.unicode.first.code_map[char_code]

ttf.sbix.all_bitmap_data_for(glyph_id).each do |bitmap|
filename = "glyph-#{glyph_id}-#{bitmap.ppem}.#{bitmap.type}"
File.write(filename, bitmap.data.read)
end
```

![glyph-569-160](https://cloud.githubusercontent.com/assets/5355/4346458/6a702a74-4100-11e4-97ec-08aab6567cfd.png)![glyph-569-96](https://cloud.githubusercontent.com/assets/5355/4346456/6a652264-4100-11e4-86a3-c8355163d157.png)![glyph-569-64](https://cloud.githubusercontent.com/assets/5355/4346454/6a62da2c-4100-11e4-8813-ffbc6db81064.png)![glyph-569-48](https://cloud.githubusercontent.com/assets/5355/4346457/6a67d810-4100-11e4-89d5-1ec7408061ea.png)![glyph-569-40](https://cloud.githubusercontent.com/assets/5355/4346452/6a5c6412-4100-11e4-8b00-80703a596bc8.png)![glyph-569-32](https://cloud.githubusercontent.com/assets/5355/4346455/6a638792-4100-11e4-8eae-b13283f24676.png)![glyph-569-20](https://cloud.githubusercontent.com/assets/5355/4346453/6a5ee96c-4100-11e4-9bbe-0305545aa084.png)