prawn-emoji 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '0946a00d0fd3bd61f4ede09d782fbf90fb9a4546'
4
- data.tar.gz: fc76bbf278462517086bb81fc753633b25169b31
3
+ metadata.gz: 26bd2353da780fc31e8ebd11751a1156916d7cea
4
+ data.tar.gz: 359e3538740e6c1e14a90ad6a399bb5be5c94624
5
5
  SHA512:
6
- metadata.gz: 1fe08b160bd51782ae7acbff906173489651480b38e873715d51ccd0f9cc68bfde30cb48b0a5013920b57759b4dedd1d9e17734cdc7530778eea383559dcb39d
7
- data.tar.gz: 85362bde5126d3fead36c462faef012ead105ed553bda946eaa48f99bee0df616821ca557afd5d34d5ed58ee89e8cb1eeb944ac1a58f75cfc4d316ddeeb1c7da
6
+ metadata.gz: e408960124f71a8c5151ac0ac12a767a47a992e9b819d35a932d7201f21887556f5a17ede3551dc5823900cdff03faf67601b884987f5d1242ef6d32299be72d
7
+ data.tar.gz: f21a974d7dcdf8e954b64639f9c33b7320d829e1467654e3f7ac0b0190d9b79b32587c57a336a8cd37a1a984e2dbaa12c6f8da868f6d41e7ed01eaae22a7b78d
data/.gitignore CHANGED
@@ -1,3 +1,2 @@
1
1
  /.bundle/
2
- /pkg/
3
2
  /Gemfile.lock
@@ -4,15 +4,12 @@ sudo: false
4
4
 
5
5
  rvm:
6
6
  - 2.1.10
7
- - 2.2.6
8
- - 2.3.3
7
+ - 2.2.7
8
+ - 2.3.4
9
+ - 2.4.1
9
10
 
10
11
  gemfile:
11
12
  - test/gemfiles/prawn-2.1
13
+ - test/gemfiles/prawn-2.2
12
14
 
13
15
  script: bundle exec rake test
14
-
15
- branches:
16
- only:
17
- - master
18
- - /\-stable$/
@@ -1,3 +1,9 @@
1
+ ## 2.0.1
2
+
3
+ ### Bug Fixes:
4
+
5
+ * Fixed: part of ASCII chars and symbols is unexpectedly replaced with emojis #17 [@juanfal]
6
+
1
7
  ## 2.0.0
2
8
 
3
9
  * prawn-emoji requires Prawn 2.1 or higher
data/README.md CHANGED
@@ -61,11 +61,11 @@ See also https://travis-ci.org/hidakatsuya/prawn-emoji.
61
61
 
62
62
  ### Ruby
63
63
 
64
- 2.1, 2.2, 2.3
64
+ 2.1, 2.2, 2.3, 2.4
65
65
 
66
66
  ### Prawn
67
67
 
68
- 2.1
68
+ 2.1, 2.2
69
69
 
70
70
  INFO: Version 1.x supports Prawn 1.3 and 2.0. See [README in 1.0-stable branch](https://github.com/hidakatsuya/prawn-emoji/blob/1.0-stable/README.md).
71
71
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'prawn'
2
4
  require 'pathname'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'drawer'
2
4
 
3
5
  module Prawn
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'substitution'
2
4
  require_relative 'index'
3
5
  require_relative 'image'
@@ -20,7 +22,7 @@ module Prawn
20
22
  private
21
23
 
22
24
  def draw_emoji(text, text_options)
23
- left_text, emoji_unicode, remaining_text = text.partition(@emoji_index.unicodes_regexp)
25
+ left_text, emoji_unicode, remaining_text = text.partition(@emoji_index.to_regexp)
24
26
 
25
27
  return text if emoji_unicode.empty?
26
28
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
 
3
5
  module Prawn
@@ -1,18 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Emoji
3
5
  class Index
4
- def unicodes
5
- @unicodes ||= YAML.load Emoji.root.join('emoji', 'index.yml').read
6
+ EXCLUSION_CHARS = '1234567890#*'.freeze
7
+
8
+ attr_reader :codepoints
9
+
10
+ def initialize
11
+ @codepoints = load_emoji_codepoints
6
12
  end
7
13
 
8
- def unicodes_regexp
9
- @unicodes_regexp ||= build_unicodes_regexp
14
+ def to_regexp
15
+ @regexp ||= build_regexp
10
16
  end
11
17
 
12
18
  private
13
19
 
14
- def build_unicodes_regexp
15
- Regexp.compile unicodes.map { |unicode| "\\u{#{unicode.split('-').join(' ')}}" }.join('|')
20
+ def build_regexp
21
+ Regexp.new(codepoints.map { |codepoint| unicode(codepoint) }.join('|'))
22
+ end
23
+
24
+ def load_emoji_codepoints
25
+ codepoints = YAML.load_file(Emoji.root.join('emoji', 'index.yml'))
26
+ codepoints.reject { |codepoint| /#{unicode(codepoint)}/ =~ EXCLUSION_CHARS }
27
+ end
28
+
29
+ def unicode(codepoint)
30
+ "\\u{#{codepoint.split('-').join(' ')}}"
16
31
  end
17
32
  end
18
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
 
3
5
  module Prawn
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Emoji
3
- VERSION = '2.0.0'.freeze
5
+ VERSION = '2.0.1'.freeze
4
6
  end
5
7
  end
@@ -1,24 +1,23 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $:.unshift(lib) unless $:.include?(lib)
1
+ rootdir = File.expand_path(File.dirname(__FILE__))
3
2
 
4
- require 'prawn/emoji/version'
3
+ require "#{rootdir}/lib/prawn/emoji/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = 'prawn-emoji'
8
7
  spec.version = Prawn::Emoji::VERSION
9
- spec.authors = ['Katsuya HIDAKA']
10
- spec.email = ['hidakatsuya@gmail.com']
8
+ spec.author = 'Katsuya HIDAKA'
9
+ spec.email = 'hidakatsuya@gmail.com'
11
10
 
12
11
  spec.summary = 'Provides support for Emoji in Prawn'
13
12
  spec.description = 'Prawn::Emoji is an extention for Prawn, provides feature for drawing Emoji.'
14
13
  spec.homepage = 'https://github.com/hidakatsuya/prawn-emoji'
15
14
  spec.license = 'MIT'
16
- spec.platform = Gem::Platform::RUBY
15
+
17
16
  spec.required_ruby_version = '>= 2.1'
18
17
 
19
18
  spec.files = `git ls-files`.split("\n")
20
19
  spec.test_files = `git ls-files -- {test}/*`.split("\n")
21
- spec.require_paths = ['lib']
20
+ spec.require_path = 'lib'
22
21
 
23
22
  spec.add_runtime_dependency 'prawn', '>= 2.1.0'
24
23
 
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'prawn', '~> 2.2.0'
4
+
5
+ gem 'rake', '>= 0'
6
+ gem 'minitest', '>= 0'
7
+ gem 'rr', '>= 0'
8
+ gem 'pdf-inspector', '>= 0'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe Prawn::Emoji::Drawable do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe Prawn::Emoji::Drawer do
@@ -15,7 +17,7 @@ describe Prawn::Emoji::Drawer do
15
17
  subject { drawer.draw(text, {}) }
16
18
 
17
19
  describe 'when text encoding is not utf-8' do
18
- let(:text) { "\xe8\x8a\xb1".force_encoding('ascii-8bit') }
20
+ let(:text) { 'a'.encode('ascii-8bit') }
19
21
 
20
22
  it 'skip' do
21
23
  mock(drawer).draw_emoji(text, {}).never
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe Prawn::Emoji::Image do
@@ -1,18 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
  require 'yaml'
3
5
 
4
6
  describe Prawn::Emoji::Index do
5
7
  let(:index) { Prawn::Emoji::Index.new }
6
8
 
7
- describe '#unicodes' do
8
- subject { index.unicodes }
9
- it { subject.must_equal YAML.load Prawn::Emoji.root.join('emoji', 'index.yml').read }
9
+ describe '#codepoints' do
10
+ subject { index.codepoints }
11
+
12
+ let(:all_codes) { YAML.load_file(Prawn::Emoji.root.join('emoji', 'index.yml')) }
13
+ # Expect to excludes ASCII characters and symbols
14
+ let(:exclusion_codes) { (0x21..0x7e).map { |code| '%04x' % code }.map(&:downcase) }
15
+
16
+ it { subject.must_equal all_codes - exclusion_codes }
10
17
  end
11
18
 
12
- describe '#unicodes_regexp' do
13
- subject { index.unicodes_regexp }
14
- before { stub(index).unicodes { %w( 00A9 00AE ) } }
19
+ describe '#to_regexp' do
20
+ subject { index.to_regexp }
21
+ before { stub(index).codepoints { %w( 00a9 00ae 002a-20e3 ) } }
15
22
 
16
- it { subject.must_equal(/\u{00A9}|\u{00AE}/) }
23
+ it { subject.must_equal(/\u{00a9}|\u{00ae}|\u{002a 20e3}/) }
17
24
  end
18
25
  end
@@ -1,26 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe Prawn::Emoji::Substitution do
4
6
  let(:document) { Prawn::Document.new }
7
+ let(:font_size) { 12 }
5
8
  let(:substitution) { Prawn::Emoji::Substitution.new(document) }
6
9
 
10
+ before do
11
+ document.font(font) if font
12
+ document.font_size = 12
13
+ end
14
+
7
15
  subject { substitution.to_s }
8
16
 
9
- describe 'full-size-space is used' do
10
- before do
11
- document.font_size = 12
12
- stub(substitution).full_size_space_width { 12 }
13
- end
17
+ describe 'When Japanese TTF font' do
18
+ let(:font) { Prawn::Emoji.root.join('test', 'fonts', 'ipag.ttf') }
14
19
 
15
20
  it { subject.must_equal ' ' }
21
+ it { document.width_of(subject).must_equal font_size }
22
+ end
23
+
24
+ describe 'When ASCII TTF font' do
25
+ let(:font) { Prawn::Emoji.root.join('test', 'fonts', 'DejaVuSans.ttf') }
26
+
27
+ it { subject.must_match /^#{Prawn::Text::NBSP}+$/ }
28
+ it { document.width_of(subject).must_be :>=, font_size - 1 }
29
+ it { document.width_of(subject).must_be :<=, font_size + 1 }
16
30
  end
17
31
 
18
- describe 'half-size-space is used' do
19
- before do
20
- document.font_size = 12
21
- stub(substitution).full_size_space_width { 11.99 }
22
- end
32
+ describe 'When built-in AFM font' do
33
+ let(:font) { nil }
23
34
 
24
- it { subject.must_equal Prawn::Text::NBSP }
35
+ it { proc { subject }.must_raise Prawn::Errors::IncompatibleStringEncoding }
25
36
  end
26
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  describe 'Prawn integration' do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $:.unshift File.expand_path('../../lib', __FILE__)
2
4
 
3
5
  require 'prawn'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-emoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya HIDAKA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2017-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -96,8 +96,7 @@ dependencies:
96
96
  version: '0'
97
97
  description: Prawn::Emoji is an extention for Prawn, provides feature for drawing
98
98
  Emoji.
99
- email:
100
- - hidakatsuya@gmail.com
99
+ email: hidakatsuya@gmail.com
101
100
  executables: []
102
101
  extensions: []
103
102
  extra_rdoc_files: []
@@ -1954,6 +1953,7 @@ files:
1954
1953
  - test/fonts/IPA_Font_License_Agreement_v1.0.txt
1955
1954
  - test/fonts/ipag.ttf
1956
1955
  - test/gemfiles/prawn-2.1
1956
+ - test/gemfiles/prawn-2.2
1957
1957
  - test/prawn/emoji/drawable_test.rb
1958
1958
  - test/prawn/emoji/drawer_test.rb
1959
1959
  - test/prawn/emoji/image_test.rb
@@ -1981,7 +1981,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1981
1981
  version: '0'
1982
1982
  requirements: []
1983
1983
  rubyforge_project:
1984
- rubygems_version: 2.6.8
1984
+ rubygems_version: 2.6.11
1985
1985
  signing_key:
1986
1986
  specification_version: 4
1987
1987
  summary: Provides support for Emoji in Prawn