prawn-emoji 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/prawn/emoji/drawer.rb +39 -9
- data/lib/prawn/emoji/image.rb +2 -7
- data/lib/prawn/emoji/index.rb +6 -1
- data/lib/prawn/emoji/unicode.rb +39 -0
- data/lib/prawn/emoji/version.rb +1 -1
- data/test/prawn/emoji/drawer_test.rb +3 -2
- data/test/prawn/emoji/image_test.rb +13 -6
- data/test/prawn/emoji/index_test.rb +1 -1
- data/test/prawn/emoji/unicode_test.rb +36 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30464f704625995fdd24c34529781eb09f5cc988
|
4
|
+
data.tar.gz: 730b6f231a9db3d31f560372bbffcc1e45da50cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00c4a04c30c7c42b529a16a0368e2f9d689dcfece6adb14c2b8d2eb339de921175e8ed469f0415fe0a21f77624ff35de9401293c9e64959002d1726c7263e02f
|
7
|
+
data.tar.gz: 871b4cdf8e5af80ac414160bd2603884900438746f08b9a43da551e90c04d25b465c54f1a5dba4f6f939219e0e96b14680e181e6354959decfce767cf30d6c21
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 2.1.0
|
2
|
+
|
3
|
+
### Breaking Changes
|
4
|
+
|
5
|
+
* Support variation selector
|
6
|
+
* An emoji with text presentation selector such as ☀︎ (U+2600 U+FE0E) will be drawn as text
|
7
|
+
* See also http://www.unicode.org/reports/tr51/tr51-12.html#def_text_presentation_selector
|
8
|
+
|
1
9
|
## 2.0.1
|
2
10
|
|
3
11
|
### Bug Fixes:
|
data/lib/prawn/emoji/drawer.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'substitution'
|
4
4
|
require_relative 'index'
|
5
5
|
require_relative 'image'
|
6
|
+
require_relative 'unicode'
|
6
7
|
|
7
8
|
module Prawn
|
8
9
|
module Emoji
|
@@ -22,25 +23,54 @@ module Prawn
|
|
22
23
|
private
|
23
24
|
|
24
25
|
def draw_emoji(text, text_options)
|
25
|
-
|
26
|
+
return text unless @emoji_index.to_regexp =~ text
|
27
|
+
|
28
|
+
result = []
|
29
|
+
target = text
|
30
|
+
|
31
|
+
while target do
|
32
|
+
left_text, emoji_unicode, remaining_text = partition_emoji(target)
|
26
33
|
|
27
|
-
|
34
|
+
if emoji_unicode.nil?
|
35
|
+
result << target
|
36
|
+
break
|
37
|
+
end
|
28
38
|
|
29
|
-
|
39
|
+
result << left_text
|
40
|
+
result << if emoji_unicode.text?
|
41
|
+
emoji_unicode.to_s
|
42
|
+
else
|
43
|
+
emoji_image = Emoji::Image.new(emoji_unicode)
|
30
44
|
|
31
|
-
|
32
|
-
|
33
|
-
|
45
|
+
emoji_x, emoji_y = text_options[:at]
|
46
|
+
emoji_x += @document.width_of(left_text, text_options)
|
47
|
+
emoji_y += @document.font_size
|
34
48
|
|
35
|
-
|
49
|
+
draw_emoji_image emoji_image, at: [emoji_x, emoji_y], width: @document.font_size
|
36
50
|
|
37
|
-
|
38
|
-
|
51
|
+
Emoji::Substitution.new(@document).to_s
|
52
|
+
end
|
53
|
+
target = remaining_text
|
54
|
+
end
|
55
|
+
|
56
|
+
result.join
|
39
57
|
end
|
40
58
|
|
41
59
|
def draw_emoji_image(emoji_image, at:, width:)
|
42
60
|
@document.image emoji_image.path, at: at, width: width
|
43
61
|
end
|
62
|
+
|
63
|
+
def partition_emoji(text)
|
64
|
+
left_text, emoji_unicode, remaining_text = text.partition(@emoji_index.to_regexp)
|
65
|
+
|
66
|
+
return nil if emoji_unicode.empty?
|
67
|
+
|
68
|
+
[
|
69
|
+
left_text,
|
70
|
+
Emoji::Unicode.new(emoji_unicode),
|
71
|
+
remaining_text
|
72
|
+
]
|
73
|
+
end
|
44
74
|
end
|
45
75
|
end
|
46
76
|
end
|
data/lib/prawn/emoji/image.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require_relative 'unicode'
|
4
5
|
|
5
6
|
module Prawn
|
6
7
|
module Emoji
|
@@ -14,18 +15,12 @@ module Prawn
|
|
14
15
|
end
|
15
16
|
|
16
17
|
def path
|
17
|
-
STORE.join("#{codepoint}.png").to_s
|
18
|
+
STORE.join("#{unicode.codepoint}.png").to_s
|
18
19
|
end
|
19
20
|
|
20
21
|
def ==(other)
|
21
22
|
unicode == other.unicode
|
22
23
|
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def codepoint
|
27
|
-
@codepoint ||= @unicode.codepoints.map { |c| '%04x' % c.to_s }.join('-').downcase
|
28
|
-
end
|
29
24
|
end
|
30
25
|
end
|
31
26
|
end
|
data/lib/prawn/emoji/index.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'unicode'
|
4
|
+
|
3
5
|
module Prawn
|
4
6
|
module Emoji
|
5
7
|
class Index
|
@@ -18,7 +20,10 @@ module Prawn
|
|
18
20
|
private
|
19
21
|
|
20
22
|
def build_regexp
|
21
|
-
|
23
|
+
emojis = codepoints.map { |codepoint| unicode(codepoint) }
|
24
|
+
variation_selectors = Emoji::Unicode::VARIATION_SELECTORS.values
|
25
|
+
|
26
|
+
Regexp.new("(#{emojis.join('|')})[#{variation_selectors.join}]?")
|
22
27
|
end
|
23
28
|
|
24
29
|
def load_emoji_codepoints
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Prawn
|
4
|
+
module Emoji
|
5
|
+
class Unicode
|
6
|
+
VARIATION_SELECTORS = {
|
7
|
+
text: '\ufe0e',
|
8
|
+
emoji: '\ufe0f'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
def initialize(char)
|
12
|
+
@present_as_text = !!char.match(VARIATION_SELECTORS[:text])
|
13
|
+
@unicode = delete_variation_selector(char)
|
14
|
+
end
|
15
|
+
|
16
|
+
def ==(other)
|
17
|
+
to_s == other.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def codepoint
|
21
|
+
@codepoint ||= @unicode.codepoints.map { |c| '%04x' % c.to_s }.join('-').downcase
|
22
|
+
end
|
23
|
+
|
24
|
+
def text?
|
25
|
+
@present_as_text
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
@unicode
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def delete_variation_selector(char)
|
35
|
+
char.gsub(/[#{VARIATION_SELECTORS.values.join}]/, '')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/prawn/emoji/version.rb
CHANGED
@@ -7,7 +7,8 @@ describe Prawn::Emoji::Drawer do
|
|
7
7
|
let(:drawer) { Prawn::Emoji::Drawer.new document: document }
|
8
8
|
|
9
9
|
let(:sushi) { '🍣' }
|
10
|
-
let(:
|
10
|
+
let(:sushi_unicode) { Prawn::Emoji::Unicode.new(sushi) }
|
11
|
+
let(:sushi_image) { Prawn::Emoji::Image.new(sushi_unicode) }
|
11
12
|
|
12
13
|
before do
|
13
14
|
document.font Prawn::Emoji.root.join 'test', 'fonts', 'DejaVuSans.ttf'
|
@@ -48,7 +49,7 @@ describe Prawn::Emoji::Drawer do
|
|
48
49
|
end
|
49
50
|
|
50
51
|
describe 'when includes emoji' do
|
51
|
-
let(:text) { "aaa#{sushi}bbb"}
|
52
|
+
let(:text) { "aaa#{sushi}bbb" }
|
52
53
|
|
53
54
|
it 'draws image for included emoji' do
|
54
55
|
image_width = 12
|
@@ -3,13 +3,20 @@
|
|
3
3
|
require 'test_helper'
|
4
4
|
|
5
5
|
describe Prawn::Emoji::Image do
|
6
|
-
|
6
|
+
describe '#path' do
|
7
|
+
let(:emojis) { %w( 😀 © 🇯🇵 ) }
|
8
|
+
let(:emoji_unicodes) { emojis.map { |emoji| Prawn::Emoji::Unicode.new(emoji) } }
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
it 'possible to find the image file' do
|
11
|
+
emoji_unicodes.each do |emoji_unicode|
|
12
|
+
emoji_image = Prawn::Emoji::Image.new(emoji_unicode)
|
13
|
+
assert File.exist?(emoji_image.path), "#{emoji_unicode} not found"
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
17
|
+
|
18
|
+
describe '#==' do
|
19
|
+
it { Prawn::Emoji::Image.new('🍣').must_be :==, Prawn::Emoji::Image.new('🍣') }
|
20
|
+
it { Prawn::Emoji::Image.new('🍣').wont_be :==, Prawn::Emoji::Image.new('🐟') }
|
21
|
+
end
|
15
22
|
end
|
@@ -20,6 +20,6 @@ describe Prawn::Emoji::Index do
|
|
20
20
|
subject { index.to_regexp }
|
21
21
|
before { stub(index).codepoints { %w( 00a9 00ae 002a-20e3 ) } }
|
22
22
|
|
23
|
-
it { subject.must_equal(
|
23
|
+
it { subject.must_equal(/(\u{00a9}|\u{00ae}|\u{002a 20e3})[\ufe0e\ufe0f]?/) }
|
24
24
|
end
|
25
25
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
describe Prawn::Emoji::Unicode do
|
6
|
+
let(:klass) { Prawn::Emoji::Unicode }
|
7
|
+
|
8
|
+
describe '#==' do
|
9
|
+
it { klass.new('🐟').must_be :==, klass.new('🐟') }
|
10
|
+
it { klass.new('🐟').wont_be :==, klass.new('🍣') }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#codepoint' do
|
14
|
+
it { klass.new('🍣').codepoint.must_equal '1f363' }
|
15
|
+
it { klass.new('🇯🇵').codepoint.must_equal '1f1ef-1f1f5' }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#to_s' do
|
19
|
+
it { klass.new('🍣').to_s.must_equal '🍣' }
|
20
|
+
it { klass.new('❤️').to_s.wont_match /[\ufe0e\ufe0f]/ }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#text?' do
|
24
|
+
describe 'no selector' do
|
25
|
+
it { klass.new('☀').wont_be :text? }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'with text presentation selector' do
|
29
|
+
it { klass.new('☀︎').must_be :text? }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'with emoji presentation selector' do
|
33
|
+
it { klass.new('☀️').wont_be :text? }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
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
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katsuya HIDAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -1947,6 +1947,7 @@ files:
|
|
1947
1947
|
- lib/prawn/emoji/image.rb
|
1948
1948
|
- lib/prawn/emoji/index.rb
|
1949
1949
|
- lib/prawn/emoji/substitution.rb
|
1950
|
+
- lib/prawn/emoji/unicode.rb
|
1950
1951
|
- lib/prawn/emoji/version.rb
|
1951
1952
|
- prawn-emoji.gemspec
|
1952
1953
|
- test/fonts/DejaVuSans.ttf
|
@@ -1959,6 +1960,7 @@ files:
|
|
1959
1960
|
- test/prawn/emoji/image_test.rb
|
1960
1961
|
- test/prawn/emoji/index_test.rb
|
1961
1962
|
- test/prawn/emoji/substitution_test.rb
|
1963
|
+
- test/prawn/emoji/unicode_test.rb
|
1962
1964
|
- test/prawn/emoji_test.rb
|
1963
1965
|
- test/test_helper.rb
|
1964
1966
|
homepage: https://github.com/hidakatsuya/prawn-emoji
|