Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse bitmap data from sbix tables #22

Merged
merged 4 commits into from Sep 20, 2014
Merged

Parse bitmap data from sbix tables #22

merged 4 commits into from Sep 20, 2014

Conversation

@javan
Copy link
Contributor

@javan javan commented Sep 20, 2014

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.

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

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-160glyph-569-96glyph-569-64glyph-569-48glyph-569-40glyph-569-32glyph-569-20

javan added 2 commits Sep 20, 2014
@practicingruby
Copy link
Member

@practicingruby practicingruby commented Sep 20, 2014

Please disregard my original comment. I was looking at some outdated information on wikipedia -- I should have been looking at the page from the Apple reference manual you linked instead. 😊

https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6sbix.html

With that in mind, I think we probably could accept this patch, but please add some tests for it.

@javan
Copy link
Contributor Author

@javan javan commented Sep 20, 2014

Ok, cool. Happy to add some tests. It's probably best to test against a file with an sbix table and the only one that I know of is Apple's emoji font. Do you have any copyright concerns about bundling it in the test suite? If so, do you happen to know of an alternative?

@practicingruby
Copy link
Member

@practicingruby practicingruby commented Sep 20, 2014

@javan: Maybe give this one a try?
https://github.com/MorbZ/OpenSansEmoji

We definitely can't bundle non-free fonts, unfortunately.

@javan
Copy link
Contributor Author

@javan javan commented Sep 20, 2014

OpenSansEmoji doesn't have an sbix table, but I found a sample font here - http://typophile.com/node/103268 - that does. Added some tests.

@practicingruby
Copy link
Member

@practicingruby practicingruby commented Sep 20, 2014

Merged, thank you!

practicingruby added a commit that referenced this pull request Sep 20, 2014
Parse bitmap data from sbix tables
@practicingruby practicingruby merged commit 12926d3 into prawnpdf:master Sep 20, 2014
1 check passed
1 check passed
continuous-integration/travis-ci The Travis CI build passed
Details
@javan
Copy link
Contributor Author

@javan javan commented Sep 20, 2014

🤘

@practicingruby
Copy link
Member

@practicingruby practicingruby commented Sep 21, 2014

@javan: Because your pull request was accepted, you now have commit access to all prawnpdf repositories. See the contribution guidelines for more details, and thanks for the patch!

@javan
Copy link
Contributor Author

@javan javan commented Sep 21, 2014

Cool. Already putting this to work github/gemoji#63 😁

@practicingruby
Copy link
Member

@practicingruby practicingruby commented Sep 21, 2014

@javan: Nice! I'll try to make sure to get a release cut soon, so you can switch back to the rubygems.org version of TTFunk when that happens.

@tremby
Copy link

@tremby tremby commented Oct 13, 2015

I'm trying to shoehorn the Android emoji font into this. I'm not having any luck. I don't know anything about TTF fonts: is it maybe the same issue as above, with this font not having an sbix table?

@DanielZanchi
Copy link

@DanielZanchi DanielZanchi commented May 19, 2016

I'm trying to do extract all the emojis with TTFunk but can't find the way. Can someone help me. What do I have to run from the terminal after installing the gem TTFunk?

@pointlessone
Copy link
Member

@pointlessone pointlessone commented May 20, 2016

@danny182 You can take a look at sbix table specs

@DanielZanchi
Copy link

@DanielZanchi DanielZanchi commented May 20, 2016

@pointlessone , thank you for the reply.
I didn't understand how to run the code. If I run "ruby file_spec.rb" I get the missing "spec_helper.rb". If I run that one I get another missing one.
Sorry but I'm having problems to run the "Rakefile".

@pointlessone
Copy link
Member

@pointlessone pointlessone commented May 20, 2016

@danny182 That code won't extract anything for you. That is merely an example of usage. You would need to write your own code to actually extract emoji.

The file is not a "Rakefile". It's a spec file meant to be run with RSpec. Try rspec spec/integration/file_spec.rb to run it but I'm not sure how that might be helpful to you.

@DanielZanchi
Copy link

@DanielZanchi DanielZanchi commented May 21, 2016

I found a way. By running "gemoji"
by terminal running "rake images:extract" it extracts the emojis but it doesn't extracts some of them.
"🙄 1F644" doesn't get extracted. I updated manually the "db/NamesList.txt" (the info of that emoji is in there).
Can someone help me?

Thanks in advance
@pointlessone @javan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants