emoji-extractor 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57fef793666240c0b03486d9408ebf3e0eaeb52f
4
+ data.tar.gz: 05488eb943f31cd1ee85e71751c4be34cb7d1a6c
5
+ SHA512:
6
+ metadata.gz: 52bff03af5915a42ca932676a97a7d1f3c748b5478ff6bc356d01b53a59c12a2f8ae1144442ccb05a44a92865191282eb01087ec0045961e60f72746ff335059
7
+ data.tar.gz: f1b3180f4ef425edbafe809db1b1c1e62b402be3ef35f6a01cfddfb46026a7253a4a28e54d3a8a88748da5a162244fcb00ad203908acddac8cc9c2957d96ea21
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "jeweler", "~> 2.0.1"
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Andrey Cherkashin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = emoji-extractor
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to emoji-extractor
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Andrey Cherkashin. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "emoji-extractor"
18
+ gem.homepage = "http://github.com/andoriyu/emoji-extractor"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{extracts high-resolution emoji pngs from ttf}
21
+ gem.description = %Q{extracts high-resolution emoji pngs from ttf}
22
+ gem.email = "with.out@me.com"
23
+ gem.authors = ["Andrey Cherkashin", "Aman Gupta"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "emoji-extractor #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,71 @@
1
+ # encoding: ascii
2
+ class EmojiExtractor
3
+ @options = {}
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def run
9
+ if File.directory?(@options[:dst])
10
+ Dir.rmdir(@options[:dst])
11
+ end
12
+ FileUtils.mkdir_p @options[:dst]
13
+
14
+ raise "Can't locate emoji ttf" unless File.exists?(@options[:file])
15
+ ttf = File.new(@options[:file],"rb")
16
+ ttf_data = ttf.read
17
+
18
+ pos = 0
19
+ while m = /\211PNG/.match(ttf_data[pos..-1])
20
+ raise "no PNG found" if !m
21
+ pos += m.begin(0) + 1
22
+ ttf.seek(pos-1)
23
+
24
+ extract_png(ttf)
25
+ end
26
+
27
+ end
28
+
29
+ private
30
+ def extract_chunk(input, output)
31
+ lenword = input.read(4)
32
+ length = lenword.unpack('N')[0]
33
+ type = input.read(4)
34
+ data = length>0 ? input.read(length) : ""
35
+ crc = input.read(4)
36
+ return nil if length<0 || !(('A'..'z')===type[0,1])
37
+ #return nil if validate_crc(type+data, crc)
38
+ output.write lenword
39
+ output.write type
40
+ output.write data
41
+ output.write crc
42
+ return [type, data]
43
+ end
44
+
45
+ def extract_png(input)
46
+ buf = StringIO.new
47
+ hdr = input.read(8)
48
+ raise "Not a PNG File" if hdr[0,4]!= "\211PNG"
49
+ raise "file not in binary mode" if hdr[4,4]!="\r\n\032\n"
50
+ buf.write(hdr)
51
+
52
+ height, width = 0, 0
53
+
54
+ loop do
55
+ chunk_type, chunk_data = extract_chunk(input,buf)
56
+ height, width = chunk_data.unpack('NN') if chunk_type == 'IHDR'
57
+ break if chunk_type.nil? || chunk_type == 'IEND'
58
+ end
59
+
60
+ FileUtils.mkdir_p(dir = "images/#{height}x#{width}")
61
+ if @prev != dir
62
+ @n = 0
63
+ @prev = dir
64
+ end
65
+
66
+ buf.rewind
67
+ ofp = File.new("#{dir}/#{@n+=1}.png","wb")
68
+ ofp.write buf.read
69
+ ofp.close
70
+ end
71
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require 'test/unit'
27
+ require 'shoulda'
28
+
29
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
30
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
31
+ require 'emoji-extractor'
32
+
33
+ class Test::Unit::TestCase
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestEmojiExtractor < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emoji-extractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Cherkashin
8
+ - Aman Gupta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jeweler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.0.1
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.1
28
+ description: extracts high-resolution emoji pngs from ttf
29
+ email: with.out@me.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files:
33
+ - LICENSE.txt
34
+ - README.rdoc
35
+ files:
36
+ - ".document"
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/emoji-extractor.rb
43
+ - test/helper.rb
44
+ - test/test_emoji-extractor.rb
45
+ homepage: http://github.com/andoriyu/emoji-extractor
46
+ licenses:
47
+ - MIT
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.2.2
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: extracts high-resolution emoji pngs from ttf
69
+ test_files: []